Skip to content

Instantly share code, notes, and snippets.

@jom
Created June 5, 2019 20:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jom/1d0b8674273289619773cbe32b8dd53c to your computer and use it in GitHub Desktop.
Save jom/1d0b8674273289619773cbe32b8dd53c to your computer and use it in GitHub Desktop.
Limit Job Listings to One Per User
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