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 );
Related Posts:
- Apply custom role capabilities to administrator (without plugin)
- Roles & capabilities GUI that does not create separate table
- How do I redirect upon login a specific user based on role?
- How to add another user to this remove_menu function?
- Add a new subscriber role using a function
- How to test for Super Admin
- Custom roles can’t access to wp-admin
- Custom registration URL lost when user makes signup mistake
- Hide Author.php template from specific user role
- edit role display name and label name without plugins
- create shortcode to list users with specific meta key value
- Toggle User Roles with button
- How to change or add user role after getting post request data about pay? [closed]
- Execute a ultimate member action when user role is updated
- Allowing users to view private posts (pending approval)
- Allow Contributor to edit their own posts after Adm aproval
- How to add custom JavaScript in functions?
- How to set default post editor based on role?
- load CSS only for administrators on backend
- Adding additional roles on registration
- The Capability to choose post/page template
- How to add array [closed]
- Get users with different roles and call function on each of them (user_meta)
- How can I show different content for different user-levels?
- Custom user role still showing up after deletion, ideas?
- How to load a css file depending on the current role
- Allow user select role in wordpress default registration without plugin
- Remove check boxes and its label from screen option for custom role
- Add Change role button for list of user in an event
- How to show only specific category post by user role without plugin and restrict all other cats
- Change user role based on total number of items ordered
- Remove all video attachment, both files and post/postmeta from database?
- delete_user_meta for user in spesific group
- Change the second role depending on the first
- Restrict certain roles registrations by domain
- Multisite Admin Roles
- add_role menu pages are not visible
- Welcome Mails based on user role
- Get all users from role and add to dropdown (select) – wordpress, javascript
- Would it be possible to disable embeds for specific user roles? If so, how?
- How to make my logged-in user-role shortcode displaying name instead of slug?
- Default content for a post in one category?
- change the comment time output to: X time ago instead of actual date and time
- redirect wp-login.php to another page
- Problem with tag
- Generate
- Shortcode to insert menu in page body?
- Error message : Call to undefined function request_filesystem_credentials()
- change billing and shipping address 1 and 2 field placeholders [closed]
- Search user metadata with checkboxes via ajax (almost working)
- woocommerce target button with class after ajax update
- Load parent theme files before child theme functions.php
- 2 Loops, Only Displaying 1 Loop in Both Loops
- Two functions.php files in one theme
- wp_dropdown_categories and custom attribute
- Make parent page only link to first subpage
- Pulling Twitter RSS feed not working as expected (fatal error)
- How to validate this deprecated function
- Scripts not appending to element in AJAX call – why?
- Trigger a custom function when option are saved in admin area
- Find a Javascript ID when trying to deregister?
- Functions For Calling Specific Elements
- How to load parent theme template parts in child theme
- allow only one post in specific category
- ACF not showing
- Cannot modify header information – headers already sent (wp_redirect in functions.php)
- Javascript function not working when placed in Text Block
- Use html inside shortcode function
- How to remove comment count column in Posts inside the admin dashboard?
- Cannot declare function twice [closed]
- Unable to return values from function
- Function not working inside of a function in functions.php
- How to Use Global Variables Inside Header and Footer
- Redirect website domain (including all pages) to external URL after Popup message (few seconds)
- processing form data with ajax
- Check from functions.php if function exists in footer.php
- Email Exists ERROR into Ajax registration form
- Split single-review.php to two parts
- The work of WordPress Function update_post
- Facebook OpenGraph error, Call to undefined function wp_get_attachment_src()
- How to Add a cutsom slug to my custom author role
- Changing the HTML of notices in WooCommerce [closed]
- How to use WP conditional tag in a functions.php with OCEANWP Theme?
- How Can I Create a Friendly Slug for a Dynamic Page?
- custom error message for empty username and password using authenticate filter not working
- Load CSS file conditionally
- my wordpress doesn’t save items to customized widget area
- save_post doesn’t correctly process function call with php class
- Display most popular posts
- Dynamically generated Navigation Diagram using Custom Fields
- Full size image option removing problem
- Add custom fields after post/page title
- Ajax call does not work for this custom code
- Force resize for all video content
- Add the title of a widget as an ID – for anchor links
- Need to use an external variable inside a function
- Correct php syntax to add an image in wp functions.php
- WordPress enque the same script causes the setInterval not to work
- Override categories with Pages (block theme)
- pre_get_comments to restrict current users view of edit-comment.php to their comments