I’d recommend to not use methods from your theme in the plugins. Only the other way around. Let your plugins provide methods to be used in the theme. Then you could simply use is_plugin_active()
.
Nonetheless you could use PHP’s class_exists()
to check for the existence of a class. Another common practice seems to be to let your plugin die;
at the very top before anything else can be loaded.
<?php
/*
Plugin Name: My Plugin
Description: Lorem ipsum dolor sit amet.
Version: 1.0
Author: You
Author URI: https://example.com
*/
if ( ! class_exists('MyThemeClass') ) {
die;
}
class MyPlugin() {
// ...
}
new MyPlugin;
Related Posts:
- Objective Best Practices for Plugin Development? [closed]
- How to get the path to the current theme?
- Inserting Taxonomy Terms During a Plugin Activation?
- Replace audio/video enclosure with player?
- wp_mail is undefined
- How do you use the plugin boilerplate loader class to hook actions and filters?
- Contact Form 7: wp_mail doesn’t work after update to 4.6
- Build path for a custom portfolio plugin
- How to save block attributes when the output doesn’t change
- Gutenberg ServerSideRender is deprecated, how to work with new wp.serverSideRender component?
- How to: Rest endpoint returning empty object
- Ensuring a plugin is loaded/run last?
- Turn revisions off in plugin instead of config.php?
- Add an image gallery to a custom post type?
- Script to remove all inactive widgets?
- Plugin options table,is the data serialized
- Disable $title in Plugin Options Screen?
- WordPress Localization and Templating
- Converting theme widgets to plugins?
- Sample — test — data for large WordPress install
- DIR vs URI when defining a path to a file
- Why after a file is programmatically deleted, is there still a reference in the media library?
- WP_LOCALIZE_SCRIPT doesn’t work
- JS / JQuery form validation in backend admin menus
- My new WordPress plugin version is not showing up in the plugin directory. It’s been 4 days what could the problem be?
- Is using register_activation_hook required?
- Synchronize Custom post type tags to WordPress default posts tags
- Tabbed navigation for plugin options using same row in database for all?
- Ethics question: what qualifies as a fork? [closed]
- How to send email in wordpress with more than one attachments
- How can I prevent my plugin’s next version from updating one of the files?
- How to i18n text coming from the db or from an external source
- Modify users.php page to create page/post on button clicked
- Is there an action like ‘after_register_custom_post_type’?
- get_current_screen() return null
- Frontend language per user
- ORDER BY wp_post custom column name in wp_query
- Check for template part, else filter content
- How to stop your plugin from executing on certain pages?
- Is it necessary to sanitize plugin options?
- Search the product by tag or category not working
- Is it possible to make sure that only my plugins output is shown to the enduser?
- How to filter content for specific content variable
- PowerPress mobile media player
- You do not have sufficient permissions to access this page on a submenu
- add javascript files only when plugin is called?
- wp_dropdown_roles() to replace option value = code
- WordPress function get_the_terms() returns ‘Invalid taxonomy’ error
- Trying to Implement .pdf File Upload in Admin for plugin
- Writing a wordpress plugin and trying to include the Facebook PHP SDK
- Codex Version Focus on Production or Nightly?
- Make a plugin page out of influence of the theme’s style
- How to cancel update messages from a changed plugin
- 400 Bad Request, in wordpress theme development, wp_ajax
- Fatal error: Uncaught Error: Call to undefined function convert_to_screen()
- how to get the post id in plugin
- Multiple array for post_content on plugin activation
- Using AND and bracket grouping in SQL not working
- Taxonomy archive page listing terms instead of posts
- How to call code when adding WooCommerce menu items via woocommerce_account_menu_items
- Check if the current user is author of first comment
- How do I force a download in the admin area?
- add_action wp_ajax_ not loading in plugin file WP Network
- Plugin creation, restricting access to specific roles
- How to avoid conflict of plugin style and theme style?
- How to move an image in a plugin to the upload directory and make it as a media of wordpress?
- Is it possible for two WordPress plugins to share the same code base?
- Configuring Xdebug with docker compose
- wp.media libary pdf type
- Add multiple checkboxes as single field to Custom Shipping Method Settings Page
- register_meta not showing custom post type metabox data in rest api
- Save meta box data from selected dropdown list in bbpress reply form
- Events Manager: Create custom Placeholder for use in Email notification
- Get the current post/page URL with plain permalinks
- Using the same class across multiple functions
- ajax multiple Values
- Change Label of custom post type
- woocommerce add a new bulk action in the bulk actions dropdown in the orders list
- Ajax Response Error | just getting error as the response
- admin-ajax.php returns “No Script Kiddies!” sometimes
- Widget won’t be activated
- Building WordPress Themes With Bootstrap with Adi Purdila → TutsPlus
- Plugin outputs content of posts unbidden!
- Need to change buddypress profile url by add_rewrite_rule
- Generate activation url
- Use different archive template for plugin
- Client Profiles
- Saving multiple fields as array
- Serialized Data
- Update custom settings field in plugin
- URL rewrite parameter lost (add_rewrite_rule)
- PHPUnit Ajax Serialization of ‘Closure’ is not allowed
- Settings API not Saving to Database or Display
- Error using @wordpress/create-block to create multiple blocks on Windows
- Help interpreting @wordpress/create-block-tutorial-template usage error
- Leveraging Core Functionality in Icon Upload Plugin [closed]
- How can I chanage the user for the composer container in wp-env?
- Adding a navigation with wp_nav_menu() to a custom block in the site editor
- Why isn’t custom sidebar panel not showing up in the Gutenberg Editor?
- Ninja Forms: Front-End Forms, Post ID?