I am new to WordPress and I'm wondering if anyone could help me understand how I should go for rendering the output of a plugin when a form of a widget is submitted in the front-end.
I'm developing a plugin that has two "views" and one widget. The widget is just a form with a dropdown menu to select a value from a list. When a value is selected, the form should submit this value to a page where the first view of the plugin is rendered. This first view should print links that take the visitor to the second view. It's like if the first view was a list of rows, and the second view was the details of the row selected from the first view. My widget's form should know to which URL the data should be posted. This is the goal.
I've been reading the Plugin API, but I don't seem to have found a proper solution. My question is: should I only rely on the Shortcodes
, previously put on certain pages, to render the plugin in the front-end? Is this the only way?
I tried to submit a custom action
with the form of my widget (with action get_admin_url().'admin-post.php'
), and hook it in the plugin with:
add_action('admin_post_customaction', 'handle_customaction');
add_action('admin_post_nopriv_customaction', 'handle_customaction');
function (handle_customaction) {
//do something
}
but the page admin-post.php truncates the execution, so I guess this practice is only for executing certain tasks and then redirect, not to display content within a page in the front-end.
Is there a solution beside using Shortcodes? Because then my question would be "which action attribute should I use in the form of the widget?", like how do I know which pages use the Shortcode I need?
Maybe by creating a custom post type
within the plugin? I do not need anything special in the admin section of the website. However, at least there, my plugin is called by WordPress with the link wp-admin/admin.php?page=myplugin
and my main callback is called. But what about the front-end?
Am I missing something? I would like to not rely on the theme's code. Any hints would be much appreciated! Thanks