I haven’t tested this, so it might not work correctly, but the essence of what you’re trying to do is hook into the after_switch_theme
hook and see if the $old_name
is DahTheme. If it is, that means that the current theme isn’t DahTheme, so you want to deactivate the plugin.
function wpse_after_switch_theme( $old_name, $old_theme ) {
if( 'DahTheme' === $old_name ) {
//* You may or may not need to include wp-admin/includes/plugin.php here
deactivate_plugins( 'dahplugin/dahplugin.php' );
}
}
add_action( 'after_switch_theme', 'wpse_after_switch_theme', 10, 2 );
Related Posts:
- disable active plugins for specific theme
- OOP: Display warning and deactivate the plugin if PHP version is less than 5.4
- add_action in functions.php, do_action in plugin?
- Plugin Deactivate Self on Activation Errors
- Prevent a plugin from being automatically activated
- Hooking in to replace the Sidebar/Widget areas
- How to get menu location in wp_update_nav_menu hook
- How to deactivate my plugin upon deactivation of NextGen
- Hooking into the HTML header container
- Is it possible to disable a theme programmatically?
- wp_login_form() ignoring login_form action hook
- to perform the requested action wordpress needs to access your web server. please enter your ftp
- How can I see all the actions attached to an “add_action” hook?
- Hide prices and checkout functionality in woocommerce
- How do I exclude plugins from getting automatically updated?
- How can I create a bash install script for my WordPress sites setup (WP+plugins+theme)?
- Shared functionality in plugins and themes
- Schedule WordPress Auto-Updates to only run during business hours
- Remove action from plugin on other plugin
- How To Determine If A Filter Is Called In A Sidebar/Widget Context?
- Filter Hook on plugin update
- WordPress Hook that will run when media file deleted
- Disallow a user to post in certain categories
- Intercepting a add_action
- Generic plugin (de)activation hook?
- Which hook callback has priority if both plugin and theme use the same hook?
- Adding a form at the end of the content
- Use external link in the add sub menu
- Force wordpress to request for FTP Info on theme/plugin install/update
- How can I add a custom meta value on file upload?
- How can I filter blog name?
- Woocommerce Shipping module available only for type of products [closed]
- WordPress Plugin Boilerplate – add_action hook in static “activate” function
- Override the core function locate_template
- publish_post plugin hook doesn’t always pass $post->post_content
- add_meta_box (Will display only in specific page admin WordPress)
- WordPress 5 upgrade: until when is it safe to keep project running in 4.x?
- Installing WordPress only for a separate page – ‘mydomain.com/blog’
- add action for displaying posts using a shortcode
- Randomize attachment IDs
- ‘wp_login’ action hook not working with wp-login.php file
- Where (or when) should I register a new taxonomy?
- Hook (or other way) to find out when another plugin is activated / installed
- Inserting above the comment template
- Insert new user with form submit ‘init’ hook
- How to stop activating a plugin and show admin notice when dependent plugins minimum version is not met
- edit_user_profile and show_user_profile are not firing inside a class
- What exactly happens to function argument availability when using a filter?
- How to check if my wordpress websiste is nulled or not?
- Remove specific plugins and themes from the Dashboard->Updates page [duplicate]
- Combining several CSS files into one for optimization
- Create a post builder skin in a plugin
- How do I add some javascript validation to the admin interface form’s onsubmit?
- Can my hooked uninstall class function access a global var declared in main plugin file?
- Theme Custom Pages
- Hook for page Request?
- How to remove js ui library added by default by wordpress
- How to use the pre_option filter before a plugin loads?
- How to get theme’s info from wordpress.org/themes using api.wordpress.org?
- How to find the list of custom post type where logged in user is author
- How to remove a class function from a plugin by using remove_action()?
- profile_update hook doesn’t works inside a class
- why need theme,if page builder is there in wordpress [closed]
- speed up pagination for huge database
- Plugin: Hooking up classes that have their own hooks
- Hook for altering the content of all wp mails
- What hook can I use to modify custom post data before it is displayed on the page?
- Is it possible for a plugin to prevent certain plugins from being installed?
- How do you create a re-useable HTML fragment in wordpress
- Identify current wordpress theme
- Upgrade not working & themes not supporting
- Why does “updated_post_meta” did not fire when uploading media other than image?
- Change Dashboard URL from wp-admin to wp-admin/index.php
- Can’t load the the canges of field groups [duplicate]
- Javascript console errors and WSOD on edit post pages
- Callback hooked to post_updated firing on new posts as well
- How Can I Create A Form In WordPress For Subscribers To Alert Them about new Listing posted?
- front end editor creation for Restropress plug in – displaying information from a WP admin area, on a different URL
- WordPress site hamburger menu toggle not working
- Link custom post type to page
- How to disable a widget area of a specific page?
- Showing different js file for different theme in wordpress customizer api
- Seeking specific WordPress Layout
- Customize plugin templates
- Hook on widget context plugin to add custom context for widget
- WordPress Theme/Plugin Install (about FTP Connection)
- Admin page and admin menu. Permissions plugin
- WordPress core update fails – no issues with plugin updates
- Why the output of an image gallery plugin is not displayed into a page of my custom theme?
- How to add the functionality of WordPress needed to be installed to be mandatory while installing themes
- How should I use a plugin function as a hook?
- Incentive theme – Getting ’You do not have sufficient permissions’ while trying to install plugins
- How do I make the selected layout display for all MarketPress pages?
- How to create and use Custom hooks
- Can’t get custom user meta to show in header
- Is it possible to run javascript on plugin deactivated?
- How to display a link in the footer section
- How to make only selected posts appear on a selected wordpress page
- wordpress illegal string offset ‘parameter’ error
- Is there a way to stop the theme and especially plugins listed?