| @@ -9,8 +9,10 @@ | ||
| 9 | 9 | * @author Tobias Bäthge |
| 10 | 10 | * @since 1.0.0 |
| 11 | 11 | */ |
| 12 | 12 | |
| 13 | +declare(strict_types=1); | |
| 14 | + | |
| 13 | 15 | // Prohibit direct script loading. |
| 14 | 16 | defined( 'ABSPATH' ) || die( 'No direct script access allowed!' ); |
| 15 | 17 | |
| 16 | 18 | // Load parent class. |
| @@ -17,8 +19,9 @@ | ||
| 17 | 19 | TablePress::load_file( 'class-wp_option.php', 'classes' ); |
| 18 | 20 | |
| 19 | 21 | /** |
| 20 | 22 | * TablePress WP User Option Wrapper class |
| 23 | + * | |
| 21 | 24 | * @package TablePress |
| 22 | 25 | * @subpackage Classes |
| 23 | 26 | * @author Tobias Bäthge |
| 24 | 27 | * @since 1.0.0 |
| @@ -33,9 +36,10 @@ | ||
| 33 | 36 | * @param string $option_name Name of the WP User Option. |
| 34 | 37 | * @param mixed $default_value Default value of the WP User Option. |
| 35 | 38 | * @return mixed Current value of the WP User Option, or $default_value if it does not exist. |
| 36 | 39 | */ |
| 37 | - protected function _get_option( $option_name, $default_value ) { | |
| 40 | + #[\Override] | |
| 41 | + protected function _get_option( string $option_name, /* string|int|float|bool|array|null */ $default_value ) /* : string|int|float|bool|array|null */ { | |
| 38 | 42 | // Non-logged-in user can never have a saved option value. |
| 39 | 43 | if ( ! is_user_logged_in() ) { |
| 40 | 44 | return $default_value; |
| 41 | 45 | } |
| @@ -56,9 +60,10 @@ | ||
| 56 | 60 | * @param string $option_name Name of the WP User Option. |
| 57 | 61 | * @param string $new_value New value of the WP User Option (not slashed). |
| 58 | 62 | * @return bool True on success, false on failure. |
| 59 | 63 | */ |
| 60 | - protected function _update_option( $option_name, $new_value ) { | |
| 64 | + #[\Override] | |
| 65 | + protected function _update_option( string $option_name, string $new_value ): bool { | |
| 61 | 66 | // Non-logged-in user can never have a saved option value to be updated. |
| 62 | 67 | if ( ! is_user_logged_in() ) { |
| 63 | 68 | return false; |
| 64 | 69 | } |
| @@ -64,9 +69,9 @@ | ||
| 64 | 69 | } |
| 65 | 70 | |
| 66 | 71 | // WP expects a slashed value. |
| 67 | 72 | $new_value = wp_slash( $new_value ); |
| 68 | - return update_user_option( get_current_user_id(), $option_name, $new_value, false ); | |
| 73 | + return (bool) update_user_option( get_current_user_id(), $option_name, $new_value, false ); | |
| 69 | 74 | } |
| 70 | 75 | |
| 71 | 76 | /** |
| 72 | 77 | * Delete a WP User Option with the WP User Options API. |
| @@ -75,9 +80,10 @@ | ||
| 75 | 80 | * |
| 76 | 81 | * @param string $option_name Name of the WP User Option. |
| 77 | 82 | * @return bool True on success, false on failure. |
| 78 | 83 | */ |
| 79 | - protected function _delete_option( $option_name ) { | |
| 84 | + #[\Override] | |
| 85 | + protected function _delete_option( string $option_name ): bool { | |
| 80 | 86 | // Non-logged-in user can never have a saved option value to be deleted. |
| 81 | 87 | if ( ! is_user_logged_in() ) { |
| 82 | 88 | return false; |
| 83 | 89 | } |
| @@ -89,13 +95,12 @@ | ||
| 89 | 95 | * Delete a WP User Option with the WP User Options API, for all users of the site. |
| 90 | 96 | * |
| 91 | 97 | * @since 1.0.0 |
| 92 | 98 | */ |
| 93 | - public function delete_for_all_users() { | |
| 99 | + public function delete_for_all_users(): void { | |
| 94 | 100 | $users = get_users(); |
| 95 | 101 | foreach ( $users as $user ) { |
| 96 | 102 | delete_user_option( $user->ID, $this->option_name, false ); |
| 97 | - // @TODO: Add other user options for different actions as well. | |
| 98 | 103 | } |
| 99 | 104 | } |
| 100 | 105 | |
| 101 | 106 | } // class TablePress_WP_User_Option |