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 +39 -33 2.2.3 → 3.4 View file →
@@ -7,8 +7,10 @@
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 /**
@@ -21,41 +23,15 @@
21 23 */
22 24 abstract class TablePress_Controller {
23 25
24 26 /**
25 - * File name of the admin screens' parent page in the admin menu.
27 + * Initializes all controllers.
26 28 *
27 29 * @since 1.0.0
28 - * @var string
29 30 */
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 31 public function __construct() {
46 32 // Update check, in all controllers (frontend and admin), to make sure we always have up-to-date options, should be done very early.
47 33 $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 34 }
59 35
60 36 /**
61 37 * Check if the plugin was updated and perform necessary actions, like updating the options.
@@ -91,11 +67,11 @@
91 67 'tablepress_version' => TablePress::version,
92 68 'message_plugin_update' => true,
93 69 );
94 70
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).
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 ) {
98 74 /**
99 75 * Load WP file functions to provide filesystem access functions early.
100 76 */
101 77 require_once ABSPATH . 'wp-admin/includes/file.php';
@@ -103,9 +79,25 @@
103 79 * Load WP admin template functions to provide `submit_button()` which is necessary for `request_filesystem_credentials()`.
104 80 */
105 81 require_once ABSPATH . 'wp-admin/includes/template.php';
106 82 $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' ) );
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 );
108 100 // If saving was successful, use "Custom CSS" file.
109 101 $updated_options['use_custom_css_file'] = $result;
110 102 // Increase the "Custom CSS" version number for cache busting.
111 103 if ( $result ) {
@@ -117,12 +109,22 @@
117 109
118 110 // Clear table caches.
119 111 TablePress::$model_table->invalidate_table_output_caches();
120 112
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.
113 + // Add mime type field to existing posts with the TablePress Custom Post Type, in TablePress 1.5.
122 114 if ( $current_plugin_options_db_version < 25 ) {
123 115 TablePress::$model_table->add_mime_type_to_posts();
124 116 }
117 +
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();
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 + }
125 127 }
126 128 }
127 129
128 130 // Maybe update the table scheme in each existing table, independently from updating the plugin options.
@@ -136,9 +138,13 @@
136 138 * User Options are not saved in DB until first change occurs.
137 139 */
138 140 if ( is_user_logged_in() && TablePress::$model_options->get( 'user_options_db_version' ) < TablePress::db_version ) {
139 141 TablePress::$model_options->merge_user_options_defaults();
140 - TablePress::$model_options->update( 'user_options_db_version', TablePress::db_version );
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 );
141 147 }
142 148 }
143 149
144 150 } // class TablePress_Controller