Edit File by line
/home/barbar84/www/wp-conte.../themes/Divi/includes/builder
File: functions.php
} else {
[4000] Fix | Delete
delete_post_meta( $post_id, '_et_pb_ab_subjects' );
[4001] Fix | Delete
}
[4002] Fix | Delete
[4003] Fix | Delete
if ( isset( $_POST['et_pb_ab_goal_module'] ) && '' !== $_POST['et_pb_ab_goal_module'] ) {
[4004] Fix | Delete
update_post_meta( $post_id, '_et_pb_ab_goal_module', sanitize_text_field( $_POST['et_pb_ab_goal_module'] ) );
[4005] Fix | Delete
} else {
[4006] Fix | Delete
delete_post_meta( $post_id, '_et_pb_ab_goal_module' );
[4007] Fix | Delete
}
[4008] Fix | Delete
[4009] Fix | Delete
if ( isset( $_POST['et_pb_ab_stats_refresh_interval'] ) && '' !== $_POST['et_pb_ab_stats_refresh_interval'] ) {
[4010] Fix | Delete
update_post_meta( $post_id, '_et_pb_ab_stats_refresh_interval', sanitize_text_field( $_POST['et_pb_ab_stats_refresh_interval'] ) );
[4011] Fix | Delete
} else {
[4012] Fix | Delete
delete_post_meta( $post_id, '_et_pb_ab_stats_refresh_interval' );
[4013] Fix | Delete
}
[4014] Fix | Delete
}
[4015] Fix | Delete
[4016] Fix | Delete
if ( isset( $_POST['et_pb_old_content'] ) ) {
[4017] Fix | Delete
update_post_meta( $post_id, '_et_pb_old_content', $_POST['et_pb_old_content'] );
[4018] Fix | Delete
[4019] Fix | Delete
/**
[4020] Fix | Delete
* Fires after the `_et_pb_old_content` post meta is updated.
[4021] Fix | Delete
*
[4022] Fix | Delete
* In case you want to over-ride `_et_pb_old_content` content, this is the hook you should use.
[4023] Fix | Delete
*
[4024] Fix | Delete
* @see et_builder_wc_long_description_metabox_save()
[4025] Fix | Delete
*
[4026] Fix | Delete
* @since 3.29
[4027] Fix | Delete
*
[4028] Fix | Delete
* @param int $post_id Post ID.
[4029] Fix | Delete
* $param WP_Post $post The Post.
[4030] Fix | Delete
* $param array $_POST Request variables. This could be used for Nonce verification, etc.
[4031] Fix | Delete
*/
[4032] Fix | Delete
do_action( 'et_pb_old_content_updated', $post_id, $post, $_POST );
[4033] Fix | Delete
} else {
[4034] Fix | Delete
delete_post_meta( $post_id, '_et_pb_old_content' );
[4035] Fix | Delete
}
[4036] Fix | Delete
[4037] Fix | Delete
et_builder_update_settings( null, $post_id );
[4038] Fix | Delete
[4039] Fix | Delete
if ( isset( $_POST['et_pb_unsynced_global_attrs'] ) ) {
[4040] Fix | Delete
$unsynced_options_array = stripslashes( sanitize_text_field( $_POST['et_pb_unsynced_global_attrs'] ) );
[4041] Fix | Delete
update_post_meta( $post_id, '_et_pb_excluded_global_options', $unsynced_options_array );
[4042] Fix | Delete
}
[4043] Fix | Delete
[4044] Fix | Delete
return $post_id;
[4045] Fix | Delete
}
[4046] Fix | Delete
add_action( 'save_post', 'et_pb_metabox_settings_save_details', 10, 2 );
[4047] Fix | Delete
[4048] Fix | Delete
/**
[4049] Fix | Delete
* Set et-saved-post-* cookie and delete et-saving-post-* cookie after post save.
[4050] Fix | Delete
*
[4051] Fix | Delete
* @param int $post_id Post id.
[4052] Fix | Delete
* @param WP_Post $post Object.
[4053] Fix | Delete
*
[4054] Fix | Delete
* @return mixed
[4055] Fix | Delete
*/
[4056] Fix | Delete
function et_pb_set_et_saved_cookie( $post_id, $post ) {
[4057] Fix | Delete
global $pagenow;
[4058] Fix | Delete
[4059] Fix | Delete
if ( 'post.php' !== $pagenow ) {
[4060] Fix | Delete
return $post_id;
[4061] Fix | Delete
}
[4062] Fix | Delete
[4063] Fix | Delete
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
[4064] Fix | Delete
return $post_id;
[4065] Fix | Delete
}
[4066] Fix | Delete
[4067] Fix | Delete
$post_type = get_post_type_object( $post->post_type );
[4068] Fix | Delete
if ( ! current_user_can( $post_type->cap->edit_post, $post_id ) ) {
[4069] Fix | Delete
return $post_id;
[4070] Fix | Delete
}
[4071] Fix | Delete
[4072] Fix | Delete
if ( ! isset( $_POST['et_pb_settings_nonce'] ) || ! wp_verify_nonce( $_POST['et_pb_settings_nonce'], basename( __FILE__ ) ) ) { // phpcs:ignore ET.Sniffs.ValidatedSanitizedInput -- The nonce value is used only for comparision in the `wp_verify_nonce`.
[4073] Fix | Delete
return $post_id;
[4074] Fix | Delete
}
[4075] Fix | Delete
[4076] Fix | Delete
// delete.
[4077] Fix | Delete
setcookie( 'et-saving-post-' . $post_id . '-bb', 'bb', time() - DAY_IN_SECONDS, SITECOOKIEPATH, false, is_ssl() );
[4078] Fix | Delete
// set.
[4079] Fix | Delete
setcookie( 'et-saved-post-' . $post_id . '-bb', 'bb', time() + MINUTE_IN_SECONDS * 5, SITECOOKIEPATH, false, is_ssl() );
[4080] Fix | Delete
}
[4081] Fix | Delete
[4082] Fix | Delete
add_action( 'save_post', 'et_pb_set_et_saved_cookie', 10, 2 );
[4083] Fix | Delete
[4084] Fix | Delete
/**
[4085] Fix | Delete
* Handling title-less & content-less switching from backend builder to normal editor
[4086] Fix | Delete
*
[4087] Fix | Delete
* @param int $maybe_empty whether the wp_insert_post content is empty or not.
[4088] Fix | Delete
* @param array $postarr all $_POST data that is being passed to wp_insert_post().
[4089] Fix | Delete
* @return int whether wp_insert_post content should be considered empty or not
[4090] Fix | Delete
*/
[4091] Fix | Delete
function et_pb_ensure_builder_activation_switching( $maybe_empty, $postarr ) {
[4092] Fix | Delete
// Consider wp_insert_post() content is not empty if incoming et_pb_use_builder is `off` while currently saved _et_pb_use_builder value is `on`.
[4093] Fix | Delete
if ( isset( $postarr['et_pb_use_builder'] ) && 'off' === $postarr['et_pb_use_builder'] && isset( $postarr['post_ID'] ) && et_pb_is_pagebuilder_used( $postarr['post_ID'] ) ) {
[4094] Fix | Delete
return false;
[4095] Fix | Delete
}
[4096] Fix | Delete
[4097] Fix | Delete
return $maybe_empty;
[4098] Fix | Delete
}
[4099] Fix | Delete
add_filter( 'wp_insert_post_empty_content', 'et_pb_ensure_builder_activation_switching', 10, 2 );
[4100] Fix | Delete
[4101] Fix | Delete
/**
[4102] Fix | Delete
* Display buttons before main editor in BFB.
[4103] Fix | Delete
*
[4104] Fix | Delete
* @param WP_Post $post object.
[4105] Fix | Delete
*/
[4106] Fix | Delete
function et_pb_before_main_editor( $post ) {
[4107] Fix | Delete
if ( ! et_builder_enabled_for_post( $post->ID ) ) {
[4108] Fix | Delete
return;
[4109] Fix | Delete
}
[4110] Fix | Delete
[4111] Fix | Delete
$_et_builder_use_builder = get_post_meta( $post->ID, '_et_pb_use_builder', true );
[4112] Fix | Delete
$is_builder_used = 'on' === $_et_builder_use_builder;
[4113] Fix | Delete
$last_builder_version_used = get_post_meta( $post->ID, '_et_builder_version', true ); // Examples: 'BB|Divi|3.0.30' 'VB|Divi|3.0.30'.
[4114] Fix | Delete
[4115] Fix | Delete
$_et_builder_use_ab_testing = et_builder_bfb_enabled() ? false : get_post_meta( $post->ID, '_et_pb_use_ab_testing', true );
[4116] Fix | Delete
$_et_builder_ab_stats_refresh_interval = et_builder_bfb_enabled() ? false : et_pb_ab_get_refresh_interval( $post->ID );
[4117] Fix | Delete
$_et_builder_ab_subjects = et_builder_bfb_enabled() ? false : get_post_meta( $post->ID, '_et_pb_ab_subjects', true );
[4118] Fix | Delete
$_et_builder_ab_goal_module = et_builder_bfb_enabled() ? false : et_pb_ab_get_goal_module( $post->ID );
[4119] Fix | Delete
[4120] Fix | Delete
$builder_always_enabled = apply_filters( 'et_builder_always_enabled', false, $post->post_type, $post );
[4121] Fix | Delete
if ( 'et_pb_layout' === $post->post_type ) {
[4122] Fix | Delete
// No matter what, in Divi Library we always want the builder.
[4123] Fix | Delete
$builder_always_enabled = true;
[4124] Fix | Delete
}
[4125] Fix | Delete
if ( $builder_always_enabled ) {
[4126] Fix | Delete
$is_builder_used = true;
[4127] Fix | Delete
$_et_builder_use_builder = 'on';
[4128] Fix | Delete
}
[4129] Fix | Delete
[4130] Fix | Delete
// TODO, need to change the output of these buttons if BFB.
[4131] Fix | Delete
[4132] Fix | Delete
// Add button only if current user is allowed to use it otherwise display placeholder with all required data.
[4133] Fix | Delete
if ( et_pb_is_allowed( 'divi_builder_control' ) ) {
[4134] Fix | Delete
$buttons = sprintf(
[4135] Fix | Delete
'<a href="#" id="et_pb_toggle_builder" data-builder="%2$s" data-editor="%3$s" class="button button-primary button-large%4$s%5$s">%1$s</a>',
[4136] Fix | Delete
( $is_builder_used ? esc_html__( 'Return To Standard Editor', 'et_builder' ) : esc_html__( 'Use The Divi Builder', 'et_builder' ) ),
[4137] Fix | Delete
esc_html__( 'Use The Divi Builder', 'et_builder' ),
[4138] Fix | Delete
esc_html__( 'Return To Standard Editor', 'et_builder' ),
[4139] Fix | Delete
( $is_builder_used ? ' et_pb_builder_is_used' : '' ),
[4140] Fix | Delete
( $builder_always_enabled ? ' et_pb_hidden' : '' )
[4141] Fix | Delete
);
[4142] Fix | Delete
[4143] Fix | Delete
// add in the visual builder button only on appropriate post types
[4144] Fix | Delete
// also, don't add the button on page if it set as static posts page.
[4145] Fix | Delete
if ( et_builder_fb_enabled_for_post( $post->ID ) && et_pb_is_allowed( 'use_visual_builder' ) && ! et_is_extra_library_layout( $post->ID ) && get_option( 'page_for_posts' ) !== $post->ID ) {
[4146] Fix | Delete
$buttons .= sprintf(
[4147] Fix | Delete
'<a href="%1$s" id="et_pb_fb_cta" class="button button-primary button-large%3$s%4$s">%2$s</a>',
[4148] Fix | Delete
esc_url( et_fb_get_vb_url() ),
[4149] Fix | Delete
esc_html__( 'Build On The Front End', 'et_builder' ),
[4150] Fix | Delete
( $builder_always_enabled ? ' et-first-child' : '' ),
[4151] Fix | Delete
( et_pb_is_pagebuilder_used( $post->ID ) ? ' et_pb_ready' : '' )
[4152] Fix | Delete
);
[4153] Fix | Delete
}
[4154] Fix | Delete
[4155] Fix | Delete
printf(
[4156] Fix | Delete
'<div class="et_pb_toggle_builder_wrapper%1$s"%4$s>%2$s</div><div id="et_pb_main_editor_wrap"%3$s>',
[4157] Fix | Delete
( $is_builder_used ? ' et_pb_builder_is_used' : '' ),
[4158] Fix | Delete
et_core_esc_previously( $buttons ),
[4159] Fix | Delete
( $is_builder_used ? ' class="et_pb_post_body_hidden"' : '' ),
[4160] Fix | Delete
( et_builder_bfb_enabled() ? ' style="opacity: 0;"' : '' )
[4161] Fix | Delete
);
[4162] Fix | Delete
} else {
[4163] Fix | Delete
printf(
[4164] Fix | Delete
'<div class="et_pb_toggle_builder_wrapper%2$s"%3$s></div><div id="et_pb_main_editor_wrap"%1$s>',
[4165] Fix | Delete
( $is_builder_used ? ' class="et_pb_post_body_hidden"' : '' ),
[4166] Fix | Delete
( $is_builder_used ? ' et_pb_builder_is_used' : '' ),
[4167] Fix | Delete
( et_builder_bfb_enabled() ? ' style="opacity: 0;"' : '' )
[4168] Fix | Delete
);
[4169] Fix | Delete
}
[4170] Fix | Delete
[4171] Fix | Delete
if ( ! et_builder_bfb_enabled() ) {
[4172] Fix | Delete
$module_fields_dependencies = wp_json_encode( ET_Builder_Element::get_field_dependencies( $post->post_type ) );
[4173] Fix | Delete
[4174] Fix | Delete
echo et_core_esc_previously(
[4175] Fix | Delete
"
[4176] Fix | Delete
<script>
[4177] Fix | Delete
window.et_pb_module_field_dependencies = JSON.parse( '{$module_fields_dependencies}' );
[4178] Fix | Delete
</script>"
[4179] Fix | Delete
);
[4180] Fix | Delete
}
[4181] Fix | Delete
[4182] Fix | Delete
?>
[4183] Fix | Delete
<p class="et_pb_page_settings" style="display: none;">
[4184] Fix | Delete
<?php wp_nonce_field( basename( __FILE__ ), 'et_pb_settings_nonce' ); ?>
[4185] Fix | Delete
<input type="hidden" id="et_pb_last_post_modified" name="et_pb_last_post_modified" value="<?php echo esc_attr( $post->post_modified ); ?>" />
[4186] Fix | Delete
<input type="hidden" id="et_pb_use_builder" name="et_pb_use_builder" value="<?php echo esc_attr( $_et_builder_use_builder ); ?>" />
[4187] Fix | Delete
<input type="hidden" id="et_builder_version" name="et_builder_version" value="<?php echo esc_attr( $last_builder_version_used ); ?>" />
[4188] Fix | Delete
<input type="hidden" autocomplete="off" id="et_pb_use_ab_testing" name="et_pb_use_ab_testing" value="<?php echo esc_attr( $_et_builder_use_ab_testing ); ?>">
[4189] Fix | Delete
<input type="hidden" autocomplete="off" id="_et_pb_ab_stats_refresh_interval" name="et_pb_ab_stats_refresh_interval" value="<?php echo esc_attr( $_et_builder_ab_stats_refresh_interval ); ?>">
[4190] Fix | Delete
<input type="hidden" autocomplete="off" id="et_pb_ab_subjects" name="et_pb_ab_subjects" value="<?php echo esc_attr( $_et_builder_ab_subjects ); ?>">
[4191] Fix | Delete
<input type="hidden" autocomplete="off" id="et_pb_ab_goal_module" name="et_pb_ab_goal_module" value="<?php echo esc_attr( $_et_builder_ab_goal_module ); ?>">
[4192] Fix | Delete
<?php et_pb_builder_settings_hidden_inputs( $post->ID ); ?>
[4193] Fix | Delete
<?php et_pb_builder_global_library_inputs( $post->ID ); ?>
[4194] Fix | Delete
[4195] Fix | Delete
<textarea id="et_pb_old_content" name="et_pb_old_content"><?php echo esc_attr( get_post_meta( $post->ID, '_et_pb_old_content', true ) ); ?></textarea>
[4196] Fix | Delete
</p>
[4197] Fix | Delete
<?php
[4198] Fix | Delete
}
[4199] Fix | Delete
[4200] Fix | Delete
/**
[4201] Fix | Delete
* Add #et_pb_main_editor_wrap closing div.
[4202] Fix | Delete
*
[4203] Fix | Delete
* @param WP_Post $post object.
[4204] Fix | Delete
*/
[4205] Fix | Delete
function et_pb_after_main_editor( $post ) {
[4206] Fix | Delete
if ( ! et_builder_enabled_for_post( $post->ID ) ) {
[4207] Fix | Delete
return;
[4208] Fix | Delete
}
[4209] Fix | Delete
echo '</div> <!-- #et_pb_main_editor_wrap -->';
[4210] Fix | Delete
}
[4211] Fix | Delete
[4212] Fix | Delete
/**
[4213] Fix | Delete
* Setup Divi Builder in BFB.
[4214] Fix | Delete
*/
[4215] Fix | Delete
function et_pb_setup_main_editor() {
[4216] Fix | Delete
if ( ! et_core_is_gutenberg_enabled() ) {
[4217] Fix | Delete
add_action( 'edit_form_after_title', 'et_pb_before_main_editor' );
[4218] Fix | Delete
add_action( 'edit_form_after_editor', 'et_pb_after_main_editor' );
[4219] Fix | Delete
}
[4220] Fix | Delete
}
[4221] Fix | Delete
add_action( 'add_meta_boxes', 'et_pb_setup_main_editor', 11 );
[4222] Fix | Delete
[4223] Fix | Delete
/**
[4224] Fix | Delete
* Load scripts and styles in admin.
[4225] Fix | Delete
*
[4226] Fix | Delete
* @param string $hook The current admin page.
[4227] Fix | Delete
*/
[4228] Fix | Delete
function et_pb_admin_scripts_styles( $hook ) {
[4229] Fix | Delete
global $typenow, $pagenow;
[4230] Fix | Delete
[4231] Fix | Delete
// load css file for the Divi menu.
[4232] Fix | Delete
wp_enqueue_style( 'library-menu-styles', ET_BUILDER_URI . '/styles/library_menu.css', array(), ET_BUILDER_VERSION );
[4233] Fix | Delete
[4234] Fix | Delete
if ( 'widgets.php' === $hook ) {
[4235] Fix | Delete
wp_enqueue_script( 'et_pb_widgets_js', ET_BUILDER_URI . '/scripts/ext/widgets.js', array( 'jquery' ), ET_BUILDER_VERSION, true );
[4236] Fix | Delete
[4237] Fix | Delete
$et_pb_options_admin = array(
[4238] Fix | Delete
'ajaxurl' => admin_url( 'admin-ajax.php' ),
[4239] Fix | Delete
'et_admin_load_nonce' => wp_create_nonce( 'et_admin_load_nonce' ),
[4240] Fix | Delete
'widget_info' => sprintf(
[4241] Fix | Delete
'<div id="et_pb_widget_area_create"><p>%1$s.</p><p>%2$s.</p><p><label>%3$s <input id="et_pb_new_widget_area_name" value="" /></label><button class="button button-primary et_pb_create_widget_area">%4$s</button></p><p class="et_pb_widget_area_result"></p></div>',
[4242] Fix | Delete
esc_html__( 'Here you can create new widget areas for use in the Sidebar module', 'et_builder' ),
[4243] Fix | Delete
esc_html__( 'Note: Naming your widget area "sidebar 1", "sidebar 2", "sidebar 3", "sidebar 4" or "sidebar 5" will cause conflicts with this theme', 'et_builder' ),
[4244] Fix | Delete
esc_html__( 'Widget Name', 'et_builder' ),
[4245] Fix | Delete
esc_html__( 'Create', 'et_builder' )
[4246] Fix | Delete
),
[4247] Fix | Delete
'delete_string' => esc_html__( 'Delete', 'et_builder' ),
[4248] Fix | Delete
);
[4249] Fix | Delete
[4250] Fix | Delete
wp_localize_script( 'et_pb_widgets_js', 'et_pb_options', apply_filters( 'et_pb_options_admin', $et_pb_options_admin ) );
[4251] Fix | Delete
[4252] Fix | Delete
wp_enqueue_style( 'et_pb_widgets_css', ET_BUILDER_URI . '/styles/widgets.css', array(), ET_BUILDER_VERSION );
[4253] Fix | Delete
[4254] Fix | Delete
return;
[4255] Fix | Delete
}
[4256] Fix | Delete
[4257] Fix | Delete
// Do not enqueue BB assets if GB is active on this page.
[4258] Fix | Delete
if ( et_core_is_gutenberg_enabled() ) {
[4259] Fix | Delete
return;
[4260] Fix | Delete
}
[4261] Fix | Delete
[4262] Fix | Delete
if ( ! in_array( $hook, array( 'post-new.php', 'post.php' ), true ) ) {
[4263] Fix | Delete
return;
[4264] Fix | Delete
}
[4265] Fix | Delete
[4266] Fix | Delete
/*
[4267] Fix | Delete
* Load the builder javascript and css files for custom post types
[4268] Fix | Delete
* custom post types can be added using et_builder_post_types filter
[4269] Fix | Delete
*/
[4270] Fix | Delete
[4271] Fix | Delete
$post_types = et_builder_get_builder_post_types();
[4272] Fix | Delete
$on_enabled_post_type = isset( $typenow ) && in_array( $typenow, $post_types, true );
[4273] Fix | Delete
$on_enabled_post = isset( $pagenow ) && 'post.php' === $pagenow && isset( $_GET['post'] ) && et_builder_enabled_for_post( intval( $_GET['post'] ) ); // phpcs:ignore WordPress.Security.NonceVerification -- This function does not change any state, and is therefore not susceptible to CSRF.
[4274] Fix | Delete
[4275] Fix | Delete
if ( $on_enabled_post_type || $on_enabled_post ) {
[4276] Fix | Delete
wp_enqueue_style( 'et_bb_bfb_common', ET_BUILDER_URI . '/styles/bb_bfb_common.css', array(), ET_BUILDER_VERSION );
[4277] Fix | Delete
[4278] Fix | Delete
// Boot one builders assets or the other.
[4279] Fix | Delete
if ( et_builder_bfb_enabled() ) {
[4280] Fix | Delete
et_bfb_enqueue_scripts();
[4281] Fix | Delete
[4282] Fix | Delete
// do not load BFB if builder is disabled on page.
[4283] Fix | Delete
if ( ! et_pb_is_pagebuilder_used( get_the_ID() ) ) {
[4284] Fix | Delete
return;
[4285] Fix | Delete
}
[4286] Fix | Delete
[4287] Fix | Delete
// BFB loads builder modal outside the iframe using react portal. external scripts
[4288] Fix | Delete
// that is used on modal needs to be enqueued.
[4289] Fix | Delete
et_builder_enqueue_assets_main();
[4290] Fix | Delete
[4291] Fix | Delete
et_builder_enqueue_open_sans();
[4292] Fix | Delete
[4293] Fix | Delete
$secondary_css_bundles = glob( ET_BUILDER_DIR . 'frontend-builder/build/bundle.*.css' );
[4294] Fix | Delete
[4295] Fix | Delete
if ( $secondary_css_bundles ) {
[4296] Fix | Delete
$bundles = array( 'et-frontend-builder' );
[4297] Fix | Delete
[4298] Fix | Delete
foreach ( $secondary_css_bundles as $css_bundle ) {
[4299] Fix | Delete
$slug = basename( $css_bundle, '.css' );
[4300] Fix | Delete
$parts = explode( '.', $slug, -1 );
[4301] Fix | Delete
[4302] Fix | Delete
// Drop "bundle" from array.
[4303] Fix | Delete
array_shift( $parts );
[4304] Fix | Delete
[4305] Fix | Delete
$slug = implode( '-', $parts );
[4306] Fix | Delete
[4307] Fix | Delete
et_fb_enqueue_bundle( "et-fb-{$slug}", basename( $css_bundle ), $bundles, null );
[4308] Fix | Delete
[4309] Fix | Delete
$bundles[] = $slug;
[4310] Fix | Delete
}
[4311] Fix | Delete
}
[4312] Fix | Delete
[4313] Fix | Delete
// Hooks for theme/plugin specific styling which complements visual builder.
[4314] Fix | Delete
do_action( 'et_bfb_boot' );
[4315] Fix | Delete
} else {
[4316] Fix | Delete
et_pb_add_builder_page_js_css();
[4317] Fix | Delete
}
[4318] Fix | Delete
}
[4319] Fix | Delete
}
[4320] Fix | Delete
add_action( 'admin_enqueue_scripts', 'et_pb_admin_scripts_styles', 10, 1 );
[4321] Fix | Delete
[4322] Fix | Delete
/**
[4323] Fix | Delete
* Disable emoji detection script on edit page which has Backend Builder on it.
[4324] Fix | Delete
* WordPress automatically replaces emoji with plain image for backward compatibility
[4325] Fix | Delete
* on older browsers. This causes issue when emoji is used on header or other input
[4326] Fix | Delete
* text field because (when the modal is saved, shortcode is generated, and emoji
[4327] Fix | Delete
* is being replaced with plain image) it creates incorrect attribute markup
[4328] Fix | Delete
* such as `title="I <img class="emoji" src="../heart.png" /> WP"` and causes
[4329] Fix | Delete
* the whole input text value to be disappeared
[4330] Fix | Delete
*
[4331] Fix | Delete
* @return void
[4332] Fix | Delete
*/
[4333] Fix | Delete
function et_pb_remove_emoji_detection_script() {
[4334] Fix | Delete
// phpcs:disable WordPress.Security.NonceVerification -- This function does not change any state, and is therefore not susceptible to CSRF.
[4335] Fix | Delete
global $pagenow;
[4336] Fix | Delete
[4337] Fix | Delete
$disable_emoji_detection = false;
[4338] Fix | Delete
[4339] Fix | Delete
// Disable emoji detection script on editing page which has Backend Builder
[4340] Fix | Delete
// global $post isn't available at admin_init, so retrieve $post data manually.
[4341] Fix | Delete
if ( 'post.php' === $pagenow && isset( $_GET['post'] ) ) {
[4342] Fix | Delete
$post_id = (int) $_GET['post'];
[4343] Fix | Delete
$post = get_post( $post_id );
[4344] Fix | Delete
[4345] Fix | Delete
if ( et_builder_enabled_for_post( $post->ID ) ) {
[4346] Fix | Delete
$disable_emoji_detection = true;
[4347] Fix | Delete
}
[4348] Fix | Delete
}
[4349] Fix | Delete
[4350] Fix | Delete
// Disable emoji detection script on post new page which has Backend Builder.
[4351] Fix | Delete
$has_post_type_query = isset( $_GET['post_type'] );
[4352] Fix | Delete
if ( 'post-new.php' === $pagenow && ( ! $has_post_type_query || ( $has_post_type_query && in_array( $_GET['post_type'], et_builder_get_builder_post_types(), true ) ) ) ) {
[4353] Fix | Delete
$disable_emoji_detection = true;
[4354] Fix | Delete
}
[4355] Fix | Delete
[4356] Fix | Delete
if ( $disable_emoji_detection ) {
[4357] Fix | Delete
remove_action( 'admin_print_scripts', 'print_emoji_detection_script' );
[4358] Fix | Delete
}
[4359] Fix | Delete
// phpcs:enable
[4360] Fix | Delete
}
[4361] Fix | Delete
add_action( 'admin_init', 'et_pb_remove_emoji_detection_script' );
[4362] Fix | Delete
[4363] Fix | Delete
/**
[4364] Fix | Delete
* Disable emoji detection script on visual builder
[4365] Fix | Delete
* WordPress automatically replaces emoji with plain image for backward compatibility
[4366] Fix | Delete
* on older browsers. This causes issue when emoji is used on header or other input
[4367] Fix | Delete
* text field because the staticize emoji creates HTML markup which appears to be
[4368] Fix | Delete
* invalid on input[type="text"] field such as `title="I <img class="emoji"
[4369] Fix | Delete
* src="../heart.png" /> WP"` and causes the input text value to be escaped and
[4370] Fix | Delete
* disappeared
[4371] Fix | Delete
*
[4372] Fix | Delete
* @return void
[4373] Fix | Delete
*/
[4374] Fix | Delete
function et_fb_remove_emoji_detection_script() {
[4375] Fix | Delete
global $post;
[4376] Fix | Delete
[4377] Fix | Delete
// Disable emoji detection script on visual builder. React's auto escaping will
[4378] Fix | Delete
// remove all staticized emoji when being opened on modal's input field.
[4379] Fix | Delete
if ( isset( $post->ID ) && et_fb_is_enabled( $post->ID ) ) {
[4380] Fix | Delete
remove_action( 'wp_head', 'print_emoji_detection_script', 7 );
[4381] Fix | Delete
}
[4382] Fix | Delete
}
[4383] Fix | Delete
add_action( 'wp', 'et_fb_remove_emoji_detection_script' );
[4384] Fix | Delete
[4385] Fix | Delete
/**
[4386] Fix | Delete
* If the builder is used for the page, get rid of random p tags.
[4387] Fix | Delete
*
[4388] Fix | Delete
* @param string $content content.
[4389] Fix | Delete
*
[4390] Fix | Delete
* @return string|string[]|null
[4391] Fix | Delete
*/
[4392] Fix | Delete
function et_pb_fix_builder_shortcodes( $content ) {
[4393] Fix | Delete
if ( is_admin() ) {
[4394] Fix | Delete
// ET_Builder_Element is not loaded in the administration and some plugins call
[4395] Fix | Delete
// the_content there (e.g. WP File Manager).
[4396] Fix | Delete
return $content;
[4397] Fix | Delete
}
[4398] Fix | Delete
[4399] Fix | Delete
$is_theme_builder = ET_Builder_Element::is_theme_builder_layout();
[4400] Fix | Delete
$is_singular = is_singular() && 'on' === get_post_meta( get_the_ID(), '_et_pb_use_builder', true );
[4401] Fix | Delete
[4402] Fix | Delete
// if the builder is used for the page, get rid of random p tags.
[4403] Fix | Delete
if ( $is_theme_builder || $is_singular ) {
[4404] Fix | Delete
$content = et_pb_fix_shortcodes( $content );
[4405] Fix | Delete
}
[4406] Fix | Delete
[4407] Fix | Delete
return $content;
[4408] Fix | Delete
}
[4409] Fix | Delete
add_filter( 'the_content', 'et_pb_fix_builder_shortcodes' );
[4410] Fix | Delete
add_filter( 'et_builder_render_layout', 'et_pb_fix_builder_shortcodes' );
[4411] Fix | Delete
[4412] Fix | Delete
/**
[4413] Fix | Delete
* Prepare code module for wpautop.
[4414] Fix | Delete
*
[4415] Fix | Delete
* @param string $content content.
[4416] Fix | Delete
*
[4417] Fix | Delete
* @return string|string[]|null
[4418] Fix | Delete
*/
[4419] Fix | Delete
function et_pb_the_content_prep_code_module_for_wpautop( $content ) {
[4420] Fix | Delete
if ( 'on' === get_post_meta( get_the_ID(), '_et_pb_use_builder', true ) ) {
[4421] Fix | Delete
$content = et_pb_prep_code_module_for_wpautop( $content );
[4422] Fix | Delete
}
[4423] Fix | Delete
return $content;
[4424] Fix | Delete
}
[4425] Fix | Delete
add_filter( 'the_content', 'et_pb_the_content_prep_code_module_for_wpautop', 0 );
[4426] Fix | Delete
add_filter( 'et_builder_render_layout', 'et_pb_the_content_prep_code_module_for_wpautop', 0 );
[4427] Fix | Delete
[4428] Fix | Delete
if ( ! function_exists( 'et_pb_generate_new_layout_modal' ) ) {
[4429] Fix | Delete
/**
[4430] Fix | Delete
* Generate the html for "Add new template" Modal in Library.
[4431] Fix | Delete
*
[4432] Fix | Delete
* @return mixed|void
[4433] Fix | Delete
*/
[4434] Fix | Delete
function et_pb_generate_new_layout_modal() {
[4435] Fix | Delete
$template_type_option_output = '';
[4436] Fix | Delete
$template_module_tabs_option_output = '';
[4437] Fix | Delete
$template_global_option_output = '';
[4438] Fix | Delete
$layout_cat_option_output = '';
[4439] Fix | Delete
[4440] Fix | Delete
$new_layout_template_types = array(
[4441] Fix | Delete
'module' => esc_html__( 'Module', 'et_builder' ),
[4442] Fix | Delete
'fullwidth_module' => esc_html__( 'Fullwidth Module', 'et_builder' ),
[4443] Fix | Delete
'row' => esc_html__( 'Row', 'et_builder' ),
[4444] Fix | Delete
'section' => esc_html__( 'Section', 'et_builder' ),
[4445] Fix | Delete
'fullwidth_section' => esc_html__( 'Fullwidth Section', 'et_builder' ),
[4446] Fix | Delete
'specialty_section' => esc_html__( 'Specialty Section', 'et_builder' ),
[4447] Fix | Delete
'layout' => et_builder_i18n( 'Layout' ),
[4448] Fix | Delete
);
[4449] Fix | Delete
[4450] Fix | Delete
$template_type_options = apply_filters( 'et_pb_new_layout_template_types', $new_layout_template_types );
[4451] Fix | Delete
[4452] Fix | Delete
// construct output for the template type option.
[4453] Fix | Delete
if ( ! empty( $template_type_options ) ) {
[4454] Fix | Delete
$template_type_option_output = sprintf(
[4455] Fix | Delete
'<br><label>%1$s:</label>
[4456] Fix | Delete
<select id="new_template_type">',
[4457] Fix | Delete
esc_html__( 'Layout Type', 'et_builder' )
[4458] Fix | Delete
);
[4459] Fix | Delete
[4460] Fix | Delete
foreach ( $template_type_options as $option_id => $option_name ) {
[4461] Fix | Delete
$template_type_option_output .= sprintf(
[4462] Fix | Delete
'<option value="%1$s">%2$s</option>',
[4463] Fix | Delete
esc_attr( $option_id ),
[4464] Fix | Delete
esc_html( $option_name )
[4465] Fix | Delete
);
[4466] Fix | Delete
}
[4467] Fix | Delete
[4468] Fix | Delete
$template_type_option_output .= '</select>';
[4469] Fix | Delete
}
[4470] Fix | Delete
[4471] Fix | Delete
$template_global_option_output = apply_filters(
[4472] Fix | Delete
'et_pb_new_layout_global_option',
[4473] Fix | Delete
sprintf(
[4474] Fix | Delete
'<br><label>%1$s<input type="checkbox" value="global" id="et_pb_template_global"></label>',
[4475] Fix | Delete
esc_html__( 'Global', 'et_builder' )
[4476] Fix | Delete
)
[4477] Fix | Delete
);
[4478] Fix | Delete
[4479] Fix | Delete
// construct output for the layout category option.
[4480] Fix | Delete
$layout_cat_option_output .= sprintf(
[4481] Fix | Delete
'<br><label>%1$s</label>',
[4482] Fix | Delete
esc_html__( 'Add To Categories', 'et_builder' )
[4483] Fix | Delete
);
[4484] Fix | Delete
[4485] Fix | Delete
$layout_categories = apply_filters( 'et_pb_new_layout_cats_array', get_terms( 'layout_category', array( 'hide_empty' => false ) ) );
[4486] Fix | Delete
if ( is_array( $layout_categories ) && ! empty( $layout_categories ) ) {
[4487] Fix | Delete
$layout_cat_option_output .= '<div class="layout_cats_container">';
[4488] Fix | Delete
[4489] Fix | Delete
foreach ( $layout_categories as $category ) {
[4490] Fix | Delete
$layout_cat_option_output .= sprintf(
[4491] Fix | Delete
'<label>%1$s<input type="checkbox" value="%2$s"/></label>',
[4492] Fix | Delete
esc_html( $category->name ),
[4493] Fix | Delete
esc_attr( $category->term_id )
[4494] Fix | Delete
);
[4495] Fix | Delete
}
[4496] Fix | Delete
[4497] Fix | Delete
$layout_cat_option_output .= '</div>';
[4498] Fix | Delete
}
[4499] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function