Skip to content

Commit

Permalink
Merge pull request #18 from newfold-labs/add/hooks-from-ecom-module
Browse files Browse the repository at this point in the history
Add coming soon hooks from ecommerce module
  • Loading branch information
wpalani authored Jan 11, 2024
2 parents 3758f8e + ec61466 commit 98f13af
Showing 5 changed files with 101 additions and 49 deletions.
1 change: 1 addition & 0 deletions build/0.0.1/coming-soon.asset.php
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?php return array('dependencies' => array('react', 'wp-api-fetch', 'wp-components', 'wp-data', 'wp-dom-ready', 'wp-edit-post', 'wp-element', 'wp-i18n', 'wp-primitives'), 'version' => '13d2f9050a5557fafa9d');
1 change: 1 addition & 0 deletions build/0.0.1/coming-soon.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions build/0.0.1/coming-soon.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

123 changes: 86 additions & 37 deletions includes/ComingSoon.php
Original file line number Diff line number Diff line change
@@ -20,25 +20,28 @@ public function __construct( Container $container ) {
$this->container = $container;
// setup args
$defaults = array(
'option_name' => 'nfd_coming_soon',
'admin_screen_id' => container()->plugin()->id,
'admin_app_url' => \admin_url( 'admin.php?page=newfold' ),
'admin_notice_text' => __( 'Your site has Coming Soon mode active.', 'newfold-module-coming-soon' ),
'admin_bar_text' => '<div>' . __( 'Coming Soon Active', 'newfold-module-coming-soon' ) . '</div>',
'template_page_title' => __( 'Coming Soon!', 'newfold-module-coming-soon' ),
'template_styles' => false,
'template_content' => false,
'template_h1' => __( 'Coming Soon!', 'newfold-module-coming-soon' ),
'template_h2' => __( 'A New WordPress Site!', 'newfold-module-coming-soon' ),
'template_login_btn' => false,
'template_p' => __( 'Be the first to know when we launch, enter your email address and we will let you know when we go live and any future website updates we have.', 'newfold-module-coming-soon' ),
'template_msg_success' => __( 'Thank you, please check your email to confirm your subscription.', 'newfold-module-coming-soon' ),
'template_msg_active' => __( 'Your email address is already subscribed to this website. Stay tuned to your inbox for our updates or try a different email address.', 'newfold-module-coming-soon' ),
'template_msg_invalid' => __( 'There was an error with your submission and you were not subscribed. Please try again with a valid email address.', 'newfold-module-coming-soon' ),
'template_email_label' => __( 'Email', 'newfold-module-coming-soon' ),
'template_email_ph' => __( 'Enter your email address', 'newfold-module-coming-soon' ),
'template_subscribe' => __( 'Subscribe', 'newfold-module-coming-soon' ),
'template_footer_t' => __( 'Is this your website? Log in to WordPress to launch your site.', 'newfold-module-coming-soon' ),
'option_name' => 'nfd_coming_soon',
'admin_screen_id' => container()->plugin()->id,
'admin_app_url' => \admin_url( 'admin.php?page=newfold' ),
'admin_notice_text' => __( 'Your site has Coming Soon mode active.', 'newfold-module-coming-soon' ),
'admin_bar_text' => '<div>' . __( 'Coming Soon Active', 'newfold-module-coming-soon' ) . '</div>',
'admin_bar_label' => __( 'Site Status: ', 'newfold-module-coming-soon' ),
'admin_bar_cs_active' => __( 'Coming Soon', 'newfold-module-coming-soon' ),
'admin_bar_cs_inactive' => __( 'Live', 'newfold-module-coming-soon' ),
'template_page_title' => __( 'Coming Soon!', 'newfold-module-coming-soon' ),
'template_styles' => false,
'template_content' => false,
'template_h1' => __( 'Coming Soon!', 'newfold-module-coming-soon' ),
'template_h2' => __( 'A New WordPress Site!', 'newfold-module-coming-soon' ),
'template_login_btn' => false,
'template_p' => __( 'Be the first to know when we launch, enter your email address and we will let you know when we go live and any future website updates we have.', 'newfold-module-coming-soon' ),
'template_msg_success' => __( 'Thank you, please check your email to confirm your subscription.', 'newfold-module-coming-soon' ),
'template_msg_active' => __( 'Your email address is already subscribed to this website. Stay tuned to your inbox for our updates or try a different email address.', 'newfold-module-coming-soon' ),
'template_msg_invalid' => __( 'There was an error with your submission and you were not subscribed. Please try again with a valid email address.', 'newfold-module-coming-soon' ),
'template_email_label' => __( 'Email', 'newfold-module-coming-soon' ),
'template_email_ph' => __( 'Enter your email address', 'newfold-module-coming-soon' ),
'template_subscribe' => __( 'Subscribe', 'newfold-module-coming-soon' ),
'template_footer_t' => __( 'Is this your website? Log in to WordPress to launch your site.', 'newfold-module-coming-soon' ),
);
$this->args = wp_parse_args( $container->has( 'comingsoon' ) ? $container['comingsoon'] : array(), $defaults );

@@ -51,11 +54,13 @@ public function __construct( Container $container ) {
\add_action( 'rest_api_init', array( $this, 'rest_api_init' ) );
\add_action( 'newfold/onboarding/completed', array( $this, 'handle_onboarding_completed' ) );
\add_action( 'admin_notices', array( $this, 'notice_display' ) );
\add_action( 'admin_bar_menu', array( $this, 'add_tool_bar_item' ), 100 );
\add_action( 'template_redirect', array( $this, 'maybe_load_template' ) );
\add_action( 'wp_ajax_newfold_coming_soon_subscribe', array( $this, 'coming_soon_subscribe' ) );
\add_action( 'wp_ajax_nopriv_newfold_coming_soon_subscribe', array( $this, 'coming_soon_subscribe' ) );
\add_action( 'plugins_loaded', array( $this, 'coming_soon_prevent_emails' ) );
\add_action( 'admin_bar_menu', array( $this, 'newfold_site_status' ), 100 );
\add_action( 'wp_body_open', array( $this, 'site_preview_warning' ) );
\add_action( 'admin_head', array($this, 'admin_bar_coming_soon_admin_styles') );

new PrePublishModal();
}
@@ -127,31 +132,75 @@ public function notice_display() {
}
}

