0

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-crm&p=documenti/list.php'),
        ''
        );

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

any idea?

  • I specify that I'm having this problem in a plugin – Andrea Somovigo Oct 23 '16 at 19:52
0

Reference: add submenu page

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

0

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

0

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.