| Server IP : _ / Your IP : 169.254.129.1 Web Server : nginx/1.28.0 System : Linux 25520b0e8825 6.6.139.1-1.azl3 #1 SMP PREEMPT_DYNAMIC Sun May 17 06:19:38 UTC 2026 x86_64 User : nginx ( 103) PHP Version : 8.2.30 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /var/www/wordpress/wp-content/plugins/posts-table-pro/lib/ |
Upload File : |
<?php
if ( ! class_exists( 'WP_Scoped_Hooks' ) ) {
/**
* Allows a temporary hook environment to be created for a given timeframe (i.e. scope), where any hooks
* added or removed will be recognised only during the specified scope. After the given scope, the
* original WordPress hook environment is restored to its previous state.
*
* @author Barn2 Media <info@barn2.co.uk>
* @license GPL-3.0
* @copyright Barn2 Media Ltd
* @version 1.3
*/
class WP_Scoped_Hooks {
private $hooks;
private $start_hook;
private $end_hook;
public function __construct( $start_hook = '', $end_hook = '' ) {
$this->initialize();
$this->set_scope( $start_hook, $end_hook );
}
private function initialize() {
$this->hooks = array(
'added' => array(),
'removed' => array()
);
if ( $this->start_hook ) {
remove_action( $this->start_hook, array( $this, 'register' ) );
}
if ( $this->end_hook ) {
remove_action( $this->end_hook, array( $this, 'reset' ) );
}
}
public function add_action( $tag, $function, $priority = 10, $accepted_args = 1 ) {
$this->add_filter( $tag, $function, $priority, $accepted_args );
}
public function add_filter( $tag, $function, $priority = 10, $accepted_args = 1 ) {
$this->hooks['added'][] = array( $tag, $function, $priority, $accepted_args );
}
public function remove_action( $tag, $function, $priority = 10, $accepted_args = 1 ) {
$this->remove_filter( $tag, $function, $priority, $accepted_args );
}
public function remove_filter( $tag, $function, $priority = 10, $accepted_args = 1 ) {
$this->hooks['removed'][] = array( $tag, $function, $priority, $accepted_args );
}
public function set_scope( $start_hook, $end_hook ) {
if ( $start_hook && $end_hook ) {
$this->start_hook = $start_hook;
$this->end_hook = $end_hook;
add_action( $start_hook, array( $this, 'register' ) );
add_action( $end_hook, array( $this, 'reset' ) );
}
}
public function register() {
array_walk( $this->hooks['added'], array( $this, 'array_walk_add_filter' ) );
$this->hooks['removed'] = array_filter( $this->hooks['removed'], array( $this, 'array_walk_remove_filter' ) );
}
public function reset() {
array_walk( $this->hooks['added'], array( $this, 'array_walk_remove_filter' ) );
array_walk( $this->hooks['removed'], array( $this, 'array_walk_add_filter' ) );
$this->initialize();
}
private function array_walk_add_filter( $hook ) {
add_filter( $hook[0], $hook[1], $hook[2], $hook[3] );
}
private function array_walk_remove_filter( $hook ) {
return remove_filter( $hook[0], $hook[1], $hook[2], $hook[3] );
}
}
// WP_Scoped_Hooks
}