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 do I replace a function, declared inside a plugin’s class, in functions.php?
- Plugin update error message
- Prevent publishing the post before setting a featured image?
- How to Loop Plugin Option Field Set?
- How to handel multiple checkbox field in the admin settings page with Settings API
- wp_insert_user – how to send verification email before logging in
- Is the WordPress HTTPS Plugin Still Safe To Use? [closed]
- Set a User as Author of all ‘New Posts’ posted
- Post source link plugin – small modification
- How do you auto-activate plugins from child themes
- How to load plugin before the wordpress jquery?
- What is the function to get plugin base url in multisite?
- Code in theme functions.php faster than with a plugin?
- Extend Elementor Archive Posts widget with a custom skin in order to show multiple badges
- HELP: Integrating WP with raw PHP code once published button is hit
- Override the core function locate_template
- How to redirect Old Post URL to new Post and keep Old post Comments?
- Modifying Footnote Plugin for Descriptive Title Attributes
- I would like to use create a function in my custom plugin to tell WP to use a different header
- bulk change of image setting “link to” to “link to: image url “
- Limit the number of plugins that can be installed in a WordPress installation
- Add get_option to jquery
- How to get variables from fucntion.php to my plugin files
- Avoiding Duplicate function names in Post Loop (WP_Footer script)
- How to add class in plugin only for network site?
- PHP Fatal error: Call to undefined function plugin_basename
- Executing my function once on a specific time
- How to stop or remove an action being called inside a function of an extended class
- Date calculations from 2 custom fields
- Does WordPress validate inputs to all functions? (such as get_user_meta and insert_user_meta)
- Using a function to change favorites listing
- How to debug error message: Cannot modify header information
- How to enable specific plugin only based around shop manager role?
- Adding a new field to the address field type in gravity forms
- Nested shortcode functions accessing variable
- Calling an attribute from a plugin shortcode
- How to set Noindex to all wordpress pages in a catergory?
- List the authors that have written posts in a category
- Load Javascript from Plugin in One Page Only?
- How to get plugin name from plugin file location
- How to keep variable `$post` to using in another file
- Create a post builder skin in a plugin
- Plugin Development – Functions or Hooks?
- wp_dequeue_script for a Plugin
- Need to replace Currency Shortforms
- wc_get_template new template does not showing up
- add_query_arg not work in admin
- Overriding an Array in a Plugin’s Class/Function from functions.php
- Api external with wordpress
- Change Header (Logo) Based on Login
- How to get rid of Ellipsis on Woocommerce [Essential] Theme [closed]
- Sharing functions between plugins
- How can i list random author?
- Can you echo PHP code from a variable?
- Defining the value of a variable before a function?
- How to get custom minimum price in Woocommerce
- Dynamic URL Rewrite for Custom
- how to validate input field in wordpress generated with wpform plugin
- implement custom roles in custom plugin
- How to get current cart values using WC_Shortcodes?
- Error using wordpress functions inside a plugin class
- How to copy the all WordPress media items to another custom plugin folder?
- Share my WordPress plugin for updating how?
- The function called on the wp head hook becomes null
- Submitting form to PHP
- How to detect 404 url and make this link underline or change background color?
- working code, not working – Plugin Dev
- How use get_plugin_updates() function?
- how override a define
- how can export data in excel file custom plugin
- How to Unhook actions/filters in within Class in plugin
- How to disable/enable a plugin at a specific time
- WP_CRON issue with UTC and local time
- Configuring default woo commerce login with modal popup
- Update User Meta Via Ajax
- Dynamically Modify s2member Options
- register_activation_hook doesn’t fire at all
- 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?
- Unexpected plugin_dir_path Output
- how to create table during plugin installation in side a class
- Create csv file in plugin
- Load wordpress enviroment for external content?
- Metabox Data not saving
- How do add_action and WP_Query
- How to structure plugin in to functions?
- Including a PHP file via a function that is part of a plugin?
- How to disable register and reset the password from WordPress admin panel?
- What is wrong with this dbDelta syntax?
- Call a function with href
- Integrate Razorpay quick payments plugin with contact form7 plugin
- Adding a script & php to functions.php
- Override the plugin class and function
- Activate and deactivate two plugins automatically at certain hours
- Create WordPress category dynamically
- How can I save the selected page in the dropdown after anyone clicks on Save Changes?
- How can I save the selected page in the dropdown after anyone clicks on Save Changes?
- add to cart linking to add to cart page
- Simple ajax request with Vanilla JS keeps given 400 Bad Request