我正在尝试使用add_filter
. 我可以像这样传递单个值:
add_filter(\'example_filter\', \'my_example_filter_1\' );
function my_example_filter_1( $array ){
$array[]=\'tax1\';
return $array;
}
add_filter(\'example_filter\', \'my_example_filter_2\' );
function my_example_filter_2( $array ){
$array[]=\'tax2\';
return $array;
}
add_filter(\'example_filter\', \'my_example_filter_3\' );
function my_example_filter_3( $array ){
$array[]=\'tax3\';
return $array;
}
print_r( apply_filters( \'example_filter\', array()) );
但如果数组的格式如下,我无法实现它。
function wte_fixed_starting_dates_license()
{
$wp_travel_engine = get_option( \'wp_travel_engine_license\' );
$wte_fixed_departure_license_key = isset( $wp_travel_engine[\'wte_fixed_departure_dates_license_key\'] ) ? esc_attr( $wp_travel_engine[\'wte_fixed_departure_dates_license_key\'] ):\'\';// setup the updater
$array =
array(
\'version\' => \'1.0.0\', // current version number
\'license\' => $wte_fixed_departure_license_key, // license key (used get_option above to retrieve from DB)
\'item_id\' => WTE_FIXED_DEPARTURE_ITEM_ID, // id of this product in EDD
\'author\' => \'WP Travel Engine\', // author of this plugin
\'url\' => home_url()
);
return $array;
}
add_filter( \'wp_travel_engine_licenses\', \'wte_fixed_starting_dates_license\' );
我使用相同的过滤器传递另一个数组,如下所示:
function wte_authorize_net_license($array)
{
$wp_travel_engine = get_option( \'wp_travel_engine_license\' );
$wte_authorize_net_license_key = isset( $wp_travel_engine[\'wte_authorize_net_dates_license_key\'] ) ? esc_attr( $wp_travel_engine[\'wte_authorize_net_dates_license_key\'] ):\'\';// setup the updater
$array =
array(
\'version\' => \'1.0.0\', // current version number
\'license\' => $wte_authorize_net_license_key, // license key (used get_option above to retrieve from DB)
\'item_id\' => WTE_FIXED_DEPARTURE_ITEM_ID, // id of this product in EDD
\'author\' => \'WP Travel Engine\', // author of this plugin
\'url\' => home_url()
);
return $array;
}
add_filter( \'wp_travel_engine_licenses\', \'wte_authorize_net_license\' );
如果我像这样传递多个数组,那么我只会在像这样的数组中得到后面的值。
Array ( [version] => 1.0.0 [license] => [item_id] => 79 [author] => WP Travel Engine [url] => http://localhost/wordpress )
打印阵列时应该有两个版本、两个许可证和其他参数,对吗?还是我遗漏了什么?
任何帮助都是值得赞赏的。谢谢