Skip to content

Commit

Permalink
Merge pull request #20 from newfold-labs/add/enable-on-fresh-installa…
Browse files Browse the repository at this point in the history
…tion

Enable coming soon on fresh installations
  • Loading branch information
wpalani authored Jan 10, 2024
2 parents 9719bae + 0bf3c88 commit 726f18d
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 7 deletions.
40 changes: 33 additions & 7 deletions bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,36 @@
use NewfoldLabs\WP\Module\ComingSoon\ComingSoon;
use NewfoldLabs\WP\Module\ComingSoon\Service;
use function NewfoldLabs\WP\ModuleLoader\register;
use WP_Forge\UpgradeHandler\UpgradeHandler;

// Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) {
return;
}

// Do not allow multiple copies of the module to be active
if ( defined( 'NFD_COMING_SOON_MODULE_VERSION' ) ) {
return;
}

define( 'NFD_COMING_SOON_MODULE_VERSION', '1.1.14' );

if ( function_exists( 'is_admin' ) && is_admin() ) {
$upgrade_handler = new UpgradeHandler(
__DIR__ . '/upgrades',
get_option( 'nfd_coming_soon_module_version' ),
NFD_DATA_MODULE_VERSION
);

if ( $upgrade_handler->maybe_upgrade() ) {
// If an upgrade occurred, update the new version in the database to prevent running the routine(s) again.
update_option( 'nfd_coming_soon_module_version', NFD_COMING_SOON_MODULE_VERSION, true );
}
}

/**
* Register the coming soon module
*/
if ( function_exists( 'add_action' ) ) {

add_action(
Expand All @@ -16,14 +45,11 @@ function () {
'name' => 'coming-soon',
'label' => __( 'Coming Soon', 'newfold-module-coming-soon' ),
'callback' => function ( Container $container ) {
if ( ! defined( 'NFD_COMING_SOON_VERSION' ) ) {
define( 'NFD_COMING_SOON_VERSION', '0.0.1' );
}
if ( ! defined( 'NFD_COMING_SOON_BUILD_DIR' ) && defined( 'NFD_COMING_SOON_VERSION' ) ) {
define( 'NFD_COMING_SOON_BUILD_DIR', __DIR__ . '/build/' . NFD_COMING_SOON_VERSION );
if ( ! defined( 'NFD_COMING_SOON_BUILD_DIR' ) && defined( 'NFD_COMING_SOON_MODULE_VERSION' ) ) {
define( 'NFD_COMING_SOON_BUILD_DIR', __DIR__ . '/build/' . NFD_COMING_SOON_MODULE_VERSION );
}
if ( ! defined( 'NFD_COMING_SOON_BUILD_URL' ) && defined( 'NFD_COMING_SOON_VERSION' ) ) {
define( 'NFD_COMING_SOON_BUILD_URL', $container->plugin()->url . 'vendor/newfold-labs/wp-module-coming-soon/build/' . NFD_COMING_SOON_VERSION );
if ( ! defined( 'NFD_COMING_SOON_BUILD_URL' ) && defined( 'NFD_COMING_SOON_MODULE_VERSION' ) ) {
define( 'NFD_COMING_SOON_BUILD_URL', $container->plugin()->url . 'vendor/newfold-labs/wp-module-coming-soon/build/' . NFD_COMING_SOON_MODULE_VERSION );
}
$container->set( 'comingSoon', $container->service( function () {
return new Service();
Expand Down
3 changes: 3 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,8 @@
"allow-plugins": {
"dealerdirect/phpcodesniffer-composer-installer": true
}
},
"require": {
"wp-forge/wp-upgrade-handler": "^1.0"
}
}
19 changes: 19 additions & 0 deletions upgrades/1.1.14.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php
/**
* Handles update for coming soon module version 1.1.14.
*
* Enable coming soon page on fresh installations.
*
* @package NewfoldLabs\WP\Module\ComingSoon
*/

use NewfoldLabs\WP\Module\ComingSoon\Service;
use function NewfoldLabs\WP\ModuleLoader\container;

add_action( 'newfold_container_set', function () {
$isFreshInstall = container()->has( 'isFreshInstallation' ) ? container()->get( 'isFreshInstallation' ) : false;
if ( $isFreshInstall ) {
$comingSoonService = new Service();
$comingSoonService->enable();
}
} );

0 comments on commit 726f18d

Please sign in to comment.