mirror of
https://github.com/WordPress/five-for-the-future.git
synced 2025-07-04 10:05:43 +03:00
Pledges: Move has_existing_pledge
function
This commit is contained in:
parent
0754ae0b28
commit
d9382a975a
2 changed files with 45 additions and 45 deletions
|
@ -260,6 +260,49 @@ function filter_query( $query ) {
|
|||
$query->set( 'posts_per_page', 100 );
|
||||
}
|
||||
|
||||
/**
|
||||
* Check a key value against existing pledges to see if one already exists.
|
||||
*
|
||||
* @param string $key The value to match against other pledges.
|
||||
* @param string $key_type The type of value being matched. `email` or `domain`.
|
||||
* @param int $current_pledge_id Optional. The post ID of the pledge to compare against others.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
function has_existing_pledge( $key, $key_type, int $current_pledge_id = 0 ) {
|
||||
$args = array(
|
||||
'post_type' => CPT_ID,
|
||||
'post_status' => array( 'draft', 'pending', 'publish' ),
|
||||
);
|
||||
|
||||
switch ( $key_type ) {
|
||||
case 'email':
|
||||
$args['meta_query'] = array(
|
||||
array(
|
||||
'key' => META_PREFIX . 'org-pledge-email',
|
||||
'value' => $key,
|
||||
),
|
||||
);
|
||||
break;
|
||||
case 'domain':
|
||||
$args['meta_query'] = array(
|
||||
array(
|
||||
'key' => META_PREFIX . 'org-domain',
|
||||
'value' => $key,
|
||||
),
|
||||
);
|
||||
break;
|
||||
}
|
||||
|
||||
if ( $current_pledge_id ) {
|
||||
$args['exclude'] = array( $current_pledge_id );
|
||||
}
|
||||
|
||||
$matching_pledge = get_posts( $args );
|
||||
|
||||
return ! empty( $matching_pledge );
|
||||
}
|
||||
|
||||
/**
|
||||
* Enqueue assets for front-end management.
|
||||
*
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue