You need to replace the following:
if ( ! current_user_can('administrator') ) {
with
if ( ! current_user_can('manage_options') ) {
This is because there’s no such capability as administrator
. There are a couple of administrator-only capabilities, and manage_options
is a reliable one to use.
Related Posts:
- function deactivate_plugins does not exist
- what’s the meaning of the field wp_capabilities in table wp_usermeta
- What is wrong with using add_option with Multisite instead of add_blog_option in a plugin
- Is there widely accepted phpDoc syntax for documenting which hook calls a function?
- Make Categories and Tags required in admin
- Getting wrong relationship value in $args in wp_Query?
- wp_schedule_event in a class
- custom XMLRPC method plus authentication of user & WooCommerce order
- How to extend LINK TO functionality in ATTACHMENT DISPLAY SETTINGS
- How do I Make a Theme “plugin-ready”?
- How to iterate through custom posts and add the title to an array
- WordPress Terminology Options Vs. Settings
- How to modify post content before writing to database?
- Display only certain posts based on visitor’s country?
- Custom user profile, registration, login page with theme
- Plugin Sidebar is not Saving Meta Attribute to Post/Page after “Update”
- Possible to preset a widget’s contents via a plugin script?
- $wp_filesystem returns NULL. What are the dependencies?
- Install widget on plugin activation
- set_sale_price in WooCommerce [closed]
- Synchronize custom post type tags with WordPress default post type tags
- Prevent Javascript Facebook SDK Conflicts in plugin
- Integrating Stripe PHP library into a custom WordPress Plugin
- How to change the URL pattern for single post view
- What for the tables ending with the meta used in database of wordpress?
- How to create custom field in worpdress default widgets?
- Ensure function has completed before allowing another Ajax call
- jquery document ready function not being called [closed]
- Loading scripts with wp_register_script and wp_enqueue_script
- WordPress is automatically linking plain text email addresses
- Is Using WordPress Supplied WYSIWYG Advisable?
- How do I add a filter to wp_list_categories() to make links nofollow?
- How to hook into publish post events in wordpress 4.7.5
- What is the best way to embed an JS App in a WordPress Page?
- add_rewrite_rule works in themes function php but when moved into plugin it stops working
- $reverse_top_level works the opposite way according to Codex?
- How to serve different thumbnails/images depending on users browser/platform
- Plugin development – How to use a specific wp_options into the real rendered code in the front end?
- Show disclaimer with accept button before redirecting to the payment gateway website
- Why is the temporary upload always 4.1K
- Problem with dinamic add_rewrite_rule()
- How to export post meta with images in wordpress
- Parse form values before sending to options.php
- Remove custom post type slug from URL and add taxonomy Slug
- How do I get the sub categories of the parent when in a sub category?
- Add Minimum Dimensions Text to Featured Image
- custom permalink’s rewrite rule for page id
- how to get context information inside my funcion
- Is disabling test_form in wp_handle_upload a security concern?
- How to connect my wordpress plugin to a remote database securely?
- How to create a backend for a custom theme?
- admin_post equivalent for guest user?
- Delete data from database using row action
- When echoing my own shortcode, it keeps adding a 1 at the end of my blogpost
- I am trying to make a page in the admin section similar to the appearance of the Profile page for users
- How to create templates for a custom module to show on the front end within my theme?
- WooCommerce change Tax Class programmatically when Recalculating an existing Order [closed]
- unregister_setting() vs delete_option() for plugin update
- settings api – add_settings_section not working
- How to redirect home page to another page after login for all user?
- add_filter img_caption_shortcode not implemented
- How to add Plugin functionality in WordPress Frontend Menus
- How to overwrite iris color pallates from theme to plugin
- in_array function Problem
- Best practice for plugin: always detect admin-ajax call?
- How to hide page links from theme menu
- Brainstorm – Slow Query from Plugin Need to Speed It Up
- Thickbox in Plugin settings page?
- WooCommerce currency converter support [closed]
- Woocommerce – looping product images
- How to add text editor in plugin menu?
- Console errors in 6.0-RC1 Widget screen
- Pass Values in URL on WooCommerce Product Page
- How to query a nested field in wordpress api using _fields param
- function add custom fields to media gallery
- ajax response strips multidimensional array and unable to decode
- Multiple instances of $opt_name in redux framework
- Using AJAX to submit and return data inside the WordPress Plugin Boiler Plate framework
- Add quick edit functionnality to plugin table
- The Events Calendar featured image as body background?
- using wordpress acf shortcods in tables goes outside the table
- Pass javascript result to shortcode executer function
- remove different admin menu for specific users
- Not able to Update database while creating a custom module
- How to load css file after a certain css file
- Shortcode from a plugin not working
- Plugins and how to assign urls to content
- Deactivate Other Incompatible Plugin Upon Activation
- How to make auto installer Plugin?
- Can’t get query string in ajax call
- first_name property missing inside register_user action hook
- Pass results of custom query to loop – when writing a plugin
- How do I use (or mimic) document.getElementById() on a page loaded from WordPress database?
- user can login from single account detail from multiple locations(computer) at the same time [closed]
- WP Cron registers hook without any action (does not call the function)
- Call API on post save/update and show the result in admin area
- Is there any other ways to replicating changes on live from staging without pushing from git
- upload image to wordpress media library failed for custom post type
- Fetch Custom Woocomerce filed data and check the data avialble in Wp-user table as nicname or username using function.php
- How to get locale within WP REST Request?