Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WiP] Raft Integrations #1976

Merged
merged 40 commits into from
Dec 18, 2023
Merged
Show file tree
Hide file tree
Changes from 45 commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
aa3e24e
Initial work on Onboarding
HardeepAsrani Nov 20, 2023
6d0df63
Add Homepage Preview
HardeepAsrani Nov 22, 2023
224cf34
Merge branch 'development' into onboarding
HardeepAsrani Nov 22, 2023
be06bf0
Finish Site Info & Appearance UI
HardeepAsrani Nov 22, 2023
7815267
Add Saving Mechanism
HardeepAsrani Nov 23, 2023
3f0c161
Add Archive Step & Saving
HardeepAsrani Nov 24, 2023
74959c2
Add Single Step & Saving
HardeepAsrani Nov 25, 2023
71a70e6
Add Page Templates Step
HardeepAsrani Nov 25, 2023
7c4c38e
Finish Page Templates & Onboarding Complete Page
HardeepAsrani Nov 27, 2023
be60d78
Add Steps Condition
HardeepAsrani Nov 27, 2023
db6a5de
Add Frontpage Step
HardeepAsrani Nov 27, 2023
8ed7969
Add Onboarding Support Docs
HardeepAsrani Nov 27, 2023
75090a0
Responsiveness Changes
HardeepAsrani Nov 27, 2023
4149e1b
Improve Homepage Preview
HardeepAsrani Nov 27, 2023
734a953
Add Redirection Conditions
HardeepAsrani Nov 28, 2023
f652cdf
Move Onboarding menu to Appearance
HardeepAsrani Nov 29, 2023
08336cb
Small code changes
HardeepAsrani Nov 30, 2023
73559bd
Add e2e Tests
HardeepAsrani Dec 5, 2023
4c07ac8
Add event tracking
HardeepAsrani Dec 8, 2023
fe77f82
Update readme
HardeepAsrani Dec 8, 2023
ccd22ec
Add Welcome Screen
HardeepAsrani Dec 11, 2023
23c3942
chore: fix phpcs
HardeepAsrani Dec 11, 2023
ebe7cbd
Allow PHP Templates
HardeepAsrani Dec 12, 2023
23870fe
Update Start.js
JohnPixle Dec 13, 2023
0e11996
Update Start.js
JohnPixle Dec 13, 2023
af9e19c
fix: doc link in onboarding
HardeepAsrani Dec 13, 2023
7a445bd
Update style.scss
JohnPixle Dec 13, 2023
49a2f62
Update Finish.js
JohnPixle Dec 13, 2023
144dded
Update Finish.js
JohnPixle Dec 13, 2023
a5dd0ff
Add Onboarding Toggle Field
HardeepAsrani Dec 13, 2023
25bfc63
Rebase
HardeepAsrani Dec 13, 2023
42170c6
Show textarea label in Finish step
HardeepAsrani Dec 14, 2023
37bedf1
Update Start.js
JohnPixle Dec 15, 2023
5a842d0
Update Dashboard.js
JohnPixle Dec 15, 2023
73db521
Add Email Subscription
HardeepAsrani Dec 15, 2023
96eded0
Improve Wonky nature of Templates Preview
HardeepAsrani Dec 15, 2023
6192a5a
Update Start.js
JohnPixle Dec 18, 2023
e9eb573
Update Finish.js
JohnPixle Dec 18, 2023
3d10a10
Toggle Email field with consent checkbox
HardeepAsrani Dec 18, 2023
2a1a87e
Merge branch 'next' into onboarding
HardeepAsrani Dec 18, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 15 additions & 8 deletions .wp-env.override.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@
"WP_DEFAULT_THEME": "twentytwentythree"
},
"env": {
"development": {
"themes": [ "./test/emptytheme" ],
"mappings": {
"wp-content/themes/raft": "https://github.com/Codeinwp/raft/archive/refs/heads/onboarding.zip"
}
},
"tests": {
"config": {
"WP_DEBUG": false,
Expand All @@ -18,14 +24,15 @@
"plugins": [
"."
],
"themes": [ "./test/emptytheme" ],
"mappings": {
"wp-content/mu-plugins": "./packages/e2e-tests/mu-plugins",
"wp-content/plugins/gutenberg-test-plugins": "./packages/e2e-tests/plugins",
"wp-content/themes/gutenberg-test-themes": "./test/gutenberg-test-themes",
"wp-content/themes/gutenberg-test-themes/twentytwentyone": "https://downloads.wordpress.org/theme/twentytwentyone.1.7.zip",
"wp-content/themes/gutenberg-test-themes/twentytwentythree": "https://downloads.wordpress.org/theme/twentytwentythree.1.0.zip"
}
"themes": [ "./test/emptytheme" ],
"mappings": {
"wp-content/mu-plugins": "./packages/e2e-tests/mu-plugins",
"wp-content/plugins/gutenberg-test-plugins": "./packages/e2e-tests/plugins",
"wp-content/themes/gutenberg-test-themes": "./test/gutenberg-test-themes",
"wp-content/themes/gutenberg-test-themes/twentytwentyone": "https://downloads.wordpress.org/theme/twentytwentyone.1.7.zip",
"wp-content/themes/gutenberg-test-themes/twentytwentythree": "https://downloads.wordpress.org/theme/twentytwentythree.1.0.zip",
"wp-content/themes/raft": "https://github.com/Codeinwp/raft/archive/refs/heads/onboarding.zip"
}
}
}
}
2 changes: 2 additions & 0 deletions inc/class-main.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,14 @@ public function autoload_classes() {
'\ThemeIsle\GutenbergBlocks\Plugins\Block_Conditions',
'\ThemeIsle\GutenbergBlocks\Plugins\Dashboard',
'\ThemeIsle\GutenbergBlocks\Plugins\Dynamic_Content',
'\ThemeIsle\GutenbergBlocks\Plugins\FSE_Onboarding',
'\ThemeIsle\GutenbergBlocks\Plugins\Options_Settings',
'\ThemeIsle\GutenbergBlocks\Plugins\Stripe_API',
'\ThemeIsle\GutenbergBlocks\Render\Masonry_Variant',
'\ThemeIsle\GutenbergBlocks\Server\Dashboard_Server',
'\ThemeIsle\GutenbergBlocks\Server\Dynamic_Content_Server',
'\ThemeIsle\GutenbergBlocks\Server\Stripe_Server',
'\ThemeIsle\GutenbergBlocks\Server\FSE_Onboarding_Server',
'\ThemeIsle\GutenbergBlocks\Integration\Form_Providers',
'\ThemeIsle\GutenbergBlocks\Integration\Form_Email',
'\ThemeIsle\GutenbergBlocks\Server\Form_Server',
Expand Down
2 changes: 2 additions & 0 deletions inc/plugins/class-dashboard.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
namespace ThemeIsle\GutenbergBlocks\Plugins;

use ThemeIsle\GutenbergBlocks\Pro;
use ThemeIsle\GutenbergBlocks\Plugins\FSE_Onboarding;

/**
* Class Dashboard
Expand Down Expand Up @@ -195,6 +196,7 @@ public function enqueue_options_assets() {
'docsLink' => Pro::get_docs_url(),
'showFeedbackNotice' => $this->should_show_feedback_notice(),
'deal' => ! Pro::is_pro_installed() ? $offer->get_localized_data() : array(),
'hasOnboarding' => false !== get_theme_support( FSE_Onboarding::SUPPORT_KEY ),
)
)
);
Expand Down
291 changes: 291 additions & 0 deletions inc/plugins/class-fse-onboarding.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,291 @@
<?php
/**
* Otter FSE_Onboarding.
*
* @package ThemeIsle\GutenbergBlocks\Plugins
*/

namespace ThemeIsle\GutenbergBlocks\Plugins;

use ThemeIsle\GutenbergBlocks\Pro;

/**
* Class FSE_Onboarding
*/
class FSE_Onboarding {

const OPTION_KEY = 'otter_onboarding_status';
const SUPPORT_KEY = 'otter-onboarding';

/**
* The main instance var.
*
* @var FSE_Onboarding|null
*/
protected static $instance = null;

/**
* Initialize the class
*/
public function init() {
add_action( 'after_switch_theme', array( $this, 'on_switch_theme' ) );
add_action( 'enqueue_block_editor_assets', array( $this, 'enqueue_options_assets' ) );
add_action( 'admin_menu', array( $this, 'register_menu_page' ) );
}

/**
* Register menu page
*
* @access public
* @return void
*/
public function register_menu_page() {
$has_support = get_theme_support( self::SUPPORT_KEY );

if ( false === $has_support || ! current_user_can( 'manage_options' ) || true !== boolval( get_option( 'themeisle_blocks_settings_onboarding_wizard', true ) ) ) {
return;
}

add_submenu_page(
'themes.php',
esc_html__( 'Theme Setup', 'otter-blocks' ),
esc_html__( 'Theme Setup', 'otter-blocks' ),
'manage_options',
'otter-onboarding',
function() {
$redirect = add_query_arg(
array(
'onboarding' => 'true',
),
admin_url( 'site-editor.php' )
);

echo '<p>Redirecting...</p>
<script>document.location.href = "' . esc_url( $redirect ) . '";</script>';
}
);
}

/**
* On switch theme
*
* @access public
* @return void
*/
public function on_switch_theme() {
// Check if the theme has support for FSE.
$support = get_theme_support( self::SUPPORT_KEY );

if ( false === $support ) {
return;
}

$status = get_option( self::OPTION_KEY, array() );
$slug = get_stylesheet();

if ( ! empty( $status[ $slug ] ) ) {
return;
}

// Run the onboarding.
$redirect = add_query_arg(
array(
'onboarding' => 'true',
),
admin_url( 'site-editor.php' )
);

// Redirect to the onboarding.
wp_safe_redirect( $redirect );
exit;
}

/**
* Set Onboarding Status
*
* @access public
* @return void
*/
public static function set_onboarding_status() {
$status = get_option( self::OPTION_KEY, array() );
$slug = get_stylesheet();

if ( ! empty( $status[ $slug ] ) ) {
return;
}

$status[ $slug ] = true;
update_option( self::OPTION_KEY, $status );
}

/**
* Get Theme Templates
*
* @access public
* @return array|false
*/
public function get_templates() {
$support = get_theme_support( self::SUPPORT_KEY );

if ( false === $support || ! is_array( $support ) || ( ! isset( $support[0]['templates'] ) && ! isset( $support[0]['page_templates'] ) ) ) {
return false;
}

$templates = array();

if ( isset( $support[0]['templates'] ) ) {
$templates = $support[0]['templates'];
}

if ( isset( $support[0]['page_templates'] ) ) {
$templates['page_templates'] = $support[0]['page_templates'];
}

if ( ! $templates ) {
return false;
}

foreach ( $templates as $key => $categories ) {
foreach ( $categories as $i => $template ) {
if ( file_exists( $template['file'] ) ) {
if ( 'php' === pathinfo( $template['file'], PATHINFO_EXTENSION ) ) {
$content = include $template['file'];
$templates[ $key ][ $i ]['content']['raw'] = $content;
} else {
$templates[ $key ][ $i ]['content']['raw'] = file_get_contents( $template['file'] );
}

unset( $templates[ $key ][ $i ]['file'] );
} else {
unset( $templates[ $key ][ $i ] );
}
}
}

return apply_filters( 'otter_fse_onboarding_templates', $templates );

}

/**
* Get Templates Types
*
* @access public
* @return array
*/
public function get_templates_types() {
$templates = $this->get_templates();

if ( ! $templates ) {
return array();
}

return array_keys( $templates );
}

/**
* Enqueue options assets.
*
* @access public
* @return void
*/
public function enqueue_options_assets() {
$current_screen = get_current_screen();
$has_support = get_theme_support( self::SUPPORT_KEY );

if (
false === $has_support ||
! current_user_can( 'manage_options' ) ||
! isset( $current_screen->id ) ||
'site-editor' !== $current_screen->id
) {
return;
}

// Flag onboarding status in case being run from a theme.
self::set_onboarding_status();

$asset_file = include OTTER_BLOCKS_PATH . '/build/onboarding/index.asset.php';

wp_enqueue_media();

wp_enqueue_style(
'otter-onboarding-styles',
OTTER_BLOCKS_URL . 'build/onboarding/style-index.css',
array( 'wp-components' ),
$asset_file['version']
);

wp_enqueue_script(
'otter-onboarding-scripts',
OTTER_BLOCKS_URL . 'build/onboarding/index.js',
$asset_file['dependencies'],
$asset_file['version'],
true
);

wp_set_script_translations( 'otter-onboarding-scripts', 'otter-blocks' );

wp_localize_script(
'otter-onboarding-scripts',
'otterOnboardingData',
apply_filters(
'otter_onboarding_data',
array(
'version' => OTTER_BLOCKS_VERSION,
'assetsPath' => OTTER_BLOCKS_URL . 'assets/',
'supportedSteps' => $this->get_templates_types(),
'license' => apply_filters( 'product_otter_license_key', 'free' ),
'rootUrl' => get_site_url(),
'dashboardUrl' => get_admin_url(),
'isDev' => defined( 'ENABLE_OTTER_PRO_DEV' ),
'userEmail' => wp_get_current_user()->user_email,
)
)
);
}

/**
* The instance method for the static class.
* Defines and returns the instance of the static class.
*
* @static
* @since 1.7.1
* @access public
* @return FSE_Onboarding
*/
public static function instance() {
if ( is_null( self::$instance ) ) {
self::$instance = new self();
self::$instance->init();
}

return self::$instance;
}

/**
* Throw error on object clone
*
* The whole idea of the singleton design pattern is that there is a single
* object therefore, we don't want the object to be cloned.
*
* @access public
* @since 1.7.1
* @return void
*/
public function __clone() {
// Cloning instances of the class is forbidden.
_doing_it_wrong( __FUNCTION__, esc_html__( 'Cheatin&#8217; huh?', 'otter-blocks' ), '1.0.0' );
}

/**
* Disable unserializing of the class
*
* @access public
* @since 1.7.1
* @return void
*/
public function __wakeup() {
// Unserializing instances of the class is forbidden.
_doing_it_wrong( __FUNCTION__, esc_html__( 'Cheatin&#8217; huh?', 'otter-blocks' ), '1.0.0' );
}
}
11 changes: 11 additions & 0 deletions inc/plugins/class-options-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -712,6 +712,17 @@ function ( $item ) {
),
)
);

register_setting(
'themeisle_blocks_settings',
'themeisle_blocks_settings_onboarding_wizard',
array(
'type' => 'boolean',
'description' => __( 'Enable Onboarding Wizard.', 'otter-blocks' ),
'show_in_rest' => true,
'default' => true,
)
);
}

/**
Expand Down
Loading
Loading