6

I want to add custom button "Send for correction" somewhere near the "Publish" button. This custom button must change a post status from "Pending" to my own created status named "On correction".

For a now it is possible to change status with 5 clicks (Edit status -> Dropdown click -> Select On-correction -> Ok -> Save as on correction).

UPDATE:

add_action('post_submitbox_misc_actions', 'send_for_correction_button');
function send_for_correction_button()
{
    //global $post;
    echo '<div id="send-for-correction" class="misc-pub-section"
    style="border-top-style:solid; border-top-width:1px; border-top-color:#EEEEEE; border-bottom-width:0px;">
    <input id="save-post2" class="button button-highlighted"
    type="submit" value="Send for correction" name="save">
        </div>';
}
add_action('save_post', 'save_status');
function save_status($post_id)
{
    if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE)
        return $post_id;

    if ($_POST['save'] == 'Send for correction')
    {
        update_post_meta($post_id, "post_status", 'on-correction');
    }
}
5

You can create your custom button in a function and hook it into post_submitbox_misc_actions and this will add it right above the publish button.

To change the status use wp_update_post in an Ajax function. Give it a try and post back with your code if you run into any problems.

UPDATE:

add_action('post_submitbox_misc_actions', 'send_for_correction_button');
function send_for_correction_button()
{
    //global $post;
    echo '<div id="send-for-correction" class="misc-pub-section"
    style="border-top-style:solid; border-top-width:1px; border-top-color:#EEEEEE; border-bottom-width:0px;">
    <input id="save-post2" class="button button-highlighted"
    type="submit" value="Send for correction" name="save">
        </div>';
}
add_filter( 'wp_insert_post_data' , 'my_filter_handler' , '99', 2 );
function my_filter_handler( $data , $postarr )
{
    if ($postarr['save'] == 'Send for correction')
        $data['post_status'] = 'on-correction';

    return $data;
}
  • Thank you Chris for help! I modify your answer with corrected code. I've used filter wp_insert_post_data. – Bubka Gob May 29 '12 at 6:57
  • Very nice that you got it to work. When you click the button does the page refresh? – Chris_O May 29 '12 at 9:30
  • Yep. This button is just a copy of a "Save" button and do the same things, it save changes but updates post_status too.. – Bubka Gob May 29 '12 at 10:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.