Skip to:
Content

BuddyPress.org

Changeset 6602


Ignore:
Timestamp:
12/10/2012 01:14:46 PM (14 years ago)
Author:
johnjamesjacoby
Message:

Allow specific blogs to be removed from blog tracking by third-party plugins. Props tiraeth. Fixes #4527.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-blogs/bp-blogs-functions.php

    r6539 r6602  
    7373
    7474/**
     75 * Makes BuddyPress aware of sites that shouldn't be recorded to activity streams.
     76 *
     77 * If $user_id is provided, you can restrict site from being recordable
     78 * only to particular users.
     79 *
     80 * @since BuddyPress (1.7)
     81 * @param int $blog_id
     82 * @param int|null $user_id
     83 * @uses apply_filters()
     84 * @return bool True if blog is recordable, false elsewhere
     85 */
     86function bp_blogs_is_blog_recordable( $blog_id, $user_id = 0 ) {
     87
     88        $recordable_globally = apply_filters( 'bp_blogs_is_blog_recordable', true, $blog_id );
     89
     90        if ( !empty( $user_id ) ) {
     91                $recordable_for_user = apply_filters( 'bp_blogs_is_blog_recordable_for_user', $recordable_globally, $blog_id, $user_id );
     92        } else {
     93                $recordable_for_user = $recordable_globally;
     94        }
     95
     96        if ( !empty( $recordable_for_user ) ) {
     97                return true;
     98        }
     99
     100        return $recordable_globally;
     101}
     102
     103/**
     104 * Makes BuddyPress aware of sites that activities shouldn't be trackable.
     105 * If $user_id is provided, the developer can restrict site from
     106 * being trackable only to particular users.
     107 *
     108 * @since BuddyPress (1.7)
     109 * @param int $blog_id
     110 * @param int|null $user_id
     111 * @uses bp_blogs_is_blog_recordable
     112 * @uses apply_filters()
     113 * @return bool True if blog is trackable, false elsewhere
     114 */
     115function bp_blogs_is_blog_trackable( $blog_id, $user_id = 0 ) {
     116
     117        $trackable_globally = apply_filters( 'bp_blogs_is_blog_trackable', bp_blogs_is_blog_recordable( $blog_id, $user_id ), $blog_id );
     118
     119        if ( !empty( $user_id ) ) {
     120                $trackable_for_user = apply_filters( 'bp_blogs_is_blog_trackable_for_user', $trackable_globally, $blog_id, $user_id );
     121        } else {
     122                $trackable_for_user = $trackable_globally;
     123        }
     124
     125        if ( !empty( $trackable_for_user ) ) {
     126                return $trackable_for_user;
     127        }
     128
     129        return $trackable_globally;
     130}
     131
     132/**
    75133 * Makes BuddyPress aware of a new site so that it can track its activity.
    76134 *
     
    86144                $user_id = bp_loggedin_user_id();
    87145
    88         $name = get_blog_option( $blog_id, 'blogname' );
     146        // If blog is not recordable, do not record the activity.
     147        if ( !bp_blogs_is_blog_recordable( $blog_id, $user_id ) )
     148                return false;
     149
     150        $name        = get_blog_option( $blog_id, 'blogname' );
    89151        $description = get_blog_option( $blog_id, 'blogdescription' );
    90152
     
    106168
    107169        // Only record this activity if the blog is public
    108         if ( !$is_private && !$no_activity ) {
     170        if ( !$is_private && !$no_activity && bp_blogs_is_blog_trackable( $blog_id, $user_id ) ) {
     171
    109172                // Record this in activity streams
    110173                bp_blogs_record_activity( array(
     
    154217        $post_id = (int) $post_id;
    155218        $blog_id = (int) $wpdb->blogid;
     219
     220        // If blog is not trackable, do not record the activity.
     221        if ( ! bp_blogs_is_blog_trackable( $blog_id, $user_id ) )
     222                return false;
    156223
    157224        if ( !$user_id )
     
    262329
    263330        // Get blog and post data
    264         $blog_id                = get_current_blog_id();
     331        $blog_id = get_current_blog_id();
     332
     333        // If blog is not trackable, do not record the activity.
     334        if ( ! bp_blogs_is_blog_trackable( $blog_id, $user_id ) )
     335                return false;
     336
    265337        $recorded_comment->post = get_post( $recorded_comment->comment_post_ID );
    266338
Note: See TracChangeset for help on using the changeset viewer.