From 7e12dbce2aa60ddedbafc09f3b2b707bcba05a6d Mon Sep 17 00:00:00 2001 From: Michael Bumann Date: Sun, 30 Oct 2022 12:03:38 +0100 Subject: [PATCH] Try to be smarter to replace only relevant short code quote signs --- includes/class-bln-publisher-paywall.php | 9 ++++++--- includes/class-bln-publisher.php | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/includes/class-bln-publisher-paywall.php b/includes/class-bln-publisher-paywall.php index ea0a1f3..b7073f2 100644 --- a/includes/class-bln-publisher-paywall.php +++ b/includes/class-bln-publisher-paywall.php @@ -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); diff --git a/includes/class-bln-publisher.php b/includes/class-bln-publisher.php index 5ea3911..12dc1b3 100644 --- a/includes/class-bln-publisher.php +++ b/includes/class-bln-publisher.php @@ -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 }