';
switch ( $id ) {
case 'persona':
return $open . '';
case 'shape':
return $open . '';
case 'overlaps':
return $open . '';
case 'connections':
return $open . '';
case 'checklist':
return $open . '';
case 'done':
return $open . '';
}
return '';
}
public static function step_lede( $id ) {
switch ( $id ) {
case 'persona': return __( 'Pick the hats you wear. Each one puts its groups first in the menu and on Home. Nothing is hidden, and you can change this here or from the menu bar whenever you like.', 'ai-eshop-optimizer' );
case 'shape': return __( 'Three things about the site that cannot be read from the install. The answers configure nothing: they decide which pages are suggested first.', 'ai-eshop-optimizer' );
case 'overlaps': return __( 'What this site already runs that Rooster One also does, with the evidence first, the steps to switch and the way back. Keeping what you have is a real choice here, and choosing it ends the reminders.', 'ai-eshop-optimizer' );
case 'connections': return __( 'Everything this plugin can connect to outside your shop, whether it is live right now, and where each one is set up. The settings stay on the page that uses them; nothing here asks any service anything until you open it.', 'ai-eshop-optimizer' );
case 'checklist': return __( 'Every line is read from the install on every visit; nothing here remembers a click. A tick means it is true now. A step you hide or mark as not applying can be brought back with the count beside it.', 'ai-eshop-optimizer' );
case 'done': return __( 'Thank you. Below is where this shop\'s own numbers say to go next, chosen for the hats you picked. Every step here can be reopened from Getting set up whenever you like.', 'ai-eshop-optimizer' );
}
return '';
}
public static function page_url() {
return add_query_arg( array( 'page' => AIEO_DMM::MENU_SLUG, 'dmm_tab' => 'getting_set_up' ), admin_url( 'admin.php' ) );
}
public static function step_url( $step ) {
return add_query_arg( 'aieo_step', sanitize_key( (string) $step ), self::page_url() ) . '#' . self::ANCHOR;
}
public static function current_step( array $states, $requested = '' ) {
$requested = sanitize_key( (string) $requested );
if ( '' !== $requested && in_array( $requested, self::STEPS, true ) ) {
return $requested;
}
return self::STEPS[0];
}
const META_PASSED = 'aieo_wizard_passed';
public static function passed( $uid ) {
$v = get_user_meta( (int) $uid, self::META_PASSED, true );
return is_array( $v ) ? array_values( array_intersect( self::STEPS, array_map( 'sanitize_key', $v ) ) ) : array();
}
public static function catch_leave() {
if ( ! empty( $_GET['aieo_leave'] ) && is_user_logged_in() ) {
self::mark_passed( get_current_user_id(), sanitize_key( wp_unslash( $_GET['aieo_leave'] ) ) );
}
}
public static function mark_passed( $uid, $step ) {
$uid = (int) $uid;
$step = sanitize_key( (string) $step );
if ( $uid < 1 || ! in_array( $step, self::STEPS, true ) ) {
return;
}
$list = self::passed( $uid );
if ( ! in_array( $step, $list, true ) ) {
$list[] = $step;
update_user_meta( $uid, self::META_PASSED, $list );
}
}
public static function states( $uid, $stages = null ) {
$held = class_exists( 'AIEO_Personas' ) ? AIEO_Personas::for_user( $uid ) : array();
$answered = class_exists( 'AIEO_Personas' ) && AIEO_Personas::answered( $uid );
$passed = self::passed( $uid );
$shape_ok = class_exists( 'AIEO_Shop_Shape' ) && AIEO_Shop_Shape::is_answered();
return array(
'persona' => $answered ? ( $held ? 'done' : 'skipped' ) : 'todo',
'shape' => $shape_ok ? 'done' : ( in_array( 'shape', $passed, true ) ? 'skipped' : 'todo' ),
'overlaps' => ( in_array( 'overlaps', $passed, true ) || 'done' === self::overlaps_state() ) ? 'done' : 'todo',
'connections' => in_array( 'connections', $passed, true ) ? 'done' : 'todo',
'checklist' => ( in_array( 'checklist', $passed, true ) || 'done' === self::checklist_state( $stages ) ) ? 'done' : 'todo',
'done' => in_array( 'done', $passed, true ) ? 'done' : 'todo',
);
}
public static function overlaps_state( $fresh = false ) {
$key = 'aieo_wizard_ov';
if ( ! $fresh ) {
$cached = get_transient( $key );
if ( 'done' === $cached || 'todo' === $cached ) {
return $cached;
}
}
$state = 'todo';
if ( class_exists( 'AIEO_Overlap' ) ) {
$present = (array) AIEO_Overlap::present();
$state = ( empty( $present ) || '' !== (string) AIEO_Overlap::decision( 'seo' ) ) ? 'done' : 'todo';
if ( 'todo' === $state ) {
$open = 0;
foreach ( $present as $pid ) {
if ( '' === (string) AIEO_Overlap::decision( $pid ) && 'alongside' !== (string) ( AIEO_Overlap::row( $pid )['family'] ?? '' ) ) {
$open++;
}
}
if ( 0 === $open || ( class_exists( 'AIEO_Simplify_Scan' ) && null !== AIEO_Simplify_Scan::verdict() ) ) {
$state = 'done';
}
}
}
set_transient( $key, $state, self::CHECKLIST_TTL );
return $state;
}
const CHECKLIST_TTL = 5 * MINUTE_IN_SECONDS;
private static function checklist_state( $stages ) {
$key = 'aieo_wizard_chk_' . (int) get_current_user_id();
if ( null === $stages ) {
$cached = get_transient( $key );
if ( 'done' === $cached || 'todo' === $cached ) {
return $cached;
}
$stages = class_exists( 'AIEO_Setup_Checklist' ) ? AIEO_Setup_Checklist::evaluate() : array();
}
$done = 0;
$all = 0;
foreach ( (array) $stages as $st ) {
$done += (int) ( $st['done'] ?? 0 );
$all += (int) ( $st['total'] ?? 0 );
}
$state = ( $all > 0 && $done >= $all ) ? 'done' : 'todo';
set_transient( $key, $state, self::CHECKLIST_TTL );
return $state;
}
public static function render( array $args = array() ) {
$w = self::vars( $args );
if ( ! $w ) {
return;
}
$path = AIEO_DIR . 'assets/pages/dmm/_wizard.php';
if ( ! file_exists( $path ) ) {
return;
}
include $path;
}
public static function vars( array $args = array() ) {
if ( ! class_exists( 'AIEO_DMM' ) || ! class_exists( 'AIEO_Shop_Shape' ) ) {
return null;
}
$uid = get_current_user_id();
$mode = ( isset( $args['mode'] ) && 'modal' === $args['mode'] ) ? 'modal' : 'page';
$want = isset( $args['step'] ) ? sanitize_key( (string) $args['step'] ) : ( isset( $_GET['aieo_step'] ) ? sanitize_key( wp_unslash( $_GET['aieo_step'] ) ) : '' );
$stages = null;
if ( isset( $args['stages'] ) && is_array( $args['stages'] ) ) {
$stages = $args['stages'];
} elseif ( 'checklist' === $want && class_exists( 'AIEO_Setup_Checklist' ) ) {
$stages = AIEO_Setup_Checklist::evaluate();
}
if ( 'page' === $mode && ! empty( $_GET['aieo_leave'] ) ) {
self::mark_passed( $uid, sanitize_key( wp_unslash( $_GET['aieo_leave'] ) ) );
}
if ( 'overlaps' === $want ) {
self::overlaps_state( true );
}
$states = self::states( $uid, $stages );
$requested = isset( $args['step'] ) ? (string) $args['step'] : ( isset( $_GET['aieo_step'] ) ? sanitize_key( wp_unslash( $_GET['aieo_step'] ) ) : '' );
$step = self::current_step( $states, $requested );
$flag = isset( $args['flag'] ) ? (string) $args['flag'] : ( isset( $_GET['persona'] ) ? sanitize_key( wp_unslash( $_GET['persona'] ) ) : '' );
$idx = array_search( $step, self::STEPS, true );
$prev = $idx > 0 ? self::STEPS[ $idx - 1 ] : '';
$next = $idx < count( self::STEPS ) - 1 ? self::STEPS[ $idx + 1 ] : '';
$steps = array();
foreach ( self::STEPS as $s ) {
$state = $states[ $s ];
if ( $s === $step ) {
$state = 'current';
}
$steps[] = array( 'id' => $s, 'label' => self::step_label( $s ), 'short' => self::step_short( $s ), 'state' => $state, 'url' => self::step_url( $s ) );
}
$w = array(
'mode' => $mode,
'step' => $step,
'steps' => $steps,
'prev' => $prev,
'next' => $next,
'prev_url' => '' !== $prev ? self::step_url( $prev ) : '',
'next_url' => '' !== $next ? add_query_arg( 'aieo_leave', $step, self::step_url( $next ) ) : '',
'page_url' => self::page_url(),
'flag' => $flag,
'nonce' => wp_create_nonce( self::NONCE ),
'held' => class_exists( 'AIEO_Personas' ) ? AIEO_Personas::for_user( $uid ) : array(),
);
switch ( $step ) {
case 'persona':
$w += self::persona_vars( $uid );
break;
case 'shape':
$w += self::shape_vars( $uid );
break;
case 'overlaps':
$w += self::overlaps_vars();
break;
case 'connections':
$w['connections_module'] = AIEO_DMM::instance()->get_module( 'connections' );
break;
case 'checklist':
if ( null === $stages ) {
$stages = class_exists( 'AIEO_Setup_Checklist' ) ? AIEO_Setup_Checklist::evaluate() : array();
}
$w += self::checklist_vars( $stages );
break;
case 'done':
$w['recs'] = self::recommendations( $uid );
break;
}
return $w;
}
public static function recommendations( $uid ) {
$recs = array();
$seen = array();
$held = class_exists( 'AIEO_Personas' ) ? AIEO_Personas::for_user( $uid ) : array();
foreach ( $held as $code ) {
$fw = AIEO_Personas::first_win( array( $code ) );
if ( $fw && empty( $seen[ $fw['id'] ] ) ) {
$seen[ $fw['id'] ] = true;
$recs[] = array( 'kind' => 'first_win', 'persona' => $code, 'id' => $fw['id'], 'label' => $fw['label'], 'why' => $fw['why'], 'url' => $fw['url'] );
}
}
if ( empty( $recs ) ) {
$shape = AIEO_Shop_Shape::get();
$fw = $shape ? self::shape_first_win( $shape ) : null;
if ( $fw ) {
$seen[ $fw['id'] ] = true;
$recs[] = array( 'kind' => 'first_win', 'persona' => '', 'id' => $fw['id'], 'label' => $fw['label'], 'why' => $fw['why'], 'url' => $fw['url'] );
}
}
$conn = class_exists( 'AIEO_DMM' ) ? AIEO_DMM::instance()->get_module( 'connections' ) : null;
if ( $held && $conn && method_exists( $conn, 'rows_for_personas' ) ) {
$n = 0;
foreach ( $conn->rows_for_personas( $held ) as $r ) {
if ( 'off' !== $r['state'] || $n >= 3 ) {
continue;
}
$n++;
$recs[] = array( 'kind' => 'connect', 'persona' => $r['persona'], 'id' => '', 'label' => $r['name'], 'why' => $r['gives'], 'url' => $r['url'] );
}
}
if ( class_exists( 'AIEO_Setup_Checklist' ) ) {
$n = 0;
foreach ( AIEO_Setup_Checklist::evaluate() as $stage ) {
foreach ( (array) $stage['steps'] as $st ) {
if ( $n >= 3 || '' !== (string) $st['decision'] || '' === (string) $st['action_url']
|| ! in_array( $st['state'], array( AIEO_Setup_Checklist::STATE_OPEN, AIEO_Setup_Checklist::STATE_PARTIAL ), true ) ) {
continue;
}
$n++;
$recs[] = array( 'kind' => 'step', 'persona' => '', 'id' => (string) $st['id'], 'label' => (string) $st['label'], 'why' => (string) $st['detail'], 'url' => (string) $st['action_url'] );
}
}
}
return array_slice( $recs, 0, 8 );
}
public static function profile( $uid ) {
$uid = (int) $uid;
$shape = class_exists( 'AIEO_Shop_Shape' ) ? AIEO_Shop_Shape::get() : null;
$held = class_exists( 'AIEO_Personas' ) ? AIEO_Personas::for_user( $uid ) : array();
$fw = $held && class_exists( 'AIEO_Personas' ) ? AIEO_Personas::first_win( $held ) : null;
return array(
'personas' => $held,
'personas_answered' => class_exists( 'AIEO_Personas' ) && AIEO_Personas::answered( $uid ),
'site_default' => class_exists( 'AIEO_Personas' ) ? AIEO_Personas::site_default() : array(),
'survey_role' => class_exists( 'AIEO_Personas' ) ? sanitize_key( (string) get_user_meta( $uid, AIEO_Personas::SURVEY_ROLE_META, true ) ) : '',
'shape' => $shape ? array( 'sell' => $shape['sell'], 'where' => $shape['where'], 'first' => $shape['first'] ) : null,
'overlap_seo' => class_exists( 'AIEO_Overlap' ) ? (string) AIEO_Overlap::decision( 'seo' ) : '',
'passed' => self::passed( $uid ),
'first_win' => $fw ? $fw['id'] : '',
);
}
public static function is_connected() {
return 'connected' === (string) get_option( 'aieo_rooster_status' ) && '' !== (string) get_option( 'aieo_rooster_api_key', '' );
}
public static function submit_profile( $uid, $reason ) {
if ( ! class_exists( 'AIEO_Portal_Client' ) || (int) $uid < 1 ) {
return;
}
$p = self::profile( $uid );
$row = static function ( $q, $codes ) {
$codes = array_values( array_filter( array_map( 'strval', (array) $codes ), 'strlen' ) );
return $codes ? array( 'q' => $q, 'd' => 'answered', 'c' => $codes ) : array( 'q' => $q, 'd' => 'skipped' );
};
$answers = array(
$row( 'personas', $p['personas'] ),
$row( 'shape_sell', $p['shape']['sell'] ?? '' ),
$row( 'shape_where', $p['shape']['where'] ?? '' ),
$row( 'shape_first', $p['shape']['first'] ?? '' ),
$row( 'overlap_seo', $p['overlap_seo'] ),
$row( 'passed', $p['passed'] ),
$row( 'first_win', $p['first_win'] ),
);
$labels = static function ( array $a ) { return array_map( 'strval', $a ); };
$q = class_exists( 'AIEO_Shop_Shape' ) ? AIEO_Shop_Shape::questions() : array();
$manifest = array( 'questions' => array(
array( 'code' => 'personas', 'label' => self::step_label( 'persona' ), 'choices' => class_exists( 'AIEO_Personas' ) ? $labels( wp_list_pluck( AIEO_Personas::defs(), 'label' ) ) : array() ),
array( 'code' => 'shape_sell', 'label' => (string) ( $q['sell']['label'] ?? 'sell' ), 'choices' => $labels( (array) ( $q['sell']['options'] ?? array() ) ) ),
array( 'code' => 'shape_where', 'label' => (string) ( $q['where']['label'] ?? 'where' ), 'choices' => $labels( (array) ( $q['where']['options'] ?? array() ) ) ),
array( 'code' => 'shape_first', 'label' => (string) ( $q['first']['label'] ?? 'first' ), 'choices' => $labels( (array) ( $q['first']['options'] ?? array() ) ) ),
array( 'code' => 'overlap_seo', 'label' => self::step_label( 'overlaps' ), 'choices' => array( 'switch' => 'switch', 'kept' => 'kept', 'later' => 'later' ) ),
array( 'code' => 'passed', 'label' => __( 'Steps passed', 'ai-eshop-optimizer' ), 'choices' => array_combine( self::STEPS, self::STEPS ) ),
array( 'code' => 'first_win', 'label' => __( 'First win', 'ai-eshop-optimizer' ), 'choices' => array() ),
) );
AIEO_Portal_Client::submit( 'form', array(
'form_code' => 'wizard',
'form_version' => '1',
'answers' => $answers,
'manifest' => $manifest,
'contact_email' => '',
'respondent' => substr( hash_hmac( 'sha256', (string) $uid, wp_salt( 'auth' ) ), 0, 16 ),
'plugin_version' => defined( 'AIEO_VERSION' ) ? AIEO_VERSION : '',
'locale' => get_user_locale(),
'environment_type' => wp_get_environment_type(),
'screen' => 'wizard:' . sanitize_key( (string) $reason ),
) );
}
public static function maybe_sync_profile( $uid ) {
if ( ! self::is_connected() || get_transient( 'aieo_wizard_sync_' . (int) $uid ) ) {
return;
}
set_transient( 'aieo_wizard_sync_' . (int) $uid, 1, MINUTE_IN_SECONDS );
self::submit_profile( $uid, 'wizard' );
}
public static function on_status_written( $old, $new ) {
if ( 'connected' !== (string) $new || 'connected' === (string) $old ) {
return;
}
$uid = get_current_user_id();
if ( $uid < 1 ) {
return;
}
self::submit_profile( $uid, 'connect' );
}
private static function persona_vars( $uid ) {
if ( ! class_exists( 'AIEO_Personas' ) ) {
return array( 'persona' => null );
}
$held = AIEO_Personas::for_user( $uid );
$answered = AIEO_Personas::answered( $uid );
$survey = $answered ? array() : AIEO_Personas::from_survey( $uid );
$counts = array();
foreach ( AIEO_Personas::codes() as $c ) {
$counts[ $c ] = AIEO_Personas::counts( array( $c ) );
}
$total = AIEO_Personas::counts( array() );
return array(
'persona' => array(
'defs' => AIEO_Personas::defs(),
'held' => $held,
'answered' => $answered,
'pretick' => $answered ? $held : ( $held ? $held : $survey ),
'from_survey' => ! $answered && empty( $held ) && ! empty( $survey ),
'counts' => $counts,
'total' => (int) $total['pages_total'],
'save_url' => admin_url( 'admin-post.php?action=' . AIEO_Personas::ACTION_SAVE ),
'can_default' => current_user_can( 'manage_options' ),
'site_default' => AIEO_Personas::site_default(),
'first_win' => AIEO_Personas::first_win( $held ),
),
);
}
private static function shape_vars( $uid ) {
$shape = AIEO_Shop_Shape::get();
return array(
'shape' => $shape,
'questions' => AIEO_Shop_Shape::questions(),
'current' => is_array( $shape ) ? $shape : AIEO_Shop_Shape::proposed(),
'facts' => AIEO_Shop_Shape::facts(),
'summary' => AIEO_Shop_Shape::summary(),
'reduced_on' => AIEO_Shop_Shape::reduced_on( $uid ),
'shape_save_url' => admin_url( 'admin-post.php?action=' . AIEO_DMM_Getting_Set_Up::ACTION_SHAPE_SAVE ),
'shape_clear_url' => admin_url( 'admin-post.php?action=' . AIEO_DMM_Getting_Set_Up::ACTION_SHAPE_CLEAR ),
'shape_first_win' => is_array( $shape ) ? self::shape_first_win( $shape ) : null,
);
}
private static function shape_first_win( array $shape ) {
$fw = AIEO_Shop_Shape::first_win( $shape['first'] );
if ( ! AIEO_Shop_Shape::destination_exists( $fw['tab'] ) ) {
return null;
}
$dest = class_exists( 'AIEO_Personas' ) ? AIEO_Personas::destination( $fw['tab'] ) : null;
return array(
'id' => $fw['tab'],
'label' => $dest ? $dest['label'] : $fw['tab'],
'url' => AIEO_DMM::instance()->get_subtab_url( $fw['tab'] ),
'why' => $fw['why'],
);
}
private static function overlaps_vars() {
$mod = AIEO_DMM::instance()->get_module( 'overlaps' );
if ( ! $mod || ! method_exists( $mod, 'template_vars' ) ) {
return array( 'overlaps' => null );
}
$vars = $mod->template_vars();
$catalogue = array();
if ( class_exists( 'AIEO_Overlap' ) ) {
foreach ( AIEO_Overlap::rows() as $row ) {
if ( 'unrelated' !== $row['family'] ) {
$catalogue[ (string) $row['family'] ][] = (string) $row['label'];
}
}
}
$vars['catalogue'] = $catalogue;
$vars['module'] = $mod;
return array( 'overlaps' => $vars );
}
private static function checklist_vars( array $stages ) {
$running = array();
if ( class_exists( 'AIEO_Setup_Checklist' ) ) {
foreach ( AIEO_Setup_Checklist::running_now() as $r ) {
if ( empty( $r['on'] ) || empty( $r['tab'] ) || ! AIEO_Shop_Shape::destination_exists( $r['tab'] ) ) {
continue;
}
$d = class_exists( 'AIEO_Personas' ) ? AIEO_Personas::destination( $r['tab'] ) : null;
$r['label'] = $d ? $d['label'] : (string) $r['tab'];
$r['url'] = AIEO_DMM::instance()->get_subtab_url( $r['tab'] );
$running[] = $r;
}
}
$uid = get_current_user_id();
$held = class_exists( 'AIEO_Personas' ) ? AIEO_Personas::for_user( $uid ) : array();
$fw = $held ? AIEO_Personas::first_win( $held ) : null;
if ( ! $fw ) {
$shape = AIEO_Shop_Shape::get();
$fw = $shape ? self::shape_first_win( $shape ) : null;
}
return array(
'stages' => $stages,
'running' => $running,
'decide_url' => admin_url( 'admin-post.php?action=' . AIEO_DMM_Getting_Set_Up::ACTION_STEP_DECIDE ),
'decide_set_url' => admin_url( 'admin-post.php?action=' . AIEO_DMM_Getting_Set_Up::ACTION_SET_DECIDE ),
'first_win' => $fw,
);
}
public static function save_personas( $uid, array $post ) {
$codes = array();
if ( empty( $post['skip'] ) && ! empty( $post['personas'] ) && is_array( $post['personas'] ) ) {
$codes = array_map( 'sanitize_key', array_map( 'strval', $post['personas'] ) );
}
$codes = AIEO_Personas::save( $uid, $codes );
if ( isset( $post['site_default_present'] ) && current_user_can( 'manage_options' ) ) {
AIEO_Personas::set_site_default( ! empty( $post['site_default'] ) ? $codes : array() );
}
return $codes;
}
public static function save_shape( $uid, array $post ) {
$in = array(
'sell' => isset( $post['sell'] ) ? sanitize_key( (string) $post['sell'] ) : '',
'where' => isset( $post['where'] ) ? sanitize_key( (string) $post['where'] ) : '',
'first' => isset( $post['first'] ) ? sanitize_key( (string) $post['first'] ) : '',
);
$ok = AIEO_Shop_Shape::save( $in, $uid );
$added = $ok ? AIEO_Shop_Shape::seed_pins( $uid ) : array();
if ( $ok && isset( $post['reduced_present'] ) ) {
AIEO_Shop_Shape::set_reduced( $uid, ! empty( $post['reduced'] ) );
}
return array( 'ok' => $ok, 'seeded' => count( $added ) );
}
private static function cap() {
return defined( 'AIEO_CAPABILITY' ) ? AIEO_CAPABILITY : 'manage_options';
}
public static function ajax_render() {
check_ajax_referer( self::NONCE, 'nonce' );
if ( ! current_user_can( self::cap() ) ) {
wp_send_json_error( array( 'message' => __( 'Unauthorized', 'ai-eshop-optimizer' ) ), 403 );
}
$step = isset( $_POST['step'] ) ? sanitize_key( wp_unslash( $_POST['step'] ) ) : '';
if ( ! empty( $_POST['leave'] ) ) {
self::mark_passed( get_current_user_id(), sanitize_key( wp_unslash( $_POST['leave'] ) ) );
}
wp_send_json_success( self::modal_payload( $step ) );
}
public static function ajax_submit() {
check_ajax_referer( self::NONCE, 'nonce' );
if ( ! current_user_can( self::cap() ) ) {
wp_send_json_error( array( 'message' => __( 'Unauthorized', 'ai-eshop-optimizer' ) ), 403 );
}
$uid = get_current_user_id();
$step = isset( $_POST['step'] ) ? sanitize_key( wp_unslash( $_POST['step'] ) ) : '';
$post = wp_unslash( $_POST );
$flag = '';
if ( 'persona' === $step && class_exists( 'AIEO_Personas' ) ) {
self::save_personas( $uid, $post );
self::mark_passed( $uid, 'persona' );
self::maybe_sync_profile( $uid );
$flag = 'saved';
} elseif ( 'shape' === $step ) {
$r = self::save_shape( $uid, $post );
if ( ! $r['ok'] ) {
wp_send_json_success( self::modal_payload( 'shape', 'incomplete' ) );
}
self::mark_passed( $uid, 'shape' );
self::maybe_sync_profile( $uid );
} else {
wp_send_json_error( array( 'message' => __( 'This step is saved from its own page.', 'ai-eshop-optimizer' ) ) );
}
$idx = array_search( $step, self::STEPS, true );
$next = false !== $idx && $idx < count( self::STEPS ) - 1 ? self::STEPS[ $idx + 1 ] : $step;
wp_send_json_success( self::modal_payload( $next, $flag ) );
}
private static function modal_payload( $step, $flag = '' ) {
ob_start();
self::render( array( 'mode' => 'modal', 'step' => $step, 'flag' => $flag ) );
$html = (string) ob_get_clean();
return array( 'html' => $html, 'step' => $step );
}
public static function enqueue_styles() {
foreach ( array(
'aieo-tokens' => array(),
'aieo-controls' => array( 'aieo-tokens' ),
'aieo-personas' => array( 'aieo-tokens', 'aieo-controls' ),
'aieo-getting-set-up' => array( 'aieo-tokens' ),
) as $handle => $deps ) {
$path = AIEO_DIR . 'assets/css/' . $handle . '.css';
wp_enqueue_style( $handle, AIEO_URI . 'assets/css/' . $handle . '.css', $deps, file_exists( $path ) ? (string) filemtime( $path ) : AIEO_VERSION );
}
}
public static function enqueue_modal_script() {
$js = AIEO_DIR . 'assets/js/aieo-wizard.js';
wp_enqueue_script( 'aieo-wizard', AIEO_URI . 'assets/js/aieo-wizard.js', array(), file_exists( $js ) ? (string) filemtime( $js ) : AIEO_VERSION, true );
wp_localize_script( 'aieo-wizard', 'aieoWizard', array(
'ajaxUrl' => admin_url( 'admin-ajax.php' ),
'render' => self::AJAX_RENDER,
'submit' => self::AJAX_SUBMIT,
'nonce' => wp_create_nonce( self::NONCE ),
'pageUrl' => self::page_url(),
'i18n' => array(
'loading' => __( 'Loading…', 'ai-eshop-optimizer' ),
'failed' => __( 'Could not load this step. Open Getting set up instead.', 'ai-eshop-optimizer' ),
),
) );
}
}
add_action( 'admin_init', array( 'AIEO_Wizard', 'catch_leave' ) );
add_action( 'update_option_aieo_rooster_status', array( 'AIEO_Wizard', 'on_status_written' ), 10, 2 );
add_action( 'add_option_aieo_rooster_status', static function ( $option, $value ) { AIEO_Wizard::on_status_written( '', $value ); }, 10, 2 );
add_action( 'wp_ajax_' . AIEO_Wizard::AJAX_RENDER, array( 'AIEO_Wizard', 'ajax_render' ) );
add_action( 'wp_ajax_' . AIEO_Wizard::AJAX_SUBMIT, array( 'AIEO_Wizard', 'ajax_submit' ) );