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

feat(ia): setup wizard #3581

Merged
merged 20 commits into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
e9df3a2
feat(ia-setup): initial dev
ronchambers Nov 25, 2024
97ac4a6
feat: conditionally load wizards if setup complete
jaredrethman Nov 26, 2024
7161d36
Merge remote-tracking branch 'origin/feat/epic-ia-trunk-rasacc' into …
jaredrethman Dec 6, 2024
32a6b10
Merge remote-tracking branch 'origin/feat/epic-ia-trunk-rasacc' into …
jaredrethman Dec 11, 2024
53b78d2
refactor: `is_setup_complete` method
jaredrethman Dec 12, 2024
858277d
refactor: only setup if `newspack_setup_complete` is not set
jaredrethman Dec 12, 2024
b466258
feat: #issuecomment-2539808085
jaredrethman Dec 12, 2024
ea94615
refactor: move wizard class instantiations outside of conditional
jaredrethman Dec 16, 2024
88a93b8
feat(ia): network, disallow menu to appear before setup
jaredrethman Dec 16, 2024
26adf0d
feat(ia): newsletters, disallow menu to appear before setup
jaredrethman Dec 16, 2024
77773e6
refactor: remove unnecessary `admin_menu` hook, use is setup method
jaredrethman Dec 16, 2024
51d770f
feat: wrap `admin_menu` in `is_setup_complete` method
jaredrethman Dec 16, 2024
fe5f058
feat: dashboard, always show menu
jaredrethman Dec 16, 2024
f4acc57
refactor: update audience donations endpoint
jaredrethman Dec 16, 2024
95f62e6
Merge remote-tracking branch 'origin/epic/ia' into feat/ia-setup
jaredrethman Dec 17, 2024
4b9dd24
revert(ia): `is_setup_complete` conditionals
jaredrethman Dec 18, 2024
f463137
Merge remote-tracking branch 'origin/epic/ia' into feat/ia-setup
jaredrethman Dec 18, 2024
7ba88a2
feat(ia-setup__review): roll back dashboard
ronchambers Dec 18, 2024
3207789
feat(ia-setup__review): roll back setup
ronchambers Dec 18, 2024
87b7a5c
Merge remote-tracking branch 'origin/feat/ia-setup__review' into feat…
jaredrethman Dec 18, 2024
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
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