steps = array( 'introduction' => array( 'name' => __( 'Introduction', 'sportspress' ), 'view' => array( $this, 'sp_setup_introduction' ), 'handler' => '' ), 'basics' => array( 'name' => __( 'Basic Setup', 'sportspress' ), 'view' => array( $this, 'sp_setup_basics' ), 'handler' => array( $this, 'sp_setup_basics_save' ) ), 'teams' => array( 'name' => __( 'Teams', 'sportspress' ), 'view' => array( $this, 'sp_setup_teams' ), 'handler' => array( $this, 'sp_setup_teams_save' ) ), 'players_staff' => array( 'name' => __( 'Players', 'sportspress' ) . ' & ' . __( 'Staff', 'sportspress' ), 'view' => array( $this, 'sp_setup_players_staff' ), 'handler' => array( $this, 'sp_setup_players_staff_save' ), ), 'venue' => array( 'name' => __( 'Venue', 'sportspress' ), 'view' => array( $this, 'sp_setup_venue' ), 'handler' => array( $this, 'sp_setup_venue_save' ), ), 'pages' => array( 'name' => __( 'Pages', 'sportspress' ), 'view' => array( $this, 'sp_setup_pages' ), 'handler' => array( $this, 'sp_setup_pages_save' ) ), 'next_steps' => array( 'name' => __( 'Ready!', 'sportspress' ), 'view' => array( $this, 'sp_setup_ready' ), 'handler' => '' ) ); $this->step = isset( $_GET['step'] ) ? sanitize_key( $_GET['step'] ) : current( array_keys( $this->steps ) ); $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; wp_enqueue_style( 'jquery-chosen', SP()->plugin_url() . '/assets/css/chosen.css', array(), '1.1.0' ); wp_enqueue_style( 'sportspress-admin', SP()->plugin_url() . '/assets/css/admin.css', array(), SP_VERSION ); wp_enqueue_style( 'sportspress-setup', SP()->plugin_url() . '/assets/css/setup.css', array( 'dashicons', 'install' ), SP_VERSION ); wp_register_script( 'chosen', SP()->plugin_url() . '/assets/js/chosen.jquery.min.js', array( 'jquery' ), '1.1.0', true ); wp_register_script( 'jquery-tiptip', SP()->plugin_url() . '/assets/js/jquery.tipTip.min.js', array( 'jquery' ), '1.3', true ); wp_register_script( 'google-maps', '//maps.googleapis.com/maps/api/js?key=AIzaSyAWyt_AG0k_Pgz4LuegtHwesA_OMRnSSAE&libraries=places' ); wp_register_script( 'sportspress-setup', SP()->plugin_url() . '/assets/js/admin/sportspress-setup.js', array( 'jquery', 'chosen', 'jquery-tiptip' ), SP_VERSION, true ); wp_register_script( 'jquery-locationpicker', SP()->plugin_url() . '/assets/js/locationpicker.jquery.js', array( 'jquery', 'google-maps' ), '0.1.6', true ); wp_register_script( 'sportspress-admin-locationpicker', SP()->plugin_url() . '/assets/js/admin/locationpicker.js', array( 'jquery', 'jquery-locationpicker' ), SP_VERSION, true ); $strings = apply_filters( 'sportspress_localized_strings', array( 'none' => __( 'None', 'sportspress' ), 'remove_text' => __( '— Remove —', 'sportspress' ), ) ); // Localize scripts wp_localize_script( 'sportspress-setup', 'localized_strings', $strings ); wp_enqueue_script( 'google-maps' ); if ( ! 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; } 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 ) ) + 1 ] ); } /** * Setup Wizard Header. */ public function setup_wizard_header() { ?> >
It’s completely optional and shouldn’t take longer than five minutes.', 'sportspress' ); ?>
get_next_step_link() ) ); exit; } /** * Team Setup. */ public function sp_setup_teams() { $class = 'chosen-select' . ( is_rtl() ? ' chosen-rtl' : '' ); ?> 0, 'fields' => 'ids' ) ); }; wp_insert_post( $post ); // Add home team $post['post_title'] = $_POST['home_team']; wp_insert_post( $post ); wp_redirect( esc_url_raw( $this->get_next_step_link() ) ); exit; } /** * Players & Staff Setup. */ public function sp_setup_players_staff() { $positions = (array) get_terms( 'sp_position', array( 'hide_empty' => 0, 'orderby' => 'slug', 'fields' => 'names' ) ) ?> 1, 'post_type' => 'sp_team', 'fields' => 'ids' ) ); $team = reset( $teams ); // Add players $post['post_type'] = 'sp_player'; $post['post_status'] = 'publish'; $post['tax_input'] = array(); $taxonomies = array( 'sp_league', 'sp_season' ); foreach ( $taxonomies as $taxonomy ) { $post['tax_input'][ $taxonomy ] = get_terms( $taxonomy, array( 'hide_empty' => 0, 'fields' => 'ids' ) ); }; if ( is_array( $_POST['players'] ) ) { foreach ( $_POST['players'] as $i => $player ) { if ( empty( $player['name'] ) ) continue; $post['post_title'] = $player['name']; $id = wp_insert_post( $post ); // Add squad number $number = sp_array_value( $player, 'number' ); update_post_meta( $id, 'sp_number', $number ); // Add position wp_set_object_terms( $id, sp_array_value( $player, 'position', __( 'Position', 'sportspress' ) ), 'sp_position', false ); // Add team if ( $team ) { update_post_meta( $id, 'sp_team', $team ); update_post_meta( $id, 'sp_current_team', $team ); } } } // Add staff if ( ! empty( $_POST['staff'] ) ) { $post['post_type'] = 'sp_staff'; $post['post_title'] = $_POST['staff']; $id = wp_insert_post( $post ); // Add role wp_set_object_terms( $id, sp_array_value( $_POST, 'role', 'Coach' ), 'sp_role', false ); // Add team if ( $team ) { update_post_meta( $id, 'sp_team', $team ); update_post_meta( $id, 'sp_current_team', $team ); } } wp_redirect( esc_url_raw( $this->get_next_step_link() ) ); exit; } /** * Venue Step. */ public function sp_setup_venue() { ?> 1, 'post_type' => 'sp_team', 'fields' => 'ids' ) ); $team = reset( $teams ); // Insert venue $venue = sanitize_text_field( $_POST['venue'] ); if ( ! is_string( $venue ) || empty( $venue ) ) { $venue = sp_array_value( $_POST, 'address', __( 'Venue', 'sportspress' ) ); } $inserted = wp_insert_term( $venue, 'sp_venue' ); // Add address and coordinates to venue if ( ! is_wp_error( $inserted ) ) { $t_id = sp_array_value( $inserted, 'term_id', 1 ); if ( $team ) { wp_set_object_terms( $team, $t_id, 'sp_venue', true ); } $meta = array( 'sp_address' => sp_array_value( $_POST, 'address' ), 'sp_latitude' => sp_array_value( $_POST, 'latitude' ), 'sp_longitude' => sp_array_value( $_POST, 'longitude' ), ); update_option( "taxonomy_$t_id", $meta ); } wp_redirect( esc_url_raw( $this->get_next_step_link() ) ); exit; } /** * Pages Step. */ public function sp_setup_pages() { $pages = apply_filters( 'sportspress_setup_pages', array( 'sp_calendar' => __( 'Organize and publish calendars using different layouts.', 'sportspress' ), 'sp_table' => __( 'Create automated league tables to keep track of team standings.', 'sportspress' ), 'sp_list' => __( 'Create team rosters, player galleries, and ranking charts.', 'sportspress' ), ) ); ?> __( 'Organize and publish calendars using different layouts.', 'sportspress' ), 'sp_table' => __( 'Create automated league tables to keep track of team standings.', 'sportspress' ), 'sp_list' => __( 'Create team rosters, player galleries, and ranking charts.', 'sportspress' ), ) ); // Initialize post $post = array( 'post_status' => 'publish' ); $sample_content = _x( 'This is an example %1$s. As a new SportsPress user, you should go to your dashboard to delete this %1$s and create new %2$s for your content. Have fun!', 'example', 'sportspress' ); // Insert posts foreach ( $pages as $post_type => $description ) { $obj = get_post_type_object( $post_type ); if ( ! is_object( $obj ) ) continue; // Skip if post exists $posts = get_posts( array( 'posts_per_page' => 1, 'post_type' => $post_type ) ); if ( $posts ) continue; // Add post args $post['post_title'] = $obj->labels->singular_name; $post['post_type'] = $post_type; $post['post_content'] = sprintf( $sample_content, $obj->labels->singular_name, $obj->labels->name, add_query_arg( 'post_type', $post_type, admin_url( 'edit.php' ) ) ); // Insert post $id = wp_insert_post( $post ); // Flag as sample update_post_meta( $id, '_sp_sample', 1 ); } wp_redirect( esc_url_raw( $this->get_next_step_link() ) ); exit; } /** * Actions on the final step. */ private function sp_setup_ready_actions() { delete_option( '_sp_needs_welcome' ); update_option( 'sportspress_installed', 1 ); update_option( 'sportspress_completed_setup', 1 ); delete_transient( '_sp_activation_redirect' ); // Check if first event already exists $events = get_posts( array( 'post_type' => 'sp_event', 'posts_per_page' => 1, 'post_status' => 'draft', 'meta_query' => array( array( 'key' => '_sp_first', 'value' => 1 ) ) ) ); if ( $events ) { $event = reset( $events ); return $event->ID; } // Get teams $team_post_type = 'sp_team'; if ( 'player' === get_option( 'sportspress_mode', 'team' ) ) { $team_post_type = 'sp_player'; } $teams = get_posts( array( 'posts_per_page' => 2, 'post_type' => $team_post_type ) ); // Get players $players = (array) get_posts( array( 'posts_per_page' => 3, 'post_type' => 'sp_player', 'fields' => 'ids' ) ); // Get staff $staff = (array) get_posts( array( 'posts_per_page' => 1, 'post_type' => 'sp_staff', 'fields' => 'ids' ) ); // Initialize post $post['post_type'] = 'sp_event'; $post['post_status'] = 'draft'; $post['tax_input'] = array(); // Add taxonomies $taxonomies = array( 'sp_league', 'sp_season', 'sp_venue' ); foreach ( $taxonomies as $taxonomy ) { $post['tax_input'][ $taxonomy ] = get_terms( $taxonomy, array( 'hide_empty' => 0, 'fields' => 'ids', 'number' => 1 ) ); }; // Add post title if ( is_array( $teams ) && sizeof( $teams ) ) { $team_names = array(); foreach ( $teams as $team ) { if ( ! $team ) continue; $team_names[] = $team->post_title; } $post['post_title'] = implode( ' ' . get_option( 'sportspress_event_teams_delimiter', 'vs' ) . ' ', $team_names ); } else { $post['post_title'] = __( 'Event', 'sportspress' ); } // Insert event $id = wp_insert_post( $post ); // Add teams if ( is_array( $teams ) && sizeof( $teams ) ) { foreach ( $teams as $team ) { if ( ! $team ) continue; add_post_meta( $id, 'sp_team', $team->ID ); } } // Add players add_post_meta( $id, 'sp_player', 0 ); foreach ( $players as $player ) { if ( ! $player ) continue; add_post_meta( $id, 'sp_player', $player ); } add_post_meta( $id, 'sp_player', 0 ); update_post_meta( $id, '_sp_first', 1 ); return $id; } /** * Final step. */ public function sp_setup_ready() { $id = $this->sp_setup_ready_actions(); shuffle( $this->tweets ); $steps = apply_filters( 'sportspress_setup_wizard_next_steps', array( 'first' => array( 'label' => __( 'Next Steps', 'sportspress' ), 'content' => '' . __( 'Schedule your first event!', 'sportspress' ) . '', ), 'last' => array( 'label' => __( 'Upgrade to Pro', 'sportspress' ), 'content' => __( 'Get SportsPress Pro to get access to all modules. You can upgrade any time without losing any of your data.', 'sportspress' ) . ' ' . __( 'Learn more', 'sportspress' ) . '', ), ) ); ?> Tweet