Hi Shane,
Probably I haven’t been clear. Let me recap with some illustrations. Let’s start from scratch. 🙂
See Figure 1. Author logs-in (Figure 1a) and accesses My Account (Figure 1b). Author clicks on the Submit Manuscript link and accesses Draft Manuscript (Figure 1c), where he can create a custom type post called Manuscript, from the front-end. On the bottom of Figure 1c there is a 'Submit Draft' button. This saves Manuscript as a draft (as specified in the form settings in Toolset in Figure 1d) and works fine.
See Figure 2. After clicking on Submit Manuscript, Author is redirected to My Account page (Figure 2a). Here Author can see a list of his Manuscripts and their statuses. This works fine. When author clicks on Edit, the manuscript Edit Form is loaded and the Author can modify Manuscript (Figure 2b).
Author has now two options: ‘Save Draft’ or ‘Submit Manuscript’. ‘Save Draft’ simply saves Manuscript as it is. We want that when Author clicks on the other button ‘Submit Manuscript’ and the checkbox submit_validation is selected (==1), the Manuscript changes from 'draft' to ‘submitted’ (which is a custom status as defined with the plugin ‘Oasis Workflow’, see Figure 2c).
The section in the ‘Edit Post Form cell’ that implements the buttons and the checkbox is:
[cred_generic_field field='submit_validation' type='checkbox' class='' urlparam='']
{
"required":0,
"validate_format":0,
"checked":0,
"default":"1",
"label":"submit_validation"
}
[/cred_generic_field]
[cred_field field='form_submit' value='Submit Manuscript' urlparam='' class='btn btn-primary btn-lg' output='bootstrap']
So, I created a dummy plugin in WordPress. The php code of plugin_name.php is the following:
if (! defined('ABSPATH')){
exit;
}
//[submit_manuscript]
function submit_manuscript_func( $atts ){
submit_man($atts);
}
add_shortcode( 'submit_manuscript', 'submit_manuscript_func' );
function submit_man($atts ){
$my_post = array(
'ID' => get_the_ID(),
'post_status' => 'submitted');
wp_update_post($my_post);
}
See Figure 3. If I include the shortcode [submit_manuscript] anywhere in the Manuscript fields (from the Admin back-end) and I load the Manuscript page, this will change the status from ‘draft’ to ‘submitted’. So, the shortcode is working fine.
However I would like to trigger the shortcode when the button 'Submit Manuscript' is pressed (with the conditions that the checkbox must be checked) . In pseudo-code it should be something like:
if ((submit manuscript button is clicked) && (submit_validation checkbox == 1) {
do shortcode [submit_manuscript];
redirect to My-account page;
}
How can I do this?