我认为没有,但我想知道以前是否有人碰到过这个问题。
是否有函数(或变量)调用来获取所有已注册的WP操作和所有已注册的WP筛选器?
我目前的做法是这样:
static private $wp_actions = array(
\'muplugins_loaded\',
\'registered_taxonomy\',
\'registered_post_type\',
\'plugins_loaded\',
\'setup_theme\',
\'load_textdomain\',
\'after_theme_setup\',
\'init\',
\'widgets_init\',
\'register_sidebar\',
\'wp_register_sidebar_widget\',
\'wp_default_scripts\',
\'wp_default_styles\',
\'admin_bar_init\',
\'add_admin_bar_menus\',
\'wp_loaded\',
\'parse_request\',
\'send_headers\',
\'parse_query\',
\'pre_get_posts\',
\'wp\',
\'template_redirect\',
\'get_header\',
\'wp_head\',
\'wp_enqueue_scripts\',
\'wp_print_styles\',
\'wp_print_scripts\',
\'loop_start\',
\'the_post\',
\'loop_end\',
\'get_sidebar\',
\'wp_footer\',
\'wp_print_footer_scripts\',
\'admin_bar_menu\',
\'shutdown\'
);
但这是不可取的,因为如果。。。WP添加了更多操作,还是不推荐了一些?如果有一个已经在内存中的解决方案,我会觉得更安全。
以上列表由专人翻译自this link.
EDIT: 我正在尝试使用类编写一个有点像样的插件系统。以下是我正在寻找的实现:
abstract class AtlantisPlugin {
static private $atlantis_actions = array( );
static private $atlantis_filters = array( \'atlantis_plugin_init\' );
// http://codex.wordpress.org/Plugin_API/Action_Reference
static private $wp_actions = /* see above */;
static private $wp_filters = array();
protected $atlantis;
private $class;
public function __construct(Atlantis $atlantis) {
$this->class = strtolower(get_class($this));
$this->atlantis =& $atlantis;
$this->atlantis->registerPlugin($this->class, $this);
$actions = array_intersect(self::$wp_actions, get_class_methods($this->class));
foreach($actions as $action) {
add_action($action, array(&$this, $action), 2);
}
$filters = array_intersect(self::$wp_filters, get_class_methods($this->class));
foreach($filters as $filter) {
add_filter($filter, array(&$this, $filter), 2);
}
}
}
谢谢。
:)