So i’m trying to create a WordPress plugin and I’ve created some menu pages using this provided function:
add_submenu_page('my_plugin_menu', 'Edit record page', 'Edit record page', 'manage_options', 'edit_record_page', array(&$this, 'display_edit_record_page');
and when I go to the page I notice on the address bar on the browser it reads something like this:
http://mydomain.com/wp/wp-admin/admin.php?page=edit_record_page
What I want to do is to be able to link this page but I find I have to hardcode the link for lack of a better way of doing it and I’m working on a dev site. So I was wondering how I could dynamically generate the link I saw on my browser so that when I copy this plugin code onto the production server it will work. Namely, is there a WordPress function that will generate the link portion of the submenu page create.
page=edit_record_page
Also, if I want to append query strings to the to the link is it as simple as adding it manually like so:
http://mydomain.com/wp/wp-admin/admin.php?page=edit_record_page&rec_id=1
or is there an appropriate WordPress function for doing that too?
admin_url()
gets you the correct administration page URL (andnetwork_admin_url()
to get a network administration page URL)Optionally, you can use
add_query_arg()
to append arguments to an URL, using an associative array:<a href="admin.php?page=edit_record_page">Link Text</a>
and
<a href="admin.php?page=edit_record_page&rec_id=1">Link Text</a>