166 /** |
166 /** |
167 * Removes a callback function from a filter hook. |
167 * Removes a callback function from a filter hook. |
168 * |
168 * |
169 * @since 4.7.0 |
169 * @since 4.7.0 |
170 * |
170 * |
171 * @param string $hook_name The filter hook to which the function to be removed is hooked. |
171 * @param string $hook_name The filter hook to which the function to be removed is hooked. |
172 * @param callable $callback The callback to be removed from running when the filter is applied. |
172 * @param callable|string|array $callback The callback to be removed from running when the filter is applied. |
173 * @param int $priority The exact priority used when adding the original filter callback. |
173 * This method can be called unconditionally to speculatively remove |
|
174 * a callback that may or may not exist. |
|
175 * @param int $priority The exact priority used when adding the original filter callback. |
174 * @return bool Whether the callback existed before it was removed. |
176 * @return bool Whether the callback existed before it was removed. |
175 */ |
177 */ |
176 public function remove_filter( $hook_name, $callback, $priority ) { |
178 public function remove_filter( $hook_name, $callback, $priority ) { |
177 $function_key = _wp_filter_build_unique_id( $hook_name, $callback, $priority ); |
179 $function_key = _wp_filter_build_unique_id( $hook_name, $callback, $priority ); |
178 |
180 |
199 * When using the `$callback` argument, this function may return a non-boolean value |
201 * When using the `$callback` argument, this function may return a non-boolean value |
200 * that evaluates to false (e.g. 0), so use the `===` operator for testing the return value. |
202 * that evaluates to false (e.g. 0), so use the `===` operator for testing the return value. |
201 * |
203 * |
202 * @since 4.7.0 |
204 * @since 4.7.0 |
203 * |
205 * |
204 * @param string $hook_name Optional. The name of the filter hook. Default empty. |
206 * @param string $hook_name Optional. The name of the filter hook. Default empty. |
205 * @param callable|false $callback Optional. The callback to check for. Default false. |
207 * @param callable|string|array|false $callback Optional. The callback to check for. |
|
208 * This method can be called unconditionally to speculatively check |
|
209 * a callback that may or may not exist. Default false. |
206 * @return bool|int If `$callback` is omitted, returns boolean for whether the hook has |
210 * @return bool|int If `$callback` is omitted, returns boolean for whether the hook has |
207 * anything registered. When checking a specific function, the priority |
211 * anything registered. When checking a specific function, the priority |
208 * of that hook is returned, or false if the function is not attached. |
212 * of that hook is returned, or false if the function is not attached. |
209 */ |
213 */ |
210 public function has_filter( $hook_name = '', $callback = false ) { |
214 public function has_filter( $hook_name = '', $callback = false ) { |
435 * @link https://www.php.net/manual/en/arrayaccess.offsetexists.php |
439 * @link https://www.php.net/manual/en/arrayaccess.offsetexists.php |
436 * |
440 * |
437 * @param mixed $offset An offset to check for. |
441 * @param mixed $offset An offset to check for. |
438 * @return bool True if the offset exists, false otherwise. |
442 * @return bool True if the offset exists, false otherwise. |
439 */ |
443 */ |
|
444 #[ReturnTypeWillChange] |
440 public function offsetExists( $offset ) { |
445 public function offsetExists( $offset ) { |
441 return isset( $this->callbacks[ $offset ] ); |
446 return isset( $this->callbacks[ $offset ] ); |
442 } |
447 } |
443 |
448 |
444 /** |
449 /** |
449 * @link https://www.php.net/manual/en/arrayaccess.offsetget.php |
454 * @link https://www.php.net/manual/en/arrayaccess.offsetget.php |
450 * |
455 * |
451 * @param mixed $offset The offset to retrieve. |
456 * @param mixed $offset The offset to retrieve. |
452 * @return mixed If set, the value at the specified offset, null otherwise. |
457 * @return mixed If set, the value at the specified offset, null otherwise. |
453 */ |
458 */ |
|
459 #[ReturnTypeWillChange] |
454 public function offsetGet( $offset ) { |
460 public function offsetGet( $offset ) { |
455 return isset( $this->callbacks[ $offset ] ) ? $this->callbacks[ $offset ] : null; |
461 return isset( $this->callbacks[ $offset ] ) ? $this->callbacks[ $offset ] : null; |
456 } |
462 } |
457 |
463 |
458 /** |
464 /** |
463 * @link https://www.php.net/manual/en/arrayaccess.offsetset.php |
469 * @link https://www.php.net/manual/en/arrayaccess.offsetset.php |
464 * |
470 * |
465 * @param mixed $offset The offset to assign the value to. |
471 * @param mixed $offset The offset to assign the value to. |
466 * @param mixed $value The value to set. |
472 * @param mixed $value The value to set. |
467 */ |
473 */ |
|
474 #[ReturnTypeWillChange] |
468 public function offsetSet( $offset, $value ) { |
475 public function offsetSet( $offset, $value ) { |
469 if ( is_null( $offset ) ) { |
476 if ( is_null( $offset ) ) { |
470 $this->callbacks[] = $value; |
477 $this->callbacks[] = $value; |
471 } else { |
478 } else { |
472 $this->callbacks[ $offset ] = $value; |
479 $this->callbacks[ $offset ] = $value; |
519 * |
529 * |
520 * @link https://www.php.net/manual/en/iterator.key.php |
530 * @link https://www.php.net/manual/en/iterator.key.php |
521 * |
531 * |
522 * @return mixed Returns current priority on success, or NULL on failure |
532 * @return mixed Returns current priority on success, or NULL on failure |
523 */ |
533 */ |
|
534 #[ReturnTypeWillChange] |
524 public function key() { |
535 public function key() { |
525 return key( $this->callbacks ); |
536 return key( $this->callbacks ); |
526 } |
537 } |
527 |
538 |
528 /** |
539 /** |