| 1 |
<?php |
| 2 |
namespace Emailkit\Admin; |
| 3 |
|
| 4 |
use EmailKit; |
| 5 |
|
| 6 |
defined("ABSPATH") || exit; |
| 7 |
|
| 8 |
class Dependency { |
| 9 |
|
| 10 |
public function __construct() |
| 11 |
{ |
| 12 |
add_action('admin_init', array($this, 'check')); |
| 13 |
} |
| 14 |
|
| 15 |
public function check() { |
| 16 |
$error = false; |
| 17 |
|
| 18 |
// check woocommerce plugin |
| 19 |
if(!did_action('woocommerce_loaded')) { |
| 20 |
add_action('admin_notices', [$this, 'missing_woocommerce']); |
| 21 |
|
| 22 |
$error = true; |
| 23 |
} |
| 24 |
|
| 25 |
if($error) { |
| 26 |
return; |
| 27 |
} |
| 28 |
} |
| 29 |
|
| 30 |
public function missing_woocommerce() { |
| 31 |
|
| 32 |
if(file_exists(WP_PLUGIN_DIR . '/woocommerce/woocommerce.php')) { |
| 33 |
|
| 34 |
$btn['label'] = esc_html__('Activate WooCommerce', 'emailkit'); |
| 35 |
$btn['url'] = wp_nonce_url('plugins.php?action=activate&plugin=woocommerce/woocommerce.php&plugin_status=all&paged=1', 'activate-plugin_woocommerce/woocommerce.php'); |
| 36 |
|
| 37 |
} else { |
| 38 |
|
| 39 |
$btn['label'] = esc_html__('Install WooCommerce', 'emailkit'); |
| 40 |
$btn['url'] = wp_nonce_url(self_admin_url('update.php?action=install-plugin&plugin=woocommerce'), 'install-plugin_woocommerce'); |
| 41 |
} |
| 42 |
|
| 43 |
EmailKit\Admin\Emails\Helpers\Notice\Notice::push( |
| 44 |
[ |
| 45 |
'id' => 'missing-woo', |
| 46 |
'type' => 'error', |
| 47 |
'dismissible' => true, |
| 48 |
'is_required' => true, |
| 49 |
'btn' => $btn, |
| 50 |
'message' => sprintf(esc_html__('Emailkit requires woocommerce Plugin, which is currently NOT RUNNING.', 'emailkit')) |
| 51 |
] |
| 52 |
); |
| 53 |
} |
| 54 |
} |