Created
June 5, 2019 20:49
-
-
Save jom/1d0b8674273289619773cbe32b8dd53c to your computer and use it in GitHub Desktop.
Limit Job Listings to One Per User
This file contains 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
add_filter( 'submit_job_steps', function( $steps ) { | |
$user = get_current_user_id(); | |
if ( ! $user || current_user_can( 'manage_options' ) ) { | |
return $steps; | |
} | |
$user_post_count = count( get_posts( [ | |
'author' => $user, | |
'post_type' => 'job_listing', | |
'post_status' => [ 'publish', 'pending' ] | |
] ) ); | |
if ( $user_post_count > 0 ) { | |
$steps = [ | |
'warning' => [ | |
'view' => function() { | |
echo __( 'Sorry, you can only post one job listing at a time.', 'wp-job-manager' ); | |
} | |
] | |
]; | |
} | |
return $steps; | |
} ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment