PluginProbe
TablePress – Tables in WordPress made easy / 3.2
TablePress – Tables in WordPress made easy v3.2
3.3.4 3.3.3 3.3.2 3.3.1 trunk 1.12 1.14 1.9.2 2.0.4 2.1.7 2.1.8 2.2 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.3 2.3.1 2.3.2 2.4 2.4.1 2.4.2 2.4.3 2.4.4 All 44 releases
← All changes | controllers/controller-frontend.php +30 -30 trunk3.2 View file →
@@ -90,11 +90,8 @@
90 90 if ( $this->use_legacy_css_loading ) {
91 91 add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_css' ) );
92 92 }
93 93
94 - // Register a placeholder script handle so that plugins can properly declare it as a dependency, even before the actual script is enqueued in `enqueue_datatables_files()`.
95 - wp_register_script( 'tablepress-datatables', '', array(), TablePress::version, array( 'in_footer' => true ) );
96 -
97 94 add_action( 'wp_print_footer_scripts', array( $this, 'add_datatables_calls' ), 9 ); // Priority 9 so that this runs before `_wp_footer_scripts()`.
98 95
99 96 // Register TablePress Shortcodes. Priority 20 is kept for backwards-compatibility purposes.
100 97 add_action( 'init', array( $this, 'init_shortcodes' ), 20 );
@@ -118,12 +115,15 @@
118 115
119 116 /**
120 117 * Register the tablepress/table block and its dependencies.
121 118 */
122 - wp_register_block_metadata_collection(
123 - TABLEPRESS_ABSPATH . 'blocks',
124 - TABLEPRESS_ABSPATH . 'blocks/blocks-manifest.php',
125 - );
119 + if ( function_exists( 'wp_register_block_metadata_collection' ) ) {
120 + // wp_register_block_metadata_collection() is only available since WP 6.7.
121 + wp_register_block_metadata_collection(
122 + TABLEPRESS_ABSPATH . 'blocks',
123 + TABLEPRESS_ABSPATH . 'blocks/blocks-manifest.php',
124 + );
125 + }
126 126 register_block_type_from_metadata(
127 127 TABLEPRESS_ABSPATH . 'blocks/table/block.json',
128 128 array(
129 129 'render_callback' => array( $this, 'table_block_render_callback' ),
@@ -323,11 +323,9 @@
323 323 * @param string[] $dependencies The dependencies for the DataTables JS library.
324 324 */
325 325 $dependencies = apply_filters( 'tablepress_datatables_js_dependencies', $dependencies );
326 326
327 - // De-register the placeholder script handle and enqueue the actual script, so that the dependencies are correct.
328 - wp_deregister_script( 'tablepress-datatables' );
329 - wp_enqueue_script( 'tablepress-datatables', $js_url, $dependencies, TablePress::version, array( 'in_footer' => true ) );
327 + wp_enqueue_script( 'tablepress-datatables', $js_url, $dependencies, TablePress::version, true );
330 328 }
331 329
332 330 /**
333 331 * Adds the JavaScript code for the invocation of the DataTables JS library.
@@ -557,21 +555,22 @@
557 555 } // foreach table instance
558 556 } // foreach table ID
559 557
560 558 // DataTables language/translation handling.
561 - $datatables_language_command = wp_json_encode( $datatables_language, JSON_HEX_TAG | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE | JSON_FORCE_OBJECT );
562 - $datatables_language_command = "var DT_language={$datatables_language_command};\n";
559 + if ( ! empty( $datatables_language ) ) {
560 + $datatables_language_command = wp_json_encode( $datatables_language, JSON_HEX_TAG | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE | JSON_FORCE_OBJECT );
561 + $datatables_language_command = "var DT_language={$datatables_language_command};\n";
562 + } else {
563 + $datatables_language_command = '';
564 + }
563 565
564 566 // DataTables datetime format string handling.
565 567 if ( ! empty( $this->datatables_datetime_formats ) ) {
566 - // Create a command like `DataTable.datetime("MM/DD/YYYY");DataTable.datetime("DD.MM.YYYY");`.
568 + // Create a command like `DataTable.datetime('MM/DD/YYYY');DataTable.datetime('DD.MM.YYYY');`.
567 569 $datatables_datetime_command = implode(
568 570 '',
569 571 array_map(
570 - static function ( string $datetime_format ): string {
571 - $datetime_format = wp_json_encode( $datetime_format, JSON_HEX_TAG | JSON_UNESCAPED_SLASHES );
572 - return "DataTable.datetime({$datetime_format});";
573 - },
572 + static fn( string $datetime_format ): string => "DataTable.datetime('{$datetime_format}');",
574 573 $this->datatables_datetime_formats,
575 574 )
576 575 ) . "\n";
577 576 } else {
@@ -629,12 +628,14 @@
629 628 * Handles the Shortcode [table id=<ID> /].
630 629 *
631 630 * @since 1.0.0
632 631 *
633 - * @param array<string, mixed> $shortcode_atts List of attributes that where included in the Shortcode.
632 + * @param array<string, mixed>|string $shortcode_atts List of attributes that where included in the Shortcode. An empty string for empty Shortcodes like [table] or [table /].
634 633 * @return string Resulting HTML code for the table with the ID <ID>.
635 634 */
636 - public function shortcode_table( array $shortcode_atts ): string {
635 + public function shortcode_table( /* array|string */ $shortcode_atts ): string {
636 + $shortcode_atts = (array) $shortcode_atts;
637 +
637 638 $this->maybe_enqueue_css();
638 639
639 640 $_render = TablePress::load_class( 'TablePress_Render', 'class-render.php', 'classes' );
640 641
@@ -899,9 +900,9 @@
899 900 }
900 901
901 902 // Maybe print a list of used render options.
902 903 if ( $render_options['shortcode_debug'] && is_user_logged_in() ) {
903 - $output .= '<pre>' . esc_html( wp_json_encode( $render_options, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES ) ) . '</pre>'; // @phpstan-ignore argument.type
904 + $output .= '<pre>' . var_export( $render_options, true ) . '</pre>'; // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_var_export
904 905 }
905 906
906 907 return $output;
907 908 }
@@ -910,12 +911,14 @@
910 911 * Handles the Shortcode [table-info id=<ID> field=<name> /].
911 912 *
912 913 * @since 1.0.0
913 914 *
914 - * @param array<string, mixed> $shortcode_atts List of attributes that where included in the Shortcode.
915 + * @param array<string, mixed>|string $shortcode_atts List of attributes that where included in the Shortcode. An empty string for empty Shortcodes like [table] or [table /].
915 916 * @return string Text that replaces the Shortcode (error message or asked-for information).
916 917 */
917 - public function shortcode_table_info( array $shortcode_atts ): string {
918 + public function shortcode_table_info( /* array|string */ $shortcode_atts ): string {
919 + $shortcode_atts = (array) $shortcode_atts;
920 +
918 921 // Parse Shortcode attributes, only allow those that are specified.
919 922 $default_shortcode_atts = array(
920 923 'id' => '',
921 924 'field' => '',
@@ -977,15 +980,8 @@
977 980 switch ( $field ) {
978 981 case 'name':
979 982 case 'description':
980 983 $output = $table[ $field ];
981 - // Replace any & with &amp; that is not already an encoded entity (from function htmlentities2 in WP 2.8).
982 - // A complete htmlentities2() or htmlspecialchars() would encode <HTML> tags, which we don't want.
983 - $output = (string) preg_replace( '/&(?![A-Za-z]{0,4}\w{2,3};|#[0-9]{2,4};)/', '&amp;', $output );
984 - /** This filter is documented in classes/class-render.php */
985 - if ( apply_filters( 'tablepress_apply_nl2br', true, $table_id ) ) {
986 - $output = nl2br( $output );
987 - }
988 984 break;
989 985 case 'last_modified':
990 986 switch ( $format ) {
991 987 case 'raw':
@@ -1182,9 +1178,13 @@
1182 1178 if ( '' === $block_attributes['id'] ) {
1183 1179 return '';
1184 1180 }
1185 1181
1186 - $render_attributes = shortcode_parse_atts( $block_attributes['parameters'] );
1182 + if ( '' !== trim( $block_attributes['parameters'] ) ) {
1183 + $render_attributes = shortcode_parse_atts( $block_attributes['parameters'] );
1184 + } else {
1185 + $render_attributes = array();
1186 + }
1187 1187 $render_attributes['id'] = $block_attributes['id'];
1188 1188
1189 1189 return $this->shortcode_table( $render_attributes );
1190 1190 }