| @@ -37,17 +37,8 @@ | ||
| 37 | 37 | */ |
| 38 | 38 | public $error = false; |
| 39 | 39 | |
| 40 | 40 | /** |
| 41 | - * Holds the Post Type to generate. | |
| 42 | - * | |
| 43 | - * @since 3.3.9 | |
| 44 | - * | |
| 45 | - * @var string | |
| 46 | - */ | |
| 47 | - public $post_type = 'page'; | |
| 48 | - | |
| 49 | - /** | |
| 50 | 41 | * The required user capability to access the setup wizard. |
| 51 | 42 | * |
| 52 | 43 | * @since 1.9.8.4 |
| 53 | 44 | * |
| @@ -59,11 +50,11 @@ | ||
| 59 | 50 | * The current step in the setup process the user is on. |
| 60 | 51 | * |
| 61 | 52 | * @since 1.9.8.4 |
| 62 | 53 | * |
| 63 | - * @var string | |
| 54 | + * @var int | |
| 64 | 55 | */ |
| 65 | - public $step = 'start'; | |
| 56 | + public $step = 1; | |
| 66 | 57 | |
| 67 | 58 | /** |
| 68 | 59 | * The programmatic name of the setup screen. |
| 69 | 60 | * |
| @@ -173,24 +164,14 @@ | ||
| 173 | 164 | set_current_screen( $this->page_name ); |
| 174 | 165 | |
| 175 | 166 | // If the convertkit-modal parameter exists and is 1, set the flag to denote |
| 176 | 167 | // this wizard is served in a modal. |
| 177 | - if ( filter_has_var( INPUT_GET, 'convertkit-modal' ) && filter_input( INPUT_GET, 'convertkit-modal', FILTER_SANITIZE_NUMBER_INT ) === '1' ) { | |
| 168 | + if ( array_key_exists( 'convertkit-modal', $_REQUEST ) && $_REQUEST['convertkit-modal'] === '1' ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended | |
| 178 | 169 | $this->is_modal = true; |
| 179 | 170 | } |
| 180 | 171 | |
| 181 | - /** | |
| 182 | - * Define the steps for the setup wizard. | |
| 183 | - * | |
| 184 | - * @since 3.1.8 | |
| 185 | - * | |
| 186 | - * @param array $steps The steps for the setup wizard. | |
| 187 | - * @return array The steps for the setup wizard. | |
| 188 | - */ | |
| 189 | - $this->steps = apply_filters( 'convertkit_admin_setup_wizard_steps_' . $this->page_name, $this->steps ); | |
| 190 | - | |
| 191 | 172 | // Define the step the user is on in the setup process. |
| 192 | - $this->step = $this->get_current_step(); | |
| 173 | + $this->step = ( isset( $_REQUEST['step'] ) ? absint( $_REQUEST['step'] ) : 1 ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended | |
| 193 | 174 | |
| 194 | 175 | // Process any posted form data. |
| 195 | 176 | $this->process_form(); |
| 196 | 177 | |
| @@ -212,68 +193,8 @@ | ||
| 212 | 193 | |
| 213 | 194 | } |
| 214 | 195 | |
| 215 | 196 | /** |
| 216 | - * Returns the current step in the setup process. | |
| 217 | - * | |
| 218 | - * @since 3.1.7 | |
| 219 | - * | |
| 220 | - * @return string Current step. | |
| 221 | - */ | |
| 222 | - public function get_current_step() { | |
| 223 | - | |
| 224 | - $step = ( filter_has_var( INPUT_GET, 'step' ) ? filter_input( INPUT_GET, 'step', FILTER_SANITIZE_FULL_SPECIAL_CHARS ) : 'start' ); | |
| 225 | - | |
| 226 | - // Fallback to 'start' if the step is a registered step. | |
| 227 | - if ( ! array_key_exists( $step, $this->steps ) ) { | |
| 228 | - $step = 'start'; | |
| 229 | - } | |
| 230 | - | |
| 231 | - return $step; | |
| 232 | - | |
| 233 | - } | |
| 234 | - | |
| 235 | - /** | |
| 236 | - * Get the number of the current step. | |
| 237 | - * | |
| 238 | - * @since 3.1.7 | |
| 239 | - * | |
| 240 | - * @return int Step number. | |
| 241 | - */ | |
| 242 | - public function get_current_step_number() { | |
| 243 | - | |
| 244 | - return array_search( $this->step, array_keys( $this->steps ), true ) + 1; | |
| 245 | - | |
| 246 | - } | |
| 247 | - | |
| 248 | - /** | |
| 249 | - * Get the step by number. | |
| 250 | - * | |
| 251 | - * @since 3.1.7 | |
| 252 | - * | |
| 253 | - * @param int $number Step number (1 based index). | |
| 254 | - * @return string Step name/key. | |
| 255 | - */ | |
| 256 | - public function get_step_key_by_number( $number ) { | |
| 257 | - | |
| 258 | - return array_keys( $this->steps )[ $number - 1 ]; | |
| 259 | - | |
| 260 | - } | |
| 261 | - | |
| 262 | - /** | |
| 263 | - * Get the total number of steps. | |
| 264 | - * | |
| 265 | - * @since 3.1.7 | |
| 266 | - * | |
| 267 | - * @return int Total steps. | |
| 268 | - */ | |
| 269 | - public function get_total_steps() { | |
| 270 | - | |
| 271 | - return count( $this->steps ); | |
| 272 | - | |
| 273 | - } | |
| 274 | - | |
| 275 | - /** | |
| 276 | 197 | * Process submitted form data for the given setup wizard name and current step. |
| 277 | 198 | * |
| 278 | 199 | * @since 1.9.8.4 |
| 279 | 200 | */ |
| @@ -283,9 +204,9 @@ | ||
| 283 | 204 | * Process submitted form data for the given setup wizard name and current step. |
| 284 | 205 | * |
| 285 | 206 | * @since 1.9.8.4 |
| 286 | 207 | * |
| 287 | - * @param string $step Current step. | |
| 208 | + * @param int $step Current step number. | |
| 288 | 209 | */ |
| 289 | 210 | do_action( 'convertkit_admin_setup_wizard_process_form_' . $this->page_name, $this->step ); |
| 290 | 211 | |
| 291 | 212 | } |
| @@ -309,14 +230,14 @@ | ||
| 309 | 230 | admin_url( 'options.php' ) |
| 310 | 231 | ); |
| 311 | 232 | |
| 312 | 233 | // Define the previous step URL if we're not on the first or last step. |
| 313 | - 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 ) ) { | |
| 314 | 235 | $this->previous_step_url = add_query_arg( |
| 315 | 236 | array( |
| 316 | 237 | 'page' => $this->page_name, |
| 317 | 238 | 'convertkit-modal' => $this->is_modal(), |
| 318 | - 'step' => $this->get_step_key_by_number( $this->get_current_step_number() - 1 ), | |
| 239 | + 'step' => ( $this->step - 1 ), | |
| 319 | 240 | ), |
| 320 | 241 | admin_url( 'options.php' ) |
| 321 | 242 | ); |
| 322 | 243 | } |
| @@ -321,14 +242,14 @@ | ||
| 321 | 242 | ); |
| 322 | 243 | } |
| 323 | 244 | |
| 324 | 245 | // Define the next step URL if we're not on the last page. |
| 325 | - if ( $this->get_current_step_number() < $this->get_total_steps() ) { | |
| 246 | + if ( $this->step < count( $this->steps ) ) { | |
| 326 | 247 | $this->next_step_url = add_query_arg( |
| 327 | 248 | array( |
| 328 | 249 | 'page' => $this->page_name, |
| 329 | 250 | 'convertkit-modal' => $this->is_modal(), |
| 330 | - 'step' => $this->get_step_key_by_number( $this->get_current_step_number() + 1 ), | |
| 251 | + 'step' => ( $this->step + 1 ), | |
| 331 | 252 | ), |
| 332 | 253 | admin_url( 'options.php' ) |
| 333 | 254 | ); |
| 334 | 255 | } |
| @@ -346,9 +267,9 @@ | ||
| 346 | 267 | * Load any data into class variables for the given setup wizard name and current step. |
| 347 | 268 | * |
| 348 | 269 | * @since 1.9.8.4 |
| 349 | 270 | * |
| 350 | - * @param string $step Current step. | |
| 271 | + * @param int $step Current step number. | |
| 351 | 272 | */ |
| 352 | 273 | do_action( 'convertkit_admin_setup_wizard_load_screen_data_' . $this->page_name, $this->step ); |
| 353 | 274 | |
| 354 | 275 | } |
| @@ -481,12 +402,12 @@ | ||
| 481 | 402 | return false; |
| 482 | 403 | } |
| 483 | 404 | |
| 484 | 405 | // Bail if we're not on the setup screen. |
| 485 | - if ( ! filter_has_var( INPUT_GET, 'page' ) ) { | |
| 406 | + if ( ! isset( $_GET['page'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification | |
| 486 | 407 | return false; |
| 487 | 408 | } |
| 488 | - if ( filter_input( INPUT_GET, 'page', FILTER_SANITIZE_FULL_SPECIAL_CHARS ) !== $this->page_name ) { | |
| 409 | + if ( sanitize_text_field( $_GET['page'] ) !== $this->page_name ) { // phpcs:ignore WordPress.Security.NonceVerification | |
| 489 | 410 | return false; |
| 490 | 411 | } |
| 491 | 412 | |
| 492 | 413 | return true; |
| @@ -512,33 +433,8 @@ | ||
| 512 | 433 | return false; |
| 513 | 434 | } |
| 514 | 435 | |
| 515 | 436 | return true; |
| 516 | - | |
| 517 | - } | |
| 518 | - | |
| 519 | - /** | |
| 520 | - * Sets the Post Type from the request, ensuring it is supported by the Plugin. | |
| 521 | - * | |
| 522 | - * @since 3.3.9 | |
| 523 | - */ | |
| 524 | - protected function set_post_type() { | |
| 525 | - | |
| 526 | - $this->post_type = ( filter_has_var( INPUT_GET, 'ck_post_type' ) ? filter_input( INPUT_GET, 'ck_post_type', FILTER_SANITIZE_FULL_SPECIAL_CHARS ) : 'page' ); | |
| 527 | - | |
| 528 | - if ( ! in_array( $this->post_type, convertkit_get_supported_post_types(), true ) ) { | |
| 529 | - wp_die( | |
| 530 | - sprintf( | |
| 531 | - /* translators: Post Type */ | |
| 532 | - esc_html__( 'The post type `%s` is not supported for Member Content.', 'convertkit' ), | |
| 533 | - esc_html( $this->post_type ) | |
| 534 | - ), | |
| 535 | - esc_html__( 'WordPress Error', 'convertkit' ), | |
| 536 | - array( | |
| 537 | - 'back_link' => true, | |
| 538 | - ) | |
| 539 | - ); | |
| 540 | - } | |
| 541 | 437 | |
| 542 | 438 | } |
| 543 | 439 | |
| 544 | 440 | } |