'0.1666',
'1/5' => '0.2',
'1/4' => '0.25',
'1/3' => '0.3333',
'2/5' => '0.4',
'1/2' => '0.5',
'3/5' => '0.6',
'2/3' => '0.6667',
'3/4' => '0.75',
'4/5' => '0.8',
'5/6' => '0.8333',
'1/1' => '1',
'divider' => '1'
];
private $values_postfixes = array(
'font-size' => 'px'
);
private $additional_styles = array(
'font-size' => 'line-height: 1.3em;'
);
/**
* Constructor
*/
public function __construct( $ajax = false ) {
// get builder options
$this->options = Mfn_Builder_Helper::get_options();
$this->theme_options['style'] = mfn_opts_get('style','');
// skip other constructor actions for ajax requests
if( $ajax ){
return true;
}
if( empty( $_GET['action'] ) || $_GET['action'] != 'mfn-live-builder' ){
if( mfn_opts_get('builder-blocks') ){
$this->blocks_classic = true;
}
// first action hooked into the admin scripts actions
add_action( 'admin_enqueue_scripts', array( $this, 'enqueue' ) );
}
// get inline shortcodes
$this->inline_shortcodes = Mfn_Builder_Fields::get_inline_shortcode();
}
/**
* SET builder fields
*/
public function set_fields(){
$this->fields = new Mfn_Builder_Fields( false, 'admin' );
}
/**
* Enqueue styles and scripts
*/
public function enqueue()
{
// Rank Math plugin support
if( class_exists('RankMath') ){
wp_enqueue_script( 'rank-math-integration', get_theme_file_uri( '/functions/builder/assets/rank-math-integration.js' ), [ 'wp-hooks' ], MFN_THEME_VERSION, true );
}
// builder scripts
if( $this->blocks_classic ){
wp_enqueue_script( 'mfn-builder', get_theme_file_uri( '/functions/builder/assets/builder.js' ), array( 'jquery' ), MFN_THEME_VERSION, true );
}
}
/**
* GET item type
*/
public function get_item_placeholder_type( $item ){
$return = false;
$array = [
'standard' => [
'blog_news', 'blog_slider', 'blog_teaser', 'clients', 'clients_slider', 'offer', 'offer_thumb',
'portfolio_grid', 'portfolio_photo', 'portfolio_slider', 'shop', 'shop_slider',
'slider', 'testimonials', 'testimonials_list'
],
'variable' => [
'blog', 'portfolio'
],
];
foreach( $array as $type => $items ){
if( in_array( $item, $items ) ){
$return = $type;
break;
}
}
return $return;
}
/**
* PRINT single FIELD
*/
public static function field( $field, $val, $type = 'meta' )
{
if( empty( $field['type'] ) || $field['type'] == 'header' ){
return;
}
if( empty( $field['std'] ) ){
$field['std'] = '';
}
// value of array type ['val'];
if( isset( $val['val'] ) ){
$value = $val['val'];
} else {
$value = $val;
}
// remove empty deprecated fields
if( ! empty($field['class']) && strpos($field['class'], 'mfn-deprecated') !== false ){
if( ! $value || ( $value == $field['std'] ) ){
return;
}
}
// class
$class = false;
$row_class = false;
$row_id = false;
$conditions = false;
// class
if( ! empty( $field['class'] ) ){
$class = $field['class'];
$row_class = $field['class'];
}
if( ! empty( $field['row_class'] ) ){
$row_class .= ' '. $field['row_class'];
}
if( ! empty( $field['responsive'] ) ){
$row_class .= ' mfn_field_'. $field['responsive'];
}
// id
if( ! empty( $field['attr_id'] ) ){
$row_id = 'id="'. $field['attr_id'] .'" ';
}
// conditions
if( isset( $field['condition'] ) ){
if( is_array( $field['condition']['val'] ) ){
$field['condition']['val'] = implode( ',', $field['condition']['val'] );
}
$row_class .= ' activeif activeif-'. $field['condition']['id'];
$conditions = 'data-conditionid="'. $field['condition']['id'] .'" data-opt="'. $field['condition']['opt'] .'" data-val="'. $field['condition']['val'] .'"';
}
// output -----
if( 'info' == $field['type'] ){
require_once( get_template_directory() .'/muffin-options/fields/info/field_info.php' );
if ( class_exists( 'MFN_Options_info' ) ) {
$field_object = new MFN_Options_info( $field, $value );
$field_object->render( $type );
}
return true;
}
// return true;
if( 'no-row' != $class ){
echo '
';
}
}
/**
* PRINT single SECTION
*/
public function section( $section = false, $deprecated = false )
{
// change section visibility
$mfn_global_section_id = false;
$class = [];
$label = [
'hide' => __('Hide section', 'mfn-opts'),
'collapse' => __('Collapse section', 'mfn-opts'),
];
if ( ! empty( $section['attr']['hide'] ) ) {
$class[] = 'hide';
$label['hide'] = __('Show section', 'mfn-opts');
}
if ( ! empty( $section['attr']['collapse'] ) ) {
$class[] = 'collapse';
$label['collapse'] = __('Expand section', 'mfn-opts');
}
if( empty( $section['wraps'] ) && empty( $section['items'] ) ){
// FIX | Muffin Builder 2 compatibility | empty( $section['items'] )
$class[] = 'empty';
}
// section styles
if( ! empty( $section['attr']['style'] ) ){
if( strpos( $section['attr']['style'], 'full-' ) !== false ){
$class[] = 'full-width';
}
}
// class
$class = implode(' ', $class);
// attributes
if ( ! empty( $section['attr']['title'] ) ) {
$title = $section['attr']['title'];
} else {
$title = '';
}
if ( ! empty( $section['attr']['custom_id'] ) ) {
$hash = '#'. $section['attr']['custom_id'];
} else if ( ! empty( $section['attr']['section_id'] ) ) {
$hash = '#'. $section['attr']['section_id'];
} else {
$hash = '';
}
// be sections global pbl
if( !empty($section['mfn_global_section_id']) ) {
$mfn_global_section_id = $section['mfn_global_section_id'];
$class .= ' mfn-global-section';
$title .= ' Global section';
}
// uid
if( ! empty( $section['uid'] ) ){
$uid = $section['uid'];
} else {
$uid = Mfn_Builder_Helper::unique_ID();
}
// output -----
echo '';
echo '
';
// section | global section edit button
if( !empty($section['mfn_global_section_id']) ) {
echo '
Edit Global Section';
}
// section | add new before
echo '
'. esc_html__('Add section', 'mfn-opts') .'';
// section | header
echo '';
// section | content
echo '
';
// section | sortable
echo '
';
// section | new
echo '
';
// section | existing content
if ( $section ){
// be sections global pbl
if( $mfn_global_section_id ) {
$section = get_post_meta($mfn_global_section_id, 'mfn-page-items', true);
if ( !is_array($section) ) {
$section = unserialize( call_user_func('base'.'64_decode', $section), ['allowed_classes' => false] );
}
$section = $section[0];
echo '
';
}
// FIX | Muffin Builder 2 compatibility
// there were no wraps inside section in Muffin Builder 2
if ( ! isset( $section['wraps'] ) && ! empty( $section['items'] ) ) {
$fix_wrap = array(
'size' => '1/1',
'items' => $section['items'],
);
$section['wraps'] = array( $fix_wrap );
}
// end FIX
if ( isset( $section['wraps'] ) && is_array( $section['wraps'] ) ) {
foreach ( $section['wraps'] as $wrap ) {
$this->wrap( $wrap, $uid );
}
}
}
echo '
';
echo '
';
// section | meta data
echo '
';
// section | meta fields
$section_fields = $this->fields->get_section();
foreach ( $section_fields as $field ) {
if( $field['type'] == 'header' || empty( $field['type'] ) ){
// row header
if ( ! isset( $field['class'] ) ) {
$field['class'] = false;
}
Mfn_Post_Type::row_header( $field['title'], $field );
} elseif( 'html' == $field['type'] ) {
echo $field['html'];
} else {
// responsive
$devices = ['desktop'];
if( ! empty( $field['responsive'] ) ){
$devices = ['desktop', 'laptop', 'tablet', 'mobile'];
}
foreach ( $devices as $device ){
$value = '';
// assign oryginal field data to device
$device_field = $field;
if( ! empty( $field['responsive'] ) ){
$device_field['responsive'] = $device;
}
// do not add postfix to device
if( 'desktop' !== $device ){
if( ! empty( $device_field['old_id'] ) ) {
$device_field['old_id'] .= '_'. $device;
}
$device_field['id'] .= '_'. $device;
}
// existing section or default value
if ( isset( $device_field['id'] ) && isset( $section['attr'][ $device_field['id'] ] ) ) {
$value = $section['attr'][ $device_field['id'] ];
} else {
$value = '';
}
// legacy: check old_id
if( ! $value && isset( $device_field['old_id'] ) && isset( $section['attr'][ $device_field['old_id'] ] ) ){
$value = $section['attr'][ $device_field['old_id'] ];
}
// default values
if ( ! $value && '0' !== $value && isset( $device_field['std'] ) ) {
$value = $device_field['std'];
}
// field ID
if( isset($device_field['id']) ){
$device_field['id'] = 'mfn-section['. $uid .']['. $device_field['id'] .']';
}
// PRINT single FIELD
$meta = 'filled'; // filled field uses 'name'
if ( empty( $value ) || ( is_array( $value ) && ! array_filter( $value ) ) ){
$meta = 'empty'; // 'empty' = field uses 'data-name'
}
// style fields using array
if ( isset( $value['val'] ) && empty( $value['val'] ) ){
$meta = 'empty'; // 'empty' = field uses 'data-name'
}
self::field( $device_field, $value, $meta );
}
}
}
echo '
';
// section | add new after
echo '
'. esc_html__('Add section', 'mfn-opts') .'';
echo '
';
}
/**
* PRINT single WRAP
*/
public function wrap( $wrap = false, $parent_id = false, $deprecated = false )
{
// size
if( empty( $wrap['size'] ) ){
$wrap['size'] = '1/1';
}
if( empty( $wrap['tablet_size'] ) ){
$wrap['tablet_size'] = $wrap['size']; // the same as desktop size
}
if( empty( $wrap['mobile_size'] ) ){
$wrap['mobile_size'] = '1/1'; // always 1/1 like in the Muffin Builder 3
}
// wrap ID
if( ! empty( $wrap['uid'] ) ){
$uid = $wrap['uid'];
} else {
$uid = Mfn_Builder_Helper::unique_ID();
}
// attributes
$class = [];
if( empty( $wrap['items'] ) ){
$class[] = 'empty';
}
if ( 'divider' == $wrap['size'] ) {
$class[] = 'divider';
}
//be sections global pbl
$is_global_wrap = !empty($wrap['attr']['global_wraps_select']);
if( $is_global_wrap ) {
$mfn_global_wrap_id = $wrap['attr']['global_wraps_select'];
$class[] = 'mfn-global-wrap';
}
$class = implode(' ', $class);
// output -----
echo '';
if( $is_global_wrap ){
echo '
Edit Global Wrap';
}
echo '
';
echo '
';
echo '
';
echo '
';
echo '
';
// wrap | header
echo '';
// wrap | content
echo '
';
echo '
';
// wrap | sortable
echo '
';
// wrap | existing content
//be sections global pbl
if( $is_global_wrap ) {
$section = get_post_meta($mfn_global_wrap_id, 'mfn-page-items', true);
if ( !is_array($section) ) {
$section = unserialize( call_user_func('base'.'64_decode', $section), ['allowed_classes' => false] );
}
$wrap['items'] = $section[0]['wraps'][0]['items'];
}
if ( isset( $wrap['items'] ) && is_array( $wrap['items'] ) ) {
foreach ( $wrap['items'] as $item ) {
$this->item( $item['type'], $item, $uid );
}
}
echo '
';
echo '
';
echo '
';
// wrap | meta
echo '
';
// wrap | meta fields
$wrap_fields = $this->fields->get_wrap();
foreach ( $wrap_fields as $field ) {
if( $field['type'] == 'header' || empty( $field['type'] ) ){
// row header
if ( ! isset( $field['class'] ) ) {
$field['class'] = false;
}
Mfn_Post_Type::row_header( $field['title'], $field );
} elseif( 'html' == $field['type'] ) {
echo $field['html'];
} else {
// responsive
$devices = ['desktop'];
if( ! empty( $field['responsive'] ) ){
$devices = ['desktop', 'laptop', 'tablet', 'mobile'];
}
foreach ( $devices as $device ){
$value = '';
// assign oryginal field data to device
$device_field = $field;
if( ! empty( $field['responsive'] ) ){
$device_field['responsive'] = $device;
}
// do not add postfix to device
if( 'desktop' !== $device ){
if( ! empty( $device_field['old_id'] ) ) {
$device_field['old_id'] .= '_'. $device;
}
$device_field['id'] .= '_'. $device;
}
// existing wrap or default value
if ( isset( $device_field['id'] ) && isset( $wrap['attr'][ $device_field['id'] ] ) ) {
$value = $wrap['attr'][ $device_field['id'] ];
} else {
$value = '';
}
// legacy: check old_id
if( ! $value && isset( $device_field['old_id'] ) && isset( $wrap['attr'][ $device_field['old_id'] ] ) ){
$value = $wrap['attr'][ $device_field['old_id'] ];
}
// default values
if ( ! $value && '0' !== $value && isset( $device_field['std'] ) ) {
$value = $device_field['std'];
}
// field ID
if( isset($device_field['id']) ){
$device_field['id'] = 'mfn-wrap['. $uid .']['. $device_field['id'] .']';
}
// PRINT single FIELD
$meta = 'filled'; // filled field uses 'name'
if ( empty( $value ) || ( is_array( $value ) && ! array_filter( $value ) ) ){
$meta = 'empty'; // 'empty' = field uses 'data-name'
}
// style fields using array
if ( isset( $value['val'] ) && empty( $value['val'] ) ){
$meta = 'empty'; // 'empty' = field uses 'data-name'
}
self::field( $device_field, $value, $meta );
}
}
}
echo '
';
echo '
';
}
/**
* PRINT single ITEM
*/
public function item( $item_type, $item = false, $parent_id = false, $deprecated = false )
{
$item_fields = $this->fields->get_item_fields( $item_type );
if( $item && ! isset( $item['attr'] ) ){
$item['attr'] = ! empty($item['fields']) ? $item['fields'] : [];
}
// size
if( empty( $item['size'] ) ){
$item['size'] = $item_fields['size'];
}
if( empty( $item['tablet_size'] ) ){
$item['tablet_size'] = $item['size']; // the same as desktop size
}
if( empty( $item['mobile_size'] ) ){
$item['mobile_size'] = '1/1'; // always 1/1 like in the Muffin Builder 3
}
// item ID
if( ! empty( $item['uid'] ) ){
$uid = $item['uid'];
} else {
$uid = Mfn_Builder_Helper::unique_ID();
}
// label
$label = false;
if( ! empty( $item['attr']['title'] ) ){
$label = $item['attr']['title'];
}
// google fonts used in the inline editor: blockquote, colum, visual
if( empty($item['used_fonts']) ){
$item['used_fonts'] = '';
};
// output -----
echo '';
echo '
';
echo '
';
echo '
';
echo '
';
echo '
';
echo '
';
echo '
';
echo '';
echo '';
// item preview
if( $this->preview ){
$preview = [
'image' => '',
'title' => '',
'subtitle' => '',
'content' => '',
'style' => '',
'number' => '',
'category' => '',
'category-all' => '',
'icon' => '',
'tabs' => '',
'images' => '',
'align' => '',
];
$preview_empty = [];
$preview_tabs_primary = 'title';
foreach ( $item_fields['attr'] as $field ) {
if ( isset( $field['preview'] ) ){
$prev_key = $field['preview'];
$prev_id = $field['id'];
// existing item or default value
if( isset( $item['attr'] ) ){
if( isset( $item['attr'][$prev_id] ) ){
if( isset( $item['attr'][$prev_id]['val'] ) ){
$preview[$prev_key] = $item['attr'][$prev_id]['val'];
} else {
$preview[$prev_key] = $item['attr'][$prev_id];
}
}
if( 'tabs' === $field['type'] && empty( $item['attr']['tabs'] ) ){
$preview[$prev_key] = '';
}
} elseif( ! empty( $field['std'] ) ){
$preview[$prev_key] = $field['std'];
if ( empty( $this->options['pre-completed'] ) ){
if ( in_array( $field['type'], ['tabs', 'text', 'textarea', 'upload'] ) ){
$preview[$prev_key] = '';
}
}
}
// tabs
if( 'tabs' == $field['preview'] ){
if( ! empty( $field['primary'] ) ){
$preview_tabs_primary = $field['primary'];
}
}
// category
if( 'category' == $field['preview'] ){
if( $preview['category'] ){
$cat_obj = get_category_by_slug( $preview['category'] );
if( is_object( $cat_obj ) ){
$preview['category'] = $cat_obj->name;
} else {
$preview['category'] = 'All';
}
} else {
$preview['category'] = 'All';
}
}
}
}
// multiple categories
if ( $preview['category-all'] ){
$preview['category'] = $preview['category-all'];
}
// icon
if ( in_array( $item_type, ['counter','icon_box','list'] ) && $preview['image'] ){
// image replaces icon in some items
$preview['icon'] = '';
}
// SVG placeholder
if ( in_array( $item_type, ['map','map_basic'] ) ){
$preview['image'] = get_theme_file_uri( '/muffin-options/svg/placeholders/map.svg' );
}
if ( in_array( $item_type, ['code','content','fancy_divider','sidebar_widget','slider_plugin','video'] ) ){
$preview['image'] = get_theme_file_uri( '/muffin-options/svg/placeholders/'. $item_type .'.svg' );
}
// empty
foreach( $preview as $prev_key => $prev_val ){
if( $prev_val ){
$preview_empty[ $prev_key ] = '';
} else {
$preview_empty[ $prev_key ] = 'empty';
}
}
// content limit
if ( $preview['content'] ){
$excerpt = $preview['content'];
if ( in_array( $item_type, ['column', 'visual'] ) ){
// remove unwanted HTML tags
$excerpt = wp_kses( $excerpt, Mfn_Builder_Helper::allowed_html() );
// wrap shortcodes into span to highlight
$excerpt = preg_replace( '/(\[(.*?)?\[\/)((.*?)?\])|(\[(.*?)?\])/', '
$0', $excerpt);
// autoclose tags
$excerpt = force_balance_tags( $excerpt );
} else {
$excerpt = strip_shortcodes( strip_tags( $excerpt ) );
$excerpt = preg_split( '/\b/', $excerpt, 16 * 2 + 1 );
array_pop( $excerpt );
$excerpt = implode( $excerpt );
if( strlen( $excerpt ) < strlen( $preview['content'] ) ){
$excerpt = $excerpt .'...';
}
}
$preview['content'] = $excerpt;
}
echo '
';
echo '
';
echo '
 .')
';
echo '
';
echo '
';
echo '
'. esc_html( $preview['title'] ) .'
';
echo '
'. esc_html( $preview['subtitle'] ) .'
';
echo '
'. $preview['content'] .'
';
echo '
';
$placeholder_type = $this->get_item_placeholder_type( $item_type );
if( 'standard' == $placeholder_type ){
$placeholder = get_theme_file_uri( '/muffin-options/svg/placeholders/'. $item_type .'.svg' );
echo '
';
} elseif ( 'variable' == $placeholder_type ) {
// existing item or default value
if( isset( $item['attr'] ) ){
$item_style = str_replace( array( ',', ' ' ), '-', $item['attr']['style'] );
} else {
$item_style = 'grid';
}
$placeholder_dir = get_theme_file_uri( '/muffin-options/svg/select/'. $item_type .'/' );
$placeholder = $placeholder_dir . $item_style .'.svg';
echo '
';
}
echo ''. esc_html( $preview['number'] ) .'';
echo '
';
echo '
';
echo '
'. esc_html__('Category', 'mfn-opts') .':'. esc_html( $preview['category'] ) .'
';
echo '
';
if ( $preview['tabs'] ){
foreach ( $preview['tabs'] as $tab ) {
echo '- '. $tab[$preview_tabs_primary] .'
';
}
}
echo '
';
echo '
';
if ( $preview['images'] ){
$preview['images'] = explode( ',', $preview['images'] );
foreach ( $preview['images'] as $image ){
echo '- '. wp_get_attachment_image( $image, 'thumbnail' ) .'
';
}
}
echo '
';
echo '
';
echo '
';
}
// item | meta
echo '
';
// item | meta fields
foreach ( $item_fields['attr'] as $field ) {
if ( ! isset( $field['class'] ) ) {
$field['class'] = '';
}
// hide fields for specified style: simple/classic
if( isset( $field['themeoptions'] ) ){
$themeoption = explode(':', $field['themeoptions']);
if( isset($themeoption[1]) ){
if( $this->theme_options['style'] != $themeoption[1] ){
continue;
}else{
$field['class'] .= empty( $this->theme_options['style'] ) ? ' theme-classic-style' : ' theme-simple-style';
}
}
}
if( $field['type'] == 'header' || empty( $field['type'] ) ){
// row header
Mfn_Post_Type::row_header( $field['title'], $field );
} elseif( 'html' == $field['type'] ) {
echo $field['html'];
} else {
// responsive
$devices = ['desktop'];
if( ! empty( $field['responsive'] ) ){
$devices = ['desktop', 'laptop', 'tablet', 'mobile'];
}
foreach ( $devices as $device ){
$value = '';
// assign oryginal field data to device
$device_field = $field;
if( ! empty( $field['responsive'] ) ){
$device_field['responsive'] = $device;
}
// do not add postfix to device
if( 'desktop' !== $device ){
if( ! empty( $device_field['old_id'] ) ) {
$device_field['old_id'] .= '_'. $device;
}
$device_field['id'] .= '_'. $device;
}
// existing item or default value
if( isset( $item['attr'] ) ){
// existing
if( isset( $device_field['id'] ) && isset( $item['attr'][ $device_field['id'] ] ) ){
$value = $item['attr'][ $device_field['id'] ];
}
// legacy: check old_id
if( ! $value && isset( $device_field['old_id'] ) && isset( $item['attr'][ $device_field['old_id'] ] ) ){
$value = $item['attr'][ $device_field['old_id'] ];
}
// tabs
if( 'tabs' === $device_field['type'] && empty( $item['attr']['tabs'] ) ){
$value = [];
}
} else {
// new
if ( isset( $device_field['std'] ) ){
$value = $device_field['std'];
}
if ( empty( $this->options['pre-completed'] ) ){
if ( in_array( $device_field['type'], ['text', 'textarea', 'upload'] ) ){
$value = '';
}
if ( 'tabs' === $device_field['type'] ){
$value = [];
}
}
}
// field ID
if( isset($device_field['id']) ){
$device_field['id'] = 'mfn-item['. $uid .']['. $device_field['id'] .']';
}
// PRINT single FIELD
$meta = 'filled'; // filled field uses 'name'
if ( empty( $value ) || ( is_array( $value ) && ! array_filter( $value ) ) ){
$meta = 'empty'; // 'empty' = field uses 'data-name'
}
// style fields using array
if ( isset( $value['val'] ) && empty( $value['val'] ) ){
$meta = 'empty'; // 'empty' = field uses 'data-name'
}
self::field( $device_field, $value, $meta );
}
}
}
echo '
';
echo '
';
}
/**
* SEO content
*/
public function rankMath( $id = false, $mfn_items = false ){
// RankMath hidden content field
if( ! $mfn_items && $id ){
if( ! class_exists('RankMath') ){
return;
}
// BeBuilder Blocks disabled
if( mfn_opts_get('builder-blocks') ){
return;
}
$mfn_items = get_post_meta($id, 'mfn-page-items', true);
// FIX | Muffin Builder 2 compatibility
if ($mfn_items && ! is_array($mfn_items)) {
$mfn_items = unserialize(call_user_func('base'.'64_decode', $mfn_items), ['allowed_classes' => false]);
}
}
// analize content
$seo_content = '';
$skip = [
'#FFFFFF',
'{featured_image}',
'contain',
'center',
'center center',
'center top',
'default',
'disable',
'full',
'h1',
'h2',
'h3',
'h4',
'h5',
'h6',
'hide',
'hide-mobile',
'hide-tablet',
'horizontal',
'inline',
'left',
'no-repeat',
'none',
'right',
'show',
'solid',
'thumbnail',
'top',
'unset',
]; // seo values to skip
if( ! empty( $mfn_items ) ){
foreach( $mfn_items as $section ){
if( ! empty( $section['wraps'] ) ){
foreach( $section['wraps'] as $wrap ){
if( ! empty( $wrap['items'] ) ){
foreach( $wrap['items'] as $item ){
if( ! isset($item['attr']) ){
$item['attr'] = ! empty($item['fields']) ? $item['fields'] : [];
}
// print_r($item);
if( ! empty( $item['attr'] ) ){
foreach( $item['attr'] as $vk => $value ){
if( !empty($item['type']) && 'heading' == $item['type'] && 'title' == $vk && !empty( $item['attr']['header_tag'] ) ){
$tag = $item['attr']['header_tag'];
$seo_content .= "\n" . '<'. $tag .'>'. $value .''. $tag .'>';
} elseif( is_string( $value ) && ! is_numeric( $value ) && ! in_array( $value, $skip ) ){
if ( in_array( $vk, array( 'image', 'src' ) ) ) {
$seo_content .= "\n" . '
';
} elseif ( 'link' == $vk ) {
$seo_content .= "\n" . ''. $value .'';
} else {
$seo_content .= "\n" . $value;
}
} elseif( 'tabs' == $vk && is_array( $value ) ){
// tabs
foreach( $value as $tab ){
if( ! empty( $tab ) ){
foreach( $tab as $tab_field ){
$seo_content .= "\n" . trim( $tab_field ?? '' );
}
}
}
}
}
}
}
}
}
}
}
}
if( $id ){
// show
echo '';
} else {
// return
return $seo_content;
}
}
/**
* PRINT Muffin Builder
*/
public function show()
{
global $post;
// Rank Math plugin support | BeBuilder Blocks disabled
$this->rankMath( $post->ID );
$replaced_logo = apply_filters('betheme_logo', '') ? 'style="background-image:url('. apply_filters('betheme_logo_nohtml', ''). ')"' : '';
// hide builder if current user does not have a specific capability
if ( $visibility = mfn_opts_get( 'builder-visibility' ) ) {
if ( $visibility == 'hide' || ( ! current_user_can( $visibility ) ) ) {
return;
}
}
// disable BeBuilder Blocks for some template types
if( get_post_type($post->ID) == 'template' && get_post_meta($post->ID, 'mfn_template_type', true) && in_array( get_post_meta($post->ID, 'mfn_template_type', true), array('header', 'footer', 'megamenu') ) ){
return;
}
// disable BeBuilder Blocks in Theme options
if( apply_filters('bebuilder_access', false) ) {
echo '';
echo '';
}
if( ! $this->blocks_classic ){
return;
}
$items = $this->fields->get_items(); // default items
// check if disable items preview
$theme_disable = mfn_opts_get( 'theme-disable' );
if( ! empty( $theme_disable['builder-preview'] ) ){
$this->preview = false;
}
// GET items
$mfn_items = get_post_meta($post->ID, 'mfn-page-items', true);
// FIX | Muffin Builder 2 compatibility
if ($mfn_items && ! is_array($mfn_items)) {
$mfn_items = unserialize(call_user_func('base'.'64_decode', $mfn_items), ['allowed_classes' => false]);
}
// debug
// echo '';
// print_r( $mfn_items );
// echo '';
// exit;
// disable BeBuilder Blocks if nested wraps exists
$json = json_encode($mfn_items);
if( false !== strpos( $json, 'item_is_wrap' ) ){
echo '';
echo '
The builder content of this page contains nested wraps.
';
if( ! WHITE_LABEL ){
echo '
'. apply_filters('betheme_label', 'Be') .'Builder Blocks Classic works in legacy mode so content created in newer versions may not be supported. Please edit with '. apply_filters('betheme_label', 'Be') .'Builder.
';
}
echo '
';
return;
}
// builder classes
$class = [];
if( ! is_array( $mfn_items ) ){
$class[] = 'empty';
}
if( is_array( $this->options ) ){
foreach( $this->options as $option_id => $option_val ){
if( $option_val ){
$class[] = $option_id;
}
}
}
$class = implode( ' ', $class );
?>
Builder
section($section);
}
}
?>
introduction();
?>
blocks_classic ){
return;
}
// FIX | Visual Composer Frontend
if ( isset( $_POST['vc_inline'] ) ) {
return false;
}
// field are required for style inputs
$this->set_fields();
// debug
// echo '';
// print_r( $_POST );
// echo '
';
// exit;
// variables
$mfn_items = [];
$mfn_wraps = [];
$elements_flat = [];
// LOOP sections
if ( isset( $_POST['mfn-section-id'] ) && is_array( $_POST['mfn-section-id'] ) ) {
foreach ( $_POST['mfn-section-id'] as $sectionID_k => $sectionID ) {
$uid = $_POST['mfn-section-id'][$sectionID_k];
$section = [
'uid' => $uid,
'attr' => [],
'wraps' => [],
'mfn_global_section_id' => '',
];
// attributes
if ( isset( $_POST['mfn-section'][$uid] ) && is_array( $_POST['mfn-section'][$uid] ) ) {
foreach ($_POST['mfn-section'][$uid] as $section_attr_k => $section_attr) {
$value = $section_attr;
// style field
if( strpos( $section_attr_k, 'css_' ) === 0 ){
$section_fields = $this->fields->get_section();
// device
if( strpos( $section_attr_k, '_laptop' ) ){
$device = '_laptop';
$key = str_replace( '_laptop', '', $section_attr_k );
} else if( strpos( $section_attr_k, '_tablet' ) ){
$device = '_tablet';
$key = str_replace( '_tablet', '', $section_attr_k );
} else if( strpos( $section_attr_k, '_mobile' ) ){
$device = '_mobile';
$key = str_replace( '_mobile', '', $section_attr_k );
} else {
$device = '';
$key = $section_attr_k;
}
foreach( $section_fields as $f => $field ){
if( !empty($field['id']) && $key == $field['id'] ){
$value = [
'val' => $value,
'css_path' => $section_fields[$f]['css_path'],
'css_style' => $section_fields[$f]['css_style'] . $device,
];
break;
}
}
}
// save
$section['attr'][$section_attr_k] = $value;
}
}
// global sections, prepare to save, pbl be
if( isset($_POST['mfn-global-section'][$uid]) ) {
$section['mfn_global_section_id'] = $_POST['mfn-global-section'][$uid];
}
// assign
$mfn_items[] = $section;
$elements_flat[] = $section;
}
$section_IDs = $_POST['mfn-section-id'];
$section_IDs_key = array_flip($section_IDs);
}
// LOOP wraps
if ( isset( $_POST['mfn-wrap-id'] ) && is_array( $_POST['mfn-wrap-id'] ) ) {
foreach ( $_POST['mfn-wrap-id'] as $wrapID_k => $wrapID ) {
$uid = $_POST['mfn-wrap-id'][$wrapID_k];
$wrap = [
'uid' => $uid,
'size' => $_POST['mfn-wrap-size'][$wrapID_k],
'tablet_size' => $_POST['mfn-wrap-size-tablet'][$wrapID_k],
'mobile_size' => $_POST['mfn-wrap-size-mobile'][$wrapID_k],
'attr' => [],
'items' => [],
];
// attributes
if ( isset( $_POST['mfn-wrap'][$uid] ) && is_array( $_POST['mfn-wrap'][$uid] ) ) {
foreach ($_POST['mfn-wrap'][$uid] as $wrap_attr_k => $wrap_attr) {
$value = $wrap_attr;
// style field
if( strpos( $wrap_attr_k, 'css_' ) === 0 ){
$wrap_fields = $this->fields->get_wrap();
// device
if( strpos( $wrap_attr_k, '_laptop' ) ){
$device = '_laptop';
$key = str_replace( '_laptop', '', $wrap_attr_k );
} else if( strpos( $wrap_attr_k, '_tablet' ) ){
$device = '_tablet';
$key = str_replace( '_tablet', '', $wrap_attr_k );
} else if( strpos( $wrap_attr_k, '_mobile' ) ){
$device = '_mobile';
$key = str_replace( '_mobile', '', $wrap_attr_k );
} else {
$device = '';
$key = $wrap_attr_k;
}
foreach( $wrap_fields as $f => $field ){
if( !empty($field['id']) && $key == $field['id'] ){
$value = [
'val' => $value,
'css_path' => $wrap_fields[$f]['css_path'],
'css_style' => $wrap_fields[$f]['css_style'] . $device,
];
break;
}
}
}
// save
$wrap['attr'][$wrap_attr_k] = $value;
}
}
// assign
$mfn_wraps[$wrapID] = $wrap;
$elements_flat[] = $wrap;
}
$wrap_IDs = $_POST['mfn-wrap-id'];
$wrap_IDs_key = array_flip($wrap_IDs);
$wrap_parents = $_POST['mfn-wrap-parent'];
}
// LOOP items
if ( isset( $_POST['mfn-item-type'] ) && is_array( $_POST['mfn-item-type'] ) ) {
$seo_content = '';
$skip = [
'1',
'default',
'horizontal',
]; // seo values to skip
foreach ( $_POST['mfn-item-type'] as $type_k => $type ) {
$uid = $_POST['mfn-item-id'][$type_k];
$item = [
'type' => $type,
'uid' => $uid,
'size' => $_POST['mfn-item-size'][$type_k],
'tablet_size' => $_POST['mfn-item-size-tablet'][$type_k],
'mobile_size' => $_POST['mfn-item-size-mobile'][$type_k],
'used_fonts' => $_POST['mfn-item-fonts'][$type_k],
'attr' => [],
];
if ( isset( $_POST['mfn-item'][$uid] ) && is_array( $_POST['mfn-item'][$uid] ) ) {
foreach ( $_POST['mfn-item'][$uid] as $attr_k => $attr ) {
$value = $attr;
if ( 'tabs' == $attr_k ) {
// field type: TABS
$item_tabs = $value;
$tabs = [];
foreach( $item_tabs as $tab_key => $tab_fields ){
foreach( $tab_fields as $tab_index => $tab_field ){
$value = stripslashes( $tab_field );
// core.trac.wordpress.org/ticket/34845
if ( ! mfn_opts_get( 'builder-storage' ) ) {
$value = preg_replace( '~\R~u', "\n", $value );
}
$tabs[$tab_index][$tab_key] = $value;
// FIX | Yoast SEO
$seo_val = trim( $value );
if ( $seo_val && $seo_val !== '1' ) {
$seo_content .= $seo_val ."\n";
}
}
}
$item['attr']['tabs'] = $tabs;
} else {
// all other field types
if( is_string( $value ) ){
$value = stripslashes( $value );
// core.trac.wordpress.org/ticket/34845
if ( ! mfn_opts_get( 'builder-storage' ) ) {
$value = preg_replace( '~\R~u', "\n", $value );
}
// FIX | Yoast SEO
$seo_val = trim( $value );
if ( $seo_val && ! in_array( $seo_val, $skip ) ) {
if ( in_array( $attr_k, array( 'image', 'src' ) ) ) {
$seo_content .= '
'."\n";
} elseif ( 'link' == $attr_k ) {
$seo_content .= ''. $seo_val .''."\n";
} else {
$seo_content .= $seo_val ."\n";
}
}
}
// products per page template
if ( $type == 'shop_products' && $attr_k == 'products' && !empty($value) ) {
update_post_meta( $post_id, 'mfn_template_perpage', strval($value) );
}
// product add to cart button template add_to_cart
if ( $type == 'product_cart_button' && $attr_k == 'cart_button_text' && !empty($value) ) {
update_post_meta( $post_id, 'mfn_cart_button', $value );
}
// product single image zoom
if ( $type == 'product_images' && $attr_k == 'zoom' ) {
update_post_meta( $post_id, 'mfn_template_product_image_zoom', $value );
}
// style field
if( strpos( $attr_k, 'css_' ) === 0 ){
$item_fields = $this->fields->get_item_fields( $type );
$item_fields = $item_fields['attr'];
// device
if( strpos( $attr_k, '_laptop' ) ){
$device = '_laptop';
$key = str_replace( '_laptop', '', $attr_k );
} else if( strpos( $attr_k, '_tablet' ) ){
$device = '_tablet';
$key = str_replace( '_tablet', '', $attr_k );
} else if( strpos( $attr_k, '_mobile' ) ){
$device = '_mobile';
$key = str_replace( '_mobile', '', $attr_k );
} else {
$device = '';
$key = $attr_k;
}
foreach( $item_fields as $f => $field ){
if( !empty($field['id']) && $key == $field['id'] ){
$value = [
'val' => $value,
'css_path' => $item_fields[$f]['css_path'],
'css_style' => $item_fields[$f]['css_style'] . $device,
];
break;
}
}
}
// save
$item['attr'][$attr_k] = $value;
}
}
$seo_content .= "\n";
}
// parent wrap
$parent_wrap_ID = $_POST['mfn-item-parent'][ $type_k ];
if ( ! isset( $mfn_wraps[ $parent_wrap_ID ]['items'] ) || ! is_array( $mfn_wraps[ $parent_wrap_ID ]['items'] ) ) {
$mfn_wraps[ $parent_wrap_ID ]['items'] = array();
}
// assign
$mfn_wraps[ $parent_wrap_ID ]['items'][] = $item;
$elements_flat[] = $item;
}
}
// assign wraps with items to sections
foreach ( $mfn_wraps as $wrap_ID => $wrap ) {
$wrap_key = $wrap_IDs_key[ $wrap_ID ];
$section_ID = $wrap_parents[ $wrap_key ];
$section_key = $section_IDs_key[ $section_ID ];
if (! isset($mfn_items[ $section_key ]['wraps']) || ! is_array($mfn_items[ $section_key ]['wraps'])) {
$mfn_items[ $section_key ]['wraps'] = array();
}
$mfn_items[ $section_key ]['wraps'][] = $wrap;
}
// debug
// echo '';
// print_r($mfn_items);
// echo '
';
// exit;
// prepare data to save
if ( $mfn_items ) {
if ( 'encode' == mfn_opts_get('builder-storage') ) {
$new = call_user_func( 'base'.'64_encode', serialize( $mfn_items ) );
} else {
// codex.wordpress.org/Function_Reference/update_post_meta
$new = wp_slash( $mfn_items );
}
}
/** START template conditions */
if ( function_exists('is_woocommerce') && get_post_type( $post_id ) == 'template' ){
// conditions
if ( isset( $_POST['mfn_template_conditions'] ) && is_array( $_POST['mfn_template_conditions'] ) && count($_POST['mfn_template_conditions']) > 0 ) {
$tmpl_conditions = $_POST['mfn_template_conditions'];
update_post_meta( $post_id, 'mfn_template_conditions', json_encode( $tmpl_conditions ) );
}elseif( $mfn_items ){ // delete conditions only if builder is enabled
delete_post_meta( $post_id, 'mfn_template_conditions' );
}
$this->set_woo_templates_conditions();
}
if ( function_exists('is_woocommerce') && get_post_type( $post_id ) == 'product' ){
$this->set_woo_templates_conditions();
}
/** END template conditions */
// SAVE data
if ( isset( $_POST['mfn-items-save'] ) ) {
$meta_key = [
'items' => 'mfn-page-items',
'seo' => 'mfn-page-items-seo',
// 'fonts' => 'mfn-page-fonts',
// 'styles' => 'mfn-page-local-style',
];
// local styles and fonts
// print_r($elements_flat);
// exit;
delete_post_meta( $post_id, 'mfn-page-object' );
Mfn_Helper::preparePostUpdate( $elements_flat, $post_id );
// builder content
$old = get_post_meta( $post_id, $meta_key['items'], true );
if ( isset( $new ) && $new != $old ) {
// update post meta if there is at least one builder section
update_post_meta( $post_id, $meta_key['items'], $new );
update_post_meta( $post_id, $meta_key['seo'], $seo_content );
} elseif ( $old && ( ! isset( $new ) || ! $new ) ) {
// delete post meta if builder is empty
delete_post_meta( $post_id, $meta_key['items'] );
delete_post_meta( $post_id, $meta_key['seo'] );
}
}
}
/**
* Introduction slider
*/
public function introduction(){
if( WHITE_LABEL ){
return false;
}
$slides = [
'The new '. apply_filters('betheme_label', 'Be') .'Builder
',
'Instant access
to Pre-Built Sections
',
'Builder History
with easy backup restoration
',
'Import & Export of content
or single sections
',
'New Text Editor with code highlighter
and shortcode manager
',
'Improved section
with tons of new features
',
'Extremely useful icon select with quick search & Font Awesome included
',
];
$max = count( $slides );
$index = 1;
echo '';
echo '
';
echo '
';
echo '
';
foreach( $slides as $slide ){
echo '-
'. $index .' / '. $max .'
'. $slide .'
Skip
';
$index++;
}
echo '
';
echo '
';
echo '
';
}
/**
* Print revisions list
*/
public function the_revisions_list( $revisions ){
if( ! empty( $revisions ) ){
foreach( $revisions as $rev_key => $rev_val ){
echo '';
echo '';
echo '';
echo '';
}
}
}
/**
* Set Shop Templates Conditions
*/
public function reset_woo_templates_conditions($lang) {
global $wpdb;
$shoppage_id = wc_get_page_id('shop');
delete_post_meta( $shoppage_id, 'mfn_shop_template'.$lang );
delete_option( 'mfn_sinle_product_tmpl_entire_shop'.$lang );
delete_option( 'mfn_sinle_product_tmpl_all_cats'.$lang );
delete_option( 'mfn_sinle_product_tmpl_all_tags'.$lang );
delete_option( 'mfn_shop_archive_tmpl_all_tags'.$lang );
delete_option( 'mfn_shop_archive_tmpl_all_cats'.$lang );
/*$cats = get_terms( 'product_cat', array( 'hide_empty' => false ) );
$tags = get_terms( 'product_tag', array( 'hide_empty' => false ) );
if( count($cats) > 0 ){
foreach($cats as $item){
delete_term_meta( $item->term_id, 'mfn_shop_template'.$lang );
}
}
if( count($tags) > 0 ){
foreach($tags as $tag){
delete_term_meta( $item->term_id, 'mfn_shop_template'.$lang );
}
}*/
$wpdb->delete( $wpdb->prefix . 'termmeta', array( 'meta_key' => 'mfn_shop_template'.$lang ) );
$wpdb->delete( $wpdb->prefix . 'postmeta', array( 'meta_key' => 'mfn_product_template'.$lang ) );
$wpdb->delete( $wpdb->prefix . 'postmeta', array( 'meta_key' => 'mfn_product_cat_template'.$lang ) );
$wpdb->delete( $wpdb->prefix . 'postmeta', array( 'meta_key' => 'mfn_product_tag_template'.$lang ) );
/*$products = get_posts( array( 'post_type' => 'product', 'numberposts' => -1 ) );
if(isset($products) && count($products) > 0){
foreach ($products as $product) {
delete_post_meta( $product->ID, 'mfn_product_template'.$lang );
delete_post_meta( $product->ID, 'mfn_product_cat_template'.$lang );
delete_post_meta( $product->ID, 'mfn_product_tag_template'.$lang );
}
}*/
}
public function set_woo_templates_conditions() {
if( !function_exists('is_woocommerce') ) return false;
global $wpdb;
$shoppage_id = wc_get_page_id('shop');
$mfn_lang = '';
// reset
// wpml fix
if( defined( 'ICL_SITEPRESS_VERSION' ) ){
$default_lang = apply_filters('wpml_default_language', NULL );
$languages = apply_filters( 'wpml_active_languages', NULL );
if( is_iterable($languages) ){
foreach ($languages as $lang) {
$mfn_lang = '';
if( isset($lang['code']) && $lang['code'] != $default_lang ){
$mfn_lang = '_'.$lang['code'];
$this->reset_woo_templates_conditions($mfn_lang);
}
}
}
}else if ( function_exists( 'pll_the_languages' ) ) {
$pll_languages = pll_the_languages(array( 'raw' => true ));
if( is_array($pll_languages) ){
foreach($pll_languages as $pll){
if( pll_default_language() != $pll['slug'] ) $this->reset_woo_templates_conditions( '_'.$pll['slug'] );
}
}
}
$this->reset_woo_templates_conditions('');
// set
/*$templates = get_posts(
array(
'post_type' => 'template',
'orderby' => 'date',
'order' => 'ASC',
'numberposts' => -1,
'meta_query' => array(
'relation' => 'OR',
array(
'key' => 'mfn_template_type',
'compare' => '=',
'value' => 'shop-archive',
),
array(
'key' => 'mfn_template_type',
'compare' => '=',
'value' => 'single-product',
)
)
)
);*/
$templates = $wpdb->get_results( "SELECT p.ID, p.post_title FROM {$wpdb->prefix}posts as p JOIN {$wpdb->prefix}postmeta as m on p.ID = m.post_id WHERE p.post_type = 'template' and p.post_status = 'publish' and m.meta_key = 'mfn_template_type' and m.meta_value IN ( 'shop-archive', 'single-product' ) LIMIT 199" );
if( isset($templates) && is_iterable($templates) ){
foreach($templates as $t=>$tmp){
$mfn_lang = '';
$cond_meta_key = 'mfn_shop_template';
$post_id = $tmp->ID;
if( get_post_meta($post_id, 'mfn_template_type', true) == 'single-product' ){
$cond_meta_key = 'mfn_product_template';
}
// wpml fix
if( defined( 'ICL_SITEPRESS_VERSION' ) ){
$tmpl_lang = apply_filters( 'wpml_post_language_details', NULL, $post_id ) ;
if( isset($tmpl_lang['language_code']) && $tmpl_lang['language_code'] != $default_lang ){
$mfn_lang = '_'.$tmpl_lang['language_code'];
}
$shoppage_id = apply_filters( 'wpml_object_id', wc_get_page_id('shop'), 'page', null, $tmpl_lang['language_code'] );
}else if ( function_exists( 'pll_the_languages' ) ) {
// polylang
if( pll_default_language() != pll_get_post_language( $post_id ) ) $mfn_lang = '_'.pll_get_post_language( $post_id );
}
$conditions = (array) json_decode( get_post_meta($post_id, 'mfn_template_conditions', true) );
if(isset($conditions) && is_array($conditions) && count($conditions) > 0 ){
foreach($conditions as $con){
// entire shop
if( $con->var == 'shop' ){
if($cond_meta_key == 'mfn_shop_template'){
if($con->rule == 'include'){
update_post_meta( $shoppage_id, $cond_meta_key.$mfn_lang, $post_id );
}else{
delete_post_meta( $shoppage_id, $cond_meta_key.$mfn_lang );
}
}else{
if($con->rule == 'include'){
update_option( 'mfn_sinle_product_tmpl_entire_shop'.$mfn_lang, $post_id );
}else{
delete_option( 'mfn_sinle_product_tmpl_entire_shop'.$mfn_lang, $post_id );
}
}
}
// all product categories
if( $con->var == 'productcategory' && $con->productcategory == 'all' ){
// set for all categories
if($cond_meta_key == 'mfn_shop_template'){
/*$cats = get_terms( 'product_cat', array( 'hide_empty' => false ) );
if( count($cats) > 0 ){
foreach($cats as $item){
if($con->rule == 'include'){
update_term_meta( $item->term_id, $cond_meta_key.$mfn_lang, $post_id);
}else{
//delete_term_meta( $item->term_id, $cond_meta_key.$mfn_lang );
update_term_meta( $item->term_id, $cond_meta_key.$mfn_lang, 'excluded');
}
}
}*/
if($con->rule == 'include'){
update_option( 'mfn_shop_archive_tmpl_all_cats'.$mfn_lang, $post_id );
}else{
delete_option( 'mfn_shop_archive_tmpl_all_cats'.$mfn_lang );
}
}else{
if($con->rule == 'include'){
update_option( 'mfn_sinle_product_tmpl_all_cats'.$mfn_lang, $post_id );
}else{
delete_option( 'mfn_sinle_product_tmpl_all_cats'.$mfn_lang, $post_id );
}
}
}
// all product tags
if( $con->var == 'producttag' && $con->producttag == 'all' ){
// set for all tags
$tags = get_terms( 'product_tag', array( 'hide_empty' => false ) );
if( count($tags) > 0 ){
foreach($tags as $tag){
if($cond_meta_key == 'mfn_shop_template'){
/*if($con->rule == 'include'){
update_term_meta( $tag->term_id, $cond_meta_key.$mfn_lang, $post_id);
}else{
//delete_term_meta( $tag->term_id, $cond_meta_key.$mfn_lang);
update_term_meta( $tag->term_id, $cond_meta_key.$mfn_lang, 'excluded');
}*/
if($con->rule == 'include'){
update_option( 'mfn_shop_archive_tmpl_all_tags'.$mfn_lang, $post_id );
}else{
delete_option( 'mfn_shop_archive_tmpl_all_tags'.$mfn_lang );
}
}else{
if($con->rule == 'include'){
update_option( 'mfn_sinle_product_tmpl_all_tags'.$mfn_lang, $post_id );
}else{
delete_option( 'mfn_sinle_product_tmpl_all_tags'.$mfn_lang, $post_id );
}
}
}
}
}
// specified categories
if( $con->var == 'productcategory' && $con->productcategory != 'all' ){
// set for specified cat
if( is_numeric($con->productcategory) ){
if($cond_meta_key == 'mfn_shop_template'){
if($con->rule == 'include'){
update_term_meta( $con->productcategory, $cond_meta_key.$mfn_lang, $post_id );
}else{
update_term_meta( $con->productcategory, $cond_meta_key.$mfn_lang, 'excluded' );
}
}else{
$products = get_posts( array( 'post_type' => 'product', 'numberposts' => -1, 'tax_query' => array( array( 'taxonomy' => 'product_cat', 'field' => 'term_id', 'terms' => $con->productcategory ) ) ) );
if(isset($products) && count($products) > 0){
foreach ($products as $product) {
$product_id = $product->ID;
if( defined( 'ICL_SITEPRESS_VERSION' ) && !empty($tmpl_lang['language_code']) ){
$product_id = apply_filters( 'wpml_object_id', $product->ID, 'product', null, $tmpl_lang['language_code'] );
}
if($con->rule == 'include'){
update_post_meta( $product_id, 'mfn_product_cat_template'.$mfn_lang, $post_id );
}else{
//delete_post_meta( $product_id, 'mfn_product_cat_template'.$mfn_lang );
update_post_meta( $product_id, 'mfn_product_cat_template'.$mfn_lang, 'excluded' );
}
}
}
}
}
}
// specified tags
if( $con->var == 'producttag' && $con->producttag != 'all' ){
// set for specified tag
if( is_numeric($con->producttag) ){
if($cond_meta_key == 'mfn_shop_template'){
if($con->rule == 'include'){
update_term_meta( $con->producttag, $cond_meta_key.$mfn_lang, $post_id );
}else{
update_term_meta( $con->producttag, $cond_meta_key.$mfn_lang, 'excluded' );
//delete_term_meta( $con->producttag, $cond_meta_key );
}
}else{
$products = get_posts( array( 'post_type' => 'product', 'numberposts' => -1, 'tax_query' => array( array( 'taxonomy' => 'product_tag', 'field' => 'term_id', 'terms' => $con->producttag ) ) ) );
if(isset($products) && count($products) > 0){
foreach ($products as $product) {
$product_id = $product->ID;
if( defined( 'ICL_SITEPRESS_VERSION' ) && !empty($tmpl_lang['language_code']) ){
$product_id = apply_filters( 'wpml_object_id', $product->ID, 'product', null, $tmpl_lang['language_code'] );
}
if($con->rule == 'include'){
update_post_meta( $product_id, 'mfn_product_tag_template'.$mfn_lang, $post_id );
}else{
update_post_meta( $product_id, 'mfn_product_tag_template'.$mfn_lang, 'excluded' );
//delete_post_meta( $product_id, 'mfn_product_tag_template'.$mfn_lang );
}
}
}
}
}
}
}
}
}
}
}
public function set_addons_templates_conditions($type) {
global $wpdb;
delete_option( 'mfn_'.$type.'_addons_archives' );
delete_option( 'mfn_'.$type.'_addons_singular' );
$archives = array();
$singular = array();
$default_lang = false;
$all_langs = array();
if( defined( 'ICL_SITEPRESS_VERSION' ) ) {
$default_lang = apply_filters('wpml_default_language', NULL );
$wpml_langs = apply_filters( 'wpml_active_languages', null );
if( is_array($wpml_langs) && is_iterable($wpml_langs) ){
foreach($wpml_langs as $a=>$al){
delete_option( 'mfn_'.$type.'_addons_archives_'.$a );
delete_option( 'mfn_'.$type.'_addons_singular_'.$a );
$all_langs[] = $a;
$archives[$a] = array();
$singular[$a] = array();
}
}
}else if ( function_exists( 'pll_the_languages' ) ) {
$default_lang = pll_default_language();
$pll_languages = pll_the_languages(array( 'raw' => true ));
if( is_array($pll_languages) ) {
foreach($pll_languages as $pll) {
delete_option( 'mfn_'.$type.'_addons_archives_'.$pll['slug'] );
delete_option( 'mfn_'.$type.'_addons_singular_'.$pll['slug'] );
$all_langs[] = $pll['slug'];
$archives[$pll['slug']] = array();
$singular[$pll['slug']] = array();
}
}
}
/*$templates = get_posts(
array(
'post_type' => 'template',
'orderby' => 'date',
'order' => 'ASC',
'numberposts' => -1,
'meta_query' => array(
array(
'key' => 'mfn_template_type',
'compare' => '=',
'value' => $type,
)
)
)
);*/
$templates = $wpdb->get_results( "SELECT p.ID, p.post_title FROM {$wpdb->prefix}posts as p JOIN {$wpdb->prefix}postmeta as m on p.ID = m.post_id WHERE p.post_type = 'template' and p.post_status = 'publish' and m.meta_key = 'mfn_template_type' and m.meta_value = '{$type}' LIMIT 199" );
if(isset($templates) && is_array($templates) && count($templates) > 0){
foreach($templates as $t=>$tmp){
$tmpl_id = $tmp->ID;
$t_lang = '';
$conditions = (array) json_decode( get_post_meta($tmpl_id, 'mfn_template_conditions', true) );
// wpml fix
if( defined( 'ICL_SITEPRESS_VERSION' ) ){
$tmpl_lang = apply_filters( 'wpml_post_language_details', NULL, $tmpl_id ) ;
$t_lang = $tmpl_lang['language_code'];
}else if ( function_exists( 'pll_the_languages' ) ) {
$t_lang = pll_get_post_language( $tmpl_id );
}
if(isset($conditions) && is_array($conditions) && count($conditions) > 0 ) {
foreach($conditions as $con) {
if( $con->var == 'everywhere' ) {
if( $con->rule == 'include' ) {
if( !empty($t_lang) ){
$archives[$t_lang]['post']['all'][] = $tmpl_id;
$archives[$t_lang]['product']['all'][] = $tmpl_id;
$archives[$t_lang]['portfolio']['all'][] = $tmpl_id;
$archives[$t_lang]['offer']['all'][] = $tmpl_id;
$singular[$t_lang]['page']['all'][] = $tmpl_id;
$singular[$t_lang]['post']['all'][] = $tmpl_id;
$singular[$t_lang]['product']['all'][] = $tmpl_id;
$singular[$t_lang]['portfolio']['all'][] = $tmpl_id;
$singular[$t_lang]['offer']['all'][] = $tmpl_id;
}else{
$archives['post']['all'][] = $tmpl_id;
$archives['product']['all'][] = $tmpl_id;
$archives['portfolio']['all'][] = $tmpl_id;
$archives['offer']['all'][] = $tmpl_id;
$singular['page']['all'][] = $tmpl_id;
$singular['post']['all'][] = $tmpl_id;
$singular['product']['all'][] = $tmpl_id;
$singular['portfolio']['all'][] = $tmpl_id;
$singular['offer']['all'][] = $tmpl_id;
}
}
}
if( $con->var == 'archives' ){
if( $con->rule == 'include' ){
if( strpos($con->archives, ':' ) !== false ){
// term id
$explode = explode(':', $con->archives);
$term_id = $explode[1];
$post_type = $explode[0];
// set term by id
if( !empty($t_lang) ){
$archives[$t_lang][$term_id][] = $tmpl_id;
}else{
$archives[$term_id][] = $tmpl_id;
}
}elseif( !empty($con->archives) ){
// all term
if( !empty($t_lang) ){
$archives[$t_lang][$con->archives]['all'][] = $tmpl_id;
}else{
$archives[$con->archives]['all'][] = $tmpl_id;
}
}elseif( empty($con->archives) ){
// all archives
if( !empty($t_lang) ){
$archives[$t_lang]['post']['all'][] = $tmpl_id;
$archives[$t_lang]['product']['all'][] = $tmpl_id;
$archives[$t_lang]['portfolio']['all'][] = $tmpl_id;
$archives[$t_lang]['offer']['all'][] = $tmpl_id;
}else{
$archives['post']['all'][] = $tmpl_id;
$archives['product']['all'][] = $tmpl_id;
$archives['portfolio']['all'][] = $tmpl_id;
$archives['offer']['all'][] = $tmpl_id;
}
}
}elseif( $con->rule == 'exclude' ){
if( strpos($con->archives, ':' ) !== false ){
// term id
$explode = explode(':', $con->archives);
$term_id = $explode[1];
$post_type = $explode[0];
// set term by id
if( !empty($t_lang) ){
$archives[$t_lang][$term_id]['exclude'][] = $tmpl_id;
}else{
$archives[$term_id]['exclude'][] = $tmpl_id;
}
}elseif( !empty($con->archives) && is_array( $archives[$t_lang][$con->archives]['all'] ) ){
// all term
foreach( $archives[$t_lang][$con->archives]['all'] as $t=>$t_id ){
if( !empty($t_lang) ){
if( $t_id == $tmpl_id ) unset($archives[$t_lang][$con->archives]['all'][$t]);
}else{
if( $t_id == $tmpl_id ) unset($archives[$con->archives]['all'][$t]);
}
}
}elseif( empty($con->archives) ){
if( !empty($t_lang) ){
if( !empty($archives[$t_lang]['post']['all'][$tmpl_id]) ) unset( $archives[$t_lang]['post']['all'][$tmpl_id] );
if( !empty($archives[$t_lang]['product']['all'][$tmpl_id]) ) unset( $archives[$t_lang]['product']['all'][$tmpl_id] );
if( !empty($archives[$t_lang]['portfolio']['all'][$tmpl_id]) ) unset( $archives[$t_lang]['portfolio']['all'][$tmpl_id] );
if( !empty($archives[$t_lang]['offer']['all'][$tmpl_id]) ) unset( $archives[$t_lang]['offer']['all'][$tmpl_id] );
}else{
if( !empty($archives['post']['all'][$tmpl_id]) ) unset( $archives['post']['all'][$tmpl_id] );
if( !empty($archives['product']['all'][$tmpl_id]) ) unset( $archives['product']['all'][$tmpl_id] );
if( !empty($archives['portfolio']['all'][$tmpl_id]) ) unset( $archives['portfolio']['all'][$tmpl_id] );
if( !empty($archives['offer']['all'][$tmpl_id]) ) unset( $archives['offer']['all'][$tmpl_id] );
}
}
}
}elseif( $con->var == 'singular' ){
if( $con->rule == 'include' ){
if( strpos($con->singular, ':' ) !== false ){
// term id
$explode = explode(':', $con->singular);
$term_id = $explode[1];
$post_type = $explode[0];
// set term by id
if( !empty($t_lang) ){
$singular[$t_lang][$term_id][] = $tmpl_id;
}else{
$singular[$term_id][] = $tmpl_id;
}
}elseif( !empty($con->singular) ){
// all term
if( !empty($t_lang) ){
$singular[$t_lang][$con->singular]['all'][] = $tmpl_id;
}else{
$singular[$con->singular]['all'][] = $tmpl_id;
}
}elseif( empty($con->singular) ){
// all singular
if( !empty($t_lang) ){
$singular[$t_lang]['page']['all'][] = $tmpl_id;
$singular[$t_lang]['post']['all'][] = $tmpl_id;
$singular[$t_lang]['product']['all'][] = $tmpl_id;
$singular[$t_lang]['portfolio']['all'][] = $tmpl_id;
$singular[$t_lang]['offer']['all'][] = $tmpl_id;
}else{
$singular['page']['all'][] = $tmpl_id;
$singular['post']['all'][] = $tmpl_id;
$singular['product']['all'][] = $tmpl_id;
$singular['portfolio']['all'][] = $tmpl_id;
$singular['offer']['all'][] = $tmpl_id;
}
}
}elseif( $con->rule == 'exclude' ){
if( strpos($con->singular, ':' ) !== false ){
// term id
$explode = explode(':', $con->singular);
$term_id = $explode[1];
$post_type = $explode[0];
// set term by id
if( !empty($t_lang) ){
$singular[$t_lang][$term_id]['exclude'][] = $tmpl_id;
}else{
$singular[$term_id]['exclude'][] = $tmpl_id;
}
}elseif( !empty($con->singular) && is_array( $singular[$t_lang][$con->singular]['all'] ) ){
// all term
foreach( $singular[$t_lang][$con->singular]['all'] as $t=>$t_id ){
if( !empty($t_lang) ){
if( $t_id == $tmpl_id ) unset($singular[$t_lang][$con->singular]['all'][$t]);
}else{
if( $t_id == $tmpl_id ) unset($singular[$con->singular]['all'][$t]);
}
}
}elseif( empty($con->singular) ){
if( !empty($t_lang) ){
if( !empty($singular[$t_lang]['page']['all'][$tmpl_id]) ) unset( $singular[$t_lang]['page']['all'][$tmpl_id] );
if( !empty($singular[$t_lang]['post']['all'][$tmpl_id]) ) unset( $singular[$t_lang]['post']['all'][$tmpl_id] );
if( !empty($singular[$t_lang]['product']['all'][$tmpl_id]) ) unset( $singular[$t_lang]['product']['all'][$tmpl_id] );
if( !empty($singular[$t_lang]['portfolio']['all'][$tmpl_id]) ) unset( $singular[$t_lang]['portfolio']['all'][$tmpl_id] );
if( !empty($singular[$t_lang]['offer']['all'][$tmpl_id]) ) unset( $singular[$t_lang]['offer']['all'][$tmpl_id] );
}else{
if( !empty($singular['page']['all'][$tmpl_id]) ) unset( $singular['page']['all'][$tmpl_id] );
if( !empty($singular['post']['all'][$tmpl_id]) ) unset( $singular['post']['all'][$tmpl_id] );
if( !empty($singular['product']['all'][$tmpl_id]) ) unset( $singular['product']['all'][$tmpl_id] );
if( !empty($singular['portfolio']['all'][$tmpl_id]) ) unset( $singular['portfolio']['all'][$tmpl_id] );
if( !empty($singular['offer']['all'][$tmpl_id]) ) unset( $singular['offer']['all'][$tmpl_id] );
}
}
}
}
}
}
}
}
if( !empty($all_langs) && is_iterable($all_langs) ) {
// with WPML
foreach($all_langs as $a) {
if( $a == $default_lang ) {
// default lang
update_option( 'mfn_'.$type.'_addons_archives', $archives[$a] );
update_option( 'mfn_'.$type.'_addons_singular', $singular[$a] );
}else{
// another langs
update_option( 'mfn_'.$type.'_addons_archives_'.$a, $archives[$a] );
update_option( 'mfn_'.$type.'_addons_singular_'.$a, $singular[$a] );
}
}
}else{
// no WPML
update_option( 'mfn_'.$type.'_addons_archives', $archives );
update_option( 'mfn_'.$type.'_addons_singular', $singular );
}
}
/**
* Set Post Templates Conditions
*/
public function set_post_templates_conditions($type) {
global $wpdb;
delete_option( 'mfn_'.$type.'_template' );
$helper_array = array();
$default_lang = false;
$all_langs = false;
if( defined( 'ICL_SITEPRESS_VERSION' ) ){
$default_lang = apply_filters('wpml_default_language', NULL );
$all_langs = apply_filters( 'wpml_active_languages', null );
if( is_array($all_langs) && is_iterable($all_langs) ){
foreach($all_langs as $a=>$al){
delete_option( 'mfn_'.$type.'_template'.$a );
$helper_array[$a] = array();
}
}
}else if ( function_exists( 'pll_the_languages' ) ) {
$pll_languages = pll_the_languages(array( 'raw' => true ));
if( is_array($pll_languages) ) {
foreach($pll_languages as $pll) {
//if( pll_default_language() != $pll['slug'] ) $this->reset_global_templates_conditions($type.'_'.$pll['slug'] );
delete_option( 'mfn_'.$type.'_template'.$pll['slug'] );
$helper_array[$pll['slug']] = array();
}
}
}
/*$templates = get_posts(
array(
'post_type' => 'template',
'orderby' => 'date',
'order' => 'ASC',
'numberposts' => -1,
'meta_query' => array(
array(
'key' => 'mfn_template_type',
'compare' => '=',
'value' => $type,
)
)
)
);*/
$templates = $wpdb->get_results( "SELECT p.ID, p.post_title FROM {$wpdb->prefix}posts as p JOIN {$wpdb->prefix}postmeta as m on p.ID = m.post_id WHERE p.post_type = 'template' and p.post_status = 'publish' and m.meta_key = 'mfn_template_type' and m.meta_value = '{$type}' LIMIT 199" );
if(isset($templates) && is_array($templates) && count($templates) > 0){
foreach($templates as $t=>$tmp){
$tmpl_id = $tmp->ID;
$t_lang = '';
$conditions = (array) json_decode( get_post_meta($tmpl_id, 'mfn_template_conditions', true) );
// wpml fix
if( defined( 'ICL_SITEPRESS_VERSION' ) ){
$tmpl_lang = apply_filters( 'wpml_post_language_details', NULL, $tmpl_id ) ;
$t_lang = $tmpl_lang['language_code'];
}else if ( function_exists( 'pll_the_languages' ) ) {
$t_lang = pll_get_post_language( $tmpl_id );
}
if(isset($conditions) && is_array($conditions) && count($conditions) > 0 ){
foreach($conditions as $con){
if( $con->rule == 'include' ){
if( $con->var == 'all' ){
if( !empty($t_lang) ){
$helper_array[$t_lang]['all'][] = $tmpl_id;
}else{
$helper_array['all'][] = $tmpl_id;
}
}else{
if( !empty($t_lang) ){
$helper_array[$t_lang][$con->var][$con->{$con->var}][] = $tmpl_id;
}else{
$helper_array[$con->var][$con->{$con->var}][] = $tmpl_id;
}
}
}elseif( $con->rule == 'exclude' ){
if( $con->var != 'all' ){
if( !empty($t_lang) ){
$helper_array[$t_lang][$con->var][$con->{$con->var}]['exclude'][] = $tmpl_id;
}else{
$helper_array[$con->var][$con->{$con->var}]['exclude'][] = $tmpl_id;
}
}
}
}
}
}
}
if( defined( 'ICL_SITEPRESS_VERSION' ) && is_array($all_langs) && is_iterable($all_langs) ){
// with WPML
foreach($all_langs as $a=>$al){
if( $a == $default_lang ){
// default lang
update_option( 'mfn_'.$type.'_template', $helper_array[$a] );
}else{
// another langs
update_option( 'mfn_'.$type.'_template_'.$a, $helper_array[$a] );
}
}
}else if ( function_exists( 'pll_the_languages' ) ) {
// polylang
$pll_languages = pll_the_languages(array( 'raw' => true ));
if( is_array($pll_languages) ) {
foreach($pll_languages as $pll) {
if( pll_default_language() != $pll['slug'] ) {
update_option( 'mfn_'.$type.'_template_'.$pll['slug'], $helper_array[$pll['slug']] );
}else{
update_option( 'mfn_'.$type.'_template', $helper_array[$pll['slug']] );
}
}
}
}else{
// no WPML
update_option( 'mfn_'.$type.'_template', $helper_array );
}
}
/**
* Set Header Templates Conditions
*/
public function reset_global_templates_conditions($type) {
global $wpdb;
delete_option( 'mfn_'.$type.'_entire_site' );
delete_option( 'mfn_'.$type.'_post_single' );
delete_option( 'mfn_'.$type.'_page_single' );
delete_option( 'mfn_'.$type.'_product_single' );
delete_option( 'mfn_'.$type.'_portfolio_single' );
delete_option( 'mfn_'.$type.'_offer_single' );
delete_option( 'mfn_'.$type.'_post_single_excluded' );
delete_option( 'mfn_'.$type.'_page_single_excluded' );
delete_option( 'mfn_'.$type.'_product_single_excluded' );
delete_option( 'mfn_'.$type.'_portfolio_single_excluded' );
delete_option( 'mfn_'.$type.'_offer_single_excluded' );
delete_option( 'mfn_'.$type.'_post_arch' );
delete_option( 'mfn_'.$type.'_product_arch' );
delete_option( 'mfn_'.$type.'_portfolio_arch' );
delete_option( 'mfn_'.$type.'_offer_arch' );
delete_option( 'mfn_'.$type.'_page_arch' );
delete_option( 'mfn_'.$type.'_post_arch_excluded' );
delete_option( 'mfn_'.$type.'_product_arch_excluded' );
delete_option( 'mfn_'.$type.'_portfolio_arch_excluded' );
delete_option( 'mfn_'.$type.'_offer_arch_excluded' );
delete_option( 'mfn_'.$type.'_page_arch_excluded' );
$wpdb->delete( $wpdb->prefix . 'postmeta', array( 'meta_key' => 'mfn_'.$type.'_post' ) );
$wpdb->delete( $wpdb->prefix . 'termmeta', array( 'meta_key' => 'mfn_'.$type.'_term' ) );
$wpdb->delete( $wpdb->prefix . 'postmeta', array( 'meta_key' => 'mfn_'.$type.'_post_excluded' ) );
$wpdb->delete( $wpdb->prefix . 'termmeta', array( 'meta_key' => 'mfn_'.$type.'_term_excluded' ) );
}
public function set_global_templates_conditions($type) {
global $wpdb;
// mfn-header-tmpl-post
// mfn-header-tmpl-term
// mfn-header-tmpl-{post/product/portfolio/offer}
// mfn-header-tmpl-entire-site
// reset
// wpml fix
if( defined( 'ICL_SITEPRESS_VERSION' ) ){
$default_lang = apply_filters('wpml_default_language', NULL );
$languages = apply_filters( 'wpml_active_languages', NULL );
if( is_iterable($languages) ){
foreach ($languages as $lang) {
if( isset($lang['code']) && $lang['code'] != $default_lang ){
$this->reset_global_templates_conditions($type.'_'.$lang['code']);
}
}
}
}else if ( function_exists( 'pll_the_languages' ) ) {
$pll_languages = pll_the_languages(array( 'raw' => true ));
if( is_array($pll_languages) ) {
foreach($pll_languages as $pll) {
if( pll_default_language() != $pll['slug'] ) $this->reset_global_templates_conditions($type.'_'.$pll['slug'] );
}
}
}
$this->reset_global_templates_conditions($type);
// set
/*$templates = get_posts(
array(
'post_type' => 'template',
'orderby' => 'date',
'order' => 'ASC',
'numberposts' => -1,
'meta_query' => array(
array(
'key' => 'mfn_template_type',
'compare' => '=',
'value' => $type,
)
)
)
);*/
$templates = $wpdb->get_results( "SELECT p.ID, p.post_title FROM {$wpdb->prefix}posts as p JOIN {$wpdb->prefix}postmeta as m on p.ID = m.post_id WHERE p.post_type = 'template' and p.post_status = 'publish' and m.meta_key = 'mfn_template_type' and m.meta_value = '{$type}' LIMIT 199" );
if(isset($templates) && is_array($templates) && count($templates) > 0){
foreach($templates as $t=>$tmp){
$t_lang = '';
$tmpl_id = $tmp->ID;
$conditions = (array) json_decode( get_post_meta($tmpl_id, 'mfn_template_conditions', true) );
// wpml fix
if( defined( 'ICL_SITEPRESS_VERSION' ) ){
$tmpl_lang = apply_filters( 'wpml_post_language_details', NULL, $tmpl_id ) ;
if( isset($tmpl_lang['language_code']) && $tmpl_lang['language_code'] != $default_lang ){
$t_lang = '_'.$tmpl_lang['language_code'];
}
}else if ( function_exists( 'pll_the_languages' ) ) {
if( pll_default_language() != pll_get_post_language( $tmpl_id ) ) $t_lang = '_'.pll_get_post_language( $tmpl_id );
}
if(isset($conditions) && is_array($conditions) && count($conditions) > 0 ){
foreach($conditions as $con){
$term = 'category';
if( !empty($con->archives) ){
if( strpos($con->archives, 'product') !== false ) $term = 'product_cat';
if( strpos($con->archives, 'offer') !== false ) $term = 'offer_types';
if( strpos($con->archives, 'portfolio') !== false ) $term = 'portfolio_types';
}else if( !empty($con->singular) ){
if( strpos($con->singular, 'product') !== false ) $term = 'product_cat';
if( strpos($con->singular, 'offer') !== false ) $term = 'offer_types';
if( strpos($con->singular, 'portfolio') !== false ) $term = 'portfolio_types';
}
// entire site
if( $con->var == 'everywhere' ){
if( $con->rule == 'include' ){
update_option( 'mfn_'.$type.$t_lang.'_entire_site', $tmpl_id );
/*update_option( 'mfn_'.$type.$t_lang.'_post_single', $tmpl_id );
update_option( 'mfn_'.$type.$t_lang.'_product_single', $tmpl_id );
update_option( 'mfn_'.$type.$t_lang.'_portfolio_single', $tmpl_id );
update_option( 'mfn_'.$type.$t_lang.'_offer_single', $tmpl_id );
update_option( 'mfn_'.$type.$t_lang.'_page_single', $tmpl_id );
update_option( 'mfn_'.$type.$t_lang.'_post_arch', $tmpl_id );
update_option( 'mfn_'.$type.$t_lang.'_product_arch', $tmpl_id );
update_option( 'mfn_'.$type.$t_lang.'_portfolio_arch', $tmpl_id );
update_option( 'mfn_'.$type.$t_lang.'_offer_arch', $tmpl_id );
update_option( 'mfn_'.$type.$t_lang.'_page_arch', $tmpl_id );*/
}
}
// terms
if( $con->var == 'archives' ){
if( $con->rule == 'include' ){
if( strpos($con->archives, ':' ) !== false ){
// term id
$explode = explode(':', $con->archives);
$term_id = $explode[1];
$post_type = $explode[0];
// set term by id
update_term_meta( $term_id, 'mfn_'.$type.$t_lang.'_term', $tmpl_id );
}elseif( !empty($con->archives) ){
// all term
update_option( 'mfn_'.$type.$t_lang.'_'.$con->archives.'_arch', $tmpl_id );
}elseif( empty($con->archives) ){
update_option( 'mfn_'.$type.$t_lang.'_post_arch', $tmpl_id );
update_option( 'mfn_'.$type.$t_lang.'_product_arch', $tmpl_id );
update_option( 'mfn_'.$type.$t_lang.'_portfolio_arch', $tmpl_id );
update_option( 'mfn_'.$type.$t_lang.'_offer_arch', $tmpl_id );
}
}elseif( $con->rule == 'exclude' ){
if( strpos($con->archives, ':' ) !== false ){
// term id
$explode = explode(':', $con->archives);
$term_id = $explode[1];
$post_type = $explode[0];
// set term by id
update_term_meta( $term_id, 'mfn_'.$type.$t_lang.'_term_excluded', $term_id );
}elseif( !empty($con->archives) ){
// all term
update_option( 'mfn_'.$type.$t_lang.'_'.$con->archives.'_arch_excluded', $tmpl_id );
}elseif( empty($con->archives) ){
update_option( 'mfn_'.$type.$t_lang.'_post_arch_excluded', $tmpl_id );
update_option( 'mfn_'.$type.$t_lang.'_product_arch_excluded', $tmpl_id );
update_option( 'mfn_'.$type.$t_lang.'_portfolio_arch_excluded', $tmpl_id );
update_option( 'mfn_'.$type.$t_lang.'_offer_arch_excluded', $tmpl_id );
}
}
}
// singulars
if( $con->var == 'singular' ){
if( $con->rule == 'include' ){
if( strpos($con->singular, ':' ) !== false ){
$explode = explode(':', $con->singular);
$term_id = $explode[1];
$post_type = $explode[0];
$posts = get_posts( array('post_type' => $post_type, 'numberposts' => -1, 'tax_query' => array( array( 'taxonomy' => $term, 'field' => 'term_id', 'terms' => $term_id ) ) ) );
if( is_iterable($posts) ){
foreach( $posts as $post ){
update_post_meta( $post->ID, 'mfn_'.$type.$t_lang.'_post', $tmpl_id );
}
}
}elseif( !empty($con->singular) ){
update_option( 'mfn_'.$type.$t_lang.'_'.$con->singular.'_single', $tmpl_id );
}elseif( empty($con->singular) ){
update_option( 'mfn_'.$type.$t_lang.'_post_single', $tmpl_id );
update_option( 'mfn_'.$type.$t_lang.'_product_single', $tmpl_id );
update_option( 'mfn_'.$type.$t_lang.'_portfolio_single', $tmpl_id );
update_option( 'mfn_'.$type.$t_lang.'_offer_single', $tmpl_id );
update_option( 'mfn_'.$type.$t_lang.'_page_single', $tmpl_id );
}
}elseif( $con->rule == 'exclude' ){
if( strpos($con->singular, ':' ) !== false ){
$explode = explode(':', $con->singular);
$term_id = $explode[1];
$post_type = $explode[0];
$posts = get_posts( array('post_type' => $post_type, 'numberposts' => -1, 'tax_query' => array( array( 'taxonomy' => $term, 'field' => 'term_id', 'terms' => $term_id ) ) ) );
if( is_iterable($posts) ){
foreach( $posts as $post ){
update_post_meta( $post->ID, 'mfn_'.$type.$t_lang.'_post_excluded', $tmpl_id );
}
}
}elseif( !empty($con->singular) ){
update_option( 'mfn_'.$type.$t_lang.'_'.$con->singular.'_single', $tmpl_id );
}elseif( empty($con->singular) ){
update_option( 'mfn_'.$type.$t_lang.'_post_single_excluded', $tmpl_id );
update_option( 'mfn_'.$type.$t_lang.'_product_single_excluded', $tmpl_id );
update_option( 'mfn_'.$type.$t_lang.'_portfolio_single_excluded', $tmpl_id );
update_option( 'mfn_'.$type.$t_lang.'_offer_single_excluded', $tmpl_id );
update_option( 'mfn_'.$type.$t_lang.'_page_single_excluded', $tmpl_id );
}
}
}
if( $con->var == 'other' ){
if( $con->rule == 'include' && !empty($con->other) && $con->other == 'search-page' ) {
update_option( 'mfn_'.$type.$t_lang.'_search_page', $tmpl_id );
}
}
}
}
}
}
}
}
}