From 7e28c7065a4325ec1780b8606d8c54aab23fd248 Mon Sep 17 00:00:00 2001 From: Micah Wood Date: Wed, 24 Jan 2024 15:21:52 -0500 Subject: [PATCH 01/11] Ensure version in module is updated when a new version is released and that a valid build directory exists --- .github/workflows/satis-update.yml | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/.github/workflows/satis-update.yml b/.github/workflows/satis-update.yml index 82a25c9..0edcab8 100644 --- a/.github/workflows/satis-update.yml +++ b/.github/workflows/satis-update.yml @@ -5,12 +5,35 @@ on: types: - created +env: + VERSION: ${GITHUB_REF#refs/tags/*} + jobs: webhook: name: Send Webhook runs-on: ubuntu-latest steps: + - name: Validate version number + if: ${{ (github.repository == 'newfold-labs/wp-module-coming-soon') && (github.event.release.prerelease == false) }} + run: | + taggedVersion=${{ env.VERSION }} + moduleVersion=`grep "NFD_COMING_SOON_MODULE_VERSION" bootstrap.php | grep -Eo "[0-9\.]*"` + packageVersion=`grep '"version"' package.json | grep -Eo "[0-9\.]*"` + echo "Tagged version: $taggedVersion" + echo "Module version: $moduleVersion" + echo "Package version: $packageVersion" + [[ "$taggedVersion" == "$moduleVersion" ]] || exit 1 + [[ "$taggedVersion" == "$packageVersion" ]] || exit 1 + + - name: Validate build directory + if: ${{ (github.repository == 'newfold-labs/wp-module-coming-soon') && (github.event.release.prerelease == false) }} + run: | + if [[ ! -d "build/${{ env.VERSION }}" ]]; then + echo "Build directory for version ${{ env.VERSION }} does not exist. + exit 1 + fi + - name: Set Package id: package env: From 045948005c155a6336017957752083bff1701c13 Mon Sep 17 00:00:00 2001 From: Micah Wood Date: Wed, 24 Jan 2024 15:22:38 -0500 Subject: [PATCH 02/11] Automatically set mm_coming_soon for new installs to keep things in sync --- upgrades/{1.1.16.php => 1.1.18.php} | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) rename upgrades/{1.1.16.php => 1.1.18.php} (72%) diff --git a/upgrades/1.1.16.php b/upgrades/1.1.18.php similarity index 72% rename from upgrades/1.1.16.php rename to upgrades/1.1.18.php index 9b96621..98db0e6 100644 --- a/upgrades/1.1.16.php +++ b/upgrades/1.1.18.php @@ -1,6 +1,6 @@ enable( false ); + + // Initially set the `mm_coming_soon` option to true as well to keep things in sync. + update_option( 'mm_coming_soon', true ); } } ); From 1a9fb4b1bcb7d68f030ab0453fcd180a8eb83ac0 Mon Sep 17 00:00:00 2001 From: Micah Wood Date: Wed, 24 Jan 2024 15:23:58 -0500 Subject: [PATCH 03/11] Remove package name since it isn't a public package - eliminates the possibility of dependency confusion --- package.json | 1 - 1 file changed, 1 deletion(-) diff --git a/package.json b/package.json index c4d6228..df9cbb3 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,4 @@ { - "name": "@newfold-labs/wp-module-coming-soon", "version": "1.1.17", "description": "Coming Soon", "license": "GPL-2.0-or-later", From 83e5f67a153f0389e5f031814d32a203be6bcb97 Mon Sep 17 00:00:00 2001 From: Micah Wood Date: Wed, 24 Jan 2024 15:25:18 -0500 Subject: [PATCH 04/11] Add comments and fix references to add/remove filter --- includes/ComingSoon.php | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/includes/ComingSoon.php b/includes/ComingSoon.php index 8321838..0927ff9 100644 --- a/includes/ComingSoon.php +++ b/includes/ComingSoon.php @@ -71,17 +71,20 @@ public function __construct( Container $container ) { } public function on_update_nfd_coming_soon( $old_value, $value ) { - remove_filter( 'pre_update_option_mm_coming_soon', array( $this, 'on_update_mm_coming_soon' ) ); + // When the database value changes for the new value, make sure we update the legacy value. + remove_filter( 'update_option_mm_coming_soon', array( $this, 'on_update_mm_coming_soon' ) ); update_option( 'mm_coming_soon', $value ); - add_filter( 'pre_update_option_mm_coming_soon', array( $this, 'on_update_mm_coming_soon' ) ); + add_filter( 'update_option_mm_coming_soon', array( $this, 'on_update_mm_coming_soon' ), 10, 2 ); return $value; } public function on_update_mm_coming_soon( $old_value, $value ) { - remove_filter( 'pre_update_option_nfd_coming_soon', array( $this, 'on_update_nfd_coming_soon' ) ); + + // When the database value changes for the legacy value, make sure we update the new value. + remove_filter( 'update_option_nfd_coming_soon', array( $this, 'on_update_nfd_coming_soon' ) ); update_option( 'nfd_coming_soon', $value ); - add_filter( 'pre_update_option_nfd_coming_soon', array( $this, 'on_update_nfd_coming_soon' ) ); + add_filter( 'update_option_nfd_coming_soon', array( $this, 'on_update_nfd_coming_soon' ), 10, 2 ); return $value; } From 95d025152ea91281ff39c3db43b5c072939c1eec Mon Sep 17 00:00:00 2001 From: Micah Wood Date: Wed, 24 Jan 2024 15:25:56 -0500 Subject: [PATCH 05/11] Fire the coming soon events on shutdown to ensure that other things have had plenty of time to load and add hooks --- includes/ComingSoon.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/includes/ComingSoon.php b/includes/ComingSoon.php index 0927ff9..ec9e746 100644 --- a/includes/ComingSoon.php +++ b/includes/ComingSoon.php @@ -71,6 +71,19 @@ public function __construct( Container $container ) { } public function on_update_nfd_coming_soon( $old_value, $value ) { + + // When the database value changes, make sure we fire the appropriate action for enabling/disabling. + add_action( + 'shutdown', + function () use ( $value ) { + if ( wp_validate_boolean( $value ) ) { + do_action( 'newfold/coming-soon/enabled' ); + } else { + do_action( 'newfold/coming-soon/disabled' ); + } + } + ); + // When the database value changes for the new value, make sure we update the legacy value. remove_filter( 'update_option_mm_coming_soon', array( $this, 'on_update_mm_coming_soon' ) ); update_option( 'mm_coming_soon', $value ); From 417343b8881b228f855f9d0ccc3296869358b862 Mon Sep 17 00:00:00 2001 From: Micah Wood Date: Wed, 24 Jan 2024 15:26:13 -0500 Subject: [PATCH 06/11] Bump version to 1.1.18 --- bootstrap.php | 2 +- build/{1.1.17 => 1.1.18}/coming-soon.asset.php | 0 build/{1.1.17 => 1.1.18}/coming-soon.css | 0 build/{1.1.17 => 1.1.18}/coming-soon.js | 0 composer.json | 1 + package.json | 2 +- 6 files changed, 3 insertions(+), 2 deletions(-) rename build/{1.1.17 => 1.1.18}/coming-soon.asset.php (100%) rename build/{1.1.17 => 1.1.18}/coming-soon.css (100%) rename build/{1.1.17 => 1.1.18}/coming-soon.js (100%) diff --git a/bootstrap.php b/bootstrap.php index 4a39e5e..d1a28f7 100644 --- a/bootstrap.php +++ b/bootstrap.php @@ -17,7 +17,7 @@ return; } -define( 'NFD_COMING_SOON_MODULE_VERSION', '1.1.17' ); +define( 'NFD_COMING_SOON_MODULE_VERSION', '1.1.18' ); require __DIR__ . '/includes/functions.php'; diff --git a/build/1.1.17/coming-soon.asset.php b/build/1.1.18/coming-soon.asset.php similarity index 100% rename from build/1.1.17/coming-soon.asset.php rename to build/1.1.18/coming-soon.asset.php diff --git a/build/1.1.17/coming-soon.css b/build/1.1.18/coming-soon.css similarity index 100% rename from build/1.1.17/coming-soon.css rename to build/1.1.18/coming-soon.css diff --git a/build/1.1.17/coming-soon.js b/build/1.1.18/coming-soon.js similarity index 100% rename from build/1.1.17/coming-soon.js rename to build/1.1.18/coming-soon.js diff --git a/composer.json b/composer.json index 2e9693f..2ff6a0e 100644 --- a/composer.json +++ b/composer.json @@ -46,6 +46,7 @@ } }, "require": { + "newfold-labs/wp-module-data": ">=2.4.18", "wp-forge/wp-upgrade-handler": "^1.0" } } diff --git a/package.json b/package.json index df9cbb3..a05f60b 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "version": "1.1.17", + "version": "1.1.18", "description": "Coming Soon", "license": "GPL-2.0-or-later", "private": true, From 2d820601ee73c957553462386ac90657eee163c3 Mon Sep 17 00:00:00 2001 From: Micah Wood Date: Wed, 24 Jan 2024 15:37:45 -0500 Subject: [PATCH 07/11] Checkout the repo so we can look at files --- .github/workflows/satis-update.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/satis-update.yml b/.github/workflows/satis-update.yml index 0edcab8..adf4185 100644 --- a/.github/workflows/satis-update.yml +++ b/.github/workflows/satis-update.yml @@ -14,6 +14,9 @@ jobs: runs-on: ubuntu-latest steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Validate version number if: ${{ (github.repository == 'newfold-labs/wp-module-coming-soon') && (github.event.release.prerelease == false) }} run: | From cbde788df8a584fecad66c842834522740691a22 Mon Sep 17 00:00:00 2001 From: Micah Wood Date: Wed, 24 Jan 2024 16:05:31 -0500 Subject: [PATCH 08/11] Add dependabot.yml file --- .github/dependabot.yml | 56 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 .github/dependabot.yml diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..8e23bdd --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,56 @@ +version: 2 +updates: + + # Maintain dependencies for GitHub Actions + - package-ecosystem: "github-actions" + directory: "/" + target-branch: "develop" + allow: + - dependency-type: direct + schedule: + interval: "daily" + commit-message: + prefix: "GitHub Actions" + include: "scope" + labels: + - "dependencies" + + # Maintain dependencies for npm + - package-ecosystem: "npm" + directory: "/" + target-branch: "develop" + allow: + - dependency-type: direct + schedule: + interval: "daily" + versioning-strategy: increase + commit-message: + prefix: "NPM" + prefix-development: "NPM Dev" + include: "scope" + labels: + - "dependencies" + - "javascript" + registries: + npm-github: + type: npm-registry + url: https://npm.pkg.github.com + token: ${{ secrets.NEWFOLD_ACCESS_TOKEN }} + replaces-base: true + + # Maintain dependencies for Composer + - package-ecosystem: "composer" + directory: "/" + target-branch: "develop" + schedule: + interval: "daily" + allow: + - dependency-type: direct + versioning-strategy: increase + commit-message: + prefix: "Composer" + prefix-development: "Composer Dev" + include: "scope" + labels: + - "dependencies" + - "php" From 6f63e547a0bfafb23f425022129e6086edb10149 Mon Sep 17 00:00:00 2001 From: Micah Wood Date: Wed, 24 Jan 2024 17:33:48 -0500 Subject: [PATCH 09/11] Remove invalid section --- .github/dependabot.yml | 6 ------ 1 file changed, 6 deletions(-) diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 8e23bdd..215f70a 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -31,12 +31,6 @@ updates: labels: - "dependencies" - "javascript" - registries: - npm-github: - type: npm-registry - url: https://npm.pkg.github.com - token: ${{ secrets.NEWFOLD_ACCESS_TOKEN }} - replaces-base: true # Maintain dependencies for Composer - package-ecosystem: "composer" From ac2a859f8f4a7f8e86baaad3ebca8c10dfa55d38 Mon Sep 17 00:00:00 2001 From: Micah Wood Date: Wed, 24 Jan 2024 20:28:44 -0500 Subject: [PATCH 10/11] Update logic so the actions always fire under the correct conditions --- includes/ComingSoon.php | 89 ++++++++++++++++++++++++++++++++++++----- 1 file changed, 78 insertions(+), 11 deletions(-) diff --git a/includes/ComingSoon.php b/includes/ComingSoon.php index ec9e746..d06f58e 100644 --- a/includes/ComingSoon.php +++ b/includes/ComingSoon.php @@ -70,19 +70,21 @@ public function __construct( Container $container ) { new PrePublishModal(); } + /** + * When the coming soon state is updated, make sure we trigger actions and update the legacy option value. + * + * @param mixed $old_value + * @param mixed $value + * + * @return mixed + */ public function on_update_nfd_coming_soon( $old_value, $value ) { - // When the database value changes, make sure we fire the appropriate action for enabling/disabling. - add_action( - 'shutdown', - function () use ( $value ) { - if ( wp_validate_boolean( $value ) ) { - do_action( 'newfold/coming-soon/enabled' ); - } else { - do_action( 'newfold/coming-soon/disabled' ); - } - } - ); + // Ensure the value is a boolean. + $value = wp_validate_boolean( $value ); + + // Trigger any actions associated with the coming soon state. + $this->conditionally_trigger_coming_soon_action_hooks( $value ); // When the database value changes for the new value, make sure we update the legacy value. remove_filter( 'update_option_mm_coming_soon', array( $this, 'on_update_mm_coming_soon' ) ); @@ -92,8 +94,22 @@ function () use ( $value ) { return $value; } + /** + * When the coming soon state is updated, make sure we trigger actions and update the new option value. + * + * @param mixed $old_value + * @param mixed $value + * + * @return mixed + */ public function on_update_mm_coming_soon( $old_value, $value ) { + // Ensure the value is a boolean. + $value = wp_validate_boolean( $value ); + + // Trigger any actions associated with the coming soon state. + $this->conditionally_trigger_coming_soon_action_hooks( $value ); + // When the database value changes for the legacy value, make sure we update the new value. remove_filter( 'update_option_nfd_coming_soon', array( $this, 'on_update_nfd_coming_soon' ) ); update_option( 'nfd_coming_soon', $value ); @@ -102,6 +118,57 @@ public function on_update_mm_coming_soon( $old_value, $value ) { return $value; } + /** + * Conditionally trigger coming soon actions. + * + * The data module only starts listening for events after the init hook. + * - If the init hook has run, we trigger the action immediately. + * - If the init hook has not run, we add a callback to the init hook to trigger the action. + * + * @param bool $isEnabled + * + * @return void + */ + public function conditionally_trigger_coming_soon_action_hooks( bool $isEnabled ) { + if ( $isEnabled ) { + if ( did_action( 'init' ) ) { + $this->trigger_enabled_action_hook(); + } else { + add_action( 'init', array( $this, 'trigger_enabled_action_hook' ), 99 ); + } + } else { + if ( did_action( 'init' ) ) { + $this->trigger_disabled_action_hook(); + } else { + add_action( 'init', array( $this, 'trigger_disabled_action_hook' ), 99 ); + } + } + } + + /** + * Trigger the enabled action hook. + * + * @return void + */ + public function trigger_enabled_action_hook() { + if ( ! did_action( 'newfold/coming-soon/enabled' ) ) { + ray( 'enabled' ); + do_action( 'newfold/coming-soon/enabled' ); + } + } + + /** + * Trigger the disabled action hook. + * + * @return void + */ + public function trigger_disabled_action_hook() { + if ( ! did_action( 'newfold/coming-soon/disabled' ) ) { + ray( 'disabled' ); + do_action( 'newfold/coming-soon/disabled' ); + } + } + /** * If nfd_coming_soon is not defined, set it to the value of mm_coming_soon. * From 59853fbd2746a07c89ed731cc4f9455fc539d5a2 Mon Sep 17 00:00:00 2001 From: Micah Wood Date: Thu, 25 Jan 2024 09:45:54 -0500 Subject: [PATCH 11/11] Simplify method --- includes/ComingSoon.php | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/includes/ComingSoon.php b/includes/ComingSoon.php index d06f58e..0566c51 100644 --- a/includes/ComingSoon.php +++ b/includes/ComingSoon.php @@ -130,18 +130,19 @@ public function on_update_mm_coming_soon( $old_value, $value ) { * @return void */ public function conditionally_trigger_coming_soon_action_hooks( bool $isEnabled ) { + + if ( ! did_action( 'init' ) ) { + add_action( 'init', function () use ( $isEnabled ) { + $this->conditionally_trigger_coming_soon_action_hooks( $isEnabled ); + }, 99 ); + + return; + } + if ( $isEnabled ) { - if ( did_action( 'init' ) ) { - $this->trigger_enabled_action_hook(); - } else { - add_action( 'init', array( $this, 'trigger_enabled_action_hook' ), 99 ); - } + $this->trigger_enabled_action_hook(); } else { - if ( did_action( 'init' ) ) { - $this->trigger_disabled_action_hook(); - } else { - add_action( 'init', array( $this, 'trigger_disabled_action_hook' ), 99 ); - } + $this->trigger_disabled_action_hook(); } }