steps = array( 'basic-config' => array( 'name' => __( 'Choose Schema Type', 'wp-schema-pro' ), 'view' => array( $this, 'choose_schema_type' ), 'handler' => array( $this, 'choose_schema_type_save' ), ), 'enable-on' => array( 'name' => __( 'Set Target Pages', 'wp-schema-pro' ), 'view' => array( $this, 'implement_on_callback' ), 'handler' => array( $this, 'implement_on_callback_save' ), ), 'setup-ready' => array( 'name' => __( 'Ready!', 'wp-schema-pro' ), 'view' => array( $this, 'schema_ready' ), 'handler' => '', ), ); } /** * Add admin menus/screens. */ public function admin_menus() { add_dashboard_page( '', '', 'manage_options', 'aiosrs-pro-setup', '' ); } /** * Show the setup wizard. */ public function setup_wizard() { if ( isset( $_REQUEST['wp_schema_pro_admin_page_nonce'] ) && ! wp_verify_nonce( sanitize_text_field( $_REQUEST['wp_schema_pro_admin_page_nonce'] ), 'wp_schema_pro_admin_page' ) ) { return; } if ( empty( $_GET['page'] ) || 'aiosrs-pro-setup' !== $_GET['page'] ) { return; } $this->step = isset( $_GET['step'] ) ? sanitize_key( $_GET['step'] ) : current( array_keys( $this->steps ) ); wp_enqueue_style( 'aiosrs-pro-setup', BSF_AIOSRS_PRO_URI . 'admin/assets/' . BSF_AIOSRS_Pro_Admin::$minfy_css . 'setup-wizard.' . BSF_AIOSRS_Pro_Admin::$minfy_css_ext, array( 'dashicons', 'install' ), BSF_AIOSRS_PRO_VER ); wp_enqueue_style( 'aiosrs-pro-admin-edit-style', BSF_AIOSRS_PRO_URI . 'admin/assets/' . BSF_AIOSRS_Pro_Admin::$minfy_css . 'style.' . BSF_AIOSRS_Pro_Admin::$minfy_css_ext, BSF_AIOSRS_PRO_VER, 'false' ); wp_register_script( 'aiosrs-pro-admin-edit-script', BSF_AIOSRS_PRO_URI . 'admin/assets/' . BSF_AIOSRS_Pro_Admin::$minfy_js . 'script.' . BSF_AIOSRS_Pro_Admin::$minfy_js_ext, array( 'jquery', 'jquery-ui-tooltip' ), BSF_AIOSRS_PRO_VER, true ); wp_register_script( 'aiosrs-pro-setup', BSF_AIOSRS_PRO_URI . 'admin/assets/' . BSF_AIOSRS_Pro_Admin::$minfy_js . 'setup-wizard.' . BSF_AIOSRS_Pro_Admin::$minfy_js_ext, array( 'jquery' ), BSF_AIOSRS_PRO_VER, true ); wp_enqueue_style( 'bsf-target-rule-select2', BSF_AIOSRS_PRO_URI . 'classes/lib/target-rule/select2.css', '', BSF_AIOSRS_PRO_VER, false ); wp_enqueue_style( 'bsf-target-rule', BSF_AIOSRS_PRO_URI . 'classes/lib/target-rule/target-rule.css', '', BSF_AIOSRS_PRO_VER, false ); wp_register_script( 'bsf-target-rule-select2', BSF_AIOSRS_PRO_URI . 'classes/lib/target-rule/select2.js', array( 'jquery', 'backbone', 'wp-util' ), BSF_AIOSRS_PRO_VER, true ); wp_register_script( 'bsf-target-rule', BSF_AIOSRS_PRO_URI . 'classes/lib/target-rule/target-rule.js', array( 'jquery', 'bsf-target-rule-select2' ), BSF_AIOSRS_PRO_VER, true ); wp_register_script( 'bsf-user-role', BSF_AIOSRS_PRO_URI . 'classes/lib/target-rule/user-role.js', array( 'jquery' ), BSF_AIOSRS_PRO_VER, true ); wp_enqueue_media(); wp_localize_script( 'bsf-target-rule', 'Targetrule', array( 'ajax_url' => admin_url( 'admin-ajax.php' ), 'security' => wp_create_nonce( 'schema_nonce' ), ) ); if ( ( isset( $_POST['_wpnonce'] ) && wp_verify_nonce( sanitize_text_field( $_POST['_wpnonce'] ), 'aiosrs-pro-setup' ) ) && ! empty( $_POST['save_step'] ) && isset( $this->steps[ $this->step ]['handler'] ) ) { call_user_func( $this->steps[ $this->step ]['handler'] ); } ob_start(); $this->setup_wizard_header(); $this->setup_wizard_steps(); $this->setup_wizard_content(); $this->setup_wizard_footer(); exit; } /** * Get next step link */ public function get_next_step_link() { $keys = array_keys( $this->steps ); return add_query_arg( 'step', $keys[ array_search( $this->step, array_keys( $this->steps ), true ) + 1 ] ); } /** * Setup Wizard Header. */ public function setup_wizard_header() { ?> <?php esc_html_e( 'Schema Setup', 'wp-schema-pro' ); ?>
steps; ?>
    $step ) : $classes = ''; if ( $step_key === $this->step ) { $classes = 'active'; } elseif ( array_search( $this->step, array_keys( $this->steps ), true ) > array_search( $step_key, array_keys( $this->steps ), true ) ) { $classes = 'done'; } ?>
'; call_user_func( $this->steps[ $this->step ]['view'] ); echo ''; } /** * Introduction step. */ public function choose_schema_type() { ?>

>

