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-optout.php

    r13395 r13888  
    2525     *
    2626     * @since 8.0.0
    27      * @access public
     27     *
    2828     * @var int
    2929     */
     
    3535     *
    3636     * @since 8.0.0
    37      * @access public
     37     *
    3838     * @var string
    3939     */
     
    4444     *
    4545     * @since 8.0.0
    46      * @access public
     46     *
    4747     * @var int
    4848     */
     
    5454     *
    5555     * @since 8.0.0
    56      * @access public
     56     *
    5757     * @var string
    5858     */
     
    6363     *
    6464     * @since 8.0.0
    65      * @access public
     65     *
    6666     * @var string
    6767     */
     
    7575     * @since 8.0.0
    7676     *
    77      * @param int $id Optional. Provide an ID to access an existing
    78      *        optout item.
     77     * @param int $id Optional. Provide an ID to access an existing optout item.
    7978     */
    8079    public function __construct( $id = 0 ) {
     
    8988     *
    9089     * @since 8.0.0
    91      * @access public
     90     *
    9291     * @return string
    9392     */
     
    103102     * @global wpdb $wpdb WordPress database object.
    104103     *
    105      * @return bool True on success, false on failure.
     104     * @return bool
    106105     */
    107106    public function save() {
    108107
    109         // Return value
     108        // Return value.
    110109        $retval = false;
    111110
    112         // Default data and format
    113         $data = array(
     111        // Default data and format.
     112        $data        = array(
    114113            'email_address_hash' => $this->email_address,
    115114            'user_id'            => $this->user_id,
     
    131130        if ( ! empty( $this->id ) ) {
    132131            $result = self::_update( $data, array( 'ID' => $this->id ), $data_format, array( '%d' ) );
    133         // Insert.
     132            // Insert.
    134133        } else {
    135134            $result = self::_insert( $data, $data_format );
     
    151150         * @since 8.0.0
    152151         *
    153          * @param BP_optout object $this Characteristics of the opt-out just saved.
     152         * @param BP_optout $bp_optout Characteristics of the opt-out just saved.
    154153         */
    155154        do_action_ref_array( 'bp_optout_after_save', array( &$this ) );
     
    189188        $this->email_type    = sanitize_key( $optout->email_type );
    190189        $this->date_modified = $optout->date_modified;
    191 
    192190    }
    193191
     
    198196     *
    199197     * @since 8.0.0
     198     *
     199     * @global wpdb $wpdb WordPress database object.
    200200     *
    201201     * @param array $data {
    202202     *     Array of optout data, passed to {@link wpdb::insert()}.
    203      *     @type string $email_address     The hashed email address of the user that wishes to opt out of
     203     *     @type string $email_address     The hashed email address of the user that wishes to opt out of
    204204     *                                     communications from this site.
    205      *     @type int    $user_id           The ID of the user that generated the contact that resulted in the opt-out.
    206      *     @type string $email_type        The type of email contact that resulted in the opt-out.
    207      *     @type string $date_modified     Date the opt-out was last modified.
     205     *     @type int    $user_id           The ID of the user that generated the contact that resulted in the opt-out.
     206     *     @type string $email_type        The type of email contact that resulted in the opt-out.
     207     *     @type string $date_modified     Date the opt-out was last modified.
    208208     * }
    209209     * @param array $data_format See {@link wpdb::insert()}.
     
    212212    protected static function _insert( $data = array(), $data_format = array() ) {
    213213        global $wpdb;
     214
    214215        // We must lowercase and hash the email address at insert.
    215216        $email                      = strtolower( $data['email_address_hash'] );
    216217        $data['email_address_hash'] = wp_hash( $email );
    217         return $wpdb->insert( BP_Optout::get_table_name(), $data, $data_format );
     218        return $wpdb->insert( self::get_table_name(), $data, $data_format );
    218219    }
    219220
     
    222223     *
    223224     * @since 8.0.0
     225     *
     226     * @global wpdb $wpdb WordPress database object.
    224227     *
    225228     * @see wpdb::update() for further description of paramater formats.
     
    244247        }
    245248
    246         return $wpdb->update( BP_Optout::get_table_name(), $data, $where, $data_format, $where_format );
     249        return $wpdb->update( self::get_table_name(), $data, $where, $data_format, $where_format );
    247250    }
    248251
     
    251254     *
    252255     * @since 8.0.0
     256     *
     257     * @global wpdb $wpdb WordPress database object.
    253258     *
    254259     * @see wpdb::update() for further description of paramater formats.
     
    262267    protected static function _delete( $where = array(), $where_format = array() ) {
    263268        global $wpdb;
    264         return $wpdb->delete( BP_Optout::get_table_name(), $where, $where_format );
     269        return $wpdb->delete( self::get_table_name(), $where, $where_format );
    265270    }
    266271
     
    272277     *
    273278     * @since 8.0.0
     279     *
     280     * @global wpdb $wpdb WordPress database object.
    274281     *
    275282     * @param array $args See {@link BP_optout::get()} for more details.
     
    358365     */
    359366    protected static function get_order_by_sql( $args = array() ) {
    360 
    361367        $conditions = array();
    362368        $retval     = '';
     
    398404     * @since 8.0.0
    399405     *
     406     * @global wpdb $wpdb WordPress database object.
     407     *
    400408     * @param array $args See {@link BP_optout::get()} for more details.
    401409     * @return string LIMIT clause.
     
    409417        // Custom LIMIT.
    410418        if ( ! empty( $args['page'] ) && ! empty( $args['per_page'] ) ) {
    411             $page     = absint( $args['page']     );
     419            $page     = absint( $args['page'] );
    412420            $per_page = absint( $args['per_page'] );
    413421            $offset   = $per_page * ( $page - 1 );
    414             $retval   = $wpdb->prepare( "LIMIT %d, %d", $offset, $per_page );
     422            $retval   = $wpdb->prepare( 'LIMIT %d, %d', $offset, $per_page );
    415423        }
    416424
     
    498506     * @since 8.0.0
    499507     *
     508     * @global wpdb $wpdb WordPress database object.
     509     *
    500510     * @param array $args {
    501511     *     Associative array of arguments. All arguments but $page and
     
    505515     *                                           Can be an array of IDs.
    506516     *     @type string|array $email_address     Email address of users who have opted out
    507      *                                           being queried. Can be an array of addresses.
     517     *                                           being queried. Can be an array of addresses.
    508518     *     @type int|array    $user_id           ID of user whose communication prompted the
    509519     *                                           opt-out. Can be an array of IDs.
     
    519529     *                                           Default: false (no pagination,
    520530     *                                           all items).
    521      *     @type string       $fields            Which fields to return. Specify 'email_addresses' to
    522      *                                           fetch a list of opt-out email_addresses.
    523      *                                           Specify 'user_ids' to
    524      *                                           fetch a list of opt-out user_ids.
    525      *                                           Specify 'ids' to fetch a list of opt-out IDs.
    526      *                                           Default: 'all' (return BP_Optout objects).
     531     *     @type string       $fields            Which fields to return. Specify 'email_addresses' to
     532     *                                           fetch a list of opt-out email_addresses.
     533     *                                           Specify 'user_ids' to
     534     *                                           fetch a list of opt-out user_ids.
     535     *                                           Specify 'ids' to fetch a list of opt-out IDs.
     536     *                                           Default: 'all' (return BP_Optout objects).
    527537     * }
    528538     *
     
    531541    public static function get( $args = array() ) {
    532542        global $wpdb;
    533         $optouts_table_name = BP_Optout::get_table_name();
     543        $optouts_table_name = self::get_table_name();
    534544
    535545        // Parse the arguments.
     
    552562
    553563        $sql = array(
    554             'select'     => "SELECT",
     564            'select'     => 'SELECT',
    555565            'fields'     => '',
    556566            'from'       => "FROM {$optouts_table_name} o",
     
    561571
    562572        if ( 'user_ids' === $r['fields'] ) {
    563             $sql['fields'] = "DISTINCT o.user_id";
    564         } else if ( 'email_addresses' === $r['fields'] ) {
    565             $sql['fields'] = "DISTINCT o.email_address_hash";
     573            $sql['fields'] = 'DISTINCT o.user_id';
     574        } elseif ( 'email_addresses' === $r['fields'] ) {
     575            $sql['fields'] = 'DISTINCT o.email_address_hash';
    566576        } else {
    567577            $sql['fields'] = 'DISTINCT o.id';
     
    583593            array(
    584594                'order_by'   => $r['order_by'],
    585                 'sort_order' => $r['sort_order']
     595                'sort_order' => $r['sort_order'],
    586596            )
    587597        );
     
    620630            // We only want the field that was found.
    621631            return array_map( 'intval', $paged_optout_ids );
    622         } else if ( 'email_addresses' === $r['fields'] ) {
     632        } elseif ( 'email_addresses' === $r['fields'] ) {
    623633            return $paged_optout_ids;
    624634        }
     
    626636        $uncached_ids = bp_get_non_cached_ids( $paged_optout_ids, 'bp_optouts' );
    627637        if ( $uncached_ids ) {
    628             $ids_sql = implode( ',', array_map( 'intval', $uncached_ids ) );
     638            $ids_sql      = implode( ',', array_map( 'intval', $uncached_ids ) );
    629639            $data_objects = $wpdb->get_results( "SELECT o.* FROM {$optouts_table_name} o WHERE o.id IN ({$ids_sql})" );
    630640            foreach ( $data_objects as $data_object ) {
     
    646656     * @since 8.0.0
    647657     *
     658     * @global wpdb $wpdb WordPress database object.
     659     *
    648660     * @see BP_optout::get() for a description of
    649661     *      arguments.
     
    654666    public static function get_total_count( $args ) {
    655667        global $wpdb;
    656         $optouts_table_name = BP_Optout::get_table_name();
     668        $optouts_table_name = self::get_table_name();
    657669
    658670        // Parse the arguments.
    659         $r  = bp_parse_args(
     671        $r = bp_parse_args(
    660672            $args,
    661673            array(
     
    674686        );
    675687
    676         // Build the query
    677         $select_sql = "SELECT COUNT(*)";
     688        // Build the query.
     689        $select_sql = 'SELECT COUNT(*)';
    678690        $from_sql   = "FROM {$optouts_table_name}";
    679691        $where_sql  = self::get_where_sql( $r );
    680692        $sql        = "{$select_sql} {$from_sql} {$where_sql}";
    681693
    682         // Return the queried results
     694        // Return the queried results.
    683695        return $wpdb->get_var( $sql );
    684696    }
     
    702714    public static function update( $update_args = array(), $where_args = array() ) {
    703715        $update = self::get_query_clauses( $update_args );
    704         $where  = self::get_query_clauses( $where_args  );
     716        $where  = self::get_query_clauses( $where_args );
    705717
    706718        /**
     
    736748        do_action( 'bp_optout_after_update', $where_args, $update_args );
    737749
    738         return $retval;
     750        return $retval;
    739751    }
    740752
     
    795807     * @see BP_Optout::get() for a description of accepted parameters.
    796808     *
     809     * @param array $args Arguments to pass to BP_optout::get().
    797810     * @return int|bool ID of first found invitation or false if none found.
    798811     */
     
    801814
    802815        $args['fields'] = 'ids';
    803         $optouts        = BP_Optout::get( $args );
     816        $optouts        = self::get( $args );
    804817        if ( $optouts ) {
    805818            $exists = current( $optouts );
     
    818831     *
    819832     * @param int $id ID of the opt-out item to be deleted.
    820      * @return bool True on success, false on failure.
     833     * @return bool|int Number of rows deleted on success, false on failure.
    821834     */
    822835    public static function delete_by_id( $id ) {
    823         return self::delete( array(
    824             'id' => $id,
    825         ) );
     836        return self::delete( array( 'id' => $id ) );
    826837    }
    827838}
Note: See TracChangeset for help on using the changeset viewer.