BP_Invitation::get_query_clauses( array $args = array() )

Assemble query clauses, based on arguments, to pass to $wpdb methods.

Description

The insert(), update(), and delete() methods of wpdb expect arguments of the following forms:

  • associative arrays whose key/value pairs are column => value, to be used in WHERE, SET, or VALUES clauses
  • arrays of "formats", which tell $wpdb->prepare() which type of value to expect when sanitizing (eg, array( ‘%s’, ‘%d’ ))

This utility method can be used to assemble both kinds of params, out of a single set of associative array arguments, such as:

$args = array(
    'user_id' => 4,
    'class'   => 'BP_Groups_Invitation_Manager',
);

This will be converted to:

array(
    'data' => array(
        'user_id' => 4,
        'class'   => 'BP_Groups_Invitation_Manager',
    ),
    'format' => array(
        '%d',
        '%s',
    ),
)

which can easily be passed as arguments to the $wpdb methods.

Parameters

$args

(Optional) Associative array of filter arguments. See {@BP_Invitation::get()} for a breakdown.

Default value: array()

Return

(array) Associative array of 'data' and 'format' args.

Source

File: bp-core/classes/class-bp-invitation.php

562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
protected static function get_query_clauses( $args = array() ) {
    $where_clauses = array(
        'data'   => array(),
        'format' => array(),
    );
 
    // id
    if ( ! empty( $args['id'] ) ) {
        $where_clauses['data']['id'] = absint( $args['id'] );
        $where_clauses['format'][] = '%d';
    }
 
    // user_id
    if ( ! empty( $args['user_id'] ) ) {
        $where_clauses['data']['user_id'] = absint( $args['user_id'] );
        $where_clauses['format'][] = '%d';
    }
 
    // inviter_id
    if ( ! empty( $args['inviter_id'] ) ) {
        $where_clauses['data']['inviter_id'] = absint( $args['inviter_id'] );
        $where_clauses['format'][] = '%d';
    }
 
    // invitee_email
    if ( ! empty( $args['invitee_email'] ) ) {
        $where_clauses['data']['invitee_email'] = $args['invitee_email'];
        $where_clauses['format'][] = '%s';
    }
 
    // class
    if ( ! empty( $args['class'] ) ) {
        $where_clauses['data']['class'] = $args['class'];
        $where_clauses['format'][] = '%s';
    }
 
    // item_id
    if ( ! empty( $args['item_id'] ) ) {
        $where_clauses['data']['item_id'] = absint( $args['item_id'] );
        $where_clauses['format'][] = '%d';
    }
 
    // secondary_item_id
    if ( ! empty( $args['secondary_item_id'] ) ) {
        $where_clauses['data']['secondary_item_id'] = absint( $args['secondary_item_id'] );
        $where_clauses['format'][] = '%d';
    }
 
    // type
    if ( ! empty( $args['type'] ) && 'all' !== $args['type'] ) {
        if ( 'invite' == $args['type'] || 'request' == $args['type'] ) {
            $where_clauses['data']['type'] = $args['type'];
            $where_clauses['format'][] = '%s';
        }
    }
 
    /**
     * invite_sent
     * Only create a where statement if something less than "all" has been
     * specifically requested.
     */
    if ( isset( $args['invite_sent'] ) && 'all' !== $args['invite_sent'] ) {
        if ( $args['invite_sent'] == 'draft' ) {
            $where_clauses['data']['invite_sent'] = 0;
            $where_clauses['format'][] = '%d';
        } else if ( $args['invite_sent'] == 'sent' ) {
            $where_clauses['data']['invite_sent'] = 1;
            $where_clauses['format'][] = '%d';
        }
    }
 
    // accepted
    if ( ! empty( $args['accepted'] ) && 'all' !== $args['accepted'] ) {
        if ( $args['accepted'] == 'pending' ) {
            $where_clauses['data']['accepted'] = 0;
            $where_clauses['format'][] = '%d';
        } else if ( $args['accepted'] == 'accepted' ) {
            $where_clauses['data']['accepted'] = 1;
            $where_clauses['format'][] = '%d';
        }
    }
 
    return $where_clauses;
}

Changelog

Changelog
Version Description
BuddyBoss 1.3.5 Introduced.

Questions?

We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.