| 1 |
<?php |
| 2 |
|
| 3 |
namespace SpringDevs\Subscription\Admin; |
| 4 |
|
| 5 |
/** |
| 6 |
* Install & Activate required plugins |
| 7 |
* |
| 8 |
* Class Required |
| 9 |
*/ |
| 10 |
class Required { |
| 11 |
|
| 12 |
private $plugin_file = true; |
| 13 |
|
| 14 |
public function __construct() { |
| 15 |
add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_assets' ) ); |
| 16 |
add_action( 'init', array( $this, 'check_plugins' ) ); |
| 17 |
} |
| 18 |
|
| 19 |
public function check_plugins() { |
| 20 |
if ( ! function_exists( 'is_plugin_active' ) ) { |
| 21 |
include_once ABSPATH . 'wp-admin/includes/plugin.php'; |
| 22 |
} |
| 23 |
|
| 24 |
$plugin_file = WP_PLUGIN_DIR . '/woocommerce/woocommerce.php'; |
| 25 |
|
| 26 |
if ( ! file_exists( $plugin_file ) ) { |
| 27 |
$this->plugin_file = false; |
| 28 |
} |
| 29 |
|
| 30 |
if ( ! file_exists( $plugin_file ) || ! is_plugin_active( 'woocommerce/woocommerce.php' ) ) { |
| 31 |
add_action( 'admin_notices', array( $this, 'install_plugin_notice' ) ); |
| 32 |
} |
| 33 |
} |
| 34 |
|
| 35 |
public function enqueue_assets() { |
| 36 |
if ( ! wp_style_is( 'sdevs_installer' ) ) { |
| 37 |
wp_enqueue_style( 'sdevs_installer' ); |
| 38 |
} |
| 39 |
|
| 40 |
if ( ! wp_script_is( 'sdevs_installer' ) ) { |
| 41 |
wp_enqueue_script( 'sdevs_installer' ); |
| 42 |
wp_localize_script( |
| 43 |
'sdevs_installer', |
| 44 |
'sdevs_installer_helper_obj', |
| 45 |
array( 'ajax_url' => admin_url( 'admin-ajax.php' ) ) |
| 46 |
); |
| 47 |
} |
| 48 |
} |
| 49 |
|
| 50 |
public function install_plugin_notice() { |
| 51 |
if ( $this->plugin_file ) { |
| 52 |
$id = 'sdevs-activate-plugin'; |
| 53 |
$label = __( 'Activate Woocommerce', 'subscription' ); |
| 54 |
} else { |
| 55 |
$id = 'sdevs-install-plugin'; |
| 56 |
$label = __( 'Install Woocommerce', 'subscription' ); |
| 57 |
} |
| 58 |
|
| 59 |
include 'views/required-notice.php'; |
| 60 |
} |
| 61 |
} |
| 62 |
|