diff --git a/.gitignore b/.gitignore index 03a100b83..667a399d8 100644 --- a/.gitignore +++ b/.gitignore @@ -30,7 +30,6 @@ $RECYCLE.BIN/ # Windows shortcuts *.lnk - ### macOS ### *.DS_Store .AppleDouble @@ -39,7 +38,6 @@ $RECYCLE.BIN/ # Icon must end with two \r Icon - # Thumbnails ._* @@ -59,12 +57,10 @@ Network Trash Folder Temporary Items .apdisk - ### Sass ### .sass-cache/ *.css.map - ### SublimeText ### # cache files for sublime text *.tmlanguage.cache @@ -98,7 +94,6 @@ bh_unicode_properties.cache # https://packagecontrol.io/packages/sublime-github GitHub.sublime-settings - ### Vim ### # swap [._]*.s[a-w][a-z] diff --git a/compat/src-deprecated/functions.php b/compat/src-deprecated/functions.php index 35b7ebb66..e7ffc7cec 100644 --- a/compat/src-deprecated/functions.php +++ b/compat/src-deprecated/functions.php @@ -15,6 +15,16 @@ use BracketSpace\Notification\Store; use BracketSpace\Notification\Dependencies\Micropackage\DocHooks\Helper as DocHooksHelper; use BracketSpace\Notification\Queries\NotificationQueries; +use function BracketSpace\Notification\getSetting; +use function BracketSpace\Notification\adaptNotification; +use function BracketSpace\Notification\adaptNotificationFrom; +use function BracketSpace\Notification\swapNotificationAdapter; +use function BracketSpace\Notification\log; +use function BracketSpace\Notification\addNotification; +use function BracketSpace\Notification\convertNotificationData; +use function BracketSpace\Notification\registerSettings; +use function BracketSpace\Notification\getSettings; +use function BracketSpace\Notification\updateSetting; /** * Helper function. @@ -62,7 +72,6 @@ function notification_cache() { return null; } - /** * Checks if the Wizard should be displayed. * @@ -388,7 +397,6 @@ function notification_register_resolver( Interfaces\Resolvable $resolver ) { Register::resolver( $resolver ); } - /** * Resolves the value * @@ -669,3 +677,166 @@ function notification_update_setting($setting, $value) { return notificationUpdateSetting($setting, $value); } + + +/** + * Adapts Notification object + * Default adapters are: WordPress || JSON + * + * @param string $adapterName Adapter class name. + * @param \BracketSpace\Notification\Core\Notification $notification Notification object. + * @return \BracketSpace\Notification\Interfaces\Adaptable + * @throws \Exception If adapter wasn't found. + * @since 6.0.0 + * @deprecated [Next] + */ +function notificationAdapt($adapterName, \BracketSpace\Notification\Core\Notification $notification) { + _deprecated_function( __FUNCTION__, '[Next]', 'BracketSpace\\Notification\\adaptNotification()'); + + return adaptNotification($adapterName, $notification); +} + +/** + * Adapts Notification from input data + * Default adapters are: WordPress || JSON + * + * @param string $adapterName Adapter class name. + * @param mixed $data Input data needed by adapter. + * @return \BracketSpace\Notification\Interfaces\Adaptable + * @since 6.0.0 + * @deprecated [Next] + */ +function notificationAdaptFrom($adapterName, $data) +{ + _deprecated_function( __FUNCTION__, '[Next]', 'BracketSpace\\Notification\\adaptNotificationFrom()'); + + return adaptNotificationFrom($adapterName, $data); +} + +/** + * Changes one adapter to another + * + * @param string $newAdapterName Adapter class name. + * @param \BracketSpace\Notification\Interfaces\Adaptable $adapter Adapter. + * @return \BracketSpace\Notification\Interfaces\Adaptable + * @since 6.0.0 + * @deprecated [Next] + */ +function notificationSwapAdapter($newAdapterName, Interfaces\Adaptable $adapter) +{ + _deprecated_function( __FUNCTION__, '[Next]', 'BracketSpace\\Notification\\swapNotificationAdapter()'); + + return swapNotificationAdapter($newAdapterName, $adapter); +} + +/** + * Logs the message in database + * + * @param string $component Component nice name, like `Core` or `Any Plugin Name`. + * @param string $type Log type, values: notification|error|warning. + * @param string $message Log formatted message. + * @return bool|\WP_Error + * @since 6.0.0 + * @deprecated [Next] + */ +function notificationLog($component, $type, $message) +{ + _deprecated_function( __FUNCTION__, '[Next]', 'BracketSpace\\Notification\\log()'); + + return log($component, $type, $message); +} + +/** + * Adds Notification to Store + * + * @param \BracketSpace\Notification\Core\Notification $notification Notification object. + * @return void + * @since 6.0.0 + * @deprecated [Next] + */ +function notificationAdd(\BracketSpace\Notification\Core\Notification $notification) +{ + _deprecated_function( __FUNCTION__, '[Next]', 'BracketSpace\\Notification\\addNotification()'); + + addNotification($notification); +} + + +/** + * Converts the static data to Trigger and Carrier objects + * + * If no `trigger` nor `carriers` keys are available it does nothing. + * If the data is already in form of objects it does nothing. + * + * @param array $data Notification static data. + * @return array Converted data. + * @since 6.0.0 + * @deprecated [Next] + */ +function notificationConvertData($data = []) +{ + _deprecated_function( __FUNCTION__, '[Next]', 'BracketSpace\\Notification\\convertNotificationData()'); + + return convertNotificationData($data); +} + +/** + * Registers settings + * + * @param mixed $callback Callback for settings registration, array of string. + * @param int $priority Action priority. + * @return void + * @since 5.0.0 + * @deprecated [Next] + */ +function notificationRegisterSettings($callback, $priority = 10) +{ + _deprecated_function( __FUNCTION__, '[Next]', 'BracketSpace\\Notification\\registerSettings()'); + + registerSettings($callback, $priority); +} + +/** + * Gets setting values + * + * @return mixed + * @since 5.0.0 + * @deprecated [Next] + */ +function notificationGetSettings() +{ + _deprecated_function( __FUNCTION__, '[Next]', 'BracketSpace\\Notification\\getSettings()'); + + return getSettings(); +} + +/** + * Gets single setting value + * + * @param string $setting setting name in `a/b/c` format. + * @return mixed + * @since 5.0.0 + * @since 7.0.0 The `notifications` section has been changed to `carriers`. + * @deprecated [Next] + */ +function notificationGetSetting($setting) +{ + _deprecated_function( __FUNCTION__, '[Next]', 'BracketSpace\\Notification\\getSetting()'); + + return getSetting($setting); +} + +/** + * Updates single setting value. + * + * @param string $setting setting name in `a/b/c` format. + * @param mixed $value setting value. + * @return mixed + * @deprecated [Next] + */ +function notificationUpdateSetting($setting, $value) +{ + _deprecated_function( __FUNCTION__, '[Next]', 'BracketSpace\\Notification\\updateSetting()'); + + return updateSetting($setting, $value); +} diff --git a/readme.txt b/readme.txt index dbb90cbb0..5e1f0e538 100644 --- a/readme.txt +++ b/readme.txt @@ -304,18 +304,31 @@ Yes! We're offering a [custom plugin development](https://bracketspace.com/custo = [Next] = +* [Changed] Global functions moved to namespace and set as deprecated. * [Changed] Removed v6 & v7 deprecated functions * [Fixed] Shortcodes being uncorrectly stripped leaving closing "]" behind. * [Fixed] PHP 8.2 deprecations. * [Changed] Minimum required PHP version from 7.4. * [Changed] WordPress Coding Standards to PSR-12 standards. * [Added] New trigger after user confirms his new email address +* [Added] Option to disable notification about admin email address changed. **Compatibility Breaking Changes** * Class methods and properties has been changed from snake_case to camelCase. * In Post Triggers, dynamic property `$trigger->{$post_type}` has been replaced with static prop `$trigger->post`. * The same as above applies to Post Trigger datetime tags, namely: postCreationDatetime, postPublicationDatetime, and postModificationDatetime. +* Renamed functions: + notification_adapt() -> BracketSpace\Notification\adaptNotification() + notification_adapt_from() -> BracketSpace\Notification\adaptNotificationFrom() + notification_swap_adapter() -> BracketSpace\Notification\swapNotificationAdapter() + notification_log() -> BracketSpace\Notification\log() + notification_add() -> BracketSpace\Notification\addNotification() + notification_convert_data() -> BracketSpace\Notification\convertNotificationData() + notification_register_settings() -> BracketSpace\Notification\registerSettings() + notification_get_settings() -> BracketSpace\Notification\getSettings() + notification_get_setting() -> BracketSpace\Notification\getSetting() + notification_update_setting() -> BracketSpace\Notification\updateSetting() == Upgrade Notice == diff --git a/resources/css/src/_variables.scss b/resources/css/src/_variables.scss index a132b5dd7..4e73a815c 100644 --- a/resources/css/src/_variables.scss +++ b/resources/css/src/_variables.scss @@ -1,4 +1,3 @@ - $mobile-width: 782px; @mixin mobile { diff --git a/resources/css/src/partials/_global.scss b/resources/css/src/partials/_global.scss index da784cdc6..419518265 100644 --- a/resources/css/src/partials/_global.scss +++ b/resources/css/src/partials/_global.scss @@ -40,7 +40,6 @@ } - /** * On/Off switch */ diff --git a/resources/css/src/partials/_metabox.scss b/resources/css/src/partials/_metabox.scss index d66a1f3fc..7f16b7990 100644 --- a/resources/css/src/partials/_metabox.scss +++ b/resources/css/src/partials/_metabox.scss @@ -71,7 +71,6 @@ } } - .question-mark { font-size: 14px; position: absolute; diff --git a/resources/templates/debug/error-log.php b/resources/templates/debug/error-log.php index 36e10326a..5f2787bdb 100644 --- a/resources/templates/debug/error-log.php +++ b/resources/templates/debug/error-log.php @@ -77,7 +77,6 @@ -

