| @@ -25,27 +25,26 @@ | ||
| 25 | 25 | * Page hooks (i.e. names) WordPress uses for the TablePress admin screens, |
| 26 | 26 | * populated in add_admin_menu_entry(). |
| 27 | 27 | * |
| 28 | 28 | * @since 1.0.0 |
| 29 | - * @var array | |
| 29 | + * @var string[] | |
| 30 | 30 | */ |
| 31 | - protected $page_hooks = array(); | |
| 31 | + protected array $page_hooks = array(); | |
| 32 | 32 | |
| 33 | 33 | /** |
| 34 | 34 | * Actions that have a view and admin menu or nav tab menu entry. |
| 35 | 35 | * |
| 36 | 36 | * @since 1.0.0 |
| 37 | - * @var array | |
| 37 | + * @var array<string, array<string, bool|string>> | |
| 38 | 38 | */ |
| 39 | - protected $view_actions = array(); | |
| 39 | + protected array $view_actions = array(); | |
| 40 | 40 | |
| 41 | 41 | /** |
| 42 | 42 | * Instance of the TablePress Admin View that is rendered. |
| 43 | 43 | * |
| 44 | 44 | * @since 1.0.0 |
| 45 | - * @var TablePress_View | |
| 46 | 45 | */ |
| 47 | - protected $view; | |
| 46 | + protected \TablePress_View $view; | |
| 48 | 47 | |
| 49 | 48 | /** |
| 50 | 49 | * Initialize the Admin Controller, determine location the admin menu, set up actions. |
| 51 | 50 | * |
| @@ -59,9 +58,10 @@ | ||
| 59 | 58 | |
| 60 | 59 | add_action( 'admin_menu', array( $this, 'add_admin_menu_entry' ) ); |
| 61 | 60 | add_action( 'admin_init', array( $this, 'add_admin_actions' ) ); |
| 62 | 61 | |
| 63 | - add_action( 'enqueue_block_editor_assets', array( $this, 'add_block_editor_js' ) ); | |
| 62 | + add_action( 'enqueue_block_editor_assets', array( $this, 'enqueue_block_editor_assets' ) ); | |
| 63 | + add_action( 'enqueue_block_assets', array( $this, 'enqueue_block_assets' ) ); | |
| 64 | 64 | } |
| 65 | 65 | |
| 66 | 66 | /** |
| 67 | 67 | * Handler for changing the number of shown tables in the list of tables (via WP List Table class). |
| @@ -70,11 +70,11 @@ | ||
| 70 | 70 | * |
| 71 | 71 | * @param mixed $screen_option Current value of the filter (probably bool false). |
| 72 | 72 | * @param string $option Option in which the setting is stored. |
| 73 | 73 | * @param int $value Current value of the setting. |
| 74 | - * @return bool|int False to not save the changed setting, or the int value to be saved. | |
| 74 | + * @return int Changed value of the setting | |
| 75 | 75 | */ |
| 76 | - public function save_list_tables_screen_option( $screen_option, $option, $value ) { | |
| 76 | + public function save_list_tables_screen_option( /* mixed */ $screen_option, string $option, int $value ): int { | |
| 77 | 77 | return $value; |
| 78 | 78 | } |
| 79 | 79 | |
| 80 | 80 | /** |
| @@ -81,9 +81,9 @@ | ||
| 81 | 81 | * Add admin screens to the correct place in the admin menu. |
| 82 | 82 | * |
| 83 | 83 | * @since 1.0.0 |
| 84 | 84 | */ |
| 85 | - public function add_admin_menu_entry() { | |
| 85 | + public function add_admin_menu_entry(): void { | |
| 86 | 86 | // Callback for all menu entries. |
| 87 | 87 | $callback = array( $this, 'show_admin_page' ); |
| 88 | 88 | /** |
| 89 | 89 | * Filters the TablePress admin menu entry name. |
| @@ -96,23 +96,27 @@ | ||
| 96 | 96 | |
| 97 | 97 | $this->init_view_actions(); |
| 98 | 98 | $min_access_cap = $this->view_actions['list']['required_cap']; |
| 99 | 99 | |
| 100 | - if ( $this->is_top_level_page ) { | |
| 101 | - $icon_url = 'dashicons-list-view'; | |
| 102 | - switch ( $this->parent_page ) { | |
| 100 | + if ( TablePress::$controller->is_top_level_page ) { | |
| 101 | + $icon_url = 'data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyMCIgaGVpZ2h0PSIyMCIgdmlld0JveD0iLTMyIC0zMiA2NCA2NCIgZmlsbD0iI2ZmZiI+PHBhdGggZD0iTTAtMjUuODU0aC0yNS44NTR2NTEuNzA4aDUxLjcwOFYwSDIxdjIxaC00MnYtNDJIMFoiLz48cGF0aCBkPSJNLTE4LTE4aDEwdjEwaC0xMHpNLTE4LTVoMTBWNWgtMTB6TS01LTVINVY1SC01ek0tMTggOGgxMHYxMGgtMTB6TS01IDhINXYxMEgtNXpNOCA4aDEwdjEwSDh6TTUtMzFoNi4xOHY2LjE4SDV6TTE5LTI1aDYuMTh2Ni4xOEgxOXpNMC0xNWgzLjgydjMuODJIMHpNMTAtMjBoMy44MnYzLjgySDEwek0yNS0xMmgzLjgydjMuODJIMjV6TTgtMTNoMTB2MTBIOHoiLz48L3N2Zz4='; | |
| 102 | + switch ( TablePress::$controller->parent_page ) { | |
| 103 | 103 | case 'top': |
| 104 | 104 | $position = 3; // Position of Dashboard + 1. |
| 105 | 105 | break; |
| 106 | 106 | case 'bottom': |
| 107 | - $position = ( ++$GLOBALS['_wp_last_utility_menu'] ); | |
| 107 | + $position = isset( $GLOBALS['_wp_last_utility_menu'] ) ? ++$GLOBALS['_wp_last_utility_menu'] : 80; | |
| 108 | 108 | break; |
| 109 | 109 | case 'middle': |
| 110 | 110 | default: |
| 111 | - $position = ( ++$GLOBALS['_wp_last_object_menu'] ); | |
| 111 | + $position = isset( $GLOBALS['_wp_last_object_menu'] ) ? ++$GLOBALS['_wp_last_object_menu'] : 25; | |
| 112 | 112 | break; |
| 113 | 113 | } |
| 114 | - add_menu_page( 'TablePress', $admin_menu_entry_name, $min_access_cap, 'tablepress', $callback, $icon_url, $position ); | |
| 114 | + // Prevent overwriting existing menu entries. | |
| 115 | + while ( isset( $GLOBALS['menu'][ $position ] ) ) { | |
| 116 | + ++$position; | |
| 117 | + } | |
| 118 | + add_menu_page( 'TablePress', $admin_menu_entry_name, $min_access_cap, 'tablepress', $callback, $icon_url, $position ); // @phpstan-ignore argument.type | |
| 115 | 119 | foreach ( $this->view_actions as $action => $entry ) { |
| 116 | 120 | if ( ! $entry['show_entry'] ) { |
| 117 | 121 | continue; |
| 118 | 122 | } |
| @@ -119,12 +123,20 @@ | ||
| 119 | 123 | $slug = 'tablepress'; |
| 120 | 124 | if ( 'list' !== $action ) { |
| 121 | 125 | $slug .= '_' . $action; |
| 122 | 126 | } |
| 123 | - $this->page_hooks[] = add_submenu_page( 'tablepress', sprintf( __( '%1$s ‹ %2$s', 'tablepress' ), $entry['page_title'], 'TablePress' ), $entry['admin_menu_title'], $entry['required_cap'], $slug, $callback ); | |
| 127 | + // @phpstan-ignore argument.type, argument.type | |
| 128 | + $page_hook = add_submenu_page( 'tablepress', sprintf( __( '%1$s ‹ %2$s', 'tablepress' ), $entry['page_title'], 'TablePress' ), $entry['admin_menu_title'], $entry['required_cap'], $slug, $callback ); | |
| 129 | + if ( false !== $page_hook ) { | |
| 130 | + $this->page_hooks[] = $page_hook; | |
| 131 | + } | |
| 124 | 132 | } |
| 125 | 133 | } else { |
| 126 | - $this->page_hooks[] = add_submenu_page( $this->parent_page, 'TablePress', $admin_menu_entry_name, $min_access_cap, 'tablepress', $callback ); | |
| 134 | + // @phpstan-ignore argument.type | |
| 135 | + $page_hook = add_submenu_page( TablePress::$controller->parent_page, 'TablePress', $admin_menu_entry_name, $min_access_cap, 'tablepress', $callback ); | |
| 136 | + if ( false !== $page_hook ) { | |
| 137 | + $this->page_hooks[] = $page_hook; | |
| 138 | + } | |
| 127 | 139 | } |
| 128 | 140 | } |
| 129 | 141 | |
| 130 | 142 | /** |
| @@ -131,9 +143,9 @@ | ||
| 131 | 143 | * Set up handlers for user actions in the backend that exceed plain viewing. |
| 132 | 144 | * |
| 133 | 145 | * @since 1.0.0 |
| 134 | 146 | */ |
| 135 | - public function add_admin_actions() { | |
| 147 | + public function add_admin_actions(): void { | |
| 136 | 148 | // Register the callbacks for processing action requests. |
| 137 | 149 | $post_actions = array( 'list', 'add', 'options', 'export', 'import' ); |
| 138 | 150 | $get_actions = array( 'hide_message', 'delete_table', 'copy_table', 'preview_table', 'editor_button_thickbox', 'uninstall_tablepress' ); |
| 139 | 151 | foreach ( $post_actions as $action ) { |
| @@ -147,11 +159,20 @@ | ||
| 147 | 159 | foreach ( $this->page_hooks as $page_hook ) { |
| 148 | 160 | add_action( "load-{$page_hook}", array( $this, 'load_admin_page' ) ); |
| 149 | 161 | } |
| 150 | 162 | |
| 151 | - $pages_with_editor_button = array( 'post.php', 'post-new.php' ); | |
| 152 | - foreach ( $pages_with_editor_button as $editor_page ) { | |
| 153 | - add_action( "load-{$editor_page}", array( $this, 'add_editor_buttons' ) ); | |
| 163 | + /** | |
| 164 | + * Filters whether the legacy editor button should be loaded on the post editing screen. | |
| 165 | + * | |
| 166 | + * @since 2.1.0 | |
| 167 | + * | |
| 168 | + * @param bool $load_button Whether to load the legacy editor button. Default true. | |
| 169 | + */ | |
| 170 | + if ( apply_filters( 'tablepress_add_legacy_editor_button', true ) ) { | |
| 171 | + $pages_with_editor_button = array( 'post.php', 'post-new.php' ); | |
| 172 | + foreach ( $pages_with_editor_button as $editor_page ) { | |
| 173 | + add_action( "load-{$editor_page}", array( $this, 'add_editor_buttons' ) ); | |
| 174 | + } | |
| 154 | 175 | } |
| 155 | 176 | |
| 156 | 177 | if ( ! is_network_admin() && ! is_user_admin() ) { |
| 157 | 178 | add_action( 'admin_bar_menu', array( $this, 'add_wp_admin_bar_new_content_menu_entry' ), 71 ); |
| @@ -157,22 +178,25 @@ | ||
| 157 | 178 | add_action( 'admin_bar_menu', array( $this, 'add_wp_admin_bar_new_content_menu_entry' ), 71 ); |
| 158 | 179 | } |
| 159 | 180 | |
| 160 | 181 | add_action( 'load-plugins.php', array( $this, 'plugins_page' ) ); |
| 161 | - | |
| 162 | - // Add filters and actions for the integration into the WP WXR exporter and importer. | |
| 163 | - add_action( 'wp_import_insert_post', array( TablePress::$model_table, 'add_table_id_on_wp_import' ), 10, 4 ); | |
| 164 | - add_filter( 'wp_import_post_meta', array( TablePress::$model_table, 'prevent_table_id_post_meta_import_on_wp_import' ), 10, 3 ); | |
| 165 | - add_filter( 'wxr_export_skip_postmeta', array( TablePress::$model_table, 'add_table_id_to_wp_export' ), 10, 3 ); | |
| 166 | 182 | } |
| 167 | 183 | |
| 168 | 184 | /** |
| 169 | - * Loads additional JavaScript code for the TablePress table block. | |
| 185 | + * Loads additional JavaScript code for the TablePress table block (in the block editor context). | |
| 170 | 186 | * |
| 171 | - * @since 2.0.0 | |
| 187 | + * @since 2.2.0 | |
| 172 | 188 | */ |
| 173 | - public function add_block_editor_js() { | |
| 174 | - // Add table information for the Block Editor to the page. | |
| 189 | + public function enqueue_block_editor_assets(): void { | |
| 190 | + /* | |
| 191 | + * Register the `react-jsx-runtime` polyfill, if it is not already registered. | |
| 192 | + * This is needed as a polyfill for WP < 6.6, and can be removed once WP 6.6 is the minimum requirement for TablePress. | |
| 193 | + */ | |
| 194 | + if ( ! wp_script_is( 'react-jsx-runtime', 'registered' ) ) { | |
| 195 | + wp_register_script( 'react-jsx-runtime', plugins_url( 'admin/js/react-jsx-runtime.min.js', TABLEPRESS__FILE__ ), array( 'react' ), TablePress::version, true ); | |
| 196 | + } | |
| 197 | + | |
| 198 | + // Add table information for the block editor to the page. | |
| 175 | 199 | $handle = generate_block_asset_handle( 'tablepress/table', 'editorScript' ); |
| 176 | 200 | $data = $this->get_block_editor_data(); |
| 177 | 201 | wp_add_inline_script( $handle, $data, 'before' ); |
| 178 | 202 | } |
| @@ -177,8 +201,20 @@ | ||
| 177 | 201 | wp_add_inline_script( $handle, $data, 'before' ); |
| 178 | 202 | } |
| 179 | 203 | |
| 180 | 204 | /** |
| 205 | + * Loads additional CSS code for the TablePress table block (inside the block editor iframe). | |
| 206 | + * | |
| 207 | + * @since 2.2.0 | |
| 208 | + */ | |
| 209 | + public function enqueue_block_assets(): void { | |
| 210 | + // Load the TablePress default CSS and the user's "Custom CSS" in the block editor iframe. | |
| 211 | + if ( is_admin() ) { | |
| 212 | + TablePress::$controller->enqueue_css(); | |
| 213 | + } | |
| 214 | + } | |
| 215 | + | |
| 216 | + /** | |
| 181 | 217 | * Gets the inline data that is referenced by the Block Editor JavaScript code for the TablePress blocks. |
| 182 | 218 | * |
| 183 | 219 | * @since 2.0.0 |
| 184 | 220 | * |
| @@ -183,9 +219,9 @@ | ||
| 183 | 219 | * @since 2.0.0 |
| 184 | 220 | * |
| 185 | 221 | * @return string JavaScript code for the Block Editor. |
| 186 | 222 | */ |
| 187 | - protected function get_block_editor_data() { | |
| 223 | + protected function get_block_editor_data(): string { | |
| 188 | 224 | $tables = array(); |
| 189 | 225 | // Load all table IDs without priming the post meta cache, as table options/visibility are not needed. |
| 190 | 226 | $table_ids = TablePress::$model_table->load_all( false ); |
| 191 | 227 | foreach ( $table_ids as $table_id ) { |
| @@ -190,8 +226,14 @@ | ||
| 190 | 226 | $table_ids = TablePress::$model_table->load_all( false ); |
| 191 | 227 | foreach ( $table_ids as $table_id ) { |
| 192 | 228 | // Load table, without table data, options, and visibility settings. |
| 193 | 229 | $table = TablePress::$model_table->load( $table_id, false, false ); |
| 230 | + | |
| 231 | + // Skip tables that could not be loaded. | |
| 232 | + if ( is_wp_error( $table ) ) { | |
| 233 | + continue; | |
| 234 | + } | |
| 235 | + | |
| 194 | 236 | if ( '' === trim( $table['name'] ) ) { |
| 195 | 237 | $table['name'] = __( '(no name)', 'tablepress' ); |
| 196 | 238 | } |
| 197 | 239 | $tables[ $table_id ] = esc_html( $table['name'] ); |
| @@ -201,22 +243,30 @@ | ||
| 201 | 243 | * Filters the list of table IDs and names that is passed to the block editor, and is then used in the dropdown of the TablePress table block. |
| 202 | 244 | * |
| 203 | 245 | * @since 2.0.0 |
| 204 | 246 | * |
| 205 | - * @param array $tables List of table names, the table ID is the array key. | |
| 247 | + * @param array<string, string> $tables List of table names, the table ID is the array key. | |
| 206 | 248 | */ |
| 207 | 249 | $tables = apply_filters( 'tablepress_block_editor_tables_list', $tables ); |
| 208 | 250 | |
| 209 | - $tables = wp_json_encode( $tables, TABLEPRESS_JSON_OPTIONS ); | |
| 210 | - // Print them inside a `JSON.parse()` call in JS for speed gains, with necessary escaping of `</script>`, `'`, and `\`. | |
| 211 | - $tables = str_replace( array( '</script>', '\\', "'" ), array( '<\/script>', '\\\\', "\'" ), $tables ); | |
| 251 | + $tables = wp_json_encode( $tables, JSON_HEX_TAG | JSON_UNESCAPED_SLASHES ); | |
| 252 | + if ( false === $tables ) { | |
| 253 | + // JSON encoding failed, return an error object. Use a prefixed "_error" key to avoid conflicts with intentionally added "error" keys. | |
| 254 | + $tables = '{ "_error": "The data could not be encoded to JSON!" }'; | |
| 255 | + } | |
| 256 | + // Print the JSON data inside a `JSON.parse()` call in JS for speed gains, with necessary escaping of `\` and `'`. | |
| 257 | + $tables = str_replace( array( '\\', "'" ), array( '\\\\', "\'" ), $tables ); | |
| 212 | 258 | |
| 213 | 259 | $shortcode = esc_js( TablePress::$shortcode ); |
| 214 | 260 | |
| 215 | 261 | $template = TablePress::$model_table->get_table_template(); |
| 216 | - $template = wp_json_encode( $template['options'], TABLEPRESS_JSON_OPTIONS ); | |
| 217 | - // Print them inside a `JSON.parse()` call in JS for speed gains, with necessary escaping of `</script>`, `'`, and `\`. | |
| 218 | - $template = str_replace( array( '</script>', '\\', "'" ), array( '<\/script>', '\\\\', "\'" ), $template ); | |
| 262 | + $template = wp_json_encode( $template['options'], JSON_HEX_TAG | JSON_UNESCAPED_SLASHES ); | |
| 263 | + if ( false === $template ) { | |
| 264 | + // JSON encoding failed, return an error object. Use a prefixed "_error" key to avoid conflicts with intentionally added "error" keys. | |
| 265 | + $template = '{ "_error": "The data could not be encoded to JSON!" }'; | |
| 266 | + } | |
| 267 | + // Print the JSON data inside a `JSON.parse()` call in JS for speed gains, with necessary escaping of `\` and `'`. | |
| 268 | + $template = str_replace( array( '\\', "'" ), array( '\\\\', "\'" ), $template ); | |
| 219 | 269 | |
| 220 | 270 | /** |
| 221 | 271 | * Filters whether the table block preview should be loaded via a <ServerSideRender> in the block editor. |
| 222 | 272 | * |
| @@ -232,17 +282,17 @@ | ||
| 232 | 282 | $url = TablePress::url( array( 'action' => 'list' ) ); |
| 233 | 283 | } |
| 234 | 284 | |
| 235 | 285 | return <<<JS |
| 236 | -// Ensure the global `tp` object exists. | |
| 237 | -window.tp = window.tp || {}; | |
| 238 | -tp.url = '{$url}'; | |
| 239 | -tp.load_block_preview = {$load_block_preview}; | |
| 240 | -tp.table = {}; | |
| 241 | -tp.table.shortcode = '{$shortcode}'; | |
| 242 | -tp.table.template = JSON.parse( '{$template}' ); | |
| 243 | -tp.tables = JSON.parse( '{$tables}' ); | |
| 244 | -JS; | |
| 286 | + // Ensure the global `tp` object exists. | |
| 287 | + window.tp = window.tp || {}; | |
| 288 | + tp.url = '{$url}'; | |
| 289 | + tp.load_block_preview = {$load_block_preview}; | |
| 290 | + tp.table = {}; | |
| 291 | + tp.table.shortcode = '{$shortcode}'; | |
| 292 | + tp.table.template = JSON.parse( '{$template}' ); | |
| 293 | + tp.tables = JSON.parse( '{$tables}' ); | |
| 294 | + JS; | |
| 245 | 295 | } |
| 246 | 296 | |
| 247 | 297 | /** |
| 248 | 298 | * Register actions to add "Table" button to "HTML editor" and "Visual editor" toolbars. |
| @@ -248,9 +298,9 @@ | ||
| 248 | 298 | * Register actions to add "Table" button to "HTML editor" and "Visual editor" toolbars. |
| 249 | 299 | * |
| 250 | 300 | * @since 1.0.0 |
| 251 | 301 | */ |
| 252 | - public function add_editor_buttons() { | |
| 302 | + public function add_editor_buttons(): void { | |
| 253 | 303 | if ( ! current_user_can( 'tablepress_list_tables' ) ) { |
| 254 | 304 | return; |
| 255 | 305 | } |
| 256 | 306 | |
| @@ -270,9 +320,9 @@ | ||
| 270 | 320 | 'title' => __( 'Insert a TablePress table', 'tablepress' ), |
| 271 | 321 | 'thickbox_title' => __( 'Insert a TablePress table', 'tablepress' ), |
| 272 | 322 | 'thickbox_url' => TablePress::url( array( 'action' => 'editor_button_thickbox' ), true, 'admin-post.php' ), |
| 273 | 323 | ), |
| 274 | - ) | |
| 324 | + ), | |
| 275 | 325 | ); |
| 276 | 326 | |
| 277 | 327 | // TinyMCE integration. |
| 278 | 328 | if ( user_can_richedit() ) { |
| @@ -285,12 +335,12 @@ | ||
| 285 | 335 | * Adds the "Table" button to the TinyMCE toolbar. |
| 286 | 336 | * |
| 287 | 337 | * @since 1.0.0 |
| 288 | 338 | * |
| 289 | - * @param array $buttons Current set of buttons in the TinyMCE toolbar. | |
| 290 | - * @return array Extended set of buttons in the TinyMCE toolbar, including the "Table" button. | |
| 339 | + * @param string[] $buttons Current set of buttons in the TinyMCE toolbar. | |
| 340 | + * @return string[] Extended set of buttons in the TinyMCE toolbar, including the "Table" button. | |
| 291 | 341 | */ |
| 292 | - public function add_tinymce_button( array $buttons ) { | |
| 342 | + public function add_tinymce_button( array $buttons ): array { | |
| 293 | 343 | $buttons[] = 'tablepress_insert_table'; |
| 294 | 344 | return $buttons; |
| 295 | 345 | } |
| 296 | 346 | |
| @@ -298,12 +348,12 @@ | ||
| 298 | 348 | * Registers the "Table" button plugin for the TinyMCE editor. |
| 299 | 349 | * |
| 300 | 350 | * @since 1.0.0 |
| 301 | 351 | * |
| 302 | - * @param array $plugins Current set of registered TinyMCE plugins. | |
| 303 | - * @return array Extended set of registered TinyMCE plugins, including the "Table" button plugin. | |
| 352 | + * @param array<string, string> $plugins Current set of registered TinyMCE plugins. | |
| 353 | + * @return array<string, string> Extended set of registered TinyMCE plugins, including the "Table" button plugin. | |
| 304 | 354 | */ |
| 305 | - public function add_tinymce_plugin( array $plugins ) { | |
| 355 | + public function add_tinymce_plugin( array $plugins ): array { | |
| 306 | 356 | $plugins['tablepress_tinymce'] = plugins_url( 'admin/js/build/tinymce-button.js', TABLEPRESS__FILE__ ); |
| 307 | 357 | return $plugins; |
| 308 | 358 | } |
| 309 | 359 | |
| @@ -313,9 +363,9 @@ | ||
| 313 | 363 | * @since 1.0.0 |
| 314 | 364 | * |
| 315 | 365 | * @param WP_Admin_Bar $wp_admin_bar The current WP Admin Bar object. |
| 316 | 366 | */ |
| 317 | - public function add_wp_admin_bar_new_content_menu_entry( $wp_admin_bar ) { | |
| 367 | + public function add_wp_admin_bar_new_content_menu_entry( WP_Admin_Bar $wp_admin_bar ): void { | |
| 318 | 368 | if ( ! current_user_can( 'tablepress_add_tables' ) ) { |
| 319 | 369 | return; |
| 320 | 370 | } |
| 321 | 371 | |
| @@ -336,12 +386,24 @@ | ||
| 336 | 386 | * Handle actions for loading of Plugins page. |
| 337 | 387 | * |
| 338 | 388 | * @since 1.0.0 |
| 339 | 389 | */ |
| 340 | - public function plugins_page() { | |
| 390 | + public function plugins_page(): void { | |
| 341 | 391 | // Add additional links on Plugins page. |
| 342 | 392 | add_filter( 'plugin_action_links_' . TABLEPRESS_BASENAME, array( $this, 'add_plugin_action_links' ) ); |
| 343 | 393 | add_filter( 'plugin_row_meta', array( $this, 'add_plugin_row_meta' ), 10, 2 ); |
| 394 | + $incompatible_superseded_extensions = array( | |
| 395 | + 'tablepress-datatables-alphabetsearch/tablepress-datatables-alphabetsearch.php', | |
| 396 | + 'tablepress-datatables-column-filter-widgets/tablepress-datatables-column-filter-widgets.php', | |
| 397 | + 'tablepress-datatables-columnfilter/tablepress-datatables-columnfilter.php', | |
| 398 | + 'tablepress-datatables-fixedcolumns/tablepress-datatables-fixedcolumns.php', | |
| 399 | + 'tablepress-datatables-row-details/tablepress-datatables-row-details.php', | |
| 400 | + 'tablepress-datatables-rowgroup/tablepress-datatables-rowgroup.php', | |
| 401 | + 'tablepress-responsive-tables/tablepress-responsive-tables.php', | |
| 402 | + ); | |
| 403 | + foreach ( $incompatible_superseded_extensions as $plugin_file ) { | |
| 404 | + add_action( "after_plugin_row_{$plugin_file}", array( $this, 'add_superseded_extension_meta_row' ), 10, 3 ); | |
| 405 | + } | |
| 344 | 406 | } |
| 345 | 407 | |
| 346 | 408 | /** |
| 347 | 409 | * Add links to the TablePress entry in the "Plugin" column on the Plugins page. |
| @@ -347,14 +409,14 @@ | ||
| 347 | 409 | * Add links to the TablePress entry in the "Plugin" column on the Plugins page. |
| 348 | 410 | * |
| 349 | 411 | * @since 1.0.0 |
| 350 | 412 | * |
| 351 | - * @param array $links List of links to print in the "Plugin" column on the Plugins page. | |
| 352 | - * @return array Extended list of links to print in the "Plugin" column on the Plugins page. | |
| 413 | + * @param string[] $links List of links to print in the "Plugin" column on the Plugins page. | |
| 414 | + * @return string[] Extended list of links to print in the "Plugin" column on the Plugins page. | |
| 353 | 415 | */ |
| 354 | - public function add_plugin_action_links( array $links ) { | |
| 416 | + public function add_plugin_action_links( array $links ): array { | |
| 355 | 417 | if ( current_user_can( 'tablepress_list_tables' ) ) { |
| 356 | - $links[] = '<a href="' . TablePress::url() . '">' . __( 'Plugin page', 'tablepress' ) . '</a>'; | |
| 418 | + $links[] = '<a href="' . esc_url( TablePress::url() ) . '">' . __( 'Plugin page', 'tablepress' ) . '</a>'; | |
| 357 | 419 | } |
| 358 | 420 | return $links; |
| 359 | 421 | } |
| 360 | 422 | |
| @@ -362,19 +424,19 @@ | ||
| 362 | 424 | * Add links to the TablePress entry in the "Description" column on the Plugins page. |
| 363 | 425 | * |
| 364 | 426 | * @since 1.0.0 |
| 365 | 427 | * |
| 366 | - * @param array $links List of links to print in the "Description" column on the Plugins page. | |
| 367 | - * @param string $file Name of the plugin. | |
| 368 | - * @return array Extended list of links to print in the "Description" column on the Plugins page. | |
| 428 | + * @param string[] $links List of links to print in the "Description" column on the Plugins page. | |
| 429 | + * @param string $file Name of the plugin. | |
| 430 | + * @return string[] Extended list of links to print in the "Description" column on the Plugins page. | |
| 369 | 431 | */ |
| 370 | - public function add_plugin_row_meta( array $links, $file ) { | |
| 432 | + public function add_plugin_row_meta( array $links, string $file ): array { | |
| 371 | 433 | if ( TABLEPRESS_BASENAME === $file ) { |
| 372 | 434 | $links[] = '<a href="https://tablepress.org/faq/" title="' . esc_attr__( 'Frequently Asked Questions', 'tablepress' ) . '">' . __( 'FAQ', 'tablepress' ) . '</a>'; |
| 373 | 435 | $links[] = '<a href="https://tablepress.org/documentation/">' . __( 'Documentation', 'tablepress' ) . '</a>'; |
| 374 | 436 | $links[] = '<a href="https://tablepress.org/support/">' . __( 'Support', 'tablepress' ) . '</a>'; |
| 375 | - if ( tb_tp_fs()->is_free_plan() ) { | |
| 376 | - $links[] = '<a href="' . 'https://tablepress.org/premium/' . '" title="' . esc_attr__( 'Check out the Premium version of TablePress!', 'tablepress' ) . '"><strong>' . __( 'Go Premium', 'tablepress' ) . '</strong></a>'; | |
| 437 | + if ( ! TABLEPRESS_IS_PLAYGROUND_PREVIEW && tb_tp_fs()->is_free_plan() ) { | |
| 438 | + $links[] = '<a href="https://tablepress.org/premium/?utm_source=plugin&utm_medium=textlink&utm_content=plugins-screen" title="' . esc_attr__( 'Check out the Premium version of TablePress!', 'tablepress' ) . '"><strong>' . __( 'Go Premium', 'tablepress' ) . '</strong></a>'; | |
| 377 | 439 | } |
| 378 | 440 | } |
| 379 | 441 | return $links; |
| 380 | 442 | } |
| @@ -379,16 +441,62 @@ | ||
| 379 | 441 | return $links; |
| 380 | 442 | } |
| 381 | 443 | |
| 382 | 444 | /** |
| 445 | + * Prints a superseded extension notice below certain TablePress Extension plugins' meta rows on the "Plugins" screen. | |
| 446 | + * | |
| 447 | + * @since 2.4.1 | |
| 448 | + * | |
| 449 | + * @param string $plugin_file Path to the plugin file relative to the plugins directory. | |
| 450 | + * @param array<int, string|string[]|bool> $plugin_data An array of plugin data. | |
| 451 | + * @param string $status Status filter currently applied to the plugin list. | |
| 452 | + */ | |
| 453 | + public function add_superseded_extension_meta_row( string $plugin_file, array $plugin_data, string $status ): void { | |
| 454 | + if ( ! is_plugin_active( $plugin_file ) ) { | |
| 455 | + return; | |
| 456 | + } | |
| 457 | + ?> | |
| 458 | + <tr class="plugin-update-tr active"> | |
| 459 | + <td colspan="<?php echo esc_attr( $GLOBALS['wp_list_table']->get_column_count() ); ?>" class="plugin-update colspanchange"> | |
| 460 | + <div class="update-message notice inline notice-error notice-alt"> | |
| 461 | + <?php | |
| 462 | + if ( tb_tp_fs()->is_free_plan() ) { | |
| 463 | + echo '<p style="font-size:14px;">'; | |
| 464 | + _e( 'This TablePress Extension was retired.', 'tablepress' ); | |
| 465 | + echo ' '; | |
| 466 | + _e( '<strong>The plugin does no longer work with TablePress 3</strong> and will no longer receive updates or support!', 'tablepress' ); | |
| 467 | + echo '<br>'; | |
| 468 | + _e( 'Keeping it activated can lead to errors on your website!', 'tablepress' ); | |
| 469 | + echo ' <strong>' . sprintf( __( '<a href="%s">Find out what you can do to continue using its features!</a>', 'tablepress' ), 'https://tablepress.org/upgrade-extensions/?utm_source=plugin&utm_medium=textlink&utm_content=plugins-list-table' ) . '</strong>'; | |
| 470 | + echo '</p>'; | |
| 471 | + } | |
| 472 | + ?> | |
| 473 | + <style> | |
| 474 | + /* Remove the separator line between the plugin's and the notice's table row. */ | |
| 475 | + .plugins .active[data-plugin="<?php echo $plugin_file; ?>"] th, | |
| 476 | + .plugins .active[data-plugin="<?php echo $plugin_file; ?>"] td { | |
| 477 | + box-shadow: none; | |
| 478 | + } | |
| 479 | + /* Hide the plugin update row for the Extension as those won't work anymore anyways. */ | |
| 480 | + .plugins .plugin-update-tr[data-plugin="<?php echo $plugin_file; ?>"] { | |
| 481 | + display: none; | |
| 482 | + } | |
| 483 | + </style> | |
| 484 | + </div> | |
| 485 | + </td> | |
| 486 | + </tr> | |
| 487 | + <?php | |
| 488 | + } | |
| 489 | + | |
| 490 | + /** | |
| 383 | 491 | * Prepare the rendering of an admin screen, by determining the current action, loading necessary data and initializing the view. |
| 384 | 492 | * |
| 385 | 493 | * @since 1.0.0 |
| 386 | 494 | */ |
| 387 | - public function load_admin_page() { | |
| 495 | + public function load_admin_page(): void { | |
| 388 | 496 | // Determine the action from either the GET parameter (for sub-menu entries, and the main admin menu entry). |
| 389 | 497 | $action = ( ! empty( $_GET['action'] ) ) ? $_GET['action'] : 'list'; // Default action is list. |
| 390 | - if ( $this->is_top_level_page ) { | |
| 498 | + if ( TablePress::$controller->is_top_level_page ) { | |
| 391 | 499 | // Or, for sub-menu entry of an admin menu "TablePress" entry, get it from the "page" GET parameter. |
| 392 | 500 | if ( 'tablepress' !== $_GET['page'] ) { |
| 393 | 501 | // Actions that are top-level entries, but don't have an action GET parameter (action is after last _ in string). |
| 394 | 502 | $action = substr( $_GET['page'], 11 ); // $_GET['page'] has the format 'tablepress_{$action}' |
| @@ -395,9 +503,9 @@ | ||
| 395 | 503 | } |
| 396 | 504 | } |
| 397 | 505 | |
| 398 | 506 | // Check if action is a supported action, and whether the user is allowed to access this screen. |
| 399 | - if ( ! isset( $this->view_actions[ $action ] ) || ! current_user_can( $this->view_actions[ $action ]['required_cap'] ) ) { | |
| 507 | + if ( ! isset( $this->view_actions[ $action ] ) || ! current_user_can( $this->view_actions[ $action ]['required_cap'] ) ) { // @phpstan-ignore argument.type (The array value for the capability is always a string.) | |
| 400 | 508 | wp_die( __( 'Sorry, you are not allowed to access this page.', 'default' ), 403 ); |
| 401 | 509 | } |
| 402 | 510 | |
| 403 | 511 | // Don't load TablePress assets on the Freemius opt-in/activation screen. |
| @@ -412,9 +520,9 @@ | ||
| 412 | 520 | * Set the `$typenow` global to the current CPT ourselves, as `WP_Screen::get()` does not determine the CPT correctly. |
| 413 | 521 | * This is necessary as the WP Admin Menu can otherwise highlight wrong entries, see https://github.com/TablePress/TablePress/issues/24. |
| 414 | 522 | */ |
| 415 | 523 | if ( isset( $_GET['post_type'] ) && post_type_exists( $_GET['post_type'] ) ) { |
| 416 | - $GLOBALS['typenow'] = $_GET['post_type']; | |
| 524 | + $GLOBALS['typenow'] = $_GET['post_type']; // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited | |
| 417 | 525 | } |
| 418 | 526 | |
| 419 | 527 | // Pre-define some view data. |
| 420 | 528 | $data = array( |
| @@ -429,17 +537,16 @@ | ||
| 429 | 537 | case 'list': |
| 430 | 538 | $data['table_id'] = ( ! empty( $_GET['table_id'] ) ) ? $_GET['table_id'] : false; |
| 431 | 539 | // Prime the post meta cache for cached loading of last_editor. |
| 432 | 540 | $data['table_ids'] = TablePress::$model_table->load_all( true ); |
| 433 | - $data['messages']['first_visit'] = TablePress::$model_options->get( 'message_first_visit' ); | |
| 434 | - $data['messages']['plugin_update_message'] = TablePress::$model_options->get( 'message_plugin_update' ); | |
| 435 | - $data['messages']['donation_message'] = $this->maybe_show_donation_message(); | |
| 541 | + $data['messages']['donation_nag'] = $this->maybe_show_donation_message(); | |
| 542 | + $data['messages']['first_visit'] = ! $data['messages']['donation_nag'] && TablePress::$model_options->get( 'message_first_visit' ); | |
| 543 | + $data['messages']['plugin_update'] = TablePress::$model_options->get( 'message_plugin_update' ); | |
| 544 | + $data['messages']['superseded_extensions'] = current_user_can( 'manage_options' ) && TablePress::$model_options->get( 'message_superseded_extensions' ); | |
| 436 | 545 | $data['table_count'] = count( $data['table_ids'] ); |
| 437 | 546 | break; |
| 438 | 547 | case 'about': |
| 439 | 548 | $data['first_activation'] = TablePress::$model_options->get( 'first_activation' ); |
| 440 | - $exporter = TablePress::load_class( 'TablePress_Export', 'class-export.php', 'classes' ); | |
| 441 | - $data['zip_support_available'] = $exporter->zip_support_available; | |
| 442 | 549 | break; |
| 443 | 550 | case 'options': |
| 444 | 551 | /* |
| 445 | 552 | * Maybe try saving "Custom CSS" to a file: |
| @@ -446,9 +553,9 @@ | ||
| 446 | 553 | * (called here, as the credentials form posts to this handler again, due to how `request_filesystem_credentials()` works) |
| 447 | 554 | */ |
| 448 | 555 | if ( isset( $_GET['item'] ) && 'save_custom_css' === $_GET['item'] ) { |
| 449 | 556 | TablePress::check_nonce( 'options', $_GET['item'] ); // Nonce check here, as we don't have an explicit handler, and even viewing the screen needs to be checked. |
| 450 | - $action = 'options_custom_css'; // to load a different view | |
| 557 | + $action = 'options_custom_css'; // To load a different view. | |
| 451 | 558 | // Try saving "Custom CSS" to a file, otherwise this gets the HTML for the credentials form. |
| 452 | 559 | $tablepress_css = TablePress::load_class( 'TablePress_CSS', 'class-css.php', 'classes' ); |
| 453 | 560 | $result = $tablepress_css->save_custom_css_to_file_plugin_options( TablePress::$model_options->get( 'custom_css' ), TablePress::$model_options->get( 'custom_css_minified' ) ); |
| 454 | 561 | if ( is_string( $result ) ) { |
| @@ -469,9 +576,9 @@ | ||
| 469 | 576 | break; |
| 470 | 577 | } |
| 471 | 578 | $data['frontend_options']['use_custom_css'] = TablePress::$model_options->get( 'use_custom_css' ); |
| 472 | 579 | $data['frontend_options']['custom_css'] = TablePress::$model_options->get( 'custom_css' ); |
| 473 | - $data['user_options']['parent_page'] = $this->parent_page; | |
| 580 | + $data['user_options']['parent_page'] = TablePress::$controller->parent_page; | |
| 474 | 581 | break; |
| 475 | 582 | case 'edit': |
| 476 | 583 | if ( empty( $_GET['table_id'] ) ) { |
| 477 | 584 | TablePress::redirect( array( 'action' => 'list', 'message' => 'error_no_table' ) ); |
| @@ -486,29 +593,54 @@ | ||
| 486 | 593 | } |
| 487 | 594 | break; |
| 488 | 595 | case 'export': |
| 489 | 596 | // Load all table IDs without priming the post meta cache, as table options/visibility are not needed. |
| 490 | - $data['table_ids'] = TablePress::$model_table->load_all( false ); | |
| 597 | + $table_ids = TablePress::$model_table->load_all( false ); | |
| 598 | + $data['tables'] = array(); | |
| 599 | + foreach ( $table_ids as $table_id ) { | |
| 600 | + if ( ! current_user_can( 'tablepress_export_table', $table_id ) ) { | |
| 601 | + continue; | |
| 602 | + } | |
| 603 | + // Load table, without table data, options, and visibility settings. | |
| 604 | + $table = TablePress::$model_table->load( $table_id, false, false ); | |
| 605 | + | |
| 606 | + // Skip tables that could not be loaded. | |
| 607 | + if ( is_wp_error( $table ) ) { | |
| 608 | + continue; | |
| 609 | + } | |
| 610 | + | |
| 611 | + $data['tables'][ $table['id'] ] = $table['name']; | |
| 612 | + } | |
| 491 | 613 | $data['tables_count'] = TablePress::$model_table->count_tables(); |
| 492 | - if ( ! empty( $_GET['table_id'] ) ) { | |
| 493 | - $data['export_ids'] = explode( ',', $_GET['table_id'] ); | |
| 494 | - } else { | |
| 495 | - // Just show empty export form. | |
| 496 | - $data['export_ids'] = array(); | |
| 497 | - } | |
| 614 | + $data['export_ids'] = ( ! empty( $_GET['table_id'] ) ) ? explode( ',', $_GET['table_id'] ) : array(); | |
| 498 | 615 | $exporter = TablePress::load_class( 'TablePress_Export', 'class-export.php', 'classes' ); |
| 499 | 616 | $data['zip_support_available'] = $exporter->zip_support_available; |
| 500 | 617 | $data['export_formats'] = $exporter->export_formats; |
| 501 | 618 | $data['csv_delimiters'] = $exporter->csv_delimiters; |
| 502 | - $data['export_format'] = ( ! empty( $_GET['export_format'] ) ) ? $_GET['export_format'] : false; | |
| 619 | + $data['export_format'] = ( ! empty( $_GET['export_format'] ) ) ? $_GET['export_format'] : 'csv'; | |
| 503 | 620 | $data['csv_delimiter'] = ( ! empty( $_GET['csv_delimiter'] ) ) ? $_GET['csv_delimiter'] : _x( ',', 'Default CSV delimiter in the translated language (";", ",", or "tab")', 'tablepress' ); |
| 504 | 621 | break; |
| 505 | 622 | case 'import': |
| 506 | 623 | // Load all table IDs without priming the post meta cache, as table options/visibility are not needed. |
| 507 | - $data['table_ids'] = TablePress::$model_table->load_all( false ); | |
| 624 | + $table_ids = TablePress::$model_table->load_all( false ); | |
| 625 | + $data['tables'] = array(); | |
| 626 | + foreach ( $table_ids as $table_id ) { | |
| 627 | + if ( ! current_user_can( 'tablepress_edit_table', $table_id ) ) { | |
| 628 | + continue; | |
| 629 | + } | |
| 630 | + // Load table, without table data, options, and visibility settings. | |
| 631 | + $table = TablePress::$model_table->load( $table_id, false, false ); | |
| 632 | + | |
| 633 | + // Skip tables that could not be loaded. | |
| 634 | + if ( is_wp_error( $table ) ) { | |
| 635 | + continue; | |
| 636 | + } | |
| 637 | + | |
| 638 | + $data['tables'][ $table['id'] ] = $table['name']; | |
| 639 | + } | |
| 640 | + $data['table_ids'] = $table_ids; // Backward compatibility for the retired "Table Auto Update" Extension, which still relies on this variable name. | |
| 508 | 641 | $data['tables_count'] = TablePress::$model_table->count_tables(); |
| 509 | 642 | $importer = TablePress::load_class( 'TablePress_Import', 'class-import.php', 'classes' ); |
| 510 | - $data['zip_support_available'] = $importer->zip_support_available; | |
| 511 | 643 | $data['import_type'] = ( ! empty( $_GET['import_type'] ) ) ? $_GET['import_type'] : 'add'; |
| 512 | 644 | $data['import_existing_table'] = ( ! empty( $_GET['import_existing_table'] ) ) ? $_GET['import_existing_table'] : ''; |
| 513 | 645 | $data['import_source'] = ( ! empty( $_GET['import_source'] ) ) ? $_GET['import_source'] : 'file-upload'; |
| 514 | 646 | $data['import_url'] = ( ! empty( $_GET['import_url'] ) ) ? wp_unslash( $_GET['import_url'] ) : 'https://'; |
| @@ -522,10 +654,10 @@ | ||
| 522 | 654 | * Filters the data that is passed to the current TablePress View. |
| 523 | 655 | * |
| 524 | 656 | * @since 1.0.0 |
| 525 | 657 | * |
| 526 | - * @param array $data Data for the view. | |
| 527 | - * @param string $action The current action for the view. | |
| 658 | + * @param array<string, mixed> $data Data for the view. | |
| 659 | + * @param string $action The current action for the view. | |
| 528 | 660 | */ |
| 529 | 661 | $data = apply_filters( 'tablepress_view_data', $data, $action ); |
| 530 | 662 | |
| 531 | 663 | // Prepare and initialize the view. |
| @@ -536,9 +668,9 @@ | ||
| 536 | 668 | * Render the view that has been initialized in load_admin_page() (called by WordPress when the actual page content is needed). |
| 537 | 669 | * |
| 538 | 670 | * @since 1.0.0 |
| 539 | 671 | */ |
| 540 | - public function show_admin_page() { | |
| 672 | + public function show_admin_page(): void { | |
| 541 | 673 | $this->view->render(); |
| 542 | 674 | } |
| 543 | 675 | |
| 544 | 676 | /** |
| @@ -547,9 +679,9 @@ | ||
| 547 | 679 | * @since 1.0.0 |
| 548 | 680 | * |
| 549 | 681 | * @return bool Whether the message shall be shown on the "All Tables" screen. |
| 550 | 682 | */ |
| 551 | - protected function maybe_show_donation_message() { | |
| 683 | + protected function maybe_show_donation_message(): bool { | |
| 552 | 684 | // Only show the message to plugin admins. |
| 553 | 685 | if ( ! current_user_can( 'tablepress_edit_options' ) ) { |
| 554 | 686 | return false; |
| 555 | 687 | } |
| @@ -567,9 +699,9 @@ | ||
| 567 | 699 | * Init list of actions that have a view with their titles/names/caps. |
| 568 | 700 | * |
| 569 | 701 | * @since 1.0.0 |
| 570 | 702 | */ |
| 571 | - protected function init_view_actions() { | |
| 703 | + protected function init_view_actions(): void { | |
| 572 | 704 | $this->view_actions = array( |
| 573 | 705 | 'list' => array( |
| 574 | 706 | 'show_entry' => true, |
| 575 | 707 | 'page_title' => __( 'All Tables', 'tablepress' ), |
| @@ -625,9 +757,9 @@ | ||
| 625 | 757 | * Filters the available TablePres Views/Actions and their parameters. |
| 626 | 758 | * |
| 627 | 759 | * @since 1.0.0 |
| 628 | 760 | * |
| 629 | - * @param array $view_actions The available Views/Actions and their parameters. | |
| 761 | + * @param array<string, array<string, bool|string>> $view_actions The available Views/Actions and their parameters. | |
| 630 | 762 | */ |
| 631 | 763 | $this->view_actions = apply_filters( 'tablepress_admin_view_actions', $this->view_actions ); |
| 632 | 764 | } |
| 633 | 765 | |
| @@ -639,9 +771,9 @@ | ||
| 639 | 771 | * Handle Bulk Actions (Copy, Export, Delete) on "All Tables" list screen. |
| 640 | 772 | * |
| 641 | 773 | * @since 1.0.0 |
| 642 | 774 | */ |
| 643 | - public function handle_post_action_list() { | |
| 775 | + public function handle_post_action_list(): void { | |
| 644 | 776 | TablePress::check_nonce( 'list' ); |
| 645 | 777 | |
| 646 | 778 | if ( isset( $_POST['bulk-action-selector-top'] ) && '-1' !== $_POST['bulk-action-selector-top'] ) { |
| 647 | 779 | $bulk_action = $_POST['bulk-action-selector-top']; |
| @@ -682,9 +814,9 @@ | ||
| 682 | 814 | * To export, redirect to "Export" screen, with selected table IDs. |
| 683 | 815 | */ |
| 684 | 816 | $table_ids = implode( ',', $tables ); |
| 685 | 817 | TablePress::redirect( array( 'action' => 'export', 'table_id' => $table_ids ) ); |
| 686 | - break; | |
| 818 | + // break; // unreachable. | |
| 687 | 819 | case 'delete': |
| 688 | 820 | foreach ( $tables as $table_id ) { |
| 689 | 821 | if ( current_user_can( 'tablepress_delete_table', $table_id ) ) { |
| 690 | 822 | $deleted = TablePress::$model_table->delete( $table_id ); |
| @@ -697,9 +829,9 @@ | ||
| 697 | 829 | } |
| 698 | 830 | break; |
| 699 | 831 | } |
| 700 | 832 | |
| 701 | - if ( 0 !== count( $no_success ) ) { // @TODO: maybe pass this information to the view? | |
| 833 | + if ( 0 !== count( $no_success ) ) { // @todo maybe pass this information to the view? | |
| 702 | 834 | $message = "error_{$bulk_action}_not_all_tables"; |
| 703 | 835 | } else { |
| 704 | 836 | $plural = ( count( $tables ) > 1 ) ? '_plural' : ''; |
| 705 | 837 | $message = "success_{$bulk_action}{$plural}"; |
| @@ -724,9 +856,9 @@ | ||
| 724 | 856 | * Add a table, according to the parameters on the "Add new Table" screen. |
| 725 | 857 | * |
| 726 | 858 | * @since 1.0.0 |
| 727 | 859 | */ |
| 728 | - public function handle_post_action_add() { | |
| 860 | + public function handle_post_action_add(): void { | |
| 729 | 861 | TablePress::check_nonce( 'add' ); |
| 730 | 862 | |
| 731 | 863 | if ( ! current_user_can( 'tablepress_add_tables' ) ) { |
| 732 | 864 | wp_die( __( 'Sorry, you are not allowed to access this page.', 'default' ), 403 ); |
| @@ -737,11 +869,11 @@ | ||
| 737 | 869 | } |
| 738 | 870 | |
| 739 | 871 | $add_table = wp_unslash( $_POST['table'] ); |
| 740 | 872 | |
| 741 | - // Perform sanity checks of posted data. | |
| 742 | - $name = ( isset( $add_table['name'] ) ) ? $add_table['name'] : ''; | |
| 743 | - $description = ( isset( $add_table['description'] ) ) ? $add_table['description'] : ''; | |
| 873 | + // Perform confidence checks of posted data. | |
| 874 | + $name = $add_table['name'] ?? ''; | |
| 875 | + $description = $add_table['description'] ?? ''; | |
| 744 | 876 | if ( ! isset( $add_table['rows'], $add_table['columns'] ) ) { |
| 745 | 877 | TablePress::redirect( array( 'action' => 'add', 'message' => 'error_add', 'error_details' => 'The HTTP POST data does not contain the table size.' ) ); |
| 746 | 878 | } |
| 747 | 879 | |
| @@ -780,9 +912,9 @@ | ||
| 780 | 912 | * Save changed "Plugin Options". |
| 781 | 913 | * |
| 782 | 914 | * @since 1.0.0 |
| 783 | 915 | */ |
| 784 | - public function handle_post_action_options() { | |
| 916 | + public function handle_post_action_options(): void { | |
| 785 | 917 | TablePress::check_nonce( 'options' ); |
| 786 | 918 | |
| 787 | 919 | if ( ! current_user_can( 'tablepress_access_options_screen' ) ) { |
| 788 | 920 | wp_die( __( 'Sorry, you are not allowed to access this page.', 'default' ), 403 ); |
| @@ -801,10 +933,10 @@ | ||
| 801 | 933 | if ( ! empty( $posted_options['admin_menu_parent_page'] ) && '-' !== $posted_options['admin_menu_parent_page'] ) { |
| 802 | 934 | $new_options['admin_menu_parent_page'] = $posted_options['admin_menu_parent_page']; |
| 803 | 935 | // Re-init parent information, as `TablePress::redirect()` URL might be wrong otherwise. |
| 804 | 936 | /** This filter is documented in classes/class-controller.php */ |
| 805 | - $this->parent_page = apply_filters( 'tablepress_admin_menu_parent_page', $posted_options['admin_menu_parent_page'] ); | |
| 806 | - $this->is_top_level_page = in_array( $this->parent_page, array( 'top', 'middle', 'bottom' ), true ); | |
| 937 | + TablePress::$controller->parent_page = apply_filters( 'tablepress_admin_menu_parent_page', $posted_options['admin_menu_parent_page'] ); | |
| 938 | + TablePress::$controller->is_top_level_page = in_array( TablePress::$controller->parent_page, array( 'top', 'middle', 'bottom' ), true ); | |
| 807 | 939 | } |
| 808 | 940 | |
| 809 | 941 | // Custom CSS can only be saved if the user is allowed to do so. |
| 810 | 942 | $update_custom_css_files = false; |
| @@ -815,13 +947,20 @@ | ||
| 815 | 947 | if ( isset( $posted_options['custom_css'] ) ) { |
| 816 | 948 | $new_options['custom_css'] = $posted_options['custom_css']; |
| 817 | 949 | |
| 818 | 950 | $tablepress_css = TablePress::load_class( 'TablePress_CSS', 'class-css.php', 'classes' ); |
| 819 | - // Sanitize and tidy up Custom CSS. | |
| 820 | - $new_options['custom_css'] = $tablepress_css->sanitize_css( $new_options['custom_css'] ); | |
| 821 | - // Minify Custom CSS. | |
| 822 | - $new_options['custom_css_minified'] = $tablepress_css->minify_css( $new_options['custom_css'] ); | |
| 823 | 951 | |
| 952 | + if ( '' !== $new_options['custom_css'] ) { | |
| 953 | + // Update "Custom CSS" to use DataTables 2 variants instead of old DataTables 1.x CSS classes. | |
| 954 | + $new_options['custom_css'] = TablePress::convert_datatables_api_data( $new_options['custom_css'] ); | |
| 955 | + // Sanitize and tidy up Custom CSS. | |
| 956 | + $new_options['custom_css'] = $tablepress_css->sanitize_css( $new_options['custom_css'] ); | |
| 957 | + // Minify Custom CSS. | |
| 958 | + $new_options['custom_css_minified'] = $tablepress_css->minify_css( $new_options['custom_css'] ); | |
| 959 | + } else { | |
| 960 | + $new_options['custom_css_minified'] = ''; | |
| 961 | + } | |
| 962 | + | |
| 824 | 963 | // Maybe update CSS files as well. |
| 825 | 964 | $custom_css_file_contents = $tablepress_css->load_custom_css_from_file( 'normal' ); |
| 826 | 965 | if ( false === $custom_css_file_contents ) { |
| 827 | 966 | $custom_css_file_contents = ''; |
| @@ -852,9 +991,9 @@ | ||
| 852 | 991 | * Export selected tables. |
| 853 | 992 | * |
| 854 | 993 | * @since 1.0.0 |
| 855 | 994 | */ |
| 856 | - public function handle_post_action_export() { | |
| 995 | + public function handle_post_action_export(): void { | |
| 857 | 996 | TablePress::check_nonce( 'export' ); |
| 858 | 997 | |
| 859 | 998 | if ( ! current_user_can( 'tablepress_export_tables' ) ) { |
| 860 | 999 | wp_die( __( 'Sorry, you are not allowed to access this page.', 'default' ), 403 ); |
| @@ -865,12 +1004,13 @@ | ||
| 865 | 1004 | } |
| 866 | 1005 | |
| 867 | 1006 | $export = wp_unslash( $_POST['export'] ); |
| 868 | 1007 | |
| 869 | - if ( empty( $export['tables'] ) ) { | |
| 1008 | + if ( empty( $export['tables_list'] ) ) { | |
| 870 | 1009 | TablePress::redirect( array( 'action' => 'export', 'message' => 'error_export', 'error_details' => 'The HTTP POST data does not contain tables.' ) ); |
| 871 | 1010 | } |
| 872 | 1011 | |
| 1012 | + /** @var TablePress_Export $exporter */ // phpcs:ignore Generic.Commenting.DocComment.MissingShort | |
| 873 | 1013 | $exporter = TablePress::load_class( 'TablePress_Export', 'class-export.php', 'classes' ); |
| 874 | 1014 | |
| 875 | 1015 | if ( empty( $export['format'] ) || ! isset( $exporter->export_formats[ $export['format'] ] ) ) { |
| 876 | 1016 | TablePress::redirect( array( 'action' => 'export', 'message' => 'error_export', 'error_details' => 'The export format is invalid.' ) ); |
| @@ -882,10 +1022,9 @@ | ||
| 882 | 1022 | if ( 'csv' === $export['format'] && ! isset( $exporter->csv_delimiters[ $export['csv_delimiter'] ] ) ) { |
| 883 | 1023 | TablePress::redirect( array( 'action' => 'export', 'message' => 'error_export', 'error_details' => 'The CSV delimiter is invalid.' ) ); |
| 884 | 1024 | } |
| 885 | 1025 | |
| 886 | - // Use list of tables from concatenated field if available (as that's hopefully not truncated by Suhosin, which is possible for $export['tables']). | |
| 887 | - $tables = ( ! empty( $export['tables_list'] ) ) ? explode( ',', $export['tables_list'] ) : $export['tables']; | |
| 1026 | + $tables = explode( ',', $export['tables_list'] ); | |
| 888 | 1027 | |
| 889 | 1028 | // Determine if ZIP file support is available. |
| 890 | 1029 | if ( $exporter->zip_support_available |
| 891 | 1030 | && ( ( isset( $export['zip_file'] ) && 'true' === $export['zip_file'] ) || count( $tables ) > 1 ) ) { |
| @@ -895,9 +1034,9 @@ | ||
| 895 | 1034 | $export_to_zip = false; |
| 896 | 1035 | } |
| 897 | 1036 | |
| 898 | 1037 | if ( ! $export_to_zip ) { |
| 899 | - // This is only possible for one table, so take the first one. | |
| 1038 | + // Exporting without a ZIP file is only possible for one table, so take the first one. | |
| 900 | 1039 | if ( ! current_user_can( 'tablepress_export_table', $tables[0] ) ) { |
| 901 | 1040 | wp_die( __( 'Sorry, you are not allowed to access this page.', 'default' ), 403 ); |
| 902 | 1041 | } |
| 903 | 1042 | // Load table, with table data, options, and visibility settings. |
| @@ -928,20 +1067,21 @@ | ||
| 928 | 1067 | * Filters the exported table data. |
| 929 | 1068 | * |
| 930 | 1069 | * @since 1.6.0 |
| 931 | 1070 | * |
| 932 | - * @param string $export_data The exported table data. | |
| 933 | - * @param array $table Table to be exported. | |
| 934 | - * @param string $export_format Format for the export ('csv', 'html', 'json'). | |
| 935 | - * @param string $csv_delimiter Delimiter for CSV export. | |
| 1071 | + * @param string $export_data The exported table data. | |
| 1072 | + * @param array<string, mixed> $table Table to be exported. | |
| 1073 | + * @param string $export_format Format for the export ('csv', 'html', 'json'). | |
| 1074 | + * @param string $csv_delimiter Delimiter for CSV export. | |
| 936 | 1075 | */ |
| 937 | 1076 | $export_data = apply_filters( 'tablepress_export_data', $export_data, $table, $export['format'], $export['csv_delimiter'] ); |
| 938 | 1077 | $download_data = $export_data; |
| 939 | 1078 | } else { |
| 940 | 1079 | // Zipping can use a lot of memory and execution time, but not this much hopefully. |
| 941 | - /** This filter is documented in the WordPress file wp-admin/admin.php */ | |
| 942 | - @ini_set( 'memory_limit', apply_filters( 'admin_memory_limit', WP_MAX_MEMORY_LIMIT ) ); // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged | |
| 943 | - @set_time_limit( 300 ); // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged | |
| 1080 | + wp_raise_memory_limit( 'admin' ); | |
| 1081 | + if ( function_exists( 'set_time_limit' ) ) { | |
| 1082 | + @set_time_limit( 300 ); // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged | |
| 1083 | + } | |
| 944 | 1084 | |
| 945 | 1085 | $zip_file = new ZipArchive(); |
| 946 | 1086 | $download_filename = sprintf( 'tablepress-export-%1$s-%2$s.zip', wp_date( 'Y-m-d-H-i-s' ), $export['format'] ); |
| 947 | 1087 | /** This filter is documented in controllers/controller-admin.php */ |
| @@ -947,10 +1087,10 @@ | ||
| 947 | 1087 | /** This filter is documented in controllers/controller-admin.php */ |
| 948 | 1088 | $download_filename = apply_filters( 'tablepress_export_filename', $download_filename, '', '', $export['format'], $export_to_zip ); |
| 949 | 1089 | $download_filename = sanitize_file_name( $download_filename ); |
| 950 | 1090 | $full_filename = wp_tempnam( $download_filename ); |
| 951 | - if ( true !== $zip_file->open( $full_filename, ZIPARCHIVE::OVERWRITE ) ) { | |
| 952 | - @unlink( $full_filename ); | |
| 1091 | + if ( true !== $zip_file->open( $full_filename, ZipArchive::OVERWRITE ) ) { | |
| 1092 | + @unlink( $full_filename ); // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged | |
| 953 | 1093 | TablePress::redirect( array( 'action' => 'export', 'message' => 'error_create_zip_file', 'export_format' => $export['format'], 'csv_delimiter' => $export['csv_delimiter'], 'error_details' => 'The ZIP file could not be opened for writing.' ) ); |
| 954 | 1094 | } |
| 955 | 1095 | |
| 956 | 1096 | foreach ( $tables as $table_id ) { |
| @@ -979,11 +1119,11 @@ | ||
| 979 | 1119 | } |
| 980 | 1120 | |
| 981 | 1121 | // If something went wrong, or no files were added to the ZIP file, bail out. |
| 982 | 1122 | // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase |
| 983 | - if ( ! ZIPARCHIVE::ER_OK === $zip_file->status || 0 === $zip_file->numFiles ) { | |
| 1123 | + if ( ZipArchive::ER_OK !== $zip_file->status || 0 === $zip_file->numFiles ) { | |
| 984 | 1124 | $zip_file->close(); |
| 985 | - @unlink( $full_filename ); | |
| 1125 | + @unlink( $full_filename ); // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged | |
| 986 | 1126 | TablePress::redirect( array( 'action' => 'export', 'message' => 'error_create_zip_file', 'export_format' => $export['format'], 'csv_delimiter' => $export['csv_delimiter'], 'error_details' => 'The ZIP file could not be written or is empty.' ) ); |
| 987 | 1127 | } |
| 988 | 1128 | $zip_file->close(); |
| 989 | 1129 | |
| @@ -988,9 +1128,13 @@ | ||
| 988 | 1128 | $zip_file->close(); |
| 989 | 1129 | |
| 990 | 1130 | // Load contents of the ZIP file, to send it as a download. |
| 991 | 1131 | $download_data = file_get_contents( $full_filename ); |
| 992 | - @unlink( $full_filename ); | |
| 1132 | + if ( false === $download_data ) { | |
| 1133 | + @unlink( $full_filename ); // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged | |
| 1134 | + TablePress::redirect( array( 'action' => 'export', 'message' => 'error_create_zip_file', 'export_format' => $export['format'], 'csv_delimiter' => $export['csv_delimiter'], 'error_details' => 'The ZIP file content could not be read.' ) ); | |
| 1135 | + } | |
| 1136 | + @unlink( $full_filename ); // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged | |
| 993 | 1137 | } |
| 994 | 1138 | |
| 995 | 1139 | // Send download headers for export file. |
| 996 | 1140 | header( 'Content-Description: File Transfer' ); |
| @@ -1013,9 +1157,9 @@ | ||
| 1013 | 1157 | * Import data from existing source (Upload, URL, Server, Direct input). |
| 1014 | 1158 | * |
| 1015 | 1159 | * @since 1.0.0 |
| 1016 | 1160 | */ |
| 1017 | - public function handle_post_action_import() { | |
| 1161 | + public function handle_post_action_import(): void { | |
| 1018 | 1162 | TablePress::check_nonce( 'import' ); |
| 1019 | 1163 | |
| 1020 | 1164 | if ( ! current_user_can( 'tablepress_import_tables' ) ) { |
| 1021 | 1165 | wp_die( __( 'Sorry, you are not allowed to access this page.', 'default' ), 403 ); |
| @@ -1037,10 +1181,17 @@ | ||
| 1037 | 1181 | TablePress::redirect( array( 'action' => 'import', 'message' => 'error_import', 'error_details' => 'You do not have the required access rights.' ) ); |
| 1038 | 1182 | } |
| 1039 | 1183 | } |
| 1040 | 1184 | |
| 1185 | + // For security reasons, the "url" source is only available admins and editors via a custom capability. | |
| 1186 | + if ( 'url' === $import_config['source'] ) { | |
| 1187 | + if ( ! current_user_can( 'tablepress_import_tables_url' ) ) { | |
| 1188 | + TablePress::redirect( array( 'action' => 'import', 'message' => 'error_import', 'error_details' => 'You do not have the required access rights.' ) ); | |
| 1189 | + } | |
| 1190 | + } | |
| 1191 | + | |
| 1041 | 1192 | // Move file upload data to the main import configuration. |
| 1042 | - $import_config['file-upload'] = isset( $_FILES['import_file_upload'] ) ? $_FILES['import_file_upload'] : null; | |
| 1193 | + $import_config['file-upload'] = $_FILES['import_file_upload'] ?? null; | |
| 1043 | 1194 | |
| 1044 | 1195 | // Check if the source data for the chosen import source is defined. |
| 1045 | 1196 | if ( empty( $import_config[ $import_config['source'] ] ) ) { |
| 1046 | 1197 | TablePress::redirect( array( 'action' => 'import', 'message' => 'error_import', 'error_details' => 'The HTTP POST data does not contain an import source.' ) ); |
| @@ -1075,9 +1226,9 @@ | ||
| 1075 | 1226 | $redirect_parameters['error_details'] = TablePress::get_wp_error_string( $import ); |
| 1076 | 1227 | } elseif ( 0 < count( $import['errors'] ) ) { |
| 1077 | 1228 | $wp_error_strings = array(); |
| 1078 | 1229 | foreach ( $import['errors'] as $file ) { |
| 1079 | - $wp_error_strings[] = TablePress::get_wp_error_string( $file['error'] ); | |
| 1230 | + $wp_error_strings[] = TablePress::get_wp_error_string( $file->error ); | |
| 1080 | 1231 | } |
| 1081 | 1232 | $redirect_parameters['error_details'] = implode( ', ', $wp_error_strings ); |
| 1082 | 1233 | } |
| 1083 | 1234 | TablePress::redirect( $redirect_parameters ); |
| @@ -1101,9 +1252,9 @@ | ||
| 1101 | 1252 | * Hide a header message on an admin screen. |
| 1102 | 1253 | * |
| 1103 | 1254 | * @since 1.0.0 |
| 1104 | 1255 | */ |
| 1105 | - public function handle_get_action_hide_message() { | |
| 1256 | + public function handle_get_action_hide_message(): void { | |
| 1106 | 1257 | $message_item = ! empty( $_GET['item'] ) ? $_GET['item'] : ''; |
| 1107 | 1258 | TablePress::check_nonce( 'hide_message', $message_item ); |
| 1108 | 1259 | |
| 1109 | 1260 | if ( ! current_user_can( 'tablepress_list_tables' ) ) { |
| @@ -1120,9 +1271,9 @@ | ||
| 1120 | 1271 | * Delete a table. |
| 1121 | 1272 | * |
| 1122 | 1273 | * @since 1.0.0 |
| 1123 | 1274 | */ |
| 1124 | - public function handle_get_action_delete_table() { | |
| 1275 | + public function handle_get_action_delete_table(): void { | |
| 1125 | 1276 | $table_id = ( ! empty( $_GET['item'] ) ) ? $_GET['item'] : false; |
| 1126 | 1277 | TablePress::check_nonce( 'delete_table', $table_id ); |
| 1127 | 1278 | |
| 1128 | 1279 | $return = ! empty( $_GET['return'] ) ? $_GET['return'] : 'list'; |
| @@ -1161,9 +1312,9 @@ | ||
| 1161 | 1312 | * Copy a table. |
| 1162 | 1313 | * |
| 1163 | 1314 | * @since 1.0.0 |
| 1164 | 1315 | */ |
| 1165 | - public function handle_get_action_copy_table() { | |
| 1316 | + public function handle_get_action_copy_table(): void { | |
| 1166 | 1317 | $table_id = ( ! empty( $_GET['item'] ) ) ? $_GET['item'] : false; |
| 1167 | 1318 | TablePress::check_nonce( 'copy_table', $table_id ); |
| 1168 | 1319 | |
| 1169 | 1320 | $return = ! empty( $_GET['return'] ) ? $_GET['return'] : 'list'; |
| @@ -1203,9 +1354,9 @@ | ||
| 1203 | 1354 | * Preview a table. |
| 1204 | 1355 | * |
| 1205 | 1356 | * @since 1.0.0 |
| 1206 | 1357 | */ |
| 1207 | - public function handle_get_action_preview_table() { | |
| 1358 | + public function handle_get_action_preview_table(): void { | |
| 1208 | 1359 | $table_id = ( ! empty( $_GET['item'] ) ) ? $_GET['item'] : false; |
| 1209 | 1360 | TablePress::check_nonce( 'preview_table', $table_id ); |
| 1210 | 1361 | |
| 1211 | 1362 | // Nonce check should actually catch this already. |
| @@ -1236,13 +1387,15 @@ | ||
| 1236 | 1387 | $default_render_options = apply_filters( 'tablepress_shortcode_table_default_shortcode_atts', $default_render_options ); |
| 1237 | 1388 | $render_options = shortcode_atts( $default_render_options, $table['options'] ); |
| 1238 | 1389 | /** This filter is documented in controllers/controller-frontend.php */ |
| 1239 | 1390 | $render_options = apply_filters( 'tablepress_shortcode_table_shortcode_atts', $render_options ); |
| 1391 | + $render_options['html_id'] = "tablepress-{$table['id']}"; | |
| 1392 | + $render_options['block_preview'] = true; | |
| 1240 | 1393 | $_render->set_input( $table, $render_options ); |
| 1241 | 1394 | $view_data = array( |
| 1242 | 1395 | 'table_id' => $table_id, |
| 1243 | 1396 | 'head_html' => $_render->get_preview_css(), |
| 1244 | - 'body_html' => $_render->get_output(), | |
| 1397 | + 'body_html' => $_render->get_output( 'html' ), | |
| 1245 | 1398 | 'site_uses_block_editor' => TablePress::site_uses_block_editor(), |
| 1246 | 1399 | ); |
| 1247 | 1400 | |
| 1248 | 1401 | $custom_css = TablePress::$model_options->get( 'custom_css' ); |
| @@ -1260,9 +1413,9 @@ | ||
| 1260 | 1413 | * Shows a list of tables in the Editor toolbar Thickbox (opened by TinyMCE or Quicktags button). |
| 1261 | 1414 | * |
| 1262 | 1415 | * @since 1.0.0 |
| 1263 | 1416 | */ |
| 1264 | - public function handle_get_action_editor_button_thickbox() { | |
| 1417 | + public function handle_get_action_editor_button_thickbox(): void { | |
| 1265 | 1418 | TablePress::check_nonce( 'editor_button_thickbox' ); |
| 1266 | 1419 | |
| 1267 | 1420 | if ( ! current_user_can( 'tablepress_list_tables' ) ) { |
| 1268 | 1421 | wp_die( __( 'Sorry, you are not allowed to access this page.', 'default' ), 403 ); |
| @@ -1284,9 +1437,9 @@ | ||
| 1284 | 1437 | * Uninstall TablePress, and delete all tables and options. |
| 1285 | 1438 | * |
| 1286 | 1439 | * @since 1.0.0 |
| 1287 | 1440 | */ |
| 1288 | - public function handle_get_action_uninstall_tablepress() { | |
| 1441 | + public function handle_get_action_uninstall_tablepress(): void { | |
| 1289 | 1442 | TablePress::check_nonce( 'uninstall_tablepress' ); |
| 1290 | 1443 | |
| 1291 | 1444 | $plugin = TABLEPRESS_BASENAME; |
| 1292 | 1445 | |
| @@ -1306,9 +1459,9 @@ | ||
| 1306 | 1459 | |
| 1307 | 1460 | TablePress::$model_table->destroy(); |
| 1308 | 1461 | TablePress::$model_options->destroy(); |
| 1309 | 1462 | |
| 1310 | - $output = '<strong>' . __( 'TablePress was uninstalled successfully.', 'tablepress' ) . '</strong><br /><br />'; | |
| 1463 | + $output = '<strong>' . __( 'TablePress was uninstalled successfully.', 'tablepress' ) . '</strong><br><br>'; | |
| 1311 | 1464 | $output .= __( 'All tables, data, and options were deleted.', 'tablepress' ); |
| 1312 | 1465 | if ( is_multisite() ) { |
| 1313 | 1466 | $output .= ' ' . __( 'You may now ask the network admin to delete the plugin’s folder <code>tablepress</code> from the server, if no other site in the network uses it.', 'tablepress' ); |
| 1314 | 1467 | } else { |
| @@ -1315,9 +1468,9 @@ | ||
| 1315 | 1468 | $output .= ' ' . __( 'You may now manually delete the plugin’s folder <code>tablepress</code> from the <code>plugins</code> directory on your server or use the “Delete” link for TablePress on the WordPress “Plugins” page.', 'tablepress' ); |
| 1316 | 1469 | } |
| 1317 | 1470 | if ( $css_files_deleted ) { |
| 1318 | 1471 | $output .= ' ' . __( 'Your TablePress “Custom CSS” files have been deleted automatically.', 'tablepress' ); |
| 1319 | - } else { | |
| 1472 | + } else { // phpcs:ignore Universal.ControlStructures.DisallowLonelyIf.Found | |
| 1320 | 1473 | if ( is_multisite() ) { |
| 1321 | 1474 | $output .= ' ' . __( 'Please also ask him to delete your TablePress “Custom CSS” files from the server.', 'tablepress' ); |
| 1322 | 1475 | } else { |
| 1323 | 1476 | $output .= ' ' . __( 'You may now also delete your TablePress “Custom CSS” files in the <code>wp-content</code> folder.', 'tablepress' ); |