/**
* Some basic styles to control visibility of the coming soon state in the admin bar
*/
public function admin_bar_coming_soon_admin_styles() {
?>
<style>
#nfd-site-status {
background-color: #F8F8F8;
color: #333333;
padding: 0 16px;
}
#nfd-site-status-coming-soon {
color: #E01C1C;
display: none;
}
#nfd-site-status-live {
color: #048200;
display: none;
}
#nfd-site-status[data-coming-soon="true"] #nfd-site-status-coming-soon {
display: inline-block;
}
#nfd-site-status[data-coming-soon="false"] #nfd-site-status-live {
display: inline-block;
}
</style>
<?php
}

/**
* Customize the admin bar.
* Customize the admin bar with site status.
*
* @param \WP_Admin_Bar $admin_bar An instance of the WP_Admin_Bar class.
*/
public function add_tool_bar_item( \WP_Admin_Bar $admin_bar ) {
public function newfold_site_status( \WP_Admin_Bar $admin_bar ) {
if ( current_user_can( 'manage_options' ) ) {
$allowed_adminbar_html = array(
// div with inline styles
'div' => array(
'style' => array()

$is_coming_soon = 'true' === get_option( 'nfd_coming_soon', 'false' );
$current_state = $is_coming_soon ? 'true' : 'false';
$content = '<div id="nfd-site-status" data-coming-soon="'.$current_state.'">';
$content .= $this->args['admin_bar_label'];
$content .= '<span id="nfd-site-status-coming-soon" class="nfd-coming-soon-active">';
$content .= $this->args['admin_bar_cs_active'];
$content .= '</span>';
$content .= '<span id="nfd-site-status-live" class="nfd-coming-soon-inactive">';
$content .= $this->args['admin_bar_cs_inactive'];
$content .= '</span>';
$content .= '</div>';

$site_status_menu = array(
'id' => 'site-status',
'parent' => 'top-secondary',
'href' => admin_url( 'admin.php?page=' . $this->container->plugin()->id . '&nfd-target=coming-soon-section#/settings' ),
'title' => $content,
'meta' => array(
'title' => esc_attr__( 'Launch Your Site', 'newfold-module-coming-soon' ),
),
);
if ( 'true' === get_option( esc_attr( $this->args['option_name'] ), 'false' ) ) {
$cs_args = array(
'id' => $this->args['admin_screen_id'] . '-coming_soon',
'href' => esc_url( $this->args['admin_app_url'] ),
'title' => wp_kses( $this->args['admin_bar_text'], $allowed_adminbar_html ),
'meta' => array(
'title' => esc_attr__( 'Launch Your Site', 'newfold-module-coming-soon' ),
),
);
$admin_bar->add_menu( $cs_args );
}
$admin_bar->add_menu( $site_status_menu );
}
}

/**
* Load warning on site Preview
*/
public function site_preview_warning() {
$is_coming_soon = 'true' === get_option( 'nfd_coming_soon', 'false' );
if($is_coming_soon){
echo "<div style='background-color: #e71616; padding: 0 16px;color:#ffffff;font-size:16px;text-align:center;font-weight: 590;'>" . esc_html__( 'Site Preview - This site is NOT LIVE, only admins can see this view.', 'newfold-module-coming-soon' ) . "</div>";
}
}

Loading

0 comments on commit 98f13af

Please sign in to comment.