Skip to content

Commit

Permalink
Mark AI Sitegen Generated Themes on themes.php
Browse files Browse the repository at this point in the history
  • Loading branch information
arunshenoy99 committed Dec 11, 2023
1 parent 35c060c commit 66ae96f
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 0 deletions.
3 changes: 3 additions & 0 deletions bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}
Expand Down
48 changes: 48 additions & 0 deletions includes/WP_Admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand All @@ -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' ) );
}
}

/**
Expand Down Expand Up @@ -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()
24 changes: 24 additions & 0 deletions src/Scripts/sitegen-theme-marker/sitegen-theme-marker.css
Original file line number Diff line number Diff line change
@@ -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;
}
21 changes: 21 additions & 0 deletions src/Scripts/sitegen-theme-marker/sitegen-theme-marker.js
Original file line number Diff line number Diff line change
@@ -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 ? '<span>Active:</span>' : '' ) +
`<svg width="20" height="21" viewBox="0 0 20 21" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M10 19.6584L8.975 18.7334C7.20833 17.1167 5.75 15.7209 4.6 14.5459C3.45 13.3709 2.53333 12.3209 1.85 11.3959C1.16667 10.4709 0.6875 9.63338 0.4125 8.88337C0.1375 8.13337 0 7.37504 0 6.60837C0 5.10837 0.504167 3.85421 1.5125 2.84587C2.52083 1.83754 3.76667 1.33337 5.25 1.33337C6.2 1.33337 7.07917 1.55837 7.8875 2.00837C8.69583 2.45837 9.4 3.10837 10 3.95837C10.7 3.05837 11.4417 2.39587 12.225 1.97087C13.0083 1.54587 13.85 1.33337 14.75 1.33337C16.2333 1.33337 17.4792 1.83754 18.4875 2.84587C19.4958 3.85421 20 5.10837 20 6.60837C20 7.37504 19.8625 8.13337 19.5875 8.88337C19.3125 9.63338 18.8333 10.4709 18.15 11.3959C17.4667 12.3209 16.55 13.3709 15.4 14.5459C14.25 15.7209 12.7917 17.1167 11.025 18.7334L10 19.6584Z" fill="#EF4A71"/>
</svg>
` +
`<svg width="24" height="25" viewBox="0 0 24 25" class="nfd-onboarding-sitegen-theme-marker-filled" fill="none" xmlns="http://www.w3.org/2000/svg">
<rect x="0.5" y="1" width="23" height="23" rx="5.5" stroke="white"/>
<path d="M6.85742 16L9.54834 8.24951H11.4551L14.1514 16H12.4434L11.8687 14.1201H9.13477L8.56006 16H6.85742ZM10.4561 9.79639L9.50537 12.9062H11.498L10.5527 9.79639H10.4561ZM14.9673 16V8.24951H16.5894V16H14.9673Z" fill="white"/>
</svg>
` +
`<span class="nfd-onboarding-sitegen-theme-marker-title">${ homepages[ homepage ].title }</span>`;
}
} );
};

0 comments on commit 66ae96f

Please sign in to comment.