Skip to content

Commit

Permalink
working on conflicts with builders
Browse files Browse the repository at this point in the history
  • Loading branch information
justin-peacock committed Oct 6, 2015
1 parent 5b94535 commit 1a2d2fe
Showing 1 changed file with 56 additions and 9 deletions.
65 changes: 56 additions & 9 deletions device-mockups.php
Original file line number Diff line number Diff line change
Expand Up @@ -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/' );
Expand Down Expand Up @@ -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 =
'/'
. '<p>' // 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' );

0 comments on commit 1a2d2fe

Please sign in to comment.