The reason your code does not work is that the if
-statement checking isset( $_POST['wp_cfc_save_meta_box'])
never evaluates to true. Your code generating the submit button,
<?php submit_button( __( 'Save as Pending' ), 'secondary button-large', 'Publish', false ); ?>
yields the following HTML:
<input type="submit" name="Publish" id="Publish" class="button button-large" value="Save as Pending" />
WordPress’ submit_button
function takes several arguments, the third of which is $name
. This is used as the HTML name
attribute of the submit button input element, and is passed in the $POST
array on submission of the form. Thus, instead of the desired $_POST['wp_cfc_save_meta_box']
, $_POST['Publish']
becomes set. To tackle the problem, change the $name$
parameter to 'wp_cfc_save_meta_box'
. This yields
<?php submit_button( __( 'Save as Pending' ), 'secondary button-large', 'wp_cfc_save_meta_box', false ); ?>
By the way…
You could make this a little bit prettier and utilize the post_submitbox_misc_actions
action to add the button to the original Publish met box instead of a custom meta box.