: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
* Define the internationalization functionality
* Loads and defines the internationalization files for this plugin
* so that it is ready for translation.
* @link https://themify.me/
* @subpackage Tbp/includes
* Define the internationalization functionality.
* Loads and defines the internationalization files for this plugin
* so that it is ready for translation.
* @subpackage Tbp/includes
* @author Themify <themify@themify.me>
public static $post_type = 'tbp_template';
private static $api_base = 'https://themify.me/demo/themes/builder-pro-themes/wp-json/wp/v2/tbp_template';
private static $defaults=array();
private static $Types = array();
private static $Labels=array();
public function __construct() {
'header' => __( 'Header', 'tbp' ),
'footer' => __( 'Footer', 'tbp' ),
'single' => __( 'Single', 'tbp' ),
'archive'=>__( 'Archive', 'tbp' ),
'page'=> __( 'Page','tbp' )
'general'=>__('Entire Site','tbp'),
'archive'=>__('Archives','tbp'),
'single'=>__('Singular','tbp'),
'page'=>__( 'All Pages', 'tbp' ),
'is_front'=>__( 'Homepage', 'tbp' ),
'is_404'=>__( '404 Page', 'tbp' ),
'child_of'=>__( 'Child of', 'tbp' ),
'is_date'=>__( 'Date Archive', 'tbp' ),
'is_author'=>__( 'Author Archive', 'tbp' ),
'is_search'=>__( 'Search Results', 'tbp' ),
'is_attachment'=>__( 'Media', 'tbp' ),
'shop'=> __( 'Shop Page', 'tbp' ),
'post'=>__( 'All Post', 'tbp' ),
'product'=>__( 'All Product', 'tbp' ),
'all_post'=>__( 'All Post Archives', 'tbp' ),
'all_product'=>__( 'All Product Archives', 'tbp' ),
'all'=>__( 'All Singular', 'tbp' ),
'product_cat'=>__( 'In Product Category', 'tbp' ),
'product_tag'=>__( 'In Product Tag', 'tbp' ),
'category'=>__( 'In Category', 'tbp' ),
'post_tag'=>__( 'In Tag', 'tbp' )
'all'=>__( 'All Archives', 'tbp' ),
'category'=>__( 'Categories', 'tbp' ),
'post_tag'=>__( 'Tags', 'tbp' ),
'product_cat'=>__( 'Product categories', 'tbp' ),
'product_tag'=>__( 'Product tags', 'tbp' )
if(themify_is_woocommerce_active()){
self::$Types['product_single'] = __( 'Product Single','tbp' );
self::$Types['product_archive'] = __( 'Product Archive','tbp' );
self::$Types = apply_filters('tbp_template_types', self::$Types);
add_action( 'admin_notices', array( __CLASS__, 'add_menu_tabs' ), 9 );
add_filter( 'manage_edit-' . self::$post_type . '_columns', array( __CLASS__, 'edit_columns' ) );
add_action( 'manage_' . self::$post_type . '_posts_custom_column', array( __CLASS__, 'manage_custom_column' ), 10, 2 );
add_action( 'wp_ajax_'.self::$post_type.'_saving', array( __CLASS__, 'save_form' ) );
add_action( 'wp_ajax_'.self::$post_type.'_get_item', array( __CLASS__, 'get_item_data' ) );
add_action( 'wp_ajax_'.self::$post_type.'_plupload', array( __CLASS__, 'import_templates' ) );
add_action( 'admin_init', array( __CLASS__, 'export_row' ) );
add_filter( 'handle_bulk_actions-edit-tbp_template', array( __CLASS__, 'export_row_bulk' ), 10, 3);
add_filter( 'bulk_actions-edit-tbp_template', array( __CLASS__, 'row_bulk_actions' ) );
add_action( 'pre_get_posts', array( __CLASS__, 'filter_template_query' ) );
add_filter( 'post_row_actions', array( __CLASS__, 'post_row_actions' ), 11 );
add_filter( 'themify_builder_layout_export_content', array( __CLASS__, 'filter_export_content' ), 10, 3);
add_filter( 'themify_builder_check_row_bulk_import_button', array( __CLASS__, 'check_row_bulk_import_btn' ), 10, 2);
add_action( 'themify_builder_layout_import_loop_set_data', array( __CLASS__, 'import_loop_set_data' ), 10, 3 );
add_action( 'themify_builder_layout_import_loop_set_metadata', array( __CLASS__, 'import_loop_set_metadata' ), 10, 3 );
add_filter( 'themify_builder_layout_import_type', array( __CLASS__, 'set_import_type' ), 10, 2 );
add_filter( 'themify_builder_post_types_support', array( __CLASS__, 'register_builder_post_type_metabox' ) );
add_filter( 'themify_post_types', array( __CLASS__, 'extend_post_types' ) );
add_filter( 'themify_metabox/fields/themify-meta-boxes', array( __CLASS__, 'themify_skip_post_options_metabox' ), 99, 2);
add_action( 'wp_ajax_tbp_load_data', array( __CLASS__, 'load_data' ) );
add_filter( 'views_edit-tbp_template', array( __CLASS__, 'views_edit_template' ) );
add_filter('themify_builder_post_types_support', array(__CLASS__,'exclude_post_type'));
add_action( 'rest_api_init', array( __CLASS__, 'register_rest_fields' ) );
add_filter( 'rest_tbp_template_query', array( __CLASS__, 'rest_post_type_query' ), 10, 2 );
add_action( 'admin_footer', array( __CLASS__, 'enqueue_scripts' ) );
if(is_admin() && $pagenow === 'post.php' && !empty( $_GET['post'] ) && get_post_type($_GET['post']) === self::$post_type){
add_action( 'admin_bar_menu', array( __CLASS__, 'admin_bar' ),999 );
add_filter('themify_exclude_cpt_post_options', array(__CLASS__,'exclude_post_type'));
add_action( 'add_meta_boxes', array( __CLASS__, 'add_meta_boxes' ) );
add_action( 'save_post', array( __CLASS__, 'save_post' ) );
private static function set_defaults(){
'tbp_template_name' => __( 'New Template', 'tbp'),
'tbp_template_type' => 'archive',
'tbp_associated_theme'=>'',
'tbp_template_conditions'=>array()
public static function add_menu_tabs() {
if( isset( $_GET['post_type'] ) && $_GET['post_type'] === self::$post_type && $pagenow === 'edit.php' ) {
$tabs = array_merge(array('active' => __( 'Active', 'tbp' )),self::$Types);
$current_tab = ( empty( $_GET['tab'] ) ) ? 'active' : sanitize_text_field( urldecode( $_GET['tab'] ) ); ?>
<div class="notice tbp_notice_template">
<h2 class="nav-tab-wrapper tbp_nav_tab_wrapper">
<?php foreach ( $tabs as $name => $label ):?>
<a href="<?php echo admin_url( 'edit.php?post_type=' . self::$post_type . '&tab=' . $name )?>" class="nav-tab<?php if( $current_tab === $name ):?> nav-tab-active<?php endif;?>"><?php echo $label?></a>
* Post Type Custom column.
public static function edit_columns( $columns ) {
'cb' => '<input type="checkbox" />',
'title' => __('Title', 'tbp'),
'type' => __('Type', 'tbp'),
'status' => __( 'Status', 'tbp' ),
'theme' => __( 'Theme', 'tbp' ),
'condition' => __( 'Conditions', 'tbp' ),
'author' => __( 'Author', 'tbp' ),
'date' => __('Date', 'tbp')
* Manage Post Type Custom Columns.
public static function manage_custom_column( $column, $post_id ) {
echo get_post_meta( $post_id, 'tbp_template_type', true );
echo get_post_meta( $post_id, 'tbp_associated_theme', true );
$records = Tbp_Utils::get_template_conditions( $post_id );
$type=get_post_meta( $post_id, 'tbp_template_type', true );
if($type==='product_archive'){
elseif($type==='product_single'){
if($type==='archive' || $type==='single'){
foreach( $records as $record ) {
foreach ( $record as $k=>$v ) {
if($k!=='type' && $k!=='detail'){
if(isset(self::$Labels[$v])){
if($type==='header' || $type==='footer'){
$key='_'.$record['general'];
if(isset(self::$Labels[$key][$v])){
$val=self::$Labels[$key][$v];
elseif(strpos($v,'all_')===0){
$val=ucfirst(str_replace('all_','',$v));
elseif($k==='detail' && ($record['general']==='general' || $record['general']==='all' || $record['general']==='is_404' || $record['general']==='is_front' || $record['general']==='is_search' || $record['general']==='is_date' || strpos($record['general'],'all_')===0 || (isset($record['query']) && ($record['query']==='all' || strpos($record['query'],'all_')===0)))){
$output[] = is_array( $val )?implode (', ', $val ):$val;
echo '<p>' , implode(' > ', $output ) , '</p>';
public static function post_row_actions( $actions ) {
if ( self::$post_type === $post->post_type ) {
$actions['edit'] = sprintf( '<a href="#" class="tbp_lightbox_edit" data-post-id="%d">%s</a>',
$actions['backend'] = sprintf( '<a href="%s">%s</a>', admin_url( 'post.php?post=' . $post->ID . '&action=edit' ), __('Backend', 'tbp') );
if ( isset( $actions['themify-builder'] ) ) {
unset( $actions['themify-builder'] );
$builder_link = sprintf( '<a href="%s" target="_blank">%s</a>', esc_url( get_permalink( $post->ID ) . '#builder_active' ), __('Frontend', 'tbp' ));
$actions['themify-builder'] = $builder_link;
$actions['tbp-template-export'] = sprintf( '<a href="%s">%s</a>', wp_nonce_url( admin_url( 'edit.php?post_type='.Tbp_Templates::$post_type.'&post=' . $post->ID . '&action='.Tbp_Templates::$post_type.'_export' ), 'tbp_template_export' ), __('Export', 'tbp') );
if ( isset( $actions['trash'] ) ) {
$actions['tbp-trash'] = $actions['trash'];
unset($actions['trash'], $actions['view'] );
public static function get_options() {
$themes = TBP_Utils::get_exist_themes();
$themesSelect[$t->post_name]=$t->post_title;
$post_types = Themify_Builder_Model::get_public_post_types(false);
$selectPostTypes = $post_types;
unset($themes,$selectPostTypes['product'],$selectPostTypes[self::$post_type],$selectPostTypes['tbp_theme'],$selectPostTypes['tglobal_style'],$selectPostTypes['tb_cf']);
$single_tax_arr=$archive_tax_arr = array();
foreach ( $post_types as $post_type => $label ) {
if ( $post_type !== 'post' && $post_type !== 'page' ) {
$post_type_object = get_post_type_object( $post_type );
$single_tax_arr[ $post_type ] = array(
'label'=> $post_type_object->labels->singular_name,
$post_type => sprintf( 'All %s', $post_type_object->labels->singular_name )
if ( $post_type_object->has_archive ) {
$archive_tax_arr[ $post_type ] = array(
'label'=> $post_type_object->labels->name,
'all_' . $post_type => sprintf( 'All %s Archives', $label )
$post_type_taxonomies = wp_filter_object_list( get_object_taxonomies( $post_type, 'objects' ), array(
'show_in_nav_menus' => true
if ( empty($post_type_taxonomies) || is_wp_error( $post_type_taxonomies ) ) {
foreach ( $post_type_taxonomies as $slug => $object ) {
$single_tax_arr[ $post_type ]['options'][ $slug ] = sprintf( 'In %s', $object->labels->singular_name );
if ( $post_type_object->has_archive ) {
$archive_tax_arr[ $post_type ]['options'][ $slug ] = $object->label;
$post_type_taxonomies = $post_types=null;
foreach(self::$Types as $type=>$v){
$method = 'get_options_'.$type;
$conditiions[$type] = self::$method($single_tax_arr,$archive_tax_arr);
$activeTheme=Tbp::get_active_theme()->post_name;
'id'=>'tbp_template_name',
'label' => __('Name', 'tbp'),
'id'=>'tbp_associated_theme',
'label' => __( 'Associated Theme', 'tbp' ),
'options'=>$themesSelect,
'default'=> $activeTheme,
'help' => __( 'Select the theme which you want this template to associated. Templates are used base on the activated theme.', 'tbp' )
'id' => 'tbp_template_type',
'label'=> __('Type', 'tbp'),
'options' => self::$Types
'id'=>'tbp_template_conditions',
'label'=>__('Display Conditions', 'tbp' ),
if ( '' === $activeTheme ) {
$no_activated_theme_args = array(
'id' => 'tbp_no_theme_activated',
'comment' => sprintf('<h3>%s</h3><p>%s</p>', esc_html__( 'No Theme Activated', 'tbp' ), __( "You don't have a Pro Theme activated. Please create or activate a <a href='" . admin_url('admin.php?page=tbp_theme') . "'>Pro Theme</a> First.", 'tbp' )),
'theme_page_url' => admin_url('admin.php?page='.Tbp_Themes::$post_type)
array_unshift( $args, $no_activated_theme_args );
return apply_filters( 'tbp_post_type_tbp_template_fields', $args);
private static function get_options_header(array $single,array $archive){
$singleData=self::get_options_single($single, $archive,true);
$pageData=self::get_options_page($single, $archive);
array_unshift($singleData['optgroup'],array('id'=>'page','label'=>self::$Types['page'],'options'=>$pageData));
'label'=>self::$Labels['general']
'label'=>self::$Labels['archive'],
'options'=>self::get_options_archive($single, $archive,true)
'label'=>self::$Labels['single'],
private static function get_options_footer(array $single,array $archive){
return self::get_options_header($single,$archive);
private static function get_options_single(array $single,array $archive,$isHeader=null){
'label'=>self::$Labels['_single']['all']
'label'=>self::$Labels['is_attachment'],
'label'=>__( 'Post', 'tbp' ),
'post'=>self::$Labels['post'],
'category'=>self::$Labels['_single']['category'],
'post_tag'=>self::$Labels['_single']['post_tag']
unset($single['product']);
$args['optgroup'][0]['selected']='post';
private static function get_options_archive(array $single,array $archive,$isHeader=null){
'label'=>self::$Labels['_archive']['all']
'label'=>self::$Labels['is_date']
'label'=>__( 'Homepage Latest posts', 'tbp' )
'label'=>self::$Labels['is_author'],
'label'=>self::$Labels['is_search']
'label'=>__( 'Posts', 'tbp' ),
'all_post'=>self::$Labels['all_post'],
'category' => self::$Labels['_archive']['category'],
'post_tag'=>self::$Labels['_archive']['post_tag'],
if(get_option( 'show_on_front')!=='posts'){
unset($args['is_front']);
unset($archive['product']);
$args['optgroup'][0]['selected']='all_post';
private static function get_options_page(array $single,array $archive){
'label'=>self::$Labels['page'],
'label'=>self::$Labels['is_front'],
'label'=>self::$Labels['is_404'],
'label'=>self::$Labels['child_of'],
if(get_option( 'show_on_front')!=='page'){
unset($args['is_front']);