usage of admin_url() in add_menu_page()

Does anybody have experienced this issue: using admin_url() in add_menu_page() returns an url that contains the domain name twice:

add_submenu_page(
        'smart-crm',
        __('WP SMART CRM Documents', 'mytextdomain'),
        __('Documents', 'mytextdomain'),
        'manage_options',
        admin_url('admin.php?page=smart-crmp=documenti/list.php'),
        ''
        );

My output link is : https://domain.com/domain.com/wp-admin/admin.php?page=smart-crmp=documenti/list.php

any idea?

Topic add-menu-page Wordpress

Category Web


I apologise for necoposting such an old topic but I ran into this exact problem recently and all I could find via Googling was "This is what the function does" and nothing related to this problem apart from this post.

I looked at the "fix" and didn't really understand how this fix solved the problem so I experimented and discovered the question marks above my head were well founded.

Yes, the above method DOES indeed fix the problem but it is a fluke. By adding the $$ in front of adminurl he is basically calling an empty string since he is storing the URL inside a variable and then trying to use a variable with a name that matches the url. Since he never created a variable called $"mysite.com/wp-admin" $$adminurl will always return an empty string.

As such I did one final experiment and simply omitted the use of admin_url() completely and that worked perfectly. I.e.

add_submenu_page(
    'smart-crm',
    __('WP SMART CRM Documents', 'mytextdomain'),
    __('Documents', 'mytextdomain'),
    'manage_options',
    'admin.php?page=smart-crm&p=documenti/list.php',
    '');

That is the solution to the double domain issue. Ideally I would also like to have known the answer to the posters question and understand WHY the domain is returned twice but as long as this works, I can live with that.


It looks like I've solved the issue using:

$adminurl=admin_url();
add_submenu_page(
    'smart-crm',
    __('WP SMART CRM Documents', 'mytextdomain'),
    __('Documents', 'mytextdomain'),
    'manage_options',
    $$adminurl.'admin.php?page=smart-crm&p=documenti/list.php',
    ''
    );

now the links are correct


Reference: add submenu page

You can not use any function as url parameter, only admin page slug.

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.