Plugin Directory

Changeset 1937694


Ignore:
Timestamp:
09/07/2018 07:35:52 PM (7 years ago)
Author:
themeblvd
Message:

1.1.5

Location:
portfolios
Files:
3 added
2 edited

Legend:

Unmodified
Added
Removed
  • portfolios/trunk/readme.txt

    r1494241 r1937694  
    33Contributors: themeblvd
    44Tags: bundle, Theme Blvd, themeblvd, Jason Bobich, portfolios
    5 Stable Tag: 1.1.4
     5Stable Tag: 1.1.5
     6Tested up to: 4.9
    67
    78Adds a "Portfolio Item" custom post type with associated "Portfolio" and "Porfolio Tag" taxonomies.
     
    106107== Changelog ==
    107108
     109= 1.1.5 - 09/07/2018 =
     110* Allow portfolio items to be available through REST API and editable with Gutenberg.
     111
    108112= 1.1.4 - 09/11/2016 =
    109 
    110 * Improvement: Apply archive post display option to portfolio item archives, opposed to just portfolio and portfolio tag taxonomy archives.
     113* Apply archive post display option to portfolio item archives, opposed to just portfolio and portfolio tag taxonomy archives.
    111114
    112115= 1.1.3 - 02/10/2015 =
    113 
    114116* Changed default value for "Portfolio Info Boxes" option.
    115117* Added Banner functionality to portfolio items (for framework 2.5+ themes).
    116118
    117119= 1.1.2 - 12/16/2014 =
    118 
    119120* Fixed filters applied to registering the taxonomies.
    120121* Added option for sidebar layout on portfolio archives (for framework 2.5+ themes).
     
    122123
    123124= 1.1.1 - 12/15/2014 =
    124 
    125125* Fixed Theme Blvd integration hook, from last update.
    126126* Fixed post meta integration (for framework 2.4 themes).
    127127
    128128= 1.1.0 - 12/13/2014 =
    129 
    130129* List associated portfolios at the bottom of the portfolio item post (for framework 2.5+ themes).
    131130* Added portfolio archive options at *Appearance > Theme Options > Content > Portfolios* (for framework 2.5+ themes).
     
    135134
    136135= 1.0.1 - 07/21/2014 =
    137 
    138136* Fixed PHP warning on Portfolio Items breadcrumb trail when no portfolio is selected.
    139137
    140138= 1.0.0 - 08/01/2013 =
    141 
    142139* This is the first release.
  • portfolios/trunk/tb-portfolios.php

    r1494241 r1937694  
    33Plugin Name: Portfolios
    44Description: Extend the Post Grid system in your Theme Blvd theme to a Portfolio custom post type.
    5 Version: 1.1.4
     5Version: 1.1.5
    66Author: Theme Blvd
    77Author URI: http://themeblvd.com
    88License: GPL2
    9 
    10     Copyright 2013  Theme Blvd
    11 
    12     This program is free software; you can redistribute it and/or modify
    13     it under the terms of the GNU General Public License version 2,
    14     as published by the Free Software Foundation.
    15 
    16     You may NOT assume that you can use any other version of the GPL.
    17 
    18     This program is distributed in the hope that it will be useful,
    19     but WITHOUT ANY WARRANTY; without even the implied warranty of
    20     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    21     GNU General Public License for more details.
    22 
    23     The license for this software can likely be found here:
    24     http://www.gnu.org/licenses/gpl-2.0.html
    25 
    269*/
    2710
    28 define( 'TB_PORTFOLIOS_PLUGIN_VERSION', '1.1.4' );
     11define( 'TB_PORTFOLIOS_PLUGIN_VERSION', '1.1.5' );
    2912define( 'TB_PORTFOLIOS_PLUGIN_DIR', dirname( __FILE__ ) );
    3013define( 'TB_PORTFOLIOS_PLUGIN_URI', plugins_url( '' , __FILE__ ) );
     
    3821class Theme_Blvd_Portfolios {
    3922
    40     /**
    41     * Only instance of object.
    42     * @var Theme_Blvd_Portfolios
    43     */
    44     private static $instance = null;
    45 
    46     /**
    47     * Creates or returns an instance of this class.
    48     *
    49     * @return Theme_Blvd_Portfolios A single instance of this class.
    50     *
    51     * @since 1.0.0
    52     */
    53     public static function get_instance() {
    54         if ( self::$instance == null ) {
    55             self::$instance = new self;
    56         }
    57         return self::$instance;
    58     }
    59 
    60     /**
    61     * Run plugin.
    62     *
    63     * @since 1.0.0
    64     */
    65     private function __construct() {
    66 
    67         // Localization
    68         add_action( 'init', array( $this, 'textdomain' ) );
    69 
    70         // Setup CPT & taxonomies
    71         add_action( 'init', array( $this, 'register' ) );
    72 
    73         // Theme Blvd Integration
    74         add_action( 'after_setup_theme', array( $this, 'themeblvd_init' ) );
    75 
    76     }
    77 
    78     /*--------------------------------------------*/
    79     /* Setup the post type and taxonomies
    80     /*--------------------------------------------*/
    81 
    82     /**
    83     * Plugin text domain for localization.
    84     * GlotPress-ready.
    85     *
    86     * @since 1.1.0
    87     */
    88     public function textdomain() {
    89         load_plugin_textdomain('portfolios');
    90     }
    91 
    92     /**
    93     * Register post type
    94     *
    95     * @since 1.0.0
    96     */
    97     public function register() {
    98 
    99         // Add Portfolio Item custom post type
    100         $labels = apply_filters( 'themeblvd_portfolio_item_cpt_labels', array(
    101             'name'                  => __( 'Portfolio Items', 'portfolios' ),
    102             'singular_name'         => __( 'Portfolio Item', 'portfolios' ),
    103             'add_new'               => __( 'Add New Item', 'portfolios' ),
    104             'add_new_item'          => __( 'Add New Portfolio Item', 'portfolios' ),
    105             'edit_item'             => __( 'Edit Item', 'portfolios' ),
    106             'new_item'              => __( 'New Portfolio Item', 'portfolios' ),
    107             'all_items'             => __( 'Portfolio Items', 'portfolios' ),
    108             'view_item'             => __( 'View Item', 'portfolios' ),
    109             'search_items'          => __( 'Search Portfolio Items', 'portfolios' ),
    110             'not_found'             => __( 'No portfolio items found', 'portfolios' ),
    111             'not_found_in_trash'    => __( 'No portfolio items found in Trash', 'portfolios' ),
    112             'menu_name'             => __( 'Portfolios' )
     23    /**
     24    * Only instance of object.
     25    * @var Theme_Blvd_Portfolios
     26    */
     27    private static $instance = null;
     28
     29    /**
     30    * Creates or returns an instance of this class.
     31    *
     32    * @return Theme_Blvd_Portfolios A single instance of this class.
     33    *
     34    * @since 1.0.0
     35    */
     36    public static function get_instance() {
     37        if ( self::$instance == null ) {
     38            self::$instance = new self;
     39        }
     40        return self::$instance;
     41    }
     42
     43    /**
     44    * Run plugin.
     45    *
     46    * @since 1.0.0
     47    */
     48    private function __construct() {
     49
     50        // Localization
     51        add_action( 'init', array( $this, 'textdomain' ) );
     52
     53        // Setup CPT & taxonomies
     54        add_action( 'init', array( $this, 'register' ) );
     55
     56        // Theme Blvd Integration
     57        add_action( 'after_setup_theme', array( $this, 'themeblvd_init' ) );
     58
     59    }
     60
     61    /*--------------------------------------------*/
     62    /* Setup the post type and taxonomies
     63    /*--------------------------------------------*/
     64
     65    /**
     66    * Plugin text domain for localization.
     67    * GlotPress-ready.
     68    *
     69    * @since 1.1.0
     70    */
     71    public function textdomain() {
     72        load_plugin_textdomain('portfolios' );
     73    }
     74
     75    /**
     76    * Register post type
     77    *
     78    * @since 1.0.0
     79    */
     80    public function register() {
     81
     82        // Add Portfolio Item custom post type
     83        $labels = apply_filters( 'themeblvd_portfolio_item_cpt_labels', array(
     84            'name'               => __( 'Portfolio Items', 'portfolios' ),
     85            'singular_name'      => __( 'Portfolio Item', 'portfolios' ),
     86            'add_new'            => __( 'Add New Item', 'portfolios' ),
     87            'add_new_item'       => __( 'Add New Portfolio Item', 'portfolios' ),
     88            'edit_item'          => __( 'Edit Item', 'portfolios' ),
     89            'new_item'           => __( 'New Portfolio Item', 'portfolios' ),
     90            'all_items'          => __( 'Portfolio Items', 'portfolios' ),
     91            'view_item'          => __( 'View Item', 'portfolios' ),
     92            'search_items'       => __( 'Search Portfolio Items', 'portfolios' ),
     93            'not_found'          => __( 'No portfolio items found', 'portfolios' ),
     94            'not_found_in_trash' => __( 'No portfolio items found in Trash', 'portfolios' ),
     95            'menu_name'          => __( 'Portfolios' ),
    11396        ));
    11497
    11598        $args = apply_filters( 'themeblvd_portfolio_item_cpt_args', array(
    116             'labels'                => $labels,
    117             'public'                => true,
    118             'publicly_queryable'    => true,
    119             'show_ui'               => true,
    120             'show_in_menu'          => true,
    121             'query_var'             => true,
    122             'rewrite'               => array( 'slug' => 'item' ),
    123             'capability_type'       => 'post',
    124             'has_archive'           => true,
    125             'hierarchical'          => false,
    126             'menu_icon'             => 'dashicons-portfolio', // overridden with CSS if using Theme Blvd theme
    127             'menu_position'         => null,
    128             'supports'              => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'comments' ),
    129             'taxonomies'            => array( 'portfolio', 'portfolio_tag' )
     99            'labels'             => $labels,
     100            'public'             => true,
     101            'publicly_queryable' => true,
     102            'show_ui'            => true,
     103            'show_in_menu'       => true,
     104            'query_var'          => true,
     105            'rewrite'            => array( 'slug' => 'item' ),
     106            'capability_type'    => 'post',
     107            'has_archive'        => true,
     108            'hierarchical'       => false,
     109            'menu_icon'          => 'dashicons-portfolio', // overridden with CSS if using Theme Blvd theme
     110            'menu_position'      => null,
     111            'supports'           => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'comments' ),
     112            'taxonomies'         => array( 'portfolio', 'portfolio_tag' ),
     113            'show_in_rest'       => true,
    130114        ));
    131115
     
    144128            'add_new_item'      => __( 'Add New Portfolio', 'portfolios' ),
    145129            'new_item_name'     => __( 'New Portfolio Name', 'portfolios' ),
    146             'menu_name'         => __( 'Portfolios', 'portfolios' )
     130            'menu_name'         => __( 'Portfolios', 'portfolios' ),
    147131        ));
    148132
     
    158142        register_taxonomy( 'portfolio', array( 'portfolio_item' ), $args );
    159143
    160         // Add "Portfolio Tag" taxonomy
    161         $labels = apply_filters( 'themeblvd_portfolio_tag_tax_labels', array(
    162             'name'              => __( 'Portfolio Tags', 'portfolios' ),
    163             'singular_name'     => __( 'Portfolio Tag', 'portfolios' ),
    164             'search_items'      => __( 'Search Portfolio Tags', 'portfolios' ),
    165             'all_items'         => __( 'All Portfolio Tags', 'portfolios' ),
    166             'edit_item'         => __( 'Edit Portfolio Tag', 'portfolios' ),
    167             'update_item'       => __( 'Update Portfolio Tag', 'portfolios' ),
    168             'add_new_item'      => __( 'Add New Portfolio Tag', 'portfolios' ),
    169             'new_item_name'     => __( 'New Portfolio Tag Name', 'portfolios' ),
    170             'menu_name'         => __( 'Portfolio Tags', 'portfolios' )
    171         ));
    172 
    173         $args = apply_filters( 'themeblvd_portfolio_tag_tax_args', array(
    174             'hierarchical'      => false,
    175             'labels'            => $labels,
    176             'show_ui'           => true,
    177             'show_admin_column' => true,
    178             'query_var'         => true,
    179             'rewrite'           => array( 'slug' => 'item-tag' ),
    180         ));
    181 
    182         register_taxonomy( 'portfolio_tag', array( 'portfolio_item' ), $args );
    183 
    184         // Better safe than sorry
     144        // Add "Portfolio Tag" taxonomy
     145        $labels = apply_filters( 'themeblvd_portfolio_tag_tax_labels', array(
     146            'name'              => __( 'Portfolio Tags', 'portfolios' ),
     147            'singular_name'     => __( 'Portfolio Tag', 'portfolios' ),
     148            'search_items'      => __( 'Search Portfolio Tags', 'portfolios' ),
     149            'all_items'         => __( 'All Portfolio Tags', 'portfolios' ),
     150            'edit_item'         => __( 'Edit Portfolio Tag', 'portfolios' ),
     151            'update_item'       => __( 'Update Portfolio Tag', 'portfolios' ),
     152            'add_new_item'      => __( 'Add New Portfolio Tag', 'portfolios' ),
     153            'new_item_name'     => __( 'New Portfolio Tag Name', 'portfolios' ),
     154            'menu_name'         => __( 'Portfolio Tags', 'portfolios' ),
     155        ));
     156
     157        $args = apply_filters( 'themeblvd_portfolio_tag_tax_args', array(
     158            'hierarchical'      => false,
     159            'labels'            => $labels,
     160            'show_ui'           => true,
     161            'show_admin_column' => true,
     162            'query_var'         => true,
     163            'rewrite'           => array( 'slug' => 'item-tag' ),
     164        ));
     165
     166        register_taxonomy( 'portfolio_tag', array( 'portfolio_item' ), $args );
     167
    185168        register_taxonomy_for_object_type( 'portfolio_tag', 'portfolio_item' );
     169
    186170        register_taxonomy_for_object_type( 'portfolio', 'portfolio_item' );
    187171
    188      }
    189 
    190     /*--------------------------------------------*/
    191     /* Initiate Theme Blvd integration
    192     /*--------------------------------------------*/
    193 
    194     /**
    195      * Apply Theme Blvd specific actions and filters.
    196      *
    197      * @since 1.0.1
    198      */
    199     public function themeblvd_init() {
    200 
    201         if ( ! defined('TB_FRAMEWORK_VERSION') ) {
    202             return;
    203         }
    204 
    205         add_filter( 'themeblvd_elements', array( $this, 'builder_options' ) );
    206         add_filter( 'themeblvd_portfolio_module_options', array( $this, 'portfolio_module_options' ) );
    207 
    208         add_filter( 'themeblvd_posts_args', array( $this, 'query_args' ), 9, 2 );
    209         add_filter( 'themeblvd_post_slider_args', array( $this, 'query_args' ), 9, 2 );
    210         add_filter( 'themeblvd_slider_auto_args', array( $this, 'query_args' ), 9, 2 );
    211         add_filter( 'themeblvd_portfolio_module_args', array( $this, 'query_args' ), 9, 2 );
    212 
    213         add_filter( 'themeblvd_template_list_query', array( $this, 'page_template_query' ), 10, 3 );
    214         add_filter( 'themeblvd_template_grid_query', array( $this, 'page_template_query' ), 10, 3 );
    215 
    216         add_filter( 'themeblvd_post_meta', array( $this, 'post_meta' ) );
    217         add_filter( 'themeblvd_banner_meta', array( $this, 'post_meta' ) ); // only in framework 2.5+
    218         add_filter( 'themeblvd_meta_options_tb_post_options', array( $this, 'post_meta_options' ) );
    219         add_filter( 'themeblvd_pto_options', array( $this, 'pto_options' ) );
    220 
    221         if ( version_compare(TB_FRAMEWORK_VERSION, '2.5.0', '>=') ) { // requires framework 2.5+
    222             add_filter( 'themeblvd_formatted_options', array( $this, 'theme_options' ) );
    223             add_filter( 'themeblvd_theme_mode_override', array( $this, 'archive_mode' ), 10, 2 );
    224             add_action( 'themeblvd_archive_info', array( $this, 'archive_info' ) );
    225             add_filter( 'themeblvd_sidebar_layout', array( $this, 'sidebar_layout' ) );
    226         }
    227 
    228         // add_filter( 'themeblvd_locals', array( $this, 'locals' ) );
    229         add_filter( 'themeblvd_pre_breadcrumb_parts', array( $this, 'breadcrumbs' ), 10, 2 );
    230         add_filter( 'the_tags', array( $this, 'tags' ), 10, 4 );
    231 
    232         // @deprecated
    233         if ( version_compare(TB_FRAMEWORK_VERSION, '2.5.0', '<') ) {
    234             add_filter( 'themeblvd_template_parts', array( $this, 'template_parts' ) );
    235             add_filter( 'themeblvd_meta', array( $this, 'meta' ), 10, 6 );
    236         }
    237 
    238     }
    239 
    240     /*--------------------------------------------*/
    241     /* Theme Blvd Layout Builder Integration
    242     /*--------------------------------------------*/
    243 
    244     /**
    245      * Modify options for posts lists and grids in
    246      * the Theme Blvd Layout Builder.
    247      *
    248      * @since 1.0.0
    249      */
    250     public function builder_options( $elements ) {
    251 
    252         // The keys for the elements that we're modifying
    253         // the options for.
    254         $items = $this->get_builder_items();
    255 
    256         // Loop through the items we're going to modify
    257         // and edit them within the overall $elements array.
    258         foreach ( $items as $item ) {
    259 
    260             if ( ! isset( $elements[$item]['options'] ) ) {
    261                 continue;
    262             }
    263 
    264             $options = $elements[$item]['options'];
    265 
    266             // Add additional sources the user can pull
    267             // posts from.
    268             if ( isset( $options['source']['options'] ) ) {
    269                 $options['source']['options'] = $this->set_sorce( $options['source']['options'] );
    270             }
    271 
    272             // Add additional filering options
    273             if ( isset( $options['filter']['options'] ) ) {
    274                 $options['filter']['options']['portfolio'] = __('Filtered by portfolio', 'portfolios');
    275                 $options['filter']['options']['portfolio_tag'] = __('Filtered by portfolio tag', 'portfolios');
    276             }
    277 
    278             // Set triggers on other options so they
    279             // appear when the user selects the source.
    280             $options = $this->set_triggers( $options );
    281 
    282             // Add options
    283             $options = $this->set_options( $options );
    284 
    285             // Finalize and put back options
    286             $elements[$item]['options'] = $options;
    287 
    288         }
    289 
    290         return $elements;
    291     }
    292 
    293     /**
    294      * Add portfolio options to Portfolio Module,
    295      * only exists in some themes, like Arcadian.
    296      *
    297      * @since 1.0.0
    298      */
    299     public function portfolio_module_options( $options ) {
    300 
    301         // Add additional sources the user can pull
    302         // posts from.
    303         if ( isset( $options['source']['options'] ) ) {
    304             $options['source']['options'] = $this->set_sorce( $options['source']['options'] );
    305         }
    306 
    307         // Set triggers on other options so they
    308         // appear when the user selects the source.
    309         $options = $this->set_triggers( $options );
    310 
    311         // Add options
    312         $options = $this->set_options( $options );
    313 
    314         return $options;
    315 
    316     }
    317 
    318     /**
    319      * Take the selections for the source of a Builder
    320      * elements and add in the Portfolios sources.
    321      *
    322      * @since 1.0.0
    323      */
    324     public function get_builder_items() {
    325          $items = array(
    326             'mini_post_list',
    327             'mini_post_grid',
    328             'post_grid',
    329             'post_list',
    330             'post_showcase',
    331             'post_slider',
    332             'post_slider_popout',
    333 
    334             // @deprecated
    335             'post_grid_paginated',
    336             'post_grid_slider',
    337             'post_list_paginated',
    338             'post_list_slider'
    339         );
    340         return apply_filters( 'themeblvd_portfolios_builder_items', $items );
    341     }
    342 
    343     /**
    344      * Take the selections for the source of a Builder
    345      * elements and add in the Portfolios sources.
    346      *
    347      * @since 1.0.0
    348      */
    349     public function set_sorce( $selections ) {
    350 
    351         if ( ! is_array( $selections ) || count( $selections ) < 0 ) {
    352             return array();
    353         }
    354 
    355         $new_selections = array();
    356 
    357         foreach ( $selections as $key => $value ) {
    358 
    359             $new_selections[$key] = $value;
    360 
    361             if ( $key == 'tag' ) {
    362                 $new_selections['portfolio'] = __('Portfolio', 'portfolios');
    363                 $new_selections['portfolio-tag'] = __('Portfolio Tag', 'portfolios');
    364             }
    365 
    366         }
    367 
    368         return $new_selections;
    369     }
    370 
    371     /**
    372      * Take the selections for the source of a Builder
    373      * elements and add in the Portfolios sources.
    374      *
    375      * @since 1.0.0
    376      */
    377     public function set_triggers( $options ) {
    378 
    379         foreach ( $options as $key => $option ) {
    380 
    381             if( ! isset( $option['class'] ) ) {
    382                 continue;
    383             }
    384 
    385             if( strpos( $option['class'], 'receiver-category receiver-tag' ) === false ) {
    386                 continue;
    387             }
    388 
    389             $options[$key]['class'] .= ' receiver-portfolio receiver-portfolio-tag';
    390 
    391         }
    392 
    393         return $options;
    394     }
    395 
    396     /**
    397      * Add options to select portfolios and insert
    398      * portfolio tag.
    399      *
    400      * @since 1.0.0
    401      */
    402     public function set_options( $options ) {
    403 
    404         $new_options = array();
    405 
    406         foreach ( $options as $key => $option ) {
    407 
    408             $new_options[$key] = $option;
    409 
    410             // Insert new options after the "Tag" option
    411             if ( $key == 'tag' ) {
    412 
    413                 // Add option to select portfolios
    414                 $new_options['portfolio'] = array(
    415                     'id'        => 'portfolio',
    416                     'name'      => __( 'Portfolio', 'portfolios' ),
    417                     'desc'      => __( 'Enter a portfolio slug, or a comma separated list of portfolio slugs, to pull posts from. Leave blank to pull all portfolio items.', 'portfolios' ),
    418                     'type'      => 'text',
    419                     'class'     => 'hide receiver receiver-portfolio'
    420                 );
    421 
    422                 // Add option to input portfolio tag
    423                 $new_options['portfolio_tag'] = array(
    424                     'id'        => 'portfolio_tag',
    425                     'name'      => __( 'Portfolio Tag', 'portfolios' ),
    426                     'desc'      => __( 'Enter a single portfolio tag, or a comma separated list of portfolio tags, to pull posts from.', 'portfolios' ),
    427                     'type'      => 'text',
    428                     'class'     => 'hide receiver receiver-portfolio-tag'
    429                 );
    430 
    431             }
    432 
    433         }
    434 
    435         return $new_options;
    436 
    437     }
    438 
    439     /*--------------------------------------------*/
    440     /* Theme Blvd "Post Options" Integration
    441     /*--------------------------------------------*/
    442 
    443     /**
    444      * Add "Post Options" to Portfolio Item custom
    445      * post type.
    446      *
    447      * @since 1.0.0
    448      */
    449     public function post_meta( $setup ) {
    450         $setup['config']['page'][] = 'portfolio_item';
    451         return $setup;
    452     }
    453 
    454     /**
    455      * Adjustments to options in "Post Options" meta box.
    456      *
    457      * @since 1.0.0
    458      */
    459     public function post_meta_options( $options ) {
    460 
    461         // Meta data hidden by default on single posts
    462         $options['tb_meta']['std'] = 'hide';
    463 
    464         return $options;
    465 
    466     }
    467 
    468     /**
    469      * Adjustments to options in Theme Blvd "Post Template
    470      * Options" plugin.
    471      *
    472      * @since 1.0.0
    473      */
    474     public function pto_options( $options ) {
    475 
    476         $new_options = array();
    477 
    478         foreach ( $options as $key => $option ) {
    479 
    480             $new_options[$key] = $option;
    481 
    482             // Add our custom options after tag
    483             if ( $key == 'tag' ) {
    484 
    485                 $new_options['portfolio'] = array(
    486                     'id'        => 'portfolio',
    487                     'name'      => __( 'portfolio', 'portfolios' ),
    488                     'desc'      => __( 'Portfolio slugs to include.<br>Ex: my-portfolio<br>Ex: my-portfolio-1, my-portfolio-2', 'portfolios' ),
    489                     'type'      => 'text'
    490                 );
    491 
    492                 $new_options['portfolio_tag'] = array(
    493                     'id'        => 'portfolio_tag',
    494                     'name'      => __( 'portfolio_tag', 'portfolios' ),
    495                     'desc'      => __( 'Portfolio tags to include.<br>Ex: my-tag<br>Ex: my-tag-1, my-tag-2', 'portfolios' ),
    496                     'type'      => 'text'
    497                 );
    498 
    499             }
    500 
    501         }
    502 
    503         return $new_options;
    504 
    505     }
    506 
    507     /*--------------------------------------------*/
    508     /* Theme Blvd "Theme Options" Integration
    509     /*--------------------------------------------*/
    510 
    511     /**
    512      * Adjustments to Theme Options page. Add "Portfolio"
    513      * section just after "Archives" section. Only applies
    514      * to framework 2.5+ themes.
    515      *
    516      * @since 1.1.0
    517      */
    518     public function theme_options( $options ) {
    519 
    520         $new_options = array();
    521 
    522         foreach ( $options as $key => $option ) {
    523 
    524             $new_options[$key] = $option;
    525 
    526             if ( $key == 'end_section_archives' ) {
    527 
    528                 $new_options['section_start_portfolios'] = array(
    529                     'name' => __('Portfolios', 'portfolios'),
    530                     'type' => 'section_start'
    531                 );
    532 
    533                 $new_options['portfolio_mode'] = array(
    534                     'name'      => __('Post Display', 'portfolios'),
    535                     'desc'      => __('When viewing a portfolio item, portfolio, or portfolio tag archive, how do you want the posts displayed?', 'portfolios'),
    536                     'id'        => 'portfolio_mode',
    537                     'std'       => 'showcase',
    538                     'type'      => 'select',
    539                     'options'   => array(
    540                         'blog'      => __('Blog', 'portfolios'),
    541                         'list'      => __('List', 'portfolios'),
    542                         'grid'      => __('Grid', 'portfolios'),
    543                         'showcase'  => __('Showcase', 'portfolios'),
    544                     )
    545                 );
    546 
    547                 $new_options['portfolio_info'] = array(
    548                     'name'      => __('Portfolio Info Boxes', 'portfolios'),
    549                     'desc'      => __('When viewing a portfolio archive, would you like to show an info box at the top that contains the title and description of the current portfolio?', 'portfolios'),
    550                     'id'        => 'portfolio_info',
    551                     'std'       => 'show',
    552                     'type'      => 'select',
    553                     'options'   => array(
    554                         'show' => __('Yes, show info boxes', 'portfolios'),
    555                         'hide' => __('No, hide info boxes', 'portfolios')
    556                     )
    557                 );
    558 
    559                 $new_options['portfolio_tag_info'] = array(
    560                     'name'      => __('Portfolio Tag Info Boxes', 'portfolios'),
    561                     'desc'      => __('When viewing a portfolio tag archive, would you like to show an info box at the top that contains the title and description of the current portfolio?', 'portfolios'),
    562                     'id'        => 'portfolio_tag_info',
    563                     'std'       => 'hide',
    564                     'type'      => 'select',
    565                     'options'   => array(
    566                         'show' => __('Yes, show info boxes', 'portfolios'),
    567                         'hide' => __('No, hide info boxes', 'portfolios')
    568                     )
    569                 );
    570 
    571                 $new_options['section_end_portfolios'] = array(
    572                     'type' => 'section_end'
    573                 );
    574 
    575             } else if ( $key == 'archive_sidebar_layout' ) {
    576 
    577                 $new_options['portfolio_sidebar_layout'] = array(
    578                     'name'      => __( 'Portfolios', 'themeblvd' ),
    579                     'desc'      => __( 'When viewing a portfolio or portfolio tag archive of posts, what do you want to use for the sidebar layout?', 'themeblvd' ),
    580                     'id'        => 'portfolio_sidebar_layout',
    581                     'std'       => 'full_width',
    582                     'type'      => 'images',
    583                     'options'   => $new_options[$key]['options'],
    584                     'img_width' => '45'
    585                 );
    586 
    587             }
    588 
    589         }
    590 
    591         return $new_options;
    592     }
    593 
    594     /**
    595      * Change post display mode for portfolio and portfolio
    596      * tag archive pages, based on theme options additions.
    597      *
    598      * @since 1.1.0
    599      */
    600     public function archive_mode( $mode, $q ) {
    601 
    602         if ( $q->is_post_type_archive('portfolio_item') || $q->is_tax('portfolio') || $q->is_tax('portfolio_tag') ) {
    603 
    604             $mode = themeblvd_get_option('portfolio_mode', null, 'showcase');
    605 
    606             if ( ! $mode || $mode == 'default' ) {
    607                 $mode = themeblvd_get_option('archive_mode', null, 'blog');
    608             }
    609 
    610         }
    611 
    612         return $mode;
    613     }
    614 
    615     /**
    616      * Display info box at the top of portfolio and portfolio
    617      * tag archive pages, based on theme options additions.
    618      *
    619      * @since 1.1.0
    620      */
    621     public function archive_info() {
    622 
    623         if ( ( is_tax('portfolio') && themeblvd_get_option('portfolio_info') == 'show' ) || ( is_tax('portfolio_tag') && themeblvd_get_option('portfolio_tag_info') == 'show' ) ) {
    624             themeblvd_tax_info();
    625         }
    626 
    627     }
    628 
    629     /**
    630      * Display info box at the top of portfolio and portfolio
    631      * tag archive pages, based on theme options additions.
    632      *
    633      * @since 1.1.2
    634      */
    635     public function sidebar_layout( $layout ) {
    636 
    637         if ( is_tax('portfolio') || is_tax('portfolio_tag') ) {
    638 
    639             $layout = themeblvd_get_option('portfolio_sidebar_layout', null, 'full_width');
    640 
    641             if ( $layout == 'default' ) {
    642                 $layout = themeblvd_get_option('sidebar_layout', null, apply_filters( 'themeblvd_default_sidebar_layout', 'sidebar_right') );
    643             }
    644         }
    645 
    646         return $layout;
    647     }
    648 
    649     /*--------------------------------------------*/
    650     /* Theme Blvd Query Modfications
    651     /*--------------------------------------------*/
    652 
    653     /**
    654      * Allow "portfolio" and "portfolio_tag" custom
    655      * fields with Post List and Post Grid page templates.
    656      *
    657      * @since 1.0.0
    658      */
    659     public function page_template_query( $query, $custom, $post_id ) {
    660 
    661         if ( ! $custom ) {
    662 
    663             $portfolio = get_post_meta( $post_id, 'portfolio', true );
    664             $portfolio_tag = get_post_meta( $post_id, 'portfolio_tag', true );
    665 
    666             if ( $portfolio || $portfolio_tag ) {
    667 
    668                 unset( $query['categories'], $query['cat'], $query['category_name'] );
    669                 unset( $query['tag'] );
    670 
    671                 $query['post_type'] = 'portfolio_item';
    672 
    673                 if ( $portfolio ) {
    674 
    675                     $portfolio = str_replace(' ', '', $portfolio );
    676                     $portfolio = explode( ',', $portfolio );
    677 
    678                     $query['tax_query'][] = array(
    679                         'taxonomy'  => 'portfolio',
    680                         'field'     => 'slug',
    681                         'terms'     => $portfolio
    682                     );
    683                 }
    684 
    685                 if ( $portfolio_tag ) {
    686 
    687                     $portfolio_tag = str_replace(' ', '', $portfolio_tag );
    688                     $portfolio_tag = explode( ',', $portfolio_tag );
    689 
    690                     $query['tax_query'][] = array(
    691                         'taxonomy'  => 'portfolio_tag',
    692                         'field'     => 'slug',
    693                         'terms'     => $portfolio_tag
    694                     );
    695                 }
    696             }
    697         }
    698 
    699         return $query;
    700 
    701     }
    702 
    703     /**
    704      * On the frontend of the site, filter the query
    705      * args for items that query posts, for our portfolio
    706      * options.
    707      *
    708      * @since 1.0.0
    709      */
    710     public function query_args( $query, $args ) {
    711 
    712         $source = '';
    713 
    714         if ( ! empty( $args['source'] ) ) {
    715             $source = $args['source'];
    716         }
    717 
    718         if ( $source == 'portfolio' || $source == 'portfolio-tag' || ! $source ) {
    719 
    720             // Portfolios
    721             if ( $source == 'portfolio' || ( ! $source && ! empty( $args['portfolio'] ) ) ) {
    722 
    723                 $query['post_type'] = 'portfolio_item';
    724 
    725                 if ( ! empty( $args['portfolio'] ) ) {
    726 
    727                     $portfolios = str_replace(' ', '', $args['portfolio'] );
    728                     $portfolios = explode( ',', $portfolios );
    729 
    730                     $query['tax_query'][] = array(
    731                         'taxonomy'  => 'portfolio',
    732                         'field'     => 'slug',
    733                         'terms'     => $portfolios
    734                     );
    735 
    736                 }
    737 
    738                 // Remove standard post taxomonies
    739                 unset( $query['categories'], $query['cat'], $query['category_name'] );
    740                 unset( $query['tag'] );
    741 
    742             }
    743 
    744             // Portfolio Tags
    745             if ( $source == 'portfolio-tag' || ( ! $source && ! empty( $args['portfolio_tag'] ) ) ) {
    746 
    747                 $query['post_type'] = 'portfolio_item';
    748 
    749                 if ( ! empty( $args['portfolio_tag'] ) ) {
    750 
    751                     $tags = str_replace(' ', '', $args['portfolio_tag'] );
    752                     $tags = explode( ',', $tags );
    753 
    754                     $query['tax_query'][] = array(
    755                         'taxonomy'  => 'portfolio_tag',
    756                         'field'     => 'slug',
    757                         'terms'     => $tags
    758                     );
    759 
    760                 }
    761 
    762                 // Remove standard post taxomonies
    763                 unset( $query['categories'], $query['cat'], $query['category_name'] );
    764                 unset( $query['tag'] );
    765             }
    766 
    767         }
    768 
    769         return $query;
    770     }
    771 
    772     /*--------------------------------------------*/
    773     /* Theme Blvd Frontend Integration
    774     /*--------------------------------------------*/
    775 
    776     /**
    777      * Frontend text strings
    778      *
    779      * @since 1.0.2
    780      */
    781     public function locals( $locals ) {
    782         // ... @TODO Maybe do later if things get more complicated
    783         return $locals;
    784     }
    785 
    786     /**
    787      * Breadcrumbs
    788      *
    789      * @since 1.0.0
    790      */
    791     public function breadcrumbs( $parts, $atts ) {
    792 
    793         global $wp_query;
    794 
    795         // Single Portfolio Items
    796         if ( is_single() && 'portfolio_item' == get_post_type() ) {
    797 
    798             $parts = array(); // reset it
    799 
    800             // Portfolio taxonomy tree
    801             $portfolio = get_the_terms( get_the_id(), 'portfolio' );
    802 
    803             if ( $portfolio ) {
    804                 $portfolio = reset( $portfolio );
    805                 $parents = themeblvd_get_term_parents( $portfolio->term_id, 'portfolio' );
    806                 $parts = array_merge( $parts, $parents );
    807             }
    808 
    809             // Single post title
    810             $parts[] = array(
    811                 'link'  => '',
    812                 'text'  => get_the_title(),
    813                 'type'  => 'single'
    814             );
    815 
    816         }
    817 
    818         // Portfolios
    819         if ( is_tax( 'portfolio' ) ) {
    820 
    821             // Parent portfolios
    822             $portfolio_obj = $wp_query->get_queried_object();
    823             $current_portfolio = $portfolio_obj->term_id;
    824             $current_portfolio = get_term( $current_portfolio, 'portfolio' );
    825 
    826             if ( $current_portfolio->parent && ( $current_portfolio->parent != $current_portfolio->term_id ) ) {
    827                 $parents = themeblvd_get_term_parents( $current_portfolio->parent, 'portfolio' );
    828                 $parts = array_merge( $parts, $parents );
    829             }
    830 
    831             // Add current portfolio
    832             $parts[] = array(
    833                 'link'  => '',
    834                 'text'  => $current_portfolio->name,
    835                 'type'  => 'category'
    836             );
    837 
    838 
    839         }
    840 
    841         // Portfolio Tags
    842         if ( is_tax( 'portfolio_tag' ) ) {
    843             $parts[] = array(
    844                 'link'  => '',
    845                 'text'  => single_term_title( '', false ),
    846                 'type'  => 'tag'
    847             );
    848         }
    849 
    850         return $parts;
    851     }
    852 
    853     /**
    854      * Tags
    855      *
    856      * @since 1.0.0
    857      */
    858     public function tags( $tags, $before, $sep, $after ) {
    859 
    860         if ( 'portfolio_item' == get_post_type() ) {
    861             $tags = get_the_term_list( get_the_id(), 'portfolio_tag', $before, $sep, $after );
    862         }
    863 
    864         return $tags;
    865     }
    866 
    867     /**
    868      * Sub post meta
    869      *
    870      * @since 1.1.0
    871      */
    872     public function sub_meta() {
    873 
    874         $taxos = apply_filters( 'themeblvd_portfolios_sub_meta_taxos', array( 'portfolio', 'portfolio_tag' ) );
    875 
    876         foreach ( $taxos as $tax ) {
    877 
    878             $terms = get_the_terms( get_the_ID(), $tax );
    879 
    880             if ( $terms ) {
    881 
    882                 $tax_obj = get_taxonomy($tax);
    883 
    884                 printf( '<div class="tb-%1$s %1$s">', $tax );
    885                 printf( '<span class="title">%s:</span>', $tax_obj->labels->name );
    886 
    887                 $count = count($terms);
    888                 $i = 1;
    889 
    890                 foreach ( $terms as $term ) {
    891                     printf( '<a href="%1$s" title="%2$s">%2$s</a>', get_term_link( $term->term_id, $tax ), $term->name );
    892                     if ( $i < $count ) {
    893                         echo ', ';
    894                     }
    895                     $i++;
    896                 }
    897 
    898                 echo '</div>';
    899             }
    900         }
    901 
    902     }
    903 
    904     /**
    905      * Post Meta
    906      *
    907      * @since 1.0.0
    908      */
    909     public function meta( $output, $time, $author, $category, $comments, $sep ) {
    910 
    911         if ( get_post_type() == 'portfolio_item' ) {
    912 
    913             if ( $category ) {
    914                 $output = str_replace( $category, '', $output );
    915             }
    916 
    917             $portfolio = get_the_term_list( get_the_id(), 'portfolio', '<span class="category"><i class="icon-reorder fa fa-bars"></i> ', ', ', '</span>' ); // "icon-reorder" class for older themes
    918 
    919             if ( $portfolio ) {
    920                 $output = str_replace( $author, $author.$sep.$portfolio, $output );
    921             }
    922 
    923         }
    924 
    925         return $output;
    926     }
    927 
    928     /**
    929      * Adjust the template part used for archives
    930      * of portfolios and portfolio tags.
    931      *
    932      * @since 1.0.0
    933      */
    934     public function template_parts( $parts ) {
    935 
    936         // Point theme to content-grid.php and
    937         // trigger "grid" mode in framework 2.3+
    938         if ( is_tax( 'portfolio' ) || is_tax( 'portfolio_tag' ) ) {
    939             $parts['archive'] = 'grid';
    940         }
    941 
    942         return $parts;
    943 
    944     }
     172    }
     173
     174    /*--------------------------------------------*/
     175    /* Initiate Theme Blvd integration
     176    /*--------------------------------------------*/
     177
     178    /**
     179     * Apply Theme Blvd specific actions and filters.
     180     *
     181     * @since 1.0.1
     182     */
     183    public function themeblvd_init() {
     184
     185        if ( ! defined('TB_FRAMEWORK_VERSION') ) {
     186            return;
     187        }
     188
     189        add_filter( 'themeblvd_elements', array( $this, 'builder_options' ) );
     190        add_filter( 'themeblvd_portfolio_module_options', array( $this, 'portfolio_module_options' ) );
     191
     192        add_filter( 'themeblvd_posts_args', array( $this, 'query_args' ), 9, 2 );
     193        add_filter( 'themeblvd_post_slider_args', array( $this, 'query_args' ), 9, 2 );
     194        add_filter( 'themeblvd_slider_auto_args', array( $this, 'query_args' ), 9, 2 );
     195        add_filter( 'themeblvd_portfolio_module_args', array( $this, 'query_args' ), 9, 2 );
     196
     197        add_filter( 'themeblvd_template_list_query', array( $this, 'page_template_query' ), 10, 3 );
     198        add_filter( 'themeblvd_template_grid_query', array( $this, 'page_template_query' ), 10, 3 );
     199
     200        add_filter( 'themeblvd_post_meta', array( $this, 'post_meta' ) );
     201        add_filter( 'themeblvd_banner_meta', array( $this, 'post_meta' ) ); // only in framework 2.5+
     202        add_filter( 'themeblvd_meta_options_tb_post_options', array( $this, 'post_meta_options' ) );
     203        add_filter( 'themeblvd_pto_options', array( $this, 'pto_options' ) );
     204
     205        if ( version_compare(TB_FRAMEWORK_VERSION, '2.5.0', '>=') ) { // requires framework 2.5+
     206            add_filter( 'themeblvd_formatted_options', array( $this, 'theme_options' ) );
     207            add_filter( 'themeblvd_theme_mode_override', array( $this, 'archive_mode' ), 10, 2 );
     208            add_action( 'themeblvd_archive_info', array( $this, 'archive_info' ) );
     209            add_filter( 'themeblvd_sidebar_layout', array( $this, 'sidebar_layout' ) );
     210        }
     211
     212        // add_filter( 'themeblvd_locals', array( $this, 'locals' ) );
     213        add_filter( 'themeblvd_pre_breadcrumb_parts', array( $this, 'breadcrumbs' ), 10, 2 );
     214        add_filter( 'the_tags', array( $this, 'tags' ), 10, 4 );
     215
     216        // @deprecated
     217        if ( version_compare(TB_FRAMEWORK_VERSION, '2.5.0', '<') ) {
     218            add_filter( 'themeblvd_template_parts', array( $this, 'template_parts' ) );
     219            add_filter( 'themeblvd_meta', array( $this, 'meta' ), 10, 6 );
     220        }
     221
     222    }
     223
     224    /*--------------------------------------------*/
     225    /* Theme Blvd Layout Builder Integration
     226    /*--------------------------------------------*/
     227
     228    /**
     229     * Modify options for posts lists and grids in
     230     * the Theme Blvd Layout Builder.
     231     *
     232     * @since 1.0.0
     233     */
     234    public function builder_options( $elements ) {
     235
     236        // The keys for the elements that we're modifying
     237        // the options for.
     238        $items = $this->get_builder_items();
     239
     240        // Loop through the items we're going to modify
     241        // and edit them within the overall $elements array.
     242        foreach ( $items as $item ) {
     243
     244        if ( ! isset( $elements[$item]['options'] ) ) {
     245            continue;
     246        }
     247
     248        $options = $elements[$item]['options'];
     249
     250        // Add additional sources the user can pull
     251        // posts from.
     252        if ( isset( $options['source']['options'] ) ) {
     253            $options['source']['options'] = $this->set_sorce( $options['source']['options'] );
     254        }
     255
     256        // Add additional filering options
     257        if ( isset( $options['filter']['options'] ) ) {
     258            $options['filter']['options']['portfolio'] = __( 'Filtered by portfolio', 'portfolios' );
     259            $options['filter']['options']['portfolio_tag'] = __( 'Filtered by portfolio tag', 'portfolios' );
     260        }
     261
     262        // Set triggers on other options so they
     263        // appear when the user selects the source.
     264        $options = $this->set_triggers( $options );
     265
     266        // Add options
     267        $options = $this->set_options( $options );
     268
     269        // Finalize and put back options
     270        $elements[$item]['options'] = $options;
     271
     272        }
     273
     274        return $elements;
     275    }
     276
     277    /**
     278     * Add portfolio options to Portfolio Module,
     279     * only exists in some themes, like Arcadian.
     280     *
     281     * @since 1.0.0
     282     */
     283    public function portfolio_module_options( $options ) {
     284
     285        // Add additional sources the user can pull
     286        // posts from.
     287        if ( isset( $options['source']['options'] ) ) {
     288            $options['source']['options'] = $this->set_sorce( $options['source']['options'] );
     289        }
     290
     291        // Set triggers on other options so they
     292        // appear when the user selects the source.
     293        $options = $this->set_triggers( $options );
     294
     295        // Add options
     296        $options = $this->set_options( $options );
     297
     298        return $options;
     299
     300    }
     301
     302    /**
     303     * Take the selections for the source of a Builder
     304     * elements and add in the Portfolios sources.
     305     *
     306     * @since 1.0.0
     307     */
     308    public function get_builder_items() {
     309
     310        $items = array(
     311            'mini_post_list',
     312            'mini_post_grid',
     313            'post_grid',
     314            'post_list',
     315            'post_showcase',
     316            'post_slider',
     317            'post_slider_popout',
     318
     319            // @deprecated
     320            'post_grid_paginated',
     321            'post_grid_slider',
     322            'post_list_paginated',
     323            'post_list_slider',
     324        );
     325
     326        return apply_filters( 'themeblvd_portfolios_builder_items', $items );
     327    }
     328
     329    /**
     330     * Take the selections for the source of a Builder
     331     * elements and add in the Portfolios sources.
     332     *
     333     * @since 1.0.0
     334     */
     335    public function set_sorce( $selections ) {
     336
     337        if ( ! is_array( $selections ) || count( $selections ) < 0 ) {
     338            return array();
     339        }
     340
     341        $new_selections = array();
     342
     343        foreach ( $selections as $key => $value ) {
     344
     345            $new_selections[$key] = $value;
     346
     347            if ( $key == 'tag' ) {
     348                $new_selections['portfolio'] = __( 'Portfolio', 'portfolios' );
     349                $new_selections['portfolio-tag'] = __( 'Portfolio Tag', 'portfolios' );
     350            }
     351
     352        }
     353
     354        return $new_selections;
     355    }
     356
     357    /**
     358     * Take the selections for the source of a Builder
     359     * elements and add in the Portfolios sources.
     360     *
     361     * @since 1.0.0
     362     */
     363    public function set_triggers( $options ) {
     364
     365        foreach ( $options as $key => $option ) {
     366
     367            if( ! isset( $option['class'] ) ) {
     368                continue;
     369            }
     370
     371            if( strpos( $option['class'], 'receiver-category receiver-tag' ) === false ) {
     372                continue;
     373            }
     374
     375            $options[$key]['class'] .= ' receiver-portfolio receiver-portfolio-tag';
     376
     377        }
     378
     379        return $options;
     380    }
     381
     382    /**
     383     * Add options to select portfolios and insert
     384     * portfolio tag.
     385     *
     386     * @since 1.0.0
     387     */
     388    public function set_options( $options ) {
     389
     390        $new_options = array();
     391
     392        foreach ( $options as $key => $option ) {
     393
     394            $new_options[ $key ] = $option;
     395
     396            // Insert new options after the "Tag" option
     397            if ( $key == 'tag' ) {
     398
     399                // Add option to select portfolios
     400                $new_options['portfolio'] = array(
     401                    'id'    => 'portfolio',
     402                    'name'  => __( 'Portfolio', 'portfolios' ),
     403                    'desc'  => __( 'Enter a portfolio slug, or a comma separated list of portfolio slugs, to pull posts from. Leave blank to pull all portfolio items.', 'portfolios' ),
     404                    'type'  => 'text',
     405                    'class' => 'hide receiver receiver-portfolio',
     406                );
     407
     408                // Add option to input portfolio tag
     409                $new_options['portfolio_tag'] = array(
     410                    'id'    => 'portfolio_tag',
     411                    'name'  => __( 'Portfolio Tag', 'portfolios' ),
     412                    'desc'  => __( 'Enter a single portfolio tag, or a comma separated list of portfolio tags, to pull posts from.', 'portfolios' ),
     413                    'type'  => 'text',
     414                    'class' => 'hide receiver receiver-portfolio-tag',
     415                );
     416
     417            }
     418
     419        }
     420
     421        return $new_options;
     422
     423    }
     424
     425    /*--------------------------------------------*/
     426    /* Theme Blvd "Post Options" Integration
     427    /*--------------------------------------------*/
     428
     429    /**
     430     * Add "Post Options" to Portfolio Item custom
     431     * post type.
     432     *
     433     * @since 1.0.0
     434     */
     435    public function post_meta( $setup ) {
     436        $setup['config']['page'][] = 'portfolio_item';
     437        return $setup;
     438    }
     439
     440    /**
     441     * Adjustments to options in "Post Options" meta box.
     442     *
     443     * @since 1.0.0
     444     */
     445    public function post_meta_options( $options ) {
     446
     447        // Meta data hidden by default on single posts
     448        $options['tb_meta']['std'] = 'hide';
     449
     450        return $options;
     451
     452    }
     453
     454    /**
     455     * Adjustments to options in Theme Blvd "Post Template
     456     * Options" plugin.
     457     *
     458     * @since 1.0.0
     459     */
     460    public function pto_options( $options ) {
     461
     462        $new_options = array();
     463
     464        foreach ( $options as $key => $option ) {
     465
     466            $new_options[ $key ] = $option;
     467
     468            // Add our custom options after tag
     469            if ( $key == 'tag' ) {
     470
     471                $new_options['portfolio'] = array(
     472                    'id'   => 'portfolio',
     473                    'name' => __( 'portfolio', 'portfolios' ),
     474                    'desc' => __( 'Portfolio slugs to include.<br>Ex: my-portfolio<br>Ex: my-portfolio-1, my-portfolio-2', 'portfolios' ),
     475                    'type' => 'text',
     476                );
     477
     478                $new_options['portfolio_tag'] = array(
     479                    'id'   => 'portfolio_tag',
     480                    'name' => __( 'portfolio_tag', 'portfolios' ),
     481                    'desc' => __( 'Portfolio tags to include.<br>Ex: my-tag<br>Ex: my-tag-1, my-tag-2', 'portfolios' ),
     482                    'type' => 'text',
     483                );
     484
     485            }
     486
     487        }
     488
     489        return $new_options;
     490
     491    }
     492
     493    /*--------------------------------------------*/
     494    /* Theme Blvd "Theme Options" Integration
     495    /*--------------------------------------------*/
     496
     497    /**
     498     * Adjustments to Theme Options page. Add "Portfolio"
     499     * section just after "Archives" section. Only applies
     500     * to framework 2.5+ themes.
     501     *
     502     * @since 1.1.0
     503     */
     504    public function theme_options( $options ) {
     505
     506        $new_options = array();
     507
     508        foreach ( $options as $key => $option ) {
     509
     510            $new_options[$key] = $option;
     511
     512            if ( $key == 'end_section_archives' ) {
     513
     514                $new_options['section_start_portfolios'] = array(
     515                    'name' => __( 'Portfolios', 'portfolios' ),
     516                    'type' => 'section_start',
     517                );
     518
     519                $new_options['portfolio_mode'] = array(
     520                    'name'    => __( 'Post Display', 'portfolios' ),
     521                    'desc'    => __( 'When viewing a portfolio item, portfolio, or portfolio tag archive, how do you want the posts displayed?', 'portfolios' ),
     522                    'id'      => 'portfolio_mode',
     523                    'std'     => 'showcase',
     524                    'type'    => 'select',
     525                    'options' => array(
     526                        'blog'     => __( 'Blog', 'portfolios' ),
     527                        'list'     => __( 'List', 'portfolios' ),
     528                        'grid'     => __( 'Grid', 'portfolios' ),
     529                        'showcase' => __( 'Showcase', 'portfolios' ),
     530                    ),
     531                );
     532
     533                $new_options['portfolio_info'] = array(
     534                    'name'    => __( 'Portfolio Info Boxes', 'portfolios' ),
     535                    'desc'    => __( 'When viewing a portfolio archive, would you like to show an info box at the top that contains the title and description of the current portfolio?', 'portfolios' ),
     536                    'id'      => 'portfolio_info',
     537                    'std'     => 'show',
     538                    'type'    => 'select',
     539                    'options' => array(
     540                        'show' => __( 'Yes, show info boxes', 'portfolios' ),
     541                        'hide' => __( 'No, hide info boxes', 'portfolios' ),
     542                    ),
     543                );
     544
     545                $new_options['portfolio_tag_info'] = array(
     546                    'name'    => __( 'Portfolio Tag Info Boxes', 'portfolios' ),
     547                    'desc'    => __( 'When viewing a portfolio tag archive, would you like to show an info box at the top that contains the title and description of the current portfolio?', 'portfolios' ),
     548                    'id'      => 'portfolio_tag_info',
     549                    'std'     => 'hide',
     550                    'type'    => 'select',
     551                    'options' => array(
     552                        'show' => __( 'Yes, show info boxes', 'portfolios' ),
     553                        'hide' => __( 'No, hide info boxes', 'portfolios' ),
     554                    ),
     555                );
     556
     557                $new_options['section_end_portfolios'] = array(
     558                    'type' => 'section_end',
     559                );
     560
     561            } else if ( $key == 'archive_sidebar_layout' ) {
     562
     563                $new_options['portfolio_sidebar_layout'] = array(
     564                    'name'      => __( 'Portfolios', 'themeblvd' ),
     565                    'desc'      => __( 'When viewing a portfolio or portfolio tag archive of posts, what do you want to use for the sidebar layout?', 'themeblvd' ),
     566                    'id'        => 'portfolio_sidebar_layout',
     567                    'std'       => 'full_width',
     568                    'type'      => 'images',
     569                    'options'   => $new_options[$key]['options'],
     570                    'img_width' => '45',
     571                );
     572
     573            }
     574
     575        }
     576
     577        return $new_options;
     578    }
     579
     580    /**
     581     * Change post display mode for portfolio and portfolio
     582     * tag archive pages, based on theme options additions.
     583     *
     584     * @since 1.1.0
     585     */
     586    public function archive_mode( $mode, $q ) {
     587
     588        if ( $q->is_post_type_archive('portfolio_item') || $q->is_tax('portfolio') || $q->is_tax('portfolio_tag') ) {
     589
     590            $mode = themeblvd_get_option('portfolio_mode', null, 'showcase');
     591
     592            if ( ! $mode || $mode == 'default' ) {
     593                $mode = themeblvd_get_option('archive_mode', null, 'blog');
     594            }
     595
     596        }
     597
     598        return $mode;
     599    }
     600
     601    /**
     602     * Display info box at the top of portfolio and portfolio
     603     * tag archive pages, based on theme options additions.
     604     *
     605     * @since 1.1.0
     606     */
     607    public function archive_info() {
     608
     609        if ( ( is_tax('portfolio') && themeblvd_get_option('portfolio_info') == 'show' ) || ( is_tax('portfolio_tag') && themeblvd_get_option('portfolio_tag_info') == 'show' ) ) {
     610            themeblvd_tax_info();
     611        }
     612
     613    }
     614
     615    /**
     616     * Display info box at the top of portfolio and portfolio
     617     * tag archive pages, based on theme options additions.
     618     *
     619     * @since 1.1.2
     620     */
     621    public function sidebar_layout( $layout ) {
     622
     623        if ( is_tax('portfolio') || is_tax('portfolio_tag') ) {
     624
     625            $layout = themeblvd_get_option('portfolio_sidebar_layout', null, 'full_width');
     626
     627            if ( $layout == 'default' ) {
     628                $layout = themeblvd_get_option('sidebar_layout', null, apply_filters( 'themeblvd_default_sidebar_layout', 'sidebar_right') );
     629            }
     630        }
     631
     632        return $layout;
     633    }
     634
     635    /*--------------------------------------------*/
     636    /* Theme Blvd Query Modfications
     637    /*--------------------------------------------*/
     638
     639    /**
     640     * Allow "portfolio" and "portfolio_tag" custom
     641     * fields with Post List and Post Grid page templates.
     642     *
     643     * @since 1.0.0
     644     */
     645    public function page_template_query( $query, $custom, $post_id ) {
     646
     647        if ( ! $custom ) {
     648
     649            $portfolio = get_post_meta( $post_id, 'portfolio', true );
     650            $portfolio_tag = get_post_meta( $post_id, 'portfolio_tag', true );
     651
     652            if ( $portfolio || $portfolio_tag ) {
     653
     654                unset( $query['categories'], $query['cat'], $query['category_name'] );
     655                unset( $query['tag'] );
     656
     657                $query['post_type'] = 'portfolio_item';
     658
     659                if ( $portfolio ) {
     660
     661                    $portfolio = str_replace(' ', '', $portfolio );
     662                    $portfolio = explode( ',', $portfolio );
     663
     664                    $query['tax_query'][] = array(
     665                        'taxonomy' => 'portfolio',
     666                        'field'    => 'slug',
     667                        'terms'    => $portfolio,
     668                    );
     669                }
     670
     671                if ( $portfolio_tag ) {
     672
     673                    $portfolio_tag = str_replace(' ', '', $portfolio_tag );
     674                    $portfolio_tag = explode( ',', $portfolio_tag );
     675
     676                    $query['tax_query'][] = array(
     677                        'taxonomy' => 'portfolio_tag',
     678                        'field'    => 'slug',
     679                        'terms'    => $portfolio_tag,
     680                    );
     681                }
     682            }
     683        }
     684
     685        return $query;
     686
     687    }
     688
     689    /**
     690     * On the frontend of the site, filter the query
     691     * args for items that query posts, for our portfolio
     692     * options.
     693     *
     694     * @since 1.0.0
     695     */
     696    public function query_args( $query, $args ) {
     697
     698        $source = '';
     699
     700        if ( ! empty( $args['source'] ) ) {
     701            $source = $args['source'];
     702        }
     703
     704        if ( $source == 'portfolio' || $source == 'portfolio-tag' || ! $source ) {
     705
     706            // Portfolios
     707            if ( $source == 'portfolio' || ( ! $source && ! empty( $args['portfolio'] ) ) ) {
     708
     709                $query['post_type'] = 'portfolio_item';
     710
     711                if ( ! empty( $args['portfolio'] ) ) {
     712
     713                    $portfolios = str_replace(' ', '', $args['portfolio'] );
     714                    $portfolios = explode( ',', $portfolios );
     715
     716                    $query['tax_query'][] = array(
     717                        'taxonomy' => 'portfolio',
     718                        'field'    => 'slug',
     719                        'terms'    => $portfolios,
     720                    );
     721
     722                }
     723
     724                // Remove standard post taxomonies
     725                unset( $query['categories'], $query['cat'], $query['category_name'] );
     726                unset( $query['tag'] );
     727
     728            }
     729
     730            // Portfolio Tags
     731            if ( $source == 'portfolio-tag' || ( ! $source && ! empty( $args['portfolio_tag'] ) ) ) {
     732
     733                $query['post_type'] = 'portfolio_item';
     734
     735                if ( ! empty( $args['portfolio_tag'] ) ) {
     736
     737                    $tags = str_replace(' ', '', $args['portfolio_tag'] );
     738                    $tags = explode( ',', $tags );
     739
     740                    $query['tax_query'][] = array(
     741                        'taxonomy'  => 'portfolio_tag',
     742                        'field'     => 'slug',
     743                        'terms'     => $tags,
     744                    );
     745
     746                }
     747
     748                // Remove standard post taxomonies
     749                unset( $query['categories'], $query['cat'], $query['category_name'] );
     750                unset( $query['tag'] );
     751            }
     752
     753        }
     754
     755        return $query;
     756    }
     757
     758    /*--------------------------------------------*/
     759    /* Theme Blvd Frontend Integration
     760    /*--------------------------------------------*/
     761
     762    /**
     763     * Frontend text strings
     764     *
     765     * @since 1.0.2
     766     */
     767    public function locals( $locals ) {
     768        // ... @TODO Maybe do later if things get more complicated
     769        return $locals;
     770    }
     771
     772    /**
     773    * Breadcrumbs
     774    *
     775    * @since 1.0.0
     776    */
     777    public function breadcrumbs( $parts, $atts ) {
     778
     779        global $wp_query;
     780
     781        // Single Portfolio Items
     782        if ( is_single() && 'portfolio_item' == get_post_type() ) {
     783
     784            $parts = array(); // reset it
     785
     786            // Portfolio taxonomy tree
     787            $portfolio = get_the_terms( get_the_id(), 'portfolio' );
     788
     789            if ( $portfolio ) {
     790                $portfolio = reset( $portfolio );
     791                $parents = themeblvd_get_term_parents( $portfolio->term_id, 'portfolio' );
     792                $parts = array_merge( $parts, $parents );
     793            }
     794
     795            // Single post title
     796            $parts[] = array(
     797                'link' => '',
     798                'text' => get_the_title(),
     799                'type' => 'single',
     800            );
     801
     802        }
     803
     804        // Portfolios
     805        if ( is_tax( 'portfolio' ) ) {
     806
     807            // Parent portfolios
     808            $portfolio_obj = $wp_query->get_queried_object();
     809            $current_portfolio = $portfolio_obj->term_id;
     810            $current_portfolio = get_term( $current_portfolio, 'portfolio' );
     811
     812            if ( $current_portfolio->parent && ( $current_portfolio->parent != $current_portfolio->term_id ) ) {
     813                $parents = themeblvd_get_term_parents( $current_portfolio->parent, 'portfolio' );
     814                $parts = array_merge( $parts, $parents );
     815            }
     816
     817            // Add current portfolio
     818            $parts[] = array(
     819                'link' => '',
     820                'text' => $current_portfolio->name,
     821                'type' => 'category',
     822            );
     823
     824
     825        }
     826
     827        // Portfolio Tags
     828        if ( is_tax( 'portfolio_tag' ) ) {
     829            $parts[] = array(
     830                'link'  => '',
     831                'text'  => single_term_title( '', false ),
     832                'type'  => 'tag',
     833            );
     834        }
     835
     836        return $parts;
     837    }
     838
     839    /**
     840     * Tags
     841     *
     842     * @since 1.0.0
     843     */
     844    public function tags( $tags, $before, $sep, $after ) {
     845
     846        if ( 'portfolio_item' == get_post_type() ) {
     847            $tags = get_the_term_list( get_the_id(), 'portfolio_tag', $before, $sep, $after );
     848        }
     849
     850        return $tags;
     851    }
     852
     853    /**
     854     * Sub post meta
     855     *
     856     * @since 1.1.0
     857     */
     858    public function sub_meta() {
     859
     860        $taxos = apply_filters( 'themeblvd_portfolios_sub_meta_taxos', array( 'portfolio', 'portfolio_tag' ) );
     861
     862        foreach ( $taxos as $tax ) {
     863
     864            $terms = get_the_terms( get_the_ID(), $tax );
     865
     866            if ( $terms ) {
     867
     868                $tax_obj = get_taxonomy($tax);
     869
     870                printf( '<div class="tb-%1$s %1$s">', $tax );
     871                printf( '<span class="title">%s:</span>', $tax_obj->labels->name );
     872
     873                $count = count($terms);
     874                $i = 1;
     875
     876                foreach ( $terms as $term ) {
     877                    printf( '<a href="%1$s" title="%2$s">%2$s</a>', get_term_link( $term->term_id, $tax ), $term->name );
     878                    if ( $i < $count ) {
     879                        echo ', ';
     880                    }
     881                    $i++;
     882                }
     883
     884                echo '</div>';
     885            }
     886        }
     887
     888    }
     889
     890    /**
     891     * Post Meta
     892     *
     893     * @since 1.0.0
     894     */
     895    public function meta( $output, $time, $author, $category, $comments, $sep ) {
     896
     897        if ( get_post_type() == 'portfolio_item' ) {
     898
     899            if ( $category ) {
     900                $output = str_replace( $category, '', $output );
     901            }
     902
     903            $portfolio = get_the_term_list( get_the_id(), 'portfolio', '<span class="category"><i class="icon-reorder fa fa-bars"></i> ', ', ', '</span>' ); // "icon-reorder" class for older themes
     904
     905            if ( $portfolio ) {
     906                $output = str_replace( $author, $author.$sep.$portfolio, $output );
     907            }
     908
     909        }
     910
     911        return $output;
     912    }
     913
     914    /**
     915     * Adjust the template part used for archives
     916     * of portfolios and portfolio tags.
     917     *
     918     * @since 1.0.0
     919     */
     920    public function template_parts( $parts ) {
     921
     922        // Point theme to content-grid.php and
     923        // trigger "grid" mode in framework 2.3+
     924        if ( is_tax( 'portfolio' ) || is_tax( 'portfolio_tag' ) ) {
     925            $parts['archive'] = 'grid';
     926        }
     927
     928        return $parts;
     929
     930    }
    945931
    946932}
     
    963949function themeblvd_portfolios_activate() {
    964950
    965     // Register CPT
    966     $portfolios = Theme_Blvd_Portfolios::get_instance();
    967     $portfolios->register();
    968 
    969     // Flush re-write rules
    970     flush_rewrite_rules();
     951    // Register CPT
     952    $portfolios = Theme_Blvd_Portfolios::get_instance();
     953    $portfolios->register();
     954
     955    // Flush re-write rules
     956    flush_rewrite_rules();
    971957
    972958}
Note: See TracChangeset for help on using the changeset viewer.