在 wordpress 中从 add_action 中检索值
retrieving value from add_action in wordpress
我正在尝试调用过滤器内的操作。我想从操作方法中检索一个值并将其用于过滤功能
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_custom_query_args 中检索 $store_id?
您应该在源代码中找到行 apply_filter('wc_product_table_query_args'
以查找允许的参数。如果第三个参数是 $store_id 那么你可以使用它。
你应该记住一件事,在动作挂钩上,什么都不应该 returned(return 仅用于过滤器挂钩)
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;
}
我正在尝试调用过滤器内的操作。我想从操作方法中检索一个值并将其用于过滤功能
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_custom_query_args 中检索 $store_id?
您应该在源代码中找到行 apply_filter('wc_product_table_query_args'
以查找允许的参数。如果第三个参数是 $store_id 那么你可以使用它。
你应该记住一件事,在动作挂钩上,什么都不应该 returned(return 仅用于过滤器挂钩)
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;
}