@@ -51,13 +51,13 @@ function plugin_basename( string $file ): string {
5151 /**
5252 * Register an action callback.
5353 *
54- * @param string $hook Hook name.
55- * @param callable $callback Callback.
56- * @param int $priority Hook priority.
57- * @param int $accepted_args Accepted args.
54+ * @param string $hook Hook name.
55+ * @param callable|string|array{0: object|string, 1: string} $callback Callback.
56+ * @param int $priority Hook priority.
57+ * @param int $accepted_args Accepted args.
5858 * @return bool True.
5959 */
60- function add_action ( string $ hook , callable $ callback , int $ priority = 10 , int $ accepted_args = 1 ): bool {
60+ function add_action ( string $ hook , callable | string | array $ callback , int $ priority = 10 , int $ accepted_args = 1 ): bool {
6161 return add_filter ( $ hook , $ callback , $ priority , $ accepted_args );
6262 }
6363}
@@ -66,13 +66,13 @@ function add_action( string $hook, callable $callback, int $priority = 10, int $
6666 /**
6767 * Register a filter callback.
6868 *
69- * @param string $hook Hook name.
70- * @param callable $callback Callback.
71- * @param int $priority Hook priority.
72- * @param int $accepted_args Accepted args.
69+ * @param string $hook Hook name.
70+ * @param callable|string|array{0: object|string, 1: string} $callback Callback.
71+ * @param int $priority Hook priority.
72+ * @param int $accepted_args Accepted args.
7373 * @return bool True.
7474 */
75- function add_filter ( string $ hook , callable $ callback , int $ priority = 10 , int $ accepted_args = 1 ): bool {
75+ function add_filter ( string $ hook , callable | string | array $ callback , int $ priority = 10 , int $ accepted_args = 1 ): bool {
7676 unset( $ hook , $ callback , $ priority , $ accepted_args );
7777 return true ;
7878 }
@@ -82,9 +82,9 @@ function add_filter( string $hook, callable $callback, int $priority = 10, int $
8282 /**
8383 * Remove an action callback.
8484 *
85- * @param string $hook Hook name.
86- * @param callable|string|array $callback Callback.
87- * @param int $priority Hook priority.
85+ * @param string $hook Hook name.
86+ * @param callable|string|array{0: object|string, 1: string} $callback Callback.
87+ * @param int $priority Hook priority.
8888 * @return bool True.
8989 */
9090 function remove_action ( string $ hook , callable |string |array $ callback , int $ priority = 10 ): bool {
@@ -96,9 +96,9 @@ function remove_action( string $hook, callable|string|array $callback, int $prio
9696 /**
9797 * Remove a filter callback.
9898 *
99- * @param string $hook Hook name.
100- * @param callable|string|array $callback Callback.
101- * @param int $priority Hook priority.
99+ * @param string $hook Hook name.
100+ * @param callable|string|array{0: object|string, 1: string} $callback Callback.
101+ * @param int $priority Hook priority.
102102 * @return bool True.
103103 */
104104 function remove_filter ( string $ hook , callable |string |array $ callback , int $ priority = 10 ): bool {
@@ -111,23 +111,35 @@ function remove_filter( string $hook, callable|string|array $callback, int $prio
111111 /**
112112 * Register activation hook.
113113 *
114- * @param string $file Plugin file.
115- * @param callable $callback Callback.
114+ * @param string $file Plugin file.
115+ * @param callable|string|array{0: object|string, 1: string} $callback Callback.
116116 */
117- function register_activation_hook ( string $ file , callable $ callback ): void {
118- unset( $ file , $ callback );
117+ function register_activation_hook ( string $ file , callable |string |array $ callback ): void {
118+ global $ es_optimizer_test_activation_hooks ;
119+
120+ if ( ! is_array ( $ es_optimizer_test_activation_hooks ) ) {
121+ $ es_optimizer_test_activation_hooks = array ();
122+ }
123+
124+ $ es_optimizer_test_activation_hooks [ $ file ] = $ callback ;
119125 }
120126}
121127
122128if ( ! function_exists ( 'register_deactivation_hook ' ) ) {
123129 /**
124130 * Register deactivation hook.
125131 *
126- * @param string $file Plugin file.
127- * @param callable $callback Callback.
132+ * @param string $file Plugin file.
133+ * @param callable|string|array{0: object|string, 1: string} $callback Callback.
128134 */
129- function register_deactivation_hook ( string $ file , callable $ callback ): void {
130- unset( $ file , $ callback );
135+ function register_deactivation_hook ( string $ file , callable |string |array $ callback ): void {
136+ global $ es_optimizer_test_deactivation_hooks ;
137+
138+ if ( ! is_array ( $ es_optimizer_test_deactivation_hooks ) ) {
139+ $ es_optimizer_test_deactivation_hooks = array ();
140+ }
141+
142+ $ es_optimizer_test_deactivation_hooks [ $ file ] = $ callback ;
131143 }
132144}
133145
@@ -142,34 +154,56 @@ function register_deactivation_hook( string $file, callable $callback ): void {
142154 function get_option ( string $ option , mixed $ default = false ): mixed {
143155 global $ es_optimizer_test_options ;
144156
145- return $ es_optimizer_test_options [ $ option ] ?? $ default ;
157+ if ( ! is_array ( $ es_optimizer_test_options ) ) {
158+ return $ default ;
159+ }
160+
161+ return array_key_exists ( $ option , $ es_optimizer_test_options ) ? $ es_optimizer_test_options [ $ option ] : $ default ;
146162 }
147163}
148164
149165if ( ! function_exists ( 'add_option ' ) ) {
150166 /**
151167 * Add an option to the test option store.
152168 *
153- * @param string $option Option name.
154- * @param mixed $value Option value.
169+ * @param string $option Option name.
170+ * @param mixed $value Option value.
171+ * @param string $deprecated Deprecated description.
172+ * @param bool|string|null $autoload Autoload setting.
155173 * @return bool True.
156174 */
157- function add_option ( string $ option , mixed $ value ): bool {
158- return update_option ( $ option , $ value );
175+ function add_option ( string $ option , mixed $ value = '' , string $ deprecated = '' , bool |string |null $ autoload = null ): bool {
176+ global $ es_optimizer_test_options ;
177+
178+ unset( $ deprecated , $ autoload );
179+
180+ if ( ! is_array ( $ es_optimizer_test_options ) ) {
181+ $ es_optimizer_test_options = array ();
182+ }
183+
184+ if ( array_key_exists ( $ option , $ es_optimizer_test_options ) ) {
185+ return false ;
186+ }
187+
188+ $ es_optimizer_test_options [ $ option ] = $ value ;
189+ return true ;
159190 }
160191}
161192
162193if ( ! function_exists ( 'update_option ' ) ) {
163194 /**
164195 * Update an option in the test option store.
165196 *
166- * @param string $option Option name.
167- * @param mixed $value Option value.
197+ * @param string $option Option name.
198+ * @param mixed $value Option value.
199+ * @param bool|string|null $autoload Autoload setting.
168200 * @return bool True.
169201 */
170- function update_option ( string $ option , mixed $ value ): bool {
202+ function update_option ( string $ option , mixed $ value, bool | string | null $ autoload = null ): bool {
171203 global $ es_optimizer_test_options ;
172204
205+ unset( $ autoload );
206+
173207 if ( ! is_array ( $ es_optimizer_test_options ) ) {
174208 $ es_optimizer_test_options = array ();
175209 }
@@ -189,6 +223,10 @@ function update_option( string $option, mixed $value ): bool {
189223 function delete_option ( string $ option ): bool {
190224 global $ es_optimizer_test_options ;
191225
226+ if ( ! is_array ( $ es_optimizer_test_options ) || ! array_key_exists ( $ option , $ es_optimizer_test_options ) ) {
227+ return false ;
228+ }
229+
192230 unset( $ es_optimizer_test_options [ $ option ] );
193231 return true ;
194232 }
@@ -234,27 +272,35 @@ function sanitize_textarea_field( string $value ): string {
234272 /**
235273 * Strip all HTML tags.
236274 *
237- * @param string $value Value to strip.
275+ * @param string $value Value to strip.
276+ * @param bool $remove_breaks Whether to remove line breaks and whitespace.
238277 * @return string Stripped value.
239278 */
240- function wp_strip_all_tags ( string $ value ): string {
241- return strip_tags ( $ value );
279+ function wp_strip_all_tags ( string $ value , bool $ remove_breaks = false ): string {
280+ $ value = strip_tags ( $ value );
281+
282+ if ( $ remove_breaks ) {
283+ $ value = preg_replace ( '/[\r\n\t ]+/ ' , ' ' , $ value ) ?? $ value ;
284+ }
285+
286+ return trim ( $ value );
242287 }
243288}
244289
245290if ( ! function_exists ( 'esc_url_raw ' ) ) {
246291 /**
247292 * Sanitize a URL for tests.
248293 *
249- * @param string $url URL.
250- * @param array<int, string> $protocols Allowed protocols.
294+ * @param string $url URL.
295+ * @param array<int, string>|null $protocols Allowed protocols.
251296 * @return string Sanitized URL.
252297 */
253- function esc_url_raw ( string $ url , array $ protocols = array () ): string {
254- $ url = trim ( $ url );
255- $ scheme = parse_url ( $ url , PHP_URL_SCHEME );
298+ function esc_url_raw ( string $ url , ?array $ protocols = null ): string {
299+ $ url = trim ( $ url );
300+ $ scheme = parse_url ( $ url , PHP_URL_SCHEME );
301+ $ allowed_protocols = $ protocols ?? array ();
256302
257- if ( ! empty ( $ protocols ) && is_string ( $ scheme ) && ! in_array ( $ scheme , $ protocols , true ) ) {
303+ if ( ! empty ( $ allowed_protocols ) && is_string ( $ scheme ) && ! in_array ( $ scheme , $ allowed_protocols , true ) ) {
258304 return '' ;
259305 }
260306
@@ -266,11 +312,11 @@ function esc_url_raw( string $url, array $protocols = array() ): string {
266312 /**
267313 * Sanitize a URL for tests.
268314 *
269- * @param string $url URL.
270- * @param array<int, string> $protocols Allowed protocols.
315+ * @param string $url URL.
316+ * @param array<int, string>|null $protocols Allowed protocols.
271317 * @return string Sanitized URL.
272318 */
273- function sanitize_url ( string $ url , array $ protocols = array () ): string {
319+ function sanitize_url ( string $ url , ? array $ protocols = null ): string {
274320 return esc_url_raw ( $ url , $ protocols );
275321 }
276322}
@@ -431,10 +477,11 @@ function wp_doing_ajax(): bool {
431477 *
432478 * @param string $hook Hook name.
433479 * @param mixed $value Value.
480+ * @param mixed ...$args Additional filter arguments.
434481 * @return mixed Filtered value.
435482 */
436- function apply_filters ( string $ hook , mixed $ value ): mixed {
437- unset( $ hook );
483+ function apply_filters ( string $ hook , mixed $ value, mixed ... $ args ): mixed {
484+ unset( $ hook, $ args );
438485 return $ value ;
439486 }
440487}
@@ -445,7 +492,7 @@ function apply_filters( string $hook, mixed $value ): mixed {
445492 *
446493 * @return null
447494 */
448- function __return_null () {
495+ function __return_null (): null {
449496 return null ;
450497 }
451498}
0 commit comments