Deactivate a plugin on wp version

The problem is not version_compare, the problem is that register_activation_hook is just a shortcut for add_action( ‘activate_’ . $file, $function ); where $file is plugin_basename( __FILE__ ); and __FILE__ is your main plugin file absolute path. So, what your code does is to call dw_deactivate_theme_options() when the action ‘activate_’ . $plugin is fired. But this … Read more

WordPress Plugin Activate / Deactive Failing

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__, ‘my_plugin_activate_plugin’ ); The Problem … Read more

how to deactivate a plugin without using a WP function?

The simplest way is probably renaming the plugin file or folder. But if you’re trying to handle it directly from the database, you’d have to grab the ‘active_plugins’ value from the wp_options table, unserialize it, remove your plugin from the array and reserialize it and update. You don’t necessarily have to use update_option. You could … Read more

Turn on and off custom post type from admin?

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( $active_cpts ) ) { … Read more

Prevent a plugin from being automatically activated

You might want to add your own plugin to deactivate their plugin (silently). First open their main plugin file and see where the plugin hooks (or filters) in. Then unhook their plugin … and your’s as well. <?php /** Plugin Name: Deactivate other plugin */ add_action( ‘the_same_hook’, ‘removeOtherPlugin’, PHP_INT_MAX -1 ); function removeOtherPlugin() { remove_filter( current_filter(), … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)