PluginProbe
TablePress – Tables in WordPress made easy / 3.4
TablePress – Tables in WordPress made easy v3.4
3.4 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 All 45 releases
← All changes | controllers/controller-admin_ajax.php +26 -15 2.2.4 → 3.4 View file →
@@ -7,8 +7,10 @@
7 7 * @author Tobias Bäthge
8 8 * @since 1.0.0
9 9 */
10 10
11 +declare(strict_types=1);
12 +
11 13 // Prohibit direct script loading.
12 14 defined( 'ABSPATH' ) || die( 'No direct script access allowed!' );
13 15
14 16 /**
@@ -87,9 +89,9 @@
87 89 $error_details = '';
88 90 do { // To be able to "break;" (allows for better readable code).
89 91 // Load table, without table data, but with options and visibility settings.
90 92 $existing_table = TablePress::$model_table->load( $edit_table['id'], false, true );
91 - if ( is_wp_error( $existing_table ) ) { // @todo Maybe somehow load a new table here? (TablePress::$model_table->get_table_template())?
93 + if ( is_wp_error( $existing_table ) ) {
92 94 $error = new WP_Error( 'ajax_save_table_load', '', $edit_table['id'] );
93 95 $error->merge_from( $existing_table );
94 96 $error_details = TablePress::get_wp_error_string( $error );
95 97 break;
@@ -160,9 +162,9 @@
160 162 } else {
161 163 $message = 'success_save_error_id_change';
162 164 $error_details = 'table_id_could_not_be_changed: capability_check_failed';
163 165 }
164 - } while ( false ); // Do-while-loop through this exactly once, to be able to "break;" early. // @phpstan-ignore-line .
166 + } while ( false ); // Do-while-loop through this exactly once, to be able to "break;" early.
165 167
166 168 // Generate the response.
167 169
168 170 // Common data for all responses.
@@ -170,13 +172,16 @@
170 172 'success' => $success,
171 173 'message' => $message,
172 174 );
173 175 if ( $success ) {
174 - $response['table_id'] = $table['id']; // @phpstan-ignore-line
175 - $response['new_edit_nonce'] = wp_create_nonce( TablePress::nonce( 'edit', $table['id'] ) ); // @phpstan-ignore-line
176 - $response['new_preview_nonce'] = wp_create_nonce( TablePress::nonce( 'preview_table', $table['id'] ) ); // @phpstan-ignore-line
177 - $response['last_modified'] = TablePress::format_datetime( $table['last_modified'] ); // @phpstan-ignore-line
178 - $response['last_editor'] = TablePress::get_user_display_name( $table['options']['last_editor'] ); // @phpstan-ignore-line
176 + // For the phpstan ignores in the next lines: If this is reached, $table is guaranteed to exist and is a valid array.
177 + $response['table_id'] = $table['id']; // @phpstan-ignore offsetAccess.nonOffsetAccessible, variable.undefined
178 + $response['new_edit_nonce'] = wp_create_nonce( TablePress::nonce( 'edit', $table['id'] ) ); // @phpstan-ignore offsetAccess.nonOffsetAccessible, variable.undefined
179 + $response['new_preview_nonce'] = wp_create_nonce( TablePress::nonce( 'preview_table', $table['id'] ) ); // @phpstan-ignore offsetAccess.nonOffsetAccessible, variable.undefined
180 + $response['new_copy_nonce'] = wp_create_nonce( TablePress::nonce( 'copy_table', $table['id'] ) ); // @phpstan-ignore offsetAccess.nonOffsetAccessible, variable.undefined
181 + $response['new_delete_nonce'] = wp_create_nonce( TablePress::nonce( 'delete_table', $table['id'] ) ); // @phpstan-ignore offsetAccess.nonOffsetAccessible, variable.undefined
182 + $response['last_modified'] = TablePress::format_datetime( $table['last_modified'] ); // @phpstan-ignore offsetAccess.nonOffsetAccessible, variable.undefined
183 + $response['last_editor'] = TablePress::get_user_display_name( $table['options']['last_editor'] ); // @phpstan-ignore offsetAccess.nonOffsetAccessible, variable.undefined
179 184 }
180 185 if ( ! empty( $error_details ) ) {
181 186 $response['error_details'] = esc_html( $error_details );
182 187 }
@@ -214,9 +219,9 @@
214 219 $success = false;
215 220 do { // To be able to "break;" (allows for better readable code).
216 221 // Load table, without table data, but with options and visibility settings.
217 222 $existing_table = TablePress::$model_table->load( $preview_table['id'], false, true );
218 - if ( is_wp_error( $existing_table ) ) { // @todo Maybe somehow load a new table here? (TablePress::$model_table->get_table_template())?
223 + if ( is_wp_error( $existing_table ) ) {
219 224 break;
220 225 }
221 226
222 227 // Check and convert all data that was transmitted as valid JSON.
@@ -254,9 +259,9 @@
254 259 }
255 260
256 261 // At this point, the table data is valid and sanitized and can be rendered.
257 262 $success = true;
258 - } while ( false ); // Do-while-loop through this exactly once, to be able to "break;" early. // @phpstan-ignore-line .
263 + } while ( false ); // Do-while-loop through this exactly once, to be able to "break;" early.
259 264
260 265 if ( $success ) {
261 266 // Create a render class instance.
262 267 $_render = TablePress::load_class( 'TablePress_Render', 'class-render.php', 'classes' );
@@ -263,13 +268,15 @@
263 268 // Merge desired options with default render options (see TablePress_Controller_Frontend::shortcode_table()).
264 269 $default_render_options = $_render->get_default_render_options();
265 270 /** This filter is documented in controllers/controller-frontend.php */
266 271 $default_render_options = apply_filters( 'tablepress_shortcode_table_default_shortcode_atts', $default_render_options );
267 - $render_options = shortcode_atts( $default_render_options, $table['options'] ); // @phpstan-ignore-line
272 + // For the phpstan ignores in the next lines: If this is reached, $table is guaranteed to exist and is a valid array.
273 + $render_options = shortcode_atts( $default_render_options, $table['options'] ); // @phpstan-ignore offsetAccess.nonOffsetAccessible, variable.undefined
268 274 /** This filter is documented in controllers/controller-frontend.php */
269 275 $render_options = apply_filters( 'tablepress_shortcode_table_shortcode_atts', $render_options );
270 - $render_options['html_id'] = "tablepress-{$table['id']}"; // @phpstan-ignore-line
271 - $_render->set_input( $table, $render_options ); // @phpstan-ignore-line
276 + $render_options['html_id'] = "tablepress-{$table['id']}"; // @phpstan-ignore offsetAccess.nonOffsetAccessible, variable.undefined
277 + $render_options['block_preview'] = true;
278 + $_render->set_input( $table, $render_options ); // @phpstan-ignore variable.undefined
272 279 $head_html = $_render->get_preview_css();
273 280 $custom_css = TablePress::$model_options->get( 'custom_css' );
274 281 $use_custom_css = ( TablePress::$model_options->get( 'use_custom_css' ) && '' !== $custom_css );
275 282 if ( $use_custom_css ) {
@@ -278,17 +285,21 @@
278 285
279 286 $body_html = '<div id="tablepress-page"><p>'
280 287 . __( 'This is a preview of your table.', 'tablepress' ) . ' '
281 288 . __( 'Because of CSS styling in your theme, the table might look different on your page!', 'tablepress' ) . ' '
282 - . __( 'The Table Features for Site Visitors, like sorting, filtering, and pagination, are also not available in this preview!', 'tablepress' ) . '<br />';
289 + . __( 'The Table Features for Site Visitors, like sorting, filtering, and pagination, are also not available in this preview!', 'tablepress' ) . '<br>';
283 290 // Show the instructions string depending on whether the Block Editor is used on the site or not.
284 - if ( TablePress::site_uses_block_editor() ) {
291 + if ( 'block' === TablePress::site_used_editor() ) {
292 + /* translators: %1$s: Block name */
285 293 $body_html .= sprintf( __( 'To insert a table into a post or page, add a “%1$s” block in the block editor and select the desired table.', 'tablepress' ), __( 'TablePress table', 'tablepress' ) );
294 + } elseif ( 'elementor' === TablePress::site_used_editor() ) {
295 + /* translators: %1$s: Widget name */
296 + $body_html .= sprintf( __( 'To insert a table into a post or page, add a “%1$s” widget in the Elementor editor and select the desired table.', 'tablepress' ), __( 'TablePress table', 'tablepress' ) );
286 297 } else {
287 298 $body_html .= __( 'To insert a table into a post or page, paste its Shortcode at the desired place in the editor.', 'tablepress' ) . ' '
288 299 . __( 'Each table has a unique ID that needs to be adjusted in that Shortcode.', 'tablepress' );
289 300 }
290 - $body_html .= '</p>' . $_render->get_output() . '</div>';
301 + $body_html .= '</p><div class="preview">' . $_render->get_output( 'html' ) . '</div></div>';
291 302 } else {
292 303 $head_html = '';
293 304 $body_html = __( 'The preview could not be loaded.', 'tablepress' );
294 305 }