Last active
August 29, 2015 14:00
-
-
Save cfoellmann/11182065 to your computer and use it in GitHub Desktop.
Auto-(De-)Activate 'The Events Calendar' with 'The Events Calendar Pro' + hide 'The Events Calendar' from plugins.php listing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class EventsConnector { | |
var $events_calendar; | |
public function __construct() { | |
$this->events_calendar = 'the-events-calendar/the-events-calendar.php'; | |
$events_calendar_pro = WP_PLUGIN_DIR . '/events-calendar-pro/events-calendar-pro.php'; | |
add_filter( 'all_plugins', array( $this, 'hide_plugin' ) ); | |
// activation | |
register_activation_hook( $events_calendar_pro, array( $this, 'test_activation' ) ); | |
register_deactivation_hook( $events_calendar_pro, array( $this, 'test_deactivation' ) ); | |
} // END __construct | |
public function hide_plugin( $plugins ) { | |
unset( $plugins[ $this->events_calendar ] ); | |
return $plugins; | |
} | |
public function test_activation() { | |
if ( is_plugin_inactive( $this->events_calendar ) ) { | |
add_action('update_option_active_plugins', array( $this, 'test_activate_dep' ) ); | |
} | |
} | |
public function test_activate_dep(){ | |
activate_plugin( $this->events_calendar ); | |
} | |
public function test_deactivation(){ | |
if ( is_plugin_active( $this->events_calendar ) ) { | |
add_action( 'update_option_active_plugins', array( $this, 'test_deactivate_dep' ) ); | |
} | |
} | |
public function test_deactivate_dep(){ | |
deactivate_plugins( $this->events_calendar ); | |
} | |
} | |
new EventsConnector(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// When this plugin activate, activate another plugin too. | |
$events_calendar_pro = WP_PLUGIN_DIR . '/events-calendar-pro/events-calendar-pro.php'; | |
add_filter( 'all_plugins', 'test_hide_plugin' ); | |
function test_hide_plugin( $plugins ) { | |
unset( $plugins[ 'the-events-calendar/the-events-calendar.php' ] ); | |
return $plugins; | |
} | |
// activation | |
register_activation_hook( $events_calendar_pro, 'test_activation' ); | |
function test_activation() { | |
$events_calendar = 'the-events-calendar/the-events-calendar.php'; | |
if ( is_plugin_inactive( $events_calendar ) ) { | |
add_action('update_option_active_plugins', 'test_activate_dep'); | |
} | |
} | |
function test_activate_dep(){ | |
activate_plugin('the-events-calendar/the-events-calendar.php'); | |
} | |
// deactivation | |
register_deactivation_hook( $events_calendar_pro, 'test_deactivation' ); | |
function test_deactivation(){ | |
$events_calendar = 'the-events-calendar/the-events-calendar.php'; | |
if ( is_plugin_active( $events_calendar ) ) { | |
add_action( 'update_option_active_plugins', 'test_deactivate_dep' ); | |
} | |
} | |
function test_deactivate_dep(){ | |
deactivate_plugins('the-events-calendar/the-events-calendar.php'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment