• Resolved Pamela

    (@infoknutsford-softwarecouk)


    I have tried adding this to my plugin to add a menu to the dashboard

    `add_submenu_page(
    ‘xls-download’,
    __( ‘XLS Download’, ‘xls-download’ ),
    __( ‘XLS Download’, ‘xls-download’ ),
    ‘export’,
    ‘xls-download’
    );`

    But I am getting

    Fatal error: Uncaught Error: Call to undefined function wp_get_current_user() in …… public_html/wp-includes/capabilities.php on line 652

Viewing 8 replies - 1 through 8 (of 8 total)
  • Working fine at my end, use below code

    function custom_options_panel(){
      add_menu_page('Custom page title', 'Custom menu label', 'manage_options', 'Custom-options', 'wps_Custom_func');
      add_submenu_page( 'Custom-options', 'Settings page title', 'Settings menu label', 'manage_options', 'Custom-op-settings', 'wps_Custom_func_settings');
      add_submenu_page( 'Custom-options', 'FAQ page title', 'FAQ menu label', 'manage_options', 'Custom-op-faq', 'wps_Custom_func_faq');
    }
    add_action('admin_menu', 'custom_options_panel');

    You have issue with capabilities options.

    
    add_submenu_page(
        'xls-download',
        __( 'XLS Download', 'xls-download' ),
        __( 'XLS Download', ‘xls-download' ),
        'export',
        'xls-download'
    );
    

    should be like this

    
    add_submenu_page(
        'xls-download',
        __( 'XLS Download', 'xls-download' ),
        __( 'XLS Download', ‘xls-download' ),
        'manage_options',
        'xls-download'
    );
    

    https://developer.www.ads-software.com/reference/functions/add_submenu_page/

    Thread Starter Pamela

    (@infoknutsford-softwarecouk)

    I have change it to

    function xls_download_menu() {	
    		add_submenu_page(
    			'xls-download',
    			__( 'XLS Download', 'xls-download' ),
    			__( 'XLS Download', 'xls-download' ),
    			'export',
    			'xls-download'			
    		);
    } 

    but the menu isn’t showing up? Is export correct? I would have thought so

    Thread Starter Pamela

    (@infoknutsford-softwarecouk)

    I also put

    add_action(‘admin_menu’,’xls_download_menu’); and it is calling the function alright

    You should use

    
    function xls_download_menu() {	
    		add_submenu_page(
    			'xls-download',
    			__( 'XLS Download', 'xls-download' ),
    			__( 'XLS Download', 'xls-download' ),
    			'manage_options',
    			'xls-download', 
                            'render_view', 
                            10	
    		);
    }
    
    function render_view() {
       // HTML Output
    }
    
    • This reply was modified 4 years, 10 months ago by Jogesh.
    Thread Starter Pamela

    (@infoknutsford-softwarecouk)

    AH I have changed it to

    function xls_download_menu(){
    add_menu_page(‘XLS Download’, ‘XLS Download’, ‘manage_options’, ‘download’, ”);
    }

    Thanks it shows up now

    I am getting a 404 on the download page now. How do I create the actual download page with a form in it?

    Thread Starter Pamela

    (@infoknutsford-softwarecouk)

    It is ok I have worked it out. A cup of coffee does wonders

    Thread Starter Pamela

    (@infoknutsford-softwarecouk)

    Thanks

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Adding menu’ is closed to new replies.