Ryan McCue had a nice idea for his plugin Hopper: add a callback for a custom filter to return the current instance.
Sample code for the plugin:
class Plugin_Class {
public function __construct()
{
add_filter( 'get_plugin_class', array ( $this, 'provide_instance' ) );
}
function provide_instance() {
return $this;
}
}
In a theme or a second plugin you can access the instance now like this:
$plugin_class = apply_filters( 'get_plugin_class', NULL );
if ( is_a( $plugin_class, 'Plugin_Class' ) )
{
// use the plugin class instance
}
Related Posts:
- Change Password Hint
- Dynamic URL to reference custom PHP files
- Second select list values are not saved after clicking update
- Use wc_enqueue_js only on specific pages – nested add_action
- How to use a frontend URL with a Plugin
- WordPress template_include filter not working properly
- Theme url in all plugin pages
- “The plugin generated 2694 characters of unexpected output…” on Plugin activation, CREATE TABLE sql command not working
- How to display a value from a radio button in the options menu in wordpress
- How to access function from outside of a class within this class in WP plugin?
- How to call function at the bottom of post using plugin?
- Adding Default Settings to Theme My Login plugin
- Hide categories that are not used in the post type
- Automated Cart Update With Alert Box Each Time
- WordPress ajax doesn’t display object method on jQuery .change() function
- what is the best practice to add new field to an api route
- filter default query to show just selected level of child pages in wordpress
- Use custom post type for a store locator
- How do I programmatically set a user as spam in BuddyPress? [closed]
- How to make my custom widget appear within WordPress widgets? Plugin development
- Adding widgets to my plugin page instead of WordPress dashboard
- WP CRON duplicate wp_insert_post with has < and > tag
- How to insert data into database using wp cron job
- How to send Ajax request from my plugin in admin dashboard?
- AJAX success response is not working but it’s saving my changes
- Best practice for show data to one specific user?
- How can I hide that I Use WordPress (with W3 Total Cache)
- Saving plugin settings – ERROR: options page not found
- class_exists returns different values [closed]
- Can’t print Yoast meta description into page template (syntax error, unexpected ‘.’) [closed]
- Asynchronous multiple requests 401 Unauthorized
- Custom array from a query only write the last row of the query
- Using data sent via AJAX in multiple functions on a WP plugin
- Is it possible to define variables in a wordpress shortcode, and then call the shortcode using a specific variable?
- What does -> mean in WordPress?
- Change product_base programmatically
- How to remove the message ‘We could not find any results for your search’ without changing template files and without adding posts/pages?
- How to add the sidebar to all the pages except the home page? [closed]
- Custom meta box values are not getting saved for my custom post type
- Plugin development and composer
- Can’t upload CSV file to plugin directory using custom upload form in admin panel
- Validate and Sanitize WP REST API Request using WP JSON Schema?
- Set default Database Storage Engine when creating tables with plugins?
- custom post type with role Vendor
- Can I remove or edit an include() from a function with a filter?
- Call to undefined function error in plugin
- How do I make this Metabox show current DB value?
- Execute Jquery when a specific page in my plugin is loading
- Get category id when SEO URL is turned on
- Using ACF Relationship field to set post type to draft or published status
- WordPress can’t use ZipArchive
- How to extend SelectControl with data from my theme
- Only the first image uploads
- WordPress loading progess – wp-blog-header.php
- Illegal string offset checkbox
- Custom plugin: how do I call a PHP file if settings option is set to true?
- Trying to use a variable to set image width
- How can i avoid duplicate same post in wp?
- wp_update_post gives 500 internal error
- How do I disable cache for a certain page?
- How to check if plugin update process completed in wordpress?
- How to identify which php file a plugin is using on page load?
- dashboard widget form not submit mails
- register_setting not save checkbox
- using filter and hook inside class
- How does one make a URL return dynamic JSON with custom Content Type?
- How to give custom roles the capability to edit one Menu instead of every Menu
- Priority call methods – PHPMailer->addAddress(NULL)
- How to properly escape in ternary operators – Wp Coding Standards?
- Add Admin Option w/ Anonymous Function
- add menu page in loop menu order
- defined (‘ABSPATH’) false after AJAX post to other PHP-file
- How to send logs to plugin owner for a plugin?
- Force CSV download with template_redirect
- How to use foreach and if statement within array of arrays?
- widget: input the px value from user and use it as inline style in widget function
- Custom post type single page return to listing page
- WordPress rewrite question
- Using Nonce for my Form
- Create new folder and upload files to custom folder via wp_handle_upload
- How to edit the default database of WordPress [closed]
- Cookie not created in AJAX request
- How to automatically convert images to WebP on WordPress?
- Check user last login date
- Transate plugin with js & wp_localize_script
- WP Custom tables query
- Import js variables loaded via wp_localize_script() into js module without global scope connection
- Redirect users by role to custom pages
- Query posts by custom taxonomy slug in WP REST API?
- oneOf JSON Schema validation not properly working for custom post meta value?
- Too few arguments at registering new templates in my plugin
- I want to lists posts in wordpress to nearest location entered by the user
- getJSON response to PHP
- Custom plugin with shortcode not working
- wp_register_script – illegal string offset
- How can I modify the html output of a custom post type admin page?
- how to escape alert/window.location.replace with variable
- Translate string in another langage than Locale
- Integrate a Custom Post Type with Learndash Plugin
- Remove slug of multiple custom post types with and without hierarchical