PluginProbe
TablePress – Tables in WordPress made easy / 3.4
TablePress – Tables in WordPress made easy v3.4
3.4 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 All 45 releases
← All changes | classes/class-wp_option.php +18 -17 2.0.4 → 3.4 View file →
@@ -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 /**
@@ -26,19 +28,18 @@
26 28 /**
27 29 * Name/Key of the Option (in its location in the database).
28 30 *
29 31 * @since 1.0.0
30 - * @var string
31 32 */
32 - protected $option_name;
33 + protected string $option_name;
33 34
34 35 /**
35 36 * Current value of the option.
36 37 *
37 38 * @since 1.0.0
38 - * @var array
39 + * @var mixed[]
39 40 */
40 - protected $option_value;
41 + protected array $option_value;
41 42
42 43 /**
43 44 * Initialize with Option Name.
44 45 *
@@ -43,9 +44,9 @@
43 44 * Initialize with Option Name.
44 45 *
45 46 * @since 1.0.0
46 47 *
47 - * @param array $params {
48 + * @param array{option_name: string, default_value: mixed[]} $params {
48 49 * An array of Option parameters.
49 50 *
50 51 * @type string $option_name Name of the Option.
51 52 * @type array $default_value Default values for the Option, as an array.
@@ -69,9 +70,9 @@
69 70 *
70 71 * @param string $name Name of the option to check.
71 72 * @return bool Whether the option is set.
72 73 */
73 - public function is_set( $name ) {
74 + public function is_set( string $name ): bool {
74 75 return isset( $this->option_value[ $name ] );
75 76 }
76 77
77 78 /**
@@ -78,13 +79,13 @@
78 79 * Get a single Option, or get all Options.
79 80 *
80 81 * @since 1.0.0
81 82 *
82 - * @param string|bool $name Optional. Name of a single option to get, or false for all options.
83 - * @param mixed $default_value Optional. Default value to return, if a single option $name does not exist.
84 - * @return mixed|array Value of the retrieved option $name or $default_value if it does not exist, or all options.
83 + * @param string|false $name Optional. Name of a single option to get, or false for all options.
84 + * @param mixed $default_value Optional. Default value to return, if a single option $name does not exist.
85 + * @return mixed Value of the retrieved option $name or $default_value if it does not exist, or all options.
85 86 */
86 - public function get( $name = false, $default_value = null ) {
87 + public function get( /* string|false */ $name = false, /* string|int|float|bool|array|null */ $default_value = null ) /* : string|int|float|bool|array|null */ {
87 88 if ( false === $name ) {
88 89 return $this->option_value;
89 90 }
90 91
@@ -100,14 +101,14 @@
100 101 * Update Option.
101 102 *
102 103 * @since 1.0.0
103 104 *
104 - * @param array $new_options New options (name => value).
105 + * @param array<string, mixed> $new_options New options (name => value).
105 106 * @return bool True on success, false on failure.
106 107 */
107 - public function update( array $new_options ) {
108 + public function update( array $new_options ): bool {
108 109 $this->option_value = $new_options;
109 - return $this->_update_option( $this->option_name, wp_json_encode( $this->option_value, TABLEPRESS_JSON_OPTIONS ) );
110 + return $this->_update_option( $this->option_name, wp_json_encode( $this->option_value, TABLEPRESS_JSON_OPTIONS ) ); // @phpstan-ignore argument.type
110 111 }
111 112
112 113 /**
113 114 * Delete Option.
@@ -115,9 +116,9 @@
115 116 * @since 1.0.0
116 117 *
117 118 * @return bool True on success, false on failure.
118 119 */
119 - public function delete() {
120 + public function delete(): bool {
120 121 return $this->_delete_option( $this->option_name );
121 122 }
122 123
123 124 /*
@@ -132,9 +133,9 @@
132 133 * @param string $option_name Name of the WP Option.
133 134 * @param mixed $default_value Default value of the WP Option.
134 135 * @return mixed Current value of the WP Option, or $default_value if it does not exist.
135 136 */
136 - protected function _get_option( $option_name, $default_value ) {
137 + protected function _get_option( string $option_name, /* string|int|float|bool|array|null */ $default_value ) /* : string|int|float|bool|array|null */ {
137 138 return get_option( $option_name, $default_value );
138 139 }
139 140
140 141 /**
@@ -145,9 +146,9 @@
145 146 * @param string $option_name Name of the WP Option.
146 147 * @param string $new_value New value of the WP Option.
147 148 * @return bool True on success, false on failure.
148 149 */
149 - protected function _update_option( $option_name, $new_value ) {
150 + protected function _update_option( string $option_name, string $new_value ): bool {
150 151 return update_option( $option_name, $new_value );
151 152 }
152 153
153 154 /**
@@ -157,9 +158,9 @@
157 158 *
158 159 * @param string $option_name Name of the WP Option.
159 160 * @return bool True on success, false on failure.
160 161 */
161 - protected function _delete_option( $option_name ) {
162 + protected function _delete_option( string $option_name ): bool {
162 163 return delete_option( $option_name );
163 164 }
164 165
165 166 } // class TablePress_WP_Option