Skip to content

Instantly share code, notes, and snippets.

@tareq1988
Created July 10, 2013 15:15
Show Gist options
  • Save tareq1988/5967163 to your computer and use it in GitHub Desktop.
Save tareq1988/5967163 to your computer and use it in GitHub Desktop.
I have a user level in a site. It allows people to post to two Custom Post Types (say Type A and Type B). I need to allow users to be able to Publish to Post Type A but only save drafts to Post Type B.
<?php
add_action( 'save_post', function( $post_id ) {
if ( !wp_is_post_revision( $post_id ) ) {
$post_type = get_post_type( $post_id );
// apply on specific post type and for specific user role
if ( $post_type == 'product' && current_user_can( 'subscriber' ) ) {
wp_update_post( array(
'ID' => $post_id,
'post_status' => 'draft'
) );
}
}
} );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment