Skip to:
Content

BuddyPress.org

Changeset 12915


Ignore:
Timestamp:
04/28/2021 11:49:50 PM (6 months ago)
Author:
dcavins
Message:

BP_Invitation_Manager: Functionality improvements.

Introduce convenience methods delete_by_id() and
get_invitations_total_count(). Also add support for
id as a parameter in accept_invitation().

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-core/classes/class-bp-invitation-manager.php

    r12914 r12915  
    389389
    390390    /**
     391     * Get a count of the number of invitations that match provided filter parameters.
     392     *
     393     * @since 8.0.0
     394     *
     395     * @see BP_Invitation::get_total_count() for a description of accepted parameters.
     396     *
     397     * @return int Total number of invitations.
     398     */
     399    public function get_invitations_total_count( $args = array() ) {
     400        // Default to returning invitations, not requests.
     401        if ( empty( $args['type'] ) ) {
     402            $args['type'] = 'invite';
     403        }
     404        // Use the class_name property value.
     405        $args['class'] = $this->class_name;
     406
     407        return BP_Invitation::get_total_count( $args );
     408    }
     409
     410    /**
    391411     * Get requests, based on provided filter parameters.
    392412     *
     
    480500
    481501        $r = bp_parse_args( $args, array(
     502            'id'                => false,
    482503            'user_id'           => 0,
    483504            'invitee_email'     => '',
     
    489510        $r['class'] = $this->class_name;
    490511
    491         if ( ! ( ( $r['user_id'] || $r['invitee_email'] ) && $r['class'] && $r['item_id'] ) ) {
     512        if ( ! $r['id'] && ! ( ( $r['user_id'] || $r['invitee_email'] ) && $r['class'] && $r['item_id'] ) ) {
    492513            return false;
    493514        }
     
    709730
    710731    /**
     732     * Delete an invitation by id.
     733     *
     734     * @since 8.0.0
     735     *
     736     * @param int $id ID of the invitation to delete.
     737     * @return int|bool Number of rows deleted on success, false on failure.
     738     */
     739    public function delete_by_id( $id ) {
     740        // Ensure that the invitation exists and was created by this class.
     741        $invite = new BP_Invitation( $id );
     742        if ( ! $invite->id || sanitize_key( $this->class_name ) !== $invite->class ) {
     743            return false;
     744        }
     745
     746        return BP_Invitation::delete_by_id( $id );
     747    }
     748
     749    /**
    711750     * This is where custom actions are added (in child classes)
    712751     * to determine whether an invitation should be allowed.
Note: See TracChangeset for help on using the changeset viewer.