public function test_array_to_hooks() { $tag1 = rand_str(); $priority1 = rand(1, 100); $tag2 = rand_str(); $priority2 = rand(1, 100); $filters = array($tag1 => array($priority1 => array('test1' => array('function' => '__return_false', 'accepted_args' => 2))), $tag2 => array($priority2 => array('test1' => array('function' => '__return_null', 'accepted_args' => 1)))); $hooks = WP_Hook::build_preinitialized_hooks($filters); $this->assertEquals($priority1, $hooks[$tag1]->has_filter($tag1, '__return_false')); $this->assertEquals($priority2, $hooks[$tag2]->has_filter($tag2, '__return_null')); }
* * Also see the {@link https://codex.wordpress.org/Plugin_API Plugin API} for * more information and examples on how to use a lot of these functions. * * This file should have no external dependencies. * * @package WordPress * @subpackage Plugin * @since 1.5.0 */ // Initialize the filter globals. require dirname(__FILE__) . '/class-wp-hook.php'; /** @var WP_Hook[] $wp_filter */ global $wp_filter, $wp_actions, $wp_current_filter; if ($wp_filter) { $wp_filter = WP_Hook::build_preinitialized_hooks($wp_filter); } else { $wp_filter = array(); } if (!isset($wp_actions)) { $wp_actions = array(); } if (!isset($wp_current_filter)) { $wp_current_filter = array(); } /** * Hook a function or method to a specific filter action. * * WordPress offers filter hooks to allow plugins to modify * various types of internal data at runtime. *
/** * Start the WordPress object cache. * * If an object-cache.php file exists in the wp-content directory, * it uses that drop-in as an external object cache. * * @since 3.0.0 * @access private */ function wp_start_object_cache() { global $wp_filter; $first_init = false; if (!function_exists('wp_cache_init')) { if (file_exists(WP_CONTENT_DIR . '/object-cache.php')) { require_once WP_CONTENT_DIR . '/object-cache.php'; if (function_exists('wp_cache_init')) { wp_using_ext_object_cache(true); } // Re-initialize any hooks added manually by object-cache.php if ($wp_filter) { $wp_filter = WP_Hook::build_preinitialized_hooks($wp_filter); } } $first_init = true; } elseif (!wp_using_ext_object_cache() && file_exists(WP_CONTENT_DIR . '/object-cache.php')) { /* * Sometimes advanced-cache.php can load object-cache.php before * it is loaded here. This breaks the function_exists check above * and can result in `$_wp_using_ext_object_cache` being set * incorrectly. Double check if an external cache exists. */ wp_using_ext_object_cache(true); } if (!wp_using_ext_object_cache()) { require_once ABSPATH . WPINC . '/cache.php'; } /* * If cache supports reset, reset instead of init if already * initialized. Reset signals to the cache that global IDs * have changed and it may need to update keys and cleanup caches. */ if (!$first_init && function_exists('wp_cache_switch_to_blog')) { wp_cache_switch_to_blog(get_current_blog_id()); } elseif (function_exists('wp_cache_init')) { wp_cache_init(); } if (function_exists('wp_cache_add_global_groups')) { wp_cache_add_global_groups(array('users', 'userlogins', 'usermeta', 'user_meta', 'useremail', 'userslugs', 'site-transient', 'site-options', 'site-lookup', 'blog-lookup', 'blog-details', 'site-details', 'rss', 'global-posts', 'blog-id-cache', 'networks', 'sites')); wp_cache_add_non_persistent_groups(array('counts', 'plugins')); } }