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 +23 -8 2.4 → 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,11 +49,11 @@
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(
55 + protected array $default_user_options = array(
54 56 'user_options_db_version' => TablePress::db_version, // To prevent saving on first load.
55 57 'admin_menu_parent_page' => 'middle',
56 58 'message_first_visit' => true,
57 59 'message_superseded_extensions' => true,
@@ -62,19 +64,17 @@
62 64 /**
63 65 * Instance of WP_Option class for Plugin Options.
64 66 *
65 67 * @since 1.0.0
66 - * @var TablePress_WP_Option
67 68 */
68 - protected $plugin_options;
69 + protected \TablePress_WP_Option $plugin_options;
69 70
70 71 /**
71 72 * Instance of WP_User_Option class for User Options.
72 73 *
73 74 * @since 1.0.0
74 - * @var TablePress_WP_User_Option
75 75 */
76 - protected $user_options;
76 + protected \TablePress_WP_User_Option $user_options;
77 77
78 78 /**
79 79 * Init Options Model by creating the object instances for the Plugin and User Options.
80 80 *
@@ -86,8 +86,11 @@
86 86 $params = array(
87 87 'option_name' => 'tablepress_plugin_options',
88 88 'default_value' => $this->default_plugin_options,
89 89 );
90 + if ( strtotime( '2026-10-10' ) >= strtotime( 'today' ) ) {
91 + $params['default_value']['message_plugin_update'] = true;
92 + }
90 93 $this->plugin_options = TablePress::load_class( 'TablePress_WP_Option', 'class-wp_option.php', 'classes', $params );
91 94
92 95 $params = array(
93 96 'option_name' => 'tablepress_user_options',
@@ -114,8 +117,11 @@
114 117 }
115 118
116 119 $plugin_options = $this->plugin_options->get();
117 120 $user_options = $this->user_options->get();
121 +
122 + $old_options = array_merge( $plugin_options, $user_options );
123 +
118 124 foreach ( $new_options as $name => $value ) {
119 125 if ( isset( $this->default_plugin_options[ $name ] ) ) {
120 126 $plugin_options[ $name ] = $value;
121 127 } elseif ( isset( $this->default_user_options[ $name ] ) ) {
@@ -126,8 +132,17 @@
126 132 }
127 133
128 134 $this->plugin_options->update( $plugin_options );
129 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 );
130 145 }
131 146
132 147 /**
133 148 * Get the value of a single option, or an array with all options.
@@ -326,9 +341,9 @@
326 341 public function map_tablepress_meta_caps( array $caps, /* string */ $cap, int $user_id, array $args ): array {
327 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.
328 343
329 344 // Protect against other plugins not supplying a string for the `$cap` argument.
330 - if ( ! is_string( $cap ) ) {
345 + if ( ! is_string( $cap ) ) { // @phpstan-ignore function.alreadyNarrowedType (The `is_string()` check is needed as the input is coming from a filter hook.)
331 346 return $caps;
332 347 }
333 348
334 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 ) ) {