Edit File by line

Deprecated: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in /home/sportsfever/public_html/filemanger/function.php on line 93
/home/sportsfe.../httpdocs/wp-conte.../themes/Divi/includes/builder/frontend.../theme-bu...
File: theme-builder.php
<?php
[0] Fix | Delete
if ( ! defined( 'ET_THEME_BUILDER_DIR' ) ) {
[1] Fix | Delete
define( 'ET_THEME_BUILDER_DIR', ET_BUILDER_DIR . 'frontend-builder/theme-builder/' );
[2] Fix | Delete
}
[3] Fix | Delete
[4] Fix | Delete
if ( ! defined( 'ET_THEME_BUILDER_THEME_BUILDER_POST_TYPE' ) ) {
[5] Fix | Delete
define( 'ET_THEME_BUILDER_THEME_BUILDER_POST_TYPE', 'et_theme_builder' );
[6] Fix | Delete
}
[7] Fix | Delete
[8] Fix | Delete
if ( ! defined( 'ET_THEME_BUILDER_TEMPLATE_POST_TYPE' ) ) {
[9] Fix | Delete
define( 'ET_THEME_BUILDER_TEMPLATE_POST_TYPE', 'et_template' );
[10] Fix | Delete
}
[11] Fix | Delete
[12] Fix | Delete
if ( ! defined( 'ET_THEME_BUILDER_HEADER_LAYOUT_POST_TYPE' ) ) {
[13] Fix | Delete
define( 'ET_THEME_BUILDER_HEADER_LAYOUT_POST_TYPE', 'et_header_layout' );
[14] Fix | Delete
}
[15] Fix | Delete
[16] Fix | Delete
if ( ! defined( 'ET_THEME_BUILDER_BODY_LAYOUT_POST_TYPE' ) ) {
[17] Fix | Delete
define( 'ET_THEME_BUILDER_BODY_LAYOUT_POST_TYPE', 'et_body_layout' );
[18] Fix | Delete
}
[19] Fix | Delete
[20] Fix | Delete
if ( ! defined( 'ET_THEME_BUILDER_FOOTER_LAYOUT_POST_TYPE' ) ) {
[21] Fix | Delete
define( 'ET_THEME_BUILDER_FOOTER_LAYOUT_POST_TYPE', 'et_footer_layout' );
[22] Fix | Delete
}
[23] Fix | Delete
[24] Fix | Delete
if ( ! defined( 'ET_THEME_BUILDER_SETTING_SEPARATOR' ) ) {
[25] Fix | Delete
// Must be a single character.
[26] Fix | Delete
define( 'ET_THEME_BUILDER_SETTING_SEPARATOR', ':' );
[27] Fix | Delete
}
[28] Fix | Delete
[29] Fix | Delete
if ( ! defined( 'ET_THEME_BUILDER_DYNAMIC_CONTENT_REGEX' ) ) {
[30] Fix | Delete
define( 'ET_THEME_BUILDER_DYNAMIC_CONTENT_REGEX', '/@ET-DC@(.*?)@/' );
[31] Fix | Delete
}
[32] Fix | Delete
[33] Fix | Delete
require_once ET_THEME_BUILDER_DIR . 'ThemeBuilderApiErrors.php';
[34] Fix | Delete
require_once ET_THEME_BUILDER_DIR . 'ThemeBuilderRequest.php';
[35] Fix | Delete
require_once ET_THEME_BUILDER_DIR . 'template-setting-validations.php';
[36] Fix | Delete
require_once ET_THEME_BUILDER_DIR . 'api.php';
[37] Fix | Delete
require_once ET_THEME_BUILDER_DIR . 'admin.php';
[38] Fix | Delete
require_once ET_THEME_BUILDER_DIR . 'frontend.php';
[39] Fix | Delete
require_once ET_THEME_BUILDER_DIR . 'dynamic-content.php';
[40] Fix | Delete
[41] Fix | Delete
// Conditional Includes.
[42] Fix | Delete
if ( et_is_woocommerce_plugin_active() ) {
[43] Fix | Delete
require_once ET_THEME_BUILDER_DIR . 'woocommerce.php';
[44] Fix | Delete
require_once ET_THEME_BUILDER_DIR . 'WoocommerceProductVariationPlaceholder.php';
[45] Fix | Delete
require_once ET_THEME_BUILDER_DIR . 'WoocommerceProductVariablePlaceholder.php';
[46] Fix | Delete
require_once ET_THEME_BUILDER_DIR . 'WoocommerceProductVariablePlaceholderDataStoreCPT.php';
[47] Fix | Delete
}
[48] Fix | Delete
[49] Fix | Delete
if ( et_core_is_wpml_plugin_active() ) {
[50] Fix | Delete
require_once ET_THEME_BUILDER_DIR . 'wpml.php';
[51] Fix | Delete
}
[52] Fix | Delete
[53] Fix | Delete
/**
[54] Fix | Delete
* Register all relevant Theme Builder entities such as post types.
[55] Fix | Delete
*
[56] Fix | Delete
* @since 4.0
[57] Fix | Delete
*
[58] Fix | Delete
* @return void
[59] Fix | Delete
*/
[60] Fix | Delete
function et_theme_builder_register_entities() {
[61] Fix | Delete
$publicly_queryable = isset( $_GET['et_fb'] ) && '1' === $_GET['et_fb'] && et_pb_is_allowed( 'use_visual_builder' );
[62] Fix | Delete
[63] Fix | Delete
register_post_type( ET_THEME_BUILDER_THEME_BUILDER_POST_TYPE, array(
[64] Fix | Delete
'labels' => array(
[65] Fix | Delete
'name' => esc_html__( 'Theme Builders', 'et_builder' ),
[66] Fix | Delete
'singular_name' => esc_html__( 'Theme Builder', 'et_builder' ),
[67] Fix | Delete
'add_new' => esc_html__( 'Add New', 'et_builder' ),
[68] Fix | Delete
'add_new_item' => esc_html__( 'Add New Theme Builder', 'et_builder' ),
[69] Fix | Delete
'edit_item' => esc_html__( 'Edit Theme Builder', 'et_builder' ),
[70] Fix | Delete
'new_item' => esc_html__( 'New Theme Builder', 'et_builder' ),
[71] Fix | Delete
'all_items' => esc_html__( 'All Theme Builders', 'et_builder' ),
[72] Fix | Delete
'view_item' => esc_html__( 'View Theme Builder', 'et_builder' ),
[73] Fix | Delete
'search_items' => esc_html__( 'Search Theme Builders', 'et_builder' ),
[74] Fix | Delete
'not_found' => esc_html__( 'Nothing found', 'et_builder' ),
[75] Fix | Delete
'not_found_in_trash' => esc_html__( 'Nothing found in Trash', 'et_builder' ),
[76] Fix | Delete
'parent_item_colon' => '',
[77] Fix | Delete
),
[78] Fix | Delete
'can_export' => false,
[79] Fix | Delete
'capability_type' => 'post',
[80] Fix | Delete
'has_archive' => false,
[81] Fix | Delete
'hierarchical' => false,
[82] Fix | Delete
'map_meta_cap' => true,
[83] Fix | Delete
'public' => false,
[84] Fix | Delete
'publicly_queryable' => false,
[85] Fix | Delete
'query_var' => false,
[86] Fix | Delete
'show_ui' => false,
[87] Fix | Delete
'show_in_rest' => false,
[88] Fix | Delete
'rewrite' => true,
[89] Fix | Delete
'supports' => array( 'title', 'author' ),
[90] Fix | Delete
) );
[91] Fix | Delete
[92] Fix | Delete
register_post_type( ET_THEME_BUILDER_TEMPLATE_POST_TYPE, array(
[93] Fix | Delete
'labels' => array(
[94] Fix | Delete
'name' => esc_html__( 'Templates', 'et_builder' ),
[95] Fix | Delete
'singular_name' => esc_html__( 'Template', 'et_builder' ),
[96] Fix | Delete
'add_new' => esc_html__( 'Add New', 'et_builder' ),
[97] Fix | Delete
'add_new_item' => esc_html__( 'Add New Template', 'et_builder' ),
[98] Fix | Delete
'edit_item' => esc_html__( 'Edit Template', 'et_builder' ),
[99] Fix | Delete
'new_item' => esc_html__( 'New Template', 'et_builder' ),
[100] Fix | Delete
'all_items' => esc_html__( 'All Templates', 'et_builder' ),
[101] Fix | Delete
'view_item' => esc_html__( 'View Template', 'et_builder' ),
[102] Fix | Delete
'search_items' => esc_html__( 'Search Templates', 'et_builder' ),
[103] Fix | Delete
'not_found' => esc_html__( 'Nothing found', 'et_builder' ),
[104] Fix | Delete
'not_found_in_trash' => esc_html__( 'Nothing found in Trash', 'et_builder' ),
[105] Fix | Delete
'parent_item_colon' => '',
[106] Fix | Delete
),
[107] Fix | Delete
'can_export' => true,
[108] Fix | Delete
'capability_type' => 'post',
[109] Fix | Delete
'has_archive' => false,
[110] Fix | Delete
'hierarchical' => false,
[111] Fix | Delete
'map_meta_cap' => true,
[112] Fix | Delete
'public' => false,
[113] Fix | Delete
'publicly_queryable' => $publicly_queryable,
[114] Fix | Delete
'query_var' => false,
[115] Fix | Delete
'show_ui' => false,
[116] Fix | Delete
'show_in_rest' => false,
[117] Fix | Delete
'rewrite' => true,
[118] Fix | Delete
'supports' => array( 'title', 'author' ),
[119] Fix | Delete
) );
[120] Fix | Delete
[121] Fix | Delete
register_post_type( ET_THEME_BUILDER_HEADER_LAYOUT_POST_TYPE, array(
[122] Fix | Delete
'labels' => array(
[123] Fix | Delete
'name' => esc_html__( 'Header Layouts', 'et_builder' ),
[124] Fix | Delete
'singular_name' => esc_html__( 'Header Layout', 'et_builder' ),
[125] Fix | Delete
'add_new' => esc_html__( 'Add New', 'et_builder' ),
[126] Fix | Delete
'add_new_item' => esc_html__( 'Add New Header Layout', 'et_builder' ),
[127] Fix | Delete
'edit_item' => esc_html__( 'Edit Header Layout', 'et_builder' ),
[128] Fix | Delete
'new_item' => esc_html__( 'New Header Layout', 'et_builder' ),
[129] Fix | Delete
'all_items' => esc_html__( 'All Header Layouts', 'et_builder' ),
[130] Fix | Delete
'view_item' => esc_html__( 'View Header Layout', 'et_builder' ),
[131] Fix | Delete
'search_items' => esc_html__( 'Search Header Layouts', 'et_builder' ),
[132] Fix | Delete
'not_found' => esc_html__( 'Nothing found', 'et_builder' ),
[133] Fix | Delete
'not_found_in_trash' => esc_html__( 'Nothing found in Trash', 'et_builder' ),
[134] Fix | Delete
'parent_item_colon' => '',
[135] Fix | Delete
),
[136] Fix | Delete
'can_export' => true,
[137] Fix | Delete
'capability_type' => 'post',
[138] Fix | Delete
'has_archive' => false,
[139] Fix | Delete
'hierarchical' => false,
[140] Fix | Delete
'map_meta_cap' => true,
[141] Fix | Delete
'public' => false,
[142] Fix | Delete
'publicly_queryable' => $publicly_queryable,
[143] Fix | Delete
'query_var' => false,
[144] Fix | Delete
'show_ui' => false,
[145] Fix | Delete
'show_in_rest' => false,
[146] Fix | Delete
'rewrite' => true,
[147] Fix | Delete
'supports' => array( 'title', 'editor', 'author', 'revisions', 'comments' ),
[148] Fix | Delete
) );
[149] Fix | Delete
[150] Fix | Delete
register_post_type( ET_THEME_BUILDER_BODY_LAYOUT_POST_TYPE, array(
[151] Fix | Delete
'labels' => array(
[152] Fix | Delete
'name' => esc_html__( 'Body Layouts', 'et_builder' ),
[153] Fix | Delete
'singular_name' => esc_html__( 'Body Layout', 'et_builder' ),
[154] Fix | Delete
'add_new' => esc_html__( 'Add New', 'et_builder' ),
[155] Fix | Delete
'add_new_item' => esc_html__( 'Add New Body Layout', 'et_builder' ),
[156] Fix | Delete
'edit_item' => esc_html__( 'Edit Body Layout', 'et_builder' ),
[157] Fix | Delete
'new_item' => esc_html__( 'New Body Layout', 'et_builder' ),
[158] Fix | Delete
'all_items' => esc_html__( 'All Body Layouts', 'et_builder' ),
[159] Fix | Delete
'view_item' => esc_html__( 'View Body Layout', 'et_builder' ),
[160] Fix | Delete
'search_items' => esc_html__( 'Search Body Layouts', 'et_builder' ),
[161] Fix | Delete
'not_found' => esc_html__( 'Nothing found', 'et_builder' ),
[162] Fix | Delete
'not_found_in_trash' => esc_html__( 'Nothing found in Trash', 'et_builder' ),
[163] Fix | Delete
'parent_item_colon' => '',
[164] Fix | Delete
),
[165] Fix | Delete
'can_export' => true,
[166] Fix | Delete
'capability_type' => 'post',
[167] Fix | Delete
'has_archive' => false,
[168] Fix | Delete
'hierarchical' => false,
[169] Fix | Delete
'map_meta_cap' => true,
[170] Fix | Delete
'public' => false,
[171] Fix | Delete
'publicly_queryable' => $publicly_queryable,
[172] Fix | Delete
'query_var' => false,
[173] Fix | Delete
'show_ui' => false,
[174] Fix | Delete
'show_in_rest' => false,
[175] Fix | Delete
'rewrite' => true,
[176] Fix | Delete
'supports' => array( 'title', 'editor', 'author', 'revisions', 'comments' ),
[177] Fix | Delete
) );
[178] Fix | Delete
[179] Fix | Delete
register_post_type( ET_THEME_BUILDER_FOOTER_LAYOUT_POST_TYPE, array(
[180] Fix | Delete
'labels' => array(
[181] Fix | Delete
'name' => esc_html__( 'Footer Layouts', 'et_builder' ),
[182] Fix | Delete
'singular_name' => esc_html__( 'Footer Layout', 'et_builder' ),
[183] Fix | Delete
'add_new' => esc_html__( 'Add New', 'et_builder' ),
[184] Fix | Delete
'add_new_item' => esc_html__( 'Add New Footer Layout', 'et_builder' ),
[185] Fix | Delete
'edit_item' => esc_html__( 'Edit Footer Layout', 'et_builder' ),
[186] Fix | Delete
'new_item' => esc_html__( 'New Footer Layout', 'et_builder' ),
[187] Fix | Delete
'all_items' => esc_html__( 'All Footer Layouts', 'et_builder' ),
[188] Fix | Delete
'view_item' => esc_html__( 'View Footer Layout', 'et_builder' ),
[189] Fix | Delete
'search_items' => esc_html__( 'Search Footer Layouts', 'et_builder' ),
[190] Fix | Delete
'not_found' => esc_html__( 'Nothing found', 'et_builder' ),
[191] Fix | Delete
'not_found_in_trash' => esc_html__( 'Nothing found in Trash', 'et_builder' ),
[192] Fix | Delete
'parent_item_colon' => '',
[193] Fix | Delete
),
[194] Fix | Delete
'can_export' => true,
[195] Fix | Delete
'capability_type' => 'post',
[196] Fix | Delete
'has_archive' => false,
[197] Fix | Delete
'hierarchical' => false,
[198] Fix | Delete
'map_meta_cap' => true,
[199] Fix | Delete
'public' => false,
[200] Fix | Delete
'publicly_queryable' => $publicly_queryable,
[201] Fix | Delete
'query_var' => false,
[202] Fix | Delete
'show_ui' => false,
[203] Fix | Delete
'show_in_rest' => false,
[204] Fix | Delete
'rewrite' => true,
[205] Fix | Delete
'supports' => array( 'title', 'editor', 'author', 'revisions', 'comments' ),
[206] Fix | Delete
) );
[207] Fix | Delete
}
[208] Fix | Delete
add_action( 'init', 'et_theme_builder_register_entities', 11 );
[209] Fix | Delete
[210] Fix | Delete
/**
[211] Fix | Delete
* Get array of post types that can be layouts within templates.
[212] Fix | Delete
*
[213] Fix | Delete
* @since 4.0
[214] Fix | Delete
*
[215] Fix | Delete
* @return string[]
[216] Fix | Delete
*/
[217] Fix | Delete
function et_theme_builder_get_layout_post_types() {
[218] Fix | Delete
return array(
[219] Fix | Delete
ET_THEME_BUILDER_HEADER_LAYOUT_POST_TYPE,
[220] Fix | Delete
ET_THEME_BUILDER_BODY_LAYOUT_POST_TYPE,
[221] Fix | Delete
ET_THEME_BUILDER_FOOTER_LAYOUT_POST_TYPE,
[222] Fix | Delete
);
[223] Fix | Delete
}
[224] Fix | Delete
[225] Fix | Delete
/**
[226] Fix | Delete
* Convert 'header', 'body', 'footer' to the appropriate layout post type name.
[227] Fix | Delete
*
[228] Fix | Delete
* @since 4.0
[229] Fix | Delete
*
[230] Fix | Delete
* @param string $layout_type
[231] Fix | Delete
*
[232] Fix | Delete
* @return string
[233] Fix | Delete
*/
[234] Fix | Delete
function et_theme_builder_get_valid_layout_post_type( $layout_type ) {
[235] Fix | Delete
$map = array(
[236] Fix | Delete
'header' => ET_THEME_BUILDER_HEADER_LAYOUT_POST_TYPE,
[237] Fix | Delete
'body' => ET_THEME_BUILDER_BODY_LAYOUT_POST_TYPE,
[238] Fix | Delete
'footer' => ET_THEME_BUILDER_FOOTER_LAYOUT_POST_TYPE,
[239] Fix | Delete
);
[240] Fix | Delete
[241] Fix | Delete
if ( ! isset( $map[ $layout_type ] ) ) {
[242] Fix | Delete
return '';
[243] Fix | Delete
}
[244] Fix | Delete
[245] Fix | Delete
return $map[ $layout_type ];
[246] Fix | Delete
}
[247] Fix | Delete
[248] Fix | Delete
/**
[249] Fix | Delete
* Get whether post type is a Theme Builder layout type.
[250] Fix | Delete
*
[251] Fix | Delete
* @since 4.0
[252] Fix | Delete
*
[253] Fix | Delete
* @param string $post_type
[254] Fix | Delete
*
[255] Fix | Delete
* @return boolean
[256] Fix | Delete
*/
[257] Fix | Delete
function et_theme_builder_is_layout_post_type( $post_type ) {
[258] Fix | Delete
return in_array( $post_type, et_theme_builder_get_layout_post_types(), true );
[259] Fix | Delete
}
[260] Fix | Delete
[261] Fix | Delete
/**
[262] Fix | Delete
* Get list of post content module slugs.
[263] Fix | Delete
*
[264] Fix | Delete
* @since 4.0
[265] Fix | Delete
*
[266] Fix | Delete
* @return string[]
[267] Fix | Delete
*/
[268] Fix | Delete
function et_theme_builder_get_post_content_modules() {
[269] Fix | Delete
return array( 'et_pb_post_content', 'et_pb_fullwidth_post_content' );
[270] Fix | Delete
}
[271] Fix | Delete
[272] Fix | Delete
/**
[273] Fix | Delete
* Filter post types with builder support by default.
[274] Fix | Delete
*
[275] Fix | Delete
* @since 4.0
[276] Fix | Delete
*
[277] Fix | Delete
* @param $post_types
[278] Fix | Delete
*
[279] Fix | Delete
* @return array
[280] Fix | Delete
*/
[281] Fix | Delete
function et_theme_builder_filter_builder_default_post_types( $post_types ) {
[282] Fix | Delete
return array_merge( $post_types, et_theme_builder_get_layout_post_types() );
[283] Fix | Delete
}
[284] Fix | Delete
add_filter( 'et_builder_default_post_types', 'et_theme_builder_filter_builder_default_post_types' );
[285] Fix | Delete
add_filter( 'et_library_builder_post_types', 'et_theme_builder_filter_builder_default_post_types' );
[286] Fix | Delete
[287] Fix | Delete
/**
[288] Fix | Delete
* Filter post types which should be blocklisted from appearing as options when enabling/disabling the builder.
[289] Fix | Delete
*
[290] Fix | Delete
* @param $post_types
[291] Fix | Delete
*
[292] Fix | Delete
* @return array
[293] Fix | Delete
*/
[294] Fix | Delete
function et_theme_builder_filter_builder_post_type_options_blocklist( $post_types ) {
[295] Fix | Delete
return array_merge(
[296] Fix | Delete
$post_types,
[297] Fix | Delete
et_theme_builder_get_layout_post_types(),
[298] Fix | Delete
array( ET_THEME_BUILDER_TEMPLATE_POST_TYPE )
[299] Fix | Delete
);
[300] Fix | Delete
}
[301] Fix | Delete
add_filter( 'et_builder_post_type_options_blocklist', 'et_theme_builder_filter_builder_default_post_types' );
[302] Fix | Delete
[303] Fix | Delete
/**
[304] Fix | Delete
* Filter builder status for template area posts.
[305] Fix | Delete
*
[306] Fix | Delete
* @since 4.0
[307] Fix | Delete
*
[308] Fix | Delete
* @param $enabled
[309] Fix | Delete
* @param $post_id
[310] Fix | Delete
*
[311] Fix | Delete
* @return bool
[312] Fix | Delete
*/
[313] Fix | Delete
function et_theme_builder_filter_enable_builder_for_post_types( $enabled, $post_id ) {
[314] Fix | Delete
$post_type = get_post_type( $post_id );
[315] Fix | Delete
[316] Fix | Delete
if ( et_theme_builder_is_layout_post_type( $post_type ) ) {
[317] Fix | Delete
$enabled = true;
[318] Fix | Delete
}
[319] Fix | Delete
[320] Fix | Delete
return $enabled;
[321] Fix | Delete
}
[322] Fix | Delete
add_filter( 'et_builder_fb_enabled_for_post', 'et_theme_builder_filter_enable_builder_for_post_types', 10, 2 );
[323] Fix | Delete
[324] Fix | Delete
/**
[325] Fix | Delete
* Get the theme builder post.
[326] Fix | Delete
*
[327] Fix | Delete
* @since 4.0
[328] Fix | Delete
*
[329] Fix | Delete
* @param boolean $live Get the live version or the draft one.
[330] Fix | Delete
* @param boolean $create Create the post if it does not exist.
[331] Fix | Delete
*
[332] Fix | Delete
* @return integer
[333] Fix | Delete
*/
[334] Fix | Delete
function et_theme_builder_get_theme_builder_post_id( $live, $create = true ) {
[335] Fix | Delete
$status = $live ? 'publish' : 'auto-draft';
[336] Fix | Delete
$query = new WP_Query( array(
[337] Fix | Delete
'post_type' => ET_THEME_BUILDER_THEME_BUILDER_POST_TYPE,
[338] Fix | Delete
'post_status' => $status,
[339] Fix | Delete
'posts_per_page' => 1,
[340] Fix | Delete
'orderby' => 'date',
[341] Fix | Delete
'order' => 'desc',
[342] Fix | Delete
'fields' => 'ids',
[343] Fix | Delete
'no_found_rows' => true,
[344] Fix | Delete
'update_post_meta_cache' => false,
[345] Fix | Delete
'update_post_term_cache' => false,
[346] Fix | Delete
) );
[347] Fix | Delete
[348] Fix | Delete
if ( ! empty( $query->posts ) ) {
[349] Fix | Delete
return $query->posts[0];
[350] Fix | Delete
}
[351] Fix | Delete
[352] Fix | Delete
if ( ! $create ) {
[353] Fix | Delete
return 0;
[354] Fix | Delete
}
[355] Fix | Delete
[356] Fix | Delete
$post_id = wp_insert_post( array(
[357] Fix | Delete
'post_type' => ET_THEME_BUILDER_THEME_BUILDER_POST_TYPE,
[358] Fix | Delete
'post_status' => $status,
[359] Fix | Delete
'post_title' => 'Theme Builder',
[360] Fix | Delete
) );
[361] Fix | Delete
[362] Fix | Delete
return $post_id;
[363] Fix | Delete
}
[364] Fix | Delete
[365] Fix | Delete
/**
[366] Fix | Delete
* Get the theme builder post's template IDs.
[367] Fix | Delete
*
[368] Fix | Delete
* @since 4.0
[369] Fix | Delete
*
[370] Fix | Delete
* @param boolean $live Get the live version or the draft one.
[371] Fix | Delete
*
[372] Fix | Delete
* @return integer[]
[373] Fix | Delete
*/
[374] Fix | Delete
function et_theme_builder_get_theme_builder_template_ids( $live ) {
[375] Fix | Delete
$post_id = et_theme_builder_get_theme_builder_post_id( $live, false );
[376] Fix | Delete
$template_ids = get_post_meta( $post_id, '_et_template', false );
[377] Fix | Delete
$template_ids = is_array( $template_ids ) ? $template_ids : array();
[378] Fix | Delete
$template_ids = array_map( 'intval', $template_ids );
[379] Fix | Delete
[380] Fix | Delete
return $template_ids;
[381] Fix | Delete
}
[382] Fix | Delete
[383] Fix | Delete
/**
[384] Fix | Delete
* Get the theme builder post's templates.
[385] Fix | Delete
*
[386] Fix | Delete
* @since 4.0
[387] Fix | Delete
*
[388] Fix | Delete
* @param boolean $live Get the live version or the draft one.
[389] Fix | Delete
*
[390] Fix | Delete
* @return array
[391] Fix | Delete
*/
[392] Fix | Delete
function et_theme_builder_get_theme_builder_templates( $live ) {
[393] Fix | Delete
return array_filter( array_map(
[394] Fix | Delete
'et_theme_builder_get_template',
[395] Fix | Delete
et_theme_builder_get_theme_builder_template_ids( $live )
[396] Fix | Delete
) );
[397] Fix | Delete
}
[398] Fix | Delete
[399] Fix | Delete
/**
[400] Fix | Delete
* Get a template.
[401] Fix | Delete
* Returns an empty array if the template is not found.
[402] Fix | Delete
*
[403] Fix | Delete
* @since 4.0
[404] Fix | Delete
*
[405] Fix | Delete
* @param integer $template_id
[406] Fix | Delete
*
[407] Fix | Delete
* @return array
[408] Fix | Delete
*/
[409] Fix | Delete
function et_theme_builder_get_template( $template_id ) {
[410] Fix | Delete
$post = get_post( $template_id );
[411] Fix | Delete
[412] Fix | Delete
if ( null === $post || ET_THEME_BUILDER_TEMPLATE_POST_TYPE !== $post->post_type ) {
[413] Fix | Delete
return array();
[414] Fix | Delete
}
[415] Fix | Delete
[416] Fix | Delete
$autogenerated_title = '1' === get_post_meta( $template_id, '_et_autogenerated_title', true );
[417] Fix | Delete
$header_id = (int) get_post_meta( $post->ID, '_et_header_layout_id', true );
[418] Fix | Delete
$header_enabled = get_post_meta( $post->ID, '_et_header_layout_enabled', true ) === '1';
[419] Fix | Delete
$body_id = (int) get_post_meta( $post->ID, '_et_body_layout_id', true );
[420] Fix | Delete
$body_enabled = get_post_meta( $post->ID, '_et_body_layout_enabled', true ) === '1';
[421] Fix | Delete
$footer_id = (int) get_post_meta( $post->ID, '_et_footer_layout_id', true );
[422] Fix | Delete
$footer_enabled = get_post_meta( $post->ID, '_et_footer_layout_enabled', true ) === '1';
[423] Fix | Delete
$use_on = get_post_meta( $post->ID, '_et_use_on', false );
[424] Fix | Delete
$exclude_from = get_post_meta( $post->ID, '_et_exclude_from', false );
[425] Fix | Delete
[426] Fix | Delete
return array(
[427] Fix | Delete
'id' => $post->ID,
[428] Fix | Delete
'default' => get_post_meta( $post->ID, '_et_default', true ) === '1',
[429] Fix | Delete
'enabled' => get_post_meta( $post->ID, '_et_enabled', true ) === '1',
[430] Fix | Delete
'title' => $autogenerated_title ? '' : $post->post_title,
[431] Fix | Delete
'layouts' => array(
[432] Fix | Delete
'header' => array(
[433] Fix | Delete
'id' => $header_id,
[434] Fix | Delete
'enabled' => $header_enabled,
[435] Fix | Delete
'override' => 0 !== $header_id || false === $header_enabled,
[436] Fix | Delete
),
[437] Fix | Delete
'body' => array(
[438] Fix | Delete
'id' => $body_id,
[439] Fix | Delete
'enabled' => $body_enabled,
[440] Fix | Delete
'override' => 0 !== $body_id || false === $body_enabled,
[441] Fix | Delete
),
[442] Fix | Delete
'footer' => array(
[443] Fix | Delete
'id' => $footer_id,
[444] Fix | Delete
'enabled' => $footer_enabled,
[445] Fix | Delete
'override' => 0 !== $footer_id || false === $footer_enabled,
[446] Fix | Delete
),
[447] Fix | Delete
),
[448] Fix | Delete
'use_on' => is_array( $use_on ) ? $use_on : array(),
[449] Fix | Delete
'exclude_from' => is_array( $exclude_from ) ? $exclude_from : array(),
[450] Fix | Delete
);
[451] Fix | Delete
}
[452] Fix | Delete
[453] Fix | Delete
/**
[454] Fix | Delete
* Trash the theme builder draft and any unused theme builder templates and layouts.
[455] Fix | Delete
*
[456] Fix | Delete
* @since 4.0
[457] Fix | Delete
*
[458] Fix | Delete
* @return void
[459] Fix | Delete
*/
[460] Fix | Delete
function et_theme_builder_trash_draft_and_unused_posts() {
[461] Fix | Delete
$mark_meta_key = '_et_theme_builder_marked_as_unused';
[462] Fix | Delete
$live_id = et_theme_builder_get_theme_builder_post_id( true, false );
[463] Fix | Delete
$draft_id = et_theme_builder_get_theme_builder_post_id( false, false );
[464] Fix | Delete
[465] Fix | Delete
if ( $draft_id > 0 ) {
[466] Fix | Delete
wp_trash_post( $draft_id );
[467] Fix | Delete
}
[468] Fix | Delete
[469] Fix | Delete
$used_templates = get_post_meta( $live_id, '_et_template', false );
[470] Fix | Delete
$used_templates = is_array( $used_templates ) ? array_map( 'intval', $used_templates ) : array();
[471] Fix | Delete
$used_posts = array();
[472] Fix | Delete
[473] Fix | Delete
foreach ( $used_templates as $template_id ) {
[474] Fix | Delete
$used_posts[] = $template_id;
[475] Fix | Delete
$used_posts[] = (int) get_post_meta( $template_id, '_et_header_layout_id', true );
[476] Fix | Delete
$used_posts[] = (int) get_post_meta( $template_id, '_et_body_layout_id', true );
[477] Fix | Delete
$used_posts[] = (int) get_post_meta( $template_id, '_et_footer_layout_id', true );
[478] Fix | Delete
}
[479] Fix | Delete
[480] Fix | Delete
$used_posts = array_filter( $used_posts );
[481] Fix | Delete
[482] Fix | Delete
// Unmark all used posts.
[483] Fix | Delete
foreach ( $used_posts as $post_id ) {
[484] Fix | Delete
delete_post_meta( $post_id, $mark_meta_key );
[485] Fix | Delete
}
[486] Fix | Delete
[487] Fix | Delete
// Mark unreferenced layouts for trashing.
[488] Fix | Delete
$posts_to_mark = new WP_Query( array(
[489] Fix | Delete
'post_type' => array(
[490] Fix | Delete
ET_THEME_BUILDER_TEMPLATE_POST_TYPE,
[491] Fix | Delete
ET_THEME_BUILDER_HEADER_LAYOUT_POST_TYPE,
[492] Fix | Delete
ET_THEME_BUILDER_BODY_LAYOUT_POST_TYPE,
[493] Fix | Delete
ET_THEME_BUILDER_FOOTER_LAYOUT_POST_TYPE,
[494] Fix | Delete
),
[495] Fix | Delete
'post__not_in' => $used_posts,
[496] Fix | Delete
'posts_per_page' => -1,
[497] Fix | Delete
'fields' => 'ids',
[498] Fix | Delete
'meta_query' => array(
[499] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function