您可以使用WordPress函数apply_filters
和add_filters
要存储和检索数据,请执行以下操作:
// The filter callback function.
function so_wp_380975_get_user_args( $array ) {
// (maybe) modify $array.
// for now, we just return the array
return [
\'meta_key\' => \'mycred_default\',
\'orderby\' => [ \'meta_value_num\' => \'DESC\' ],
\'order\' => \'desc\',
\'number\' => 10
];
}
add_filter( \'get_user_args\', \'so_wp_380975_get_user_args\', 10, 1 );
// get the stored args from the filter
$args = apply_filters( \'get_user_args\', [] );
注意,您可以做更多的事情,例如向过滤器传递额外的参数来修改参数,或者在过滤器不返回任何内容的情况下传递默认值。
https://developer.wordpress.org/reference/functions/apply_filters/