PluginProbe
TablePress – Tables in WordPress made easy / 3.0
TablePress – Tables in WordPress made easy v3.0
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 +44 -14 2.23.0 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 *
@@ -207,9 +206,9 @@
207 206 $this->user_options->update( $user_options );
208 207 }
209 208
210 209 /**
211 - * Add default capabilities to "Administrator", "Editor", and "Author" user roles.
210 + * Adds the TablePress default capabilities to the "Administrator", "Editor", and "Author" user roles.
212 211 *
213 212 * @since 1.0.0
214 213 */
215 214 public function add_access_capabilities(): void {
@@ -240,9 +239,14 @@
240 239 // Capabilities for single roles.
241 240 $role = get_role( 'administrator' );
242 241 if ( ! empty( $role ) ) {
243 242 $role->add_cap( 'tablepress_edit_options' );
243 + $role->add_cap( 'tablepress_import_tables_url' );
244 244 }
245 + $role = get_role( 'editor' );
246 + if ( ! empty( $role ) ) {
247 + $role->add_cap( 'tablepress_import_tables_url' );
248 + }
245 249
246 250 // Refresh current set of capabilities of the user, to be able to directly use the new caps.
247 251 $user = wp_get_current_user();
248 252 $user->get_role_caps();
@@ -248,8 +252,27 @@
248 252 $user->get_role_caps();
249 253 }
250 254
251 255 /**
256 + * Adds a custom "Import from URL" access capability to the "Editor" and "Administrator" user roles.
257 + *
258 + * @since 2.3.2
259 + */
260 + public function add_access_capabilities_tp232(): void {
261 + $roles = array( 'administrator', 'editor' );
262 + foreach ( $roles as $role ) {
263 + $role = get_role( $role );
264 + if ( ! empty( $role ) ) {
265 + $role->add_cap( 'tablepress_import_tables_url' );
266 + }
267 + }
268 +
269 + // Refresh current set of capabilities of the user, to be able to directly use the new caps.
270 + $user = wp_get_current_user();
271 + $user->get_role_caps();
272 + }
273 +
274 + /**
252 275 * Remove all TablePress capabilities from all roles.
253 276 *
254 277 * @since 1.1.0
255 278 *
@@ -297,9 +320,16 @@
297 320 * @param int $user_id User ID for which meta cap is to be checked.
298 321 * @param mixed[] $args Arguments for the check, here e.g. the table ID.
299 322 * @return string[] Modified set of primitive caps.
300 323 */
301 - public function map_tablepress_meta_caps( array $caps, string $cap, int $user_id, array $args ): array {
324 + public function map_tablepress_meta_caps( array $caps, /* string */ $cap, int $user_id, array $args ): array {
325 + // 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.
326 +
327 + // Protect against other plugins not supplying a string for the `$cap` argument.
328 + if ( ! is_string( $cap ) ) { // @phpstan-ignore function.alreadyNarrowedType (The `is_string()` check is needed as the input is coming from a filter hook.)
329 + return $caps;
330 + }
331 +
302 332 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 333 return $caps;
304 334 }
305 335