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 | models/model-options.php +61 -14 2.2.1 → 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 /**
@@ -27,9 +29,9 @@
27 29 * @since 1.0.0
28 30 * @since 2.0.0 Added the "modules" option.
29 31 * @var array<string, mixed>
30 32 */
31 - protected $default_plugin_options = array(
33 + protected array $default_plugin_options = array(
32 34 'plugin_options_db_version' => 0,
33 35 'table_scheme_db_version' => 0,
34 36 'prev_tablepress_version' => '0',
35 37 'tablepress_version' => TablePress::version,
@@ -47,16 +49,17 @@
47 49 /**
48 50 * Default User Options.
49 51 *
50 52 * @since 1.0.0
51 - * @var array<string, mixed>>
53 + * @var array<string, mixed>
52 54 */
53 - protected $default_user_options = array(
54 - 'user_options_db_version' => TablePress::db_version, // To prevent saving on first load.
55 - 'admin_menu_parent_page' => 'middle',
56 - 'message_first_visit' => true,
57 - 'table_editor_column_width' => '170', // Default column width of 170px of the table editor on the "Edit" screen.
58 - 'table_editor_line_clamp' => '5', // Maximum number of lines per cell in the table editor on the "Edit" screen.
55 + protected array $default_user_options = array(
56 + 'user_options_db_version' => TablePress::db_version, // To prevent saving on first load.
57 + 'admin_menu_parent_page' => 'middle',
58 + 'message_first_visit' => true,
59 + 'message_superseded_extensions' => true,
60 + 'table_editor_column_width' => '170', // Default column width of 170px of the table editor on the "Edit" screen.
61 + 'table_editor_line_clamp' => '5', // Maximum number of lines per cell in the table editor on the "Edit" screen.
59 62 );
60 63
61 64 /**
62 65 * Instance of WP_Option class for Plugin Options.
@@ -61,19 +64,17 @@
61 64 /**
62 65 * Instance of WP_Option class for Plugin Options.
63 66 *
64 67 * @since 1.0.0
65 - * @var TablePress_WP_Option
66 68 */
67 - protected $plugin_options;
69 + protected \TablePress_WP_Option $plugin_options;
68 70
69 71 /**
70 72 * Instance of WP_User_Option class for User Options.
71 73 *
72 74 * @since 1.0.0
73 - * @var TablePress_WP_User_Option
74 75 */
75 - protected $user_options;
76 + protected \TablePress_WP_User_Option $user_options;
76 77
77 78 /**
78 79 * Init Options Model by creating the object instances for the Plugin and User Options.
79 80 *
@@ -85,8 +86,11 @@
85 86 $params = array(
86 87 'option_name' => 'tablepress_plugin_options',
87 88 'default_value' => $this->default_plugin_options,
88 89 );
90 + if ( strtotime( '2026-10-10' ) >= strtotime( 'today' ) ) {
91 + $params['default_value']['message_plugin_update'] = true;
92 + }
89 93 $this->plugin_options = TablePress::load_class( 'TablePress_WP_Option', 'class-wp_option.php', 'classes', $params );
90 94
91 95 $params = array(
92 96 'option_name' => 'tablepress_user_options',
@@ -113,8 +117,11 @@
113 117 }
114 118
115 119 $plugin_options = $this->plugin_options->get();
116 120 $user_options = $this->user_options->get();
121 +
122 + $old_options = array_merge( $plugin_options, $user_options );
123 +
117 124 foreach ( $new_options as $name => $value ) {
118 125 if ( isset( $this->default_plugin_options[ $name ] ) ) {
119 126 $plugin_options[ $name ] = $value;
120 127 } elseif ( isset( $this->default_user_options[ $name ] ) ) {
@@ -125,8 +132,17 @@
125 132 }
126 133
127 134 $this->plugin_options->update( $plugin_options );
128 135 $this->user_options->update( $user_options );
136 +
137 + /**
138 + * Fires after the options have been saved.
139 + *
140 + * @since 3.1.0
141 + *
142 + * @param array<string, mixed> $old_options Array of all options before the update.
143 + */
144 + do_action( 'tablepress_event_updated_options', $old_options );
129 145 }
130 146
131 147 /**
132 148 * Get the value of a single option, or an array with all options.
@@ -207,9 +223,9 @@
207 223 $this->user_options->update( $user_options );
208 224 }
209 225
210 226 /**
211 - * Add default capabilities to "Administrator", "Editor", and "Author" user roles.
227 + * Adds the TablePress default capabilities to the "Administrator", "Editor", and "Author" user roles.
212 228 *
213 229 * @since 1.0.0
214 230 */
215 231 public function add_access_capabilities(): void {
@@ -240,9 +256,14 @@
240 256 // Capabilities for single roles.
241 257 $role = get_role( 'administrator' );
242 258 if ( ! empty( $role ) ) {
243 259 $role->add_cap( 'tablepress_edit_options' );
260 + $role->add_cap( 'tablepress_import_tables_url' );
244 261 }
262 + $role = get_role( 'editor' );
263 + if ( ! empty( $role ) ) {
264 + $role->add_cap( 'tablepress_import_tables_url' );
265 + }
245 266
246 267 // Refresh current set of capabilities of the user, to be able to directly use the new caps.
247 268 $user = wp_get_current_user();
248 269 $user->get_role_caps();
@@ -248,8 +269,27 @@
248 269 $user->get_role_caps();
249 270 }
250 271
251 272 /**
273 + * Adds a custom "Import from URL" access capability to the "Editor" and "Administrator" user roles.
274 + *
275 + * @since 2.3.2
276 + */
277 + public function add_access_capabilities_tp232(): void {
278 + $roles = array( 'administrator', 'editor' );
279 + foreach ( $roles as $role ) {
280 + $role = get_role( $role );
281 + if ( ! empty( $role ) ) {
282 + $role->add_cap( 'tablepress_import_tables_url' );
283 + }
284 + }
285 +
286 + // Refresh current set of capabilities of the user, to be able to directly use the new caps.
287 + $user = wp_get_current_user();
288 + $user->get_role_caps();
289 + }
290 +
291 + /**
252 292 * Remove all TablePress capabilities from all roles.
253 293 *
254 294 * @since 1.1.0
255 295 *
@@ -297,9 +337,16 @@
297 337 * @param int $user_id User ID for which meta cap is to be checked.
298 338 * @param mixed[] $args Arguments for the check, here e.g. the table ID.
299 339 * @return string[] Modified set of primitive caps.
300 340 */
301 - public function map_tablepress_meta_caps( array $caps, string $cap, int $user_id, array $args ): array {
341 + public function map_tablepress_meta_caps( array $caps, /* string */ $cap, int $user_id, array $args ): array {
342 + // Don't use a type hint for the `$cap` argument as many WordPress plugins seem to be passing `null` to capability check or admin menu functions.
343 +
344 + // Protect against other plugins not supplying a string for the `$cap` argument.
345 + if ( ! is_string( $cap ) ) { // @phpstan-ignore function.alreadyNarrowedType (The `is_string()` check is needed as the input is coming from a filter hook.)
346 + return $caps;
347 + }
348 +
302 349 if ( ! in_array( $cap, array( 'tablepress_edit_table', 'tablepress_edit_table_id', 'tablepress_copy_table', 'tablepress_delete_table', 'tablepress_export_table', 'tablepress_preview_table' ), true ) ) {
303 350 return $caps;
304 351 }
305 352