The core has functions like current_user_can
to check for an capability of a role or check the role directly. The follow example extend your source for this check so that the function not (!
) run, if the current user haven’t the rights, the capability of his role.
add_filter('request', function( $vars ) {
// Check the capability of the current user.
if ( ! current_user_can( 'manage_options' ) )
return;
global $typenow, $wpdb;
// Add logic to determine if the orders list should be filtered, and which
// currency
$currency = 'GBP';
if($typenow == 'shop_order') {
$vars['meta_query']['relation'] = 'AND';
// Only show orders in the specific currency
$vars['meta_query'] = array(
array(
'key' => '_order_currency',
'value' => $currency,
'compare' => '=',
),
);
}
return $vars;
}, 15 );