To do literally what you’re wanting here, the easiest way is to store the instance of the plugin class in a global variable at the end of your plugin:
class My_Plugin {
static $instance;
function __construct(){} /* or private, with singleton get_instance() method */
function setup(){ ... }
}
$my_plugin_instance = new My_Plugin();
add_action( 'plugins_loaded', array( $my_plugin_instance, 'setup' ) );
Then you can do:
$has_plugin = (
isset( $my_plugin_instance )
&&
has_filter( 'plugins_loaded', array( $my_plugin_instance, 'setup' )
);
if ( $has_plugin ) ...
However, this approach to see if a plugin has been loaded seems overly complicated. Why not just check to see if class_exists( 'My_Plugin' )
? If the class does exist, then you know the plugin was loaded. No need to do any checks for if a filter was added.
Related Posts:
- How to export comments in WordPress?
- How can I call a function from one plugin within another plugin?
- Gutenberg disallow certain custom blocks but keep all core blocks?
- Publish author posts only with editor approval?
- Replacing Icons in the Dashboard
- Customizing subject in comment notification e-mails
- WP showing “warning: call_user_func_array()”, What to do?
- Declare a function before plugin does on the theme functions.php file
- Generate Advanced Custom Fields box in custom admin menu page
- Removing user contact methods works from functions.php but not from a plugin
- While Using Static Pages, How Can I Get /blog into the URL of Each Post?
- Use functionality of 2 wordpress plugins
- Fatal error: Class not found in
- What’s the point of using WordPress’s built in admin-ajax.php?
- How can i change an image’s author?
- Using plugin functionality in external php script not working
- greatest() function returns undefined property
- Override plugin with functions.php
- The Point of Using apply_filters()
- How to get post URL in the_content filter?
- How to get subscription key or id using Woocommerce Subscriptions [closed]
- How to include code into functions.php file via a plugin
- May i Use ShortCode in Template?
- Missing argument 3 for wp_register_sidebar_widget()
- Pass info from functions.php to plugin
- WordPress Plugin Page is Loading in Admin Content Container Instead of Separate Page
- add_query_arg not working
- Shortcode button dosent work for all posts. Work for first post only
- Is there a way I can find wordpress posts that don’t contain a word?
- Prevent shortcode from being wrapped in tags
- How to Display a Plugin function (content) on frontpage using index.php
- Theme my Login plugin, how to update fields
- Calling plugin function inside custom plugin for onclick event
- Show function to super admin
- get current date + 90 days and checking every day
- All sites themes functions.php have been changed
- Grab WordPress Salt Data From URL
- How to set Noindex to all wordpress pages in a catergory?
- Plugin is a widget, but I want to call it in the head, can I?
- Cannot get wpdb data (Error in a simple fuction) [closed]
- How to keep variable `$post` to using in another file
- Plugin Development – Functions or Hooks?
- Help with WP Business Directory Manager Plugin?
- wp_dequeue_script for a Plugin
- Return multiple values in a shortcode attribute
- get specific value of a array | PHP
- wc_get_template new template does not showing up
- Loading a plugin’s js file from functions.php
- Overriding an Array in a Plugin’s Class/Function from functions.php
- Change Header (Logo) Based on Login
- How to access OOP plugin function inside themes or other plugin
- Different registration form for different roles
- Defining the value of a variable before a function?
- Elementor Pro display featured image on section -> style -> image using shortcode
- How to get custom minimum price in Woocommerce
- Create a pdf from the entries in DB
- RSS feeds for specific topics
- add_rewrite_rule to load different page, without changing URL in browser
- Error using wordpress functions inside a plugin class
- Share my WordPress plugin for updating how?
- Overriding a function in a WordPress plugin
- Adding discount functionality to the cart
- Precheck fields when I add a new post
- How to detect 404 url and make this link underline or change background color?
- Get Shortcode output to database for static post_content
- working code, not working – Plugin Dev
- Use buddypress function outside of plugin
- How to Unhook actions/filters in within Class in plugin
- WPML – Hook when language is switched (change user language)
- Use action, filter, or hook to append HTML to WordPress plugin function
- Change custom rewrite rule when permalink is updated/changed
- Configuring default woo commerce login with modal popup
- Save Post Permalink In .txt File
- Dynamically Modify s2member Options
- register_activation_hook doesn’t fire at all
- How To Add Code To WP Without Plugin or Functions
- My ajax request don´t work and return 0
- How can I add a custom checkbox / radio button on the admin theme options to display a CSS or other?
- How to delete posts older than one year with post meta, post attachments and files?
- Disqus comments count taking long to update
- plugin not hooking to my custom hook
- Populate select option with JSON file
- Home page letters
- Find all strings between an enclosing shortcode
- Create csv file in plugin
- How do add_action and WP_Query
- Trying to output a “Most visited blogs” list in wordpress multisite
- wordpress Search function is not working
- What is wrong with this dbDelta syntax?
- Call a function with href
- Override the plugin class and function
- Activate and deactivate two plugins automatically at certain hours
- PHP Creating a formula from mysql db values and db stored math operator
- How to Allow Users to Select Recipients In a WordPress Comment section?
- How often should I execute add_filter and function declaration in Code Snippets?
- Product customizing quiz – quiz adding products to the cart
- How to change all the urls of the WordPress site?
- Show WooCommerce products based on query parameters on redirect
- Event Made Easy – Block registration to two or more events that have the same category
- I want to allow certain file types on dokan upload files