| @@ -87,9 +87,9 @@ | ||
| 87 | 87 | $error_details = ''; |
| 88 | 88 | do { // To be able to "break;" (allows for better readable code). |
| 89 | 89 | // Load table, without table data, but with options and visibility settings. |
| 90 | 90 | $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())? | |
| 91 | + if ( is_wp_error( $existing_table ) ) { | |
| 92 | 92 | $error = new WP_Error( 'ajax_save_table_load', '', $edit_table['id'] ); |
| 93 | 93 | $error->merge_from( $existing_table ); |
| 94 | 94 | $error_details = TablePress::get_wp_error_string( $error ); |
| 95 | 95 | break; |
| @@ -160,10 +160,12 @@ | ||
| 160 | 160 | } else { |
| 161 | 161 | $message = 'success_save_error_id_change'; |
| 162 | 162 | $error_details = 'table_id_could_not_be_changed: capability_check_failed'; |
| 163 | 163 | } |
| 164 | - } while ( false ); // Do-while-loop through this exactly once, to be able to "break;" early. // @phpstan-ignore-line . | |
| 165 | 164 | |
| 165 | + // @phpstan-ignore doWhile.alwaysFalse | |
| 166 | + } while ( false ); // Do-while-loop through this exactly once, to be able to "break;" early. | |
| 167 | + | |
| 166 | 168 | // Generate the response. |
| 167 | 169 | |
| 168 | 170 | // Common data for all responses. |
| 169 | 171 | $response = array( |
| @@ -170,15 +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['new_copy_nonce'] = wp_create_nonce( TablePress::nonce( 'copy_table', $table['id'] ) ); // @phpstan-ignore-line | |
| 178 | - $response['new_delete_nonce'] = wp_create_nonce( TablePress::nonce( 'delete_table', $table['id'] ) ); // @phpstan-ignore-line | |
| 179 | - $response['last_modified'] = TablePress::format_datetime( $table['last_modified'] ); // @phpstan-ignore-line | |
| 180 | - $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 | |
| 181 | 184 | } |
| 182 | 185 | if ( ! empty( $error_details ) ) { |
| 183 | 186 | $response['error_details'] = esc_html( $error_details ); |
| 184 | 187 | } |
| @@ -216,9 +219,9 @@ | ||
| 216 | 219 | $success = false; |
| 217 | 220 | do { // To be able to "break;" (allows for better readable code). |
| 218 | 221 | // Load table, without table data, but with options and visibility settings. |
| 219 | 222 | $existing_table = TablePress::$model_table->load( $preview_table['id'], false, true ); |
| 220 | - 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 ) ) { | |
| 221 | 224 | break; |
| 222 | 225 | } |
| 223 | 226 | |
| 224 | 227 | // Check and convert all data that was transmitted as valid JSON. |
| @@ -256,10 +259,12 @@ | ||
| 256 | 259 | } |
| 257 | 260 | |
| 258 | 261 | // At this point, the table data is valid and sanitized and can be rendered. |
| 259 | 262 | $success = true; |
| 260 | - } while ( false ); // Do-while-loop through this exactly once, to be able to "break;" early. // @phpstan-ignore-line . | |
| 261 | 263 | |
| 264 | + // @phpstan-ignore doWhile.alwaysFalse | |
| 265 | + } while ( false ); // Do-while-loop through this exactly once, to be able to "break;" early. | |
| 266 | + | |
| 262 | 267 | if ( $success ) { |
| 263 | 268 | // Create a render class instance. |
| 264 | 269 | $_render = TablePress::load_class( 'TablePress_Render', 'class-render.php', 'classes' ); |
| 265 | 270 | // Merge desired options with default render options (see TablePress_Controller_Frontend::shortcode_table()). |
| @@ -265,13 +270,15 @@ | ||
| 265 | 270 | // Merge desired options with default render options (see TablePress_Controller_Frontend::shortcode_table()). |
| 266 | 271 | $default_render_options = $_render->get_default_render_options(); |
| 267 | 272 | /** This filter is documented in controllers/controller-frontend.php */ |
| 268 | 273 | $default_render_options = apply_filters( 'tablepress_shortcode_table_default_shortcode_atts', $default_render_options ); |
| 269 | - $render_options = shortcode_atts( $default_render_options, $table['options'] ); // @phpstan-ignore-line | |
| 274 | + // For the phpstan ignores in the next lines: If this is reached, $table is guaranteed to exist and is a valid array. | |
| 275 | + $render_options = shortcode_atts( $default_render_options, $table['options'] ); // @phpstan-ignore offsetAccess.nonOffsetAccessible, variable.undefined | |
| 270 | 276 | /** This filter is documented in controllers/controller-frontend.php */ |
| 271 | 277 | $render_options = apply_filters( 'tablepress_shortcode_table_shortcode_atts', $render_options ); |
| 272 | - $render_options['html_id'] = "tablepress-{$table['id']}"; // @phpstan-ignore-line | |
| 273 | - $_render->set_input( $table, $render_options ); // @phpstan-ignore-line | |
| 278 | + $render_options['html_id'] = "tablepress-{$table['id']}"; // @phpstan-ignore offsetAccess.nonOffsetAccessible, variable.undefined | |
| 279 | + $render_options['block_preview'] = true; | |
| 280 | + $_render->set_input( $table, $render_options ); // @phpstan-ignore variable.undefined | |
| 274 | 281 | $head_html = $_render->get_preview_css(); |
| 275 | 282 | $custom_css = TablePress::$model_options->get( 'custom_css' ); |
| 276 | 283 | $use_custom_css = ( TablePress::$model_options->get( 'use_custom_css' ) && '' !== $custom_css ); |
| 277 | 284 | if ( $use_custom_css ) { |
| @@ -280,9 +287,9 @@ | ||
| 280 | 287 | |
| 281 | 288 | $body_html = '<div id="tablepress-page"><p>' |
| 282 | 289 | . __( 'This is a preview of your table.', 'tablepress' ) . ' ' |
| 283 | 290 | . __( 'Because of CSS styling in your theme, the table might look different on your page!', 'tablepress' ) . ' ' |
| 284 | - . __( 'The Table Features for Site Visitors, like sorting, filtering, and pagination, are also not available in this preview!', 'tablepress' ) . '<br />'; | |
| 291 | + . __( 'The Table Features for Site Visitors, like sorting, filtering, and pagination, are also not available in this preview!', 'tablepress' ) . '<br>'; | |
| 285 | 292 | // Show the instructions string depending on whether the Block Editor is used on the site or not. |
| 286 | 293 | if ( TablePress::site_uses_block_editor() ) { |
| 287 | 294 | $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' ) ); |
| 288 | 295 | } else { |
| @@ -288,9 +295,9 @@ | ||
| 288 | 295 | } else { |
| 289 | 296 | $body_html .= __( 'To insert a table into a post or page, paste its Shortcode at the desired place in the editor.', 'tablepress' ) . ' ' |
| 290 | 297 | . __( 'Each table has a unique ID that needs to be adjusted in that Shortcode.', 'tablepress' ); |
| 291 | 298 | } |
| 292 | - $body_html .= '</p>' . $_render->get_output() . '</div>'; | |
| 299 | + $body_html .= '</p>' . $_render->get_output( 'html' ) . '</div>'; | |
| 293 | 300 | } else { |
| 294 | 301 | $head_html = ''; |
| 295 | 302 | $body_html = __( 'The preview could not be loaded.', 'tablepress' ); |
| 296 | 303 | } |