I have already developed my plugin for WordPress and I can manage it from admin. I have passed the access to the plugin file using add_submenu_page
. The problem is that the plugin is extending and I want to use another file that is linked from the main file. For example I have second_page.php?id=3
. When I try to access this link, I get a
You do not have sufficient permissions to access this page.
message. I want to “validate” this page also for using with this script and I don’t know how. Ideas?
When you add a page with
add_submenu_page()
, the url should be something like:wp-admin/admin.php?page=<your_page_handle>
Your page is actually loaded from
admin.php
(typically). You can add parameters to your links by appending something like&id=3
and then have your main plugin page-loading logic determine which file to include based on the parameter.For instance
Edit:
I found a trick that may be easier for you, though I haven’t thoroughly tested it. Let’s say that you have two pages:
my_one
andmy_two
. Just calladd_submenu_page
twice, and set the second page’s parent as the first page. This will cause WordPress to not add a link to the navigation bar, but you can still access your page by navigating toadmin.php?page=my_two
.Example:
Since WP natively supports URLs like
wp-admin/admin.php?page=<your_page_handle>
you can do sub pages with something like:wp-admin/admin.php?page=yourpage
wp-admin/admin.php?page=yourpage&sub=2
wp-admin/admin.php?page=yourpage&sub=3
Then in the code that handles
wp-admin/admin.php?page=<your_page_handle>
you just look at the $_GET and pull up the main page or a sub-page as needed.I’ve definitely seen plugins where the admin page has a little row of links across the top linking the various sub-pages.