Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
07/23/2024 01:32:42 AM (23 months ago)
Author:
espellcaste
Message:

WPCS: miscellaneous fixes for cache-related files in several components.

See #9174 and #9173
Closes https://github.com/buddypress/buddypress/pull/331

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-groups/bp-groups-cache.php

    r13890 r13971  
    33 * BuddyPress Groups Caching.
    44 *
    5  * Caching functions handle the clearing of cached objects and pages on specific
    6  * actions throughout BuddyPress.
    7  *
    85 * @package BuddyPress
    9  * @subpackage Groups
     6 * @subpackage GroupsCache
    107 * @since 1.5.0
    118 */
     
    3532
    3633    $cache_args = array(
    37         'object_ids'       => $group_ids,
    38         'object_type'      => $bp->groups->id,
     34        'object_ids'       => $group_ids,
     35        'object_type'      => $bp->groups->id,
    3936        'cache_group'      => 'group_meta',
    4037        'object_column'    => 'group_id',
    41         'meta_table'       => $bp->groups->table_name_groupmeta,
    42         'cache_key_prefix' => 'bp_groups_groupmeta'
     38        'meta_table'       => $bp->groups->table_name_groupmeta,
     39        'cache_key_prefix' => 'bp_groups_groupmeta',
    4340    );
    4441
     
    5653    wp_cache_delete( 'bp_total_group_count', 'bp' );
    5754}
    58 add_action( 'groups_group_deleted',              'groups_clear_group_object_cache' );
    59 add_action( 'groups_settings_updated',           'groups_clear_group_object_cache' );
    60 add_action( 'groups_details_updated',            'groups_clear_group_object_cache' );
    61 add_action( 'groups_group_avatar_updated',       'groups_clear_group_object_cache' );
     55add_action( 'groups_group_deleted', 'groups_clear_group_object_cache' );
     56add_action( 'groups_settings_updated', 'groups_clear_group_object_cache' );
     57add_action( 'groups_details_updated', 'groups_clear_group_object_cache' );
     58add_action( 'groups_group_avatar_updated', 'groups_clear_group_object_cache' );
    6259add_action( 'groups_create_group_step_complete', 'groups_clear_group_object_cache' );
    6360
     
    7269    wp_cache_delete( $group_id, 'bp_groups' );
    7370}
    74 add_action( 'groups_delete_group',     'bp_groups_delete_group_cache' );
    75 add_action( 'groups_update_group',     'bp_groups_delete_group_cache' );
    76 add_action( 'groups_details_updated',  'bp_groups_delete_group_cache' );
     71add_action( 'groups_delete_group', 'bp_groups_delete_group_cache' );
     72add_action( 'groups_update_group', 'bp_groups_delete_group_cache' );
     73add_action( 'groups_details_updated', 'bp_groups_delete_group_cache' );
    7774add_action( 'groups_settings_updated', 'bp_groups_delete_group_cache' );
    7875
     
    115112function bp_groups_clear_group_members_caches( $group_obj, $user_ids ) {
    116113    // Clears the 'total groups' cache for each member in a group.
    117     foreach ( (array) $user_ids as $user_id )
     114    foreach ( (array) $user_ids as $user_id ) {
    118115        groups_clear_group_user_object_cache( $group_obj->id, $user_id );
     116    }
    119117}
    120118add_action( 'bp_groups_delete_group', 'bp_groups_clear_group_members_caches', 10, 2 );
     
    123121 * Clear a user's cached total group invite count.
    124122 *
    125  * Count is cleared when an invite is accepted, rejected or deleted.
     123 * Count is cleared when an invitation is accepted, rejected or deleted.
    126124 *
    127125 * @since 2.0.0
     
    177175    wp_cache_delete( 'bp_total_groups_for_user_' . $user_id, 'bp' );
    178176}
    179 add_action( 'groups_join_group',    'groups_clear_group_user_object_cache', 10, 2 );
    180 add_action( 'groups_leave_group',   'groups_clear_group_user_object_cache', 10, 2 );
    181 add_action( 'groups_ban_member',    'groups_clear_group_user_object_cache', 10, 2 );
    182 add_action( 'groups_unban_member',  'groups_clear_group_user_object_cache', 10, 2 );
     177add_action( 'groups_join_group', 'groups_clear_group_user_object_cache', 10, 2 );
     178add_action( 'groups_leave_group', 'groups_clear_group_user_object_cache', 10, 2 );
     179add_action( 'groups_ban_member', 'groups_clear_group_user_object_cache', 10, 2 );
     180add_action( 'groups_unban_member', 'groups_clear_group_user_object_cache', 10, 2 );
    183181add_action( 'groups_uninvite_user', 'groups_clear_group_user_object_cache', 10, 2 );
    184182add_action( 'groups_remove_member', 'groups_clear_group_user_object_cache', 10, 2 );
     
    196194}
    197195add_action( 'groups_promote_member', 'groups_clear_group_administrator_cache' );
    198 add_action( 'groups_demote_member',  'groups_clear_group_administrator_cache' );
    199 add_action( 'groups_delete_group',   'groups_clear_group_administrator_cache' );
     196add_action( 'groups_demote_member', 'groups_clear_group_administrator_cache' );
     197add_action( 'groups_delete_group', 'groups_clear_group_administrator_cache' );
    200198
    201199/**
     
    265263 * @since 5.0.0
    266264 *
    267  * @param BP_Invitation object $invitation Characteristics of the invitation just saved.
     265 * @param BP_Invitation $invitation Characteristics of the invitation just saved.
    268266 */
    269267function bp_groups_clear_user_group_cache_on_invitation_save( BP_Invitation $invitation ) {
     
    274272    wp_cache_delete( $invitation->id, 'bp_groups_invitations_as_memberships' );
    275273}
    276 add_action( 'bp_invitation_after_save', 'bp_groups_clear_user_group_cache_on_invitation_save', 10, 2 );
     274add_action( 'bp_invitation_after_save', 'bp_groups_clear_user_group_cache_on_invitation_save' );
    277275
    278276/**
     
    285283 */
    286284function bp_groups_clear_user_group_cache_on_invitation_change( $args ) {
    287     $args['fields' ] = 'ids';
     285    $args['fields']          = 'ids';
    288286    $affected_invitation_ids = groups_get_invites( $args );
    289287    foreach ( $affected_invitation_ids as $invitation_id ) {
     
    320318 *
    321319 * @since 2.7.0
    322  *
    323  * @return bool
    324320 */
    325321function bp_groups_reset_cache_incrementor() {
    326     return bp_core_reset_incrementor( 'bp_groups' );
    327 }
    328 add_action( 'groups_group_after_save',    'bp_groups_reset_cache_incrementor' );
    329 add_action( 'bp_groups_delete_group',     'bp_groups_reset_cache_incrementor' );
    330 add_action( 'updated_group_meta',         'bp_groups_reset_cache_incrementor' );
    331 add_action( 'deleted_group_meta',         'bp_groups_reset_cache_incrementor' );
    332 add_action( 'added_group_meta',           'bp_groups_reset_cache_incrementor' );
     322    bp_core_reset_incrementor( 'bp_groups' );
     323}
     324add_action( 'groups_group_after_save', 'bp_groups_reset_cache_incrementor' );
     325add_action( 'bp_groups_delete_group', 'bp_groups_reset_cache_incrementor' );
     326add_action( 'updated_group_meta', 'bp_groups_reset_cache_incrementor' );
     327add_action( 'deleted_group_meta', 'bp_groups_reset_cache_incrementor' );
     328add_action( 'added_group_meta', 'bp_groups_reset_cache_incrementor' );
    333329add_action( 'groups_member_after_remove', 'bp_groups_reset_cache_incrementor' );
    334330
     
    345341 * @param array  $tt_ids    Array of term taxonomy IDs.
    346342 * @param string $taxonomy  Taxonomy slug.
    347  * @return bool
    348343 */
    349344function bp_groups_reset_cache_incrementor_on_group_term_change( $object_id, $terms, $tt_ids, $taxonomy ) {
    350345    $tax_object = get_taxonomy( $taxonomy );
    351346    if ( $tax_object && in_array( 'bp_group', $tax_object->object_type, true ) ) {
    352         return bp_groups_reset_cache_incrementor();
    353     }
    354 
    355     return false;
     347        bp_groups_reset_cache_incrementor();
     348    }
    356349}
    357350add_action( 'bp_set_object_terms', 'bp_groups_reset_cache_incrementor_on_group_term_change', 10, 4 );
     
    368361 * @param array  $terms     Array of object terms.
    369362 * @param string $taxonomy  Taxonomy slug.
    370  * @return bool
    371363 */
    372364function bp_groups_reset_cache_incrementor_on_group_term_remove( $object_id, $terms, $taxonomy ) {
    373365    $tax_object = get_taxonomy( $taxonomy );
    374366    if ( $tax_object && in_array( 'bp_group', $tax_object->object_type, true ) ) {
    375         return bp_groups_reset_cache_incrementor();
    376     }
    377 
    378     return false;
     367        bp_groups_reset_cache_incrementor();
     368    }
    379369}
    380370add_action( 'bp_remove_object_terms', 'bp_groups_reset_cache_incrementor_on_group_term_remove', 10, 3 );
    381371
    382372/* List actions to clear super cached pages on, if super cache is installed */
    383 add_action( 'groups_join_group',                 'bp_core_clear_cache' );
    384 add_action( 'groups_leave_group',                'bp_core_clear_cache' );
    385 add_action( 'groups_accept_invite',              'bp_core_clear_cache' );
    386 add_action( 'groups_reject_invite',              'bp_core_clear_cache' );
    387 add_action( 'groups_invite_user',                'bp_core_clear_cache' );
    388 add_action( 'groups_uninvite_user',              'bp_core_clear_cache' );
    389 add_action( 'groups_details_updated',            'bp_core_clear_cache' );
    390 add_action( 'groups_settings_updated',           'bp_core_clear_cache' );
    391 add_action( 'groups_unban_member',               'bp_core_clear_cache' );
    392 add_action( 'groups_ban_member',                 'bp_core_clear_cache' );
    393 add_action( 'groups_demote_member',              'bp_core_clear_cache' );
    394 add_action( 'groups_promote_member',             'bp_core_clear_cache' );
    395 add_action( 'groups_membership_rejected',        'bp_core_clear_cache' );
    396 add_action( 'groups_membership_accepted',        'bp_core_clear_cache' );
    397 add_action( 'groups_membership_requested',       'bp_core_clear_cache' );
     373add_action( 'groups_join_group', 'bp_core_clear_cache' );
     374add_action( 'groups_leave_group', 'bp_core_clear_cache' );
     375add_action( 'groups_accept_invite', 'bp_core_clear_cache' );
     376add_action( 'groups_reject_invite', 'bp_core_clear_cache' );
     377add_action( 'groups_invite_user', 'bp_core_clear_cache' );
     378add_action( 'groups_uninvite_user', 'bp_core_clear_cache' );
     379add_action( 'groups_details_updated', 'bp_core_clear_cache' );
     380add_action( 'groups_settings_updated', 'bp_core_clear_cache' );
     381add_action( 'groups_unban_member', 'bp_core_clear_cache' );
     382add_action( 'groups_ban_member', 'bp_core_clear_cache' );
     383add_action( 'groups_demote_member', 'bp_core_clear_cache' );
     384add_action( 'groups_promote_member', 'bp_core_clear_cache' );
     385add_action( 'groups_membership_rejected', 'bp_core_clear_cache' );
     386add_action( 'groups_membership_accepted', 'bp_core_clear_cache' );
     387add_action( 'groups_membership_requested', 'bp_core_clear_cache' );
    398388add_action( 'groups_create_group_step_complete', 'bp_core_clear_cache' );
    399 add_action( 'groups_created_group',              'bp_core_clear_cache' );
    400 add_action( 'groups_group_avatar_updated',       'bp_core_clear_cache' );
     389add_action( 'groups_created_group', 'bp_core_clear_cache' );
     390add_action( 'groups_group_avatar_updated', 'bp_core_clear_cache' );
Note: See TracChangeset for help on using the changeset viewer.