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

Warning: Undefined array key "page_file_edit_line" in /home/sportsfever/public_html/filemanger/edit_text_line.php on line 32
/home/sportsfe.../httpdocs/clone/wp-conte.../themes/Divi/includes/builder
File: functions.php
/**
[9000] Fix | Delete
* Is Gutenberg active and enabled for the current post
[9001] Fix | Delete
* WP 5.0 WARNING - don't use before global post has been set
[9002] Fix | Delete
*
[9003] Fix | Delete
* @deprecated See {@see et_core_is_gutenberg_enabled()}
[9004] Fix | Delete
*
[9005] Fix | Delete
* @since 3.19.2 Renamed and moved to core.
[9006] Fix | Delete
* @since 3.18
[9007] Fix | Delete
*
[9008] Fix | Delete
* @return bool True - if the plugin is active and enabled.
[9009] Fix | Delete
*/
[9010] Fix | Delete
if ( ! function_exists( 'et_is_gutenberg_enabled' ) ) :
[9011] Fix | Delete
function et_is_gutenberg_enabled() {
[9012] Fix | Delete
return et_core_is_gutenberg_enabled();
[9013] Fix | Delete
}
[9014] Fix | Delete
endif;
[9015] Fix | Delete
[9016] Fix | Delete
/**
[9017] Fix | Delete
* Modify comment count for preview screen. Somehow WordPress' get_comments_number() doesn't get correct $post_id
[9018] Fix | Delete
* param and doesn't have proper fallback to global $post if $post_id variable isn't found. This causes incorrect
[9019] Fix | Delete
* comment count in preview screen
[9020] Fix | Delete
* @see get_comments_number()
[9021] Fix | Delete
* @see get_comments_number_text()
[9022] Fix | Delete
* @see comments_number()
[9023] Fix | Delete
* @return string
[9024] Fix | Delete
*/
[9025] Fix | Delete
function et_pb_preview_comment_count( $count, $post_id ) {
[9026] Fix | Delete
if ( is_et_pb_preview() ) {
[9027] Fix | Delete
global $post;
[9028] Fix | Delete
$count = isset( $post->comment_count ) ? $post->comment_count : $count;
[9029] Fix | Delete
}
[9030] Fix | Delete
[9031] Fix | Delete
return $count;
[9032] Fix | Delete
}
[9033] Fix | Delete
add_filter( 'get_comments_number', 'et_pb_preview_comment_count', 10, 2 );
[9034] Fix | Delete
[9035] Fix | Delete
/**
[9036] Fix | Delete
* List of shortcodes that triggers error if being used in admin
[9037] Fix | Delete
*
[9038] Fix | Delete
* @return array shortcode tag
[9039] Fix | Delete
*/
[9040] Fix | Delete
function et_pb_admin_excluded_shortcodes() {
[9041] Fix | Delete
$shortcodes = array();
[9042] Fix | Delete
[9043] Fix | Delete
// Triggers issue if Sensei and YOAST SEO are activated
[9044] Fix | Delete
if ( et_is_yoast_seo_plugin_active() && function_exists( 'Sensei' ) ) {
[9045] Fix | Delete
$shortcodes[] = 'usercourses';
[9046] Fix | Delete
}
[9047] Fix | Delete
[9048] Fix | Delete
// WPL real estate prints unwanted on-page JS that caused an issue on BB
[9049] Fix | Delete
if ( class_exists( 'wpl_extensions' ) ) {
[9050] Fix | Delete
$shortcodes[] = 'WPL';
[9051] Fix | Delete
}
[9052] Fix | Delete
[9053] Fix | Delete
// [submit_job_form] shortcode prints wp_editor this creating problems post edit page render
[9054] Fix | Delete
if ( et_is_wp_job_manager_plugin_active() ) {
[9055] Fix | Delete
$shortcodes[] = 'submit_job_form';
[9056] Fix | Delete
}
[9057] Fix | Delete
[9058] Fix | Delete
// [shop_messages] shortcode causes a fatal error when rendered too soon
[9059] Fix | Delete
if ( et_is_woocommerce_plugin_active() ) {
[9060] Fix | Delete
$shortcodes[] = 'shop_messages';
[9061] Fix | Delete
}
[9062] Fix | Delete
[9063] Fix | Delete
return apply_filters( 'et_pb_admin_excluded_shortcodes', $shortcodes );
[9064] Fix | Delete
}
[9065] Fix | Delete
[9066] Fix | Delete
/**
[9067] Fix | Delete
* Get GMT offset string that can be used for parsing date into correct timestamp
[9068] Fix | Delete
*
[9069] Fix | Delete
* @return string
[9070] Fix | Delete
*/
[9071] Fix | Delete
function et_pb_get_gmt_offset_string() {
[9072] Fix | Delete
$gmt_offset = get_option( 'gmt_offset' );
[9073] Fix | Delete
$gmt_divider = '-' === substr( $gmt_offset, 0, 1 ) ? '-' : '+';
[9074] Fix | Delete
$gmt_offset_hour = str_pad( abs( intval( $gmt_offset ) ), 2, "0", STR_PAD_LEFT );
[9075] Fix | Delete
$gmt_offset_minute = str_pad( ( ( abs( $gmt_offset ) * 100 ) % 100 ) * ( 60 / 100 ), 2, "0", STR_PAD_LEFT );
[9076] Fix | Delete
$gmt_offset_string = "GMT{$gmt_divider}{$gmt_offset_hour}{$gmt_offset_minute}";
[9077] Fix | Delete
[9078] Fix | Delete
return $gmt_offset_string;
[9079] Fix | Delete
}
[9080] Fix | Delete
[9081] Fix | Delete
/**
[9082] Fix | Delete
* Get post's category label and permalink to be used on frontend
[9083] Fix | Delete
*
[9084] Fix | Delete
* @param int $post_id
[9085] Fix | Delete
* @param WP_Term[] $default
[9086] Fix | Delete
*
[9087] Fix | Delete
* @return array categories
[9088] Fix | Delete
*/
[9089] Fix | Delete
function et_pb_get_post_categories( $post_id, $default = array() ) {
[9090] Fix | Delete
$categories = get_the_category( $post_id );
[9091] Fix | Delete
$post_categories = array();
[9092] Fix | Delete
[9093] Fix | Delete
if ( $default && ! $categories ) {
[9094] Fix | Delete
$categories = array_values( $default );
[9095] Fix | Delete
[9096] Fix | Delete
foreach ( array_keys( $categories ) as $key ) {
[9097] Fix | Delete
_make_cat_compat( $categories[ $key ] );
[9098] Fix | Delete
}
[9099] Fix | Delete
}
[9100] Fix | Delete
[9101] Fix | Delete
// Filter out any falsy values that may appear due from $default.
[9102] Fix | Delete
$categories = array_filter( $categories );
[9103] Fix | Delete
[9104] Fix | Delete
if ( ! empty( $categories ) ) {
[9105] Fix | Delete
foreach ( $categories as $category ) {
[9106] Fix | Delete
$post_categories[ $category->cat_ID ] = array(
[9107] Fix | Delete
'id' => $category->cat_ID,
[9108] Fix | Delete
'label' => $category->cat_name,
[9109] Fix | Delete
'permalink' => get_category_link( $category->cat_ID ),
[9110] Fix | Delete
);
[9111] Fix | Delete
}
[9112] Fix | Delete
}
[9113] Fix | Delete
[9114] Fix | Delete
return $post_categories;
[9115] Fix | Delete
}
[9116] Fix | Delete
[9117] Fix | Delete
/**
[9118] Fix | Delete
* Add "Use Visual Builder" link to WP-Admin bar
[9119] Fix | Delete
*
[9120] Fix | Delete
* @return void
[9121] Fix | Delete
*/
[9122] Fix | Delete
function et_fb_add_admin_bar_link() {
[9123] Fix | Delete
$is_not_builder_enabled_single = ! is_singular() || ! et_builder_fb_enabled_for_post( get_the_ID() );
[9124] Fix | Delete
$is_not_in_wc_shop = ! et_builder_used_in_wc_shop();
[9125] Fix | Delete
$not_allowed_fb_access = ! et_pb_is_allowed( 'use_visual_builder' );
[9126] Fix | Delete
if ( $not_allowed_fb_access || ( $is_not_builder_enabled_single && $is_not_in_wc_shop ) ) {
[9127] Fix | Delete
return;
[9128] Fix | Delete
}
[9129] Fix | Delete
[9130] Fix | Delete
global $wp_admin_bar, $wp_the_query;
[9131] Fix | Delete
[9132] Fix | Delete
$post_id = get_the_ID();
[9133] Fix | Delete
[9134] Fix | Delete
// WooCommerce Shop Page replaces main query, thus it has to be normalized
[9135] Fix | Delete
if ( et_builder_used_in_wc_shop() && method_exists( $wp_the_query, 'get_queried_object' ) && isset( $wp_the_query->get_queried_object()->ID ) ) {
[9136] Fix | Delete
$post_id = $wp_the_query->get_queried_object()->ID;
[9137] Fix | Delete
}
[9138] Fix | Delete
[9139] Fix | Delete
$is_divi_library = 'et_pb_layout' === get_post_type( $post_id );
[9140] Fix | Delete
[9141] Fix | Delete
$page_url = $is_divi_library ? get_edit_post_link( $post_id ) : get_permalink( $post_id );
[9142] Fix | Delete
[9143] Fix | Delete
// Don't add the link, if Frontend Builder has been loaded already
[9144] Fix | Delete
if ( et_fb_is_enabled() ) {
[9145] Fix | Delete
$wp_admin_bar->add_menu( array(
[9146] Fix | Delete
'id' => 'et-disable-visual-builder',
[9147] Fix | Delete
'title' => esc_html__( 'Exit Visual Builder', 'et_builder' ),
[9148] Fix | Delete
'href' => esc_url( $page_url ),
[9149] Fix | Delete
) );
[9150] Fix | Delete
[9151] Fix | Delete
return;
[9152] Fix | Delete
}
[9153] Fix | Delete
[9154] Fix | Delete
$current_object = $wp_the_query->get_queried_object();
[9155] Fix | Delete
[9156] Fix | Delete
if ( ! current_user_can( 'edit_post', $current_object->ID ) || ! et_pb_is_allowed( 'divi_builder_control' ) ) {
[9157] Fix | Delete
return;
[9158] Fix | Delete
}
[9159] Fix | Delete
[9160] Fix | Delete
$use_visual_builder_url = et_pb_is_pagebuilder_used( $post_id ) ?
[9161] Fix | Delete
et_fb_get_builder_url( $page_url ) :
[9162] Fix | Delete
add_query_arg( array(
[9163] Fix | Delete
'et_fb_activation_nonce' => wp_create_nonce( 'et_fb_activation_nonce_' . $post_id ),
[9164] Fix | Delete
), $page_url );
[9165] Fix | Delete
[9166] Fix | Delete
$wp_admin_bar->add_menu( array(
[9167] Fix | Delete
'id' => 'et-use-visual-builder',
[9168] Fix | Delete
'title' => esc_html__( 'Enable Visual Builder', 'et_builder' ),
[9169] Fix | Delete
'href' => esc_url( $use_visual_builder_url ),
[9170] Fix | Delete
) );
[9171] Fix | Delete
}
[9172] Fix | Delete
add_action( 'admin_bar_menu', 'et_fb_add_admin_bar_link', 999 );
[9173] Fix | Delete
[9174] Fix | Delete
/**
[9175] Fix | Delete
* Retrieve and process saved Layouts.
[9176] Fix | Delete
* It different than the function which retrieves saved Sections, Rows and Modules from library because layouts require different processing
[9177] Fix | Delete
*
[9178] Fix | Delete
* @return array
[9179] Fix | Delete
*/
[9180] Fix | Delete
function et_fb_get_saved_layouts() {
[9181] Fix | Delete
if ( ! wp_verify_nonce( $_POST['et_fb_retrieve_library_modules_nonce'], 'et_fb_retrieve_library_modules_nonce' ) ){
[9182] Fix | Delete
die(-1);
[9183] Fix | Delete
}
[9184] Fix | Delete
[9185] Fix | Delete
if ( ! current_user_can( 'edit_posts' ) ) {
[9186] Fix | Delete
die( -1 );
[9187] Fix | Delete
}
[9188] Fix | Delete
[9189] Fix | Delete
// Reduce number of results per page if we're hosted on wpengine to avoid 500 error due to memory allocation.
[9190] Fix | Delete
// This is caused by one of their custom mu-plugins doing additional stuff but we have no control over there.
[9191] Fix | Delete
$page_size = function_exists( 'is_wpe' ) || function_exists( 'is_wpe_snapshot' ) ? 25 : 50;
[9192] Fix | Delete
$post_type = ! empty( $_POST['et_post_type'] ) ? sanitize_text_field( $_POST['et_post_type'] ) : 'post';
[9193] Fix | Delete
$layouts_type = ! empty( $_POST['et_load_layouts_type'] ) ? sanitize_text_field( $_POST['et_load_layouts_type'] ) : 'all';
[9194] Fix | Delete
$start_from = ! empty( $_POST['et_templates_start_page'] ) ? sanitize_text_field( $_POST['et_templates_start_page'] ) : 0;
[9195] Fix | Delete
[9196] Fix | Delete
$post_type = apply_filters( 'et_pb_show_all_layouts_built_for_post_type', $post_type, $layouts_type );
[9197] Fix | Delete
[9198] Fix | Delete
$all_layouts_data = et_pb_retrieve_templates( 'layout', '', 'false', '0', $post_type, $layouts_type, array( $start_from, $page_size ) );
[9199] Fix | Delete
$all_layouts_data_processed = $all_layouts_data;
[9200] Fix | Delete
$next_page = 'none';
[9201] Fix | Delete
[9202] Fix | Delete
if ( 0 !== $start_from && empty( $all_layouts_data ) ) {
[9203] Fix | Delete
$all_layouts_data_processed = array();
[9204] Fix | Delete
} else {
[9205] Fix | Delete
if ( empty( $all_layouts_data ) ) {
[9206] Fix | Delete
$all_layouts_data_processed = array( 'error' => esc_html__( 'You have not saved any items to your Divi Library yet. Once an item has been saved to your library, it will appear here for easy use.', 'et_builder' ) );
[9207] Fix | Delete
} else {
[9208] Fix | Delete
foreach( $all_layouts_data as $index => $data ) {
[9209] Fix | Delete
$all_layouts_data_processed[ $index ]['shortcode'] = et_fb_process_shortcode( $data['shortcode'] );
[9210] Fix | Delete
}
[9211] Fix | Delete
$next_page = $start_from + $page_size;
[9212] Fix | Delete
}
[9213] Fix | Delete
}
[9214] Fix | Delete
[9215] Fix | Delete
$json_templates = json_encode( array( 'templates_data' => $all_layouts_data_processed, 'next_page' => $next_page ) );
[9216] Fix | Delete
[9217] Fix | Delete
die( et_core_intentionally_unescaped( $json_templates, 'html' ) );
[9218] Fix | Delete
}
[9219] Fix | Delete
[9220] Fix | Delete
add_action( 'wp_ajax_et_fb_get_saved_layouts', 'et_fb_get_saved_layouts' );
[9221] Fix | Delete
[9222] Fix | Delete
function et_fb_process_imported_content() {
[9223] Fix | Delete
if ( ! isset( $_POST['et_fb_process_imported_data_nonce'] ) || ! wp_verify_nonce( $_POST['et_fb_process_imported_data_nonce'], 'et_fb_process_imported_data_nonce' ) ) {
[9224] Fix | Delete
die( -1 );
[9225] Fix | Delete
}
[9226] Fix | Delete
[9227] Fix | Delete
if ( ! current_user_can( 'edit_posts' ) ) {
[9228] Fix | Delete
die( -1 );
[9229] Fix | Delete
}
[9230] Fix | Delete
[9231] Fix | Delete
$processed_shortcode = et_fb_process_shortcode( stripslashes( $_POST['et_raw_shortcode'] ) );
[9232] Fix | Delete
[9233] Fix | Delete
die( json_encode( $processed_shortcode ) );
[9234] Fix | Delete
}
[9235] Fix | Delete
add_action( 'wp_ajax_et_fb_process_imported_content', 'et_fb_process_imported_content' );
[9236] Fix | Delete
[9237] Fix | Delete
function et_fb_maybe_get_bfb_initial_content( $content, $post_id ) {
[9238] Fix | Delete
if ( isset( $_GET['from_post'] ) && 'empty' !== $_GET['from_post'] ) {
[9239] Fix | Delete
$copy_content_from = get_post( $_GET['from_post'] );
[9240] Fix | Delete
$existing_content = $copy_content_from->post_content;
[9241] Fix | Delete
[9242] Fix | Delete
if ( '' !== $existing_content && has_shortcode( $existing_content, 'et_pb_section' ) ) {
[9243] Fix | Delete
return $existing_content;
[9244] Fix | Delete
}
[9245] Fix | Delete
}
[9246] Fix | Delete
[9247] Fix | Delete
// process the content only for BFB
[9248] Fix | Delete
if ( ! et_builder_bfb_enabled() ) {
[9249] Fix | Delete
return $content;
[9250] Fix | Delete
}
[9251] Fix | Delete
[9252] Fix | Delete
// If content already has a section, it means builder is active and activation has to be
[9253] Fix | Delete
// skipped to avoid nested and unwanted builder structure.
[9254] Fix | Delete
if ( has_shortcode( $content, 'et_pb_section' ) ) {
[9255] Fix | Delete
return $content;
[9256] Fix | Delete
}
[9257] Fix | Delete
[9258] Fix | Delete
// Save old content
[9259] Fix | Delete
$saved_old_content = get_post_meta( $post_id, '_et_pb_old_content', true );
[9260] Fix | Delete
$save_old_content = false;
[9261] Fix | Delete
$post = get_post( $post_id );
[9262] Fix | Delete
[9263] Fix | Delete
if ( '' !== $content ) {
[9264] Fix | Delete
$save_old_content = update_post_meta( $post_id, '_et_pb_old_content', $content );
[9265] Fix | Delete
}
[9266] Fix | Delete
[9267] Fix | Delete
/**
[9268] Fix | Delete
* Filters the flag that sets default Content during Builder activation.
[9269] Fix | Delete
*
[9270] Fix | Delete
* @since 3.29
[9271] Fix | Delete
*
[9272] Fix | Delete
* @used-by et_builder_wc_init()
[9273] Fix | Delete
*/
[9274] Fix | Delete
if ( apply_filters( 'et_builder_skip_content_activation', false, $post ) ) {
[9275] Fix | Delete
return $content;
[9276] Fix | Delete
}
[9277] Fix | Delete
[9278] Fix | Delete
if ( true !== $save_old_content && $saved_old_content !== $content && '' !== $content ) {
[9279] Fix | Delete
return $content;
[9280] Fix | Delete
}
[9281] Fix | Delete
[9282] Fix | Delete
$text_module = '' !== $content ? '[et_pb_text admin_label="Text"]'. $content .'[/et_pb_text]' : '';
[9283] Fix | Delete
[9284] Fix | Delete
// Re-format content
[9285] Fix | Delete
$updated_content =
[9286] Fix | Delete
'[et_pb_section admin_label="section"]
[9287] Fix | Delete
[et_pb_row admin_label="row"]
[9288] Fix | Delete
[et_pb_column type="4_4"]'. $text_module .'[/et_pb_column]
[9289] Fix | Delete
[/et_pb_row]
[9290] Fix | Delete
[/et_pb_section]';
[9291] Fix | Delete
[9292] Fix | Delete
return $updated_content;
[9293] Fix | Delete
}
[9294] Fix | Delete
[9295] Fix | Delete
// Called via async AJAX call after the builder rendered. It will regenerate both helper/definitions files.
[9296] Fix | Delete
// If their content changed, the builder will trigger a page reload to use the updated cached files.
[9297] Fix | Delete
function et_fb_update_builder_assets() {
[9298] Fix | Delete
if ( ! isset( $_POST['et_fb_helper_nonce'] ) || ! wp_verify_nonce( $_POST['et_fb_helper_nonce'], 'et_fb_update_helper_assets_nonce' ) ) {
[9299] Fix | Delete
die( -1 );
[9300] Fix | Delete
}
[9301] Fix | Delete
[9302] Fix | Delete
$post_id = ! empty( $_POST['et_post_id'] ) ? sanitize_text_field( $_POST['et_post_id'] ) : '';
[9303] Fix | Delete
[9304] Fix | Delete
if ( ! current_user_can( 'edit_post', $post_id ) ) {
[9305] Fix | Delete
die( -1 );
[9306] Fix | Delete
}
[9307] Fix | Delete
[9308] Fix | Delete
// Set current post as global $post
[9309] Fix | Delete
$post = get_post( $post_id ); // phpcs:ignore WordPress.Variables.GlobalVariables.OverrideProhibited
[9310] Fix | Delete
[9311] Fix | Delete
$post_type = ! empty( $_POST['et_post_type'] ) ? sanitize_text_field( $_POST['et_post_type'] ) : 'post';
[9312] Fix | Delete
[9313] Fix | Delete
// Update helpers cached js file
[9314] Fix | Delete
$helpers = et_fb_get_dynamic_asset( 'helpers', $post_type, true );
[9315] Fix | Delete
// Update definitions cached js file
[9316] Fix | Delete
$definitions = et_fb_get_dynamic_asset( 'definitions', $post_type, true );
[9317] Fix | Delete
[9318] Fix | Delete
// When either definitions or helpers needs an update, also clear modules cache.
[9319] Fix | Delete
if ( $definitions['updated'] || $helpers['updated'] ) {
[9320] Fix | Delete
$modules_cache = ET_Builder_Element::get_cache_filename( $post_type );
[9321] Fix | Delete
[9322] Fix | Delete
if ( file_exists( $modules_cache ) ) {
[9323] Fix | Delete
@unlink( $modules_cache );
[9324] Fix | Delete
}
[9325] Fix | Delete
}
[9326] Fix | Delete
[9327] Fix | Delete
die( json_encode( array( 'helpers' => $helpers, 'definitions' => $definitions ) ) );
[9328] Fix | Delete
}
[9329] Fix | Delete
add_action( 'wp_ajax_et_fb_update_builder_assets', 'et_fb_update_builder_assets' );
[9330] Fix | Delete
[9331] Fix | Delete
// Returns builder module defintions.
[9332] Fix | Delete
function et_fb_get_builder_definitions( $post_type ) {
[9333] Fix | Delete
[9334] Fix | Delete
// force render builder data when retrieving builder definition to ensure definitions retrieved via ajax call
[9335] Fix | Delete
// equal to definitions retrieved on wp_footer when no dynamic asset cache found
[9336] Fix | Delete
add_filter( 'et_builder_module_force_render', '__return_true' );
[9337] Fix | Delete
[9338] Fix | Delete
$fields_data = array();
[9339] Fix | Delete
$fields_data['custom_css'] = ET_Builder_Element::get_custom_css_fields( $post_type );
[9340] Fix | Delete
$fields_data['advanced_fields'] = ET_Builder_Element::get_advanced_fields( $post_type );
[9341] Fix | Delete
$fields_data['general_fields'] = ET_Builder_Element::get_general_fields( $post_type );
[9342] Fix | Delete
$fields_data['childModuleTitles'] = ET_Builder_Element::get_child_module_titles( $post_type );
[9343] Fix | Delete
$fields_data['optionsToggles'] = ET_Builder_Element::get_toggles( $post_type );
[9344] Fix | Delete
$fields_data['customTabs'] = ET_Builder_Element::get_tabs( $post_type );
[9345] Fix | Delete
$fields_data['customTabsFields'] = ET_Builder_Element::get_settings_modal_tabs_fields( $post_type );
[9346] Fix | Delete
$fields_data['customLayoutsTabs'] = ET_Builder_Library::builder_library_modal_custom_tabs( $post_type );
[9347] Fix | Delete
$fields_data['moduleItemsConfig'] = ET_Builder_Element::get_module_items_configs( $post_type );
[9348] Fix | Delete
$fields_data['moduleTransitions'] = ET_Builder_Element::get_modules_transitions( $post_type );
[9349] Fix | Delete
$fields_data['contact_form_input_defaults'] = et_fb_process_shortcode( sprintf(
[9350] Fix | Delete
'[et_pb_contact_field field_title="%1$s" field_type="input" field_id="Name" required_mark="on" fullwidth_field="off" /][et_pb_contact_field field_title="%2$s" field_type="email" field_id="Email" required_mark="on" fullwidth_field="off" /][et_pb_contact_field field_title="%3$s" field_type="text" field_id="Message" required_mark="on" fullwidth_field="on" /]',
[9351] Fix | Delete
esc_attr__( 'Name', 'et_builder' ),
[9352] Fix | Delete
esc_attr__( 'Email Address', 'et_builder' ),
[9353] Fix | Delete
esc_attr__( 'Message', 'et_builder' )
[9354] Fix | Delete
) );
[9355] Fix | Delete
[9356] Fix | Delete
// Remove duplicates from field definitions
[9357] Fix | Delete
$map = array();
[9358] Fix | Delete
$unique_fields = array();
[9359] Fix | Delete
$unique_count = 0;
[9360] Fix | Delete
[9361] Fix | Delete
foreach ( array( 'custom_css', 'general_fields', 'advanced_fields' ) as $source ) {
[9362] Fix | Delete
$definitions = &$fields_data[ $source ];
[9363] Fix | Delete
$module_names = array_keys( $definitions );
[9364] Fix | Delete
[9365] Fix | Delete
foreach ( $module_names as $module_name ) {
[9366] Fix | Delete
$module = &$definitions[ $module_name ];
[9367] Fix | Delete
$setting_names = array_keys( $module );
[9368] Fix | Delete
[9369] Fix | Delete
foreach ( $setting_names as $setting_name ) {
[9370] Fix | Delete
$setting = &$module[ $setting_name ];
[9371] Fix | Delete
[9372] Fix | Delete
if ( 'advanced_defaults' === $setting_name ) {
[9373] Fix | Delete
// advanced_defaults are just duplicated data, we can rebuilt them later.
[9374] Fix | Delete
$setting = false;
[9375] Fix | Delete
continue;
[9376] Fix | Delete
}
[9377] Fix | Delete
[9378] Fix | Delete
$key = json_encode( $setting );
[9379] Fix | Delete
[9380] Fix | Delete
if ( ! isset( $map[ $key ] ) ) {
[9381] Fix | Delete
// Found a duplicate here
[9382] Fix | Delete
$unique_fields[] = $setting;
[9383] Fix | Delete
$map[ $key ] = $unique_count++;
[9384] Fix | Delete
}
[9385] Fix | Delete
[9386] Fix | Delete
$setting = $map[ $key ];
[9387] Fix | Delete
}
[9388] Fix | Delete
}
[9389] Fix | Delete
}
[9390] Fix | Delete
[9391] Fix | Delete
// Remove force builder data render
[9392] Fix | Delete
remove_filter( 'et_builder_module_force_render', '__return_true' );
[9393] Fix | Delete
[9394] Fix | Delete
// No longer needed
[9395] Fix | Delete
unset( $map );
[9396] Fix | Delete
[9397] Fix | Delete
// Include the unique fields in the AJAX payload
[9398] Fix | Delete
$fields_data['unique_fields'] = $unique_fields;
[9399] Fix | Delete
[9400] Fix | Delete
return $fields_data;
[9401] Fix | Delete
}
[9402] Fix | Delete
[9403] Fix | Delete
// Returns builder shortcode object
[9404] Fix | Delete
function et_fb_get_builder_shortcode_object( $post_type, $post_id, $layout_type ) {
[9405] Fix | Delete
[9406] Fix | Delete
// We need to store the current post when this function is executed in a wp-admin page
[9407] Fix | Delete
// to prevent post based modules included in the shortcode from altering the loop.
[9408] Fix | Delete
global $post;
[9409] Fix | Delete
$backup = $post;
[9410] Fix | Delete
[9411] Fix | Delete
$fields_data = array();
[9412] Fix | Delete
add_filter( 'et_builder_module_force_render', '__return_true' );
[9413] Fix | Delete
[9414] Fix | Delete
$post_data = get_post( $post_id );
[9415] Fix | Delete
$post_data_post_modified = date( 'U', strtotime( $post_data->post_modified ) );
[9416] Fix | Delete
$post_content = $post_data->post_content;
[9417] Fix | Delete
[9418] Fix | Delete
// if autosave exists here, return it with the real content, autosave.js and getServerSavedPostData() will look for it
[9419] Fix | Delete
$current_user_id = get_current_user_id();
[9420] Fix | Delete
// Store one autosave per author. If there is already an autosave, overwrite it.
[9421] Fix | Delete
$autosave = wp_get_post_autosave( $post_id, $current_user_id );
[9422] Fix | Delete
[9423] Fix | Delete
if ( !empty( $autosave ) ) {
[9424] Fix | Delete
$autosave_post_modified = date( 'U', strtotime( $autosave->post_modified ) );
[9425] Fix | Delete
[9426] Fix | Delete
if ( $autosave_post_modified > $post_data_post_modified ) {
[9427] Fix | Delete
$fields_data['autosave_shortcode_object'] = et_fb_process_shortcode( $autosave->post_content );
[9428] Fix | Delete
$fields_data['has_newer_autosave'] = true;
[9429] Fix | Delete
} else {
[9430] Fix | Delete
$fields_data['has_newer_autosave'] = false;
[9431] Fix | Delete
}
[9432] Fix | Delete
// Delete the autosave, becuase we will present the option to use the autosave to the user, and they will use it or not
[9433] Fix | Delete
// we need to delete the db copy now
[9434] Fix | Delete
wp_delete_post_revision( $autosave->ID );
[9435] Fix | Delete
}
[9436] Fix | Delete
[9437] Fix | Delete
switch ( $layout_type ) {
[9438] Fix | Delete
case 'module':
[9439] Fix | Delete
$use_fullwidth_section = false !== strpos( $post_content, '[et_pb_fullwidth_' ) ? true : false;
[9440] Fix | Delete
// Remove module placeholders
[9441] Fix | Delete
$post_content = false !== strpos( $post_content, 'et_pb_fullwidth_module_placeholder' ) || false !== strpos( $post_content, 'et_pb_module_placeholder' ) ? '' : $post_content;
[9442] Fix | Delete
[9443] Fix | Delete
if ( ! $use_fullwidth_section ) {
[9444] Fix | Delete
$post_content = sprintf( '[et_pb_row][et_pb_column type="4_4"]%1$s[/et_pb_column][/et_pb_row]', $post_content );
[9445] Fix | Delete
}
[9446] Fix | Delete
[9447] Fix | Delete
$post_content = sprintf(
[9448] Fix | Delete
'[et_pb_section%2$s]%1$s[/et_pb_section]',
[9449] Fix | Delete
$post_content,
[9450] Fix | Delete
$use_fullwidth_section ? ' fullwidth="on"' : ''
[9451] Fix | Delete
);
[9452] Fix | Delete
[9453] Fix | Delete
break;
[9454] Fix | Delete
case 'row':
[9455] Fix | Delete
$post_content = '[et_pb_section]' . $post_content . '[/et_pb_section]';
[9456] Fix | Delete
break;
[9457] Fix | Delete
}
[9458] Fix | Delete
[9459] Fix | Delete
$post_content = et_fb_maybe_get_bfb_initial_content( $post_content, $post_id );
[9460] Fix | Delete
[9461] Fix | Delete
/**
[9462] Fix | Delete
* Filters the raw post content when the Builder is loaded.
[9463] Fix | Delete
*
[9464] Fix | Delete
* @since 3.29
[9465] Fix | Delete
*
[9466] Fix | Delete
* @param string $post_content The raw/unprocessed post content.
[9467] Fix | Delete
* @param int $post_id Post ID.
[9468] Fix | Delete
*/
[9469] Fix | Delete
$post_content = apply_filters( 'et_fb_load_raw_post_content', $post_content, $post_id );
[9470] Fix | Delete
[9471] Fix | Delete
$fields_data['shortcode_object'] = et_fb_process_shortcode( $post_content );
[9472] Fix | Delete
[9473] Fix | Delete
remove_filter( 'et_builder_module_force_render', '__return_true' );
[9474] Fix | Delete
[9475] Fix | Delete
// Restore post
[9476] Fix | Delete
$post = $backup;
[9477] Fix | Delete
setup_postdata( $post );
[9478] Fix | Delete
[9479] Fix | Delete
return $fields_data;
[9480] Fix | Delete
}
[9481] Fix | Delete
[9482] Fix | Delete
function et_fb_retrieve_builder_data() {
[9483] Fix | Delete
if ( ! isset( $_POST['et_fb_helper_nonce'] ) || ! wp_verify_nonce( $_POST['et_fb_helper_nonce'], 'et_fb_load_helper_assets_nonce' ) ) {
[9484] Fix | Delete
die( -1 );
[9485] Fix | Delete
}
[9486] Fix | Delete
[9487] Fix | Delete
$post_id = ! empty( $_POST['et_post_id'] ) ? sanitize_text_field( $_POST['et_post_id'] ) : '';
[9488] Fix | Delete
[9489] Fix | Delete
if ( ! current_user_can( 'edit_posts' ) || ! current_user_can( 'edit_post', $post_id ) ) {
[9490] Fix | Delete
die( -1 );
[9491] Fix | Delete
}
[9492] Fix | Delete
[9493] Fix | Delete
$post_type = ! empty( $_POST['et_post_type'] ) ? sanitize_text_field( $_POST['et_post_type'] ) : 'post';
[9494] Fix | Delete
[9495] Fix | Delete
$layout_type = ! empty( $_POST['et_layout_type'] ) ? sanitize_text_field( $_POST['et_layout_type'] ) : '';
[9496] Fix | Delete
[9497] Fix | Delete
$fields_data = array_merge(
[9498] Fix | Delete
et_fb_get_builder_definitions( $post_type ),
[9499] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function