get_next_step_link(); $title = isset( $_POST['bsf-aiosrs-schema-title'] ) ? sanitize_text_field( $_POST['bsf-aiosrs-schema-title'] ) : 0; $type = isset( $_POST['bsf-aiosrs-schema-type'] ) ? sanitize_text_field( $_POST['bsf-aiosrs-schema-type'] ) : 0; $default_fields = array(); if ( isset( BSF_AIOSRS_Pro_Schema::$schema_meta_fields[ 'bsf-aiosrs-' . $type ]['subkeys'] ) ) { $default_data = BSF_AIOSRS_Pro_Schema::$schema_meta_fields[ 'bsf-aiosrs-' . $type ]['subkeys']; foreach ( $default_data as $key => $value ) { if ( 'repeater' === $value['type'] ) { foreach ( $value['fields'] as $subkey => $subvalue ) { if ( isset( $subvalue['default'] ) && 'none' !== $subvalue['default'] ) { $default_fields[ $key ][0][ $subkey ] = $subvalue['default']; } else { $default_fields[ $key ][0][ $subkey ] = 'create-field'; } } } else { if ( isset( $value['default'] ) && 'none' !== $value['default'] ) { $default_fields[ $key ] = $value['default']; } else { $default_fields[ $key ] = 'create-field'; } } } } $postarr = array( 'post_type' => 'aiosrs-schema', 'post_title' => $title, 'post_status' => 'publish', 'meta_input' => array( 'bsf-aiosrs-schema-type' => $type, 'bsf-aiosrs-' . $type => $default_fields, ), ); $post_id = wp_insert_post( $postarr ); if ( ! is_wp_error( $post_id ) ) { $redirect_url = add_query_arg( 'schema-id', $post_id, $redirect_url ); } wp_safe_redirect( esc_url_raw( $redirect_url ) ); exit; } /** * Locale settings */ public function implement_on_callback() { if ( isset( $_REQUEST['wp_schema_pro_admin_page_nonce'] ) && ! wp_verify_nonce( sanitize_text_field( $_REQUEST['wp_schema_pro_admin_page_nonce'] ), 'wp_schema_pro_admin_page' ) ) { return; } $schema_id = 0; $title = ''; $redirect_url = $this->get_next_step_link(); if ( isset( $_GET['schema-id'] ) && ! empty( $_GET['schema-id'] ) ) { $schema_id = intval( $_GET['schema-id'] ); $redirect_url = add_query_arg( 'schema-id', $schema_id, $redirect_url ); $title = get_the_title( $schema_id ); } $meta_values = array( 'include-locations' => array( 'rule' => array( 'basic-singulars' ), ), 'exclude-locations' => array(), ); ?>

__( 'Display Rules', 'wp-schema-pro' ), 'value' => '[{"type":"basic-global","specific":null}]', 'tags' => 'site,enable,target,pages', 'rule_type' => 'display', 'add_rule_label' => __( 'Add “AND” Rule', 'wp-schema-pro' ), ), $meta_values['include-locations'] ); ?>
__( 'Exclude On', 'wp-schema-pro' ), 'value' => '[]', 'tags' => 'site,enable,target,pages', 'add_rule_label' => __( 'Add “OR” Rule', 'wp-schema-pro' ), 'rule_type' => 'exclude', ), $meta_values['exclude-locations'] ); ?>

get_next_step_link(); if ( $schema_id ) { $redirect_url = add_query_arg( 'schema-id', $schema_id, $redirect_url ); update_post_meta( $schema_id, 'bsf-aiosrs-schema-location', $enabled_on ); update_post_meta( $schema_id, 'bsf-aiosrs-schema-exclusion', $exclude_from ); } wp_safe_redirect( esc_url_raw( $redirect_url ) ); exit; } /** * Get Location rules of schema for Custom meta box. * * @param array $enabled_on Enabled on rules. * @param array $exclude_from Exlcude on rules. * @return array */ public static function get_display_rules_for_meta_box( $enabled_on, $exclude_from ) { $locations = array(); $enabled_location = array(); $exclude_location = array(); $args = array( 'public' => true, '_builtin' => true, ); $post_types = get_post_types( $args ); unset( $post_types['attachment'] ); $args['_builtin'] = false; $custom_post_type = get_post_types( $args ); $post_types = array_merge( $post_types, $custom_post_type ); if ( ! empty( $enabled_on ) && isset( $enabled_on['rule'] ) ) { $enabled_location = $enabled_on['rule']; } if ( ! empty( $exclude_from ) && isset( $exclude_from['rule'] ) ) { $exclude_location = $exclude_from['rule']; } if ( in_array( 'specifics', $enabled_location, true ) || ( in_array( 'basic-singulars', $enabled_location, true ) && ! in_array( 'basic-singulars', $exclude_location, true ) ) ) { foreach ( $post_types as $post_type ) { $locations[ $post_type ] = 1; } } else { foreach ( $post_types as $post_type ) { $key = $post_type . '|all'; if ( in_array( $key, $enabled_location, true ) && ! in_array( $key, $exclude_location, true ) ) { $locations[ $post_type ] = 1; } } } return $locations; } /** * Final step. */ public function schema_ready() { if ( isset( $_REQUEST['wp_schema_pro_admin_page_nonce'] ) && ! wp_verify_nonce( sanitize_text_field( $_REQUEST['wp_schema_pro_admin_page_nonce'] ), 'wp_schema_pro_admin_page' ) ) { return; } $schema_id = 0; $title = ''; if ( isset( $_GET['schema-id'] ) && ! empty( $_GET['schema-id'] ) ) { $schema_id = intval( $_GET['schema-id'] ); $title = get_the_title( $schema_id ); } ?>

%s Schema has been added and enabled on selected target locations.', 'wp-schema-pro' ), esc_html( $title ) ); ?>