Skip to content

Commit

Permalink
Merge pull request #448 from BracketSpace/feature/CU-862k89yd4
Browse files Browse the repository at this point in the history
Move global scope functions to namespace
  • Loading branch information
jakubmikita authored Aug 24, 2023
2 parents 1abc2a9 + b40149a commit aa40ff6
Show file tree
Hide file tree
Showing 41 changed files with 395 additions and 122 deletions.
173 changes: 173 additions & 0 deletions compat/src-deprecated/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -669,3 +679,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<mixed> $data Notification static data.
* @return array<mixed> 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);
}
12 changes: 12 additions & 0 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,7 @@ 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.
Expand All @@ -316,6 +317,17 @@ Yes! We're offering a [custom plugin development](https://bracketspace.com/custo
* 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 ==

Expand Down
3 changes: 2 additions & 1 deletion src/Abstracts/Adapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use BracketSpace\Notification\Dependencies\Micropackage\Casegnostic\Helpers\CaseHelper;
use BracketSpace\Notification\Interfaces;
use BracketSpace\Notification\Core\Notification;
use function BracketSpace\Notification\addNotification;

/**
* Adapter class
Expand Down Expand Up @@ -108,6 +109,6 @@ public function isEnabled()
*/
public function registerNotification()
{
notificationAdd($this->getNotification());
addNotification($this->getNotification());
}
}
5 changes: 3 additions & 2 deletions src/Abstracts/Carrier.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand All @@ -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
Expand Down
3 changes: 2 additions & 1 deletion src/Abstracts/Trigger.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
);
}
Expand Down
5 changes: 3 additions & 2 deletions src/Admin/Debugging.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
}
Expand Down
10 changes: 6 additions & 4 deletions src/Admin/ImportExport.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down
7 changes: 5 additions & 2 deletions src/Admin/NotificationDuplicator.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@

namespace BracketSpace\Notification\Admin;

use function BracketSpace\Notification\adaptNotificationFrom;
use function BracketSpace\Notification\swapNotificationAdapter;

/**
* Notification duplicator class
*/
Expand Down Expand Up @@ -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);
Expand Down
6 changes: 4 additions & 2 deletions src/Admin/PostTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

namespace BracketSpace\Notification\Admin;

use function BracketSpace\Notification\adaptNotificationFrom;

/**
* PostTable class
*/
Expand Down Expand Up @@ -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':
Expand Down Expand Up @@ -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();
}
Expand Down
Loading

0 comments on commit aa40ff6

Please sign in to comment.