[wp-trac] [WordPress Trac] #39003: menu_page_url() not working on Ajax call
WordPress Trac
noreply at wordpress.org
Fri Nov 29 18:12:06 UTC 2019
#39003: menu_page_url() not working on Ajax call
---------------------------------------------+-----------------------------
Reporter: vinoth06 | Owner: (none)
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting
| Review
Component: Administration | Version: 4.6.1
Severity: normal | Resolution:
Keywords: needs-testing reporter-feedback | Focuses:
---------------------------------------------+-----------------------------
Changes (by donmhico):
* keywords: needs-testing => needs-testing reporter-feedback
Comment:
Hello @vinoth06,
Welcome to WordPress trac! Thank you for submitting this ticket.
I looked more into the issue and I found out that I'm getting the correct
value from `menu_page_url()` via AJAX if the current user has the
capability to see the created admin page. If the user isn't logged-in or
lacking capability then I also receive nothing.
Here's the code I used for testing.
{{{#!php
<?php
// Create admin menu page.
function test_admin_menu_page() {
add_menu_page( 'Test Menu', 'Test Menu', 'manage_options',
'test_menu', 'test_menu_page' );
}
add_action( 'admin_init', 'test_admin_menu_page' );
// AJAX handler.
function test_ajax_menu_page_url() {
// Outputs - http://wp.test/wp-admin/admin.php?page=test_menu if
logged in as admin.
// Outputs nothing if logged-out.
echo menu_page_url( 'test_menu', false );
wp_die();
}
add_action( 'wp_ajax_ampu', 'test_ajax_menu_page_url' );
add_action( 'wp_ajax_nopriv_ampu', 'test_ajax_menu_page_url' );
}}}
--
Ticket URL: <https://core.trac.wordpress.org/ticket/39003#comment:3>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list