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 | classes/class-controller.php +45 -69 1.12 → 3.4 View file →
@@ -7,13 +7,16 @@
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 /**
15 17 * Base Controller class
18 + *
16 19 * @package TablePress
17 20 * @subpackage Controllers
18 21 * @author Tobias Bäthge
19 22 * @since 1.0.0
@@ -20,64 +23,15 @@
20 23 */
21 24 abstract class TablePress_Controller {
22 25
23 26 /**
24 - * Instance of the Options Model.
27 + * Initializes all controllers.
25 28 *
26 29 * @since 1.0.0
27 - * @var TablePress_Options_Model
28 30 */
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 31 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 32 // Update check, in all controllers (frontend and admin), to make sure we always have up-to-date options, should be done very early.
69 33 $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 34 }
81 35
82 36 /**
83 37 * Check if the plugin was updated and perform necessary actions, like updating the options.
@@ -83,14 +37,16 @@
83 37 * Check if the plugin was updated and perform necessary actions, like updating the options.
84 38 *
85 39 * @since 1.0.0
86 40 */
87 - protected function plugin_update_check() {
41 + protected function plugin_update_check(): void {
88 42 // First activation or plugin update.
89 43 $current_plugin_options_db_version = TablePress::$model_options->get( 'plugin_options_db_version' );
90 44 if ( $current_plugin_options_db_version < TablePress::db_version ) {
91 45 // Allow more PHP execution time for update process.
92 - @set_time_limit( 300 );
46 + if ( function_exists( 'set_time_limit' ) ) {
47 + @set_time_limit( 300 ); // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged
48 + }
93 49
94 50 // Add TablePress capabilities to the WP_Roles objects, for new installations and all versions below 12.
95 51 if ( $current_plugin_options_db_version < 12 ) {
96 52 TablePress::$model_options->add_access_capabilities();
@@ -98,9 +54,9 @@
98 54
99 55 if ( 0 === TablePress::$model_options->get( 'first_activation' ) ) {
100 56 // Save initial set of plugin options, and time of first activation of the plugin, on first activation.
101 57 TablePress::$model_options->update( array(
102 - 'first_activation' => current_time( 'timestamp' ),
58 + 'first_activation' => time(),
103 59 'plugin_options_db_version' => TablePress::db_version,
104 60 ) );
105 61 } else {
106 62 // Update Plugin Options Options, if necessary.
@@ -111,11 +67,11 @@
111 67 'tablepress_version' => TablePress::version,
112 68 'message_plugin_update' => true,
113 69 );
114 70
115 - // Only write files, if "Custom CSS" is to be used, and if there is "Custom CSS".
116 - if ( TablePress::$model_options->get( 'use_custom_css' ) && '' !== TablePress::$model_options->get( 'custom_css' ) ) {
117 - // Re-save "Custom CSS" to re-create all files (as TablePress Default CSS might have changed).
71 + // If used, re-save "Custom CSS" to re-create all files (as TablePress Default CSS might have changed).
72 + $custom_css = TablePress::$model_options->get( 'custom_css' );
73 + if ( TablePress::$model_options->get( 'use_custom_css' ) && '' !== $custom_css ) {
118 74 /**
119 75 * Load WP file functions to provide filesystem access functions early.
120 76 */
121 77 require_once ABSPATH . 'wp-admin/includes/file.php';
@@ -123,9 +79,25 @@
123 79 * Load WP admin template functions to provide `submit_button()` which is necessary for `request_filesystem_credentials()`.
124 80 */
125 81 require_once ABSPATH . 'wp-admin/includes/template.php';
126 82 $tablepress_css = TablePress::load_class( 'TablePress_CSS', 'class-css.php', 'classes' );
127 - $result = $tablepress_css->save_custom_css_to_file( TablePress::$model_options->get( 'custom_css' ), TablePress::$model_options->get( 'custom_css_minified' ) );
83 +
84 + $custom_css_minified = TablePress::$model_options->get( 'custom_css_minified' );
85 +
86 + // Update "Custom CSS" to be compatible with DataTables 2, introduced in TablePress 3.0.
87 + if ( $current_plugin_options_db_version < 96 ) {
88 + $old_custom_css = $custom_css;
89 + $custom_css = TablePress::convert_datatables_api_data( $custom_css );
90 + if ( $old_custom_css !== $custom_css ) {
91 + $custom_css = $tablepress_css->sanitize_css( $custom_css );
92 + $custom_css_minified = $tablepress_css->minify_css( $custom_css );
93 + $updated_options['custom_css'] = $custom_css;
94 + $updated_options['custom_css_minified'] = $custom_css_minified;
95 + }
96 + unset( $old_custom_css );
97 + }
98 +
99 + $result = $tablepress_css->save_custom_css_to_file( $custom_css, $custom_css_minified );
128 100 // If saving was successful, use "Custom CSS" file.
129 101 $updated_options['use_custom_css_file'] = $result;
130 102 // Increase the "Custom CSS" version number for cache busting.
131 103 if ( $result ) {
@@ -137,17 +109,22 @@
137 109
138 110 // Clear table caches.
139 111 TablePress::$model_table->invalidate_table_output_caches();
140 112
141 - // 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.
113 + // Add mime type field to existing posts with the TablePress Custom Post Type, in TablePress 1.5.
142 114 if ( $current_plugin_options_db_version < 25 ) {
143 115 TablePress::$model_table->add_mime_type_to_posts();
144 116 }
145 117
146 - // Convert old parameter names to new ones in DataTables "Custom Commands".
147 - if ( $current_plugin_options_db_version < 26 ) {
148 - TablePress::$model_table->convert_datatables_parameter_names_tp15();
118 + // Add new access capabilities that were introduced in TablePress 2.3.2.
119 + if ( $current_plugin_options_db_version < 77 ) {
120 + TablePress::$model_options->add_access_capabilities_tp232();
149 121 }
122 +
123 + // Update all tables' "Custom Commands" to be compatible with DataTables 2, introduced in TablePress 3.0.
124 + if ( $current_plugin_options_db_version < 96 ) {
125 + TablePress::$model_table->update_custom_commands_datatables_tp30();
126 + }
150 127 }
151 128 }
152 129
153 130 // Maybe update the table scheme in each existing table, independently from updating the plugin options.
@@ -152,12 +129,9 @@
152 129
153 130 // Maybe update the table scheme in each existing table, independently from updating the plugin options.
154 131 if ( TablePress::$model_options->get( 'table_scheme_db_version' ) < TablePress::table_scheme_version ) {
155 132 TablePress::$model_table->merge_table_options_defaults();
156 -
157 - TablePress::$model_options->update( array(
158 - 'table_scheme_db_version' => TablePress::table_scheme_version,
159 - ) );
133 + TablePress::$model_options->update( 'table_scheme_db_version', TablePress::table_scheme_version );
160 134 }
161 135
162 136 /*
163 137 * Update User Options, if necessary.
@@ -162,13 +136,15 @@
162 136 /*
163 137 * Update User Options, if necessary.
164 138 * User Options are not saved in DB until first change occurs.
165 139 */
166 - if ( is_user_logged_in() && ( TablePress::$model_options->get( 'user_options_db_version' ) < TablePress::db_version ) ) {
140 + if ( is_user_logged_in() && TablePress::$model_options->get( 'user_options_db_version' ) < TablePress::db_version ) {
167 141 TablePress::$model_options->merge_user_options_defaults();
168 - TablePress::$model_options->update( array(
169 - 'user_options_db_version' => TablePress::db_version,
170 - ) );
142 + $updated_options = array(
143 + 'user_options_db_version' => TablePress::db_version,
144 + 'message_superseded_extensions' => true,
145 + );
146 + TablePress::$model_options->update( $updated_options );
171 147 }
172 148 }
173 149
174 150 } // class TablePress_Controller