Skip to content

Commit

Permalink
clean deactivation
Browse files Browse the repository at this point in the history
  • Loading branch information
Aurovrata V committed Nov 4, 2016
1 parent 8a55f39 commit 21fd93b
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 8 deletions.
1 change: 1 addition & 0 deletions README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ This is because the translation in your language have not be completed. You can
= 1.2.5 =
* Added french translation
* Moved cf7 language files to wp-content/languages folder
* cleaner exist in case either cf7 or polylang plugin is deactivated

= 1.2.4 =
* Updated FAQ!
Expand Down
20 changes: 16 additions & 4 deletions admin/class-cf7-polylang-admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,16 @@ public function __construct( $plugin_name, $version ) {
//public function deactivate_cf7_polylang( $plugin, $network_deactivating ) {
public function check_plugin_dependency() {
//if either the polylang for the cf7 plugin is not active anymore, deactive this extension
if(is_plugin_active("cf7-polylang/cf7-polylang.php") && (!defined ("POLYLANG_VERSION")) ){
if( !is_plugin_active("contact-form-7/wp-contact-form-7.php") || !defined ("POLYLANG_VERSION") ){
deactivate_plugins( "cf7-polylang/cf7-polylang.php" );
wp_die( '<strong>CF7 Polylang Module Extension</strong> requires both <strong>CfF7 & Polylang</strong> and has been deactivated!' );
debug_msg("Deactivating CF7 Polylang Module Enxtension");
}

$button = '<a href="'.network_admin_url('plugins.php').'">Return to Plugins</a></a>';
wp_die( '<p><strong>CF7 Polylang Module Extension</strong> requires both <strong>CfF7 & Polylang</strong> and has been deactivated!</p>'.$button );

return false;
}
return true;
}
/**
* Register the stylesheets for the admin area.
Expand Down Expand Up @@ -199,7 +203,10 @@ public function delete_translations($post_id){
*/
public function polylang_register_cf7_post_type($types) {
//CF7 cpt post type
$post_type = WPCF7_ContactForm::post_type;
include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
$this->check_plugin_dependency();

$post_type = WPCF7_ContactForm::post_type;

$types = array_merge($types, array($post_type => $post_type));

Expand Down Expand Up @@ -338,6 +345,11 @@ public function cf7_new_translation_link($link, $language, $from_post_id ){
* @since 1.0.0
*/
public function get_cf7_translations(){
include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
if(! $this->check_plugin_dependency()){
return;
};

//what locales are already installed
$local_locales = $this->scan_local_locales();
//what are the needed locales
Expand Down
10 changes: 6 additions & 4 deletions includes/class-cf7-polylang-deactivator.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,12 @@ class Cf7_Polylang_Deactivator {
*/
public static function deactivate() {
//remove the CF7 custom post for polylang post types.
$options = get_option('polylang',false);
if( $options && in_array(WPCF7_ContactForm::post_type, $options['post_types']) ){
$options['post_types'] = array_diff( $options['post_types'], array(WPCF7_ContactForm::post_type) );
update_option('polylang',$options);
if( is_plugin_active("contact-form-7/wp-contact-form-7.php") && defined ("POLYLANG_VERSION") ){
$options = get_option('polylang',false);
if( $options && in_array(WPCF7_ContactForm::post_type, $options['post_types']) ){
$options['post_types'] = array_diff( $options['post_types'], array(WPCF7_ContactForm::post_type) );
update_option('polylang',$options);
}
}
}

Expand Down

0 comments on commit 21fd93b

Please sign in to comment.