| @@ -50,11 +50,11 @@ | ||
| 50 | 50 | * The current step in the setup process the user is on. |
| 51 | 51 | * |
| 52 | 52 | * @since 1.9.8.4 |
| 53 | 53 | * |
| 54 | - * @var string | |
| 54 | + * @var int | |
| 55 | 55 | */ |
| 56 | - public $step = 'start'; | |
| 56 | + public $step = 1; | |
| 57 | 57 | |
| 58 | 58 | /** |
| 59 | 59 | * The programmatic name of the setup screen. |
| 60 | 60 | * |
| @@ -168,20 +168,10 @@ | ||
| 168 | 168 | if ( filter_has_var( INPUT_GET, 'convertkit-modal' ) && filter_input( INPUT_GET, 'convertkit-modal', FILTER_SANITIZE_NUMBER_INT ) === '1' ) { |
| 169 | 169 | $this->is_modal = true; |
| 170 | 170 | } |
| 171 | 171 | |
| 172 | - /** | |
| 173 | - * Define the steps for the setup wizard. | |
| 174 | - * | |
| 175 | - * @since 3.1.8 | |
| 176 | - * | |
| 177 | - * @param array $steps The steps for the setup wizard. | |
| 178 | - * @return array The steps for the setup wizard. | |
| 179 | - */ | |
| 180 | - $this->steps = apply_filters( 'convertkit_admin_setup_wizard_steps_' . $this->page_name, $this->steps ); | |
| 181 | - | |
| 182 | 172 | // Define the step the user is on in the setup process. |
| 183 | - $this->step = $this->get_current_step(); | |
| 173 | + $this->step = ( filter_has_var( INPUT_GET, 'step' ) ? absint( filter_input( INPUT_GET, 'step', FILTER_SANITIZE_NUMBER_INT ) ) : 1 ); | |
| 184 | 174 | |
| 185 | 175 | // Process any posted form data. |
| 186 | 176 | $this->process_form(); |
| 187 | 177 | |
| @@ -203,68 +193,8 @@ | ||
| 203 | 193 | |
| 204 | 194 | } |
| 205 | 195 | |
| 206 | 196 | /** |
| 207 | - * Returns the current step in the setup process. | |
| 208 | - * | |
| 209 | - * @since 3.1.7 | |
| 210 | - * | |
| 211 | - * @return string Current step. | |
| 212 | - */ | |
| 213 | - public function get_current_step() { | |
| 214 | - | |
| 215 | - $step = ( filter_has_var( INPUT_GET, 'step' ) ? filter_input( INPUT_GET, 'step', FILTER_SANITIZE_FULL_SPECIAL_CHARS ) : 'start' ); | |
| 216 | - | |
| 217 | - // Fallback to 'start' if the step is a registered step. | |
| 218 | - if ( ! array_key_exists( $step, $this->steps ) ) { | |
| 219 | - $step = 'start'; | |
| 220 | - } | |
| 221 | - | |
| 222 | - return $step; | |
| 223 | - | |
| 224 | - } | |
| 225 | - | |
| 226 | - /** | |
| 227 | - * Get the number of the current step. | |
| 228 | - * | |
| 229 | - * @since 3.1.7 | |
| 230 | - * | |
| 231 | - * @return int Step number. | |
| 232 | - */ | |
| 233 | - public function get_current_step_number() { | |
| 234 | - | |
| 235 | - return array_search( $this->step, array_keys( $this->steps ), true ) + 1; | |
| 236 | - | |
| 237 | - } | |
| 238 | - | |
| 239 | - /** | |
| 240 | - * Get the step by number. | |
| 241 | - * | |
| 242 | - * @since 3.1.7 | |
| 243 | - * | |
| 244 | - * @param int $number Step number (1 based index). | |
| 245 | - * @return string Step name/key. | |
| 246 | - */ | |
| 247 | - public function get_step_key_by_number( $number ) { | |
| 248 | - | |
| 249 | - return array_keys( $this->steps )[ $number - 1 ]; | |
| 250 | - | |
| 251 | - } | |
| 252 | - | |
| 253 | - /** | |
| 254 | - * Get the total number of steps. | |
| 255 | - * | |
| 256 | - * @since 3.1.7 | |
| 257 | - * | |
| 258 | - * @return int Total steps. | |
| 259 | - */ | |
| 260 | - public function get_total_steps() { | |
| 261 | - | |
| 262 | - return count( $this->steps ); | |
| 263 | - | |
| 264 | - } | |
| 265 | - | |
| 266 | - /** | |
| 267 | 197 | * Process submitted form data for the given setup wizard name and current step. |
| 268 | 198 | * |
| 269 | 199 | * @since 1.9.8.4 |
| 270 | 200 | */ |
| @@ -274,9 +204,9 @@ | ||
| 274 | 204 | * Process submitted form data for the given setup wizard name and current step. |
| 275 | 205 | * |
| 276 | 206 | * @since 1.9.8.4 |
| 277 | 207 | * |
| 278 | - * @param string $step Current step. | |
| 208 | + * @param int $step Current step number. | |
| 279 | 209 | */ |
| 280 | 210 | do_action( 'convertkit_admin_setup_wizard_process_form_' . $this->page_name, $this->step ); |
| 281 | 211 | |
| 282 | 212 | } |
| @@ -300,14 +230,14 @@ | ||
| 300 | 230 | admin_url( 'options.php' ) |
| 301 | 231 | ); |
| 302 | 232 | |
| 303 | 233 | // Define the previous step URL if we're not on the first or last step. |
| 304 | - if ( $this->get_current_step_number() > 1 && $this->get_current_step_number() < $this->get_total_steps() ) { | |
| 234 | + if ( $this->step > 1 && $this->step < count( $this->steps ) ) { | |
| 305 | 235 | $this->previous_step_url = add_query_arg( |
| 306 | 236 | array( |
| 307 | 237 | 'page' => $this->page_name, |
| 308 | 238 | 'convertkit-modal' => $this->is_modal(), |
| 309 | - 'step' => $this->get_step_key_by_number( $this->get_current_step_number() - 1 ), | |
| 239 | + 'step' => ( $this->step - 1 ), | |
| 310 | 240 | ), |
| 311 | 241 | admin_url( 'options.php' ) |
| 312 | 242 | ); |
| 313 | 243 | } |
| @@ -312,14 +242,14 @@ | ||
| 312 | 242 | ); |
| 313 | 243 | } |
| 314 | 244 | |
| 315 | 245 | // Define the next step URL if we're not on the last page. |
| 316 | - if ( $this->get_current_step_number() < $this->get_total_steps() ) { | |
| 246 | + if ( $this->step < count( $this->steps ) ) { | |
| 317 | 247 | $this->next_step_url = add_query_arg( |
| 318 | 248 | array( |
| 319 | 249 | 'page' => $this->page_name, |
| 320 | 250 | 'convertkit-modal' => $this->is_modal(), |
| 321 | - 'step' => $this->get_step_key_by_number( $this->get_current_step_number() + 1 ), | |
| 251 | + 'step' => ( $this->step + 1 ), | |
| 322 | 252 | ), |
| 323 | 253 | admin_url( 'options.php' ) |
| 324 | 254 | ); |
| 325 | 255 | } |
| @@ -337,9 +267,9 @@ | ||
| 337 | 267 | * Load any data into class variables for the given setup wizard name and current step. |
| 338 | 268 | * |
| 339 | 269 | * @since 1.9.8.4 |
| 340 | 270 | * |
| 341 | - * @param string $step Current step. | |
| 271 | + * @param int $step Current step number. | |
| 342 | 272 | */ |
| 343 | 273 | do_action( 'convertkit_admin_setup_wizard_load_screen_data_' . $this->page_name, $this->step ); |
| 344 | 274 | |
| 345 | 275 | } |