0

I created a new navigation item on the left for my WP Admin:

add_action( 'admin_menu', 'addManagementMenuItem' );


function addManagementMenuItem(){

add_menu_page('Issue Management', 'Issue Management', 'manage_options', 'issue_management_slug', 'issue_management_building_function','',3);

} 


function issue_management_building_function(){

if(!current_user_can('manage_options')){

}
else {
    ?>
...
...

So where I have the ellipsis ... is where my HTML begins and I write out some information to the page with various php echo statements to print some data out.

What I would like to do is now give the user the ability to enter in a filter and press submit. This would issue a POST to another page which would receive the post data, run some stuff, and spit out something else to the screen. I was just thinking this would take the user away from the WP-ADMIN area entirely (what I want to do is keep the user all within the right pane so it looks like it's natively happening on WordPress under my new admin area)

Something feels wrong about this approach above where I'm putting tons of html into functions.php - what is the way to create pages for a custom admin section where I can do things like post forms and go to multiple pages?

I was thinking the best solution would be to put an iframe in my injected HTML in functions.php, and then the pages can talk to themselves just like normal behind the scenes in WP-admin.

Could anyone point me in the right direction?

thanks!

NullHypothesis
  • 4,286
  • 6
  • 37
  • 79

1 Answers1

1

Considering the user input/_POST features you'd like to add to this, you may want to consider building this functionality out as your own plugin. I've always kept custom functionality limited to non-user interaction in the functions.php file, but anything further would probably be better fit as it's own plugin.

For example, what if you created a plugin directory named nullhypothesis:

add_action( 'admin_menu', 'addManagementMenuItem' );

function addManagementMenuItem(){
add_menu_page('Issue Management', 'Issue Management', 'manage_options', 'nullhypothesis/file_to_do_your_bidding.php', 'issue_management_building_function','',3);
} 

It's that fourth parameter that in the documentation mentions that you should include the menu_slug, but it doesn't necessarily need to only be a function - it can also be a file you define.

Then, in your file_to_do_your_bidding.php file (within your plugin), you can add whatever _POST functionality you'd need it to. It could also exist as the 'admin' page that the administrator/whoever interacts with.

Was that what you were looking for?

markp
  • 74
  • 1
  • 3
  • thanks so much - Should this new plugin directory live in the same dir as my functions.php? or should it be in plugins? not sure what the "recommended" way is. thanks! – NullHypothesis Nov 04 '17 at 02:18
  • I would keep everything in a plugin directory - you can call your add_action() call in there. This doesn't mean that you can't have both a functions.php file and a custom plugin. Check out the WordPress documentation for creating your own plugin. In general, if it needs user interaction or does something complicated, I wrap up all of that into my custom plugin - I can add classes, it carries over if I switch themes, I can basically stay more organized in my code through the use of a plugin, over the static nature of the functions.php file. Please let me know if you have any questions. – markp Nov 05 '17 at 04:54
  • yes thank you, I did have a question, it relates to my other post if you don't mind. https://stackoverflow.com/questions/47142515/custom-plugin-posting-data-from-main-page-to-another-page-within-your-plugin I need to be able to now take some data, and submit it to another page. I don't want to put all of my logic on the same page (so how would I post from nullhypothesis/file_to_do_your_bidding.php to another php page, but make sure it's all within the admin look and feel (so it doesn't redirect out to a blank white page or something). – NullHypothesis Nov 06 '17 at 23:06