Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updates to support the site launch event #27

Merged
merged 11 commits into from
Jan 26, 2024
50 changes: 50 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -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"
26 changes: 26 additions & 0 deletions .github/workflows/satis-update.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
}
},
"require": {
"newfold-labs/wp-module-data": ">=2.4.18",
"wp-forge/wp-upgrade-handler": "^1.0"
}
}
92 changes: 88 additions & 4 deletions includes/ComingSoon.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{
"name": "@newfold-labs/wp-module-coming-soon",
BrianHenryIE marked this conversation as resolved.
Show resolved Hide resolved
"version": "1.1.17",
"version": "1.1.18",
"description": "Coming Soon",
"license": "GPL-2.0-or-later",
"private": true,
Expand Down
5 changes: 4 additions & 1 deletion upgrades/1.1.16.php → upgrades/1.1.18.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* Handles update for coming soon module version 1.1.14.
* Handles update for coming soon module version 1.1.18.
*
* Enable coming soon page on fresh installations.
*
Expand All @@ -15,5 +15,8 @@
if ( $isFreshInstall ) {
$comingSoonService = new Service();
$comingSoonService->enable( false );

// Initially set the `mm_coming_soon` option to true as well to keep things in sync.
update_option( 'mm_coming_soon', true );
}
} );
Loading