Navigating links within custom WordPress plugin

Issue

I have created a custom WordPress plugin that will display a list of information and i will have the ability to add or edit this information. This seems easy but somehow i am not able to make it work how i would like it to. I have a list of companys and i am showing this list in a table. For each company, i can change its info.

Here is a pic of what a company looks in a table

I want to make it so when i click on settings or profile that the page will change and i will pass in the id of the company as a parameter.
I can add a new php page to the href but then that navigates to a new page and i am no longer in the admin dashboard. How can i navigate the url to another page with id without having to leave the dashboard?
When i created a plugin i created submenu pages and when i navigate to these pages… i am executing code all in the same file but different functions with different html which i feel is the way i want when navigating to Settings or Profile for a company.

Solution

You can do this by following the below steps:

  1. If you admin/dashboard page URL is something like this: /wp-admin/admin.php?page=list then you need to add extra parameter for settings & profile page like this way: /wp-admin/admin.php?page=list&action=settings&id={id} or /wp-admin/admin.php?page=list&action=profile&id={id}

  2. After that, you need to check if $_GET['action'] is profile or settings, then you need to render the profile page or settings page content respectively instead of list page content. Otherwise, if the action parameter is not set you can render the list page content.

Let me know if you need further assistance.

Answered By – Mahedi Hasan

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published