Pregunta

By default Wordpress assigns the draft status to a post that has been untrashed. I would like to assign the pending status to posts that are untrashed.

This seems to be possible with wp_untrash_post_status, but I can't seem to find the proper way to use it. I have this in my code :

add_action( 'untrash_post', 'my_function' );
function my_function( $post_id ) {
  apply_filters( 'wp_untrash_post_status', 'pending', $post_id, 'pending' );
}

What am I doing wrong ?

¿Fue útil?

Solución

I think for your purpose wp_untrash_post_status filter will be enough. Will work with single and multiple posts restore.

Filters the status that a post gets assigned when it is restored from the trash (untrashed).

add_filter( 'wp_untrash_post_status', 'change_untrash_post_status');

function change_untrash_post_status($status){
    return 'pending';
}

P.S. apply_filtershook is used to call callback functions created by us, like a snippet above, so apply_filters will fire a callback function which we added with add_filter (As I understood wp logic right)

Licenciado bajo: CC-BY-SA con atribución
scroll top