Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
06/01/2024 10:25:18 PM (2 years ago)
Author:
espellcaste
Message:

WPCS: Part IV: miscellaneous fixes for some of the files of the core component.

Follow-up to [13883], [13886], and [13887]

See #9164 and #7228

File:
1 edited

Legend:

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

    r13395 r13888  
    2525         *
    2626         * @since 5.0.0
    27          * @access public
     27         *
    2828         * @var int
    2929         */
    … …  
    3434         *
    3535         * @since 5.0.0
    36          * @access public
     36         *
    3737         * @var int
    3838         */
    … …  
    4343         *
    4444         * @since 5.0.0
    45          * @access public
     45         *
    4646         * @var int
    4747         */
    … …  
    5353         *
    5454         * @since 5.0.0
    55          * @access public
     55         *
    5656         * @var string
    5757         */
    … …  
    6262         *
    6363         * @since 5.0.0
    64          * @access public
     64         *
    6565         * @var string
    6666         */
    … …  
    7272         *
    7373         * @since 5.0.0
    74          * @access public
     74         *
    7575         * @var int
    7676         */
    … …  
    8282         *
    8383         * @since 5.0.0
    84          * @access public
    85          * @var int
     84         *
     85         * @var int|null
    8686         */
    8787        public $secondary_item_id = null;
    … …  
    9191         *
    9292         * @since 5.0.0
    93          * @access public
     93         *
    9494         * @var string
    9595         */
    … …  
    100100         *
    101101         * @since 5.0.0
    102          * @access public
     102         *
    103103         * @var string
    104104         */
    … …  
    109109         *
    110110         * @since 5.0.0
    111          * @access public
     111         *
    112112         * @var string
    113113         */
    … …  
    118118         *
    119119         * @since 5.0.0
    120          * @access public
     120         *
    121121         * @var bool
    122122         */
    … …  
    127127         *
    128128         * @since 5.0.0
    129          * @access public
     129         *
    130130         * @var bool
    131131         */
    … …  
    136136         *
    137137         * @since 9.0.0
    138          * @access public
     138         *
    139139         * @var array
    140140         */
    … …  
    151151                'date_modified',
    152152                'invite_sent',
    153                 'accepted'
     153                'accepted',
    154154        );
    155155
    … …  
    161161         * @since 5.0.0
    162162         *
    163          * @param int $id Optional. Provide an ID to access an existing
    164          *        invitation item.
     163         * @param int $id Optional. Provide an ID to access an existing invitation item.
    165164         */
    166165        public function __construct( $id = 0 ) {
    … …  
    182181        public function save() {
    183182
    184                 // Return value
     183                // Return value.
    185184                $retval = false;
    186185
    187                 // Default data and format
    188                 $data = array(
     186                // Default data and format.
     187                $data        = array(
    189188                        'user_id'           => $this->user_id,
    190189                        'inviter_id'        => $this->inviter_id,
    … …  
    213212                if ( ! empty( $this->id ) ) {
    214213                        $result = self::_update( $data, array( 'ID' => $this->id ), $data_format, array( '%d' ) );
    215                 // Insert.
     214                        // Insert.
    216215                } else {
    217216                        $result = self::_insert( $data, $data_format );
    … …  
    258257                if ( false === $invitation ) {
    259258                        $invitation = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$invites_table_name} WHERE id = %d", $this->id ) );
    260                         wp_cache_set( $this->id, $invitation,'bp_invitations' );
     259                        wp_cache_set( $this->id, $invitation, 'bp_invitations' );
    261260                }
    262261
    … …  
    278277                $this->invite_sent       = (int) $invitation->invite_sent;
    279278                $this->accepted          = (int) $invitation->accepted;
    280 
    281279        }
    282280
    … …  
    287285         *
    288286         * @since 5.0.0
     287         *
     288         * @global wpdb $wpdb WordPress database object.
    289289         *
    290290         * @param array $data {
    291291         *     Array of invitation data, passed to {@link wpdb::insert()}.
    292          *         @type int    $user_id           ID of the invited user.
    293          *         @type int    $inviter_id        ID of the user who created the invitation.
    294          *         @type string $invitee_email     Email address of the invited user.
    295          *         @type string $class             Name of the related class.
    296          *         @type int    $item_id           ID associated with the invitation and component.
    297          *         @type int    $secondary_item_id Secondary ID associated with the invitation and
     292         *     @type int    $user_id           ID of the invited user.
     293         *     @type int    $inviter_id        ID of the user who created the invitation.
     294         *     @type string $invitee_email     Email address of the invited user.
     295         *     @type string $class             Name of the related class.
     296         *     @type int    $item_id           ID associated with the invitation and component.
     297         *     @type int    $secondary_item_id Secondary ID associated with the invitation and
    298298         *                                     component.
    299          *         @type string $content           Extra information provided by the requester
    300          *                                                 or inviter.
    301          *         @type string $date_modified     Date the invitation was last modified.
    302          *         @type int    $invite_sent       Has the invitation been sent, or is it a draft
     299         *     @type string $content           Extra information provided by the requester
     300         *                                     or inviter.
     301         *     @type string $date_modified     Date the invitation was last modified.
     302         *     @type int    $invite_sent       Has the invitation been sent, or is it a draft
    303303         *                                     invite?
    304304         * }
    … …  
    315315         *
    316316         * @since 5.0.0
     317         *
     318         * @global wpdb $wpdb WordPress database object.
    317319         *
    318320         * @see wpdb::update() for further description of paramater formats.
    … …  
    338340         * @since 5.0.0
    339341         *
     342         * @global wpdb $wpdb WordPress database object.
     343         *
    340344         * @see wpdb::update() for further description of paramater formats.
    341345         *
    … …  
    359363         * @since 5.0.0
    360364         *
     365         * @global wpdb $wpdb WordPress database object.
     366         *
    361367         * @param array $args See {@link BP_Invitation::get()} for more details.
    362368         * @return string WHERE clause.
    … …  
    370376                // id.
    371377                if ( false !== $args['id'] ) {
    372                         $id_in = implode( ',', wp_parse_id_list( $args['id'] ) );
     378                        $id_in                  = implode( ',', wp_parse_id_list( $args['id'] ) );
    373379                        $where_conditions['id'] = "id IN ({$id_in})";
    374380                }
    … …  
    376382                // user_id.
    377383                if ( ! empty( $args['user_id'] ) ) {
    378                         $user_id_in = implode( ',', wp_parse_id_list( $args['user_id'] ) );
     384                        $user_id_in                  = implode( ',', wp_parse_id_list( $args['user_id'] ) );
    379385                        $where_conditions['user_id'] = "user_id IN ({$user_id_in})";
    380386                }
    … …  
    382388                // inviter_id. 0 can be meaningful, in the case of requests.
    383389                if ( ! empty( $args['inviter_id'] ) || 0 === $args['inviter_id'] ) {
    384                         $inviter_id_in = implode( ',', wp_parse_id_list( $args['inviter_id'] ) );
     390                        $inviter_id_in                  = implode( ',', wp_parse_id_list( $args['inviter_id'] ) );
    385391                        $where_conditions['inviter_id'] = "inviter_id IN ({$inviter_id_in})";
    386392                }
    … …  
    399405                        }
    400406
    401                         $invitee_email_in = implode( ',', $email_clean );
     407                        $invitee_email_in                  = implode( ',', $email_clean );
    402408                        $where_conditions['invitee_email'] = "invitee_email IN ({$invitee_email_in})";
    403409                }
    … …  
    416422                        }
    417423
    418                         $cn_in = implode( ',', $cn_clean );
     424                        $cn_in                     = implode( ',', $cn_clean );
    419425                        $where_conditions['class'] = "class IN ({$cn_in})";
    420426                }
    … …  
    422428                // item_id.
    423429                if ( ! empty( $args['item_id'] ) ) {
    424                         $item_id_in = implode( ',', wp_parse_id_list( $args['item_id'] ) );
     430                        $item_id_in                  = implode( ',', wp_parse_id_list( $args['item_id'] ) );
    425431                        $where_conditions['item_id'] = "item_id IN ({$item_id_in})";
    426432                }
    … …  
    428434                // secondary_item_id.
    429435                if ( ! empty( $args['secondary_item_id'] ) ) {
    430                         $secondary_item_id_in = implode( ',', wp_parse_id_list( $args['secondary_item_id'] ) );
     436                        $secondary_item_id_in                  = implode( ',', wp_parse_id_list( $args['secondary_item_id'] ) );
    431437                        $where_conditions['secondary_item_id'] = "secondary_item_id IN ({$secondary_item_id_in})";
    432438                }
    … …  
    434440                // Type.
    435441                if ( ! empty( $args['type'] ) && 'all' !== $args['type'] ) {
    436                         if ( 'invite' == $args['type'] || 'request' == $args['type'] ) {
    437                                 $type_clean = $wpdb->prepare( '%s', $args['type'] );
     442                        if ( 'invite' === $args['type'] || 'request' === $args['type'] ) {
     443                                $type_clean               = $wpdb->prepare( '%s', $args['type'] );
    438444                                $where_conditions['type'] = "type = {$type_clean}";
    439445                        }
    … …  
    441447
    442448                /**
    443                  * invite_sent
    444449                 * Only create a where statement if something less than "all" has been
    445450                 * specifically requested.
    446451                 */
    447452                if ( ! empty( $args['invite_sent'] ) && 'all' !== $args['invite_sent'] ) {
    448                         if ( $args['invite_sent'] == 'draft' ) {
    449                                 $where_conditions['invite_sent'] = "invite_sent = 0";
    450                         } else if ( $args['invite_sent'] == 'sent' ) {
    451                                 $where_conditions['invite_sent'] = "invite_sent = 1";
     453                        if ( $args['invite_sent'] === 'draft' ) {
     454                                $where_conditions['invite_sent'] = 'invite_sent = 0';
     455                        } elseif ( $args['invite_sent'] === 'sent' ) {
     456                                $where_conditions['invite_sent'] = 'invite_sent = 1';
    452457                        }
    453458                }
    … …  
    455460                // Accepted.
    456461                if ( ! empty( $args['accepted'] ) && 'all' !== $args['accepted'] ) {
    457                         if ( $args['accepted'] == 'pending' ) {
    458                                 $where_conditions['accepted'] = "accepted = 0";
    459                         } else if ( $args['accepted'] == 'accepted' ) {
    460                                 $where_conditions['accepted'] = "accepted = 1";
     462                        if ( $args['accepted'] === 'pending' ) {
     463                                $where_conditions['accepted'] = 'accepted = 0';
     464                        } elseif ( $args['accepted'] === 'accepted' ) {
     465                                $where_conditions['accepted'] = 'accepted = 1';
    461466                        }
    462467                }
    … …  
    464469                // search_terms.
    465470                if ( ! empty( $args['search_terms'] ) ) {
    466                         $search_terms_like = '%' . bp_esc_like( $args['search_terms'] ) . '%';
     471                        $search_terms_like                = '%' . bp_esc_like( $args['search_terms'] ) . '%';
    467472                        $where_conditions['search_terms'] = $wpdb->prepare( '( invitee_email LIKE %s OR content LIKE %s )', $search_terms_like, $search_terms_like );
    468473                }
    … …  
    539544                // Custom LIMIT.
    540545                if ( ! empty( $args['page'] ) && ! empty( $args['per_page'] ) ) {
    541                         $page     = absint( $args['page']     );
     546                        $page     = absint( $args['page'] );
    542547                        $per_page = absint( $args['per_page'] );
    543548                        $offset   = $per_page * ( $page - 1 );
    544                         $retval   = $wpdb->prepare( "LIMIT %d, %d", $offset, $per_page );
     549                        $retval   = $wpdb->prepare( 'LIMIT %d, %d', $offset, $per_page );
    545550                }
    546551
    … …  
    597602                if ( ! empty( $args['id'] ) ) {
    598603                        $where_clauses['data']['id'] = absint( $args['id'] );
    599                         $where_clauses['format'][] = '%d';
     604                        $where_clauses['format'][]   = '%d';
    600605                }
    601606
    … …  
    603608                if ( ! empty( $args['user_id'] ) ) {
    604609                        $where_clauses['data']['user_id'] = absint( $args['user_id'] );
    605                         $where_clauses['format'][] = '%d';
     610                        $where_clauses['format'][]        = '%d';
    606611                }
    607612
    … …  
    609614                if ( ! empty( $args['inviter_id'] ) ) {
    610615                        $where_clauses['data']['inviter_id'] = absint( $args['inviter_id'] );
    611                         $where_clauses['format'][] = '%d';
     616                        $where_clauses['format'][]           = '%d';
    612617                }
    613618
    … …  
    615620                if ( ! empty( $args['invitee_email'] ) ) {
    616621                        $where_clauses['data']['invitee_email'] = $args['invitee_email'];
    617                         $where_clauses['format'][] = '%s';
     622                        $where_clauses['format'][]              = '%s';
    618623                }
    619624
    … …  
    621626                if ( ! empty( $args['class'] ) ) {
    622627                        $where_clauses['data']['class'] = $args['class'];
    623                         $where_clauses['format'][] = '%s';
     628                        $where_clauses['format'][]      = '%s';
    624629                }
    625630
    … …  
    627632                if ( ! empty( $args['item_id'] ) ) {
    628633                        $where_clauses['data']['item_id'] = absint( $args['item_id'] );
    629                         $where_clauses['format'][] = '%d';
     634                        $where_clauses['format'][]        = '%d';
    630635                }
    631636
    … …  
    633638                if ( ! empty( $args['secondary_item_id'] ) ) {
    634639                        $where_clauses['data']['secondary_item_id'] = absint( $args['secondary_item_id'] );
    635                         $where_clauses['format'][] = '%d';
     640                        $where_clauses['format'][]                  = '%d';
    636641                }
    637642
    638643                // type.
    639644                if ( ! empty( $args['type'] ) && 'all' !== $args['type'] ) {
    640                         if ( 'invite' == $args['type'] || 'request' == $args['type'] ) {
     645                        if ( 'invite' === $args['type'] || 'request' === $args['type'] ) {
    641646                                $where_clauses['data']['type'] = $args['type'];
    642                                 $where_clauses['format'][] = '%s';
     647                                $where_clauses['format'][]     = '%s';
    643648                        }
    644649                }
    645650
    646651                /**
    647                  * invite_sent
    648652                 * Only create a where statement if something less than "all" has been
    649653                 * specifically requested.
    650654                 */
    651655                if ( isset( $args['invite_sent'] ) && 'all' !== $args['invite_sent'] ) {
    652                         if ( $args['invite_sent'] == 'draft' ) {
     656                        if ( $args['invite_sent'] === 'draft' ) {
    653657                                $where_clauses['data']['invite_sent'] = 0;
    654                                 $where_clauses['format'][] = '%d';
    655                         } else if ( $args['invite_sent'] == 'sent' ) {
     658                                $where_clauses['format'][]            = '%d';
     659                        } elseif ( $args['invite_sent'] === 'sent' ) {
    656660                                $where_clauses['data']['invite_sent'] = 1;
    657                                 $where_clauses['format'][] = '%d';
     661                                $where_clauses['format'][]            = '%d';
    658662                        }
    659663                }
    … …  
    661665                // accepted.
    662666                if ( ! empty( $args['accepted'] ) && 'all' !== $args['accepted'] ) {
    663                         if ( $args['accepted'] == 'pending' ) {
     667                        if ( $args['accepted'] === 'pending' ) {
    664668                                $where_clauses['data']['accepted'] = 0;
    665                                 $where_clauses['format'][] = '%d';
    666                         } else if ( $args['accepted'] == 'accepted' ) {
     669                                $where_clauses['format'][]         = '%d';
     670                        } elseif ( $args['accepted'] === 'accepted' ) {
    667671                                $where_clauses['data']['accepted'] = 1;
    668                                 $where_clauses['format'][] = '%d';
    669                         }
    670                 }
    671 
    672                 // date_modified
     672                                $where_clauses['format'][]         = '%d';
     673                        }
     674                }
     675
     676                // date_modified.
    673677                if ( ! empty( $args['date_modified'] ) ) {
    674678                        $where_clauses['data']['date_modified'] = $args['date_modified'];
    675                         $where_clauses['format'][] = '%s';
     679                        $where_clauses['format'][]              = '%s';
    676680                }
    677681
    … …  
    685689         *
    686690         * @since 5.0.0
     691         *
     692         * @global wpdb $wpdb WordPress database object.
    687693         *
    688694         * @param array $args {
    … …  
    697703         *                                           invitation. Can be an array of IDs.
    698704         *     @type string|array $invitee_email     Email address of invited users
    699          *                                                       being queried. Can be an array of
     705         *                                           being queried. Can be an array of
    700706         *                                           addresses.
    701707         *     @type string|array $class             Name of the class to filter by.
    … …  
    735741         * }
    736742         *
    737          * @return array BP_Invitation objects | IDs of found invite.
     743         * @return int[]|BP_Invitation[] BP_Invitation objects | IDs of found invite.
    738744         */
    739745        public static function get( $args = array() ) {
    … …  
    766772
    767773                $sql = array(
    768                         'select'     => "SELECT",
     774                        'select'     => 'SELECT',
    769775                        'fields'     => '',
    770776                        'from'       => "FROM {$invites_table_name} i",
    … …  
    775781
    776782                if ( 'item_ids' === $r['fields'] ) {
    777                         $sql['fields'] = "DISTINCT i.item_id";
    778                 } else if ( 'user_ids' === $r['fields'] ) {
    779                         $sql['fields'] = "DISTINCT i.user_id";
    780                 } else if ( 'inviter_ids' === $r['fields'] ) {
    781                         $sql['fields'] = "DISTINCT i.inviter_id";
     783                        $sql['fields'] = 'DISTINCT i.item_id';
     784                } elseif ( 'user_ids' === $r['fields'] ) {
     785                        $sql['fields'] = 'DISTINCT i.user_id';
     786                } elseif ( 'inviter_ids' === $r['fields'] ) {
     787                        $sql['fields'] = 'DISTINCT i.inviter_id';
    782788                } else {
    783789                        $sql['fields'] = 'DISTINCT i.id';
    … …  
    785791
    786792                // WHERE.
    787                 $sql['where'] = self::get_where_sql( array(
    788                         'id'                => $r['id'],
    789                         'user_id'           => $r['user_id'],
    790                         'inviter_id'            => $r['inviter_id'],
    791                         'invitee_email'     => $r['invitee_email'],
    792                         'class'             => $r['class'],
    793                         'item_id'           => $r['item_id'],
    794                         'secondary_item_id' => $r['secondary_item_id'],
    795                         'type'              => $r['type'],
    796                         'invite_sent'       => $r['invite_sent'],
    797                         'accepted'          => $r['accepted'],
    798                         'search_terms'      => $r['search_terms'],
    799                 ) );
     793                $sql['where'] = self::get_where_sql(
     794                        array(
     795                                'id'                => $r['id'],
     796                                'user_id'           => $r['user_id'],
     797                                'inviter_id'        => $r['inviter_id'],
     798                                'invitee_email'     => $r['invitee_email'],
     799                                'class'             => $r['class'],
     800                                'item_id'           => $r['item_id'],
     801                                'secondary_item_id' => $r['secondary_item_id'],
     802                                'type'              => $r['type'],
     803                                'invite_sent'       => $r['invite_sent'],
     804                                'accepted'          => $r['accepted'],
     805                                'search_terms'      => $r['search_terms'],
     806                        )
     807                );
    800808
    801809                // ORDER BY.
    802                 $sql['orderby'] = self::get_order_by_sql( array(
    803                         'order_by'   => $r['order_by'],
    804                         'sort_order' => $r['sort_order']
    805                 ) );
     810                $sql['orderby'] = self::get_order_by_sql(
     811                        array(
     812                                'order_by'   => $r['order_by'],
     813                                'sort_order' => $r['sort_order'],
     814                        )
     815                );
    806816
    807817                // LIMIT %d, %d.
    808                 $sql['pagination'] = self::get_paged_sql( array(
    809                         'page'     => $r['page'],
    810                         'per_page' => $r['per_page'],
    811                 ) );
     818                $sql['pagination'] = self::get_paged_sql(
     819                        array(
     820                                'page'     => $r['page'],
     821                                'per_page' => $r['per_page'],
     822                        )
     823                );
    812824
    813825                $paged_invites_sql = "{$sql['select']} {$sql['fields']} {$sql['from']} {$sql['where']} {$sql['orderby']} {$sql['pagination']}";
    … …  
    840852                $uncached_ids = bp_get_non_cached_ids( $paged_invite_ids, 'bp_invitations' );
    841853                if ( $uncached_ids ) {
    842                         $ids_sql = implode( ',', array_map( 'intval', $uncached_ids ) );
     854                        $ids_sql      = implode( ',', array_map( 'intval', $uncached_ids ) );
    843855                        $data_objects = $wpdb->get_results( "SELECT i.* FROM {$invites_table_name} i WHERE i.id IN ({$ids_sql})" );
    844856                        foreach ( $data_objects as $data_object ) {
    … …  
    859871         *
    860872         * @since 5.0.0
     873         *
     874         * @global wpdb $wpdb WordPress database object.
    861875         *
    862876         * @see BP_Invitation::get() for a description of
    … …  
    893907                );
    894908
    895                 // Build the query
    896                 $select_sql = "SELECT COUNT(*)";
     909                // Build the query.
     910                $select_sql = 'SELECT COUNT(*)';
    897911                $from_sql   = "FROM {$invites_table_name}";
    898912                $where_sql  = self::get_where_sql( $r );
    899913                $sql        = "{$select_sql} {$from_sql} {$where_sql}";
    900914
    901                 // Return the queried results
     915                // Return the queried results.
    902916                return $wpdb->get_var( $sql );
    903917        }
    … …  
    921935        public static function update( $update_args = array(), $where_args = array() ) {
    922936                $update = self::get_query_clauses( $update_args );
    923                 $where  = self::get_query_clauses( $where_args  );
     937                $where  = self::get_query_clauses( $where_args );
    924938
    925939                /**
    … …  
    937951
    938952                // Clear matching items from the cache.
    939                 $cache_args = $where_args;
     953                $cache_args           = $where_args;
    940954                $cache_args['fields'] = 'ids';
    941                 $maybe_cached_ids = self::get( $cache_args );
     955                $maybe_cached_ids     = self::get( $cache_args );
    942956                foreach ( $maybe_cached_ids as $invite_id ) {
    943957                        wp_cache_delete( $invite_id, 'bp_invitations' );
    … …  
    984998
    985999                // Clear matching items from the cache.
    986                 $cache_args = $args;
     1000                $cache_args           = $args;
    9871001                $cache_args['fields'] = 'ids';
    988                 $maybe_cached_ids = self::get( $cache_args );
     1002                $maybe_cached_ids     = self::get( $cache_args );
    9891003                foreach ( $maybe_cached_ids as $invite_id ) {
    9901004                        wp_cache_delete( $invite_id, 'bp_invitations' );
    … …  
    10161030         *
    10171031         * @param int $id ID of the invitation item to be deleted.
    1018          * @return bool True on success, false on failure.
     1032         * @return bool|int Number of rows deleted on success, false on failure.
    10191033         */
    10201034        public static function delete_by_id( $id ) {
    1021                 return self::delete( array(
    1022                         'id' => $id,
    1023                 ) );
     1035                return self::delete( array( 'id' => $id ) );
    10241036        }
    10251037
    … …  
    11531165                return self::update( $update_args, $args );
    11541166        }
    1155 
    11561167}
Note: See TracChangeset for help on using the changeset viewer.