import_service = ImportService::get_instance(); $this->post_meta_services = PostMetaServices::get_instance(); $this->niches = NicheLoader::get_instance()->get_niches(); $this->selected_niche = NicheLoader::get_instance()->get_niche( $niche_id ); } public function install_niche( array $allowed_content, $builder = 'gutenberg' ) { $result = array(); if ( empty( $this->selected_niche ) ) { throw new \Error( 'Niche not found' ); } if ( function_exists( 'wc_set_time_limit' ) ) { \wc_set_time_limit( 0 ); } update_option( 'brandy_current_niche', $this->selected_niche['id'] ); if ( in_array( 'clean_data', $allowed_content, true ) ) { $this->clean_sample_data(); } if ( in_array( 'posts', $allowed_content, true ) ) { $this->reset_data(); $this->install_template(); $result['posts'] = $this->import_posts( $builder ); } if ( in_array( 'products', $allowed_content, true ) ) { $result['products'] = $this->import_sample_products(); } if ( in_array( 'product_categories', $allowed_content, true ) ) { $result['products'] = $this->import_product_categories(); } if ( in_array( 'pages', $allowed_content, true ) ) { $result['pages'] = $this->import_pages( $builder ); } if ( in_array( 'menus', $allowed_content, true ) ) { $result['menus'] = $this->import_menus(); } if ( in_array( 'widgets', $allowed_content, true ) ) { $result['imported_widgets'] = $this->import_widgets(); } return $result; } private function install_template() { if ( empty( $this->selected_niche ) ) { return; } $niche_id = $this->selected_niche['id']; do_action( 'brandy_before_' . $niche_id . '_installing_template_settings' ); if ( isset( $this->selected_niche['template'] ) ) { $this->override_template_settings( $this->selected_niche['template'] ); } do_action( 'brandy_after_' . $niche_id . '_installing_template_settings' ); } private function import_sample_products() { if ( empty( $this->selected_niche ) ) { return array(); } if ( ! isset( $this->selected_niche['sample_products'] ) || ! file_exists( $this->selected_niche['sample_products'] ) ) { return array(); } $csv_file = $this->selected_niche['sample_products']; if ( ! file_exists( $csv_file ) ) { return array(); } $imported_products = $this->import_service::read_products_from_csv( $csv_file ); return $imported_products; } private function import_product_categories() { if ( empty( $this->selected_niche ) ) { return array(); } $category_images_file = $this->selected_niche['sample_product_category_images'] ?? ''; if ( file_exists( $category_images_file ) ) { try { $images_file_content = file_get_contents( $category_images_file ); $images_data = json_decode( $images_file_content ); $images_data = empty( $images_data ) ? array() : $images_data; } catch ( \Error $error ) { $images_data = array(); } foreach ( $images_data as $cat_slug => $img_source ) { $cat = get_term_by( 'slug', $cat_slug, 'product_cat' ); if ( empty( $cat ) ) { continue; } if ( empty( $cat->term_id ) ) { continue; } \wp_update_term( $cat->term_id, 'product_cat', array( 'name' => trim( str_replace( 'Brandy', '', $cat->name ) ), ) ); if ( ! empty( \get_term_meta( $cat->term_id, 'thumbnail_id' ) ) ) { continue; } try { $image_id = media_sideload_image( $img_source, 0, '', 'id' ); } catch ( \Error $error ) { $bypass = true; } if ( ! is_wp_error( $image_id ) ) { \update_term_meta( $cat->term_id, 'thumbnail_id', absint( $image_id ) ); } } } $sample_ratings = array( array( 'rate' => 4, 'review' => __( 'Great product! It exceeded my expectations in quality and performance. The only downside is the packaging, which could be more eco-friendly.', 'brandy' ), ), array( 'rate' => 3, 'review' => __( 'Decent product but not worth the price. It works as advertised, but I found similar options for less money. Customer service was helpful, though.', 'brandy' ), ), array( 'rate' => 5, 'review' => __( 'Absolutely love this product! It has made my daily routine so much easier. Highly recommend to anyone looking for reliability and efficiency.', 'brandy' ), ), array( 'rate' => 4, 'review' => __( "Very good product overall. It's sturdy and performs well, but it took a bit longer to arrive than I expected. Still, I'd buy it again!", 'brandy' ), ), array( 'rate' => 1, 'review' => __( "Disappointed with this product. It didn't work as promised, and I had issues with durability. Customer support was slow to respond, which made it worse.", 'brandy' ), ), ); try { $product_tags_ids = get_terms( array( 'taxonomy' => 'product_tag', 'search' => 'brandy-', 'fields' => 'ids', ) ); $args = array( 'posts_per_page' => -1, 'tax_query' => array( 'relation' => 'AND', array( 'taxonomy' => 'product_tag', 'field' => 'id', 'terms' => $product_tags_ids, ), ), 'post_type' => 'product', 'orderby' => 'title,', ); $product_query = new \WP_Query( $args ); $imported_products = array( 'imported' => array(), ); if ( $product_query->have_posts() ) { foreach ( $product_query->get_posts() as $post ) { $imported_products['imported'][] = $post->ID; } } if ( ! empty( $imported_products['imported'] ) ) { foreach ( $imported_products['imported'] as $id ) { $random_rating_indexes = array_rand( $sample_ratings, wp_rand( 2, 4 ) ); foreach ( $random_rating_indexes as $random_index ) { if ( empty( $sample_ratings[ $random_index ] ) ) { continue; } $rating_data = $sample_ratings[ $random_index ]; $comment_id = wp_new_comment( array( 'comment_post_ID' => $id, 'comment_content' => $rating_data['review'], 'comment_type' => 'review', 'comment_approved' => true, 'user_ID' => get_current_user_id(), 'comment_author_email' => '', 'comment_author' => wp_get_current_user()->display_name, 'comment_author_url' => '#', ) ); if ( false != $comment_id && ! is_wp_error( $comment_id ) ) { add_comment_meta( $comment_id, 'rating', $rating_data['rate'], true ); } } } } } catch ( \Error $error ) { $bypass = true; } return true; } private function import_posts( $builder = 'gutenberg' ) { if ( empty( $this->selected_niche ) ) { return array(); } $niche_id = $this->selected_niche['id']; if ( ! isset( $this->selected_niche['sample_posts'][ $builder ] ) || ! file_exists( $this->selected_niche['sample_posts'][ $builder ] ) ) { return array(); } $csv_file = $this->selected_niche['sample_posts'][ $builder ]; $sample_posts = $this->import_service::read_posts_from_csv( $csv_file ); do_action( 'brandy_before_import_posts', $niche_id, $sample_posts ); $query = new \WP_Query( array( 'post_type' => 'post', 'post_name__in' => array_map( function( $p ) { return $p['name']; }, $sample_posts ), ) ); $existed_posts_name = array_map( function( $p ) { return $p->post_name; }, $query->have_posts() ? $query->posts : array() ); $not_existed_posts = array_filter( $sample_posts, function( $post_info ) use ( $existed_posts_name ) { return ! in_array( $post_info['name'], $existed_posts_name, true ); } ); $inserted_posts = array(); foreach ( $not_existed_posts as $post_info ) { $comment_status = isset( $post_info['comment_status'] ) ? ( empty( $post_info['comment_status'] ) ? 'closed' : 'open' ) : 'open'; $comments = isset( $post_info['comments'] ) ? $post_info['comments'] : array(); $post_args = array( 'post_title' => $post_info['title'], 'post_type' => 'post', 'post_name' => $post_info['name'], 'post_content' => $post_info['content'], 'post_category' => $post_info['post_category'], 'tags_input' => $post_info['tags_input'], 'post_status' => 'publish', 'comment_status' => 'closed', 'ping_status' => 'closed', 'post_author' => 1, 'menu_order' => 0, 'comment_status' => $comment_status, ); $inserted_id = wp_insert_post( $post_args ); if ( 0 === $inserted_id || is_wp_error( $inserted_id ) ) { continue; } if ( ! empty( $post_info['post_meta'] ) ) { foreach ( $post_info['post_meta'] as $key => $value ) { update_post_meta( $inserted_id, $key, $value ); } } foreach ( $comments as $comment ) { wp_insert_comment( array( 'comment_post_ID' => $inserted_id, 'comment_content' => $comment, ) ); } do_action( 'brandy_after_import_post', $niche_id, $builder, $inserted_id, $post_info ); $inserted_posts[] = $inserted_id; $this->import_service::add_featured_image( $inserted_id, $post_info['featured_image'] ?? '', $post_info['name'] ?? '' ); } do_action( 'brandy_after_import_posts', $niche_id, $inserted_posts ); return $inserted_posts; } private function import_pages( $builder = 'gutenberg' ) { if ( empty( $this->selected_niche ) ) { return; } $niche_id = $this->selected_niche['id']; $sample_pages = $this->import_service::read_posts_from_csv( BRANDY_TEMPLATE_DIR . '/inc/Niches/DefaultNiche/sample-data/sample-pages.json' ); if ( isset( $this->selected_niche['sample_pages'][ $builder ] ) && file_exists( $this->selected_niche['sample_pages'][ $builder ] ) ) { $csv_file = $this->selected_niche['sample_pages'][ $builder ]; $sample_pages = array_merge( $sample_pages, $this->import_service::read_posts_from_csv( $csv_file ) ); } if ( empty( $sample_pages ) ) { return array(); } do_action( 'brandy_before_import_pages', $niche_id, $sample_pages ); $query = new \WP_Query( array( 'post_type' => 'page', 'post_status' => 'publish', 'post_name__in' => array_map( function( $p ) { return $p['name']; }, $sample_pages ), ) ); $existed_pages_name = array(); $imported_pages = array(); if ( $query->have_posts() ) { foreach ( $query->posts as $p ) { $same_pages = array_filter( $sample_pages, function( $item ) use ( $p ) { return $p->post_name === $item['name']; } ); $find_page = end( $same_pages ); $data = array( 'id' => $p->ID, 'name' => $p->post_name, 'title' => $p->post_title, ); if ( $find_page ) { $data['post_meta'] = $find_page['post_meta'] ?? array(); } $imported_pages[] = $data; $existed_pages_name[] = $p->post_name; } } $not_existed_pages = array_filter( $sample_pages, function( $page_info ) use ( $existed_pages_name ) { return ! in_array( $page_info['name'], $existed_pages_name, true ); } ); $inserted_pages = array(); foreach ( $not_existed_pages as $page_info ) { $post_args = array_merge( array( 'post_title' => $page_info['title'], 'post_type' => 'page', 'post_name' => $page_info['name'], 'post_content' => $page_info['content'], 'post_status' => 'publish', 'comment_status' => 'closed', 'ping_status' => 'closed', 'post_author' => 1, 'menu_order' => 0, ), isset( $page_info['page_template'] ) ? array( 'page_template' => $page_info['page_template'], ) : array() ); $new_post_id = wp_insert_post( $post_args ); $inserted_pages[] = $new_post_id; $imported_pages[] = array( 'id' => $new_post_id, 'title' => $page_info['title'], 'name' => $page_info['name'], 'post_meta' => $page_info['post_meta'] ?? array(), ); if ( 0 === $new_post_id || is_wp_error( $new_post_id ) ) { continue; } do_action( 'brandy_after_import_page', $niche_id, $builder, $new_post_id, $page_info ); } foreach ( $imported_pages as $data ) { $matching_items = array_values( array_filter( $sample_pages, function( $item ) use ( $data ) { return $item['name'] == $data['name']; } ) ); if ( count( $matching_items ) < 1 ) { continue; } $page_info = $matching_items[0]; $new_post_id = $data['id']; if ( ! empty( $page_info['name'] ) && 'homepage' === $page_info['name'] ) { update_option( 'show_on_front', 'page' ); update_option( 'page_on_front', $new_post_id ); } if ( ! empty( $page_info['name'] ) && 'blog' === $page_info['name'] ) { update_option( 'show_on_front', 'page' ); update_option( 'page_for_posts', $new_post_id ); } if ( ! empty( $page_info['name'] ) && 'terms-and-conditions' === $page_info['name'] ) { update_option( 'woocommerce_terms_page_id', $new_post_id ); } if ( ! empty( $page_info['name'] ) && 'privacy-policy' === $page_info['name'] ) { update_option( 'wp_page_for_privacy_policy', $new_post_id ); } if ( ! empty( $page_info['name'] ) && 'shop' === $page_info['name'] ) { update_option( 'woocommerce_shop_page_id', $new_post_id ); } if ( ! empty( $page_info['name'] ) && 'cart' === $page_info['name'] ) { update_option( 'woocommerce_cart_page_id', $new_post_id ); } if ( ! empty( $page_info['name'] ) && 'checkout' === $page_info['name'] ) { update_option( 'woocommerce_checkout_page_id', $new_post_id ); } wp_update_post( array_merge( array( 'ID' => $new_post_id, 'post_status' => 'publish', ), ! empty( $page_info['page_template'] ) ? array( 'page_template' => $page_info['page_template'], ) : array() ) ); /** * Remove old meta for pages */ foreach ( ( $this->post_meta_services->services ?? array() ) as $meta_service ) { delete_post_meta( $new_post_id, $meta_service::META_NAME ); } if ( ! empty( $page_info['post_meta'] ) ) { foreach ( $page_info['post_meta'] as $key => $value ) { update_post_meta( $new_post_id, $key, $value ); } } } do_action( 'brandy_after_import_pages', $niche_id, $imported_pages ); return $inserted_pages; } private function import_menus() { if ( empty( $this->selected_niche ) ) { return; } $niche_id = $this->selected_niche['id']; if ( ! isset( $this->selected_niche['sample_menus'] ) || ! is_array( $this->selected_niche['sample_menus'] ) ) { return array(); } $niche_instance = NicheLoader::get_instance()->get_niche_instance( $niche_id ); if ( ! empty( $niche_instance ) && is_callable( array( $niche_instance, 'get_sample_menus' ) ) ) { $sample_menus = $niche_instance::get_sample_menus(); } else { $sample_menus = $this->selected_niche['sample_menus']; } do_action( 'brandy_before_import_menus', $niche_id, $sample_menus ); $imported_menus = array(); foreach ( $sample_menus as $menu_info ) { $menu_exists = wp_get_nav_menu_object( $menu_info['name'] ); if ( $menu_exists ) { $imported_menus[] = array_merge( array( 'id' => $menu_exists->term_id ), $menu_info ); continue; } $menu_id = wp_create_nav_menu( $menu_info['name'] ); if ( is_wp_error( $menu_id ) ) { continue; } $imported_menus[] = array_merge( array( 'id' => $menu_id ), $menu_info ); $parent_menus = array(); foreach ( $menu_info['items'] as $menu_item ) { if ( isset( $menu_item['parent'] ) ) { continue; } $id = wp_update_nav_menu_item( $menu_id, 0, empty( $menu_item['object_id'] ) ? array( 'menu-item-title' => $menu_item['title'] ?? 'Sample item', 'menu-item-url' => $menu_item['url'] ?? '#', 'menu-item-status' => $menu_item['status'] ?? 'publish', ) : array( 'menu-item-title' => $menu_item['title'] ?? 'Sample item', 'menu-item-type' => isset( $menu_item['item_type'] ) ? $menu_item['item_type'] : '', 'menu-item-object-id' => $menu_item['object_id'], 'menu-item-object' => $menu_item['item_object'], 'menu-item-status' => $menu_item['status'], ) ); if ( ! is_wp_error( $id ) && ! empty( $menu_item['key'] ) ) { $parent_menus[ $menu_item['key'] ] = $id; } } foreach ( $menu_info['items'] as $submenu ) { if ( ! isset( $submenu['parent'] ) ) { continue; } if ( ! isset( $parent_menus[ $submenu['parent'] ] ) ) { continue; } $id = wp_update_nav_menu_item( $menu_id, 0, empty( $submenu['object_id'] ) ? array( 'menu-item-title' => $submenu['title'] ?? 'Sample item', 'menu-item-url' => $submenu['url'] ?? '#', 'menu-item-status' => $submenu['status'] ?? 'publish', 'menu-item-parent-id' => $parent_menus[ $submenu['parent'] ], ) : array( 'menu-item-type' => isset( $submenu['item_type'] ) ? $submenu['item_type'] : '', 'menu-item-object-id' => $submenu['object_id'], 'menu-item-object' => $submenu['item_object'], 'menu-item-status' => $submenu['status'], 'menu-item-parent-id' => $parent_menus[ $submenu['parent'] ], ) ); } } do_action( 'brandy_after_import_menus', $niche_id, $imported_menus ); return $imported_menus; } private function import_widgets() { if ( empty( $this->selected_niche ) ) { return; } update_option( 'brandy_sample_widgets', $this->selected_niche['id'] ); } public static function register_widgets() { $niche_id = get_option( 'brandy_sample_widgets' ); $import_service = ImportService::get_instance(); $selected_niche = NicheLoader::get_instance()->get_niche( $niche_id ); if ( empty( $selected_niche ) ) { return; } if ( ! isset( $selected_niche['sample_widgets'] ) || ! file_exists( $selected_niche['sample_widgets'] ) ) { return array(); } $csv_file = $selected_niche['sample_widgets']; $sample_widgets = $import_service::read_widgets_from_csv( $csv_file ); foreach ( $sample_widgets as $widget ) { register_sidebar( array( 'name' => $widget['title'], 'id' => $widget['id'], 'description' => esc_html__( 'Add widgets here:', 'brandy' ), 'before_widget' => '
', 'after_widget' => '
', 'before_title' => '

', 'after_title' => '

', ) ); } } private function override_template_settings( $data ) { /** * Override button */ $button_settings = ButtonService::get_default_settings(); if ( isset( $data['button'] ) ) { $button_settings = Helpers::recursive_wp_parse_args( $data['button'], $button_settings ); } $this->override_button_settings( $button_settings ); /** * Override input */ $input_settings = InputService::get_default_settings(); if ( isset( $data['input'] ) ) { $input_settings = Helpers::recursive_wp_parse_args( $data['input'], $input_settings ); } $this->override_input_settings( $input_settings ); /** * Override select */ $select_settings = SelectService::get_default_settings(); if ( isset( $data['select'] ) ) { $select_settings = Helpers::recursive_wp_parse_args( $data['select'], $select_settings ); } $this->override_select_settings( $select_settings ); /** * Override select */ $breadcrumb_settings = BreadcrumbService::get_default_settings(); if ( isset( $data['breadcrumb'] ) ) { $breadcrumb_settings = Helpers::recursive_wp_parse_args( $data['breadcrumb'], $breadcrumb_settings ); } $this->override_breadcrumb_settings( $breadcrumb_settings ); /** * Override woocommerce */ $woocommerce_settings = array( 'product_layout' => 'option_1', 'product_thumb_size' => 'size_1', 'sale_badge' => SaleBadgeService::get_default_settings(), ); if ( isset( $data['woocommerce'] ) ) { $woocommerce_settings = Helpers::recursive_wp_parse_args( $data['woocommerce'], $woocommerce_settings ); } $this->override_woocommerce_settings( $woocommerce_settings ); /** * Override builder settings */ if ( isset( $data['headers'] ) ) { $this->override_builder_settings( $data['headers'], 'header' ); } if ( isset( $data['footers'] ) ) { $this->override_builder_settings( $data['footers'], 'footer' ); } } private function override_button_settings( $data ) { ButtonService::save_settings( $data ); } private function override_input_settings( $data ) { InputService::save_settings( $data ); } private function override_select_settings( $data ) { SelectService::save_settings( $data ); } private function override_breadcrumb_settings( $data ) { BreadcrumbService::save_settings( $data ); } private function override_builder_settings( $files, $builder = 'header' ) { if ( empty( $this->selected_niche ) ) { return; } $niche_id = $this->selected_niche['id']; $fn = "brandy_get_{$builder}_settings"; if ( ! is_callable( $fn ) ) { return; } $builder_settings = call_user_func( $fn ); $templates = &$builder_settings['templates']; $imported_data = array(); foreach ( $files as $file ) { if ( ! file_exists( $file ) ) { continue; } $template_data = json_decode( file_get_contents( $file ), true ); //phpcs:ignore $template_exists = false; foreach ( $templates as $index => $template ) { if ( $template_data['id'] === $template['id'] ) { $template_exists = true; $builder_settings['templates'][ $index ] = $template_data; break; } } if ( ! $template_exists ) { $builder_settings['templates'][] = $template_data; } $imported_data[] = $template_data; } $save_function = "brandy_save_{$builder}_settings"; if ( is_callable( $save_function ) ) { call_user_func( $save_function, $builder_settings ); do_action( "brandy_after_{$niche_id}_import_{$builder}", $imported_data ); } } private function override_woocommerce_settings( $data ) { $product_catalog_data = array(); if ( isset( $data['product_layout'] ) ) { $product_catalog_data['product_layout'] = $data['product_layout']; } if ( isset( $data['product_thumb_size'] ) ) { $product_catalog_data['product_thumb_size'] = $data['product_thumb_size']; } ProductCatalogService::save_settings( $product_catalog_data ); if ( isset( $data['single_product'] ) ) { SingleProductService::save_settings( $data['single_product'] ); } if ( isset( $data['sale_badge'] ) ) { SaleBadgeService::save_settings( $data['sale_badge'] ); } } public function reset_wp_templates() { $post_names = array(); $dir = new \DirectoryIterator( BRANDY_TEMPLATE_DIR . '/templates' ); foreach ( $dir as $fileinfo ) { if ( ! $fileinfo->isDot() ) { $post_names[] = basename( $fileinfo->getFilename(), '.html' ); } } $dir = new \DirectoryIterator( BRANDY_TEMPLATE_DIR . '/parts' ); foreach ( $dir as $fileinfo ) { if ( ! $fileinfo->isDot() ) { $post_names[] = basename( $fileinfo->getFilename(), '.html' ); } } $args = array( 'post_type' => array( 'wp_template', 'wp_template_part' ), 'post_name__in' => $post_names, ); $query = new \WP_Query( $args ); if ( ! $query->have_posts() ) { return; } foreach ( $query->posts as $post ) { wp_delete_post( $post->ID ); } } public function reset_editor_settings() { if ( ! class_exists( 'WP_Theme_JSON_Resolver' ) ) { return; } $id = \WP_Theme_JSON_Resolver::get_user_global_styles_post_id(); if ( empty( $id ) ) { return; } if ( ! class_exists( 'WP_REST_Global_Styles_Controller' ) ) { return; } try { wp_update_post( array( 'ID' => $id, 'post_content' => '{"isGlobalStylesUserThemeJSON":true,"version":3}', ) ); } catch ( \WP_Error $error ) { $trick_mode = 1; // This is silent } catch ( \Exception $exp ) { $trick_mode = 1; // This is silent } } public function clean_sample_data() { global $wpdb; /** * Cleaning headers/footers */ // if ( ! empty( $this->selected_niche ) ) { // $header_settings = brandy_get_header_settings(); // $footer_settings = brandy_get_footer_settings(); // $header_settings['templates'] = array_values( // array_filter( // $header_settings['templates'], // function( $template ) { // return ( false === strpos( $template['id'], '_main_header' ) && false === strpos( $template['id'], '_checkout_header' ) ); // } // ) // ); // $footer_settings['templates'] = array_values( // array_filter( // $footer_settings['templates'], // function( $template ) { // return ( false === strpos( $template['id'], '_main_footer' ) && false === strpos( $template['id'], '_checkout_footer' ) ); // } // ) // ); // brandy_save_header_settings( $header_settings ); // brandy_save_footer_settings( $footer_settings ); // } /** * Cleaning posts */ $posts_query = new \WP_Query( array( 'posts_per_page' => -1, 'tag' => 'brandy-demo', 'fields' => 'ids', ) ); if ( $posts_query->have_posts() ) { foreach ( $posts_query->get_posts() as $post_id ) { wp_delete_post( $post_id, true ); } } /** * Cleaning sample products */ $product_tags_ids = get_terms( array( 'taxonomy' => 'product_tag', 'search' => 'brandy-', 'fields' => 'ids', ) ); $product_cats_ids = get_terms( array( 'taxonomy' => 'product_cat', 'search' => 'brandy-', 'fields' => 'ids', ) ); $post_cats_ids = get_terms( array( 'taxonomy' => 'category', 'search' => 'brandy-', 'hide_empty' => false, 'fields' => 'ids', ) ); $args = array( 'posts_per_page' => -1, 'tax_query' => array( 'relation' => 'AND', array( 'taxonomy' => 'product_tag', 'field' => 'id', 'terms' => $product_tags_ids, ), ), 'post_type' => 'product', 'orderby' => 'title,', ); $product_query = new \WP_Query( $args ); if ( $product_query->have_posts() ) { foreach ( $product_query->get_posts() as $post ) { $product = \wc_get_product( $post ); $product->delete( true ); $product_cats_ids = array_merge( $product_cats_ids, $product->get_category_ids() ); } } foreach ( array_unique( $product_cats_ids ) as $cat ) { wp_delete_term( $cat, 'product_cat' ); } foreach ( array_unique( $post_cats_ids ) as $cat ) { wp_delete_term( $cat, 'category' ); } foreach ( array_unique( $product_tags_ids ) as $tag ) { wp_delete_term( $tag, 'product_tag' ); } /** Clean menus */ if ( empty( $this->selected_niche ) ) { return; } $menus = $this->selected_niche['sample_menus']; foreach ( $menus as $menu ) { $menu_exists = wp_get_nav_menu_object( $menu['name'] ); if ( $menu_exists ) { wp_delete_nav_menu( $menu_exists ); } } } public function reset_data() { $this->reset_editor_settings(); $this->reset_wp_templates(); } }