From b4f38827abb9da4a47cef1f14656910163a59e21 Mon Sep 17 00:00:00 2001 From: Daniel Walmsley Date: Mon, 23 Jan 2017 15:34:25 -0800 Subject: [PATCH] Only remove/add post shortcodes if rendering filtered content --- sync/class.jetpack-sync-module-posts.php | 47 ++++++++++++------------ 1 file changed, 24 insertions(+), 23 deletions(-) diff --git a/sync/class.jetpack-sync-module-posts.php b/sync/class.jetpack-sync-module-posts.php index 344cdd129f5b3..be31c761a25d0 100644 --- a/sync/class.jetpack-sync-module-posts.php +++ b/sync/class.jetpack-sync-module-posts.php @@ -133,7 +133,7 @@ function add_embed() { // Expands wp_insert_post to include filtered content function filter_post_content_and_add_links( $post_object ) { - global $post, $shortcode_tags; + global $post; $post = $post_object; // return non existant post @@ -178,36 +178,37 @@ function filter_post_content_and_add_links( $post_object ) { $post->post_password = 'auto-' . wp_generate_password( 10, false ); } - $shortcodes_and_callbacks_to_remove = array(); - /** - * Filter prevents some shortcodes from expanding. - * - * Since we can can expand some type of shortcode better on the .com side and make the - * expansion more relevant to contexts. For example [galleries] and subscription emails - * - * @since 4.5.0 - * - * @param array of shortcode tags to remove. - */ - $shortcodes_to_remove = apply_filters( 'jetpack_sync_do_not_expand_shortcodes', array( 'gallery', 'slideshow' ) ); - $removed_shortcode_callbacks = array(); - foreach ( $shortcodes_to_remove as $shortcode ) { - if ( isset ( $shortcode_tags[ $shortcode ] ) ) { - $removed_shortcode_callbacks[ $shortcode ] = $shortcode_tags[ $shortcode ]; + /** This filter is already documented in core. wp-includes/post-template.php */ + if ( Jetpack_Sync_Settings::get_setting( 'render_filtered_content' ) && $post_type->public ) { + global $shortcode_tags; + $shortcodes_and_callbacks_to_remove = array(); + /** + * Filter prevents some shortcodes from expanding. + * + * Since we can can expand some type of shortcode better on the .com side and make the + * expansion more relevant to contexts. For example [galleries] and subscription emails + * + * @since 4.5.0 + * + * @param array of shortcode tags to remove. + */ + $shortcodes_to_remove = apply_filters( 'jetpack_sync_do_not_expand_shortcodes', array( 'gallery', 'slideshow' ) ); + $removed_shortcode_callbacks = array(); + foreach ( $shortcodes_to_remove as $shortcode ) { + if ( isset ( $shortcode_tags[ $shortcode ] ) ) { + $removed_shortcode_callbacks[ $shortcode ] = $shortcode_tags[ $shortcode ]; + } } - } - array_map( 'remove_shortcode' , array_keys( $removed_shortcode_callbacks ) ); + array_map( 'remove_shortcode' , array_keys( $removed_shortcode_callbacks ) ); - /** This filter is already documented in core. wp-includes/post-template.php */ - if ( Jetpack_Sync_Settings::get_setting( 'render_filtered_content' ) && $post_type->public ) { $post->post_content_filtered = apply_filters( 'the_content', $post->post_content ); $post->post_excerpt_filtered = apply_filters( 'the_excerpt', $post->post_excerpt ); - } - foreach ( $removed_shortcode_callbacks as $shortcode => $callback ) { + foreach ( $removed_shortcode_callbacks as $shortcode => $callback ) { add_shortcode( $shortcode, $callback ); } + } $this->add_embed();