| @@ -8,8 +8,12 @@ | ||
| 8 | 8 | * Embed code example: |
| 9 | 9 | * <script type="text/javascript" src="//downloads.mailchimp.com/js/signup-forms/popup/unique-methods/embed.js" data-dojo-config="usePlainJson: true, isDebug: false"></script><script type="text/javascript">window.dojoRequire(["mojo/signup-forms/Loader"], function(L) { L.start({"baseUrl":"mc.us11.list-manage.com","uuid":"1ca7856462585a934b8674c71","lid":"2d24f1898b","uniqueMethods":true}) })</script> |
| 10 | 10 | */ |
| 11 | 11 | |
| 12 | +if ( ! defined( 'ABSPATH' ) ) { | |
| 13 | + exit( 0 ); | |
| 14 | +} | |
| 15 | + | |
| 12 | 16 | // phpcs:disable Universal.Files.SeparateFunctionsFromOO.Mixed -- TODO: Move classes to appropriately-named class files. |
| 13 | 17 | |
| 14 | 18 | /** |
| 15 | 19 | * Register [mailchimp_subscriber_popup] shortcode and add a filter to 'pre_kses' queue to reverse MailChimp embed to shortcode. |
| @@ -23,15 +27,18 @@ | ||
| 23 | 27 | 'MailChimp_Subscriber_Popup', |
| 24 | 28 | 'shortcode', |
| 25 | 29 | ) |
| 26 | 30 | ); |
| 27 | - add_filter( | |
| 28 | - 'pre_kses', | |
| 29 | - array( | |
| 30 | - 'MailChimp_Subscriber_Popup', | |
| 31 | - 'reversal', | |
| 32 | - ) | |
| 33 | - ); | |
| 31 | + | |
| 32 | + if ( jetpack_shortcodes_should_hook_pre_kses() ) { | |
| 33 | + add_filter( | |
| 34 | + 'pre_kses', | |
| 35 | + array( | |
| 36 | + 'MailChimp_Subscriber_Popup', | |
| 37 | + 'reversal', | |
| 38 | + ) | |
| 39 | + ); | |
| 40 | + } | |
| 34 | 41 | } |
| 35 | 42 | |
| 36 | 43 | if ( defined( 'IS_WPCOM' ) && IS_WPCOM ) { |
| 37 | 44 | add_action( 'init', 'jetpack_mailchimp_subscriber_popup' ); |
| @@ -105,14 +112,11 @@ | ||
| 105 | 112 | // the regex rule for a specific embed. |
| 106 | 113 | $replace_regex = sprintf( '#\s*%s\s*#', preg_quote( $matches[0][ $index ], '#' ) ); |
| 107 | 114 | |
| 108 | 115 | $attrs = json_decode( '{' . $js_vars . '}' ); |
| 109 | - | |
| 110 | - if ( $matches[2][ $index ] ) { | |
| 111 | - $config_attrs = json_decode( '{' . $matches[2][ $index ] . '}' ); | |
| 112 | - foreach ( $config_attrs as $key => $value ) { | |
| 113 | - $attrs->$key = ( 1 === $value ) ? 'true' : 'false'; | |
| 114 | - } | |
| 116 | + // If JSON is garbage, skip. | |
| 117 | + if ( ! $attrs ) { | |
| 118 | + continue; | |
| 115 | 119 | } |
| 116 | 120 | |
| 117 | 121 | $shortcode = self::build_shortcode_from_reversal_attrs( $attrs ); |
| 118 | 122 | |
| @@ -219,7 +223,7 @@ | ||
| 219 | 223 | do_action( 'jetpack_stats_extra', 'mailchimp_subscriber_popup', 'view' ); |
| 220 | 224 | |
| 221 | 225 | $displayed_once = true; |
| 222 | 226 | |
| 223 | - return "\n\n" . '<script type="text/javascript" data-dojo-config="' . esc_attr( implode( ', ', $config_vars ) ) . '">jQuery.getScript( "//downloads.mailchimp.com/js/signup-forms/popup/unique-methods/embed.js", function( data, textStatus, jqxhr ) { window.dojoRequire(["mojo/signup-forms/Loader"], function(L) { L.start(' . wp_json_encode( $js_vars ) . ') });} );</script>' . "\n\n"; | |
| 227 | + return "\n\n" . '<script type="text/javascript" data-dojo-config="' . esc_attr( implode( ', ', $config_vars ) ) . '">jQuery.getScript( "//downloads.mailchimp.com/js/signup-forms/popup/unique-methods/embed.js", function( data, textStatus, jqxhr ) { window.dojoRequire(["mojo/signup-forms/Loader"], function(L) { L.start(' . wp_json_encode( $js_vars, JSON_UNESCAPED_SLASHES | JSON_HEX_TAG | JSON_HEX_AMP ) . ') });} );</script>' . "\n\n"; | |
| 224 | 228 | } |
| 225 | 229 | } |