Plugins are loaded before functions.php. You should include the class in your plugin if possible.
I have had scenarios where a class was part of the theme, but also needed in a plugin where you couldn’t assume the class was included in the theme. In those cases, I simply included the class in both places and wrapped it in a “class exists” check.
Like this:
if(!class_exists('My_Class'))
{
class My_Class{
// Class Methods and Properties
}
}
You could also include the class only once in MU Plugins, which is loaded before the other plugins.
Related Posts:
- Customizing subject in comment notification e-mails
- Placement of Code in Plugin for hooking `save_post`
- Using a post-signup hook to get user details
- The function called on the wp head hook becomes null
- plugin not hooking to my custom hook
- When can you get current page ID and initialize hooks right after?
- WP showing “warning: call_user_func_array()”, What to do?
- How to Loop Plugin Option Field Set?
- Using the ‘draft_to_publish’ hook (post status transition)
- 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
- Execute a function using ajax
- Failed to invoke other hook from the init hook
- How can I add a custom meta value on file upload?
- Adding dynamic section to WordPress
- Use functionality of 2 wordpress plugins
- What is the function to get plugin base url in multisite?
- How can I filter blog name?
- Showing Notifications While Activating 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
- Determine plugin name from within plugin_action_links filter
- Override the core function locate_template
- I would like to use create a function in my custom plugin to tell WP to use a different header
- publish_post plugin hook doesn’t always pass $post->post_content
- add_action in functions.php, do_action in plugin?
- The Point of Using apply_filters()
- How to get variables from fucntion.php to my plugin files
- How to include code into functions.php file via a plugin
- Avoiding Duplicate function names in Post Loop (WP_Footer script)
- add action for displaying posts using a shortcode
- ‘wp_login’ action hook not working with wp-login.php file
- How to add class in plugin only for network site?
- Pass info from functions.php to plugin
- WordPress Plugin Page is Loading in Admin Content Container Instead of Separate Page
- Remove rewrite rules generated by plugin during deactivation
- Where (or when) should I register a new taxonomy?
- How to stop activating a plugin and show admin notice when dependent plugins minimum version is not met
- Calling plugin function inside custom plugin for onclick event
- get current date + 90 days and checking every day
- Are functions in main plugin file called before function bound to register_activation_hook runs?
- Difference and examples of esc_attr__() and esc_attr_e()
- Redirect to another page using contact form 7? [closed]
- List the authors that have written posts in a category
- Create a post builder skin in a plugin
- Plugin Development – Functions or Hooks?
- Hook for page Request?
- How do I add $_SESSION[”] to my wordpress page?
- How to remove a class function from a plugin by using remove_action()?
- strange shortcode error: does shortcodes requires any dependency?
- How to access OOP plugin function inside themes or other plugin
- Hook for altering the content of all wp mails
- Quick press publish post hook
- Different registration form for different roles
- How can i list random author?
- More gentle way to hook WordPress custom url
- How to deactivate my plugin upon deactivation of NextGen
- Creating a plugin that will display text on every page
- auto activate plugin when theme is active
- Build a must-use plugin that tracks when other plugins are activated or deactivated
- Activation flow of a plugin in a multisite environment
- Checkbox show / hide output result
- How to keep plugin (media-sync) running even the tab is closed?
- Where do I put the code snippets I found here or somewhere else on the web?
- Error using wordpress functions inside a plugin class
- How to copy the all WordPress media items to another custom plugin folder?
- Fatal error “Call to undefined function is_plugin_active” each time the plugin is activated
- function post to trash problem
- Custom Plugin: How to Include Install Buttons of other 3rd Party Plugins?
- adding dynamic/multiple slug values in ‘option_none_value’
- front end editor creation for Restropress plug in – displaying information from a WP admin area, on a different URL
- working code, not working – Plugin Dev
- how override a define
- Use action, filter, or hook to append HTML to WordPress plugin function
- Passing function into add_action always returns the first argument
- Hook to display element as product on category page
- register_activation_hook doesn’t fire at all
- My ajax request don´t work and return 0
- WordPress Add advertising ads befor and after content with periority [closed]
- Populate select option with JSON file
- Can plugin automatically update if i hide the update notification?
- how to create table during plugin installation in side a class
- Plugin hook breaks new WP 4.0 media library grid view?
- Saving plugin data returns “You do not have sufficient permissions to access this page.”
- How to add a handler for a button in plugin?
- Can anyone tell me why I can’t edit a plugin when it is installed without having to re-install?
- How to create and use Custom hooks
- Custom Function for SEO by Yoast plugin
- Doing action based on input from options menu
- Call current post parameters inside a plugin
- How to list posts that appear in two categories
- Checking url from plugin [duplicate]
- Pass strings to plugin function [closed]
- WordPress Hooks : Where to place callbacks that repetitively yield the same effect?
- How to Add Extra Text In WordPress Title Before Post Publish
- How can I save the selected page in the dropdown after anyone clicks on Save Changes?
- Gravity Forms and Gravity View Permissions
- How can I save the selected page in the dropdown after anyone clicks on Save Changes?
- wp_enqueue_script doesn’t load JS in plugin
- Why is my activator class adding the files/running the actions I add?