diff --git a/resources/templates/debug/notification-log.php b/resources/templates/debug/notification-log.php index ed9ec7092..be390512b 100644 --- a/resources/templates/debug/notification-log.php +++ b/resources/templates/debug/notification-log.php @@ -216,7 +216,6 @@ -

getNotification()); + addNotification($this->getNotification()); } } diff --git a/src/Abstracts/Carrier.php b/src/Abstracts/Carrier.php index 745036247..317525f48 100644 --- a/src/Abstracts/Carrier.php +++ b/src/Abstracts/Carrier.php @@ -18,6 +18,7 @@ use BracketSpace\Notification\Interfaces\Triggerable; use BracketSpace\Notification\Store\Recipient as RecipientStore; use BracketSpace\Notification\Traits; +use function BracketSpace\Notification\getSetting; /** * Carrier abstract class @@ -421,7 +422,7 @@ protected function resolveValue($value, Triggerable $trigger) // Unused tags. $stripMergeTags = apply_filters( 'notification/resolve/strip_empty_mergetags', - notificationGetSetting('general/content/strip_empty_tags') + getSetting('general/content/strip_empty_tags') ); if ($stripMergeTags) { @@ -431,7 +432,7 @@ protected function resolveValue($value, Triggerable $trigger) // Shortcodes. $stripShortcodes = apply_filters( 'notification/carrier/field/value/strip_shortcodes', - notificationGetSetting('general/content/strip_shortcodes') + getSetting('general/content/strip_shortcodes') ); $resolved = $stripShortcodes diff --git a/src/Abstracts/Trigger.php b/src/Abstracts/Trigger.php index 3252b1399..ed400a40d 100644 --- a/src/Abstracts/Trigger.php +++ b/src/Abstracts/Trigger.php @@ -14,6 +14,7 @@ use BracketSpace\Notification\Interfaces\Taggable; use BracketSpace\Notification\Interfaces\Triggerable; use BracketSpace\Notification\Traits; +use function BracketSpace\Notification\getSetting; /** * Trigger abstract class @@ -378,7 +379,7 @@ public function hasBackgroundProcessingEnabled() return apply_filters( 'notification/trigger/process_in_background', - notificationGetSetting('general/advanced/background_processing'), + getSetting('general/advanced/background_processing'), $this ); } diff --git a/src/Admin/Debugging.php b/src/Admin/Debugging.php index 346f7a9ce..f462739d6 100644 --- a/src/Admin/Debugging.php +++ b/src/Admin/Debugging.php @@ -12,6 +12,7 @@ use BracketSpace\Notification\Utils\Settings\CoreFields; use BracketSpace\Notification\Utils\Settings\Fields as SpecificFields; +use function BracketSpace\Notification\getSetting; /** * Debugging class @@ -126,8 +127,8 @@ public function debugWarning() { if ( get_post_type() !== 'notification' || - !notificationGetSetting('debugging/settings/debug_log') || - !notificationGetSetting('debugging/settings/debug_suppressing') + !getSetting('debugging/settings/debug_log') || + !getSetting('debugging/settings/debug_suppressing') ) { return; } diff --git a/src/Admin/ImportExport.php b/src/Admin/ImportExport.php index c18bd749b..f4ba88a1c 100644 --- a/src/Admin/ImportExport.php +++ b/src/Admin/ImportExport.php @@ -12,6 +12,8 @@ use BracketSpace\Notification\Utils\Settings\Fields as SettingFields; use BracketSpace\Notification\Queries\NotificationQueries; +use function BracketSpace\Notification\adaptNotificationFrom; +use function BracketSpace\Notification\swapNotificationAdapter; /** * Import/Export class @@ -125,14 +127,14 @@ public function prepareNotificationsExportData(array $items = []) ); foreach ($posts as $wppost) { - $wpAdapter = notificationAdaptFrom('WordPress', $wppost); + $wpAdapter = adaptNotificationFrom('WordPress', $wppost); /** * JSON Adapter * * @var \BracketSpace\Notification\Defaults\Adapter\JSON */ - $jsonAdapter = notificationSwapAdapter('JSON', $wpAdapter); + $jsonAdapter = swapNotificationAdapter('JSON', $wpAdapter); $json = $jsonAdapter->save(null, false); // Decode because it's encoded in the last step of export. @@ -223,14 +225,14 @@ public function processNotificationsImportRequest($data) $updated = 0; foreach ($data as $notificationData) { - $jsonAdapter = notificationAdaptFrom('JSON', wp_json_encode($notificationData)); + $jsonAdapter = adaptNotificationFrom('JSON', wp_json_encode($notificationData)); /** * WordPress Adapter * * @var \BracketSpace\Notification\Defaults\Adapter\WordPress */ - $wpAdapter = notificationSwapAdapter('WordPress', $jsonAdapter); + $wpAdapter = swapNotificationAdapter('WordPress', $jsonAdapter); /** * @var \BracketSpace\Notification\Defaults\Adapter\WordPress|null diff --git a/src/Admin/NotificationDuplicator.php b/src/Admin/NotificationDuplicator.php index 1c16a4f41..7a21c4c68 100644 --- a/src/Admin/NotificationDuplicator.php +++ b/src/Admin/NotificationDuplicator.php @@ -10,6 +10,9 @@ namespace BracketSpace\Notification\Admin; +use function BracketSpace\Notification\adaptNotificationFrom; +use function BracketSpace\Notification\swapNotificationAdapter; + /** * Notification duplicator class */ @@ -64,14 +67,14 @@ public function notificationDuplicate() // Get the source notification post. $source = get_post(intval(wp_unslash($_GET['duplicate']))); - $wp = notificationAdaptFrom('WordPress', $source); + $wp = adaptNotificationFrom('WordPress', $source); /** * JSON Adapter * * @var \BracketSpace\Notification\Defaults\Adapter\JSON */ - $json = notificationSwapAdapter('JSON', $wp); + $json = swapNotificationAdapter('JSON', $wp); $json->refreshHash(); $json->setEnabled(false); diff --git a/src/Admin/PostTable.php b/src/Admin/PostTable.php index 908204e56..f61e3629a 100644 --- a/src/Admin/PostTable.php +++ b/src/Admin/PostTable.php @@ -10,6 +10,8 @@ namespace BracketSpace\Notification\Admin; +use function BracketSpace\Notification\adaptNotificationFrom; + /** * PostTable class */ @@ -57,7 +59,7 @@ public function tableColumnContent($column, $postId) * * @var \BracketSpace\Notification\Defaults\Adapter\WordPress */ - $notification = notificationAdaptFrom('WordPress', $postId); + $notification = adaptNotificationFrom('WordPress', $postId); switch ($column) { case 'hash': @@ -216,7 +218,7 @@ public function handleStatusBulkActions($redirectTo, $doaction, $postIds) ); foreach ($postIds as $postId) { - $notification = notificationAdaptFrom('WordPress', $postId); + $notification = adaptNotificationFrom('WordPress', $postId); $notification->setEnabled($doaction === 'enable'); $notification->save(); } diff --git a/src/Admin/PostType.php b/src/Admin/PostType.php index ae3cf4058..aa3dff434 100644 --- a/src/Admin/PostType.php +++ b/src/Admin/PostType.php @@ -15,6 +15,8 @@ use BracketSpace\Notification\Dependencies\Micropackage\Ajax\Response; use BracketSpace\Notification\Dependencies\Micropackage\Cache\Cache; use BracketSpace\Notification\Dependencies\Micropackage\Cache\Driver as CacheDriver; +use function BracketSpace\Notification\adaptNotificationFrom; +use function BracketSpace\Notification\addNotification; /** * PostType class @@ -283,7 +285,7 @@ public function save($postId, $post, $update) } $data = $_POST; - $notificationPost = notificationAdaptFrom('WordPress', $post); + $notificationPost = adaptNotificationFrom('WordPress', $post); // Title. if (isset($data['post_title'])) { @@ -375,7 +377,7 @@ public function ajaxChangeNotificationStatus() $ajax->verify_nonce('change_notification_status_' . $data['post_id']); - $adapter = notificationAdaptFrom('WordPress', (int)$data['post_id']); + $adapter = adaptNotificationFrom('WordPress', (int)$data['post_id']); $adapter->setEnabled($data['status'] === 'true'); $result = $adapter->save(); @@ -450,7 +452,7 @@ public function setupNotifications() continue; } - $adapter = notificationAdaptFrom('JSON', $notificationJson); + $adapter = adaptNotificationFrom('JSON', $notificationJson); // Set source back to WordPress. $adapter->setSource('WordPress'); @@ -460,7 +462,7 @@ public function setupNotifications() continue; } - notificationAdd($adapter->getNotification()); + addNotification($adapter->getNotification()); } } } diff --git a/src/Admin/Screen.php b/src/Admin/Screen.php index ab16889f9..35fff90a5 100644 --- a/src/Admin/Screen.php +++ b/src/Admin/Screen.php @@ -16,6 +16,7 @@ use BracketSpace\Notification\Interfaces; use BracketSpace\Notification\Store; use BracketSpace\Notification\Dependencies\Micropackage\Ajax\Response; +use function BracketSpace\Notification\adaptNotificationFrom; /** * Screen class @@ -52,7 +53,7 @@ public function renderMainColumn($post) return; } - $notificationPost = notificationAdaptFrom('WordPress', $post); + $notificationPost = adaptNotificationFrom('WordPress', $post); do_action('notification/post/column/main', $notificationPost); } @@ -284,7 +285,7 @@ public function addMergeTagsMetaBox() */ public function renderMergeTagsMetabox($post) { - $notification = notificationAdaptFrom('WordPress', $post); + $notification = adaptNotificationFrom('WordPress', $post); $trigger = $notification->getTrigger(); $triggerSlug = $trigger ? $trigger->getSlug() diff --git a/src/Admin/Settings.php b/src/Admin/Settings.php index f0e4551a6..3cf9a791f 100644 --- a/src/Admin/Settings.php +++ b/src/Admin/Settings.php @@ -283,7 +283,7 @@ public function triggersSettings($settings) ); // phpcs:ignore WordPress.WP.CapitalPDangit.Misspelled - $triggers->addGroup(__('WordPress', 'notification'), 'WordPress') + $triggers->addGroup(__('WordPress', 'notification'), 'wordpress') ->addField( [ 'name' => __('Updates', 'notification'), @@ -667,6 +667,22 @@ public function emailsSettings($settings) 'sanitize' => [new CoreFields\Checkbox(), 'sanitize'], ] ) + ->addField( + [ + 'name' => __('Admin Email address changed', 'notification'), + 'slug' => 'send_confirmation_on_admin_email_changed', + 'default' => false, + 'addons' => [ + 'label' => __( + 'Disable email to new admin about site email address changed.', + 'notification' + ), + ], + 'description' => __('Email is sent when new site email address is confirmed.', 'notification'), + 'render' => [new CoreFields\Checkbox(), 'input'], + 'sanitize' => [new CoreFields\Checkbox(), 'sanitize'], + ] + ) ->addField( [ 'name' => __('Automatic WordPress core update', 'notification'), diff --git a/src/Admin/Sync.php b/src/Admin/Sync.php index ac706b3d9..cca0bf0da 100644 --- a/src/Admin/Sync.php +++ b/src/Admin/Sync.php @@ -16,6 +16,8 @@ use BracketSpace\Notification\Utils\Settings\Fields as SpecificFields; use BracketSpace\Notification\Dependencies\Micropackage\Ajax\Response; use BracketSpace\Notification\Queries\NotificationQueries; +use function BracketSpace\Notification\adaptNotificationFrom; +use function BracketSpace\Notification\swapNotificationAdapter; /** * Sync class @@ -146,7 +148,7 @@ public function loadNotificationToWordpress($hash) * * @var \BracketSpace\Notification\Defaults\Adapter\JSON */ - $jsonAdapter = notificationAdaptFrom('JSON', $json); + $jsonAdapter = adaptNotificationFrom('JSON', $json); if ($jsonAdapter->getHash() === $hash) { /** @@ -154,7 +156,7 @@ public function loadNotificationToWordpress($hash) * * @var \BracketSpace\Notification\Defaults\Adapter\WordPress */ - $wpAdapter = notificationSwapAdapter('WordPress', $jsonAdapter); + $wpAdapter = swapNotificationAdapter('WordPress', $jsonAdapter); $wpAdapter->save(); return get_edit_post_link($wpAdapter->getId(), 'admin'); } diff --git a/src/Admin/Wizard.php b/src/Admin/Wizard.php index bf681b738..a0284b932 100644 --- a/src/Admin/Wizard.php +++ b/src/Admin/Wizard.php @@ -14,6 +14,8 @@ use BracketSpace\Notification\Core\Whitelabel; use BracketSpace\Notification\Dependencies\Micropackage\Cache\Driver as CacheDriver; use BracketSpace\Notification\Dependencies\Micropackage\Filesystem\Filesystem; +use function BracketSpace\Notification\adaptNotificationFrom; +use function BracketSpace\Notification\swapNotificationAdapter; /** * Wizard class @@ -329,10 +331,10 @@ private function addNotifications($notifications) $json = $this->filesystem->get_contents($jsonPath); - $jsonAdapter = notificationAdaptFrom('JSON', $json); + $jsonAdapter = adaptNotificationFrom('JSON', $json); $jsonAdapter->refreshHash(); - $wpAdapter = notificationSwapAdapter('WordPress', $jsonAdapter); + $wpAdapter = swapNotificationAdapter('WordPress', $jsonAdapter); $wpAdapter->save(); } diff --git a/src/Api/Controller/RepeaterController.php b/src/Api/Controller/RepeaterController.php index 115c21213..fd61d0225 100644 --- a/src/Api/Controller/RepeaterController.php +++ b/src/Api/Controller/RepeaterController.php @@ -11,6 +11,7 @@ namespace BracketSpace\Notification\Api\Controller; use BracketSpace\Notification\Store; +use function BracketSpace\Notification\adaptNotificationFrom; /** * RepeaterHandler class @@ -100,7 +101,7 @@ public function formFieldData($data = null) */ public function getValues($postId, $carrier, $field) { - $notification = notificationAdaptFrom('WordPress', $postId); + $notification = adaptNotificationFrom('WordPress', $postId); $carrier = $notification->getCarrier($carrier); if ($carrier) { diff --git a/src/Core/Cron.php b/src/Core/Cron.php index 4cc842b04..60b04d562 100644 --- a/src/Core/Cron.php +++ b/src/Core/Cron.php @@ -10,6 +10,8 @@ namespace BracketSpace\Notification\Core; +use function BracketSpace\Notification\getSetting; + /** * Cron class */ @@ -65,7 +67,7 @@ public function registerIntervals($intervals) public function registerCheckUpdatesEvent() { $event = wp_get_schedule('notification_check_wordpress_updates'); - $schedule = notificationGetSetting('triggers/wordpress/updates_cron_period'); + $schedule = getSetting('triggers/wordpress/updates_cron_period'); if ($event === false) { $this->schedule($schedule, 'notification_check_wordpress_updates'); diff --git a/src/Core/Debugging.php b/src/Core/Debugging.php index 1fac0bee3..f76486bf4 100644 --- a/src/Core/Debugging.php +++ b/src/Core/Debugging.php @@ -10,6 +10,8 @@ namespace BracketSpace\Notification\Core; +use function BracketSpace\Notification\log; +use function BracketSpace\Notification\getSetting; /** * Debugging class */ @@ -199,7 +201,7 @@ public function getLogsCount($type = 'total') */ public function catchNotification($carrier, $trigger, $notification) { - if (!notificationGetSetting('debugging/settings/debug_log')) { + if (!getSetting('debugging/settings/debug_log')) { return; } @@ -229,7 +231,7 @@ public function catchNotification($carrier, $trigger, $notification) 'name' => $trigger->getName(), ], ]; - notificationLog( + log( 'Core', 'notification', (string)wp_json_encode($data) @@ -239,7 +241,7 @@ public function catchNotification($carrier, $trigger, $notification) if ( apply_filters( 'notification/debug/suppress', - (bool)notificationGetSetting('debugging/settings/debug_suppressing'), + (bool)getSetting('debugging/settings/debug_suppressing'), $data['notification'], $data['carrier'], $data['trigger'] diff --git a/src/Core/Processor.php b/src/Core/Processor.php index e921bae99..a0d6c1db4 100644 --- a/src/Core/Processor.php +++ b/src/Core/Processor.php @@ -17,6 +17,9 @@ use BracketSpace\Notification\ErrorHandler; use BracketSpace\Notification\Interfaces\Sendable; use BracketSpace\Notification\Interfaces\Triggerable; +use function BracketSpace\Notification\adaptNotification; +use function BracketSpace\Notification\adaptNotificationFrom; +use function BracketSpace\Notification\getSetting; /** * Processor class @@ -40,7 +43,7 @@ static function ($index, $notification, $trigger) { $bpEnabled = apply_filters( 'notification/trigger/process_in_background', - notificationGetSetting('general/advanced/background_processing'), + getSetting('general/advanced/background_processing'), $trigger ); @@ -94,7 +97,7 @@ public static function schedule(Notification $notification, Triggerable $trigger time() + apply_filters('notification/background_processing/delay', 30), 'notification_background_processing', [ - notificationAdapt('JSON', $notification)->save(JSON_UNESCAPED_UNICODE, true), + adaptNotification('JSON', $notification)->save(JSON_UNESCAPED_UNICODE, true), $triggerKey, ] ); @@ -145,7 +148,7 @@ public static function processNotification(Notification $notification, Triggerab */ public static function handleCron($notificationJson, $triggerKey) { - $notification = notificationAdaptFrom('JSON', $notificationJson) + $notification = adaptNotificationFrom('JSON', $notificationJson) ->getNotification(); $trigger = self::getCache($triggerKey)->get(); diff --git a/src/Core/Sync.php b/src/Core/Sync.php index 28e8f0943..70c376eee 100644 --- a/src/Core/Sync.php +++ b/src/Core/Sync.php @@ -12,6 +12,8 @@ use BracketSpace\Notification\Dependencies\Micropackage\Casegnostic\Casegnostic; use BracketSpace\Notification\Dependencies\Micropackage\Filesystem\Filesystem; +use function BracketSpace\Notification\adaptNotificationFrom; +use function BracketSpace\Notification\swapNotificationAdapter; /** * Sync class @@ -87,7 +89,7 @@ public function loadLocalJson() * * @var \BracketSpace\Notification\Defaults\Adapter\JSON */ - $adapter = notificationAdaptFrom('JSON', $json); + $adapter = adaptNotificationFrom('JSON', $json); if ($adapter->isEnabled()) { $adapter->registerNotification(); @@ -121,7 +123,7 @@ public static function saveLocalJson($wpAdapter) } $file = $wpAdapter->getHash() . '.json'; - $json = notificationSwapAdapter('JSON', $wpAdapter) + $json = swapNotificationAdapter('JSON', $wpAdapter) ->save(); $fs->put_contents($file, $json); @@ -148,7 +150,7 @@ public function deleteLocalJson($postId) return; } - $adapter = notificationAdaptFrom('WordPress', $postId); + $adapter = adaptNotificationFrom('WordPress', $postId); $file = $adapter->getHash() . '.json'; if (!$fs->exists($file)) { diff --git a/src/Defaults/Adapter/JSON.php b/src/Defaults/Adapter/JSON.php index d2578b928..3f2a9f15e 100644 --- a/src/Defaults/Adapter/JSON.php +++ b/src/Defaults/Adapter/JSON.php @@ -11,6 +11,7 @@ namespace BracketSpace\Notification\Defaults\Adapter; use BracketSpace\Notification\Abstracts; +use function BracketSpace\Notification\convertNotificationData; /** * JSON Adapter class @@ -32,7 +33,7 @@ public function read($input = null) throw new \Exception('Read method of JSON adapter expects valid JSON string'); } - $this->setupNotification(notificationConvertData($data)); + $this->setupNotification(convertNotificationData((array)$data)); $this->setSource('JSON'); return $this; diff --git a/src/Defaults/Adapter/WordPress.php b/src/Defaults/Adapter/WordPress.php index 7f714b5ac..386e63f0f 100644 --- a/src/Defaults/Adapter/WordPress.php +++ b/src/Defaults/Adapter/WordPress.php @@ -12,6 +12,9 @@ use BracketSpace\Notification\Abstracts; use BracketSpace\Notification\Core\Notification; +use function BracketSpace\Notification\adaptNotificationFrom; +use function BracketSpace\Notification\convertNotificationData; +use function BracketSpace\Notification\swapNotificationAdapter; /** * WordPress Adapter class @@ -58,14 +61,18 @@ public function read($input = null) } try { - $jsonAdapter = notificationAdaptFrom( + $jsonAdapter = adaptNotificationFrom( 'JSON', wp_specialchars_decode( $this->post->post_content, ENT_COMPAT ) ); - $this->setupNotification(notificationConvertData($jsonAdapter->getNotification()->toArray())); + $this->setupNotification( + convertNotificationData( + $jsonAdapter->getNotification()->toArray() + ) + ); } catch (\Throwable $e) { $doNothing = true; } @@ -94,7 +101,7 @@ public function save() $data = $this->getNotification()->toArray(); /** @var \BracketSpace\Notification\Defaults\Adapter\JSON */ - $jsonAdapter = notificationSwapAdapter('JSON', $this); + $jsonAdapter = swapNotificationAdapter('JSON', $this); $json = $jsonAdapter->save(JSON_UNESCAPED_UNICODE); // Update the hash. diff --git a/src/Defaults/Carrier/Email.php b/src/Defaults/Carrier/Email.php index 91208ea2d..827020b5f 100644 --- a/src/Defaults/Carrier/Email.php +++ b/src/Defaults/Carrier/Email.php @@ -13,6 +13,8 @@ use BracketSpace\Notification\Interfaces\Triggerable; use BracketSpace\Notification\Abstracts; use BracketSpace\Notification\Defaults\Field; +use function BracketSpace\Notification\log; +use function BracketSpace\Notification\getSetting; /** * Email Carrier @@ -57,9 +59,10 @@ public function formFields() ) ); - $bodyField = notificationGetSetting('carriers/email/type') === 'html' && !notificationGetSetting( - 'carriers/email/unfiltered_html' - ) + $bodyField = getSetting('carriers/email/type') === 'html' && + !getSetting( + 'carriers/email/unfiltered_html' + ) ? new Field\EditorField( [ 'label' => __('Body', 'notification'), @@ -85,7 +88,7 @@ public function formFields() $this->addRecipientsField(); - if (!notificationGetSetting('carriers/email/headers')) { + if (!getSetting('carriers/email/headers')) { return; } @@ -136,7 +139,7 @@ public function setMailType() */ public function send(Triggerable $trigger) { - $defaultHtmlMime = notificationGetSetting('carriers/email/type') === 'html'; + $defaultHtmlMime = getSetting('carriers/email/type') === 'html'; $htmlMime = apply_filters_deprecated( 'notification/email/use_html_mime', [$defaultHtmlMime, $this, $trigger], @@ -204,7 +207,7 @@ public function send(Triggerable $trigger) } $headers = []; - if (notificationGetSetting('carriers/email/headers') && !empty($data['headers'])) { + if (getSetting('carriers/email/headers') && !empty($data['headers'])) { foreach ($data['headers'] as $header) { $headers[] = $header['key'] . ': ' . $header['value']; } @@ -250,7 +253,7 @@ public function send(Triggerable $trigger) } foreach ($errors as $error => $errorData) { - notificationLog( + log( $this->getName(), 'error', // phpcs:ignore Squiz.PHP.DiscouragedFunctions.Discouraged @@ -289,7 +292,7 @@ public function send(Triggerable $trigger) **/ public function allowUnfilteredHtmlBody($carrierData, $rawData) { - if (notificationGetSetting('carriers/email/unfiltered_html')) { + if (getSetting('carriers/email/unfiltered_html')) { $carrierData['body'] = $rawData['body']; } diff --git a/src/Defaults/Carrier/Webhook.php b/src/Defaults/Carrier/Webhook.php index 2fe0f0f6b..ac50c5a52 100644 --- a/src/Defaults/Carrier/Webhook.php +++ b/src/Defaults/Carrier/Webhook.php @@ -14,6 +14,7 @@ use BracketSpace\Notification\Abstracts; use BracketSpace\Notification\Defaults\Field; use BracketSpace\Notification\Traits\Webhook as WebhookTrait; +use function BracketSpace\Notification\getSetting; /** * Webhook Carrier @@ -92,7 +93,7 @@ public function formFields() ) ); - if (!notificationGetSetting('carriers/webhook/headers')) { + if (!getSetting('carriers/webhook/headers')) { return; } @@ -160,7 +161,7 @@ public function send(Triggerable $trigger) ? ['Content-Type' => 'application/json'] : []; - if (notificationGetSetting('carriers/webhook/headers')) { + if (getSetting('carriers/webhook/headers')) { $headers = array_merge($headers, $this->parseArgs($data['headers'])); } diff --git a/src/Defaults/Carrier/WebhookJson.php b/src/Defaults/Carrier/WebhookJson.php index f059b18ef..c549cede9 100644 --- a/src/Defaults/Carrier/WebhookJson.php +++ b/src/Defaults/Carrier/WebhookJson.php @@ -14,6 +14,7 @@ use BracketSpace\Notification\Abstracts; use BracketSpace\Notification\Defaults\Field; use BracketSpace\Notification\Traits\Webhook as WebhookTrait; +use function BracketSpace\Notification\getSetting; /** * Webhook Carrier @@ -61,7 +62,7 @@ public function formFields() ) ); - if (!notificationGetSetting('carriers/webhook/headers')) { + if (!getSetting('carriers/webhook/headers')) { return; } @@ -129,7 +130,7 @@ public function send(Triggerable $trigger) ? ['Content-Type' => 'application/json'] : []; - if (notificationGetSetting('carriers/webhook/headers')) { + if (getSetting('carriers/webhook/headers')) { $headers = array_merge( $headers, $this->parseArgs($data['headers']) diff --git a/src/Defaults/Trigger/Comment/CommentAdded.php b/src/Defaults/Trigger/Comment/CommentAdded.php index 961c23a96..efbc2f14f 100644 --- a/src/Defaults/Trigger/Comment/CommentAdded.php +++ b/src/Defaults/Trigger/Comment/CommentAdded.php @@ -12,6 +12,7 @@ use BracketSpace\Notification\Defaults\MergeTag; use BracketSpace\Notification\Utils\WpObjectHelper; +use function BracketSpace\Notification\getSetting; /** * Comment added trigger class @@ -60,7 +61,10 @@ public function context($commentId, $comment) { $this->comment = $comment; - if ($this->comment->comment_approved === 'spam' && notificationGetSetting('triggers/comment/akismet')) { + if ( + $this->comment->comment_approved === 'spam' && + getSetting('triggers/comment/akismet') + ) { return false; } diff --git a/src/Defaults/Trigger/Comment/CommentApproved.php b/src/Defaults/Trigger/Comment/CommentApproved.php index 5ef9b990b..a6b6e5a9e 100644 --- a/src/Defaults/Trigger/Comment/CommentApproved.php +++ b/src/Defaults/Trigger/Comment/CommentApproved.php @@ -11,6 +11,7 @@ namespace BracketSpace\Notification\Defaults\Trigger\Comment; use BracketSpace\Notification\Utils\WpObjectHelper; +use function BracketSpace\Notification\getSetting; /** * Comment added trigger class @@ -56,7 +57,10 @@ public function context($commentNewStatus, $commentOldStatus, $comment) { $this->comment = $comment; - if ($this->comment->comment_approved === 'spam' && notificationGetSetting('triggers/comment/akismet')) { + if ( + $this->comment->comment_approved === 'spam' && + getSetting('triggers/comment/akismet') + ) { return false; } diff --git a/src/Defaults/Trigger/Comment/CommentReplied.php b/src/Defaults/Trigger/Comment/CommentReplied.php index d54dec1ff..dca68cf5d 100644 --- a/src/Defaults/Trigger/Comment/CommentReplied.php +++ b/src/Defaults/Trigger/Comment/CommentReplied.php @@ -12,6 +12,7 @@ use BracketSpace\Notification\Defaults\MergeTag; use BracketSpace\Notification\Utils\WpObjectHelper; +use function BracketSpace\Notification\getSetting; /** * Comment replied trigger class @@ -72,7 +73,10 @@ public function context($commentNewStatus, $commentOldStatus, $comment) { $this->comment = $comment; - if ($this->comment->comment_approved === 'spam' && notificationGetSetting('triggers/comment/akismet')) { + if ( + $this->comment->comment_approved === 'spam' && + getSetting('triggers/comment/akismet') + ) { return false; } diff --git a/src/Defaults/Trigger/Comment/CommentSpammed.php b/src/Defaults/Trigger/Comment/CommentSpammed.php index 32d0bdd6f..bfe88c2f4 100644 --- a/src/Defaults/Trigger/Comment/CommentSpammed.php +++ b/src/Defaults/Trigger/Comment/CommentSpammed.php @@ -11,6 +11,7 @@ namespace BracketSpace\Notification\Defaults\Trigger\Comment; use BracketSpace\Notification\Utils\WpObjectHelper; +use function BracketSpace\Notification\getSetting; /** * Comment spammed trigger class @@ -55,7 +56,10 @@ public function context($commentId, $comment) { $this->comment = $comment; - if ($this->comment->comment_approved === 'spam' && notificationGetSetting('triggers/comment/akismet')) { + if ( + $this->comment->comment_approved === 'spam' && + getSetting('triggers/comment/akismet') + ) { return false; } diff --git a/src/Defaults/Trigger/Comment/CommentTrashed.php b/src/Defaults/Trigger/Comment/CommentTrashed.php index 2b6c6b98c..853235aa2 100644 --- a/src/Defaults/Trigger/Comment/CommentTrashed.php +++ b/src/Defaults/Trigger/Comment/CommentTrashed.php @@ -11,6 +11,7 @@ namespace BracketSpace\Notification\Defaults\Trigger\Comment; use BracketSpace\Notification\Utils\WpObjectHelper; +use function BracketSpace\Notification\getSetting; /** * Comment trashed trigger class @@ -55,7 +56,10 @@ public function context($commentId, $comment) { $this->comment = $comment; - if ($this->comment->comment_approved === 'spam' && notificationGetSetting('triggers/comment/akismet')) { + if ( + $this->comment->comment_approved === 'spam' && + getSetting('triggers/comment/akismet') + ) { return false; } diff --git a/src/Defaults/Trigger/Comment/CommentUnapproved.php b/src/Defaults/Trigger/Comment/CommentUnapproved.php index 7be92e2d6..b621638c3 100644 --- a/src/Defaults/Trigger/Comment/CommentUnapproved.php +++ b/src/Defaults/Trigger/Comment/CommentUnapproved.php @@ -11,6 +11,7 @@ namespace BracketSpace\Notification\Defaults\Trigger\Comment; use BracketSpace\Notification\Utils\WpObjectHelper; +use function BracketSpace\Notification\getSetting; /** * Comment unapproved trigger class @@ -60,7 +61,10 @@ public function context($commentNewStatus, $commentOldStatus, $comment) { $this->comment = $comment; - if ($this->comment->comment_approved === 'spam' && notificationGetSetting('triggers/comment/akismet')) { + if ( + $this->comment->comment_approved === 'spam' && + getSetting('triggers/comment/akismet') + ) { return false; } diff --git a/src/Defaults/Trigger/User/UserRegistered.php b/src/Defaults/Trigger/User/UserRegistered.php index 8c4e19d25..096c2efbc 100644 --- a/src/Defaults/Trigger/User/UserRegistered.php +++ b/src/Defaults/Trigger/User/UserRegistered.php @@ -11,6 +11,7 @@ namespace BracketSpace\Notification\Defaults\Trigger\User; use BracketSpace\Notification\Defaults\MergeTag; +use function BracketSpace\Notification\log; /** * User registered trigger class @@ -133,7 +134,7 @@ public function getPasswordResetKey() ); if (is_wp_error($resetKey)) { - notificationLog( + log( 'Core', 'error', 'User registration trigger error: ' . $resetKey->get_error_message() diff --git a/src/Defaults/Trigger/WordPress/UpdatesAvailable.php b/src/Defaults/Trigger/WordPress/UpdatesAvailable.php index 5cafd866b..8a6da2af1 100644 --- a/src/Defaults/Trigger/WordPress/UpdatesAvailable.php +++ b/src/Defaults/Trigger/WordPress/UpdatesAvailable.php @@ -12,6 +12,7 @@ use BracketSpace\Notification\Defaults\MergeTag; use BracketSpace\Notification\Abstracts; +use function BracketSpace\Notification\getSetting; /** * WordPress Updates Available trigger class @@ -67,7 +68,7 @@ public function context() } // Don't send any empty notifications unless the Setting is enabled. - if (!$hasUpdates && !notificationGetSetting('triggers/wordpress/updates_send_anyway')) { + if (!$hasUpdates && !getSetting('triggers/wordpress/updates_send_anyway')) { return false; } } diff --git a/src/Integration/WordPress.php b/src/Integration/WordPress.php index f4a4cc27f..3c64501a7 100644 --- a/src/Integration/WordPress.php +++ b/src/Integration/WordPress.php @@ -11,6 +11,7 @@ namespace BracketSpace\Notification\Integration; use BracketSpace\Notification\Interfaces\Triggerable; +use function BracketSpace\Notification\getSetting; /** * WordPress integration class @@ -34,7 +35,7 @@ class WordPress */ public function filterEmailFromName($fromName) { - $setting = notificationGetSetting('carriers/email/from_name'); + $setting = getSetting('carriers/email/from_name'); return empty($setting) ? $fromName : $setting; } @@ -50,7 +51,7 @@ public function filterEmailFromName($fromName) */ public function filterEmailFromEmail($fromEmail) { - $setting = notificationGetSetting('carriers/email/from_email'); + $setting = getSetting('carriers/email/from_email'); return empty($setting) ? $fromEmail : $setting; } @@ -161,7 +162,7 @@ public function proxyPostCommentToPublished($commentId, $approved) public function proxyTransitionCommentStatusToPublished($commentNewStatus, $commentOldStatus, $comment) { // phpcs:ignore Squiz.NamingConventions.ValidVariableName.MemberNotCamelCaps - if ($comment->comment_approved === 'spam' && notificationGetSetting('triggers/comment/akismet')) { + if ($comment->comment_approved === 'spam' && getSetting('triggers/comment/akismet')) { return; } diff --git a/src/Integration/WordPressEmails.php b/src/Integration/WordPressEmails.php index e781c5259..a4101fb34 100644 --- a/src/Integration/WordPressEmails.php +++ b/src/Integration/WordPressEmails.php @@ -10,6 +10,8 @@ namespace BracketSpace\Notification\Integration; +use function BracketSpace\Notification\getSetting; + /** * WordPress integration class */ @@ -72,10 +74,10 @@ public function disableNewUserNotify($userId, $notify = 'both') $isAdminNotify = in_array($notify, ['', 'admin', 'both'], true); $isUserNotify = in_array($notify, ['user', 'both'], true); - if ($isAdminNotify && (notificationGetSetting('integration/emails/new_user_to_admin') !== 'true')) { + if ($isAdminNotify && (getSetting('integration/emails/new_user_to_admin') !== 'true')) { wp_new_user_notification($userId, null, 'admin'); } - if (!$isUserNotify || (notificationGetSetting('integration/emails/new_user_to_user') === 'true')) { + if (!$isUserNotify || (getSetting('integration/emails/new_user_to_user') === 'true')) { return; } @@ -94,7 +96,7 @@ public function disableNewUserNotify($userId, $notify = 'both') */ public function disablePostAuthorNotify($maybeNotify, $commentId) { - if (notificationGetSetting('integration/emails/post_author') === 'true') { + if (getSetting('integration/emails/post_author') === 'true') { $maybeNotify = false; } return $maybeNotify; @@ -112,7 +114,7 @@ public function disablePostAuthorNotify($maybeNotify, $commentId) */ public function disableCommentModeratorNotify($maybeNotify, $commentId) { - if (notificationGetSetting('integration/emails/comment_moderator') === 'true') { + if (getSetting('integration/emails/comment_moderator') === 'true') { $maybeNotify = false; } return $maybeNotify; @@ -128,7 +130,7 @@ public function disableCommentModeratorNotify($maybeNotify, $commentId) */ public function disablePasswordChangeNotifyToAdmin() { - if (notificationGetSetting('integration/emails/password_change_to_admin') !== 'true') { + if (getSetting('integration/emails/password_change_to_admin') !== 'true') { return; } add_filter( @@ -151,7 +153,7 @@ public function disablePasswordChangeNotifyToAdmin() */ public function disableSendConfirmationOnProfileEmail() { - if (notificationGetSetting('integration/emails/send_confirmation_on_profile_email') !== 'true') { + if (getSetting('integration/emails/send_confirmation_on_profile_email') !== 'true') { return; } @@ -174,7 +176,7 @@ static function ($emailText = false, $newUserEmail = false) { */ public function disableSendConfirmationOnAdminEmail() { - if (notificationGetSetting('integration/emails/send_confirmation_on_admin_email') !== 'true') { + if (getSetting('integration/emails/send_confirmation_on_admin_email') !== 'true') { return; } @@ -184,6 +186,19 @@ public function disableSendConfirmationOnAdminEmail() ); } + /** + * Disables email on admin email address changed + * + * @filter send_site_admin_email_change_email + * + * @since [Next] + * @return bool + */ + public function disableSendConfirmationOnAdminEmailChanged() + { + return getSetting('integration/emails/send_confirmation_on_admin_email_changed') !== 'true'; + } + /** * Disables send the email change email to user * @@ -197,7 +212,7 @@ public function disableSendConfirmationOnAdminEmail() */ public function disablePasswordChangeNotifyToUser($send, $user, $userdata) { - if (notificationGetSetting('integration/emails/password_change_to_user') === 'true') { + if (getSetting('integration/emails/password_change_to_user') === 'true') { $send = false; } return $send; @@ -214,7 +229,7 @@ public function disablePasswordChangeNotifyToUser($send, $user, $userdata) */ public function disablePasswordResetNotifyToUser($message) { - if (notificationGetSetting('integration/emails/password_forgotten_to_user') === 'true') { + if (getSetting('integration/emails/password_forgotten_to_user') === 'true') { return ''; } return $message; @@ -233,7 +248,7 @@ public function disablePasswordResetNotifyToUser($message) */ public function disableEmailChangeNotifyToUser($send, $user, $userdata) { - if (notificationGetSetting('integration/emails/email_change_to_user') === 'true') { + if (getSetting('integration/emails/email_change_to_user') === 'true') { $send = false; } return $send; @@ -255,7 +270,7 @@ public function disableAutomaticWpCoreUpdateNotify($send, $type, $coreUpdate, $r { if ( ($type === 'success') && - (notificationGetSetting('integration/emails/automatic_wp_core_update') === 'true') + (getSetting('integration/emails/automatic_wp_core_update') === 'true') ) { $send = false; } @@ -277,8 +292,8 @@ private function getSettingForUserRole($value, $userId, $slug) $isAdmin = ($user && is_array($user->roles) && in_array('administrator', $user->roles, true)); $value = $isAdmin - ? notificationGetSetting('integration/emails/' . $slug . '_to_admin') - : notificationGetSetting('integration/emails/' . $slug . '_to_user'); + ? getSetting('integration/emails/' . $slug . '_to_admin') + : getSetting('integration/emails/' . $slug . '_to_user'); return $value; } } diff --git a/src/Queries/NotificationQueries.php b/src/Queries/NotificationQueries.php index 39c4641c2..ec57c5e03 100644 --- a/src/Queries/NotificationQueries.php +++ b/src/Queries/NotificationQueries.php @@ -10,6 +10,8 @@ namespace BracketSpace\Notification\Queries; +use function BracketSpace\Notification\adaptNotificationFrom; + /** * Notification Queries class */ @@ -46,7 +48,7 @@ public static function all(bool $includingDisabled = false): array } foreach ($wpposts as $wppost) { - $posts[] = notificationAdaptFrom('WordPress', $wppost); + $posts[] = adaptNotificationFrom('WordPress', $wppost); } return $posts; @@ -65,6 +67,6 @@ public static function withHash(string $hash) return empty($post) ? null - : notificationAdaptFrom('WordPress', $post); + : adaptNotificationFrom('WordPress', $post); } } diff --git a/src/Repository/CarrierRepository.php b/src/Repository/CarrierRepository.php index db4459301..0f8c8de64 100644 --- a/src/Repository/CarrierRepository.php +++ b/src/Repository/CarrierRepository.php @@ -13,6 +13,7 @@ use BracketSpace\Notification\Defaults\Carrier; use BracketSpace\Notification\Register; use BracketSpace\Notification\Dependencies\Micropackage\DocHooks\Helper as DocHooksHelper; +use function BracketSpace\Notification\getSetting; /** * Carrier Repository. @@ -24,11 +25,11 @@ class CarrierRepository */ public static function register() { - if (notificationGetSetting('carriers/email/enable')) { + if (getSetting('carriers/email/enable')) { Register::carrier(DocHooksHelper::hook(new Carrier\Email())); } - if (!notificationGetSetting('carriers/webhook/enable')) { + if (!getSetting('carriers/webhook/enable')) { return; } diff --git a/src/Repository/TriggerRepository.php b/src/Repository/TriggerRepository.php index c8bec3d0c..96d3394ab 100644 --- a/src/Repository/TriggerRepository.php +++ b/src/Repository/TriggerRepository.php @@ -12,6 +12,7 @@ use BracketSpace\Notification\Register; use BracketSpace\Notification\Defaults\Trigger; +use function BracketSpace\Notification\getSetting; /** * Trigger Repository. @@ -27,11 +28,11 @@ public static function register() self::registerTaxonomyTriggers(); - if (notificationGetSetting('triggers/user/enable')) { + if (getSetting('triggers/user/enable')) { self::registerUserTriggers(); } - if (notificationGetSetting('triggers/media/enable')) { + if (getSetting('triggers/media/enable')) { self::registerMediaTriggers(); } @@ -39,15 +40,15 @@ public static function register() self::registerWpTriggers(); - if (notificationGetSetting('triggers/plugin/enable')) { + if (getSetting('triggers/plugin/enable')) { self::registerPluginTriggers(); } - if (notificationGetSetting('triggers/theme/enable')) { + if (getSetting('triggers/theme/enable')) { self::registerThemeTriggers(); } - if (!notificationGetSetting('triggers/privacy/enable')) { + if (!getSetting('triggers/privacy/enable')) { return; } @@ -59,7 +60,7 @@ public static function register() */ public static function registerPostTriggers() { - $postTypes = notificationGetSetting('triggers/post_types/types'); + $postTypes = getSetting('triggers/post_types/types'); if (!$postTypes) { return; @@ -83,7 +84,7 @@ public static function registerPostTriggers() */ public static function registerTaxonomyTriggers() { - $taxonomies = notificationGetSetting('triggers/taxonomies/types'); + $taxonomies = getSetting('triggers/taxonomies/types'); if (!$taxonomies) { return; @@ -128,7 +129,7 @@ public static function registerMediaTriggers() */ public static function registerCommentTriggers() { - $commentTypes = notificationGetSetting('triggers/comment/types'); + $commentTypes = getSetting('triggers/comment/types'); if (!$commentTypes) { return; @@ -150,11 +151,11 @@ public static function registerCommentTriggers() */ public static function registerWpTriggers() { - if (notificationGetSetting('triggers/wordpress/updates')) { + if (getSetting('triggers/wordpress/updates')) { Register::trigger(new Trigger\WordPress\UpdatesAvailable()); } - if (!notificationGetSetting('triggers/wordpress/email_address_change_request')) { + if (!getSetting('triggers/wordpress/email_address_change_request')) { return; } diff --git a/src/Runtime.php b/src/Runtime.php index 4ff551e7e..41a1c80c0 100644 --- a/src/Runtime.php +++ b/src/Runtime.php @@ -263,28 +263,28 @@ public function actions() { $this->registerHooks(); - notificationRegisterSettings([$this->component('admin_settings'), 'generalSettings']); - notificationRegisterSettings( + registerSettings([$this->component('admin_settings'), 'generalSettings']); + registerSettings( [$this->component('admin_settings'), 'triggersSettings'], 20 ); - notificationRegisterSettings( + registerSettings( [$this->component('admin_settings'), 'carriersSettings'], 30 ); - notificationRegisterSettings( + registerSettings( [$this->component('admin_settings'), 'emailsSettings'], 40 ); - notificationRegisterSettings( + registerSettings( [$this->component('admin_sync'), 'settings'], 50 ); - notificationRegisterSettings( + registerSettings( [$this->component('admin_impexp'), 'settings'], 60 ); - notificationRegisterSettings( + registerSettings( [$this->component('admin_debugging'), 'debuggingSettings'], 70 ); diff --git a/src/Traits/Webhook.php b/src/Traits/Webhook.php index d26bfe39d..70f532801 100644 --- a/src/Traits/Webhook.php +++ b/src/Traits/Webhook.php @@ -10,6 +10,8 @@ namespace BracketSpace\Notification\Traits; +use function BracketSpace\Notification\log; + /** * Webhook trait */ @@ -56,7 +58,7 @@ public function httpRequest($url, $args = [], $headers = [], $method = 'GET') $response = wp_remote_request($url, $remoteArgs); if (is_wp_error($response)) { - notificationLog( + log( $this->getName(), 'error', // phpcs:ignore Squiz.PHP.DiscouragedFunctions.Discouraged @@ -74,7 +76,7 @@ public function httpRequest($url, $args = [], $headers = [], $method = 'GET') $code = wp_remote_retrieve_response_code($response); if ($code < 200 || $code >= 300) { - notificationLog( + log( $this->getName(), 'warning', // phpcs:ignore Squiz.PHP.DiscouragedFunctions.Discouraged diff --git a/src/Utils/Settings/Fields/SyncTable.php b/src/Utils/Settings/Fields/SyncTable.php index 8942ea376..0bc3ef9f8 100644 --- a/src/Utils/Settings/Fields/SyncTable.php +++ b/src/Utils/Settings/Fields/SyncTable.php @@ -14,6 +14,7 @@ use BracketSpace\Notification\Core\Sync as CoreSync; use BracketSpace\Notification\Core\Templates; use BracketSpace\Notification\Queries\NotificationQueries; +use function BracketSpace\Notification\adaptNotificationFrom; /** * SyncTable class @@ -36,7 +37,7 @@ public function input($field) // Load the WP Notifications first. foreach ($wpJsonNotifiactions as $json) { try { - $adapter = notificationAdaptFrom('JSON', $json); + $adapter = adaptNotificationFrom('JSON', $json); $notification = $adapter->getNotification(); } catch (\Throwable $e) { // Do nothing. @@ -64,7 +65,7 @@ public function input($field) // Compare against JSON. foreach ($jsonNotifications as $json) { try { - $adapter = notificationAdaptFrom('JSON', $json); + $adapter = adaptNotificationFrom('JSON', $json); $notification = $adapter->getNotification(); } catch (\Throwable $e) { // Do nothing. diff --git a/src/api.php b/src/api.php index 4af5b59dc..c0b101243 100644 --- a/src/api.php +++ b/src/api.php @@ -8,9 +8,9 @@ declare(strict_types=1); +namespace BracketSpace\Notification; + use BracketSpace\Notification\Core\Notification; -use BracketSpace\Notification\Store; -use BracketSpace\Notification\Interfaces; /** * Adapts Notification object @@ -21,10 +21,10 @@ * @return \BracketSpace\Notification\Interfaces\Adaptable * @throws \Exception If adapter wasn't found. * @since 6.0.0 + * @since [Next] Function lives under BracketSpace\Notifiation namespace. */ -function notificationAdapt($adapterName, Notification $notification) +function adaptNotification($adapterName, Notification $notification) { - if (class_exists($adapterName)) { $adapter = new $adapterName($notification); } elseif (class_exists('BracketSpace\\Notification\\Defaults\\Adapter\\' . $adapterName)) { @@ -36,6 +36,7 @@ function notificationAdapt($adapterName, Notification $notification) ); } + /** @var \BracketSpace\Notification\Interfaces\Adaptable $adapter */ return $adapter; } @@ -47,10 +48,11 @@ function notificationAdapt($adapterName, Notification $notification) * @param mixed $data Input data needed by adapter. * @return \BracketSpace\Notification\Interfaces\Adaptable * @since 6.0.0 + * @since [Next] Function lives under BracketSpace\Notifiation namespace. */ -function notificationAdaptFrom($adapterName, $data) +function adaptNotificationFrom($adapterName, $data) { - $adapter = notificationAdapt( + $adapter = adaptNotification( $adapterName, new Notification() ); @@ -64,10 +66,11 @@ function notificationAdaptFrom($adapterName, $data) * @param \BracketSpace\Notification\Interfaces\Adaptable $adapter Adapter. * @return \BracketSpace\Notification\Interfaces\Adaptable * @since 6.0.0 + * @since [Next] Function lives under BracketSpace\Notifiation namespace. */ -function notificationSwapAdapter($newAdapterName, Interfaces\Adaptable $adapter) +function swapNotificationAdapter($newAdapterName, Interfaces\Adaptable $adapter) { - return notificationAdapt( + return adaptNotification( $newAdapterName, $adapter->getNotification() ); @@ -81,11 +84,12 @@ function notificationSwapAdapter($newAdapterName, Interfaces\Adaptable $adapter) * @param string $message Log formatted message. * @return bool|\WP_Error * @since 6.0.0 + * @since [Next] Function lives under BracketSpace\Notifiation namespace. */ -function notificationLog($component, $type, $message) +function log($component, $type, $message) { - if ($type !== 'notification' && !notificationGetSetting('debugging/settings/error_log')) { + if ($type !== 'notification' && !getSetting('debugging/settings/error_log')) { return false; } @@ -112,12 +116,13 @@ function notificationLog($component, $type, $message) * @param array $data Notification data. * @return \WP_Error | true * @since 6.0.0 + * @since [Next] Function lives under BracketSpace\Notifiation namespace. */ function notification($data = []) { try { - notificationAdd(new Notification(notificationConvertData($data))); + addNotification(new Notification(convertNotificationData($data))); } catch (\Throwable $e) { return new \WP_Error('notification_error', $e->getMessage()); } @@ -131,8 +136,9 @@ function notification($data = []) * @param \BracketSpace\Notification\Core\Notification $notification Notification object. * @return void * @since 6.0.0 + * @since [Next] Function lives under BracketSpace\Notifiation namespace. */ -function notificationAdd(Notification $notification) +function addNotification(Notification $notification) { Store\Notification::insert( $notification->getHash(), @@ -150,8 +156,9 @@ function notificationAdd(Notification $notification) * @param array $data Notification static data. * @return array Converted data. * @since 6.0.0 + * @since [Next] Function lives under BracketSpace\Notifiation namespace. */ -function notificationConvertData($data = []) +function convertNotificationData($data = []) { // Trigger conversion. @@ -192,9 +199,10 @@ function notificationConvertData($data = []) * @param mixed $callback Callback for settings registration, array of string. * @param int $priority Action priority. * @return void - * @since 5.0.0 + * @since 6.0.0 + * @since [Next] Function lives under BracketSpace\Notifiation namespace. */ -function notificationRegisterSettings($callback, $priority = 10) +function registerSettings($callback, $priority = 10) { if (!is_callable($callback)) { @@ -208,9 +216,10 @@ function notificationRegisterSettings($callback, $priority = 10) * Gets setting values * * @return mixed - * @since 5.0.0 + * @since 6.0.0 + * @since [Next] Function lives under BracketSpace\Notifiation namespace. */ -function notificationGetSettings() +function getSettings() { return \Notification::component('core_settings')->getSettings(); } @@ -220,10 +229,10 @@ function notificationGetSettings() * * @param string $setting setting name in `a/b/c` format. * @return mixed - * @since 5.0.0 - * @since 7.0.0 The `notifications` section has been changed to `carriers`. + * @since 6.0.0 + * @since [Next] Function lives under BracketSpace\Notifiation namespace. */ -function notificationGetSetting($setting) +function getSetting($setting) { $parts = explode('/', $setting); @@ -247,8 +256,10 @@ function notificationGetSetting($setting) * @param string $setting setting name in `a/b/c` format. * @param mixed $value setting value. * @return mixed + * @since 6.0.0 + * @since [Next] Function lives under BracketSpace\Notifiation namespace. */ -function notificationUpdateSetting($setting, $value) +function updateSetting($setting, $value) { return \Notification::component('core_settings')->updateSetting( $setting, diff --git a/tests/unit/Helpers/Registerer.php b/tests/unit/Helpers/Registerer.php index 6522ff729..ea30f5994 100644 --- a/tests/unit/Helpers/Registerer.php +++ b/tests/unit/Helpers/Registerer.php @@ -86,7 +86,7 @@ public static function register_notification( $trigger = null, $carriers = [] ) 'trigger' => $trigger, 'carriers' => $carriers, ] ); - notificationAdd( $notification ); + \Bracketspace\Notification\addNotification($notification ); return $notification; }