Possibly you’re trying to use that code in a non-admin page. The functon get_plugins
is only available on admin side and if you ant to use it somewhere else you have to load the file “plugin.php” manually.
To solve this error add that check at the beginning of your function:
if ( ! function_exists( 'get_plugins' ) ) {
require_once ABSPATH . 'wp-admin/includes/plugin.php';
}
Related Posts:
- How can I see all the actions attached to an “add_action” hook?
- How to include code only on specific pages?
- Changing the “Plugin Activated” Message Default
- Schedule WordPress Auto-Updates to only run during business hours
- Remove action from plugin on other plugin
- How To Determine If A Filter Is Called In A Sidebar/Widget Context?
- Is there any debug toolbar that shows whick hooks are called for the current page in WordPress?
- When can you get current page ID and initialize hooks right after?
- Can we hook a static method of a class to add_action inside that class?
- What is the ‘admin_action_’ . $_REQUEST[‘action’] hook used for?
- Filter out results from REST API
- How can I remove a hooked action created by a plugin?
- WordPress admin notice in plugin function
- Using the ‘draft_to_publish’ hook (post status transition)
- Filter Hook on plugin update
- WordPress Hook that will run when media file deleted
- Disallow a user to post in certain categories
- Intercepting a add_action
- Generic plugin (de)activation hook?
- disable active plugins for specific theme
- Twillio How To Send SMS for Custom Post Type
- Adding a form at the end of the content
- Find out if request is for custom post type archive before query runs
- Use external link in the add sub menu
- Failed to invoke other hook from the init hook
- How can I add a custom meta value on file upload?
- How can I filter blog name?
- Is it possible to remove this action? (as it’s added just before it’s called)
- Woocommerce Shipping module available only for type of products [closed]
- WordPress Plugin Boilerplate – add_action hook in static “activate” function
- Determine plugin name from within plugin_action_links filter
- Placement of Code in Plugin for hooking `save_post`
- publish_post plugin hook doesn’t always pass $post->post_content
- How to initialize something in unit test before the init hook being called?
- ‘wp_login’ action hook not working with wp-login.php file
- Prevent a plugin from being automatically activated
- Where (or when) should I register a new taxonomy?
- How get a value from a plugin into another plugin through action/filter
- Hook (or other way) to find out when another plugin is activated / installed
- Any hook for pre-plugin-update -either bulk or single plugin update
- Inserting above the comment template
- Insert new user with form submit ‘init’ hook
- How do I display only the latest post on my home page, while maintaining proper plugin hooks?
- How to stop activating a plugin and show admin notice when dependent plugins minimum version is not met
- wp_get_post_terms is difference obj model than the one in rest api response
- Get Time Taken By Each Action Hook in WordPress
- Are functions in main plugin file called before function bound to register_activation_hook runs?
- Best place for short bio,image and button [closed]
- password_reset hook is not working
- The Hook registration_errors was not called
- edit_user_profile and show_user_profile are not firing inside a class
- Template filter for custom taxonomy terms
- What exactly happens to function argument availability when using a filter?
- Combining several CSS files into one for optimization
- Create a post builder skin in a plugin
- remove_action not removing add_action from constructor
- How do I add some javascript validation to the admin interface form’s onsubmit?
- Can my hooked uninstall class function access a global var declared in main plugin file?
- Flipping Book PHP Code? Any experience?
- Hook for page Request?
- Display Plugin Panels Outside of Admin Areas
- How to remove js ui library added by default by wordpress
- How to use the pre_option filter before a plugin loads?
- How to remove a class function from a plugin by using remove_action()?
- profile_update hook doesn’t works inside a class
- Plugin: Hooking up classes that have their own hooks
- Hook for altering the content of all wp mails
- What hook can I use to modify custom post data before it is displayed on the page?
- Quick press publish post hook
- How to deactivate my plugin upon deactivation of NextGen
- Creating a plugin that will display text on every page
- Hooks to run after a core upgrade?
- Why does “updated_post_meta” did not fire when uploading media other than image?
- Build a must-use plugin that tracks when other plugins are activated or deactivated
- Change Dashboard URL from wp-admin to wp-admin/index.php
- Activation flow of a plugin in a multisite environment
- Callback hooked to post_updated firing on new posts as well
- front end editor creation for Restropress plug in – displaying information from a WP admin area, on a different URL
- Replace plugin HTML to single text using hooks
- How can I disable W3 Total Cache Image Lazy Load for Specific Post Type?
- Customize plugin templates
- wordpress plugin translation not working
- WordPress Boilerplate Plugin doesn’t see callback functions for add_settings_field and add_settings_section
- What is the correct entry point for capturing coverage data
- Hook on widget context plugin to add custom context for widget
- Publish check if the edited content has HTML “div”
- Admin page and admin menu. Permissions plugin
- How should I use a plugin function as a hook?
- Display_rows() and column_cb() strange behaviour
- change output location of plugin function using a custom hook
- Plugin constructor called multiple times
- How to change value of $menu_class in ep_nav_menu?
- How to create and use Custom hooks
- How to display a link in the footer section
- How wordpress plugin hooks works? [duplicate]
- Post curl function save twice using plugin hook function wordpress
- How to Add Extra Text In WordPress Title Before Post Publish
- Suitable hook when creating, updating and deleting posts programmatically
- Change social icon in twenty twenty three theme
- is_user_logged_in() undefined at shutdown in plugin context