set_vars( $config );
$this->init();
}
/**
* Set variables based on configuration
* @param $config Configuration parameters
*/
public function set_vars( $config ) {
if ( isset( $config['page_slug'] ) ) {
$this->page_slug = esc_attr( $config['page_slug'] );
}
if ( isset( $config['page_title'] ) ) {
$this->page_title = esc_attr( $config['page_title'] );
}
if ( isset( $config['steps'] ) ) {
$this->config_steps = $config['steps'];
}
$current_theme = wp_get_theme();
$this->theme_title = $current_theme->get( 'Name' );
$this->theme_name = strtolower( preg_replace( '#[^a-zA-Z]#', '', $current_theme->get( 'Name' ) ) );
$this->page_slug = apply_filters( $this->theme_name . '_theme_setup_wizard_page_slug', $this->theme_name . '-wizard' );
$this->parent_slug = apply_filters( $this->theme_name . '_theme_setup_wizard_parent_slug', '' );
}
/*** Initialize hooks and actions ***/
public function init() {
add_action( 'after_switch_theme', array( $this, 'redirect_to_wizard' ) );
add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
add_action( 'admin_menu', array( $this, 'menu_page' ) );
add_action( 'wp_ajax_setup_widgets', array( $this, 'setup_widgets' ) );
}
public function redirect_to_wizard() {
global $pagenow;
if ( is_admin() && 'themes.php' === $pagenow && isset( $_GET['activated'] ) && current_user_can( 'manage_options' ) ) {
wp_redirect( admin_url( 'themes.php?page=' . esc_attr( $this->page_slug ) ) );
}
}
public function enqueue_scripts() {
wp_enqueue_style( 'theme-wizard-style', get_template_directory_uri() . '/theme-wizard/assets/css/theme-wizard-style.css');
wp_register_script( 'theme-wizard-script', get_template_directory_uri() . '/theme-wizard/assets/js/theme-wizard-script.js', array( 'jquery' ));
wp_localize_script(
'theme-wizard-script',
'aster_vlogger_whizzie_params',
array(
'ajaxurl' => admin_url( 'admin-ajax.php' ),
'verify_text' => esc_html( 'verifying', 'aster-vlogger' )
)
);
wp_enqueue_script( 'theme-wizard-script' );
}
public function menu_page() {
add_theme_page( esc_html( $this->page_title ), esc_html( $this->page_title ), 'manage_options', $this->page_slug, array( $this, 'aster_vlogger_setup_wizard' ) );
}
/*** Display the wizard page content ***/
public function wizard_page() { ?>
array(
'id' => 'intro',
'title' => __( 'Welcome to ', 'aster-vlogger' ) . $this->theme_title,
'view' => 'get_step_intro',
'callback' => 'do_next_step',
'button_text' => __( 'Start Now', 'aster-vlogger' ),
'can_skip' => false
),
'widgets' => array(
'id' => 'widgets',
'title' => __( 'Demo Importer', 'aster-vlogger' ),
'view' => 'get_step_widgets',
'callback' => 'install_widgets',
'button_text' => __( 'Import Demo', 'aster-vlogger' ),
'can_skip' => true
),
'done' => array(
'id' => 'done',
'title' => __( 'All Done', 'aster-vlogger' ),
'view' => 'get_step_done'
)
);
return $steps;
}
/*** Display the content for the intro step ***/
public function get_step_intro() { ?>
__('Home','aster-vlogger'),
'menu-item-classes' => 'home',
'menu-item-url' => home_url( '/' ),
'menu-item-status' => 'publish'));
wp_update_nav_menu_item($aster_vlogger_menu_id, 0, array(
'menu-item-title' => __('About','aster-vlogger'),
'menu-item-classes' => 'about',
'menu-item-url' => get_permalink(get_page_by_title('About')),
'menu-item-status' => 'publish'));
wp_update_nav_menu_item($aster_vlogger_menu_id, 0, array(
'menu-item-title' => __('Modules','aster-vlogger'),
'menu-item-classes' => 'modules',
'menu-item-url' => get_permalink(get_page_by_title('Modules')),
'menu-item-status' => 'publish'));
wp_update_nav_menu_item($aster_vlogger_menu_id, 0, array(
'menu-item-title' => __('Pages','aster-vlogger'),
'menu-item-classes' => 'pages',
'menu-item-url' => get_permalink(get_page_by_title('Pages')),
'menu-item-status' => 'publish'));
wp_update_nav_menu_item($aster_vlogger_menu_id, 0, array(
'menu-item-title' => __('Blogs','aster-vlogger'),
'menu-item-classes' => 'blog',
'menu-item-url' => get_permalink(get_page_by_title('Blogs')),
'menu-item-status' => 'publish'));
wp_update_nav_menu_item($aster_vlogger_menu_id, 0, array(
'menu-item-title' => __('Contact Us','aster-vlogger'),
'menu-item-classes' => 'contact',
'menu-item-url' => get_permalink(get_page_by_title('Contact Us')),
'menu-item-status' => 'publish'));
if( !has_nav_menu( $aster_vlogger_bpmenulocation ) ){
$locations = get_theme_mod('nav_menu_locations');
$locations[$aster_vlogger_bpmenulocation] = $aster_vlogger_menu_id;
set_theme_mod( 'nav_menu_locations', $locations );
}
}
}
public function aster_vlogger_customizer_socail_nav_menu() {
// ------- Create Social Menu --------
$aster_vlogger_menuname = $aster_vlogger_themename . 'Social Menu';
$aster_vlogger_bpmenulocation = 'social';
$aster_vlogger_menu_exists = wp_get_nav_menu_object( $aster_vlogger_menuname );
if( !$aster_vlogger_menu_exists){
$aster_vlogger_menu_id = wp_create_nav_menu($aster_vlogger_menuname);
wp_update_nav_menu_item( $aster_vlogger_menu_id, 0, array(
'menu-item-title' => __( 'Facebook', 'aster-vlogger' ),
'menu-item-url' => 'https://www.facebook.com',
'menu-item-status' => 'publish',
) );
wp_update_nav_menu_item( $aster_vlogger_menu_id, 0, array(
'menu-item-title' => __( 'Twitter', 'aster-vlogger' ),
'menu-item-url' => 'https://www.twitter.com',
'menu-item-status' => 'publish',
) );
wp_update_nav_menu_item( $aster_vlogger_menu_id, 0, array(
'menu-item-title' => __( 'Instagram', 'aster-vlogger' ),
'menu-item-url' => 'https://www.instagram.com',
'menu-item-status' => 'publish',
) );
wp_update_nav_menu_item( $aster_vlogger_menu_id, 0, array(
'menu-item-title' => __( 'Youtube', 'aster-vlogger' ),
'menu-item-url' => 'https://www.youtube.com',
'menu-item-status' => 'publish',
) );
wp_update_nav_menu_item( $aster_vlogger_menu_id, 0, array(
'menu-item-title' => __( 'Google', 'aster-vlogger' ),
'menu-item-url' => 'https://www.google.com',
'menu-item-status' => 'publish',
) );
if( !has_nav_menu( $aster_vlogger_bpmenulocation ) ){
$locations = get_theme_mod('nav_menu_locations');
$locations[$aster_vlogger_bpmenulocation] = $aster_vlogger_menu_id;
set_theme_mod( 'nav_menu_locations', $locations );
}
}
}
// ------------- /*** Imports demo content ***/ ----------------- //
public function setup_widgets() {
// Create a front page and assigned the template
$aster_vlogger_home_title = 'Home';
$aster_vlogger_home_check = get_page_by_title($aster_vlogger_home_title);
$aster_vlogger_home = array(
'post_type' => 'page',
'post_title' => $aster_vlogger_home_title,
'post_status' => 'publish',
'post_author' => 1,
'post_slug' => 'home'
);
$aster_vlogger_home_id = wp_insert_post($aster_vlogger_home);
//Set the static front page
$aster_vlogger_home = get_page_by_title( 'Home' );
update_option( 'page_on_front', $aster_vlogger_home->ID );
update_option( 'show_on_front', 'page' );
// Create a posts page and assigned the template
$aster_vlogger_blog_title = 'Blogs';
$aster_vlogger_blog = get_page_by_title($aster_vlogger_blog_title);
if (!$aster_vlogger_blog) {
$aster_vlogger_blog = array(
'post_type' => 'page',
'post_title' => $aster_vlogger_blog_title,
'post_status' => 'publish',
'post_author' => 1,
'post_name' => 'blog'
);
$aster_vlogger_blog_id = wp_insert_post($aster_vlogger_blog);
if (is_wp_error($aster_vlogger_blog_id)) {
// Handle error
}
} else {
$aster_vlogger_blog_id = $aster_vlogger_blog->ID;
}
// Set the posts page
update_option('page_for_posts', $aster_vlogger_blog_id);
// Create a about and assigned the template
$aster_vlogger_about_title = 'About';
$aster_vlogger_about_check = get_page_by_title($aster_vlogger_about_title);
$aster_vlogger_about = array(
'post_type' => 'page',
'post_title' => $aster_vlogger_about_title,
'post_status' => 'publish',
'post_author' => 1,
'post_slug' => 'blog'
);
$aster_vlogger_about_id = wp_insert_post($aster_vlogger_about);
// Create a Contact Us and assigned the template
$aster_vlogger_contact_title = 'Contact Us';
$aster_vlogger_contact_check = get_page_by_title($aster_vlogger_contact_title);
$aster_vlogger_contact = array(
'post_type' => 'page',
'post_title' => $aster_vlogger_contact_title,
'post_status' => 'publish',
'post_author' => 1,
'post_slug' => 'blog'
);
$aster_vlogger_contact_id = wp_insert_post($aster_vlogger_contact);
// Create a pages and assigned the template
$aster_vlogger_pages_title = 'Pages';
$aster_vlogger_pages_check = get_page_by_title($aster_vlogger_pages_title);
$aster_vlogger_pages = array(
'post_type' => 'page',
'post_title' => $aster_vlogger_pages_title,
'post_status' => 'publish',
'post_author' => 1,
'post_slug' => 'blog'
);
$aster_vlogger_pages_id = wp_insert_post($aster_vlogger_pages);
// Create a modules and assigned the template
$aster_vlogger_modules_title = 'Modules';
$aster_vlogger_modules_check = get_page_by_title($aster_vlogger_modules_title);
$aster_vlogger_modules = array(
'post_type' => 'page',
'post_title' => $aster_vlogger_modules_title,
'post_status' => 'publish',
'post_author' => 1,
'post_slug' => 'blog'
);
$aster_vlogger_modules_id = wp_insert_post($aster_vlogger_modules);
/*----------------------------------------- Header --------------------------------------------------*/
set_theme_mod( 'aster_vlogger_discount_topbar_text','Daily New & Trneding Vlog at One Point');
set_theme_mod( 'aster_vlogger_menu_custom_button_label','Submit Video');
set_theme_mod( 'aster_vlogger_menu_custom_button_url','#');
/*----------------------------------------- Blogs --------------------------------------------------*/
// Create categories if not already created
$aster_vlogger_category_slider = wp_create_category('Slider');
$aster_vlogger_category_services = wp_create_category('Services');
// Array of categories to assign to each set of posts
$aster_vlogger_categories = array($aster_vlogger_category_slider, $aster_vlogger_category_services);
// Array of image URLs for the "Slider" category
$slider_images = array(
get_template_directory_uri() . '/resource/image/slider1.png',
get_template_directory_uri() . '/resource/image/slider2.png',
get_template_directory_uri() . '/resource/image/slider3.png',
get_template_directory_uri() . '/resource/image/slider4.png',
get_template_directory_uri() . '/resource/image/slider5.png',
get_template_directory_uri() . '/resource/image/slider6.png'
);
// Array of image URLs for the "Services" category
$services_images = array(
get_template_directory_uri() . '/resource/image/service1.png',
get_template_directory_uri() . '/resource/image/service2.png',
get_template_directory_uri() . '/resource/image/service3.png',
);
// Loop to create posts
for ($i = 1; $i <=9; $i++) { // Adjusted to 10 posts in total
$title = array(
'What tech insider secret do you find most...',
'Travel the way you wish to...',
'Yes, there is art on',
'Food was more a distraction than',
'If she had cared about fashion, it',
'2018 fifa world cup official theme song released',
'What to Wear: 7 Ways to Stay in Style for Couples This Season',
'Simple Step by Step Tutorial for Making a Small Cake',
'Hot Air Balloon Travel for the Luxury Traveler of the 1800s',
);
$content = ' Exclusive, high-quality art at an affordable price.';
// Determine category and post index to use for title
$category_index = ($i <= 6) ? 0 : 1; // First 6 for Slider, next 4 for Services
$post_title = $title[$i - 1]; // Adjust for zero-based index in title array
// Create post object
$my_post = array(
'post_title' => wp_strip_all_tags($post_title),
'post_content' => $content,
'post_status' => 'publish',
'post_type' => 'post',
'post_category' => array($aster_vlogger_categories[$category_index]), // Assign Slider to first 6, Services to last 4
);
// Insert the post into the database
$post_id = wp_insert_post($my_post);
// Determine the category and set image URLs based on category
if ($category_index === 0) { // Slider category
// Use different images for each post in Slider category
$slider_image_index = $i - 1; // Get the correct index for the Slider images array (1-6 corresponds to 0-5)
$aster_vlogger_image_url = $slider_images[$slider_image_index];
$aster_vlogger_image_name = basename($aster_vlogger_image_url);
} else { // Services category
// Use different images for each post in Services category
$service_image_index = $i - 7; // Get the correct index for the Services images array (7-10 corresponds to 0-3)
$aster_vlogger_image_url = $services_images[$service_image_index];
$aster_vlogger_image_name = basename($aster_vlogger_image_url);
}
$aster_vlogger_upload_dir = wp_upload_dir();
$aster_vlogger_image_data = file_get_contents($aster_vlogger_image_url);
$aster_vlogger_unique_file_name = wp_unique_filename($aster_vlogger_upload_dir['path'], $aster_vlogger_image_name);
$filename = basename($aster_vlogger_unique_file_name);
if (wp_mkdir_p($aster_vlogger_upload_dir['path'])) {
$file = $aster_vlogger_upload_dir['path'] . '/' . $filename;
} else {
$file = $aster_vlogger_upload_dir['basedir'] . '/' . $filename;
}
if ( ! function_exists( 'WP_Filesystem' ) ) {
require_once( ABSPATH . 'wp-admin/includes/file.php' );
}
WP_Filesystem();
global $wp_filesystem;
if ( ! $wp_filesystem->put_contents( $file, $aster_vlogger_image_data, FS_CHMOD_FILE ) ) {
wp_die( 'Error saving file!' );
}
$wp_filetype = wp_check_filetype($filename, null);
$attachment = array(
'post_mime_type' => $wp_filetype['type'],
'post_title' => sanitize_file_name($filename),
'post_content' => '',
'post_status' => 'inherit'
);
$aster_vlogger_attach_id = wp_insert_attachment($attachment, $file, $post_id);
require_once(ABSPATH . 'wp-admin/includes/image.php');
$aster_vlogger_attach_data = wp_generate_attachment_metadata($aster_vlogger_attach_id, $file);
wp_update_attachment_metadata($aster_vlogger_attach_id, $aster_vlogger_attach_data);
set_post_thumbnail($post_id, $aster_vlogger_attach_id);
}
// ---------------------------------------- Videos --------------------------------------------------- //
set_theme_mod('aster_vlogger_video_section_title','Popular Videos');
set_theme_mod('aster_vlogger_video_section_text','Lorem Ipsum is simply dummy text of the printing and typesetting industry.');
// ---------------------------------------- Footer section --------------------------------------------------- //
set_theme_mod('footer_background_color_setting','#000000');
// ---------------------------------------- Related post_tag --------------------------------------------------- //
set_theme_mod('aster_vlogger_post_related_post_label','Related Posts');
set_theme_mod('aster_vlogger_related_posts_count','3');
$this->aster_vlogger_customizer_primary_menu();
$this->aster_vlogger_customizer_socail_nav_menu ();
}
}