What i want to do is fire up the add_submenu_page()
function from within ajax on my plugin options page.
When i click an “Add League” link, i want to display an ajax input[text] that will save into the database, then add the submenu page using the values that have been inserted.
I am also hoping to be able to delete the entry as well as the newly created page.
As you can’t suppose to get a full working example without any given code, I’ll show you a rough wordpress AJAX setup:
Put all this in
functions.php
:I recommend to return a json-encoded array, so you could provide more-detailed information. I.e. if the sanitization fails because it is too short:
http://php.net/manual/de/function.json-encode.php
Then in your
response
function of the ajax call:http://api.jquery.com/jQuery.parseJSON/
Here is a good write-up about using ajax in wordpress:
http://www.garyc40.com/2010/03/5-tips-for-using-ajax-in-wordpress/
EDIT:
Totally forgot about this:
add_submenu_page()
won’t work, because the page is already rendered at this point.