我还是个新手。
我有一个WordPress问题,我只能在同一个类中存在的apply\\u filters命令的类中使用add\\u filters。
下面是一个成功添加筛选器的示例类:
$CTAExtensions = new CTALoadExtensions;
class CTALoadExtensions
{
public $definitions;
public $template_categories;
function __construct()
{
$this->add_core_definitions();
$this->load_definitions();
}
/* collects & loads extension array data */
function load_definitions()
{
$wp_cta_data = $this->template_definitions;
$this->definitions = apply_filters( \'wp_cta_extension_data\' , $wp_cta_data);
}
/* filters to add in core definitions to the calls to action extension definitions array */
function add_core_definitions()
{
add_filter(\'wp_cta_extension_data\' , array( $this , \'add_advanced_settings\') , 1 );
}
function add_advanced_settings()
{
echo 1;exit; works!
}
}
如果我尝试像这样在类外添加筛选器。。。我没有运气:
add_filter( "wp_cta_extension_data", "wp_cta_bt_meta_boxes" , 10 , 1 );
function wp_cta_bt_meta_boxes( $wp_cta_data )
{
echo 1; exit; //does not work outside of class.
return $wp_cta_data;
}
我甚至尝试扩展该类并添加过滤器,以查看它是否可以工作,但没有成功:
$wp_cta_bt = new CTABehavioralExtend;
class CTABehavioralExtend extends CTALoadExtensions
{
function __construct(){
add_filter( "wp_cta_extension_data", array( $this , "add_advanced_settings" ) , 10 , 1 );
}
function add_advanced_settings( $wp_cta_data )
{
echo here;exit; // does not work.
return $wp_cta_data;
}
}
有人对我不理解的东西有什么见解吗?