| 1 |
<?php |
| 2 |
|
| 3 |
namespace Sellkit\Admin\Notices; |
| 4 |
|
| 5 |
defined( 'ABSPATH' ) || die(); |
| 6 |
|
| 7 |
/** |
| 8 |
* Woocommerce not installed. |
| 9 |
* |
| 10 |
* @since 1.1.0 |
| 11 |
*/ |
| 12 |
class Woocommerce_Not_Installed extends Notice_Base { |
| 13 |
|
| 14 |
/** |
| 15 |
* Notice key. |
| 16 |
* |
| 17 |
* @since 1.1.0 |
| 18 |
* @var string |
| 19 |
*/ |
| 20 |
public $key = 'sellkit-woocommerce-not-installed'; |
| 21 |
|
| 22 |
/** |
| 23 |
* Construct of class. |
| 24 |
* |
| 25 |
* @since 1.1.0 |
| 26 |
*/ |
| 27 |
public function __construct() { |
| 28 |
parent::__construct(); |
| 29 |
|
| 30 |
$this->assets(); |
| 31 |
|
| 32 |
$this->content = $this->content_html(); |
| 33 |
$this->buttons = []; |
| 34 |
} |
| 35 |
|
| 36 |
/** |
| 37 |
* Enqueue required assets because these won't be loaded if Woocommerce is not installed. |
| 38 |
* |
| 39 |
* @since 1.1.0 |
| 40 |
*/ |
| 41 |
public function assets() { |
| 42 |
if ( ! $this->is_valid() ) { |
| 43 |
return; |
| 44 |
} |
| 45 |
|
| 46 |
add_action( 'admin_enqueue_scripts', function() { |
| 47 |
wp_enqueue_style( |
| 48 |
'sellkit-admin-notices-woo', |
| 49 |
sellkit()->plugin_url() . 'assets/dist/css/admin.min.css', |
| 50 |
[], |
| 51 |
sellkit()->version() |
| 52 |
); |
| 53 |
|
| 54 |
wp_enqueue_script( |
| 55 |
'sellkit-admin-notice-woo', |
| 56 |
sellkit()->plugin_url() . 'assets/dist/js/admin.min.js', |
| 57 |
[ 'jquery' ], |
| 58 |
sellkit()->version(), |
| 59 |
true |
| 60 |
); |
| 61 |
} ); |
| 62 |
} |
| 63 |
|
| 64 |
/** |
| 65 |
* Check if notice is valid or not. |
| 66 |
* |
| 67 |
* @since 1.1.0 |
| 68 |
* @return bool |
| 69 |
*/ |
| 70 |
public function is_valid() { |
| 71 |
if ( class_exists( 'woocommerce' ) ) { |
| 72 |
return false; |
| 73 |
} |
| 74 |
|
| 75 |
return true; |
| 76 |
} |
| 77 |
|
| 78 |
/** |
| 79 |
* Content of notice. |
| 80 |
* |
| 81 |
* @since 1.1.0 |
| 82 |
*/ |
| 83 |
public function content_html() { |
| 84 |
$message = sprintf( |
| 85 |
'<span>' |
| 86 |
. '<h3>' |
| 87 |
. esc_html__( 'Welcome to Sellkit', 'sellkit' ) |
| 88 |
. '</h3>' |
| 89 |
/* Translators: 1: bold sellkit 2: bold woocommerce */ |
| 90 |
. esc_html__( 'The %1$s plugin requires the %2$s plugin to be installed & activated as well.', 'sellkit' ) |
| 91 |
. '</span>', |
| 92 |
'<b>Sellkit</b>', |
| 93 |
'<b>WooCommerce</b>' |
| 94 |
); |
| 95 |
|
| 96 |
return $message; |
| 97 |
} |
| 98 |
|
| 99 |
/** |
| 100 |
* Set the priority of notice. |
| 101 |
* |
| 102 |
* @since 1.1.0 |
| 103 |
* @return int |
| 104 |
*/ |
| 105 |
public function priority() { |
| 106 |
return 1; |
| 107 |
} |
| 108 |
} |
| 109 |
|