| 1 |
<?php |
| 2 |
/** |
| 3 |
* Admin: Service provider |
| 4 |
* |
| 5 |
* @package SimplePay |
| 6 |
* @subpackage Core |
| 7 |
* @copyright Copyright (c) 2022, Sandhills Development, LLC |
| 8 |
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License |
| 9 |
* @since 4.4.1 |
| 10 |
*/ |
| 11 |
|
| 12 |
namespace SimplePay\Core\Admin; |
| 13 |
|
| 14 |
use Exception; |
| 15 |
use SimplePay\Core\AbstractPluginServiceProvider; |
| 16 |
use SimplePay\Core\AdminNotice; |
| 17 |
use SimplePay\Core\AdminPage; |
| 18 |
use SimplePay\Core\NotificationInbox\NotificationRepository; |
| 19 |
use SimplePay\Core\NotificationInbox\Notifications\PluginRatingNotification; |
| 20 |
|
| 21 |
/** |
| 22 |
* AdminServiceProvider class. |
| 23 |
* |
| 24 |
* @since 4.4.1 |
| 25 |
*/ |
| 26 |
class AdminServiceProvider extends AbstractPluginServiceProvider { |
| 27 |
|
| 28 |
/** |
| 29 |
* {@inheritdoc} |
| 30 |
*/ |
| 31 |
public function get_services() { |
| 32 |
return array( |
| 33 |
'admin-page-notification-inbox', |
| 34 |
'admin-page-system-report', |
| 35 |
'admin-page-about-us', |
| 36 |
'admin-page-setup-wizard', |
| 37 |
'admin-page-form-templates', |
| 38 |
'admin-notice-update-available', |
| 39 |
'admin-notice-license-upgrade-top-of-page', |
| 40 |
'admin-notice-license-missing', |
| 41 |
'admin-notice-license-expired', |
| 42 |
'admin-notice-stripe-api-error', |
| 43 |
); |
| 44 |
} |
| 45 |
|
| 46 |
/** |
| 47 |
* {@inheritdoc} |
| 48 |
*/ |
| 49 |
public function get_subscribers() { |
| 50 |
return array( |
| 51 |
'admin-branding', |
| 52 |
'admin-page-subscriber', |
| 53 |
'admin-notice-subscriber', |
| 54 |
); |
| 55 |
} |
| 56 |
|
| 57 |
/** |
| 58 |
* {@inheritdoc} |
| 59 |
*/ |
| 60 |
public function register() { |
| 61 |
$container = $this->getContainer(); |
| 62 |
|
| 63 |
// Admin branding. |
| 64 |
$container->share( 'admin-branding', AdminBranding::class ); |
| 65 |
|
| 66 |
// Admin pages. |
| 67 |
$container->share( |
| 68 |
'admin-page-subscriber', |
| 69 |
AdminPageSubscriber::class |
| 70 |
) |
| 71 |
->withArgument( $this->get_pages() ); |
| 72 |
|
| 73 |
// Admin notices. |
| 74 |
$container->share( |
| 75 |
'admin-notice-subscriber', |
| 76 |
AdminNoticeSubscriber::class |
| 77 |
) |
| 78 |
->withArgument( $this->get_notices() ); |
| 79 |
} |
| 80 |
|
| 81 |
/** |
| 82 |
* Returns a list of admin pages to register. |
| 83 |
* |
| 84 |
* @since 4.4.0 |
| 85 |
* |
| 86 |
* @return array<\SimplePay\Core\AdminPage\AdminPageInterface> Admin pages to register. |
| 87 |
*/ |
| 88 |
private function get_pages() { |
| 89 |
$container = $this->getContainer(); |
| 90 |
|
| 91 |
// Setup wizard. |
| 92 |
$container->share( |
| 93 |
'admin-page-setup-wizard', |
| 94 |
AdminPage\SetupWizardPage::class |
| 95 |
); |
| 96 |
|
| 97 |
// System Report. |
| 98 |
$container->share( |
| 99 |
'admin-page-system-report', |
| 100 |
AdminPage\SystemReportPage::class |
| 101 |
); |
| 102 |
|
| 103 |
// About Us. |
| 104 |
$container->share( |
| 105 |
'admin-page-about-us', |
| 106 |
AdminPage\AboutUsPage::class |
| 107 |
); |
| 108 |
|
| 109 |
$pages = array( |
| 110 |
$container->get( 'admin-page-setup-wizard' ), |
| 111 |
$container->get( 'admin-page-system-report' ), |
| 112 |
$container->get( 'admin-page-about-us' ), |
| 113 |
); |
| 114 |
|
| 115 |
// Add Form templates if the Template Explorer is available. |
| 116 |
try { |
| 117 |
$container->share( |
| 118 |
'admin-page-form-templates', |
| 119 |
AdminPage\FormTemplatesPage::class |
| 120 |
) |
| 121 |
->withArgument( |
| 122 |
$container->get( 'form-builder-template-explorer' ) |
| 123 |
); |
| 124 |
|
| 125 |
$pages[] = $container->get( 'admin-page-form-templates' ); |
| 126 |
} catch ( Exception $e ) { |
| 127 |
// Do not add. |
| 128 |
} |
| 129 |
|
| 130 |
// Add Activity & Reports if the minimum WordPress version is met. |
| 131 |
global $wp_version; |
| 132 |
|
| 133 |
if ( version_compare( $wp_version, '5.5', '>=' ) ) { |
| 134 |
$container->share( |
| 135 |
'admin-page-activity-reports', |
| 136 |
AdminPage\ActivityReportsPage::class |
| 137 |
); |
| 138 |
|
| 139 |
$pages[] = $container->get( 'admin-page-activity-reports' ); |
| 140 |
} |
| 141 |
|
| 142 |
// Add notification inbox page if notifications are being used. |
| 143 |
try { |
| 144 |
$notifications = $container->get( 'notification-inbox-repository' ); |
| 145 |
|
| 146 |
if ( |
| 147 |
$notifications instanceof NotificationRepository && |
| 148 |
$notifications->get_unread_count() > 0 |
| 149 |
) { |
| 150 |
$container->share( |
| 151 |
'admin-page-notification-inbox', |
| 152 |
AdminPage\NotificationInboxPage::class |
| 153 |
) |
| 154 |
->withArgument( $notifications ); |
| 155 |
|
| 156 |
$pages[] = $container->get( 'admin-page-notification-inbox' ); |
| 157 |
} |
| 158 |
} catch ( Exception $e ) { |
| 159 |
// Do not add. |
| 160 |
} |
| 161 |
|
| 162 |
/** @var array<\SimplePay\Core\AdminPage\AdminPageInterface> $pages */ |
| 163 |
return $pages; |
| 164 |
} |
| 165 |
|
| 166 |
/** |
| 167 |
* Returns a list of admin notices to register. |
| 168 |
* |
| 169 |
* @since 4.4.1 |
| 170 |
* @since 4.4.4 Register notices against container to take advantage of dependency injection. |
| 171 |
* |
| 172 |
* @return array<\SimplePay\Core\AdminNotice\AdminNoticeInterface> Admin notices to register. |
| 173 |
*/ |
| 174 |
private function get_notices() { |
| 175 |
$container = $this->getContainer(); |
| 176 |
|
| 177 |
// Update Available. |
| 178 |
$container->share( |
| 179 |
'admin-notice-update-available', |
| 180 |
AdminNotice\UpdateAvailableNotice::class |
| 181 |
); |
| 182 |
|
| 183 |
// License Upgrade (top of page). |
| 184 |
$container->share( |
| 185 |
'admin-notice-license-upgrade-top-of-page', |
| 186 |
AdminNotice\LicenseUpgradeTopOfPageNotice::class |
| 187 |
); |
| 188 |
|
| 189 |
// License key missing. |
| 190 |
$container->share( |
| 191 |
'admin-notice-license-missing', |
| 192 |
AdminNotice\LicenseMissingNotice::class |
| 193 |
); |
| 194 |
|
| 195 |
// License key expired. |
| 196 |
$container->share( |
| 197 |
'admin-notice-license-expired', |
| 198 |
AdminNotice\LicenseExpiredNotice::class |
| 199 |
); |
| 200 |
|
| 201 |
// Stripe API error. |
| 202 |
$container->share( |
| 203 |
'admin-notice-stripe-api-error', |
| 204 |
AdminNotice\StripeApiErrorNotice::class |
| 205 |
); |
| 206 |
|
| 207 |
/** @var array<\SimplePay\Core\AdminNotice\AdminNoticeInterface> */ |
| 208 |
$notices = array( |
| 209 |
$container->get( 'admin-notice-update-available' ), |
| 210 |
$container->get( 'admin-notice-license-upgrade-top-of-page' ), |
| 211 |
$container->get( 'admin-notice-license-missing' ), |
| 212 |
$container->get( 'admin-notice-license-expired' ), |
| 213 |
$container->get( 'admin-notice-stripe-api-error' ), |
| 214 |
); |
| 215 |
|
| 216 |
return $notices; |
| 217 |
} |
| 218 |
} |
| 219 |
|