17

To test the current system for required featurs like PHP version or installed extensions you can use something like that: <?php # -*- coding: utf-8 -*- /** * Plugin Name: T5 Check Plugin Requirements * Description: Test for PHP version and installed extensions * Plugin URI: * Version: 2013.03.31 * Author: Thomas Scholz * Author URI: http:...


9

Note: After writing this, I submitted a trac ticket, only to be told that this one already existed. @OneTrickPony's answer didn't work forme, and after inspecting the source (specifically deactivate_plugins()) I found why: Let's suppose B depends on A, and A is deactivated by the user. WordPress calls deactivate_plugins(A). This function does the ...


4

You shouldn't cleanup the database on the deactivation hook. As @Darhazer said, use the uninstall hook or create an uninstall.php inside the plugin folder. What you can do is to create an export settings page, which the user can use to save/backup his data. You could call this page before deativation, so the user will be prompted with an option to save the ...


4

That would be: remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_title', 5 ); You can read about it here: remove_action Codex


3

Actually, there's a better way. All of my plugins require PHP5. Until recently, that wasn't a requirement in WordPress, so a lot of people tried to install my plugins on systems missing vital PHP functions. I added some checks to my plugin to make sure it would work and, if not, display a message. But I keep the plugin active. It just doesn't function. ...


3

The following code will reset a WordPress default role to it's default capabilities. Note: these defaults are for WordPress 3.5, any other versions might have different defaults. To be safe, only use this code on WordPress 3.5. Warning This cannot be undone! The role, in it's current state, is removed and recreated with it's default values. /* * example ...


3

Method 1 You can use activate_plugin() and deactivate_plugins() to activate/deactivate plugins programmatically. If you want to control the time at which those actions happen, then you can use wp_schedule_event() too. Method 2 I know you asked about PHP, but if you have WP-CLI installed on your server, you can also write a script that uses wp plugin ...


3

As far as I know, a plugin can be deactivated in these conditions: manual deactivation failed plugin upgrade remove or rename the containing folder changing the active plugin list in the database Hopefully someone else will come through and add to this if I missed any.


2

Use uninstall hook to delete all settings. On deactivation you can move temporary some data that was inserted in the plugin, like menu items, etc., but keep plugin settings active.


2

It's a bit of a guessing game without error reports. Here are a few ways to collect info which will help you or others diagnose the cause: Turn on WP-Debug: WordPress WP DEBUG Codex page *Be careful if your site is live if you choose to use define('WP_DEBUG', true); in you wp-config.php file, by default the errors will be visible on the live site. WP-...


2

You may need to have this line in your code require_once( ABSPATH . 'wp-admin/includes/plugin.php' ); The plugin.php file is not automatically included.


2

Here's my bare-bones template that I use when creating a plugin with OOP. Feel free to modify to your liking. Template if ( !defined( 'ABSPATH' ) ) exit; // Exit if accessed directly if ( !class_exists( 'MyPluginName' ) ) { class MyPluginName { public function __construct() { // Call your actions/filters here add_action( 'tag', ...


2

So the 'activate_plugin' was a typo in the question. But even so, as a friendly reminder (for all of us), activate_plugin() is an existing function in WordPress. And you should use unique prefix in your custom functions (that are defined in the global scope): function my_plugin_activate_plugin() { ... } register_activation_hook( __FILE__, '...


1

This entire approach is backwards. The problem is not deactivating on theme switch, but making sure the plugin isn't available unless the theme it was built for is active. So, the check should be in the plugin, not the theme So lets start by figuring out which theme is active, we can do this via wp_get_theme documented here We then Register a hook in our ...


1

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' === $...


1

Depends the way you want to implement it. The static is used because you don't have to instantiate the class to use the functions of the class. It's up to you. I generally would do: <?php /*it's good practice that every class has its own file. So put it in for example 'classes/class-hooks.php' and require it properly in your plugin file. */ class Hooks{...


1

What @Sumit says in the comments (and you found out for yourself) is correct. If you deactivate a plugin in a theme it is deactivated permanently, until it is activated again. Also, if you attach your deactivation action to wp_head it is executed at every pageload, which is not necessary. What you need to do is deactivate the plugin when the theme is ...


1

Use a plugin to manage roles, not a theme. Roles are not for presentation. In your plugin use register_activation_hook() and register_deactivation_hook() to add or remove new roles. Do not remove built-in roles, other plugins may rely on their existence.


1

You can add the bp_core_signup_send_activation_key filter to prevent the activation email being sent as follows add_filter('bp_core_signup_send_activation_key', 'my_bp_core_signup_send_activation_key', 10, 5); function my_bp_core_signup_send_activation_key($send, $user_id, $user_email, $activation_key, $usermeta) { return false; }


1

I have implemented a workaround with JavaScript. I'm loading my own JavaScript file: wp_enqueue_script('wp-deactivation-message', plugins_url('js/message.js', dirname(__FILE__)), array()); which contains a script that adds following Event Listener - when user clicks on our plugin deactivate button it prevent it from performing this action and display a ...


1

Yes, custom post types are registered on the fly, on every request. So you can create an option, say active_custom_post_types and check for that before you register the post type. Pseudo-code: $possible_cpts = array( 'book', 'portfolio' ); $active_cpts = get_option( 'active_custom_post_types' ); if ( ! empty ( $active_cpts ) && is_array( $...


1

I would start by looking into the set_user_role action hook. You would be passed 3 arguments to your callback function - the User ID, the new user role, and an array of the old user roles(that seems strange to me, that you can't pass an array of roles, but oh well). So here's an example code - I'm not certain for how you would get the sites that the user ...


1

You've got to actually check is_plugin_active. I would use something more like this, shamelessly stolen and modified from here: register_activation_hook( __FILE__, 'dependentplugin_activate' ); function dependentplugin_activate() { require_once( ABSPATH . '/wp-admin/includes/plugin.php' ); if ( is_plugin_active( 'nextgen-gallery/nggallery.php' ) ) {...


1

Quick and easy. if ( is_plugin_active( 'plugin-folder-name/main-plugin-file.php' ) ) deactivate_plugins( '/plugin-folder-name/main-plugin-file.php' ); It's important to note the is_plugin_active string is slightly different than the deactivate_plugins string.


Only top voted, non community-wiki answers of a minimum length are eligible