PluginProbe
TablePress – Tables in WordPress made easy / 3.2
TablePress – Tables in WordPress made easy v3.2
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 2.4.4 All 44 releases
← All changes | models/model-options.php +24 -13 2.3.23.2 View file →
@@ -27,9 +27,9 @@
27 27 * @since 1.0.0
28 28 * @since 2.0.0 Added the "modules" option.
29 29 * @var array<string, mixed>
30 30 */
31 - protected $default_plugin_options = array(
31 + protected array $default_plugin_options = array(
32 32 'plugin_options_db_version' => 0,
33 33 'table_scheme_db_version' => 0,
34 34 'prev_tablepress_version' => '0',
35 35 'tablepress_version' => TablePress::version,
@@ -47,16 +47,17 @@
47 47 /**
48 48 * Default User Options.
49 49 *
50 50 * @since 1.0.0
51 - * @var array<string, mixed>>
51 + * @var array<string, mixed>
52 52 */
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.
53 + protected array $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 + 'message_superseded_extensions' => true,
58 + 'table_editor_column_width' => '170', // Default column width of 170px of the table editor on the "Edit" screen.
59 + 'table_editor_line_clamp' => '5', // Maximum number of lines per cell in the table editor on the "Edit" screen.
59 60 );
60 61
61 62 /**
62 63 * Instance of WP_Option class for Plugin Options.
@@ -61,19 +62,17 @@
61 62 /**
62 63 * Instance of WP_Option class for Plugin Options.
63 64 *
64 65 * @since 1.0.0
65 - * @var TablePress_WP_Option
66 66 */
67 - protected $plugin_options;
67 + protected \TablePress_WP_Option $plugin_options;
68 68
69 69 /**
70 70 * Instance of WP_User_Option class for User Options.
71 71 *
72 72 * @since 1.0.0
73 - * @var TablePress_WP_User_Option
74 73 */
75 - protected $user_options;
74 + protected \TablePress_WP_User_Option $user_options;
76 75
77 76 /**
78 77 * Init Options Model by creating the object instances for the Plugin and User Options.
79 78 *
@@ -113,8 +112,11 @@
113 112 }
114 113
115 114 $plugin_options = $this->plugin_options->get();
116 115 $user_options = $this->user_options->get();
116 +
117 + $old_options = array_merge( $plugin_options, $user_options );
118 +
117 119 foreach ( $new_options as $name => $value ) {
118 120 if ( isset( $this->default_plugin_options[ $name ] ) ) {
119 121 $plugin_options[ $name ] = $value;
120 122 } elseif ( isset( $this->default_user_options[ $name ] ) ) {
@@ -125,8 +127,17 @@
125 127 }
126 128
127 129 $this->plugin_options->update( $plugin_options );
128 130 $this->user_options->update( $user_options );
131 +
132 + /**
133 + * Fires after the options have been saved.
134 + *
135 + * @since 3.1.0
136 + *
137 + * @param array<string, mixed> $old_options Array of all options before the update.
138 + */
139 + do_action( 'tablepress_event_updated_options', $old_options );
129 140 }
130 141
131 142 /**
132 143 * Get the value of a single option, or an array with all options.
@@ -325,9 +336,9 @@
325 336 public function map_tablepress_meta_caps( array $caps, /* string */ $cap, int $user_id, array $args ): array {
326 337 // 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.
327 338
328 339 // Protect against other plugins not supplying a string for the `$cap` argument.
329 - if ( ! is_string( $cap ) ) {
340 + if ( ! is_string( $cap ) ) { // @phpstan-ignore function.alreadyNarrowedType (The `is_string()` check is needed as the input is coming from a filter hook.)
330 341 return $caps;
331 342 }
332 343
333 344 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 ) ) {