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 can i display post loop in table format?
- 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
- Access Child Class of Plugin Main Class Instance
- Best practice for show data to one specific user?
- Font Awesome changing default WordPress Font
- Can’t print Yoast meta description into page template (syntax error, unexpected ‘.’) [closed]
- Download full html page with CSV export plugin
- Asynchronous multiple requests 401 Unauthorized
- Using data sent via AJAX in multiple functions on a WP plugin
- What does -> mean in WordPress?
- Usage of call back function of add_meta_box()
- Change product_base programmatically
- How to add the sidebar to all the pages except the home page? [closed]
- how to save checkbox data for custom setting?
- WordPress shortcode returns the data before
- Plugin development and composer
- How to Schedule Cronjobs for start of every month and year
- Set default Database Storage Engine when creating tables with plugins?
- WordPress WP_Query without query GET parameters
- Where to copy woocommerce files to in my custom theme to avoid editing the core plugin?
- custom post type with role Vendor
- Execute Jquery when a specific page in my plugin is loading
- How can I get plugin meta data without knowing the plugin folder?
- Flatten Responses returned via WP REST API via WP_Error for obfuscation
- How does add_option() function enable action hooks to fire right after actiavtion?
- Ajax on the Administration Side of plugin – wp_localize_script – how to pass value from JQuery to PHP function in class?
- Create plugin with custom page and template caused an error `Call to undefined function get_header()`
- WordPress can’t use ZipArchive
- Settings API form – submit with AJAX
- How to change basename url for wp-admin?
- 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
- wp_update_post gives 500 internal error
- Submit remote form to wordpress REST API and save data to custom post type
- Foreach Loop Of Post Types With Nested If Else If Not Completing Process
- How to identify which php file a plugin is using on page load?
- dashboard widget form not submit mails
- In a foreach loop, how can I add a meta value if it doesn’t exist?
- Looping through and combining calls to Woocommerce REST API
- Should I use wp_cache in my plugin to make it faster?
- register_setting not save checkbox
- How to import woocommerce custom fields data into another site?
- Add a custom link to each image in WordPress gallery
- When I create a new custom post type, it replaces the old post type
- 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
- add menu page in loop menu order
- Add .php to end of all WordPress Pages (multisite)
- defined (‘ABSPATH’) false after AJAX post to other PHP-file
- Getting Member Data From WhishList Member on Register
- Private messaging – Getting and displaying the avatar/url of a message recipient
- global $post inside plugin query messes up every new post page in wp-admin
- wp_query (or hook) posts by date (id) in array then set post_type
- Chosen Select jquery Not Working in Plugin
- widget: input the px value from user and use it as inline style in widget function
- PHP calling function within a class
- 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
- Can’t remove menu items added by plugin
- Issues separating my Plugin pages into different files
- SHARING TO FACEBOOK – FROM DYNAMICALLY GENERATED PAGE
- How to hide Ads From Certain Categories?
- Custom field fetch error on woocommerce pdf invoice
- Implement OAuth2 in custom plugin
- login redirect based on user role not work as expected
- redirect user from login page if is logged
- How to pass and validate nonce in custom REST routes
- How to lock users account until approvation
- Variable ++ in query loop
- ajax problems on loading page [closed]
- WordPress REST API – Custom field not added to pages