从wordpress中的add_操作中检索值
我正在尝试调用筛选器内部的操作。我想从action方法中检索一个值,并将其用于filter函数从wordpress中的add_操作中检索值,wordpress,hook,Wordpress,Hook,我正在尝试调用筛选器内部的操作。我想从action方法中检索一个值,并将其用于filter函数 add_filter( 'wc_product_table_query_args', 'wcpt_custom_query_args', 10, 3 ); function wcpt_custom_query_args( $args, $product_table) { add_action('dokan_store_profile_frame_after', 'add_store_id',
add_filter( 'wc_product_table_query_args', 'wcpt_custom_query_args', 10, 3 );
function wcpt_custom_query_args( $args, $product_table) {
add_action('dokan_store_profile_frame_after', 'add_store_id', 13, 2);
;
// do something with $args
$args += array('author' => $store_id);
return $args;
}
function add_store_id($store_user, $store_info){
$store_id = $store_user->ID;
return $store_id;
}
如何在函数wcpt\u custom\u query\u args中检索$store\u id?您应该在源代码中找到行
apply\u filter('wc\u product\u table\u query\u args'
以查找允许的参数。如果第三个参数是$store\u id,则可以使用该行
有一件事您应该记住,在ActionHook上,不应该返回任何内容(只返回过滤器挂钩)apply\u filter('wc_product_table_query_args'只包含两个参数,其中没有一个是$store_id您可以尝试使用var_dump$args、$product_table来查看任何参数是否可用于获取$store_user和$store_id?不可以从这些参数猜出。请先加载add_store_id,然后再加载wcpt_custom_query_args函数大量存储…通过加载add_store_id f它起作用了吗:):)
add_action('dokan_store_profile_frame_after', 'add_store_id', 13, 2);
function add_store_id($store_user, $store_info){
global $store_id;
$store_id = $store_user->ID;
add_filter( 'wc_product_table_query_args', 'wcpt_custom_query_args', 10, 2 );
}
function wcpt_custom_query_args( $args, $product_table) {
global $store_id;
// do something with $args
$args += array('author' => $store_id);
return $args;
}