function save($post_id) { foreach ($this->fields as $meta_key => $field) { if (isset($_POST[$meta_key])) { $args = array('meta_key' => $meta_key, 'meta_value' => 1, 'posts_per_page' => 1); $layouts = extra_get_layouts($args); if (!empty($layouts->post)) { delete_post_meta($layouts->post->ID, $meta_key); } update_post_meta($post_id, $meta_key, 1); } else { delete_post_meta($post_id, $meta_key); } } if (isset($_POST[EXTRA_HOME_LAYOUT_META_KEY])) { update_option('show_on_front', 'layout'); } else { update_option('show_on_front', 'posts'); } }
function extra_save_show_on_front_layout() { global $wp_customize; if (is_a($wp_customize, 'WP_Customize_Manager') && $wp_customize->is_preview()) { $show_on_front_layout = $wp_customize->get_setting('show_on_front_layout')->post_value(); $show_on_front = $wp_customize->get_setting('show_on_front')->post_value(get_option('show_on_front')); $args = array('meta_key' => EXTRA_HOME_LAYOUT_META_KEY, 'meta_value' => 1, 'posts_per_page' => 1); $layouts = extra_get_layouts($args); wp_reset_postdata(); if (!empty($layouts->post)) { delete_post_meta($layouts->post->ID, EXTRA_HOME_LAYOUT_META_KEY); } if ($show_on_front == 'layout' && !empty($show_on_front_layout)) { update_post_meta(absint($show_on_front_layout), EXTRA_HOME_LAYOUT_META_KEY, 1); } } }
function _et_extra_get_tax_layout() { global $wp_query; $args = array('posts_per_page' => 1); if (is_category()) { $args['tax_query'] = array(array('taxonomy' => 'category', 'field' => 'id', 'terms' => array(get_query_var('cat')), 'operator' => 'IN')); } elseif (is_tax()) { $args['tax_query'] = array(array('taxonomy' => 'tag', 'field' => 'id', 'terms' => array(get_query_var('tag')), 'operator' => 'IN')); } else { return false; } $layouts = extra_get_layouts($args); return !empty($layouts->posts) ? $layouts->posts[0] : false; }
function et_pb_extra_add_default_layouts() { $et_builder_layouts = et_pb_extra_get_default_layouts(); $is_home_layout_exists = false; $is_index_layout_exists = false; $layout_args = array('posts_per_page' => -1, 'nopaging' => true, 'post_status' => 'publish', 'meta_key' => '_et_pb_predefined_default_layout', 'meta_value' => 'on'); $layout_args['meta_query'] = array(array('key' => '_et_pb_predefined_default_type', 'value' => 'home', 'compare' => 'IN')); // get the predefiend default home layouts $home_layouts_query = extra_get_layouts($layout_args); $layout_args['meta_query'] = array(array('key' => '_et_pb_predefined_default_type', 'value' => 'index', 'compare' => 'IN')); // get the predefiend default layouts $default_layouts_query = extra_get_layouts($layout_args); if ($home_layouts_query->posts) { $is_home_layout_exists = true; } if ($default_layouts_query->posts) { $is_index_layout_exists = true; } // do not proceed if both layouts already exist if ($is_index_layout_exists && $is_home_layout_exists) { return; } if (isset($et_builder_layouts) && is_array($et_builder_layouts)) { foreach ($et_builder_layouts as $et_builder_layout) { // do nothing if current layout already exist if (isset($et_builder_layout['default_home']) && $et_builder_layout['default_home'] && $is_home_layout_exists || isset($et_builder_layout['default_index']) && $et_builder_layout['default_index'] && $is_index_layout_exists) { continue; } $meta = array('_et_pb_predefined_default_layout' => 'on', '_et_pb_predefined_default_type' => $et_builder_layout['default_type']); // add meta for default home and index page layouts if ('home' === $et_builder_layout['default_type'] && false === extra_get_home_layout_id()) { $meta['_extra_layout_home'] = 1; } else { if ('index' === $et_builder_layout['default_type'] && false === extra_get_default_layout_id()) { $meta['_extra_layout_default'] = 1; } } et_pb_create_extra_layout($et_builder_layout['name'], $et_builder_layout['content'], $meta); } } }