Skip to content

Commit

Permalink
WPCIVIUX-107 fix dependency check for network activated CiviCRM
Browse files Browse the repository at this point in the history
  • Loading branch information
agileware-fj committed Oct 7, 2021
1 parent de38755 commit 7fa9a77
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 18 deletions.
20 changes: 7 additions & 13 deletions civicrm-ux.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* Plugin Name: WP CiviCRM UX
* Plugin URI: https://github.com/agileware/wp-civicrm-ux
* Description: A better user experience for integrating WordPress and CiviCRM
* Version: 1.8.4
* Version: 1.8.5
* Requires at least: 5.8
* Requires PHP: 7.4
* Author: Agileware
Expand All @@ -26,28 +26,22 @@
* Start at version 1.0.0 and use SemVer - https://semver.org
* Rename this for your plugin and update it as you release new versions.
*/
define( 'CIVICRM_UXVERSION', '1.8.4' );
define( 'CIVICRM_UXVERSION', '1.8.5' );

// If this file is called directly, abort.
if ( ! defined( 'WPINC' ) ) {
die;
}

// check CiviCRM activated
$active_plugins = apply_filters( 'active_plugins', get_option( 'active_plugins' ) );
if ( ! in_array( 'civicrm/civicrm.php', $active_plugins ) ) {
deactivate_plugins( plugin_basename( __FILE__ ) );
add_action( 'admin_notices', 'agileware_caldera_forms_magic_tags_child_plugin_notice' );
}
add_action( 'admin_init', function() {
if ( ! is_plugin_active( 'civicrm/civicrm.php' ) && function_exists('deactivate_plugins') ) {
add_action( 'admin_notices', 'agileware_caldera_forms_magic_tags_child_plugin_notice' );
}
});

require_once plugin_dir_path( __FILE__ ) . 'vendor/autoload.php';

function fail_check_dependency_civicrm_ux() {
?>
<div class="error"><p>Sorry, plugin CiviCRM UX requires the CiviCRM plugin
to be installed and active.</p></div><?php
}

/**
* The code that runs during plugin activation.
* This action is documented in includes/class-civicrm-ux-activator.php
Expand Down
7 changes: 2 additions & 5 deletions includes/class-civicrm-ux-activator.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,13 @@ class Civicrm_Ux_Activator {
* @since 1.0.0
*/
public static function activate() {
if ( ! self::check_dependency() ) {
if ( !self::check_dependency() && function_exists( 'deactivate_plugins' ) ) {
deactivate_plugins( plugin_basename( __FILE__ ) );
wp_die( __( 'Please install and Activate CiviCRM.', 'civicrm-ux' ), 'Plugin dependency check', array( 'back_link' => true ) );
}
}

public static function check_dependency() {
// TODO
$active_plugins = apply_filters( 'active_plugins', get_option( 'active_plugins' ) );

return in_array( 'civicrm/civicrm.php', $active_plugins );
return is_plugin_active( 'civicrm/civicrm.php' );
}
}

0 comments on commit 7fa9a77

Please sign in to comment.