| @@ -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. |
| @@ -325,9 +341,9 @@ | ||
| 325 | 341 | public function map_tablepress_meta_caps( array $caps, /* string */ $cap, int $user_id, array $args ): array { |
| 326 | 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. |
| 327 | 343 | |
| 328 | 344 | // Protect against other plugins not supplying a string for the `$cap` argument. |
| 329 | - 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.) | |
| 330 | 346 | return $caps; |
| 331 | 347 | } |
| 332 | 348 | |
| 333 | 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 ) ) { |