Wordpress:对未加载操作的挂钩进行故障排除

时间:2015-11-22 05:01:59

标签: php wordpress plugins action-hook

我正在扩展现有的插件。该插件的作者在其插件的主类中提供了一个动作钩子:

public static function instance() {

            if ( ! isset( self::$instance ) && ! (self::$instance instanceof self) ) {
                self::$instance = new self();
                self::$instance->setup_constants();
                self::$instance->actions = array();
                self::$instance->filters = array();

                add_action( 'plugins_loaded', array( self::$instance, 'load_textdomain' ) );

                add_action( 'bp_loaded', array( self::$instance, 'bp_include' ) );

                global $ap_classes;
                $ap_classes = array();

                self::$instance->includes();

                self::$instance->ajax_hooks();
                self::$instance->site_include();

                self::$instance->anspress_forms         = new AnsPress_Process_Form();
                self::$instance->anspress_query_filter  = new AnsPress_Query_Filter();
                self::$instance->anspress_cpt           = new AnsPress_PostTypes();
                self::$instance->anspress_reputation    = new AP_Reputation();

                /*
                 * ACTION: anspress_loaded
                 * Hooks for extension to load their codes after AnsPress is leaded
                 */
                do_action( 'anspress_loaded' );

                self::$instance->setup_hooks();
            }

            return self::$instance;
        }

我正在尝试使用此挂钩来运行我的代码,但它不起作用。我使用has_action()尝试查看是否正在运行此操作挂钩,但事实并非如此。

if(has_action('anspress_loaded', 'find_do_for_anspress')){
    echo 'fd is hooked';
} else {
    echo 'NOT WORKING CORRECTLY';
}

上面的代码位于主插件的php文件的底部,在任何类之外。知道怎么解决这个问题??

0 个答案:

没有答案