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
- Advantages and disadvantages of using automatic-feed-links
- Publish author posts only with editor approval?
- How to change the markup WordPress inserts for post images
- Convert hyphen to underscore in permalinks
- wp_mail not running inside Cron
- Remove product description from product archive page
- Logging in redirects to correct page but shows logged out content until forced refresh
- Increment price for Woocommerce Minicart [closed]
- Change woocommerce products weight varation based its product category or tags? [closed]
- Function to “Press Update Button” on all posts
- Completely disable RSS feeds on WP 5.5.2 and show a 404 page instead of die();
- Check if row exists before inserting
- Missing argument 2 for a custom function widgets_init
- Add custom image size not working
- Not sure if enqueuing js scripts properly
- Shortcode inserts paragraphs before and after executing shortcode
- Best practices regarding the creation of custom widgets?
- How to remove style attribute in WordPress RSS output?
- Multiple Loops Meta Data
- How to stop wordpress from injecting hard-coded style into image attachments with captions
- What is the text that appears beside the page titles in the list of pages in the WP admin?
- Two functions with different arguments and add_actions, but identical code
- How to fix get_the_category function returning incorrect slug?
- How to edit the Tags within the image file URLs?
- Disabling visual editor on a specific post
- Disable wp_is_mobile()
- Testing for a shortcode using a function. 404 page throwing PHP Notice
- How to get post revisions in my custom rest API? [closed]
- Possible to merge these two functions?
- Strip div From Excerpt
- The_content and Preg_replace in loaded Iframe [closed]
- dynamic site link for future migration in echo do_shortcode()
- Hide tab Buddypress profile for visitors, not logged in users
- Add a mature content warning to first-time visitors
- Show Featured Image in else statement
- Function to check if custom page is used by page?
- Simplest Way to Build Custom Archives Page?
- Filter for replacing the WP_query object for a given category
- How to Display WooCommerce Product Price in WooCommerce Archive
- Bizarre Child Menu Issue on WP Site
- get variables data from functions.php to template wordpress (without global variables)
- how to increase connection time
- Shortcode to insert default text and change one word throughout it?
- Its my first time trying to create a website , I got an error Please help
- Add schema to Search result page’s body. Tried using is_search
- Drop down list code for sidebar
- Shortcode Initialization in a Custom Theme
- Hide disclaimer from summary excerpts
- Load scripts into an AJAX div
- Restricted images only for logged user. (hidden url)
- Allow BBPress participant role to trash topics
- Open image size links in a page instead of direct image link
- Allow tags and attributes in post and pages content
- Get author meta of all writers
- Override parent theme function that is not hooked or in the functions.php file
- Function to get thumbnail img source
- WP Custom Comment Callback Not Responding
- Do something when user creates post (that’s pending)
- Add product to cart from functions.php
- How I can show short content with short tag
- Add functionality to block comment authors in the Comment edit pag