| @@ -12,8 +12,9 @@ | ||
| 12 | 12 | defined( 'ABSPATH' ) || die( 'No direct script access allowed!' ); |
| 13 | 13 | |
| 14 | 14 | /** |
| 15 | 15 | * Base Controller class |
| 16 | + * | |
| 16 | 17 | * @package TablePress |
| 17 | 18 | * @subpackage Controllers |
| 18 | 19 | * @author Tobias Bäthge |
| 19 | 20 | * @since 1.0.0 |
| @@ -20,64 +21,15 @@ | ||
| 20 | 21 | */ |
| 21 | 22 | abstract class TablePress_Controller { |
| 22 | 23 | |
| 23 | 24 | /** |
| 24 | - * Instance of the Options Model. | |
| 25 | + * Initializes all controllers. | |
| 25 | 26 | * |
| 26 | 27 | * @since 1.0.0 |
| 27 | - * @var TablePress_Options_Model | |
| 28 | 28 | */ |
| 29 | - public $model_options; | |
| 30 | - | |
| 31 | - /** | |
| 32 | - * Instance of the Table Model. | |
| 33 | - * | |
| 34 | - * @since 1.0.0 | |
| 35 | - * @var TablePress_Table_Model | |
| 36 | - */ | |
| 37 | - public $model_table; | |
| 38 | - | |
| 39 | - /** | |
| 40 | - * File name of the admin screens' parent page in the admin menu. | |
| 41 | - * | |
| 42 | - * @since 1.0.0 | |
| 43 | - * @var string | |
| 44 | - */ | |
| 45 | - public $parent_page = 'middle'; | |
| 46 | - | |
| 47 | - /** | |
| 48 | - * Whether TablePress admin screens are a top-level menu item in the admin menu. | |
| 49 | - * | |
| 50 | - * @since 1.0.0 | |
| 51 | - * @var bool | |
| 52 | - */ | |
| 53 | - public $is_top_level_page = false; | |
| 54 | - | |
| 55 | - /** | |
| 56 | - * Initialize all controllers, by loading Plugin and User Options, and by performing an update check. | |
| 57 | - * | |
| 58 | - * @since 1.0.0 | |
| 59 | - */ | |
| 60 | 29 | public function __construct() { |
| 61 | - /* | |
| 62 | - * References to the TablePress models (only for backwards compatibility in TablePress Extensions!). | |
| 63 | - * Using `TablePress::$model_options` and `TablePress::$model_table` is recommended! | |
| 64 | - */ | |
| 65 | - $this->model_options = TablePress::$model_options; | |
| 66 | - $this->model_table = TablePress::$model_table; | |
| 67 | - | |
| 68 | 30 | // Update check, in all controllers (frontend and admin), to make sure we always have up-to-date options, should be done very early. |
| 69 | 31 | $this->plugin_update_check(); |
| 70 | - | |
| 71 | - /** | |
| 72 | - * Filter the admin menu parent page, which is needed for the construction of plugin URLs. | |
| 73 | - * | |
| 74 | - * @since 1.0.0 | |
| 75 | - * | |
| 76 | - * @param string $parent_page Current admin menu parent page. | |
| 77 | - */ | |
| 78 | - $this->parent_page = apply_filters( 'tablepress_admin_menu_parent_page', TablePress::$model_options->get( 'admin_menu_parent_page' ) ); | |
| 79 | - $this->is_top_level_page = in_array( $this->parent_page, array( 'top', 'middle', 'bottom' ), true ); | |
| 80 | 32 | } |
| 81 | 33 | |
| 82 | 34 | /** |
| 83 | 35 | * Check if the plugin was updated and perform necessary actions, like updating the options. |
| @@ -83,15 +35,16 @@ | ||
| 83 | 35 | * Check if the plugin was updated and perform necessary actions, like updating the options. |
| 84 | 36 | * |
| 85 | 37 | * @since 1.0.0 |
| 86 | 38 | */ |
| 87 | - protected function plugin_update_check() { | |
| 39 | + protected function plugin_update_check(): void { | |
| 88 | 40 | // First activation or plugin update. |
| 89 | 41 | $current_plugin_options_db_version = TablePress::$model_options->get( 'plugin_options_db_version' ); |
| 90 | 42 | if ( $current_plugin_options_db_version < TablePress::db_version ) { |
| 91 | 43 | // Allow more PHP execution time for update process. |
| 92 | - // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged | |
| 93 | - @set_time_limit( 300 ); | |
| 44 | + if ( function_exists( 'set_time_limit' ) ) { | |
| 45 | + @set_time_limit( 300 ); // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged | |
| 46 | + } | |
| 94 | 47 | |
| 95 | 48 | // Add TablePress capabilities to the WP_Roles objects, for new installations and all versions below 12. |
| 96 | 49 | if ( $current_plugin_options_db_version < 12 ) { |
| 97 | 50 | TablePress::$model_options->add_access_capabilities(); |
| @@ -112,21 +65,37 @@ | ||
| 112 | 65 | 'tablepress_version' => TablePress::version, |
| 113 | 66 | 'message_plugin_update' => true, |
| 114 | 67 | ); |
| 115 | 68 | |
| 116 | - // Only write files, if "Custom CSS" is to be used, and if there is "Custom CSS". | |
| 117 | - if ( TablePress::$model_options->get( 'use_custom_css' ) && '' !== TablePress::$model_options->get( 'custom_css' ) ) { | |
| 118 | - // Re-save "Custom CSS" to re-create all files (as TablePress Default CSS might have changed). | |
| 69 | + // If used, re-save "Custom CSS" to re-create all files (as TablePress Default CSS might have changed). | |
| 70 | + $custom_css = TablePress::$model_options->get( 'custom_css' ); | |
| 71 | + if ( TablePress::$model_options->get( 'use_custom_css' ) && '' !== $custom_css ) { | |
| 119 | 72 | /** |
| 120 | 73 | * Load WP file functions to provide filesystem access functions early. |
| 121 | 74 | */ |
| 122 | - require_once ABSPATH . 'wp-admin/includes/file.php'; | |
| 75 | + require_once ABSPATH . 'wp-admin/includes/file.php'; // @phpstan-ignore requireOnce.fileNotFound (This is a WordPress core file that always exists.) | |
| 123 | 76 | /** |
| 124 | 77 | * Load WP admin template functions to provide `submit_button()` which is necessary for `request_filesystem_credentials()`. |
| 125 | 78 | */ |
| 126 | - require_once ABSPATH . 'wp-admin/includes/template.php'; | |
| 79 | + require_once ABSPATH . 'wp-admin/includes/template.php'; // @phpstan-ignore requireOnce.fileNotFound (This is a WordPress core file that always exists.) | |
| 127 | 80 | $tablepress_css = TablePress::load_class( 'TablePress_CSS', 'class-css.php', 'classes' ); |
| 128 | - $result = $tablepress_css->save_custom_css_to_file( TablePress::$model_options->get( 'custom_css' ), TablePress::$model_options->get( 'custom_css_minified' ) ); | |
| 81 | + | |
| 82 | + $custom_css_minified = TablePress::$model_options->get( 'custom_css_minified' ); | |
| 83 | + | |
| 84 | + // Update "Custom CSS" to be compatible with DataTables 2, introduced in TablePress 3.0. | |
| 85 | + if ( $current_plugin_options_db_version < 96 ) { | |
| 86 | + $old_custom_css = $custom_css; | |
| 87 | + $custom_css = TablePress::convert_datatables_api_data( $custom_css ); | |
| 88 | + if ( $old_custom_css !== $custom_css ) { | |
| 89 | + $custom_css = $tablepress_css->sanitize_css( $custom_css ); | |
| 90 | + $custom_css_minified = $tablepress_css->minify_css( $custom_css ); | |
| 91 | + $updated_options['custom_css'] = $custom_css; | |
| 92 | + $updated_options['custom_css_minified'] = $custom_css_minified; | |
| 93 | + } | |
| 94 | + unset( $old_custom_css ); | |
| 95 | + } | |
| 96 | + | |
| 97 | + $result = $tablepress_css->save_custom_css_to_file( $custom_css, $custom_css_minified ); | |
| 129 | 98 | // If saving was successful, use "Custom CSS" file. |
| 130 | 99 | $updated_options['use_custom_css_file'] = $result; |
| 131 | 100 | // Increase the "Custom CSS" version number for cache busting. |
| 132 | 101 | if ( $result ) { |
| @@ -138,17 +107,22 @@ | ||
| 138 | 107 | |
| 139 | 108 | // Clear table caches. |
| 140 | 109 | TablePress::$model_table->invalidate_table_output_caches(); |
| 141 | 110 | |
| 142 | - // Add mime type field to existing posts with the TablePress Custom Post Type, so that other plugins know that they are not dealing with plain text. | |
| 111 | + // Add mime type field to existing posts with the TablePress Custom Post Type, in TablePress 1.5. | |
| 143 | 112 | if ( $current_plugin_options_db_version < 25 ) { |
| 144 | 113 | TablePress::$model_table->add_mime_type_to_posts(); |
| 145 | 114 | } |
| 146 | 115 | |
| 147 | - // Convert old parameter names to new ones in DataTables "Custom Commands". | |
| 148 | - if ( $current_plugin_options_db_version < 26 ) { | |
| 149 | - TablePress::$model_table->convert_datatables_parameter_names_tp15(); | |
| 116 | + // Add new access capabilities that were introduced in TablePress 2.3.2. | |
| 117 | + if ( $current_plugin_options_db_version < 77 ) { | |
| 118 | + TablePress::$model_options->add_access_capabilities_tp232(); | |
| 150 | 119 | } |
| 120 | + | |
| 121 | + // Update all tables' "Custom Commands" to be compatible with DataTables 2, introduced in TablePress 3.0. | |
| 122 | + if ( $current_plugin_options_db_version < 96 ) { | |
| 123 | + TablePress::$model_table->update_custom_commands_datatables_tp30(); | |
| 124 | + } | |
| 151 | 125 | } |
| 152 | 126 | } |
| 153 | 127 | |
| 154 | 128 | // Maybe update the table scheme in each existing table, independently from updating the plugin options. |
| @@ -153,12 +127,9 @@ | ||
| 153 | 127 | |
| 154 | 128 | // Maybe update the table scheme in each existing table, independently from updating the plugin options. |
| 155 | 129 | if ( TablePress::$model_options->get( 'table_scheme_db_version' ) < TablePress::table_scheme_version ) { |
| 156 | 130 | TablePress::$model_table->merge_table_options_defaults(); |
| 157 | - | |
| 158 | - TablePress::$model_options->update( array( | |
| 159 | - 'table_scheme_db_version' => TablePress::table_scheme_version, | |
| 160 | - ) ); | |
| 131 | + TablePress::$model_options->update( 'table_scheme_db_version', TablePress::table_scheme_version ); | |
| 161 | 132 | } |
| 162 | 133 | |
| 163 | 134 | /* |
| 164 | 135 | * Update User Options, if necessary. |
| @@ -163,13 +134,15 @@ | ||
| 163 | 134 | /* |
| 164 | 135 | * Update User Options, if necessary. |
| 165 | 136 | * User Options are not saved in DB until first change occurs. |
| 166 | 137 | */ |
| 167 | - if ( is_user_logged_in() && ( TablePress::$model_options->get( 'user_options_db_version' ) < TablePress::db_version ) ) { | |
| 138 | + if ( is_user_logged_in() && TablePress::$model_options->get( 'user_options_db_version' ) < TablePress::db_version ) { | |
| 168 | 139 | TablePress::$model_options->merge_user_options_defaults(); |
| 169 | - TablePress::$model_options->update( array( | |
| 170 | - 'user_options_db_version' => TablePress::db_version, | |
| 171 | - ) ); | |
| 140 | + $updated_options = array( | |
| 141 | + 'user_options_db_version' => TablePress::db_version, | |
| 142 | + 'message_superseded_extensions' => true, | |
| 143 | + ); | |
| 144 | + TablePress::$model_options->update( $updated_options ); | |
| 172 | 145 | } |
| 173 | 146 | } |
| 174 | 147 | |
| 175 | 148 | } // class TablePress_Controller |