Changeset 9676
- Timestamp:
- 04/01/2015 11:14:16 PM (9 years ago)
- Location:
- trunk/src/bp-xprofile
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/bp-xprofile/bp-xprofile-cache.php
r9351 r9676 53 53 * object type ('group', 'field', 'data') 54 54 */ 55 function bp_xprofile_update_meta_cache( $object_ids = array() , $user_id = 0) {55 function bp_xprofile_update_meta_cache( $object_ids = array() ) { 56 56 global $wpdb; 57 57 … … 76 76 foreach ( $uncached_object_ids as $object_type => $uncached_object_type_ids ) { 77 77 if ( ! empty( $object_ids[ $object_type ] ) ) { 78 78 79 // Sanitize $object_ids passed to the function 79 80 $object_type_ids = wp_parse_id_list( $object_ids[ $object_type ] ); … … 90 91 91 92 // If there are uncached items, go ahead with the query 92 if ( $do_query ) {93 if ( true === $do_query ) { 93 94 $where = array(); 94 95 foreach ( $uncached_object_ids as $otype => $oids ) { … … 139 140 } 140 141 142 /** 143 * Clear cached XProfile field group data 144 * 145 * @since BuddyPress (2.1.0) 146 * 147 * @param object $group_obj 148 */ 141 149 function xprofile_clear_profile_groups_object_cache( $group_obj ) { 142 wp_cache_delete( ' xprofile_groups_inc_empty', 'bp' );143 wp_cache_delete( 'xprofile_group_' . $group_obj->id, 'bp' );150 wp_cache_delete( 'all', 'bp_xprofile_groups' ); 151 wp_cache_delete( $group_obj->id, 'bp_xprofile_groups' ); 144 152 } 145 153 add_action( 'xprofile_group_after_delete', 'xprofile_clear_profile_groups_object_cache' ); 146 154 add_action( 'xprofile_group_after_save', 'xprofile_clear_profile_groups_object_cache' ); 147 155 148 function xprofile_clear_profile_data_object_cache( $group_id ) { 149 wp_cache_delete( 'bp_user_fullname_' . bp_loggedin_user_id(), 'bp' ); 150 } 151 add_action( 'xprofile_updated_profile', 'xprofile_clear_profile_data_object_cache' ); 156 /** 157 * Clear cached XProfile fullname data for user 158 * 159 * @since BuddyPress (2.1.0) 160 * 161 * @param int $user_id ID of user whose fullname cache to delete 162 */ 163 function xprofile_clear_profile_data_object_cache( $user_id = 0 ) { 164 wp_cache_delete( 'bp_user_fullname_' . $user_id, 'bp' ); 165 } 166 add_action( 'xprofile_updated_profile', 'xprofile_clear_profile_data_object_cache' ); 152 167 153 168 /** … … 174 189 */ 175 190 function xprofile_clear_profile_field_object_cache( $field_obj ) { 191 176 192 // Clear default visibility level cache 177 wp_cache_delete( ' xprofile_default_visibility_levels', 'bp' );193 wp_cache_delete( 'default_visibility_levels', 'bp_xprofile' ); 178 194 179 195 // Modified fields can alter parent group status, in particular when 180 196 // the group goes from empty to non-empty. Bust its cache, as well as 181 // the global group_inc_emptycache182 wp_cache_delete( ' xprofile_group_' . $field_obj->group_id, 'bp' );183 wp_cache_delete( 'xprofile_groups_inc_empty', 'bp' );184 } 185 add_action( 'xprofile_fields_saved_field', 'xprofile_clear_profile_field_object_cache' );197 // the global 'all' cache 198 wp_cache_delete( 'all', 'bp_xprofile_groups' ); 199 wp_cache_delete( $field_obj->group_id, 'bp_xprofile_groups' ); 200 } 201 add_action( 'xprofile_fields_saved_field', 'xprofile_clear_profile_field_object_cache' ); 186 202 add_action( 'xprofile_fields_deleted_field', 'xprofile_clear_profile_field_object_cache' ); 187 203 -
trunk/src/bp-xprofile/bp-xprofile-loader.php
r9515 r9676 368 368 'bp_xprofile', 369 369 'bp_xprofile_data', 370 'bp_xprofile_groups', 370 371 'xprofile_meta' 371 372 ) ); -
trunk/src/bp-xprofile/bp-xprofile-template.php
r9515 r9676 881 881 */ 882 882 function bp_profile_get_field_groups() { 883 $groups = wp_cache_get( 'xprofile_groups_inc_empty', 'bp' ); 884 885 if ( empty( $groups )) {883 884 $groups = wp_cache_get( 'all', 'bp_xprofile_groups' ); 885 if ( false === $groups ) { 886 886 $groups = bp_xprofile_get_groups( array( 'fetch_fields' => true ) ); 887 wp_cache_set( ' xprofile_groups_inc_empty', $groups, 'bp' );887 wp_cache_set( 'all', $groups, 'bp_xprofile' ); 888 888 } 889 889 … … 974 974 } 975 975 function bp_get_profile_group_name() { 976 if ( !$group_id = bp_action_variable( 1 ) ) 976 977 // Check action variable 978 $group_id = bp_action_variable( 1 ); 979 if ( empty( $group_id ) || ! is_numeric( $group_id ) ) { 977 980 $group_id = 1; 978 979 if ( !is_numeric( $group_id ) ) 980 $group_id = 1; 981 982 if ( !$group = wp_cache_get( 'xprofile_group_' . $group_id, 'bp' ) ) { 983 $group = new BP_XProfile_Group($group_id); 984 wp_cache_set( 'xprofile_group_' . $group_id, $group, 'bp' ); 985 } 981 } 982 983 // Check for cached group 984 $group = new BP_XProfile_Group( $group_id ); 986 985 987 986 /** -
trunk/src/bp-xprofile/classes/class-bp-xprofile-group.php
r9671 r9676 82 82 global $wpdb; 83 83 84 $group = wp_cache_get( 'xprofile_group_' . $this->id, 'bp' );84 $group = wp_cache_get( $id, 'bp_xprofile_groups' ); 85 85 86 86 if ( false === $group ) { 87 $bp = buddypress();87 $bp = buddypress(); 88 88 $group = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$bp->profile->table_name_groups} WHERE id = %d", $id ) ); 89 wp_cache_set( $id, $group, 'bp_xprofile_groups' ); 89 90 } 90 91 … … 94 95 95 96 $this->id = $group->id; 96 $this->name = stripslashes( $group->name );97 $this->description = stripslashes( $group->description );97 $this->name = $group->name; 98 $this->description = $group->description; 98 99 $this->can_delete = $group->can_delete; 99 100 $this->group_order = $group->group_order; … … 456 457 457 458 // If cached data is found, use it 458 $cache_key = 'xprofile_group_' . $group_id; 459 $group_data = wp_cache_get( $cache_key, 'bp' ); 459 $group_data = wp_cache_get( $group_id, 'bp_xprofile_groups' ); 460 460 if ( false !== $group_data ) { 461 461 $groups[ $group_id ] = $group_data; … … 493 493 494 494 // Cache previously uncached group data 495 $cache_key = 'xprofile_group_' . $gdata->id; 496 wp_cache_set( $cache_key, $gdata, 'bp' ); 495 wp_cache_set( $gdata->id, $gdata, 'bp_xprofile_groups' ); 497 496 } 498 497 } … … 543 542 544 543 // Purge profile field group cache 545 wp_cache_delete( ' xprofile_groups_inc_empty', 'bp' );544 wp_cache_delete( 'all', 'bp_xprofile_groups' ); 546 545 547 546 $bp = buddypress(); … … 608 607 global $wpdb; 609 608 610 $default_visibility_levels = wp_cache_get( ' xprofile_default_visibility_levels', 'bp' );609 $default_visibility_levels = wp_cache_get( 'default_visibility_levels', 'bp_xprofile' ); 611 610 612 611 if ( false === $default_visibility_levels ) { … … 628 627 } 629 628 630 wp_cache_set( ' xprofile_default_visibility_levels', $default_visibility_levels, 'bp' );629 wp_cache_set( 'default_visibility_levels', $default_visibility_levels, 'bp_xprofile' ); 631 630 } 632 631
Note: See TracChangeset
for help on using the changeset viewer.