'publish', 'post_type' => 'page', 'post_author' => 1, 'post_name' => sanitize_title( $title ), 'post_title' => $title, 'post_content' => $content, 'post_parent' => 0, 'comment_status' => 'closed', ]; $page_id = wp_insert_post( $page_data ); if ( $option ) { update_option( $option, $page_id ); } } /** * Handle request to the setup page. */ public function setup_page() { $usage_tracking = WP_Job_Manager_Usage_Tracking::get_instance(); $step = ! empty( $_GET['step'] ) ? absint( $_GET['step'] ) : 1; if ( isset( $_SERVER['REQUEST_METHOD'] ) && 'POST' === $_SERVER['REQUEST_METHOD'] ) { // Handle step 1 (usage tracking). $enable = isset( $_POST['job_manager_usage_tracking_enabled'] ) && '1' === $_POST['job_manager_usage_tracking_enabled']; $nonce = isset( $_POST['nonce'] ) ? wp_unslash( $_POST['nonce'] ) : null; // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Nonce should not be modified. $valid_nonce = wp_verify_nonce( $nonce, 'enable-usage-tracking' ); if ( $valid_nonce ) { $usage_tracking->set_tracking_enabled( $enable ); $usage_tracking->hide_tracking_opt_in(); } // Handle step 2 -> step 3 (setting up pages). if ( 3 === $step && ! empty( $_POST ) ) { if ( ! isset( $_REQUEST['setup_wizard'] ) || false === wp_verify_nonce( wp_unslash( $_REQUEST['setup_wizard'] ), 'step_3' ) // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Nonce should not be modified. ) { wp_die( esc_html__( 'Error in nonce. Try again.', 'wp-job-manager' ), 'wp-job-manager' ); } $create_pages = isset( $_POST['wp-job-manager-create-page'] ) ? array_map( 'sanitize_text_field', wp_unslash( $_POST['wp-job-manager-create-page'] ) ) : []; $page_titles = isset( $_POST['wp-job-manager-page-title'] ) ? array_map( 'sanitize_text_field', wp_unslash( $_POST['wp-job-manager-page-title'] ) ) : []; $pages_to_create = [ 'submit_job_form' => '[submit_job_form]', 'job_dashboard' => '[job_dashboard]', 'jobs' => '[jobs]', ]; foreach ( $pages_to_create as $page => $content ) { if ( ! isset( $create_pages[ $page ] ) || empty( $page_titles[ $page ] ) ) { continue; } $this->create_page( sanitize_text_field( $page_titles[ $page ] ), $content, 'job_manager_' . $page . '_page_id' ); } } } // Handle step 3 (from step 1 or 2). if ( 3 === $step ) { WP_Job_Manager_Admin_Notices::remove_notice( WP_Job_Manager_Admin_Notices::NOTICE_CORE_SETUP ); } $this->output(); } /** * Usage tracking opt in text for setup page. * * Used in `views/html-admin-setup-opt-in-usage-tracking.php` */ private function opt_in_text() { return WP_Job_Manager_Usage_Tracking::get_instance()->opt_in_checkbox_text(); } /** * Output opt-in checkbox if usage tracking isn't already enabled. * * Used in `views/html-admin-setup-step-1.php` */ private function maybe_output_opt_in_checkbox() { // Only show the checkbox if we aren't already opted in. $usage_tracking = WP_Job_Manager_Usage_Tracking::get_instance(); if ( ! $usage_tracking->get_tracking_enabled() ) { include dirname( __FILE__ ) . '/views/html-admin-setup-opt-in-usage-tracking.php'; } } /** * Displays setup page. */ public function output() { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Input is used safely. $step = ! empty( $_GET['step'] ) ? absint( $_GET['step'] ) : 1; include dirname( __FILE__ ) . '/views/html-admin-setup-header.php'; if ( 1 === $step ) { include dirname( __FILE__ ) . '/views/html-admin-setup-step-1.php'; } elseif ( 2 === $step ) { include dirname( __FILE__ ) . '/views/html-admin-setup-step-2.php'; } elseif ( 3 === $step ) { include dirname( __FILE__ ) . '/views/html-admin-setup-step-3.php'; } include dirname( __FILE__ ) . '/views/html-admin-setup-footer.php'; } } WP_Job_Manager_Setup::instance();