| 1 |
<?php |
| 2 |
|
| 3 |
namespace Texty; |
| 4 |
|
| 5 |
/** |
| 6 |
* Notification Class |
| 7 |
*/ |
| 8 |
class Notifications { |
| 9 |
|
| 10 |
/** |
| 11 |
* Option key to hold the notifications |
| 12 |
*/ |
| 13 |
const OPTION_KEY = 'texty_notifications'; |
| 14 |
|
| 15 |
/** |
| 16 |
* Notifications |
| 17 |
* |
| 18 |
* @var array |
| 19 |
*/ |
| 20 |
private $notifications = []; |
| 21 |
|
| 22 |
/** |
| 23 |
* Get a notification class |
| 24 |
* |
| 25 |
* @param string $key |
| 26 |
* |
| 27 |
* @return false|string |
| 28 |
*/ |
| 29 |
public function get( $key ) { |
| 30 |
$notifications = $this->all(); |
| 31 |
|
| 32 |
if ( array_key_exists( $key, $notifications ) ) { |
| 33 |
return $notifications[ $key ]; |
| 34 |
} |
| 35 |
|
| 36 |
return false; |
| 37 |
} |
| 38 |
|
| 39 |
/** |
| 40 |
* Get available notification classes |
| 41 |
* |
| 42 |
* @return array |
| 43 |
*/ |
| 44 |
public function all() { |
| 45 |
if ( $this->notifications ) { |
| 46 |
return $this->notifications; |
| 47 |
} |
| 48 |
|
| 49 |
$notifications = [ |
| 50 |
'registration' => __NAMESPACE__ . '\Notifications\WP\Registration', |
| 51 |
'comment' => __NAMESPACE__ . '\Notifications\WP\Comment', |
| 52 |
]; |
| 53 |
|
| 54 |
if ( class_exists( 'WooCommerce' ) ) { |
| 55 |
// WC Admin |
| 56 |
$notifications['order_admin_processing'] = __NAMESPACE__ . '\Notifications\WC\ProcessingAdmin'; |
| 57 |
$notifications['order_admin_complete'] = __NAMESPACE__ . '\Notifications\WC\CompleteAdmin'; |
| 58 |
|
| 59 |
// WC Customers |
| 60 |
$notifications['order_customer_hold'] = __NAMESPACE__ . '\Notifications\WC\HoldCustomer'; |
| 61 |
$notifications['order_customer_processing'] = __NAMESPACE__ . '\Notifications\WC\ProcessingCustomer'; |
| 62 |
$notifications['order_customer_complete'] = __NAMESPACE__ . '\Notifications\WC\CompleteCustomer'; |
| 63 |
} |
| 64 |
|
| 65 |
if ( class_exists( 'WeDevs_Dokan' ) ) { |
| 66 |
$notifications['order_dokan_processing'] = __NAMESPACE__ . '\Notifications\Dokan\ProcessingVendor'; |
| 67 |
$notifications['order_dokan_complete'] = __NAMESPACE__ . '\Notifications\Dokan\CompleteVendor'; |
| 68 |
} |
| 69 |
|
| 70 |
$this->notifications = apply_filters( 'texty_available_notifications', $notifications ); |
| 71 |
|
| 72 |
return $this->notifications; |
| 73 |
} |
| 74 |
|
| 75 |
/** |
| 76 |
* Get the name of the groups |
| 77 |
* |
| 78 |
* @return void |
| 79 |
*/ |
| 80 |
public function get_groups() { |
| 81 |
return apply_filters( 'texty_notification_groups', [ // phpcs:ignore |
| 82 |
'wp' => [ |
| 83 |
'title' => __( 'WordPress', 'texty' ), |
| 84 |
'description' => '', |
| 85 |
'available' => true, |
| 86 |
], |
| 87 |
'wc' => [ |
| 88 |
'title' => __( 'WooCommerce', 'texty' ), |
| 89 |
'description' => '', |
| 90 |
'available' => class_exists( 'WooCommerce' ) ? true : false, |
| 91 |
], |
| 92 |
'dokan' => [ |
| 93 |
'title' => __( 'Dokan', 'texty' ), |
| 94 |
'description' => '', |
| 95 |
'available' => class_exists( 'WeDevs_Dokan' ) ? true : false, |
| 96 |
], |
| 97 |
] ); // phpcs:ignore |
| 98 |
} |
| 99 |
|
| 100 |
/** |
| 101 |
* Retreive all the settings |
| 102 |
* |
| 103 |
* @return array |
| 104 |
*/ |
| 105 |
public function settings() { |
| 106 |
return get_option( self::OPTION_KEY, [] ); |
| 107 |
} |
| 108 |
} |
| 109 |
|