diff --git a/bootstrap.php b/bootstrap.php index 02d798e95..cca511730 100644 --- a/bootstrap.php +++ b/bootstrap.php @@ -27,6 +27,9 @@ function nfd_wp_module_onboarding_register() { if ( ! defined( 'NFD_ONBOARDING_DIR' ) ) { define( 'NFD_ONBOARDING_DIR', __DIR__ ); } + if ( ! defined( 'NFD_ONBOARDING_SCRIPTS_URL' ) ) { + define( 'NFD_ONBOARDING_SCRIPTS_URL', $container->plugin()->url . 'vendor/newfold-labs/wp-module-onboarding/src/Scripts' ); + } if ( ! defined( 'NFD_ONBOARDING_BUILD_DIR' ) && defined( 'NFD_ONBOARDING_VERSION' ) ) { define( 'NFD_ONBOARDING_BUILD_DIR', __DIR__ . '/build/' . NFD_ONBOARDING_VERSION ); } diff --git a/includes/WP_Admin.php b/includes/WP_Admin.php index 1f6c94c1e..fb5ba7022 100644 --- a/includes/WP_Admin.php +++ b/includes/WP_Admin.php @@ -2,9 +2,11 @@ namespace NewfoldLabs\WP\Module\Onboarding; use NewfoldLabs\WP\Module\Onboarding\Data\Data; +use NewfoldLabs\WP\Module\Onboarding\Data\Options; use NewfoldLabs\WP\Module\Onboarding\Services\PluginService; use NewfoldLabs\WP\Module\Onboarding\Services\ThemeService; use NewfoldLabs\WP\Module\Onboarding\Data\Services\FlowService; +use NewfoldLabs\WP\Module\Onboarding\Data\Themes; use NewfoldLabs\WP\Module\Onboarding\Services\I18nService; /** @@ -28,6 +30,9 @@ public function __construct() { \add_action( 'init', array( __CLASS__, 'load_php_textdomain' ) ); \add_action( 'admin_menu', array( __CLASS__, 'register_page' ) ); \add_action( 'load-dashboard_page_' . self::$slug, array( __CLASS__, 'initialize' ) ); + if ( 'sitegen' === Data::current_flow() ) { + \add_action( 'load-themes.php', array( __CLASS__, 'mark_sitegen_generated_themes' ) ); + } } /** @@ -160,4 +165,47 @@ public static function initialize() { self::register_assets(); } + /** + * Enqueue scripts that mark Sitegen flow generated themes. + * + * @return void + */ + public static function mark_sitegen_generated_themes() { + $flow_data = get_option( Options::get_option_name( 'flow' ), false ); + + if ( ! $flow_data || ! isset( $flow_data['sitegen']['homepages'] ) ) { + return; + } + + \wp_register_script( + 'sitegen-theme-marker', + NFD_ONBOARDING_SCRIPTS_URL . '/sitegen-theme-marker/sitegen-theme-marker.js', + array(), + '1.0.0', + true + ); + + \wp_add_inline_script( + 'sitegen-theme-marker', + 'var nfdOnboarding =' . wp_json_encode( + array( + 'homepages' => $flow_data['sitegen']['homepages'], + 'active' => Themes::get_active_theme(), + ) + ) . ';', + 'before' + ); + + \wp_register_style( + 'sitegen-theme-marker', + NFD_ONBOARDING_SCRIPTS_URL . '/sitegen-theme-marker/sitegen-theme-marker.css', + array(), + '1.0.0', + 'all' + ); + + \wp_enqueue_script( 'sitegen-theme-marker' ); + \wp_enqueue_style( 'sitegen-theme-marker' ); + } + } // END /NewfoldLabs/WP/Module/Onboarding/Admin() diff --git a/src/Scripts/sitegen-theme-marker/sitegen-theme-marker.css b/src/Scripts/sitegen-theme-marker/sitegen-theme-marker.css new file mode 100644 index 000000000..6e382b961 --- /dev/null +++ b/src/Scripts/sitegen-theme-marker/sitegen-theme-marker.css @@ -0,0 +1,24 @@ +.theme-name { + display: flex; + flex-direction: row; + align-items: center; + + svg { + margin-left: 8px; + } +} + +.nfd-onboarding-sitegen-theme-marker-filled { + fill: #1d2327; +} + +.theme.active { + + .nfd-onboarding-sitegen-theme-marker-filled { + fill: none; + } +} + +.nfd-onboarding-sitegen-theme-marker-title { + margin-left: 8px; +} diff --git a/src/Scripts/sitegen-theme-marker/sitegen-theme-marker.js b/src/Scripts/sitegen-theme-marker/sitegen-theme-marker.js new file mode 100644 index 000000000..d4f6d8526 --- /dev/null +++ b/src/Scripts/sitegen-theme-marker/sitegen-theme-marker.js @@ -0,0 +1,21 @@ +window.onload = function () { + const homepages = window.nfdOnboarding.homepages.data; + const activeTheme = window.nfdOnboarding.active; + Object.keys( homepages ).forEach( ( homepage ) => { + const ele = document.getElementById( `${ homepage }-name` ); + if ( ele ) { + ele.innerHTML = + ( activeTheme === homepage ? 'Active:' : '' ) + + ` + + + ` + + ` + + + + ` + + `${ homepages[ homepage ].title }`; + } + } ); +};