One Click Demo Import


#1

Hi Guys,

I’m new to using this plugin. Can someone help me on this?
What is the proper code for this

this is the after import code from One Click Demo Import

$main_menu = get_term_by( 'name', 'Main Menu', 'nav_menu' );
set_theme_mod( 'primary-menu', array( 'main-menu' => $main_menu->term_id, ) );

and this is my register_nav_menus() code

register_nav_menus( array( 'primary-menu' => esc_html__( 'Primary Menu', 'textdomain' ) ) );

The menu does not automatically assign the menu locations after the import. What I’m doing wrong?

Thank you!


#2

primary-menu is menu location
main-menu is the name of the menu

What have I done wrong? Can anyone help?

Thank you!


#3

I don’t use One Click Demo importer, but I know that there was a bug with default WordPress import plugin - the same like your problem, menu was not imported if you are using PHP 7.

I think this is fixed with last update in WordPress Importer - maybe is the same/similar problem with One Click Demo importer.

Hope someone will provide you more info.


#4

Maybe my code example will be useful:

// Register Navigation
register_nav_menu('main_navigation', 'Main Navigation');
register_nav_menu('bottom_navigation', 'Bottom Navigation');

// One Click Demo Import plugin	
if(class_exists('OCDI_Plugin')) { 

//Setup basic demo import
function taunita_import_files() {
			
	return array(
      array(
      'import_file_name'             => 'taunita',
      'categories'                   => array( 'Category 1', 'Category 2' ),
      'local_import_file'            => get_parent_theme_file_path( 'framework/ocdi/taunita.xml' ),
      'local_import_widget_file'     => get_parent_theme_file_path( 'framework/ocdi/taunita.wie' ),
      'local_import_customizer_file' => get_parent_theme_file_path( 'framework/ocdi/taunita.dat' ),
      'local_import_redux'           => array(
      array(
        'file_path'                  => get_parent_theme_file_path( 'framework/ocdi/taunita.json' ),
        'option_name'                => 'smof_data',
      ),
      ),
      'import_preview_image_url'     => get_parent_theme_file_uri( '/screenshot.png' ),
      'preview_url'                  => 'http://themeperfect.me/taunita/',
      ),
	);
    
}
add_filter( 'pt-ocdi/import_files', 'taunita_import_files' );

//Setup front page and menus
function taunita_after_import_setup() {
	
    // Assign menus to their locations
    $main_menu = get_term_by( 'name', 'Main Menu', 'nav_menu' );
    $bottom_menu = get_term_by( 'name', 'Bottom Menu', 'nav_menu' );

    set_theme_mod( 'nav_menu_locations', array(
            'main_navigation'  => $main_menu->term_id,
            'bottom_navigation' => $bottom_menu->term_id,
        )
    );

    // Assign front page and blog page.
    $front_page_id = get_page_by_title( 'Home' );
    $blog_page_id  = get_page_by_title( 'Blog' );

    update_option( 'show_on_front', 'page' );
    update_option( 'page_on_front', $front_page_id->ID );
    update_option( 'page_for_posts', $blog_page_id->ID );
    update_option( 'posts_per_page', '4' );

}
add_action( 'pt-ocdi/after_import', 'taunita_after_import_setup' );

//Remove Branding
add_filter( 'pt-ocdi/disable_pt_branding', '__return_true' );

//Save customize options
add_action( 'pt-ocdi/enable_wp_customize_save_hooks', '__return_true' );

}

#5

Thanks, man. I tested this and unfortunately, it’s not working. I’m using register_nav_menus() not register_nav_menu(). Below is my updated code.

register_nav_menus( array( 'primary-menu' => esc_html__( 'Primary Menu', 'textdomain' ) ) );

$main_menu = get_term_by( 'name', 'Main Menu', 'nav_menu' );
set_theme_mod( 'nav_menu_locations', array(
          'primary-menu'  => $main_menu->term_id,
     )
);

Not sure if this is a bug or code issue above?
Does the “Main Menu” label is the menu name? If yes, then I should change it to “main-menu”


#6

It works fine now. I just change the “Main Menu” label to “main-menu” which is the name of my menu.

register_nav_menus( array( 'primary-menu' => esc_html__( 'Primary Menu', 'textdomain' ) ) );

$main_menu = get_term_by( 'name', 'main-menu', 'nav_menu' );
set_theme_mod( 'nav_menu_locations', array(
          'primary-menu'  => $main_menu->term_id,
     )
);

Thanks for the help @themeperfect