Skip to content

Instantly share code, notes, and snippets.

@tharlab
Forked from hivepress/functions.php
Created December 14, 2023 02:37
Show Gist options
  • Save tharlab/85f6982fffe2110e9a6c662625672b8f to your computer and use it in GitHub Desktop.
Save tharlab/85f6982fffe2110e9a6c662625672b8f to your computer and use it in GitHub Desktop.
Limit the maximum number of listings per user account #hivepress #listings
<?php
add_filter(
'hivepress/v1/forms/listing_submit/errors',
function( $errors, $form ) {
$listing = $form->get_model();
if ( $listing && $listing->get_user__id() ) {
$listing_count = \HivePress\Models\Listing::query()->filter(
[
'status__in' => [ 'publish', 'pending', 'draft' ],
'user' => $listing->get_user__id(),
]
)->get_count();
if ( $listing_count >= 123 ) {
$errors[] = 'Only 123 listings per account are allowed.';
}
}
return $errors;
},
1000,
2
);
@tharlab
Copy link
Author

tharlab commented Dec 14, 2023

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment