You need to register/enqueue your admin scripts on admin_enqueue_scripts
, not on wp_enqueue_scripts
. wp_enqueue_scripts
is a front end hook. It won’t run on the admin pages.
Secondly, is_admin()
just checks whether the page is an admin page, not whether the user is an administrator. To check whether the user is an administrator use:
$current_user = wp_get_current_user();
if (user_can( $current_user, 'administrator' )) {
// user is an admin
}
Reference:
http://codex.wordpress.org/Function_Reference/user_can
http://codex.wordpress.org/Function_Reference/wp_get_current_user
Related Posts:
- Is it possible to reuse wp.media.editor Modal for dialogs other than media
- How to include jQuery and JavaScript files correctly?
- API to trigger prompt on leaving page
- jQuery in header or footer
- Hook the Keydown Event in the TinyMCE Post Editor
- Use js script from one plugin in another plugin
- Can’t get JS code to work with shortcode
- How do I add a javascript file to all admin pages via a plugin?
- Where to call wp_enqueue_script in a plugin with custom template?
- Replacing Scripts in Admin Load_Scripts
- How to load library scripts in admin from plugins in noConflict wrapper?
- Enqueue script globally
- should i be checking for jquery before enqueing it in a plugin
- How to import the css in the plugin admin area?
- Custom Plugin – CSS works, JS doesn’t
- Is “document loaded” different on admin side than public side?
- Append php file to footer
- Add a Script button in W3 Total Cache plugin not working due to conflicting jQuery version
- Is there an event or an other method that tells me the preview is loaded?
- Problems with: manage_${post_type}_posts_columns
- Global State During an Admin Post
- WordPress Plugin with a shortcode that dynamically generates javascript. Can I use add_action without wrapping the javascript in a function?
- conditionally load javascript & CSS for do_action() calls from plugin
- Render content after post title in wp-admin
- What stylesheets are available in core?
- On cliking add new post redirect user to a custom page first
- Enqueue WordPress plugin scripts below all other JS
- How to prevent UNDO on guternberg block editor
- Do I have to worry about useState causing a re-render?
- Creating a custom Gutenberg block with columns
- “import declarations may only appear at top level of a module” when importing WooCommerce API node module
- What should happen when a WordPress Plugin is activated across the network (Network Wide Activation)
- Prevent third party plugin’s admin page access based on user type
- How to add WordPress Admin “Insert Link” UI (searches through existing posts for URL) and functionality into a custom plugin?
- Is it possible to restrict all admin pages except theme customisation and storefront using plugin?
- wp.template() returns tags in Ajax response
- Gutenberg: import dependency or assign from global variable?
- Admin – Handle data before creating or updating a post, page or custom post
- How to enqueue or include json file to a plugin
- wp_filesystem put_contents issue with owner/group
- My WordPress plugin cannot load my JavaScript file
- javascript datatables in a plugin
- Password field is empty when using wp_signon();
- How can I replace content in the WP Admin area before an admin page is rendered?
- Using ReactJS in the WordPress admin for plugin development
- template_redirect or admin-ajax.php?
- Creating Admin Plugin – Content of a page is displayed at global scope as well
- Show error message after exception handled
- add javascript files only when plugin is called?
- jQuery does not enqueue for my purpose… (before an inline script in the footer)
- Issue with contextual help overwriting existing content
- Inserting code to HTML view from a pop up initiated from visual view
- Plugin – Make sure jquery is loaded in my settings page plus my JS file
- How can I remove the WordPress-Version (?ver=5.x) from my plugin
- How can I avoid conflicts between plugin and theme?
- How to control an elements classes from multiple Gutenberg sidebar controls?
- Alternatives to DISALLOW_FILE_EDIT wp-config Constant? It Breaks Some Plugins
- How should I go about registering JavaScript that isn’t a file? [duplicate]
- How do I add a favicon that only shows during viewing of my plugin’s admin panel?
- What action hook can I use to add a JavaScript to a page post using a theme template that is not including get_header() nor get_footer()?
- How do I link to a php file in my plugin directory?
- WP Plugin Running before jQuery
- WordPress Admin Login Custom Logo
- wp_localize_script is not adding a global variable for javascript
- Loading Modernizr (or other JavaScript libraries) for use in a plugin
- How to create custom settings page for custom plugin
- 400 Bad Request, in wordpress theme development, wp_ajax
- Loading custom js file on the admin page through plugin
- Creating multiple wp_editer() text fields in for loop — the text/visual switch only works for first editor
- Displaying “One Time” Notification in Plugins
- My stylesheets are not enqueuing
- Run JavaScript validation script on form submit in plugin
- Plugin Development – Class Constructor Not Firing wp_enqueue_style action hook
- Enqueuing scripts and styles in custom plugins
- How to enqueue scripts in right way in a plugin?
- Wp-admin Custom User Management
- Admin Subpages without Menu entry
- unable to wp_enqueue_script(‘suggest’);
- Translate javascript with WordPress built-in localization API for static strings
- Filter for admin (back end) ‘reply to’ comment
- Data not insert and update through ajax and jQuery in admin page?
- How to make my shortcode load scripts and styles, from within the plugin?
- Need help about understand api, wp, $ syntax in WordPress plugin script
- Catching Form Submission in WordPress Admin Panel
- Redirect in WordPress plugin
- How do I get rid of my inclusion race-condition on wp_enqueue_script
- How to add a panel/box/widget/are/screen to the right side of edit post/page confusion
- Insert Into Post Not Working For Audio File Using jQuery
- Service Worker Uncaught (in promise) DOMException
- How to add custom view links to wp-admin/post.php?
- Developing the save function in Gutenberg blocks
- Is it possible to load the css just on my plugin admin page?
- Gutenberg – is it ok to load dependencies multiple times?
- Preventing double loading JS scripts (like React) when developing for Gutenberg
- AJAX button with success callback. (Titan Framework)
- Using function from enqueued .js file in theme in plugin?
- Enqueue a file that’s not js or css
- Enqueueing common php scripts in a plugin
- jQuery UI tab does not work in the plugin page
- Disable Auto-Expanding Menu in WordPress Admin Menus