Skip to:
Content

bbPress.org


Ignore:
Timestamp:
06/12/2017 05:41:49 PM (9 years ago)
Author:
johnjamesjacoby
Message:

Engagements: Keep topic engagement counts up-to-date.

This changes the way the old 'voice count' works with the new engagements API in the following ways:

  • Introduce new function to update voice count meta when necessary
  • Modify recalculation function with a $force parameter, and only recalculate the counts when the engagements have changed by default
  • Hook the above functions in where appropriate, largely when deleting replies (this is a unique case where a fully deleted reply needs to check if the author of the current reply has a previously public reply in that same topic already, which should not trigger a recalculation.)
  • We are silently moving the bbp_delete_ actions onto the before_delete_post hook, so that all term & meta-data is available to them (which helps with race conditions mentioned in r6528)

Engagements are now hooked in and listening in the most efficient way possible, at least until a common & shared walker is introduced for the entire tree.

See: #3068.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/includes/core/actions.php

    r6369 r6529  
    155155
    156156// Before Delete/Trash/Untrash Forum
    157 add_action( 'wp_trash_post', 'bbp_trash_forum'   );
    158 add_action( 'trash_post',    'bbp_trash_forum'   );
    159 add_action( 'untrash_post',  'bbp_untrash_forum' );
    160 add_action( 'delete_post',  'bbp_delete_forum'  );
     157add_action( 'wp_trash_post',      'bbp_trash_forum'   );
     158add_action( 'trash_post',         'bbp_trash_forum'   );
     159add_action( 'untrash_post',       'bbp_untrash_forum' );
     160add_action( 'before_delete_post', 'bbp_delete_forum'  );
    161161
    162162// After Deleted/Trashed/Untrashed Forum
     
    184184
    185185// Before Delete/Trash/Untrash Reply
    186 add_action( 'wp_trash_post', 'bbp_trash_reply'   );
    187 add_action( 'trash_post',    'bbp_trash_reply'   );
    188 add_action( 'untrash_post',  'bbp_untrash_reply' );
    189 add_action( 'delete_post',  'bbp_delete_reply'  );
     186add_action( 'wp_trash_post',      'bbp_trash_reply'   );
     187add_action( 'trash_post',         'bbp_trash_reply'   );
     188add_action( 'untrash_post',       'bbp_untrash_reply' );
     189add_action( 'before_delete_post', 'bbp_delete_reply'  );
    190190
    191191// After Deleted/Trashed/Untrashed Reply
     
    206206
    207207// Before Delete/Trash/Untrash Topic
    208 add_action( 'wp_trash_post', 'bbp_trash_topic'   );
    209 add_action( 'trash_post',    'bbp_trash_topic'   );
    210 add_action( 'untrash_post',  'bbp_untrash_topic' );
    211 add_action( 'delete_post',  'bbp_delete_topic'  );
     208add_action( 'wp_trash_post',      'bbp_trash_topic'   );
     209add_action( 'trash_post',         'bbp_trash_topic'   );
     210add_action( 'untrash_post',       'bbp_untrash_topic' );
     211add_action( 'before_delete_post', 'bbp_delete_topic'  );
    212212
    213213// After Deleted/Trashed/Untrashed Topic
     
    293293add_action( 'bbp_unapproved_reply', 'bbp_decrease_topic_reply_count'        );
    294294add_action( 'bbp_unapproved_reply', 'bbp_increase_topic_reply_count_hidden' );
     295add_action( 'bbp_deleted_reply',    'bbp_decrease_topic_reply_count_hidden' );
    295296
    296297// Users topic & reply counts.
     
    310311add_action( 'bbp_insert_reply', 'bbp_insert_reply_update_counts', 10, 3 );
    311312
    312 // Update topic voice counts.
     313// Update engagements.
     314add_action( 'bbp_new_topic', 'bbp_update_topic_engagements' );
     315add_action( 'bbp_new_reply', 'bbp_update_topic_engagements' );
     316
     317// Recalculate engagements.
     318add_action( 'bbp_deleted_topic', 'bbp_recalculate_topic_engagements' );
     319add_action( 'bbp_deleted_reply', 'bbp_recalculate_topic_engagements' );
     320
     321// Update engagement counts.
    313322add_action( 'bbp_new_reply',        'bbp_update_topic_voice_count' );
    314323add_action( 'bbp_trashed_reply',    'bbp_update_topic_voice_count' );
     
    318327add_action( 'bbp_approved_reply',   'bbp_update_topic_voice_count' );
    319328add_action( 'bbp_unapproved_reply', 'bbp_update_topic_voice_count' );
     329add_action( 'bbp_deleted_reply',    'bbp_update_topic_voice_count' );
    320330
    321331// Insert reply voice counts.
Note: See TracChangeset for help on using the changeset viewer.