constants(); register_activation_hook( __FILE__, array( $this, 'activation' ) ); register_deactivation_hook( __FILE__, array( $this, 'deactivation' ) ); add_action( 'init', array( $this, 'content_types' ) ); add_action( 'after_setup_theme', array( $this, 'post_thumbnail_support' ), 9999 ); add_action( 'manage_posts_custom_column', array( $this, 'columns_data' ) ); add_action( 'wp_enqueue_scripts', array( $this, 'scripts' ) ); add_action( 'admin_enqueue_scripts', array( $this, 'admin_css' ) ); add_action( 'right_now_content_table_end', array( $this, 'right_now' ) ); add_action( 'wp_dashboard_setup', array( $this, 'register_dashboard_widget' ) ); add_action( 'init', 'arconix_portfolio_init_meta_boxes', 99 ); add_filter( 'manage_portfolio_posts_columns', array( $this, 'columns_filter' ) ); add_filter( 'post_updated_messages', array( $this, 'updated_messages' ) ); add_filter( 'cmb_meta_boxes', array( $this, 'metaboxes' ) ); add_filter( 'widget_text', 'do_shortcode' ); add_image_size( 'portfolio-thumb', 275, 200 ); add_image_size( 'portfolio-large', 620, 9999 ); add_shortcode( 'portfolio', array( $this, 'acp_portfolio_shortcode' ) ); } /** * Define plugin constants * * @since 1.2.0 */ function constants() { define( 'ACP_VERSION', '1.3.1' ); define( 'ACP_URL', trailingslashit( plugin_dir_url( __FILE__ ) ) ); define( 'ACP_IMAGES_URL', trailingslashit( ACP_URL . 'images' ) ); define( 'ACP_INCLUDES_URL', trailingslashit( ACP_URL . 'includes' ) ); define( 'ACP_CSS_URL', trailingslashit( ACP_INCLUDES_URL . 'css' ) ); define( 'ACP_JS_URL', trailingslashit( ACP_INCLUDES_URL . 'js' ) ); define( 'ACP_DIR', trailingslashit( plugin_dir_path( __FILE__ ) ) ); define( 'ACP_INCLUDES_DIR', trailingslashit( ACP_DIR . 'includes' ) ); define( 'ACP_VIEWS_DIR', trailingslashit( ACP_INCLUDES_DIR . 'views' ) ); } /** * Runs on Plugin Activation * Registers our Post Type and Taxonomy * * @since 1.2.0 */ function activation() { $this->content_types(); flush_rewrite_rules(); } /** * Runs on Plugin Deactivation * * @since 1.2.0 */ function deactivation() { flush_rewrite_rules(); } /** * Register the post_type and taxonomy * * @since 1.2.0 */ function content_types() { $defaults = $this->portfolio_defaults(); register_post_type( $defaults['post_type']['slug'], $defaults['post_type']['args'] ); register_taxonomy( $defaults['taxonomy']['slug'], $defaults['post_type']['slug'], $defaults['taxonomy']['args'] ); } /** * Define the defaults used in the registration of the post type and taxonomy * * @since 1.2.0 * @return array $defaults */ function portfolio_defaults() { // Establishes plugin registration defaults for post type and taxonomy $defaults = array( 'post_type' => array( 'slug' => 'portfolio', 'args' => array( 'labels' => array( 'name' => __( 'Portfolio', 'acp' ), 'singular_name' => __( 'Portfolio', 'acp' ), 'add_new' => __( 'Add New', 'acp' ), 'add_new_item' => __( 'Add New Portfolio Item', 'acp' ), 'edit' => __( 'Edit', 'acp' ), 'edit_item' => __( 'Edit Portfolio Item', 'acp' ), 'new_item' => __( 'New Item', 'acp' ), 'view' => __( 'View Portfolio', 'acp' ), 'view_item' => __( 'View Portfolio Item', 'acp' ), 'search_items' => __( 'Search Portfolio', 'acp' ), 'not_found' => __( 'No portfolio items found', 'acp' ), 'not_found_in_trash' => __( 'No portfolio items found in Trash', 'acp' ) ), 'public' => true, 'query_var' => true, 'menu_position' => 20, 'menu_icon' => ACP_IMAGES_URL . 'portfolio-icon-16x16.png', 'has_archive' => false, 'supports' => array( 'title', 'editor', 'thumbnail' ), 'rewrite' => array( 'slug' => 'portfolio', 'with_front' => false ) ) ), 'taxonomy' => array( 'slug' => 'feature', 'args' => array( 'labels' => array( 'name' => __( 'Features', 'acp' ), 'singular_name' => __( 'Feature', 'acp' ), 'search_items' => __( 'Search Features', 'acp' ), 'popular_items' => __( 'Popular Features', 'acp' ), 'all_items' => __( 'All Features', 'acp' ), 'parent_item' => null, 'parent_item_colon' => null, 'edit_item' => __( 'Edit Feature' , 'acp' ), 'update_item' => __( 'Update Feature', 'acp' ), 'add_new_item' => __( 'Add New Feature', 'acp' ), 'new_item_name' => __( 'New Feature Name', 'acp' ), 'separate_items_with_commas' => __( 'Separate features with commas', 'acp' ), 'add_or_remove_items' => __( 'Add or remove features', 'acp' ), 'choose_from_most_used' => __( 'Choose from the most used features', 'acp' ), 'menu_name' => __( 'Features', 'acp' ), ), 'hierarchical' => false, 'show_ui' => true, 'update_count_callback' => '_update_post_term_count', 'query_var' => true, 'rewrite' => array( 'slug' => 'feature' ) ) ), 'query' => array( 'link' => '', 'thumb' => 'portfolio-thumb', 'full' => 'portfolio-large', 'title' => 'above', 'display' => '', 'heading' => 'Display', 'orderby' => 'date', 'order' => 'desc', 'posts_per_page' => -1, 'terms' => '', 'operator' => 'IN', 'terms_orderby' => 'name', 'terms_order' => 'ASC' ) ); return apply_filters( 'arconix_portfolio_defaults', $defaults ); } /** * Create the post type metabox * * @param array $meta_boxes * @return array $meta_boxes * @since 1.3.0 */ function metaboxes( $meta_boxes ) { $metabox = array( 'id' => 'portfolio-setting', 'title' => __( 'Portfolio Setting', 'acp' ), 'pages' => array( 'portfolio' ), 'context' => 'side', 'priority' => 'default', 'show_names' => false, 'fields' => array( array( 'id' => '_acp_link_type', 'name' => __( 'Select Link Type', 'acp' ), 'type' => 'select', 'desc' => __( 'Set the hyperlink value for the portfolio item', 'acp' ), 'options' => array( array( 'name' => 'Image', 'value' => 'image' ), array( 'name' => 'Page', 'value' => 'page' ), array( 'name' => 'External Link', 'value' => 'external' ) ) ), array( 'id' => '_acp_link_value', 'name' => __( 'Optional Link', 'acp' ), 'desc' => __( 'If selected, enter the destination hyperlink', 'acp' ), 'type' => 'text' ) ) ); $meta_boxes[] = apply_filters( 'arconix_portfolio_metabox', $metabox ); return $meta_boxes; } /** * Correct messages when Portfolio post type is saved * * @global stdObject $post * @global int $post_ID * @param array $messages * @return array $messages * @since 0.9 */ function updated_messages( $messages ) { global $post, $post_ID; $messages['portfolio'] = array( 0 => '', // Unused. Messages start at index 1. 1 => sprintf( __( 'Portfolio Item updated. View portfolio item' ), esc_url( get_permalink($post_ID) ) ), 2 => __( 'Custom field updated.' ), 3 => __( 'Custom field deleted.' ), 4 => __( 'Portfolio item updated.' ), /* translators: %s: date and time of the revision */ 5 => isset( $_GET['revision'] ) ? sprintf( __( 'Portfolio item restored to revision from %s' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false, 6 => sprintf( __( 'Portfolio item published. View portfolio item' ), esc_url( get_permalink($post_ID) ) ), 7 => __( 'Portfolio item saved.'), 8 => sprintf( __( 'Portfolio item submitted. Preview portfolio item' ), esc_url( add_query_arg( 'preview', 'true', get_permalink( $post_ID ) ) ) ), 9 => sprintf( __( 'Portfolio item scheduled for: %1$s. Preview portfolio item' ), // translators: Publish box date format, see http://php.net/date date_i18n( __( 'M j, Y @ G:i' ), strtotime( $post->post_date ) ), esc_url( get_permalink($post_ID) ) ), 10 => sprintf( __( 'Portfolio item draft updated. Preview portfolio item' ), esc_url( add_query_arg( 'preview', 'true', get_permalink( $post_ID ) ) ) ), ); return $messages; } /** * Filter the columns on the admin screen and define our own * * @param array $columns * @return array $soumns * @since 0.9.0 * @version 1.2.0 */ function columns_filter ( $columns ) { $columns = array( 'cb' => '', 'portfolio_thumbnail' => __( 'Image', 'acp' ), 'title' => __( 'Title', 'acp' ), 'portfolio_description' => __( 'Description', 'acp' ), 'portfolio_features' => __( 'Features', 'acp' ), 'portfolio_link' => __( 'Link Type', 'acp' ), 'date' => __( 'Date', 'acp' ) ); return $columns; } /** * Filter the data that shows up in the columns we defined above * * @global stdObject $post * @param object $column * @since 0.9.0 * @version 1.2.0 */ function columns_data( $column ) { global $post; switch( $column ) { case "portfolio_thumbnail": printf( '
%s
', the_post_thumbnail( 'thumbnail' ) ); break; case "portfolio_description": the_excerpt(); break; case "portfolio_features": echo get_the_term_list( $post->ID, 'feature', '', ', ', '' ); break; case "portfolio_link": get_post_meta( $post->ID, '_acp_link_type', true ); break; } } /** * Check for post-thumbnails and add portfolio post type to it * * @global type $_wp_theme_features * @since 0.9 */ function post_thumbnail_support() { global $_wp_theme_features; if( ! isset( $_wp_theme_features['post-thumbnails'] ) ) $_wp_theme_features['post-thumbnails'] = array( array( 'portfolio' ) ); elseif( is_array( $_wp_theme_features['post-thumbnails'] ) ) $_wp_theme_features['post-thumbnails'][0][] = 'portfolio'; } /** * Portfolio Shortcode * * @param array $atts * @param string $content * @since 0.9 * @version 1.3.1 */ function acp_portfolio_shortcode( $atts, $content = null ) { if( wp_script_is( 'arconix-portfolio-js', 'registered' ) ) wp_enqueue_script( 'arconix-portfolio-js' ); return $this->get_portfolio_data( $atts ); } /** * Return Porfolio Content * * Grab all portfolio items from the database and sets up their display. * * Supported Arguments * - link => page, image * - thumb => any built-in image size * - full => any built-in image size (this setting is ignored of 'link' is set to 'page') * - title => above, below or 'blank' ("yes" is converted to "above" for backwards compatibility) * - display => content, excerpt (leave blank for nothing) * - heading => When displaying the 'feature' items in a row above the portfolio items, define the heading text for that section. * - orderby => date or any other orderby param available. http://codex.wordpress.org/Class_Reference/WP_Query#Order_.26_Orderby_Parameters * - order => ASC (ascending), DESC (descending) * - terms => a 'feature' tag you want to filter on operator => 'IN', 'NOT IN' filter for the term tag above * * 'Image' is the only officially supported link option. While linking to a page is possible, it may require additional coding * knowledge due to the fact that there are so many themes and nearly every one is different. {@see http://arconixpc.com/2012/linking-portfolio-items-to-pages } * * @param array $args * @param bool $echo Determines whether the data is returned or echo'd * @since 1.2.0 * @version 1.3.0 * */ function get_portfolio_data( $args, $echo = false ) { $default_args = $this->portfolio_defaults(); $defaults = $default_args['query']; // Merge incoming args with the function defaults and then extract them into variables $args = wp_parse_args( $args, $defaults ); extract( $args ); if( $title != "below" ) $title == "above"; // For backwards compatibility with "yes" and built-in data check // Default Query arguments $args = array( 'post_type' => 'portfolio', 'meta_key' => '_thumbnail_id', // Should pull only items with featured images 'posts_per_page' => $posts_per_page, 'orderby' => $orderby, 'order' => $order, ); // If the user has defined any tax terms, then we create our tax_query and merge to our main query if( $terms ) { $tax_query_args = apply_filters( 'arconix_portfolio_tax_query_args', array( 'tax_query' => array( array( 'taxonomy' => $default_args['taxonomy']['slug'], 'field' => 'slug', 'terms' => $terms, 'operator' => $operator ) ) ) ); // Join the tax array to the general query $args = array_merge( $args, $tax_query_args ); } $return = ''; // Var that will be concatenated with our portfolio data // Create a new query based on our own arguments $portfolio_query = new WP_Query( $args ); if( $portfolio_query->have_posts() ) { $a = array(); // Var to hold our operate arguments if( $terms ) { // Translate our user-entered slug into an id we can use $termid = get_term_by( 'slug', $terms, $default_args['taxonomy']['slug'] ); $termid = $termid->term_id; // Change the get_terms argument based on the shortcode $operator, but default to IN switch( $operator) { case "NOT IN": $a = array( 'exclude' => $termid ); break; case "IN": default: $a = array( 'include' => $termid ); break; } } // Set our terms list orderby and order $a['orderby'] = $terms_orderby; $a['order'] = $terms_order; // Allow a user to filter the terms list to modify or add their own parameters. $a = apply_filters( 'arconix_portfolio_get_terms', $a ); // Get the tax terms only from the items in our query $get_terms = get_terms( 'feature', $a ); // If there are multiple terms in use, then create our filter list if( count( $get_terms ) > 1 ) { $display_list = '