diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..215f70a --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,50 @@ +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" + + # 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" diff --git a/.github/workflows/satis-update.yml b/.github/workflows/satis-update.yml index 82a25c9..adf4185 100644 --- a/.github/workflows/satis-update.yml +++ b/.github/workflows/satis-update.yml @@ -5,12 +5,38 @@ on: types: - created +env: + VERSION: ${GITHUB_REF#refs/tags/*} + jobs: webhook: name: Send Webhook 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: | + 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: 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/includes/ComingSoon.php b/includes/ComingSoon.php index fa0f109..c30dd4a 100644 --- a/includes/ComingSoon.php +++ b/includes/ComingSoon.php @@ -70,22 +70,106 @@ 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 ) { - remove_filter( 'pre_update_option_mm_coming_soon', array( $this, 'on_update_mm_coming_soon' ) ); + + // 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' ) ); 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; } + /** + * 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 ) { - remove_filter( 'pre_update_option_nfd_coming_soon', array( $this, 'on_update_nfd_coming_soon' ) ); + + // 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 ); - 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; } + /** + * 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 ( ! did_action( 'init' ) ) { + add_action( 'init', function () use ( $isEnabled ) { + $this->conditionally_trigger_coming_soon_action_hooks( $isEnabled ); + }, 99 ); + + return; + } + + if ( $isEnabled ) { + $this->trigger_enabled_action_hook(); + } else { + $this->trigger_disabled_action_hook(); + } + } + + /** + * 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. * diff --git a/package.json b/package.json index c4d6228..a05f60b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,5 @@ { - "name": "@newfold-labs/wp-module-coming-soon", - "version": "1.1.17", + "version": "1.1.18", "description": "Coming Soon", "license": "GPL-2.0-or-later", "private": true, 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 ); } } );