: 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 $isLoop=false;
public static $isActive=null;
* Get attachment image url by post_name.
public static function get_attachment_url($slug) {
$attachment_id = self::get_post_type_query('ID', 'attachment', $slug, null);
return $attachment_id ? wp_get_attachment_url($attachment_id) : '';
* Custom query post type using $wpdb object.
* @param string $post_type
* @param string $post_status
* @return string|int|boolean
public static function get_post_type_query($field, $post_type, $slug, $post_status = 'publish') {
$post_status_query = is_null($post_status) ? '' : " AND post_status='" . $post_status . "'";
$sql = $wpdb->prepare("SELECT " . $field . " FROM $wpdb->posts WHERE post_type='%s'" . $post_status_query . " AND post_name='%s' LIMIT 1", $post_type, $slug);
return $wpdb->get_var($sql);
public static function move_array_index(&$array, $a, $b) {
$out = array_splice($array, $a, 1);
array_splice($array, $b, 0, $out);
* Get attachment image by post_name.
public static function get_attachment_image($slug, $size = 'thumbnail', $icon = false, $attr = '') {
$attachment_id = self::get_post_type_query('ID', 'attachment', $slug, null);
return $attachment_id ? wp_get_attachment_image($attachment_id, $size, $icon, $attr) : '';
public static function theme_exists() {
$count = $wpdb->get_var($wpdb->prepare("SELECT 1 FROM $wpdb->posts WHERE post_type='%s' AND post_status='%s' LIMIT 1", array(Tbp_Themes::$post_type, 'publish')));
public static function set_active_theme($id, $set = true) {
update_option('tbp_active_theme', $id);
public static function get_active_theme() {
$post_id = get_option('tbp_active_theme');
return get_post($post_id);
* Get post_meta values by fields.
public static function get_field_exist_values($fields, $post_id) {
$keys = array_keys($fields);
foreach ($keys as $key) {
$value = get_post_meta($post_id, $key, true);
public static function get_template_conditions($post_id, $data = array()) {
$condition = !empty($data) ? $data : get_post_meta($post_id, 'tbp_template_conditions', true);
if (!empty($condition)) {
foreach ($condition as $c) {
$new_arr['type'] = isset($c['include']) ? ($c['include'] === 'ex' ? 'exclude' : $c['include']) : 'include';
if (isset($c['general'])) {
$new_arr['general'] = $c['general'];
if (isset($c['query'])) {
$new_arr['query'] = $c['query'];
$new_arr['detail'] = !empty($c['detail']) && $c['detail']!=='all'?array_map('strval', array_keys($c['detail'])):'all';
public static function get_taxonomies() {
$taxonomies = get_taxonomies(array('public' => true));
$exclude_tax = array('post_format', 'product_shipping_class');
// Exclude unnecessary taxonomies
foreach ($exclude_tax as $tax) {
if (isset($taxonomies[$tax]))
unset($taxonomies[$tax]);
return array_map('get_taxonomy', $taxonomies);
public static function get_public_post_types($args = array()) {
'show_in_nav_menus' => true,
if (!empty($args['post_type'])) {
$post_type_args['name'] = $args['post_type'];
$_post_types = get_post_types($post_type_args, 'objects');
foreach ($_post_types as $post_type => $object) {
$post_types[$post_type] = $object->labels->singular_name;
public static function theme_post_exists($title) {
$count = $wpdb->get_var($wpdb->prepare("SELECT 1 FROM $wpdb->posts WHERE post_type='".Tbp_Themes::$post_type."' AND post_status='publish' AND post_title='%s' LIMIT 1", array($title)));
* Get all related template and template parts ids based on specific theme.
* @param string $theme_slug
public static function get_template_related_post_ids($theme_id, $theme_slug) {
$return = array($theme_id);
'post_type' => Tbp_Templates::$post_type,
'ignore_sticky_posts'=>true,
'key' => 'tbp_associated_theme',
$query = new WP_Query($args);
$data = $query->get_posts();
$return = array_merge($return, $data);
// Include the post thumbnail attachment post type
//if ( has_post_thumbnail( $theme_id ) )
// array_push( $return, get_post_thumbnail_id( $theme_id ) );
public static function get_actual_viewing_post() {
if ( self::$isLoop === true ) {
return ! empty( $return_post ) ? $return_post : null;
public static function get_actual_viewing_post_id() {
$post = self::get_actual_viewing_post();
public static function get_actual_query() {
if(self::$isLoop ===true){
if(Themify_Builder::$frontedit_active===true || Tbp_Public::$isTemplatePage===true){
if(isset($_POST['pageId'])){
$id=(int)$_POST['pageId'];
$isTerm=isset($_POST['terms'],$_POST['term_type']);
$vals=array('post_type','order','orderby','offset');
if(isset($args['offset'])){
$args['offset']=(int)$args['offset'];
if($isTerm===false && $type==='category'){
$args['post_type']='post';
elseif($isTerm===false && $type==='tag'){
$args['post_type']='post';
elseif($type==='archive'){
$args['post_type']=$_POST['pageId'];
$args['post_type']='page';
elseif($type==='search'){
$args['s']=$_POST['pageId'];
elseif($type==='author'){
elseif(taxonomy_exists($type)){
$args['ignore_sticky_posts']=true;
if ( $_POST['term_type'] === 'post_slug' ) {
$args['post__in'] = Themify_Builder_Model::parse_slug_to_ids( sanitize_text_field( $_POST['slug'] ), $args['post_type'] );
Themify_Builder_Model::parseTermsQuery( $args, sanitize_text_field( $_POST['terms'] ), $type );
$tax = get_taxonomy($type);
$args['tax_query']=array(
$args['post_type']=$tax->object_type;
if(post_type_exists($type)){
$args['post_type']=$type;
if($args['orderby']==='id'){
elseif( ! empty( $args['meta_key'] ) && ($args['orderby']==='meta_value' || $args['orderby']==='meta_value_num')) {
$args[ 'meta_key' ] = $args['meta_key'];
elseif(isset($_POST['tb_post_id']) && is_numeric($_POST['tb_post_id']) && get_post_status ( $_POST['tb_post_id'] ) ){// id can be generated element id
$id=(int)$_POST['tb_post_id'];
elseif(Tbp_Public::$isTemplatePage===true){
$id=current(Tbp_Public::get_location());
$post_type=get_post_type($id);
if($post_type===Tbp_Templates::$post_type){
$condition=self::get_template_conditions($id);
$post_type=self::get_post_type(get_post_meta($id, 'tbp_template_type', true), $condition[0]);
$args['post_type']=$post_type==='any'?'post':$post_type;
$args['post_type']='post';
$original_post = self::get_actual_viewing_post();
$args['p'] = $original_post->ID;
$args['post_type'] = $original_post->post_type;
if($args['orderby']==='id'){
elseif( ! empty( $args['meta_key'] ) && ($args['orderby']==='meta_value' || $args['orderby']==='meta_value_num')) {
$args[ 'meta_key' ] = $args['meta_key'];
$data= new WP_Query($args);
public static function get_wc_actual_query() {
if(self::$isLoop ===true){
'post_type' => 'product',
'post_status'=>'publish',
'ignore_sticky_posts' => true
if(Themify_Builder::$frontedit_active===true || Tbp_Public::$isTemplatePage===true){
$cache=Tbp_Public::$isTemplatePage===true;
$args['tax_query']=array(
'taxonomy' => 'product_type',
'taxonomy' => 'product_visibility',
'terms' => array('exclude-from-catalog','outofstock','exclude-from-search','featured')
if(Themify_Builder::$frontedit_active===true){
if(isset($_POST['pageId'])){
$id=(int)$_POST['pageId'];
if ( ! empty( $_POST['aap'] ) ) {
if ( ! empty( $_POST['terms'] ) ) {
Themify_Builder_Model::parseTermsQuery( $args, sanitize_text_field( $_POST['terms'] ), $type );
} else if(taxonomy_exists($type)){
$args['tax_query']=array(
elseif(isset($_POST['tb_post_id']) && is_numeric($_POST['tb_post_id']) && get_post_status ( $_POST['tb_post_id'] )){
$id=(int)$_POST['tb_post_id'];
$post_type=get_post_type($id);
if($post_type!==Tbp_Templates::$post_type){
$args['p'] = self::get_actual_viewing_post_id();
$data= new WP_Query($args);
public static function get_post_type($location,$condition){
$general=isset($condition['general'])?$condition['general']:'general';
$query=isset($condition['query'])?$condition['query']:'';
if($location!=='header' && $location!=='footer'){
if($general==='general'){
if($query==='is_404' || $query==='page' || $location==='page' || $query==='child_of' || ($query==='is_front' && $location==='single')){
if($query==='all' || $query==='is_date' || $query==='is_author' || $query==='is_search'){