| 1 |
<?php |
| 2 |
namespace EmailKit\Admin; |
| 3 |
|
| 4 |
use EmailKit; |
| 5 |
|
| 6 |
defined("ABSPATH") || exit; |
| 7 |
|
| 8 |
class Dependency { |
| 9 |
|
| 10 |
const INACTIVE = 'inactive'; |
| 11 |
const ACTIVE = 'active'; |
| 12 |
const NEED_INSTALL = 'install'; |
| 13 |
|
| 14 |
|
| 15 |
public static function check(string $plugin) { |
| 16 |
|
| 17 |
|
| 18 |
$dependency = self::dependency_list($plugin); |
| 19 |
if($dependency){ |
| 20 |
if(!empty($dependency['status']) && $dependency['status'] == self::INACTIVE) { |
| 21 |
return $dependency['active']; |
| 22 |
} else if(!empty($dependency['status']) && $dependency['status'] == self::NEED_INSTALL) { |
| 23 |
return $dependency['install']; |
| 24 |
} |
| 25 |
} |
| 26 |
|
| 27 |
return true; |
| 28 |
} |
| 29 |
|
| 30 |
|
| 31 |
public static function dependency_list(string $dependency = ''): array { |
| 32 |
|
| 33 |
|
| 34 |
if(!function_exists('is_plugin_active')){ |
| 35 |
// Include necessary WordPress files |
| 36 |
require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
| 37 |
|
| 38 |
} |
| 39 |
|
| 40 |
$dependency_list = [ |
| 41 |
'wordpress' => [ |
| 42 |
'status' => self::ACTIVE, // by default wordpress is active |
| 43 |
'install' => [ |
| 44 |
'label' => '', |
| 45 |
'url' => '', |
| 46 |
], |
| 47 |
'active' => [ |
| 48 |
'label' => '', |
| 49 |
'url' => '', |
| 50 |
] |
| 51 |
], |
| 52 |
'saved-templates' => [ |
| 53 |
'status' => self::ACTIVE, // save templates have dependency |
| 54 |
'install' => [ |
| 55 |
'label' => '', |
| 56 |
'url' => '', |
| 57 |
], |
| 58 |
'active' => [ |
| 59 |
'label' => '', |
| 60 |
'url' => '', |
| 61 |
] |
| 62 |
], |
| 63 |
'woocommerce' => [ |
| 64 |
'status' => (file_exists(WP_PLUGIN_DIR.'/woocommerce/woocommerce.php') ? (is_plugin_active('woocommerce/woocommerce.php') == false ? self::INACTIVE : self::ACTIVE) : self::NEED_INSTALL), |
| 65 |
'install' => [ |
| 66 |
'label' => esc_html__('Install WooCommerce', 'emailkit'), |
| 67 |
// 'url' => wp_nonce_url(self_admin_url('update.php?action=install-plugin&plugin=woocommerce'), 'install-plugin_woocommerce'), |
| 68 |
'url' => self_admin_url('plugin-install.php?s=woocommerce&tab=search&type=term'), |
| 69 |
], |
| 70 |
'active' => [ |
| 71 |
'label' => esc_html__('Activate WooCommerce', 'emailkit'), |
| 72 |
'url' => ('plugins.php?plugin=woocommerce'), |
| 73 |
] |
| 74 |
], |
| 75 |
]; |
| 76 |
|
| 77 |
return $dependency_list[$dependency] ?? []; |
| 78 |
} |
| 79 |
} |