From 8562cf96a1f3f48429503434bd449f570d0b3224 Mon Sep 17 00:00:00 2001 From: Evan Mullins Date: Wed, 3 Jan 2024 17:51:06 -0500 Subject: [PATCH] add coming soon hooks from ecommerce module --- includes/ComingSoon.php | 45 ++++++++++++++++++++++++----------------- 1 file changed, 26 insertions(+), 19 deletions(-) diff --git a/includes/ComingSoon.php b/includes/ComingSoon.php index d50e5ca..49b04b3 100644 --- a/includes/ComingSoon.php +++ b/includes/ComingSoon.php @@ -48,11 +48,12 @@ public function __construct( Container $container ) { } // set up all actions \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' ) ); } @@ -86,31 +87,37 @@ public function notice_display() { } } - /** - * 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' ); + $status = $is_coming_soon + ? '' . esc_html__( 'Coming Soon', 'newfold-module-coming-soon' ) . '' + : '' . esc_html__( 'Live', 'newfold-module-coming-soon' ) . ''; + $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' => '
' . esc_html__( 'Site Status: ', 'newfold-module-coming-soon' ) . $status . '
', + '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 "
" . esc_html__( 'Site Preview - This site is NOT LIVE, only admins can see this view.', 'newfold-module-coming-soon' ) . "
"; } }