| @@ -21,41 +21,15 @@ | ||
| 21 | 21 | */ |
| 22 | 22 | abstract class TablePress_Controller { |
| 23 | 23 | |
| 24 | 24 | /** |
| 25 | - * File name of the admin screens' parent page in the admin menu. | |
| 25 | + * Initializes all controllers. | |
| 26 | 26 | * |
| 27 | 27 | * @since 1.0.0 |
| 28 | - * @var string | |
| 29 | 28 | */ |
| 30 | - public $parent_page = 'middle'; | |
| 31 | - | |
| 32 | - /** | |
| 33 | - * Whether TablePress admin screens are a top-level menu item in the admin menu. | |
| 34 | - * | |
| 35 | - * @since 1.0.0 | |
| 36 | - * @var bool | |
| 37 | - */ | |
| 38 | - public $is_top_level_page = false; | |
| 39 | - | |
| 40 | - /** | |
| 41 | - * Initialize all controllers, by loading Plugin and User Options, and by performing an update check. | |
| 42 | - * | |
| 43 | - * @since 1.0.0 | |
| 44 | - */ | |
| 45 | 29 | public function __construct() { |
| 46 | 30 | // Update check, in all controllers (frontend and admin), to make sure we always have up-to-date options, should be done very early. |
| 47 | 31 | $this->plugin_update_check(); |
| 48 | - | |
| 49 | - /** | |
| 50 | - * Filters the admin menu parent page, which is needed for the construction of plugin URLs. | |
| 51 | - * | |
| 52 | - * @since 1.0.0 | |
| 53 | - * | |
| 54 | - * @param string $parent_page Current admin menu parent page. | |
| 55 | - */ | |
| 56 | - $this->parent_page = apply_filters( 'tablepress_admin_menu_parent_page', TablePress::$model_options->get( 'admin_menu_parent_page' ) ); | |
| 57 | - $this->is_top_level_page = in_array( $this->parent_page, array( 'top', 'middle', 'bottom' ), true ); | |
| 58 | 32 | } |
| 59 | 33 | |
| 60 | 34 | /** |
| 61 | 35 | * Check if the plugin was updated and perform necessary actions, like updating the options. |
| @@ -91,21 +65,37 @@ | ||
| 91 | 65 | 'tablepress_version' => TablePress::version, |
| 92 | 66 | 'message_plugin_update' => true, |
| 93 | 67 | ); |
| 94 | 68 | |
| 95 | - // Only write files, if "Custom CSS" is to be used, and if there is "Custom CSS". | |
| 96 | - if ( TablePress::$model_options->get( 'use_custom_css' ) && '' !== TablePress::$model_options->get( 'custom_css' ) ) { | |
| 97 | - // 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 ) { | |
| 98 | 72 | /** |
| 99 | 73 | * Load WP file functions to provide filesystem access functions early. |
| 100 | 74 | */ |
| 101 | - 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.) | |
| 102 | 76 | /** |
| 103 | 77 | * Load WP admin template functions to provide `submit_button()` which is necessary for `request_filesystem_credentials()`. |
| 104 | 78 | */ |
| 105 | - 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.) | |
| 106 | 80 | $tablepress_css = TablePress::load_class( 'TablePress_CSS', 'class-css.php', 'classes' ); |
| 107 | - $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 ); | |
| 108 | 98 | // If saving was successful, use "Custom CSS" file. |
| 109 | 99 | $updated_options['use_custom_css_file'] = $result; |
| 110 | 100 | // Increase the "Custom CSS" version number for cache busting. |
| 111 | 101 | if ( $result ) { |
| @@ -117,12 +107,22 @@ | ||
| 117 | 107 | |
| 118 | 108 | // Clear table caches. |
| 119 | 109 | TablePress::$model_table->invalidate_table_output_caches(); |
| 120 | 110 | |
| 121 | - // 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. | |
| 122 | 112 | if ( $current_plugin_options_db_version < 25 ) { |
| 123 | 113 | TablePress::$model_table->add_mime_type_to_posts(); |
| 124 | 114 | } |
| 115 | + | |
| 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(); | |
| 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 | + } | |
| 125 | 125 | } |
| 126 | 126 | } |
| 127 | 127 | |
| 128 | 128 | // Maybe update the table scheme in each existing table, independently from updating the plugin options. |
| @@ -136,9 +136,13 @@ | ||
| 136 | 136 | * User Options are not saved in DB until first change occurs. |
| 137 | 137 | */ |
| 138 | 138 | if ( is_user_logged_in() && TablePress::$model_options->get( 'user_options_db_version' ) < TablePress::db_version ) { |
| 139 | 139 | TablePress::$model_options->merge_user_options_defaults(); |
| 140 | - TablePress::$model_options->update( 'user_options_db_version', TablePress::db_version ); | |
| 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 ); | |
| 141 | 145 | } |
| 142 | 146 | } |
| 143 | 147 | |
| 144 | 148 | } // class TablePress_Controller |