Skip to content

Commit

Permalink
Try to be smarter to replace only relevant short code quote signs
Browse files Browse the repository at this point in the history
  • Loading branch information
bumi committed Oct 30, 2022
1 parent ae19923 commit 7e12dbc
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
9 changes: 6 additions & 3 deletions includes/class-bln-publisher-paywall.php
Original file line number Diff line number Diff line change
Expand Up @@ -244,10 +244,13 @@ protected function extract_options_from_shortcode()
$atts_string = $m[1];
// wptexturize might replace the quotes in the shortcode we try to make this undone
// maybe related: https://github.com/WordPress/gutenberg/issues/37754 + https://github.com/elementor/elementor/issues/9340
// replaceing potential quotes that I found with normal quotes (`"`) that can be parsed by `shortcode_parse_atts`
$invalid_quotes = array("", "", "ˮ", "ʺ", "", "", "˝", "", "", "", "");
// replacing potential quotes that I found with normal quotes (`"`) that can be parsed by `shortcode_parse_atts`
// NOTE: this means none of those character can be used in the paywall attributes (button text, description, etc.)
$invalid_quotes = array("", "ˮ", "ʺ", "", "", "˝", "", "", "", "", "`", "´");
foreach($invalid_quotes as $invalid_char) {
$atts_string = str_replace($invalid_char, '"', $atts_string);
// trying to match only the relevant quotes (not the ones that might be used in the text
$atts_string = str_replace("=". $invalid_char, '="', $atts_string); // replace the quotes at the beginning (after an = sign
$atts_string = preg_replace('/' . $invalid_char . '(\s|\z)/', '" ', $atts_string); // replace the quotes at the end of an attribute (either followed by a whitespace or the end of the string)
}

$atts = shortcode_parse_atts($atts_string);
Expand Down
2 changes: 1 addition & 1 deletion includes/class-bln-publisher.php
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ private function define_public_hooks()
}

// Apply Paywall to the content
$this->loader->add_filter('no_texturize_shortcodes', $this->plugin_public, 'shortcodes_to_exempt_from_wptexturize', 9); // try to avoid wptexturize from texturizing the short codes
$this->loader->add_filter('no_texturize_shortcodes', $this->plugin_public, 'shortcodes_to_exempt_from_wptexturize', 8); // try to avoid wptexturize from texturizing the short codes
$this->loader->add_filter('the_content', $this->plugin_public, 'ln_paywall_filter', 999999999); // then number is the priority. Elementor uses a high number and does loads of things in the `the_content` filter so we need to run afterwards
}

Expand Down

0 comments on commit 7e12dbc

Please sign in to comment.