| 1 |
<?php |
| 2 |
/** |
| 3 |
* Template for the MLSImport onboarding wizard |
| 4 |
* |
| 5 |
* This file provides the main structure for the onboarding wizard interface. |
| 6 |
* It displays the header, step navigation, and content for the current step. |
| 7 |
* |
| 8 |
* Outer shell rendered for the mlsimport-onboarding admin page: logo/title bar, |
| 9 |
* a progress bar with numbered step markers, the current step's body (delegated |
| 10 |
* to mlsimport_render_onboarding_step()), Back/Continue (or Complete Setup) |
| 11 |
* actions, and a footer with support/restart links. Step list and current step |
| 12 |
* come from mlsimport_get_steps() / mlsimport_get_current_step(). The form posts |
| 13 |
* back to itself with the onboarding nonce; step content is included inside it. |
| 14 |
* |
| 15 |
* NOTE: comments here live only inside PHP regions; the inline HTML below is |
| 16 |
* emitted verbatim and is intentionally left uncommented. |
| 17 |
* |
| 18 |
* @link https://mlsimport.com/ |
| 19 |
* @since 6.1.0 |
| 20 |
* |
| 21 |
* @package Mlsimport |
| 22 |
* @subpackage Mlsimport/admin/partials |
| 23 |
*/ |
| 24 |
|
| 25 |
// If this file is called directly, abort. |
| 26 |
if (!defined('WPINC')) { |
| 27 |
die; |
| 28 |
} |
| 29 |
|
| 30 |
// Ordered map of wizard steps (id => step data). |
| 31 |
// Get all steps |
| 32 |
$steps = mlsimport_get_steps(); |
| 33 |
|
| 34 |
// Bail out early if there are no steps to render. |
| 35 |
// Check if steps exist |
| 36 |
if (empty($steps) || !is_array($steps)) { |
| 37 |
return; |
| 38 |
} |
| 39 |
|
| 40 |
// Resolve which step is currently being displayed. |
| 41 |
// Get current step |
| 42 |
$current_step = mlsimport_get_current_step(); |
| 43 |
|
| 44 |
// Derive index/total and the progress bar fill percentage from the step keys. |
| 45 |
// Get all step keys for progress calculation |
| 46 |
$step_keys = array_keys($steps); |
| 47 |
$current_step_index = array_search($current_step, $step_keys); |
| 48 |
$total_steps = count($steps); |
| 49 |
$progress_percentage = ($current_step_index / ($total_steps - 1)) * 100; |
| 50 |
|
| 51 |
// Data (title/description) for the current step, with a safe fallback. |
| 52 |
// Get current step data |
| 53 |
$current_step_data = isset($steps[$current_step]) ? $steps[$current_step] : array( |
| 54 |
'title' => __('Unknown Step', 'mlsimport'), |
| 55 |
'description' => '', |
| 56 |
); |
| 57 |
|
| 58 |
// Back button shows only when not on the first step. |
| 59 |
// Check if we can go back |
| 60 |
$can_go_back = $current_step_index > 0; |
| 61 |
|
| 62 |
// True on the final step (switches the primary button to "Complete Setup"). |
| 63 |
// Check if we're on the last step |
| 64 |
$is_last_step = $current_step_index === count($step_keys) - 1; |
| 65 |
|
| 66 |
// Compute the next/previous step ids (empty at the ends). |
| 67 |
// Get next/previous step URLs |
| 68 |
$next_step = $current_step_index < count($step_keys) - 1 ? $step_keys[$current_step_index + 1] : ''; |
| 69 |
$prev_step = $current_step_index > 0 ? $step_keys[$current_step_index - 1] : ''; |
| 70 |
|
| 71 |
// Build the admin URLs used by the Back/next navigation. |
| 72 |
$next_url = admin_url('admin.php?page=mlsimport-onboarding&step=' . $next_step); |
| 73 |
$prev_url = admin_url('admin.php?page=mlsimport-onboarding&step=' . $prev_step); |
| 74 |
|
| 75 |
?> |
| 76 |
<div class="mlsimport-wizard-wrap"> |
| 77 |
<div class="mlsimport-wizard-header-bar"> |
| 78 |
|
| 79 |
|
| 80 |
<?php |
| 81 |
echo '<img src="' . MLSIMPORT_PLUGIN_URL . '/img/mlsimport-logo.webp" alt="My Plugin Logo" style="max-width:200px;" />'; |
| 82 |
?> |
| 83 |
|
| 84 |
<h1 class="mlsimport-wizard-title"> |
| 85 |
<?php _e('MLSImport Setup Wizard', 'mlsimport'); ?> |
| 86 |
</h1> |
| 87 |
|
| 88 |
<a href="<?php echo esc_url(admin_url('admin.php?page=mlsimport_plugin_options')); ?>" class="mlsimport-wizard-close"> |
| 89 |
<span class="dashicons dashicons-no-alt"></span> |
| 90 |
</a> |
| 91 |
</div> |
| 92 |
|
| 93 |
<div class="mlsimport-wizard-header"> |
| 94 |
<div class="mlsimport-wizard-progress"> |
| 95 |
<div class="mlsimport-wizard-progress-bar"> |
| 96 |
<div class="mlsimport-wizard-progress-bar-inner" style="width: <?php echo esc_attr($progress_percentage); ?>%"></div> |
| 97 |
</div> |
| 98 |
<div class="mlsimport-wizard-steps"> |
| 99 |
<?php /* render one marker per step in the progress bar */ foreach ($steps as $step_id => $step) : ?> |
| 100 |
<?php |
| 101 |
// Position of this step, used to flag it completed/active. |
| 102 |
$step_index = array_search($step_id, $step_keys); |
| 103 |
$step_class = 'mlsimport-wizard-step'; |
| 104 |
// Steps before the current one are marked completed... |
| 105 |
if ($step_index < $current_step_index) { |
| 106 |
$step_class .= ' completed'; |
| 107 |
// ...and the current step is marked active. |
| 108 |
} elseif ($step_index === $current_step_index) { |
| 109 |
$step_class .= ' active'; |
| 110 |
} |
| 111 |
// 1-based number shown in the step marker. |
| 112 |
$step_number = $step_index + 1; |
| 113 |
?> |
| 114 |
<div class="<?php echo esc_attr($step_class); ?>"> |
| 115 |
<div class="mlsimport-wizard-step-number"><?php echo esc_html($step_number); ?></div> |
| 116 |
<div class="mlsimport-wizard-step-title"><?php echo esc_html($step['title']); ?></div> |
| 117 |
</div> |
| 118 |
<?php endforeach; ?> |
| 119 |
</div> |
| 120 |
</div> |
| 121 |
</div> |
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
<div class="mlsimport-wizard-content mlsimport_2025_card mlsimport-wizard-content-30margin |
| 126 |
<?php |
| 127 |
echo ' mlsimport-wizard-content-'.$current_step; |
| 128 |
?> |
| 129 |
|
| 130 |
"> |
| 131 |
<div class="mlsimport-wizard-content-header"> |
| 132 |
<h2><?php echo esc_html($current_step_data['title']); ?></h2> |
| 133 |
<p class="mlsimport-wizard-description"><?php echo esc_html($current_step_data['description']); ?></p> |
| 134 |
</div> |
| 135 |
|
| 136 |
<div class="mlsimport-wizard-content-body"> |
| 137 |
<form id="mlsimport-wizard-form" method="post" action=""> |
| 138 |
<?php |
| 139 |
// Output nonce field |
| 140 |
// CSRF nonce for the onboarding form submission. |
| 141 |
wp_nonce_field('mlsimport_onboarding', 'mlsimport_onboarding_nonce'); |
| 142 |
|
| 143 |
// Include the current step template |
| 144 |
// Render the body of the current step (one of the step-*.php partials). |
| 145 |
mlsimport_render_onboarding_step($current_step); |
| 146 |
?> |
| 147 |
|
| 148 |
<div class="mlsimport-wizard-actions"> |
| 149 |
<?php if ($can_go_back) : /* Back link hidden on the first step */ ?> |
| 150 |
<a href="<?php echo esc_url($prev_url); ?>" class="button mlsimport_button secondary"> |
| 151 |
<?php _e('Back', 'mlsimport'); ?> |
| 152 |
</a> |
| 153 |
<?php endif; ?> |
| 154 |
|
| 155 |
<?php if ($is_last_step) : /* final step: primary button completes setup */ ?> |
| 156 |
<button type="submit" class="button button-primary mlsimport-wizard-next mlsimport_button mlsimport-wizard-submit"> |
| 157 |
<?php _e('Complete Setup', 'mlsimport'); ?> |
| 158 |
</button> |
| 159 |
<?php else : /* otherwise: primary button advances to the next step */ ?> |
| 160 |
<button type="submit" class="button button-primary mlsimport-wizard-next mlsimport_button "> |
| 161 |
<?php _e('Continue', 'mlsimport'); ?> |
| 162 |
</button> |
| 163 |
<?php endif; ?> |
| 164 |
|
| 165 |
<input type="hidden" name="mlsimport_onboarding_submit" value="1"> |
| 166 |
<input type="hidden" name="mlsimport_current_step" value="<?php echo esc_attr($current_step); ?>"> |
| 167 |
</div> |
| 168 |
</form> |
| 169 |
</div> |
| 170 |
</div> |
| 171 |
|
| 172 |
<div class="mlsimport-wizard-footer"> |
| 173 |
<div class="mlsimport-wizard-help"> |
| 174 |
<p> |
| 175 |
<?php _e('Need help?', 'mlsimport'); ?> |
| 176 |
<a href="https://mlsimport.com/support" target="_blank"><?php _e('Contact Support', 'mlsimport'); ?></a> |
| 177 |
</p> |
| 178 |
</div> |
| 179 |
<div class="mlsimport-wizard-restart"> |
| 180 |
<a href="<?php echo esc_url(admin_url('admin.php?page=mlsimport-onboarding&restart_wizard=1')); ?>" class=" button mlsimport_button secondary"> |
| 181 |
<?php _e('Restart Setup', 'mlsimport'); ?> |
| 182 |
</a> |
| 183 |
</div> |
| 184 |
</div> |
| 185 |
</div> |