diff --git a/device-mockups.php b/device-mockups.php index 6b1031f..43cc3e3 100644 --- a/device-mockups.php +++ b/device-mockups.php @@ -38,8 +38,6 @@ /** * Load plugin textdomain. - * - * @since 1.0.0 */ function device_mockups_load_textdomain() { load_plugin_textdomain( 'device_mockups', false, plugin_basename( DEVICE_MOCKUPS_PATH ) . '/languages/' ); @@ -101,12 +99,61 @@ function device_mockups_shortcode_exclude( $shortcodes ) { return $shortcodes; } -add_filter( 'no_texturize_shortcodes', 'device_mockups_shortcode_exclude' ); +function device_mockups_shortcode_unautop( $pee ) { + global $shortcode_tags; -/** - * remove and re-prioritize wpautop to prevent auto formatting inside shortcodes - */ -remove_filter( 'the_content', 'wpautop' ); -add_filter( 'the_content', 'wpautop', 99 ); -add_filter( 'the_content', 'shortcode_unautop', 100 ); + if ( empty( $shortcode_tags ) || ! is_array( $shortcode_tags ) ) { + return $pee; + } + + $tagregexp = join( '|', array_map( 'preg_quote', array_keys( $shortcode_tags ) ) ); + + $pattern = + '/' + . '
' // Opening paragraph + . '\\s*+' // Optional leading whitespace + . '(' // 1: The shortcode + . '\\[\\/?' // Opening bracket for opening or closing shortcode tag + . "($tagregexp)" // 2: Shortcode name + . '(?![\\w-])' // Not followed by word character or hyphen + // Unroll the loop: Inside the opening shortcode tag + . '[^\\]\\/]*' // Not a closing bracket or forward slash + . '(?:' + . '\\/(?!\\])' // A forward slash not followed by a closing bracket + . '[^\\]\\/]*' // Not a closing bracket or forward slash + . ')*?' + . '[\\w\\s="\']*' // Shortcode attributes + . '(?:' + . '\\s*+' // Optional leading whitespace, supports [footag /] + . '\\/\\]' // Self closing tag and closing bracket + . '|' + . '\\]' // Closing bracket + . '(?:' // Unroll the loop: Optionally, anything between the opening and closing shortcode tags + . '(?!<\/p>)' // Not followed by closing paragraph + . '[^\\[]*+' // Not an opening bracket, matches all content between closing bracket and closing shortcode tag + . '(?:' + . '\\[(?!\\/\\2\\])' // An opening bracket not followed by the closing shortcode tag + . '[^\\[]*+' // Not an opening bracket + . ')*+' + . '\\[\\/\\2\\]' // Closing shortcode tag + . ')?' + . ')' + . ')' + . '\\s*+' // optional trailing whitespace + . '<\\/p>' // closing paragraph + . '/s'; + + return preg_replace( $pattern, '$1', $pee ); +} + +foreach ( array( 'device', 'browser' ) as $filter ) { + remove_filter( $filter, 'shortcode_unautop' ); + add_filter( $filter, 'device_mockups_shortcode_unautop' ); +} + +remove_filter( 'the_content', 'shortcode_unautop' ); +add_filter( 'the_content', 'device_mockups_shortcode_unautop' ); +remove_filter( 'the_excerpt', 'shortcode_unautop' ); +add_filter( 'the_excerpt', 'device_mockups_shortcode_unautop' ); +add_filter( 'no_texturize_shortcodes', 'device_mockups_shortcode_exclude' ); add_filter( 'widget_text', 'do_shortcode' ); \ No newline at end of file