From cc19de6af2cfc2c26a1470c8ff95eceb4f9f8849 Mon Sep 17 00:00:00 2001 From: Gene Robinson Date: Tue, 27 Nov 2012 12:35:11 -0500 Subject: [PATCH 1/5] Adding hooks for bbPress compatibility. --- syntaxhighlighter.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/syntaxhighlighter.php b/syntaxhighlighter.php index 4fe2499..c446be4 100644 --- a/syntaxhighlighter.php +++ b/syntaxhighlighter.php @@ -46,12 +46,22 @@ function __construct() { add_filter( 'the_content', array( &$this, 'parse_shortcodes' ), 7 ); // Posts add_filter( 'comment_text', array( &$this, 'parse_shortcodes_comment' ), 7 ); // Comments add_filter( 'bp_get_the_topic_post_content', array( &$this, 'parse_shortcodes' ), 7 ); // BuddyPress + add_filter( 'bbp_get_topic_content', array( &$this, 'parse_shortcodes' ), 7 ); // bbPress + add_filter( 'bbp_get_reply_content', array( &$this, 'parse_shortcodes' ), 7 ); // bbPress // Into the database add_filter( 'content_save_pre', array( &$this, 'encode_shortcode_contents_slashed_noquickedit' ), 1 ); // Posts add_filter( 'pre_comment_content', array( &$this, 'encode_shortcode_contents_slashed' ), 1 ); // Comments add_filter( 'group_forum_post_text_before_save', array( &$this, 'encode_shortcode_contents_slashed' ), 1 ); // BuddyPress add_filter( 'group_forum_topic_text_before_save', array( &$this, 'encode_shortcode_contents_slashed' ), 1 ); // BuddyPress + add_filter( 'bbp_new_topic_pre_content', array( &$this, 'encode_shortcode_contents_slashed' ), 1 ); // bbPress + add_filter( 'bbp_new_reply_pre_content', array( &$this, 'encode_shortcode_contents_slashed' ), 1 ); // bbPress + add_filter( 'bbp_edit_topic_pre_content', array( &$this, 'encode_shortcode_contents_slashed' ), 1 ); // bbPress + add_filter( 'bbp_edit_reply_pre_content', array( &$this, 'encode_shortcode_contents_slashed' ), 1 ); // bbPress + + // Out of the database for decoded display + add_filter( 'bbp_get_topic_content', array( &$this, 'decode_shortcode_contents' ), 1); // bbPress + add_filter( 'bbp_get_reply_content', array( &$this, 'decode_shortcode_contents' ), 1); // bbPress // Out of the database for editing add_filter( 'the_editor_content', array( &$this, 'the_editor_content' ), 1 ); // Posts @@ -74,6 +84,10 @@ function __construct() { add_filter( 'save_post', array( &$this, 'mark_as_encoded' ), 10, 2 ); add_filter( 'plugin_action_links', array( &$this, 'settings_link' ), 10, 2 ); + // Load scortcodes script for bbPress if front-end tinymce editing is enabled + if ( function_exists('bbp_use_wp_editor') && bbp_use_wp_editor() ) + add_action( 'bbp_head', array( &$this, 'output_shortcodes_for_tinymce' ) ); // bbPress + // Register widget hooks // Requires change added in WordPress 2.9 if ( class_exists('WP_Embed') ) { From 24f54e4bd19e53d97c7d12f8d33ccfb8ae94a1c9 Mon Sep 17 00:00:00 2001 From: Gene Robinson Date: Tue, 27 Nov 2012 13:00:41 -0500 Subject: [PATCH 2/5] bbPress front-end editor encoding fix When bbPress tinymce editor is used on the front-end, the html tab needs decoding even when initially opened to the "visual" tab. --- syntaxhighlighter.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/syntaxhighlighter.php b/syntaxhighlighter.php index c446be4..de2269f 100644 --- a/syntaxhighlighter.php +++ b/syntaxhighlighter.php @@ -461,7 +461,8 @@ function the_editor_content( $content ) { // New code format (stored encoded in database) if ( 2 == $this->get_code_format( $post ) ) { // If TinyMCE is disabled or the HTML tab is set to be displayed first, we need to decode the HTML - if ( !user_can_richedit() || 'html' == wp_default_editor() ) + // bbPress front-end editor tinymce html tab needs decoding ( when visual tab is displayed first ) + if ( !user_can_richedit() || 'html' == wp_default_editor() || ( class_exists('bbPress') && !is_admin() ) ) $content = $this->decode_shortcode_contents( $content ); } From 38f3dc6e30096bcf9744be8c4ca42b5561270eaf Mon Sep 17 00:00:00 2001 From: Gene Robinson Date: Tue, 27 Nov 2012 14:14:20 -0500 Subject: [PATCH 3/5] New Function: no_texturize_shortcodes Avoiding extra formatting since bbPress it's content through wptexturize. Probably not a bad idea overall to exempt the shortcodes regardless of bbPress being active. --- syntaxhighlighter.php | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/syntaxhighlighter.php b/syntaxhighlighter.php index de2269f..33745ba 100644 --- a/syntaxhighlighter.php +++ b/syntaxhighlighter.php @@ -69,6 +69,9 @@ function __construct() { add_filter( 'bp_get_the_topic_text', array( &$this, 'decode_shortcode_contents' ), 1 ); // BuddyPress add_filter( 'bp_get_the_topic_post_edit_text', array( &$this, 'decode_shortcode_contents' ), 1 ); // BuddyPress + // Exempt shortcodes from wp_texturize() + add_filter( 'no_texturize_shortcodes', array( &$this, 'no_texturize_shortcodes' ) ); //bbPress + // Outputting SyntaxHighlighter's JS and CSS add_action( 'wp_head', array( &$this, 'output_header_placeholder' ), 15 ); add_action( 'admin_head', array( &$this, 'output_header_placeholder' ), 15 ); // For comments @@ -86,7 +89,7 @@ function __construct() { // Load scortcodes script for bbPress if front-end tinymce editing is enabled if ( function_exists('bbp_use_wp_editor') && bbp_use_wp_editor() ) - add_action( 'bbp_head', array( &$this, 'output_shortcodes_for_tinymce' ) ); // bbPress + add_action( 'bbp_head', array( &$this, 'output_shortcodes_for_tinymce' ) ); // bbPress // Register widget hooks // Requires change added in WordPress 2.9 @@ -336,6 +339,14 @@ function enforce_font_size() { } + // A filter function that exempts shortcodes from wptexturize() + function no_texturize_shortcodes( $exempted_shortcodes = array() ) { + foreach ( $this->shortcodes as $shortcode ) + $exempted_shortcodes[] = $shortcode; + return $exempted_shortcodes; + } + + // A filter function that runs do_shortcode() but only with this plugin's shortcodes function shortcode_hack( $content, $callback ) { global $shortcode_tags; From 2fd563d89175b75e106b0228bb5fed0936c29286 Mon Sep 17 00:00:00 2001 From: Gene Robinson Date: Fri, 30 Nov 2012 03:39:28 -0500 Subject: [PATCH 4/5] More complete bbPress compatibility Removed function: break_tinymce_cache() the hook it was loaded into had been deprecated. A query string can be added to the external plugin script uri if desired. Someone else can decide if that is still necessary. New function: force_bbp_tiny_editor() forces bbpress to use the tiny not its current default teeny editor. The teeny wont load external plugins. New function: function tinymce_before_init() filtering tinymce so it doesn't mangle code by stripping class attributes and injecting rogue pre tags. Added support for WP post revisions and WP trash & bbPress' front-end quicksave AJAX requests This commit needs more testing but I think it's buttoned down for the most part. --- syntaxhighlighter.php | 82 ++++++++++++++++++++++++++++++++----------- 1 file changed, 61 insertions(+), 21 deletions(-) diff --git a/syntaxhighlighter.php b/syntaxhighlighter.php index 33745ba..466c2a0 100644 --- a/syntaxhighlighter.php +++ b/syntaxhighlighter.php @@ -54,14 +54,15 @@ function __construct() { add_filter( 'pre_comment_content', array( &$this, 'encode_shortcode_contents_slashed' ), 1 ); // Comments add_filter( 'group_forum_post_text_before_save', array( &$this, 'encode_shortcode_contents_slashed' ), 1 ); // BuddyPress add_filter( 'group_forum_topic_text_before_save', array( &$this, 'encode_shortcode_contents_slashed' ), 1 ); // BuddyPress - add_filter( 'bbp_new_topic_pre_content', array( &$this, 'encode_shortcode_contents_slashed' ), 1 ); // bbPress - add_filter( 'bbp_new_reply_pre_content', array( &$this, 'encode_shortcode_contents_slashed' ), 1 ); // bbPress - add_filter( 'bbp_edit_topic_pre_content', array( &$this, 'encode_shortcode_contents_slashed' ), 1 ); // bbPress - add_filter( 'bbp_edit_reply_pre_content', array( &$this, 'encode_shortcode_contents_slashed' ), 1 ); // bbPress + add_filter( 'bbp_new_topic_pre_content', array( &$this, 'encode_shortcode_contents_slashed_noquickedit' ), 1 ); // bbPress + add_filter( 'bbp_new_reply_pre_content', array( &$this, 'encode_shortcode_contents_slashed_noquickedit' ), 1 ); // bbPress + add_filter( 'bbp_edit_topic_pre_content', array( &$this, 'encode_shortcode_contents_slashed_noquickedit' ), 1 ); // bbPress + add_filter( 'bbp_edit_reply_pre_content', array( &$this, 'encode_shortcode_contents_slashed_noquickedit' ), 1 ); // bbPress // Out of the database for decoded display - add_filter( 'bbp_get_topic_content', array( &$this, 'decode_shortcode_contents' ), 1); // bbPress - add_filter( 'bbp_get_reply_content', array( &$this, 'decode_shortcode_contents' ), 1); // bbPress + add_filter( '_wp_post_revision_field_post_content', array( &$this, 'decode_shortcode_contents' ), 1); // Revisions + add_filter( 'bbp_get_topic_content', array( &$this, 'decode_shortcode_contents' ), 1); // bbPress + add_filter( 'bbp_get_reply_content', array( &$this, 'decode_shortcode_contents' ), 1); // bbPress // Out of the database for editing add_filter( 'the_editor_content', array( &$this, 'the_editor_content' ), 1 ); // Posts @@ -69,8 +70,8 @@ function __construct() { add_filter( 'bp_get_the_topic_text', array( &$this, 'decode_shortcode_contents' ), 1 ); // BuddyPress add_filter( 'bp_get_the_topic_post_edit_text', array( &$this, 'decode_shortcode_contents' ), 1 ); // BuddyPress - // Exempt shortcodes from wp_texturize() - add_filter( 'no_texturize_shortcodes', array( &$this, 'no_texturize_shortcodes' ) ); //bbPress + // Exempt shortcodes from wp_texturize + add_filter( 'no_texturize_shortcodes', array( &$this, 'no_texturize_shortcodes' ) ); // bbPress // Outputting SyntaxHighlighter's JS and CSS add_action( 'wp_head', array( &$this, 'output_header_placeholder' ), 15 ); @@ -79,17 +80,18 @@ function __construct() { add_action( 'admin_footer', array( &$this, 'maybe_output_scripts' ), 15 ); // For comments // Admin hooks - add_action( 'admin_init', array( &$this, 'register_setting' ) ); - add_action( 'admin_menu', array( &$this, 'register_settings_page' ) ); - add_action( 'admin_head', array( &$this, 'output_shortcodes_for_tinymce' ) ); - add_filter( 'mce_external_plugins', array( &$this, 'add_tinymce_plugin' ) ); - add_filter( 'tiny_mce_version', array( &$this, 'break_tinymce_cache' ) ); - add_filter( 'save_post', array( &$this, 'mark_as_encoded' ), 10, 2 ); - add_filter( 'plugin_action_links', array( &$this, 'settings_link' ), 10, 2 ); + add_action( 'admin_init', array( &$this, 'register_setting' ) ); + add_action( 'admin_menu', array( &$this, 'register_settings_page' ) ); + add_action( 'admin_head', array( &$this, 'output_shortcodes_for_tinymce' ) ); + add_filter( 'bbp_after_get_the_content_parse_args', array( &$this, 'force_bbp_tiny_editor' ) ); // bbPress + add_filter( 'tiny_mce_before_init', array( &$this, 'tinymce_before_init') ); // bbPress + add_filter( 'mce_external_plugins', array( &$this, 'add_tinymce_plugin' ) ); + add_filter( 'save_post', array( &$this, 'mark_as_encoded' ), 10, 2 ); + add_filter( 'plugin_action_links', array( &$this, 'settings_link' ), 10, 2 ); // Load scortcodes script for bbPress if front-end tinymce editing is enabled if ( function_exists('bbp_use_wp_editor') && bbp_use_wp_editor() ) - add_action( 'bbp_head', array( &$this, 'output_shortcodes_for_tinymce' ) ); // bbPress + add_action( 'bbp_head', array( &$this, 'output_shortcodes_for_tinymce' ) );// bbPress // Register widget hooks // Requires change added in WordPress 2.9 @@ -299,10 +301,33 @@ function add_tinymce_plugin( $plugins ) { return $plugins; } - - // Break the TinyMCE cache - function break_tinymce_cache( $version ) { - return $version . '-sh' . $this->pluginver; + // Filter tinymce so that it does not reformat the preformatted code so badly + function tinymce_before_init( $args) { + $elements = array( 'blockquote', + 'center', + 'dir', + 'div', + 'dl', + 'fieldset', + 'form', + 'h1','h2','h3','h4','h5','h6', + 'hr', + 'isindex', + 'noframes', + 'noscript', + 'ol', + 'p', + 'table', + 'ul', + ); + + $children = "+pre['address']"; + foreach ($elements as $element) + $children .= ",+pre[$element]"; + + $args['valid_children'] = $children; + $args['paste_strip_class_attributes'] = 'none'; + return $args; } @@ -320,6 +345,13 @@ function settings_link( $links, $file ) { } + // Force bbPress to use tiny not teeny mce so that our mceplugin will load + function force_bbp_tiny_editor( $args = array() ) { + $args['teeny'] = false; + return $args; + } + + // Output list of shortcode tags for the TinyMCE plugin function output_shortcodes_for_tinymce() { $shortcodes = array(); @@ -437,7 +469,15 @@ function encode_shortcode_contents_slashed_noquickedit( $content ) { // Post quick edits aren't decoded for display, so we don't need to encode them (again) if ( !empty($_POST) && !empty($_POST['action']) && 'inline-save' == $_POST['action'] ) return $content; - + + // Trashed Posts need to be decoded on undo and restore (untrashing) + if ( !empty($_REQUEST) && !empty($_REQUEST['action']) && 'untrash' == $_REQUEST['action'] ) + return $this->decode_shortcode_contents( $content ); + + // bbPress' quick edit AJAX request on front end editor don't need encoding upon save. + if ( !empty($_REQUEST) && !empty($_REQUEST['action']) && ('untrash' == $_REQUEST['sub_action'] || 'trash' == $_REQUEST['sub_action'] ) ) + return $content ; + return $this->encode_shortcode_contents_slashed( $content ); } From 49c7d917d1e6e25b76a342ec7aec8c7fc529a149 Mon Sep 17 00:00:00 2001 From: Gene Robinson Date: Fri, 30 Nov 2012 14:14:23 -0500 Subject: [PATCH 5/5] Improved WordPress and bbPress compatiblity Improved support for WP post revisions, WP trash & bbPress quicksave/adminlinks ( merge split trash ) New function: force_bbp_tiny_editor() Will force bbpress to use the tiny editor not its current default the teeny editor. The teeny one wont load external plugins. New function: function tinymce_before_init() filtering tinymce so taht it doesn't mangle code by stripping class attributes and injecting rogue pre tags. Added support for WP post revisions, WP trash & bbPress quicksave/adminlinks ( merge split trash ) --- syntaxhighlighter.php | 94 +++++++++++++++++++++++++------------------ 1 file changed, 54 insertions(+), 40 deletions(-) diff --git a/syntaxhighlighter.php b/syntaxhighlighter.php index 466c2a0..3e3ac5a 100644 --- a/syntaxhighlighter.php +++ b/syntaxhighlighter.php @@ -46,23 +46,23 @@ function __construct() { add_filter( 'the_content', array( &$this, 'parse_shortcodes' ), 7 ); // Posts add_filter( 'comment_text', array( &$this, 'parse_shortcodes_comment' ), 7 ); // Comments add_filter( 'bp_get_the_topic_post_content', array( &$this, 'parse_shortcodes' ), 7 ); // BuddyPress - add_filter( 'bbp_get_topic_content', array( &$this, 'parse_shortcodes' ), 7 ); // bbPress - add_filter( 'bbp_get_reply_content', array( &$this, 'parse_shortcodes' ), 7 ); // bbPress + add_filter( 'bbp_get_topic_content', array( &$this, 'parse_shortcodes' ), 7 ); // bbPress + add_filter( 'bbp_get_reply_content', array( &$this, 'parse_shortcodes' ), 7 ); // bbPress // Into the database - add_filter( 'content_save_pre', array( &$this, 'encode_shortcode_contents_slashed_noquickedit' ), 1 ); // Posts + add_filter( 'content_save_pre', array( &$this, 'encode_shortcode_contents_slashed_noquickedit' ), 1 ); // Posts add_filter( 'pre_comment_content', array( &$this, 'encode_shortcode_contents_slashed' ), 1 ); // Comments add_filter( 'group_forum_post_text_before_save', array( &$this, 'encode_shortcode_contents_slashed' ), 1 ); // BuddyPress add_filter( 'group_forum_topic_text_before_save', array( &$this, 'encode_shortcode_contents_slashed' ), 1 ); // BuddyPress - add_filter( 'bbp_new_topic_pre_content', array( &$this, 'encode_shortcode_contents_slashed_noquickedit' ), 1 ); // bbPress - add_filter( 'bbp_new_reply_pre_content', array( &$this, 'encode_shortcode_contents_slashed_noquickedit' ), 1 ); // bbPress - add_filter( 'bbp_edit_topic_pre_content', array( &$this, 'encode_shortcode_contents_slashed_noquickedit' ), 1 ); // bbPress - add_filter( 'bbp_edit_reply_pre_content', array( &$this, 'encode_shortcode_contents_slashed_noquickedit' ), 1 ); // bbPress + add_filter( 'bbp_new_topic_pre_content', array( &$this, 'encode_shortcode_contents_slashed_noquickedit' ), 1 ); // bbPress + add_filter( 'bbp_new_reply_pre_content', array( &$this, 'encode_shortcode_contents_slashed_noquickedit' ), 1 ); // bbPress + add_filter( 'bbp_edit_topic_pre_content', array( &$this, 'encode_shortcode_contents_slashed_noquickedit' ), 1 ); // bbPress + add_filter( 'bbp_edit_reply_pre_content', array( &$this, 'encode_shortcode_contents_slashed_noquickedit' ), 1 ); // bbPress // Out of the database for decoded display - add_filter( '_wp_post_revision_field_post_content', array( &$this, 'decode_shortcode_contents' ), 1); // Revisions - add_filter( 'bbp_get_topic_content', array( &$this, 'decode_shortcode_contents' ), 1); // bbPress - add_filter( 'bbp_get_reply_content', array( &$this, 'decode_shortcode_contents' ), 1); // bbPress + add_filter( '_wp_post_revision_field_post_content', array( &$this, 'decode_shortcode_contents' ), 1); // Revisions + add_filter( 'bbp_get_topic_content', array( &$this, 'decode_shortcode_contents' ), 1); // bbPress + add_filter( 'bbp_get_reply_content', array( &$this, 'decode_shortcode_contents' ), 1); // bbPress // Out of the database for editing add_filter( 'the_editor_content', array( &$this, 'the_editor_content' ), 1 ); // Posts @@ -71,7 +71,7 @@ function __construct() { add_filter( 'bp_get_the_topic_post_edit_text', array( &$this, 'decode_shortcode_contents' ), 1 ); // BuddyPress // Exempt shortcodes from wp_texturize - add_filter( 'no_texturize_shortcodes', array( &$this, 'no_texturize_shortcodes' ) ); // bbPress + add_filter( 'no_texturize_shortcodes', array( &$this, 'no_texturize_shortcodes' ) ); // bbPress // Outputting SyntaxHighlighter's JS and CSS add_action( 'wp_head', array( &$this, 'output_header_placeholder' ), 15 ); @@ -83,15 +83,15 @@ function __construct() { add_action( 'admin_init', array( &$this, 'register_setting' ) ); add_action( 'admin_menu', array( &$this, 'register_settings_page' ) ); add_action( 'admin_head', array( &$this, 'output_shortcodes_for_tinymce' ) ); - add_filter( 'bbp_after_get_the_content_parse_args', array( &$this, 'force_bbp_tiny_editor' ) ); // bbPress - add_filter( 'tiny_mce_before_init', array( &$this, 'tinymce_before_init') ); // bbPress + add_filter( 'bbp_after_get_the_content_parse_args', array( &$this, 'force_bbp_tiny_editor' ) ); // bbPress + add_filter( 'tiny_mce_before_init', array( &$this, 'tinymce_before_init') ); // bbPress add_filter( 'mce_external_plugins', array( &$this, 'add_tinymce_plugin' ) ); add_filter( 'save_post', array( &$this, 'mark_as_encoded' ), 10, 2 ); add_filter( 'plugin_action_links', array( &$this, 'settings_link' ), 10, 2 ); // Load scortcodes script for bbPress if front-end tinymce editing is enabled if ( function_exists('bbp_use_wp_editor') && bbp_use_wp_editor() ) - add_action( 'bbp_head', array( &$this, 'output_shortcodes_for_tinymce' ) );// bbPress + add_action( 'bbp_head', array( &$this, 'output_shortcodes_for_tinymce' ) );// bbPress // Register widget hooks // Requires change added in WordPress 2.9 @@ -303,30 +303,33 @@ function add_tinymce_plugin( $plugins ) { // Filter tinymce so that it does not reformat the preformatted code so badly function tinymce_before_init( $args) { - $elements = array( 'blockquote', - 'center', - 'dir', - 'div', - 'dl', - 'fieldset', - 'form', - 'h1','h2','h3','h4','h5','h6', - 'hr', - 'isindex', - 'noframes', - 'noscript', - 'ol', - 'p', - 'table', - 'ul', - ); + $elements = array( + 'blockquote', + 'center', + 'dir', + 'div', + 'dl', + 'fieldset', + 'form', + 'h1','h2','h3','h4','h5','h6', + 'hr', + 'isindex', + 'noframes', + 'noscript', + 'ol', + 'p', + 'table', + 'ul', + ); $children = "+pre['address']"; + foreach ($elements as $element) $children .= ",+pre[$element]"; $args['valid_children'] = $children; $args['paste_strip_class_attributes'] = 'none'; + return $args; } @@ -458,7 +461,8 @@ function encode_shortcode_contents_slashed( $content ) { // HTML entity encode the contents of shortcodes. Expects slashed content. Aborts if AJAX. function encode_shortcode_contents_slashed_noquickedit( $content ) { - + // Cases which do not need encoding + // In certain weird circumstances, the content gets run through "content_save_pre" twice // Keep track and don't allow this filter to be run twice // I couldn't easily figure out why this happens and didn't bother looking into it further as this works fine @@ -466,17 +470,27 @@ function encode_shortcode_contents_slashed_noquickedit( $content ) { return $content; $this->content_save_pre_ran = true; - // Post quick edits aren't decoded for display, so we don't need to encode them (again) - if ( !empty($_POST) && !empty($_POST['action']) && 'inline-save' == $_POST['action'] ) + // Post quick edits (wp-admin) + if ( !empty( $_POST ) && !empty( $_POST['action'] ) && 'inline-save' == $_POST['action'] ) return $content; - // Trashed Posts need to be decoded on undo and restore (untrashing) - if ( !empty($_REQUEST) && !empty($_REQUEST['action']) && 'untrash' == $_REQUEST['action'] ) - return $this->decode_shortcode_contents( $content ); + // bbPress (front-end) admin links for topic split or merge + if ( !empty( $_POST ) && !empty( $_POST['action'] ) && ( 'bbp-split-topic' == $_POST['action'] || 'bbp-merge-topic' == $_POST['action'] ) ) + return $content; + + // bbPress (front-end) admin links for trash + if ( !empty( $_GET ) && !empty( $_GET['action'] ) && ( 'bbp_toggle_topic_trash' == $_GET['action'] || 'bbp_toggle_reply_trash' == $_GET['action'] ) ) + return $content; + + // bbPress admin links (front-end) and quick links (wp-admin) for spam + if ( !empty( $_GET ) && !empty( $_GET['action'] ) && ( 'bbp_toggle_topic_spam' == $_GET['action'] || 'bbp_toggle_reply_spam' == $_GET['action'] ) ) + return $content; - // bbPress' quick edit AJAX request on front end editor don't need encoding upon save. - if ( !empty($_REQUEST) && !empty($_REQUEST['action']) && ('untrash' == $_REQUEST['sub_action'] || 'trash' == $_REQUEST['sub_action'] ) ) - return $content ; + // Cases which need decoding + + // Trashed posts (wp-admin) need to be decoded on undo and restore (untrashing) + if ( !empty( $_GET ) && !empty( $_GET['action'] ) && 'untrash' == $_GET['action'] ) + return $this->decode_shortcode_contents( $content ); return $this->encode_shortcode_contents_slashed( $content ); }