Created
July 10, 2013 15:15
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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