Skip to:
Content

BuddyPress.org

Changeset 10778


Ignore:
Timestamp:
05/19/2016 02:51:45 AM (8 years ago)
Author:
boonebgorges
Message:

XProfile: Only cache field object when query is successful.

Previously, a PHP notice was being thrown when a bad $field_id was passed
to BP_XProfile_Field::get_instance().

Props mmcachran.
Fixes #7073.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-xprofile/classes/class-bp-xprofile-field.php

    r10740 r10778  
    238238            $field = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$bp->profile->table_name_fields} WHERE id = %d", $field_id ) );
    239239
    240             wp_cache_add( $field->id, $field, 'bp_xprofile_fields' );
    241 
    242240            if ( ! $field ) {
    243241                return false;
    244242            }
     243
     244            wp_cache_add( $field->id, $field, 'bp_xprofile_fields' );
    245245        }
    246246
  • trunk/tests/phpunit/testcases/xprofile/class-bp-xprofile-field.php

    r10164 r10778  
    175175        $this->assertSame( $num_queries, $wpdb->num_queries );
    176176    }
     177
     178    /**
     179     * @ticket BP7073
     180     */
     181    public function test_bad_field_id_should_not_be_cached() {
     182        BP_XProfile_Field::get_instance( 12345 );
     183
     184        $this->assertFalse( wp_cache_get( 12345, 'bp_xprofile_fields' ) );
     185    }
    177186}
Note: See TracChangeset for help on using the changeset viewer.