Skip to content

Commit

Permalink
Merge pull request #3581 from Automattic/feat/ia-setup
Browse files Browse the repository at this point in the history
feat(ia): setup wizard
  • Loading branch information
jaredrethman authored Dec 18, 2024
2 parents 1483c09 + 87b7a5c commit 9a7d0c7
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 15 deletions.
8 changes: 8 additions & 0 deletions includes/class-newspack.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ private function define_constants() {
define( 'NEWSPACK_ACTIVATION_TRANSIENT', '_newspack_activation_redirect' );
define( 'NEWSPACK_NRH_CONFIG', 'newspack_nrh_config' );
define( 'NEWSPACK_CLIENT_ID_COOKIE_NAME', 'newspack-cid' );
define( 'NEWSPACK_SETUP_COMPLETE', 'newspack_setup_complete' );
}

/**
Expand Down Expand Up @@ -387,6 +388,13 @@ public static function is_debug_mode() {
return defined( 'WP_NEWSPACK_DEBUG' ) && WP_NEWSPACK_DEBUG;
}

/**
* Is the Setup completed?
*/
public static function is_setup_complete() {
return '1' === get_option( NEWSPACK_SETUP_COMPLETE, '0' );
}

/**
* Load the common assets.
*/
Expand Down
2 changes: 1 addition & 1 deletion includes/class-wizards.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ class Wizards {
*/
public static function init() {
self::$wizards = [
'setup' => new Setup_Wizard(),
'site-design' => new Site_Design_Wizard(),
'syndication' => new Syndication_Wizard(),
'analytics' => new Analytics_Wizard(),
Expand All @@ -41,6 +40,7 @@ public static function init() {
'settings' => new Settings(),
// v2 Information Architecture.
'newspack-dashboard' => new Newspack_Dashboard(),
'setup' => new Setup_Wizard(),
'newspack-settings' => new Newspack_Settings(
[
'sections' => [
Expand Down
30 changes: 21 additions & 9 deletions includes/wizards/class-setup-wizard.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@

use WP_Error, WP_REST_Server;
defined( 'ABSPATH' ) || exit;
require_once NEWSPACK_ABSPATH . '/includes/wizards/class-wizard.php';

define( 'NEWSPACK_SETUP_COMPLETE', 'newspack_setup_complete' );

/**
* Setup Newspack.
Expand All @@ -36,6 +33,20 @@ class Setup_Wizard extends Wizard {
*/
protected $slug = 'newspack-setup-wizard';

/**
* The parent menu item name.
*
* @var string
*/
public $parent_menu = 'newspack-dashboard';

/**
* Make sure Setup is first submenu item (after the dashboard wizard creates the "Newspack" menu).
*
* @var int.
*/
protected $admin_menu_priority = 2;

/**
* The capability required to access this wizard.
*
Expand All @@ -56,7 +67,7 @@ class Setup_Wizard extends Wizard {
public function __construct() {
parent::__construct();
add_action( 'rest_api_init', [ $this, 'register_api_endpoints' ] );
if ( ! get_option( NEWSPACK_SETUP_COMPLETE ) ) {
if ( ! Newspack::is_setup_complete() ) {
add_action( 'current_screen', [ $this, 'redirect_to_setup' ] );
add_action( 'admin_menu', [ $this, 'hide_non_setup_menu_items' ], 1000 );
}
Expand Down Expand Up @@ -609,14 +620,15 @@ public function api_update_services( $request ) {
}
if ( true === $request['reader-revenue']['is_service_enabled'] ) {
Plugin_Manager::activate( 'woocommerce' );
$rr_wizard = new Reader_Revenue_Wizard();
if ( isset( $request['reader-revenue']['donation_data'] ) ) {
$rr_wizard = new Audience_Donations();
$rr_wizard->update_donation_settings( $request['reader-revenue']['donation_data'] );
}
if ( ! empty( $request['reader-revenue']['payment_gateways']['stripe'] ) ) {
$audience_wizard = new Audience_Wizard();
$stripe_settings = $request['reader-revenue']['payment_gateways']['stripe'];
$stripe_settings['enabled'] = true;
$rr_wizard->update_stripe_settings( $stripe_settings );
$audience_wizard->update_stripe_settings( $stripe_settings );
}
}
if ( true === $request['google-ad-manager']['is_service_enabled'] ) {
Expand Down Expand Up @@ -682,9 +694,9 @@ public function hide_non_setup_menu_items() {
if ( ! current_user_can( $this->capability ) ) {
return;
}
foreach ( $submenu['newspack'] as $key => $value ) {
foreach ( $submenu['newspack-dashboard'] as $key => $value ) {
if ( 'newspack-setup-wizard' !== $value[2] ) {
unset( $submenu['newspack'][ $key ] );
unset( $submenu['newspack-dashboard'][ $key ] );
}
}
}
Expand All @@ -694,7 +706,7 @@ public function hide_non_setup_menu_items() {
*/
public function redirect_to_setup() {
$screen = get_current_screen();
if ( $screen && 'toplevel_page_newspack' === $screen->id ) {
if ( $screen && 'toplevel_page_newspack-dashboard' === $screen->id ) {
$setup_url = Wizards::get_url( 'setup' );
wp_safe_redirect( esc_url( $setup_url ) );
exit;
Expand Down
6 changes: 3 additions & 3 deletions includes/wizards/class-wizard.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ public function enqueue_scripts_and_styles() {
$support_email = ( defined( 'NEWSPACK_SUPPORT_EMAIL' ) && NEWSPACK_SUPPORT_EMAIL ) ? NEWSPACK_SUPPORT_EMAIL : false;

$urls = [
'dashboard' => Wizards::get_url( 'dashboard' ),
'dashboard' => Wizards::get_url( 'newspack-dashboard' ),
'public_path' => Newspack::plugin_url() . '/dist/',
'bloginfo' => [
'name' => get_bloginfo( 'name' ),
Expand All @@ -171,7 +171,7 @@ public function enqueue_scripts_and_styles() {
array(
'newspack_reset' => 'starter-content',
),
Wizards::get_url( 'dashboard' )
Wizards::get_url( 'newspack-dashboard' )
)
);
}
Expand All @@ -184,7 +184,7 @@ public function enqueue_scripts_and_styles() {
array(
'newspack_reset' => 'reset',
),
Wizards::get_url( 'dashboard' )
Wizards::get_url( 'newspack-dashboard' )
)
);
}
Expand Down
1 change: 1 addition & 0 deletions src/wizards/setup/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@

.newspack--error,
.newspack-checkbox-icon {
line-height: 24px;
margin-right: 8px;
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/wizards/setup/views/services/ReaderRevenue.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@ import { __ } from '@wordpress/i18n';
import Platform from '../../../audience/components/platform';
import { DonationAmounts } from '../../../audience/views/donations/configuration';
import { Wizard } from '../../../../components/src';
import { AUDIENCE_DONATIONS_WIZARD_SLUG } from '../../../audience/constants';

const ReaderRevenue = ( { className } ) => {
const wizardData = Wizard.useWizardData( 'audience-donations' );
const wizardData = Wizard.useWizardData( AUDIENCE_DONATIONS_WIZARD_SLUG );
return (
<div className={ classnames( className, { 'o-50': isEmpty( wizardData ) } ) }>
<Platform />
Expand Down
3 changes: 2 additions & 1 deletion src/wizards/setup/views/services/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { withWizardScreen, Wizard, ActionCard, hooks } from '../../../../compone
import ReaderRevenue from './ReaderRevenue';
import { Settings as NewslettersSettings } from '../../../newsletters/views';
import GAMOnboarding from '../../../advertising/components/onboarding';
import { AUDIENCE_DONATIONS_WIZARD_SLUG } from '../../../audience/constants';
import './style.scss';

const SERVICES_LIST = {
Expand Down Expand Up @@ -56,7 +57,7 @@ const Services = ( { renderPrimaryButton } ) => {
const [ services, updateServices ] = hooks.useObjectState( SERVICES_LIST );
const [ isLoading, setIsLoading ] = useState( true );
const slugs = keys( services );
const wizardData = Wizard.useWizardData( 'audience-donations' );
const wizardData = Wizard.useWizardData( AUDIENCE_DONATIONS_WIZARD_SLUG );

useEffect( () => {
apiFetch( {
Expand Down

0 comments on commit 9a7d0c7

Please sign in to comment.