Skip to:
Content

BuddyPress.org

Ticket #8913: 8913.patch

File 8913.patch, 7.3 KB (added by viralsampat, 3 years ago)

I have checked above mentioned issue and resolved few errors and warning. Here, I have added its patch.

  • bp-xprofile-caps.php

     
    3838                        }
    3939
    4040                        // Visibility on the fullname field is not editable.
    41                         if ( 1 == $field_id ) {
     41                        if ( 1 === $field_id ) {
    4242                                $caps[] = 'do_not_allow';
    4343                                break;
    4444                        }
    4545
    4646                        // Has the admin disabled visibility modification for this field?
    47                         if ( 'disabled' == bp_xprofile_get_meta( $field_id, 'field', 'allow_custom_visibility' ) ) {
     47                        if ( 'disabled' === bp_xprofile_get_meta( $field_id, 'field', 'allow_custom_visibility' ) ) {
    4848                                $caps[] = 'do_not_allow';
    4949                                break;
    5050                        }
    5151
    5252                        // Friends don't let friends edit each other's visibility.
    53                         if ( $profile_user_id != bp_displayed_user_id() && ! bp_current_user_can( 'bp_moderate' ) ) {
     53                        if ( $profile_user_id !== bp_displayed_user_id() && ! bp_current_user_can( 'bp_moderate' ) ) {
    5454                                $caps[] = 'do_not_allow';
    5555                                break;
    5656                        }
  • bp-xprofile-cssjs.php

     
    1616 * @since 1.1.0
    1717 */
    1818function xprofile_add_admin_css() {
    19         if ( ! empty( $_GET['page'] ) && strpos( $_GET['page'], 'bp-profile-setup' ) !== false ) {
     19        if ( ! empty( $_GET['page'] ) && strpos( sanitize_text_field( $_GET['page'] ), 'bp-profile-setup' ) !== false ) {
    2020                $min = bp_core_get_minified_asset_suffix();
    2121
    2222                wp_enqueue_style( 'xprofile-admin-css', buddypress()->plugin_url . "bp-xprofile/admin/css/admin{$min}.css", array(), bp_get_version() );
     
    3535 * @since 1.5.0
    3636 */
    3737function xprofile_add_admin_js() {
    38         if ( ! empty( $_GET['page'] ) && strpos( $_GET['page'], 'bp-profile-setup' ) !== false ) {
     38        if ( ! empty( $_GET['page'] ) && strpos( sanitize_text_field( $_GET['page'] ), 'bp-profile-setup' ) !== false ) {
    3939                wp_enqueue_script( 'jquery-ui-core'      );
    4040                wp_enqueue_script( 'jquery-ui-tabs'      );
    4141                wp_enqueue_script( 'jquery-ui-mouse'     );
  • classes/class-bp-xprofile-field-type-checkbox.php

     
    126126
    127127                // Check for updated posted values, but errors preventing them from
    128128                // being saved first time.
    129                 if ( isset( $_POST[ 'field_' . $this->field_obj->id ] ) && $option_values != maybe_serialize( $_POST[ 'field_' . $this->field_obj->id ] ) ) {
     129                if ( isset( $_POST[ 'field_' . $this->field_obj->id ] ) && $option_values !== maybe_serialize( $_POST[ 'field_' . $this->field_obj->id ] ) ) {
    130130                        if ( ! empty( $_POST[ 'field_' . $this->field_obj->id ] ) ) {
    131131                                $option_values = array_map( 'sanitize_text_field', $_POST[ 'field_' . $this->field_obj->id ] );
    132132                        }
     
    142142                                // so we'll be sure to get a match.
    143143                                $allowed_options = xprofile_sanitize_data_value_before_save( $options[ $k ]->name, false, false );
    144144
    145                                 if ( $option_values[ $j ] === $allowed_options || in_array( $allowed_options, $option_values ) ) {
     145                                if ( $option_values[ $j ] === $allowed_options || in_array( $allowed_options, $option_values, true ) ) {
    146146                                        $selected = ' checked="checked"';
    147147                                        break;
    148148                                }
  • classes/class-bp-xprofile-field.php

     
    484484                                $parent_id = $this->id;
    485485
    486486                                // Allow plugins to filter the field's child options (i.e. the items in a selectbox).
    487                                 $post_option  = ! empty( $_POST[ "{$this->type}_option" ]           ) ? $_POST[ "{$this->type}_option" ] : '';
    488                                 $post_default = ! empty( $_POST[ "isDefault_{$this->type}_option" ] ) ? $_POST[ "isDefault_{$this->type}_option" ] : '';
     487                                $post_option  = ! empty( $_POST[ "{$this->type}_option" ]           ) ? sanitize_text_field( $_POST[ "{$this->type}_option" ] ) : '';
     488                                $post_default = ! empty( $_POST[ "isDefault_{$this->type}_option" ] ) ? sanitize_text_field( $_POST[ "isDefault_{$this->type}_option" ] ) : '';
    489489
    490490                                /**
    491491                                 * Filters the submitted field option value before saved.
     
    517517                                                                $is_default = 1;
    518518                                                        }
    519519                                                } else {
    520                                                         if ( (int) $defaults == $option_key ) {
     520                                                        if ( (int) $defaults === $option_key ) {
    521521                                                                $is_default = 1;
    522522                                                        }
    523523                                                }
    524524
    525                                                 if ( '' != $option_value ) {
     525                                                if ( '' !== $option_value ) {
    526526                                                        $sql = $wpdb->prepare( "INSERT INTO {$bp->profile->table_name_fields} (group_id, parent_id, type, name, description, is_required, option_order, is_default_option) VALUES (%d, %d, 'option', %s, '', 0, %d, %d)", $this->group_id, $parent_id, $option_value, $counter, $is_default );
    527527                                                        if ( ! $wpdb->query( $sql ) ) {
    528528                                                                return false;
     
    651651
    652652                // If '_none' is found in the array, it overrides all types.
    653653                $types = array();
    654                 if ( ! in_array( '_none', $raw_types ) ) {
     654                if ( ! in_array( '_none', $raw_types, true ) ) {
    655655                        $registered_types = bp_get_member_types();
    656656
    657657                        // Eliminate invalid member types saved in the database.
     
    766766         */
    767767        public function get_member_type_label() {
    768768                // Field 1 is always displayed to everyone, so never gets a label.
    769                 if ( 1 == $this->id ) {
     769                if ( 1 === $this->id ) {
    770770                        return '';
    771771                }
    772772
     
    780780
    781781                // If the field applies to all member types, show no message.
    782782                $all_types[] = 'null';
    783                 if ( array_values( $all_types ) == $member_types ) {
     783                if ( array_values( $all_types ) === $member_types ) {
    784784                        return '';
    785785                }
    786786
     
    11651165                // Check that field is of valid type.
    11661166                if ( ! in_array( $_POST['fieldtype'], array_keys( bp_xprofile_get_field_types() ), true ) ) {
    11671167                        /* translators: %s: field type name */
    1168                         $message = sprintf( esc_html__( 'The profile field type %s is not registered.', 'buddypress' ), '<code>' . esc_attr( $_POST['fieldtype'] ) . '</code>' );
     1168                        $message = sprintf( esc_html__( 'The profile field type %s is not registered.', 'buddypress' ), '<code>' . sanitize_text_field( $_POST['fieldtype'] ) . '</code>' );
    11691169                        return false;
    11701170                }
    11711171
    11721172                // Get field type so we can check for and validate any field options.
    1173                 $field_type = bp_xprofile_create_field_type( $_POST['fieldtype'] );
     1173                $field_type = bp_xprofile_create_field_type( sanitize_text_field( $_POST['fieldtype'] ) );
    11741174
    11751175                // Field type requires options.
    11761176                if ( true === $field_type->supports_options ) {
     
    12531253                        ), $users_url . '#tabs-' . (int) $this->group_id );
    12541254
    12551255                        if ( ! empty( $_POST['saveField'] ) ) {
    1256                                 $this->name        = $_POST['title'];
    1257                                 $this->description = $_POST['description'];
    1258                                 $this->is_required = $_POST['required'];
    1259                                 $this->type        = $_POST['fieldtype'];
    1260                                 $this->field_order = $_POST['field_order'];
     1256                                $this->name        = sanitize_text_field( $_POST['title'] );
     1257                                $this->description = sanitize_text_field( $_POST['description'] );
     1258                                $this->is_required = sanitize_text_field( $_POST['required'] );
     1259                                $this->type        = sanitize_text_field( $_POST['fieldtype'] );
     1260                                $this->field_order = sanitize_text_field( $_POST['field_order'] );
    12611261
    12621262                                if ( ! empty( $_POST[ "sort_order_{$this->type}" ] ) ) {
    12631263                                        $this->order_by = $_POST[ "sort_order_{$this->type}" ];