Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
03/28/2014 10:33:16 PM (11 years ago)
Author:
r-a-y
Message:

Blogs: Mirror a blog's various comment options to BP's blogmeta.

This commit mirrors the following blog options to BP's blogmeta:

  • 'close_comments_for_old_posts'
  • 'close_comment_days_old'
  • 'thread_comments_depth'

These options will be used later in the new bp_blogs_comments_open()
function to determine whether a blog post's activity item should be
closed from commenting. This is designed to prevent multiple calls
to switch_to_blog().

See #5130

File:
1 edited

Legend:

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

    r8135 r8189  
    183183        return false;
    184184
    185     $url         = get_home_url( $blog_id );
    186     $name        = get_blog_option( $blog_id, 'blogname' );
    187     $description = get_blog_option( $blog_id, 'blogdescription' );
    188 
    189     if ( empty( $name ) )
    190         return false;
     185    $name = get_blog_option( $blog_id, 'blogname' );
     186
     187    if ( empty( $name ) ) {
     188        return false;
     189    }
     190
     191    $url             = get_home_url( $blog_id );
     192    $description     = get_blog_option( $blog_id, 'blogdescription' );
     193    $close_old_posts = get_blog_option( $blog_id, 'close_comments_for_old_posts' );
     194    $close_days_old  = get_blog_option( $blog_id, 'close_comments_days_old' );
     195
     196    $thread_depth = get_blog_option( $blog_id, 'thread_comments' );
     197    if ( ! empty( $thread_depth ) ) {
     198        $thread_depth = get_blog_option( $blog_id, 'thread_comments_depth' );
     199    } else {
     200        // perhaps filter this?
     201        $thread_depth = 1;
     202    }
    191203
    192204    $recorded_blog          = new BP_Blogs_Blog;
     
    200212    bp_blogs_update_blogmeta( $recorded_blog->blog_id, 'description', $description );
    201213    bp_blogs_update_blogmeta( $recorded_blog->blog_id, 'last_activity', bp_core_current_time() );
     214    bp_blogs_update_blogmeta( $recorded_blog->blog_id, 'close_comments_for_old_posts', $close_old_posts );
     215    bp_blogs_update_blogmeta( $recorded_blog->blog_id, 'close_comments_days_old', $close_days_old );
     216    bp_blogs_update_blogmeta( $recorded_blog->blog_id, 'thread_comments_depth', $thread_depth );
    202217
    203218    $is_private = !empty( $_POST['blog_public'] ) && (int) $_POST['blog_public'] ? false : true;
     
    251266}
    252267add_action( 'update_option_blogdescription', 'bp_blogs_update_option_blogdescription', 10, 2 );
     268
     269/**
     270 * Update "Close comments for old posts" option in BuddyPress blogmeta table.
     271 *
     272 * @since BuddyPress (2.0.0)
     273 *
     274 * @global object $wpdb DB Layer.
     275 *
     276 * @param string $oldvalue Value before save. Passed by do_action() but
     277 *        unused here.
     278 * @param string $newvalue Value to change meta to.
     279 */
     280function bp_blogs_update_option_close_comments_for_old_posts( $oldvalue, $newvalue ) {
     281    global $wpdb;
     282
     283    bp_blogs_update_blogmeta( $wpdb->blogid, 'close_comments_for_old_posts', $newvalue );
     284}
     285add_action( 'update_option_close_comments_for_old_posts', 'bp_blogs_update_option_close_comments_for_old_posts', 10, 2 );
     286
     287/**
     288 * Update "Close comments after days old" option in BuddyPress blogmeta table.
     289 *
     290 * @since BuddyPress (2.0.0)
     291 *
     292 * @global object $wpdb DB Layer.
     293 *
     294 * @param string $oldvalue Value before save. Passed by do_action() but
     295 *        unused here.
     296 * @param string $newvalue Value to change meta to.
     297 */
     298function bp_blogs_update_option_close_close_comments_days_old( $oldvalue, $newvalue ) {
     299    global $wpdb;
     300
     301    bp_blogs_update_blogmeta( $wpdb->blogid, 'close_comments_days_old', $newvalue );
     302}
     303add_action( 'update_option_close_comments_days_old', 'bp_blogs_update_option_close_comments_days_old', 10, 2 );
     304
     305/**
     306 * When toggling threaded comments, update thread depth in blogmeta table.
     307 *
     308 * @since BuddyPress (2.0.0)
     309 *
     310 * @global object $wpdb DB Layer.
     311 *
     312 * @param string $oldvalue Value before save. Passed by do_action() but
     313 *        unused here.
     314 * @param string $newvalue Value to change meta to.
     315 */
     316function bp_blogs_update_option_thread_comments( $oldvalue, $newvalue ) {
     317    global $wpdb;
     318
     319    if ( empty( $newvalue ) ) {
     320        $thread_depth = 1;
     321    } else {
     322        $thread_depth = get_option( 'thread_comments_depth' );
     323    }
     324
     325    bp_blogs_update_blogmeta( $wpdb->blogid, 'thread_comments_depth', $thread_depth );
     326}
     327add_action( 'update_option_thread_comments', 'bp_blogs_update_option_thread_comments', 10, 2 );
     328
     329/**
     330 * When updating comment depth, update thread depth in blogmeta table.
     331 *
     332 * @since BuddyPress (2.0.0)
     333 *
     334 * @global object $wpdb DB Layer.
     335 *
     336 * @param string $oldvalue Value before save. Passed by do_action() but
     337 *        unused here.
     338 * @param string $newvalue Value to change meta to.
     339 */
     340function bp_blogs_update_option_thread_comments_depth( $oldvalue, $newvalue ) {
     341    global $wpdb;
     342
     343    $comments_enabled = get_option( 'thread_comments' );
     344
     345    if (  $comments_enabled ) {
     346        bp_blogs_update_blogmeta( $wpdb->blogid, 'thread_comments_depth', $newvalue );
     347    }
     348}
     349add_action( 'update_option_thread_comments_depth', 'bp_blogs_update_option_thread_comments_depth', 10, 2 );
    253350
    254351/**
Note: See TracChangeset for help on using the changeset viewer.