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 +49 -14 2.33.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.
@@ -207,9 +218,9 @@
207 218 $this->user_options->update( $user_options );
208 219 }
209 220
210 221 /**
211 - * Add default capabilities to "Administrator", "Editor", and "Author" user roles.
222 + * Adds the TablePress default capabilities to the "Administrator", "Editor", and "Author" user roles.
212 223 *
213 224 * @since 1.0.0
214 225 */
215 226 public function add_access_capabilities(): void {
@@ -240,9 +251,14 @@
240 251 // Capabilities for single roles.
241 252 $role = get_role( 'administrator' );
242 253 if ( ! empty( $role ) ) {
243 254 $role->add_cap( 'tablepress_edit_options' );
255 + $role->add_cap( 'tablepress_import_tables_url' );
244 256 }
257 + $role = get_role( 'editor' );
258 + if ( ! empty( $role ) ) {
259 + $role->add_cap( 'tablepress_import_tables_url' );
260 + }
245 261
246 262 // Refresh current set of capabilities of the user, to be able to directly use the new caps.
247 263 $user = wp_get_current_user();
248 264 $user->get_role_caps();
@@ -248,8 +264,27 @@
248 264 $user->get_role_caps();
249 265 }
250 266
251 267 /**
268 + * Adds a custom "Import from URL" access capability to the "Editor" and "Administrator" user roles.
269 + *
270 + * @since 2.3.2
271 + */
272 + public function add_access_capabilities_tp232(): void {
273 + $roles = array( 'administrator', 'editor' );
274 + foreach ( $roles as $role ) {
275 + $role = get_role( $role );
276 + if ( ! empty( $role ) ) {
277 + $role->add_cap( 'tablepress_import_tables_url' );
278 + }
279 + }
280 +
281 + // Refresh current set of capabilities of the user, to be able to directly use the new caps.
282 + $user = wp_get_current_user();
283 + $user->get_role_caps();
284 + }
285 +
286 + /**
252 287 * Remove all TablePress capabilities from all roles.
253 288 *
254 289 * @since 1.1.0
255 290 *
@@ -301,9 +336,9 @@
301 336 public function map_tablepress_meta_caps( array $caps, /* string */ $cap, int $user_id, array $args ): array {
302 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.
303 338
304 339 // Protect against other plugins not supplying a string for the `$cap` argument.
305 - 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.)
306 341 return $caps;
307 342 }
308 343
309 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 ) ) {