| @@ -61,8 +61,16 @@ | ||
| 61 | 61 | $version = $script_asset['version']; |
| 62 | 62 | } |
| 63 | 63 | } |
| 64 | 64 | |
| 65 | + /* | |
| 66 | + * Register the `react-jsx-runtime` polyfill, if it is not already registered. | |
| 67 | + * This is needed as a polyfill for WP < 6.6, and can be removed once WP 6.6 is the minimum requirement for TablePress. | |
| 68 | + */ | |
| 69 | + if ( ! wp_script_is( 'react-jsx-runtime', 'registered' ) ) { | |
| 70 | + wp_register_script( 'react-jsx-runtime', plugins_url( 'admin/js/react-jsx-runtime.min.js', TABLEPRESS__FILE__ ), array( 'react' ), TablePress::version, true ); | |
| 71 | + } | |
| 72 | + | |
| 65 | 73 | /** |
| 66 | 74 | * Filters the dependencies of a TablePress script file. |
| 67 | 75 | * |
| 68 | 76 | * @since 2.0.0 |
| @@ -80,9 +88,9 @@ | ||
| 80 | 88 | } |
| 81 | 89 | |
| 82 | 90 | if ( ! empty( $script_data ) ) { |
| 83 | 91 | foreach ( $script_data as $var_name => $var_data ) { |
| 84 | - $var_data = wp_json_encode( $var_data, JSON_FORCE_OBJECT ); | |
| 92 | + $var_data = wp_json_encode( $var_data, JSON_FORCE_OBJECT | JSON_HEX_TAG | JSON_UNESCAPED_SLASHES ); | |
| 85 | 93 | wp_add_inline_script( "tablepress-{$name}", "const tablepress_{$var_name} = {$var_data};", 'before' ); |
| 86 | 94 | } |
| 87 | 95 | } |
| 88 | 96 | } |
| @@ -108,9 +116,9 @@ | ||
| 108 | 116 | public function _admin_footer_text( /* string */ $content ): string { |
| 109 | 117 | // Don't use a type hint in the method declaration as many WordPress plugins use the `admin_footer_text` filter in the wrong way. |
| 110 | 118 | |
| 111 | 119 | // Protect against other plugins not returning a string in their filter callbacks. |
| 112 | - if ( ! is_string( $content ) ) { | |
| 120 | + if ( ! is_string( $content ) ) { // @phpstan-ignore function.alreadyNarrowedType (The `is_string()` check is needed as the input is coming from a filter hook.) | |
| 113 | 121 | $content = ''; |
| 114 | 122 | } |
| 115 | 123 | |
| 116 | 124 | $content .= ' • ' . sprintf( __( 'Thank you for using <a href="%s">TablePress</a>.', 'tablepress' ), 'https://tablepress.org/' ); |
| @@ -140,9 +148,9 @@ | ||
| 140 | 148 | */ |
| 141 | 149 | ?> |
| 142 | 150 | <script> |
| 143 | 151 | ( function( $ ) { |
| 144 | - let options = <?php echo wp_json_encode( $args, TABLEPRESS_JSON_OPTIONS ); ?>; | |
| 152 | + let options = <?php echo wp_json_encode( $args, JSON_HEX_TAG | JSON_UNESCAPED_SLASHES ); ?>; | |
| 145 | 153 | |
| 146 | 154 | if ( ! options ) { |
| 147 | 155 | return; |
| 148 | 156 | } |
| @@ -177,15 +185,15 @@ | ||
| 177 | 185 | * @param mixed $data Variable to convert to JSON. |
| 178 | 186 | * @return string Safe JSON representation of a variable for printing inside of JavaScript code. |
| 179 | 187 | */ |
| 180 | 188 | public function convert_to_json_parse_output( /* string|array|bool|int|float|null */ $data ): string { |
| 181 | - $json = wp_json_encode( $data, TABLEPRESS_JSON_OPTIONS ); | |
| 189 | + $json = wp_json_encode( $data, JSON_HEX_TAG | JSON_UNESCAPED_SLASHES ); | |
| 182 | 190 | if ( false === $json ) { |
| 183 | 191 | // JSON encoding failed, return an error object. Use a prefixed "_error" key to avoid conflicts with intentionally added "error" keys. |
| 184 | 192 | $json = '{ "_error": "The data could not be encoded to JSON!" }'; |
| 185 | 193 | } |
| 186 | - // Print them inside a `JSON.parse()` call in JS for speed gains, with necessary escaping of `</script>`, `'`, and `\`. | |
| 187 | - $json = str_replace( array( '</script>', '\\', "'" ), array( '<\/script>', '\\\\', "\'" ), $json ); | |
| 194 | + // Print the JSON data inside a `JSON.parse()` call in JS for speed gains, with necessary escaping of `\` and `'`. | |
| 195 | + $json = str_replace( array( '\\', "'" ), array( '\\\\', "\'" ), $json ); | |
| 188 | 196 | return "JSON.parse( '{$json}' )"; |
| 189 | 197 | } |
| 190 | 198 | |
| 191 | 199 | } // class TablePress_Admin_Page |