BuddyPress - Version 1.2.2

Version Description

Download this release

Release Info

Developer apeatling
Plugin Icon 128x128 BuddyPress
Version 1.2.2
Comparing to
See all releases

Code changes from version 1.2.1 to 1.2.2

bp-activity.php CHANGED
@@ -1,6 +1,6 @@
1
<?php
2
3
- define ( 'BP_ACTIVITY_DB_VERSION', '2060' );
4
5
/* Define the slug for the component */
6
if ( !defined( 'BP_ACTIVITY_SLUG' ) )
@@ -44,8 +44,8 @@ function bp_activity_install() {
44
secondary_item_id varchar(75) DEFAULT NULL,
45
date_recorded datetime NOT NULL,
46
hide_sitewide bool DEFAULT 0,
47
- mptt_left int(11) NOT NULL,
48
- mptt_right int(11) NOT NULL,
49
KEY date_recorded (date_recorded),
50
KEY user_id (user_id),
51
KEY item_id (item_id),
@@ -247,7 +247,11 @@ function bp_activity_screen_single_activity_permalink() {
247
248
if ( !$has_access ) {
249
bp_core_add_message( __( 'You do not have access to this activity.', 'buddypress' ), 'error' );
250
- bp_core_redirect( $bp->loggedin_user->domain );
251
}
252
253
bp_core_load_template( apply_filters( 'bp_activity_template_profile_activity_permalink', 'members/single/activity/permalink' ) );
@@ -311,19 +315,21 @@ function bp_activity_action_permalink_router() {
311
/* Redirect based on the type of activity */
312
if ( $activity->component == $bp->groups->id ) {
313
if ( $activity->user_id )
314
- $redirect = bp_core_get_user_domain( $activity->user_id, $activity->user_nicename, $activity->user_login ) . $bp->activity->slug . '/' . $activity->id;
315
else {
316
if ( $group = groups_get_group( array( 'group_id' => $activity->item_id ) ) )
317
- $redirect = bp_get_group_permalink( $group ) . $bp->activity->slug . '/' . $activity->id;
318
}
319
} else
320
$redirect = bp_core_get_user_domain( $activity->user_id, $activity->user_nicename, $activity->user_login ) . $bp->activity->slug . '/' . $activity->id;
321
322
if ( !$redirect )
323
bp_core_redirect( $bp->root_domain );
324
325
/* Redirect to the actual activity permalink page */
326
- bp_core_redirect( apply_filters( 'bp_activity_action_permalink_url', $redirect . '/', &$activity ) );
327
}
328
add_action( 'wp', 'bp_activity_action_permalink_router', 3 );
329
@@ -714,6 +720,7 @@ function bp_activity_new_comment( $args = '' ) {
714
global $bp;
715
716
$defaults = array(
717
'content' => false,
718
'user_id' => $bp->loggedin_user->id,
719
'activity_id' => false, // ID of the root activity item
@@ -735,6 +742,7 @@ function bp_activity_new_comment( $args = '' ) {
735
736
/* Insert the activity comment */
737
$comment_id = bp_activity_add( array(
738
'action' => apply_filters( 'bp_activity_comment_action', sprintf( __( '%s posted a new activity comment:', 'buddypress' ), bp_core_get_userlink( $user_id ) ) ),
739
'content' => apply_filters( 'bp_activity_comment_content', $content ),
740
'component' => $bp->activity->id,
@@ -772,13 +780,14 @@ function bp_activity_get_activity_id( $args = '' ) {
772
'item_id' => false,
773
'secondary_item_id' => false,
774
'action' => false,
775
- 'content' => false
776
);
777
778
$r = wp_parse_args( $args, $defaults );
779
extract( $r, EXTR_SKIP );
780
781
- return apply_filters( 'bp_activity_get_activity_id', BP_Activity_Activity::get_id( $user_id, $component, $type, $item_id, $secondary_item_id, $action, $content ) );
782
}
783
784
/***
1
<?php
2
3
+ define ( 'BP_ACTIVITY_DB_VERSION', '2100' );
4
5
/* Define the slug for the component */
6
if ( !defined( 'BP_ACTIVITY_SLUG' ) )
44
secondary_item_id varchar(75) DEFAULT NULL,
45
date_recorded datetime NOT NULL,
46
hide_sitewide bool DEFAULT 0,
47
+ mptt_left int(11) NOT NULL DEFAULT 0,
48
+ mptt_right int(11) NOT NULL DEFAULT 0,
49
KEY date_recorded (date_recorded),
50
KEY user_id (user_id),
51
KEY item_id (item_id),
247
248
if ( !$has_access ) {
249
bp_core_add_message( __( 'You do not have access to this activity.', 'buddypress' ), 'error' );
250
+
251
+ if ( is_user_logged_in() )
252
+ bp_core_redirect( $bp->loggedin_user->domain );
253
+ else
254
+ bp_core_redirect( site_url( 'wp-login.php?redirect_to=' . clean_url( $bp->root_domain . '/' . $bp->activity->slug . '/p/' . $bp->current_action ) ) );
255
}
256
257
bp_core_load_template( apply_filters( 'bp_activity_template_profile_activity_permalink', 'members/single/activity/permalink' ) );
315
/* Redirect based on the type of activity */
316
if ( $activity->component == $bp->groups->id ) {
317
if ( $activity->user_id )
318
+ $redirect = bp_core_get_user_domain( $activity->user_id, $activity->user_nicename, $activity->user_login ) . $bp->activity->slug . '/' . $activity->id . '/';
319
else {
320
if ( $group = groups_get_group( array( 'group_id' => $activity->item_id ) ) )
321
+ $redirect = bp_get_group_permalink( $group ) . $bp->activity->slug . '/' . $activity->id . '/';
322
}
323
} else
324
$redirect = bp_core_get_user_domain( $activity->user_id, $activity->user_nicename, $activity->user_login ) . $bp->activity->slug . '/' . $activity->id;
325
326
+ $redirect = apply_filters( 'bp_activity_permalink_redirect_url', $redirect, &$activity );
327
+
328
if ( !$redirect )
329
bp_core_redirect( $bp->root_domain );
330
331
/* Redirect to the actual activity permalink page */
332
+ bp_core_redirect( $redirect );
333
}
334
add_action( 'wp', 'bp_activity_action_permalink_router', 3 );
335
720
global $bp;
721
722
$defaults = array(
723
+ 'id' => false,
724
'content' => false,
725
'user_id' => $bp->loggedin_user->id,
726
'activity_id' => false, // ID of the root activity item
742
743
/* Insert the activity comment */
744
$comment_id = bp_activity_add( array(
745
+ 'id' => $id,
746
'action' => apply_filters( 'bp_activity_comment_action', sprintf( __( '%s posted a new activity comment:', 'buddypress' ), bp_core_get_userlink( $user_id ) ) ),
747
'content' => apply_filters( 'bp_activity_comment_content', $content ),
748
'component' => $bp->activity->id,
780
'item_id' => false,
781
'secondary_item_id' => false,
782
'action' => false,
783
+ 'content' => false,
784
+ 'date_recorded' => false,
785
);
786
787
$r = wp_parse_args( $args, $defaults );
788
extract( $r, EXTR_SKIP );
789
790
+ return apply_filters( 'bp_activity_get_activity_id', BP_Activity_Activity::get_id( $user_id, $component, $type, $item_id, $secondary_item_id, $action, $content, $date_recorded ) );
791
}
792
793
/***
bp-activity/bp-activity-classes.php CHANGED
@@ -198,7 +198,7 @@ Class BP_Activity_Activity {
198
return array( 'activities' => $activities, 'total' => (int)$total_activities );
199
}
200
201
- function get_id( $user_id, $component, $type, $item_id, $secondary_item_id, $action, $content ) {
202
global $bp, $wpdb;
203
204
$where_args = false;
@@ -224,6 +224,9 @@ Class BP_Activity_Activity {
224
if ( !empty( $content ) )
225
$where_args[] = $wpdb->prepare( "content = %s", $content );
226
227
if ( !empty( $where_args ) )
228
$where_sql = 'WHERE ' . join( ' AND ', $where_args );
229
else
198
return array( 'activities' => $activities, 'total' => (int)$total_activities );
199
}
200
201
+ function get_id( $user_id, $component, $type, $item_id, $secondary_item_id, $action, $content, $date_recorded ) {
202
global $bp, $wpdb;
203
204
$where_args = false;
224
if ( !empty( $content ) )
225
$where_args[] = $wpdb->prepare( "content = %s", $content );
226
227
+ if ( !empty( $date_recorded ) )
228
+ $where_args[] = $wpdb->prepare( "date_recorded = %s", $date_recorded );
229
+
230
if ( !empty( $where_args ) )
231
$where_sql = 'WHERE ' . join( ' AND ', $where_args );
232
else
bp-activity/bp-activity-templatetags.php CHANGED
@@ -540,7 +540,7 @@ function bp_activity_parent_content( $args = '' ) {
540
}
541
542
function bp_activity_is_favorite() {
543
- echo bp_get_is_activity_favorite();
544
}
545
function bp_get_activity_is_favorite() {
546
global $bp, $activities_template;
540
}
541
542
function bp_activity_is_favorite() {
543
+ echo bp_get_activity_is_favorite();
544
}
545
function bp_get_activity_is_favorite() {
546
global $bp, $activities_template;
bp-blogs.php CHANGED
@@ -27,30 +27,6 @@ function bp_blogs_install() {
27
KEY blog_id (blog_id)
28
) {$charset_collate};";
29
30
- $sql[] = "CREATE TABLE {$bp->blogs->table_name_blog_posts} (
31
- id bigint(20) NOT NULL AUTO_INCREMENT PRIMARY KEY,
32
- user_id bigint(20) NOT NULL,
33
- blog_id bigint(20) NOT NULL,
34
- post_id bigint(20) NOT NULL,
35
- date_created datetime NOT NULL,
36
- KEY user_id (user_id),
37
- KEY blog_id (blog_id),
38
- KEY post_id (post_id)
39
- ) {$charset_collate};";
40
-
41
- $sql[] = "CREATE TABLE {$bp->blogs->table_name_blog_comments} (
42
- id bigint(20) NOT NULL AUTO_INCREMENT PRIMARY KEY,
43
- user_id bigint(20) NOT NULL,
44
- blog_id bigint(20) NOT NULL,
45
- comment_id bigint(20) NOT NULL,
46
- comment_post_id bigint(20) NOT NULL,
47
- date_created datetime NOT NULL,
48
- KEY user_id (user_id),
49
- KEY blog_id (blog_id),
50
- KEY comment_id (comment_id),
51
- KEY comment_post_id (comment_post_id)
52
- ) {$charset_collate};";
53
-
54
$sql[] = "CREATE TABLE {$bp->blogs->table_name_blogmeta} (
55
id bigint(20) NOT NULL AUTO_INCREMENT PRIMARY KEY,
56
blog_id bigint(20) NOT NULL,
@@ -93,8 +69,6 @@ function bp_blogs_setup_globals() {
93
$bp->blogs->id = 'blogs';
94
95
$bp->blogs->table_name = $wpdb->base_prefix . 'bp_user_blogs';
96
- $bp->blogs->table_name_blog_posts = $wpdb->base_prefix . 'bp_user_blogs_posts';
97
- $bp->blogs->table_name_blog_comments = $wpdb->base_prefix . 'bp_user_blogs_comments';
98
$bp->blogs->table_name_blogmeta = $wpdb->base_prefix . 'bp_user_blogs_blogmeta';
99
$bp->blogs->format_notification_function = 'bp_blogs_format_notifications';
100
$bp->blogs->slug = BP_BLOGS_SLUG;
@@ -182,16 +156,6 @@ function bp_blogs_screen_my_blogs() {
182
bp_core_load_template( apply_filters( 'bp_blogs_template_my_blogs', 'members/single/home' ) );
183
}
184
185
- function bp_blogs_screen_recent_posts() {
186
- do_action( 'bp_blogs_screen_recent_posts' );
187
- bp_core_load_template( apply_filters( 'bp_blogs_template_recent_posts', 'members/single/home' ) );
188
- }
189
-
190
- function bp_blogs_screen_recent_comments() {
191
- do_action( 'bp_blogs_screen_recent_comments' );
192
- bp_core_load_template( apply_filters( 'bp_blogs_template_recent_comments', 'members/single/home' ) );
193
- }
194
-
195
function bp_blogs_screen_create_a_blog() {
196
global $bp;
197
@@ -330,7 +294,6 @@ function bp_blogs_get_blogs( $args = '' ) {
330
return apply_filters( 'bp_blogs_get_blogs', BP_Blogs_Blog::get( $type, $per_page, $page, $user_id, $search_terms ), &$params );
331
}
332
333
-
334
function bp_blogs_record_existing_blogs() {
335
global $bp, $wpdb;
336
@@ -402,7 +365,7 @@ function bp_blogs_record_post( $post_id, $post, $user_id = false ) {
402
if ( !$user_id )
403
$user_id = (int)$post->post_author;
404
405
- /* This is to stop infinate loops with Donncha's sitewide tags plugin */
406
if ( (int)$bp->site_options['tags_blog_id'] == (int)$blog_id )
407
return false;
408
@@ -410,59 +373,11 @@ function bp_blogs_record_post( $post_id, $post, $user_id = false ) {
410
if ( $post->post_type != 'post' )
411
return false;
412
413
- if ( !$is_recorded = BP_Blogs_Post::is_recorded( $post_id, $blog_id, $user_id ) ) {
414
- if ( 'publish' == $post->post_status && '' == $post->post_password ) {
415
-
416
- /* If we're on a multiblog install, record this post */
417
- if ( bp_core_is_multisite() ) {
418
- $recorded_post = new BP_Blogs_Post;
419
- $recorded_post->user_id = $user_id;
420
- $recorded_post->blog_id = $blog_id;
421
- $recorded_post->post_id = $post_id;
422
- $recorded_post->date_created = strtotime( $post->post_date );
423
-
424
- $recorded_post_id = $recorded_post->save();
425
-
426
- bp_blogs_update_blogmeta( $recorded_post->blog_id, 'last_activity', gmdate( "Y-m-d H:i:s" ) );
427
- }
428
-
429
- if ( (int)get_blog_option( $blog_id, 'blog_public' ) || !bp_core_is_multisite() ) {
430
- /* Record this in activity streams */
431
- $post_permalink = get_permalink( $post_id );
432
-
433
- $activity_action = sprintf( __( '%s wrote a new blog post: %s', 'buddypress' ), bp_core_get_userlink( (int)$post->post_author ), '<a href="' . $post_permalink . '">' . $post->post_title . '</a>' );
434
- $activity_content = $post->post_content;
435
-
436
- bp_blogs_record_activity( array(
437
- 'user_id' => (int)$post->post_author,
438
- 'action' => apply_filters( 'bp_blogs_activity_new_post_action', $activity_action, &$post, $post_permalink ),
439
- 'content' => apply_filters( 'bp_blogs_activity_new_post_content', $activity_content, &$post, $post_permalink ),
440
- 'primary_link' => apply_filters( 'bp_blogs_activity_new_post_primary_link', $post_permalink, $post_id ),
441
- 'type' => 'new_blog_post',
442
- 'item_id' => $blog_id,
443
- 'secondary_item_id' => $post_id,
444
- 'recorded_time' => $post->post_date_gmt
445
- ));
446
- }
447
- }
448
- } else {
449
- $existing_post = new BP_Blogs_Post( null, $blog_id, $post_id );
450
-
451
- /* Delete the recorded post if the status is not published or it is password protected */
452
- if ( 'publish' != $post->post_status || '' != $post->post_password ) {
453
- return bp_blogs_remove_post( $post_id, $blog_id, $existing_post );
454
-
455
- /* If the post author has changed, delete the post and re-add it. */
456
- } else if ( (int)$existing_post->user_id != (int)$post->post_author ) {
457
- // Delete the existing recorded post
458
- bp_blogs_remove_post( $post_id, $blog_id, $existing_post );
459
-
460
- // Re-record the post with the new author.
461
- bp_blogs_record_post( $post_id );
462
- }
463
464
if ( (int)get_blog_option( $blog_id, 'blog_public' ) || !bp_core_is_multisite() ) {
465
- /* Now re-record the post in the activity streams */
466
$post_permalink = get_permalink( $post_id );
467
468
$activity_action = sprintf( __( '%s wrote a new blog post: %s', 'buddypress' ), bp_core_get_userlink( (int)$post->post_author ), '<a href="' . $post_permalink . '">' . $post->post_title . '</a>' );
@@ -477,20 +392,18 @@ function bp_blogs_record_post( $post_id, $post, $user_id = false ) {
477
'item_id' => $blog_id,
478
'secondary_item_id' => $post_id,
479
'recorded_time' => $post->post_date_gmt
480
- ) );
481
}
482
- }
483
484
- do_action( 'bp_blogs_new_blog_post', $existing_post, $is_private, $is_recorded );
485
}
486
add_action( 'save_post', 'bp_blogs_record_post', 10, 2 );
487
488
- function bp_blogs_record_comment( $comment_id, $is_approved ) {
489
global $wpdb, $bp;
490
491
- if ( !$is_approved )
492
- return false;
493
-
494
$comment = get_comment($comment_id);
495
$comment->post = get_post( $comment->comment_post_ID );
496
@@ -505,20 +418,6 @@ function bp_blogs_record_comment( $comment_id, $is_approved ) {
505
if ( !empty( $post->post_password ) )
506
return false;
507
508
- /* If we're on a multiblog install, record this post */
509
- if ( bp_core_is_multisite() ) {
510
- $recorded_comment = new BP_Blogs_Comment;
511
- $recorded_comment->user_id = $user_id;
512
- $recorded_comment->blog_id = $wpdb->blogid;
513
- $recorded_comment->comment_id = $comment_id;
514
- $recorded_comment->comment_post_id = $comment->comment_post_ID;
515
- $recorded_comment->date_created = strtotime( $comment->comment_date_gmt );
516
-
517
- $recorded_commment_id = $recorded_comment->save();
518
-
519
- bp_blogs_update_blogmeta( $recorded_comment->blog_id, 'last_activity', gmdate( "Y-m-d H:i:s" ) );
520
- }
521
-
522
if ( (int)get_blog_option( $recorded_comment->blog_id, 'blog_public' ) || !bp_core_is_multisite() ) {
523
/* Record in activity streams */
524
$comment_link = get_permalink( $comment->comment_post_ID ) . '#comment-' . $comment_id;
@@ -541,6 +440,7 @@ function bp_blogs_record_comment( $comment_id, $is_approved ) {
541
return $recorded_comment;
542
}
543
add_action( 'comment_post', 'bp_blogs_record_comment', 10, 2 );
544
545
function bp_blogs_manage_comment( $comment_id, $comment_status ) {
546
if ( 'spam' == $comment_status || 'hold' == $comment_status || 'delete' == $comment_status || 'trash' == $comment_status )
@@ -600,7 +500,7 @@ function bp_blogs_remove_blog_for_user( $user_id, $blog_id ) {
600
}
601
add_action( 'remove_user_from_blog', 'bp_blogs_remove_blog_for_user', 10, 2 );
602
603
- function bp_blogs_remove_post( $post_id, $blog_id = false, $existing_post = false ) {
604
global $current_blog, $bp;
605
606
$post_id = (int)$post_id;
@@ -608,12 +508,6 @@ function bp_blogs_remove_post( $post_id, $blog_id = false, $existing_post = fals
608
if ( !$blog_id )
609
$blog_id = (int)$current_blog->blog_id;
610
611
- if ( !$existing_post )
612
- $existing_post = new BP_Blogs_Post( null, $blog_id, $post_id );
613
-
614
- // Delete post from the bp_blogs table
615
- BP_Blogs_Post::delete( $post_id, $blog_id );
616
-
617
// Delete activity stream item
618
bp_blogs_delete_activity( array( 'item_id' => $blog_id, 'secondary_item_id' => $post_id, 'component' => $bp->blogs->slug, 'type' => 'new_blog_post' ) );
619
@@ -624,9 +518,6 @@ add_action( 'delete_post', 'bp_blogs_remove_post' );
624
function bp_blogs_remove_comment( $comment_id ) {
625
global $wpdb, $bp;
626
627
- $recorded_comment = new BP_Blogs_Comment( false, $wpdb->blogid, $comment_id );
628
- BP_Blogs_Comment::delete( $comment_id, $wpdb->blogid );
629
-
630
// Delete activity stream item
631
bp_blogs_delete_activity( array( 'item_id' => $wpdb->blogid , 'secondary_item_id' => $comment_id, 'type' => 'new_blog_comment' ) );
632
@@ -662,8 +553,6 @@ function bp_blogs_remove_data_for_blog( $blog_id ) {
662
663
/* If this is regular blog, delete all data for that blog. */
664
BP_Blogs_Blog::delete_blog_for_all( $blog_id );
665
- BP_Blogs_Post::delete_posts_for_blog( $blog_id );
666
- BP_Blogs_Comment::delete_comments_for_blog( $blog_id );
667
668
// Delete activity stream item
669
bp_blogs_delete_activity( array( 'item_id' => $blog_id, 'component' => $bp->blogs->slug, 'type' => false ) );
@@ -676,25 +565,6 @@ function bp_blogs_get_blogs_for_user( $user_id, $show_hidden = false ) {
676
return BP_Blogs_Blog::get_blogs_for_user( $user_id, $show_hidden );
677
}
678
679
- /* DEPRECATED - scheduled for removal. Please use the activity stream with a 'new_blog_post' filter. */
680
- function bp_blogs_get_posts_for_user( $user_id ) {
681
- return BP_Blogs_Post::get_posts_for_user( $user_id );
682
- }
683
-
684
- /* DEPRECATED - scheduled for removal. Please use the activity stream with a 'new_blog_comment' filter. */
685
- function bp_blogs_get_comments_for_user( $user_id ) {
686
- return BP_Blogs_Comment::get_comments_for_user( $user_id );
687
- }
688
-
689
- function bp_blogs_get_latest_posts( $blog_id = null, $limit = 5 ) {
690
- global $bp;
691
-
692
- if ( !is_numeric( $limit ) )
693
- $limit = 5;
694
-
695
- return BP_Blogs_Post::get_latest_posts( $blog_id, $limit );
696
- }
697
-
698
function bp_blogs_get_all_blogs( $limit = null, $page = null ) {
699
return BP_Blogs_Blog::get_all( $limit, $page );
700
}
@@ -703,18 +573,6 @@ function bp_blogs_get_random_blogs( $limit = null, $page = null ) {
703
return BP_Blogs_Blog::get( 'random', $limit, $page );
704
}
705
706
- function bp_blogs_get_all_posts( $limit = null, $page = null ) {
707
- return BP_Blogs_Post::get_all( $limit, $page );
708
- }
709
-
710
- function bp_blogs_total_post_count( $blog_id ) {
711
- return BP_Blogs_Post::total_post_count( $blog_id );
712
- }
713
-
714
- function bp_blogs_total_comment_count( $blog_id, $post_id = false ) {
715
- return BP_Blogs_Post::total_comment_count( $blog_id, $post_id );
716
- }
717
-
718
function bp_blogs_is_blog_hidden( $blog_id ) {
719
return BP_Blogs_Blog::is_hidden( $blog_id );
720
}
@@ -831,10 +689,11 @@ function bp_blogs_update_blogmeta( $blog_id, $meta_key, $meta_value ) {
831
}
832
833
function bp_blogs_remove_data( $user_id ) {
834
/* If this is regular blog, delete all data for that blog. */
835
BP_Blogs_Blog::delete_blogs_for_user( $user_id );
836
- BP_Blogs_Post::delete_posts_for_user( $user_id );
837
- BP_Blogs_Comment::delete_comments_for_user( $user_id );
838
839
do_action( 'bp_blogs_remove_data', $user_id );
840
}
@@ -866,36 +725,9 @@ function bp_blogs_format_clear_blog_cache( $recorded_blog_obj ) {
866
wp_cache_delete( 'bp_total_blogs', 'bp' );
867
}
868
869
- function bp_blogs_clear_post_object_cache( $blog_id, $post_id, $user_id ) {
870
- wp_cache_delete( 'bp_user_posts_' . $user_id, 'bp' );
871
- }
872
-
873
- function bp_blogs_format_clear_post_cache( $recorded_post_obj ) {
874
- bp_blogs_clear_post_object_cache( false, false, $recorded_post_obj->user_id );
875
-
876
- /* Clear the sitewide activity cache */
877
- wp_cache_delete( 'sitewide_activity', 'bp' );
878
- }
879
-
880
- function bp_blogs_clear_comment_object_cache( $blog_id, $comment_id, $user_id ) {
881
- wp_cache_delete( 'bp_user_comments_' . $user_id, 'bp' );
882
- }
883
-
884
- function bp_blogs_format_clear_comment_cache( $recorded_comment_obj ) {
885
- bp_blogs_clear_comment_object_cache( false, false, $recorded_comment_obj->user_id );
886
-
887
- /* Clear the sitewide activity cache */
888
- wp_cache_delete( 'sitewide_activity', 'bp' );
889
- }
890
-
891
// List actions to clear object caches on
892
add_action( 'bp_blogs_remove_blog_for_user', 'bp_blogs_clear_blog_object_cache', 10, 2 );
893
- add_action( 'bp_blogs_remove_post', 'bp_blogs_clear_post_object_cache', 10, 3 );
894
- add_action( 'bp_blogs_remove_comment', 'bp_blogs_clear_comment_object_cache', 10, 3 );
895
-
896
add_action( 'bp_blogs_new_blog', 'bp_blogs_format_clear_blog_cache', 10, 2 );
897
- add_action( 'bp_blogs_new_blog_post', 'bp_blogs_format_clear_post_cache', 10, 2 );
898
- add_action( 'bp_blogs_new_blog_comment', 'bp_blogs_format_clear_comment_cache', 10, 2 );
899
900
// List actions to clear super cached pages on, if super cache is installed
901
add_action( 'bp_blogs_remove_data_for_blog', 'bp_core_clear_cache' );
27
KEY blog_id (blog_id)
28
) {$charset_collate};";
29
30
$sql[] = "CREATE TABLE {$bp->blogs->table_name_blogmeta} (
31
id bigint(20) NOT NULL AUTO_INCREMENT PRIMARY KEY,
32
blog_id bigint(20) NOT NULL,
69
$bp->blogs->id = 'blogs';
70
71
$bp->blogs->table_name = $wpdb->base_prefix . 'bp_user_blogs';
72
$bp->blogs->table_name_blogmeta = $wpdb->base_prefix . 'bp_user_blogs_blogmeta';
73
$bp->blogs->format_notification_function = 'bp_blogs_format_notifications';
74
$bp->blogs->slug = BP_BLOGS_SLUG;
156
bp_core_load_template( apply_filters( 'bp_blogs_template_my_blogs', 'members/single/home' ) );
157
}
158
159
function bp_blogs_screen_create_a_blog() {
160
global $bp;
161
294
return apply_filters( 'bp_blogs_get_blogs', BP_Blogs_Blog::get( $type, $per_page, $page, $user_id, $search_terms ), &$params );
295
}
296
297
function bp_blogs_record_existing_blogs() {
298
global $bp, $wpdb;
299
365
if ( !$user_id )
366
$user_id = (int)$post->post_author;
367
368
+ /* This is to stop infinite loops with Donncha's sitewide tags plugin */
369
if ( (int)$bp->site_options['tags_blog_id'] == (int)$blog_id )
370
return false;
371
373
if ( $post->post_type != 'post' )
374
return false;
375
376
+ if ( 'publish' == $post->post_status && '' == $post->post_password ) {
377
+ bp_blogs_update_blogmeta( $recorded_post->blog_id, 'last_activity', gmdate( "Y-m-d H:i:s" ) );
378
379
if ( (int)get_blog_option( $blog_id, 'blog_public' ) || !bp_core_is_multisite() ) {
380
+ /* Record this in activity streams */
381
$post_permalink = get_permalink( $post_id );
382
383
$activity_action = sprintf( __( '%s wrote a new blog post: %s', 'buddypress' ), bp_core_get_userlink( (int)$post->post_author ), '<a href="' . $post_permalink . '">' . $post->post_title . '</a>' );
392
'item_id' => $blog_id,
393
'secondary_item_id' => $post_id,
394
'recorded_time' => $post->post_date_gmt
395
+ ));
396
}
397
+ } else
398
+ bp_blogs_remove_post( $post_id, $blog_id );
399
400
+ do_action( 'bp_blogs_new_blog_post', $post_id, $post, $user_id );
401
}
402
add_action( 'save_post', 'bp_blogs_record_post', 10, 2 );
403
404
+ function bp_blogs_record_comment( $comment_id, $is_approved = true ) {
405
global $wpdb, $bp;
406
407
$comment = get_comment($comment_id);
408
$comment->post = get_post( $comment->comment_post_ID );
409
418
if ( !empty( $post->post_password ) )
419
return false;
420
421
if ( (int)get_blog_option( $recorded_comment->blog_id, 'blog_public' ) || !bp_core_is_multisite() ) {
422
/* Record in activity streams */
423
$comment_link = get_permalink( $comment->comment_post_ID ) . '#comment-' . $comment_id;
440
return $recorded_comment;
441
}
442
add_action( 'comment_post', 'bp_blogs_record_comment', 10, 2 );
443
+ add_action( 'edit_comment', 'bp_blogs_record_comment', 10 );
444
445
function bp_blogs_manage_comment( $comment_id, $comment_status ) {
446
if ( 'spam' == $comment_status || 'hold' == $comment_status || 'delete' == $comment_status || 'trash' == $comment_status )
500
}
501
add_action( 'remove_user_from_blog', 'bp_blogs_remove_blog_for_user', 10, 2 );
502
503
+ function bp_blogs_remove_post( $post_id, $blog_id = false ) {
504
global $current_blog, $bp;
505
506
$post_id = (int)$post_id;
508
if ( !$blog_id )
509
$blog_id = (int)$current_blog->blog_id;
510
511
// Delete activity stream item
512
bp_blogs_delete_activity( array( 'item_id' => $blog_id, 'secondary_item_id' => $post_id, 'component' => $bp->blogs->slug, 'type' => 'new_blog_post' ) );
513
518
function bp_blogs_remove_comment( $comment_id ) {
519
global $wpdb, $bp;
520
521
// Delete activity stream item
522
bp_blogs_delete_activity( array( 'item_id' => $wpdb->blogid , 'secondary_item_id' => $comment_id, 'type' => 'new_blog_comment' ) );
523
553
554
/* If this is regular blog, delete all data for that blog. */
555
BP_Blogs_Blog::delete_blog_for_all( $blog_id );
556
557
// Delete activity stream item
558
bp_blogs_delete_activity( array( 'item_id' => $blog_id, 'component' => $bp->blogs->slug, 'type' => false ) );
565
return BP_Blogs_Blog::get_blogs_for_user( $user_id, $show_hidden );
566
}
567
568
function bp_blogs_get_all_blogs( $limit = null, $page = null ) {
569
return BP_Blogs_Blog::get_all( $limit, $page );
570
}
573
return BP_Blogs_Blog::get( 'random', $limit, $page );
574
}
575
576
function bp_blogs_is_blog_hidden( $blog_id ) {
577
return BP_Blogs_Blog::is_hidden( $blog_id );
578
}
689
}
690
691
function bp_blogs_remove_data( $user_id ) {
692
+ if ( !bp_core_is_multisite() )
693
+ return false;
694
+
695
/* If this is regular blog, delete all data for that blog. */
696
BP_Blogs_Blog::delete_blogs_for_user( $user_id );
697
698
do_action( 'bp_blogs_remove_data', $user_id );
699
}
725
wp_cache_delete( 'bp_total_blogs', 'bp' );
726
}
727
728
// List actions to clear object caches on
729
add_action( 'bp_blogs_remove_blog_for_user', 'bp_blogs_clear_blog_object_cache', 10, 2 );
730
add_action( 'bp_blogs_new_blog', 'bp_blogs_format_clear_blog_cache', 10, 2 );
731
732
// List actions to clear super cached pages on, if super cache is installed
733
add_action( 'bp_blogs_remove_data_for_blog', 'bp_core_clear_cache' );
bp-blogs/bp-blogs-classes.php CHANGED
@@ -278,16 +278,8 @@ Class BP_Blogs_Blog {
278
if ( empty( $blog_ids ) )
279
return $paged_blogs;
280
281
- /* Fetch lastest post for each blog. */
282
- $post_ids = $wpdb->get_results( $wpdb->prepare( "SELECT p.post_id, p.blog_id FROM {$bp->blogs->table_name_blog_posts} p LEFT JOIN {$wpdb->base_prefix}blogs b ON p.blog_id = b.blog_id WHERE b.deleted = 0 AND b.archived = '0' AND b.spam = 0 AND b.mature = 0 AND p.blog_id IN ( {$blog_ids} ) GROUP BY p.blog_id ORDER BY p.date_created DESC" ) );
283
-
284
- for ( $i = 0; $i < count( $paged_blogs ); $i++ ) {
285
- foreach ( (array)$post_ids as $post ) {
286
- if ( $post->blog_id == $paged_blogs[$i]->blog_id ) {
287
- $paged_blogs[$i]->latest_post = $wpdb->get_row( "SELECT post_title, guid FROM {$wpdb->base_prefix}" . $post->blog_id . "_posts WHERE post_status = 'publish' AND post_type = 'post' ORDER BY id DESC LIMIT 1" );
288
- }
289
- }
290
- }
291
292
/* Fetch the blog description for each blog (as it may be empty we can't fetch it in the main query). */
293
$blog_descs = $wpdb->get_results( $wpdb->prepare( "SELECT blog_id, meta_value as description FROM {$bp->blogs->table_name_blogmeta} WHERE meta_key = 'description' AND blog_id IN ( {$blog_ids} )" ) );
@@ -315,398 +307,4 @@ Class BP_Blogs_Blog {
315
}
316
}
317
318
- /* DEPRECATED - Post DB recording is scheduled for removal. Please use the activity stream to fetch a user's posts. */
319
- Class BP_Blogs_Post {
320
- var $id;
321
- var $user_id;
322
- var $blog_id;
323
- var $post_id;
324
- var $date_created;
325
-
326
- function bp_blogs_post( $id = null, $blog_id = null, $post_id = null ) {
327
- global $bp, $wpdb;
328
-
329
- if ( $id || ( !$id && $blog_id && $post_id ) ) {
330
- $this->id = $id;
331
- $this->blog_id = $blog_id;
332
- $this->post_id = $post_id;
333
- $this->populate();
334
- }
335
- }
336
-
337
- function populate() {
338
- global $wpdb, $bp;
339
-
340
- if ( $this->id )
341
- $post = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$bp->blogs->table_name_blog_posts} WHERE id = %d", $this->id ) );
342
- else
343
- $post = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$bp->blogs->table_name_blog_posts} WHERE blog_id = %d AND post_id = %d", $this->blog_id, $this->post_id ) );
344
-
345
- $this->id = $post->id;
346
- $this->user_id = $post->user_id;
347
- $this->blog_id = $post->blog_id;
348
- $this->post_id = $post->post_id;
349
- $this->date_created = $post->date_created;
350
- }
351
-
352
- function save() {
353
- global $wpdb, $bp;
354
-
355
- $this->post_id = apply_filters( 'bp_blogs_post_id_before_save', $this->post_id, $this->id );
356
- $this->blog_id = apply_filters( 'bp_blogs_post_blog_id_before_save', $this->blog_id, $this->id );
357
- $this->user_id = apply_filters( 'bp_blogs_post_user_id_before_save', $this->user_id, $this->id );
358
- $this->date_created = apply_filters( 'bp_blogs_post_date_created_before_save', $this->date_created, $this->id );
359
-
360
- do_action( 'bp_blogs_post_before_save', $this );
361
-
362
- if ( $this->id ) {
363
- // Update
364
- $sql = $wpdb->prepare( "UPDATE {$bp->blogs->table_name_blog_posts} SET post_id = %d, blog_id = %d, user_id = %d, date_created = FROM_UNIXTIME(%d) WHERE id = %d", $this->post_id, $this->blog_id, $this->user_id, $this->date_created, $this->id );
365
- } else {
366
- // Save
367
- $sql = $wpdb->prepare( "INSERT INTO {$bp->blogs->table_name_blog_posts} ( post_id, blog_id, user_id, date_created ) VALUES ( %d, %d, %d, FROM_UNIXTIME(%d) )", $this->post_id, $this->blog_id, $this->user_id, $this->date_created );
368
- }
369
-
370
- if ( !$wpdb->query($sql) )
371
- return false;
372
-
373
- do_action( 'bp_blogs_post_after_save', $this );
374
-
375
- if ( $this->id )
376
- return $this->id;
377
- else
378
- return $wpdb->insert_id;
379
- }
380
-
381
- /* Static Functions */
382
-
383
- function delete( $post_id, $blog_id ) {
384
- global $wpdb, $bp, $current_user;
385
-
386
- if ( !$bp->blogs )
387
- bp_blogs_setup_globals();
388
-
389
- return $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->blogs->table_name_blog_posts} WHERE blog_id = %d AND post_id = %d", $blog_id, $post_id ) );
390
- }
391
-
392
- function delete_oldest( $user_id = null ) {
393
- global $wpdb, $bp;
394
-
395
- if ( !$bp->blogs )
396
- bp_blogs_setup_globals();
397
-
398
- if ( !$user_id )
399
- $user_id = $current_user->ID;
400
-
401
- return $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->blogs->table_name_blog_posts} WHERE user_id = %d ORDER BY date_created ASC LIMIT 1", $user_id ) );
402
- }
403
-
404
- function delete_posts_for_user( $user_id = null ) {
405
- global $wpdb, $bp;
406
-
407
- if ( !$bp->blogs )
408
- bp_blogs_setup_globals();
409
-
410
- if ( !$user_id )
411
- $user_id = $bp->loggedin_user->id;
412
-
413
- return $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->blogs->table_name_blog_posts} WHERE user_id = %d", $user_id ) );
414
- }
415
-
416
- function delete_posts_for_blog( $blog_id ) {
417
- global $wpdb, $bp;
418
-
419
- if ( !$bp->blogs )
420
- bp_blogs_setup_globals();
421
-
422
- return $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->blogs->table_name_blog_posts} WHERE blog_id = %d", $blog_id ) );
423
- }
424
-
425
- function get_latest_posts( $blog_id = null, $limit = 5 ) {
426
- global $wpdb, $bp;
427
-
428
- if ( !$bp->blogs )
429
- bp_blogs_setup_globals();
430
-
431
- if ( $blog_id )
432
- $blog_sql = $wpdb->prepare( " AND p.blog_id = %d", $blog_id );
433
-
434
- $post_ids = $wpdb->get_results( $wpdb->prepare( "SELECT DISTINCT p.post_id, p.blog_id FROM {$bp->blogs->table_name_blog_posts} p LEFT JOIN {$wpdb->base_prefix}blogs b ON p.blog_id = b.blog_id WHERE b.public = 1 AND b.deleted = 0 AND b.archived = '0' AND b.spam = 0 AND b.mature = 0 $blog_sql ORDER BY p.date_created DESC LIMIT $limit" ) );
435
-
436
- for ( $i = 0; $i < count($post_ids); $i++ ) {
437
- $posts[$i] = BP_Blogs_Post::fetch_post_content($post_ids[$i]);
438
- }
439
-
440
- return $posts;
441
- }
442
-
443
- function get_posts_for_user( $user_id = null ) {
444
- global $bp, $wpdb;
445
-
446
- if ( !$bp->blogs )
447
- bp_blogs_setup_globals();
448
-
449
- if ( !$user_id )
450
- $user_id = $bp->displayed_user->id;
451
-
452
- // Show a logged in user their posts on private blogs, but not anyone else.
453
- if ( !bp_is_my_profile() ) {
454
- $post_ids = $wpdb->get_results( $wpdb->prepare( "SELECT p.post_id, p.blog_id FROM {$bp->blogs->table_name_blog_posts} p LEFT JOIN {$wpdb->base_prefix}blogs b ON p.blog_id = b.blog_id WHERE b.public = 1 AND b.deleted = 0 AND b.archived = '0' AND b.spam = 0 AND b.mature = 0 AND p.user_id = %d ORDER BY p.date_created DESC", $user_id) );
455
- $total_post_count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(p.post_id) FROM {$bp->blogs->table_name_blog_posts} p LEFT JOIN {$wpdb->base_prefix}blogs b ON p.blog_id = b.blog_id WHERE b.public = 1 AND b.deleted = 0 AND b.archived = '0' AND b.spam = 0 AND b.mature = 0 AND p.user_id = %d", $user_id) );
456
- } else {
457
- $post_ids = $wpdb->get_results( $wpdb->prepare( "SELECT p.post_id, p.blog_id FROM {$bp->blogs->table_name_blog_posts} p LEFT JOIN {$wpdb->base_prefix}blogs b ON p.blog_id = b.blog_id WHERE b.deleted = 0 AND b.archived = '0' AND b.spam = 0 AND b.mature = 0 AND p.user_id = %d ORDER BY p.date_created DESC", $user_id) );
458
-
459
- $total_post_count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(p.post_id) FROM {$bp->blogs->table_name_blog_posts} p LEFT JOIN {$wpdb->base_prefix}blogs b ON p.blog_id = b.blog_id WHERE b.deleted = 0 AND b.archived = '0' AND b.spam = 0 AND b.mature = 0 AND p.user_id = %d", $user_id) );
460
- }
461
-
462
- for ( $i = 0; $i < count($post_ids); $i++ ) {
463
- $posts[$i] = BP_Blogs_Post::fetch_post_content($post_ids[$i]);
464
- }
465
-
466
- return array( 'posts' => $posts, 'count' => $total_post_count );
467
- }
468
-
469
- function fetch_post_content( $post_object ) {
470
- // TODO: switch_to_blog() calls are expensive and this needs to be changed.
471
- switch_to_blog( $post_object->blog_id );
472
- $post = get_post($post_object->post_id);
473
- $post->blog_id = $post_object->blog_id;
474
- restore_current_blog();
475
-
476
- return $post;
477
- }
478
-
479
- function get_total_recorded_for_user( $user_id = null ) {
480
- global $bp, $wpdb;
481
-
482
- if ( !$bp->blogs )
483
- bp_blogs_setup_globals();
484
-
485
- if ( !$user_id )
486
- $user_id = $current_user->ID;
487
-
488
- return $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(post_id) FROM {$bp->blogs->table_name_blog_posts} WHERE user_id = %d", $user_id ) );
489
- }
490
-
491
- function is_recorded( $post_id, $blog_id, $user_id = null ) {
492
- global $bp, $wpdb, $current_user;
493
-
494
- if ( !$bp->blogs )
495
- bp_blogs_setup_globals();
496
-
497
- if ( !$user_id )
498
- $user_id = $current_user->ID;
499
-
500
- return $wpdb->get_var( $wpdb->prepare( "SELECT post_id FROM {$bp->blogs->table_name_blog_posts} WHERE post_id = %d AND blog_id = %d AND user_id = %d", $post_id, $blog_id, $user_id ) );
501
- }
502
-
503
- function total_post_count( $blog_id ) {
504
- global $bp, $wpdb;
505
-
506
- if ( !$bp->blogs )
507
- bp_blogs_setup_globals();
508
-
509
- if ( !$blog_id )
510
- return false;
511
-
512
- return $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(post_id) FROM {$bp->blogs->table_name_blog_posts} WHERE blog_id = %d", $blog_id ) );
513
- }
514
-
515
- function get_all() {
516
- global $bp, $wpdb;
517
-
518
- if ( !$bp->blogs )
519
- bp_blogs_setup_globals();
520
-
521
- return $wpdb->get_col( $wpdb->prepare( "SELECT post_id, blog_id FROM " . $bp->blogs->table_name_blog_posts ) );
522
- }
523
-
524
- }
525
-
526
- /* DEPRECATED - Comment DB recording is scheduled for removal. Please use the activity stream to fetch a user's comments. */
527
- Class BP_Blogs_Comment {
528
- var $id;
529
- var $user_id;
530
- var $blog_id;
531
- var $comment_id;
532
- var $comment_post_id;
533
- var $date_created;
534
-
535
- function bp_blogs_comment( $id = false, $blog_id = false, $comment_id = false ) {
536
- global $bp, $wpdb;
537
-
538
- if ( !$user_id )
539
- $user_id = $bp->displayed_user->id;
540
-
541
- if ( $id || ( !$id && $blog_id && $comment_id ) ) {
542
- $this->id = $id;
543
- $this->blog_id = $blog_id;
544
- $this->comment_id = $comment_id;
545
- $this->populate();
546
- }
547
- }
548
-
549
- function populate() {
550
- global $wpdb, $bp;
551
-
552
- if ( $this->id )
553
- $comment = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$bp->blogs->table_name_blog_comments} WHERE id = %d", $this->id ) );
554
- else
555
- $comment = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$bp->blogs->table_name_blog_comments} WHERE blog_id = %d AND comment_id = %d", (int)$this->blog_id, (int)$this->comment_id ) );
556
-
557
- $this->comment_id = $comment->comment_id;
558
- $this->user_id = $comment->user_id;
559
- $this->blog_id = $comment->blog_id;
560
- $this->comment_post_id = $comment->comment_post_id;
561
- $this->date_created = $comment->date_created;
562
- }
563
-
564
- function save() {
565
- global $wpdb, $bp;
566
-
567
- $this->comment_id = apply_filters( 'bp_blogs_comment_id_before_save', $this->comment_id, $this->id );
568
- $this->comment_post_id = apply_filters( 'bp_blogs_comment_post_id_before_save', $this->comment_post_id, $this->id );
569
- $this->blog_id = apply_filters( 'bp_blogs_comment_blog_id_before_save', $this->blog_id, $this->id );
570
- $this->user_id = apply_filters( 'bp_blogs_comment_user_id_before_save', $this->user_id, $this->id );
571
- $this->date_created = apply_filters( 'bp_blogs_comment_date_created_before_save', $this->date_created, $this->id );
572
-
573
- do_action( 'bp_blogs_comment_before_save', $this );
574
-
575
- if ( $this->id ) {
576
- // Update
577
- $sql = $wpdb->prepare( "UPDATE {$bp->blogs->table_name_blog_comments} SET comment_id = %d, comment_post_id = %d, blog_id = %d, user_id = %d, date_created = FROM_UNIXTIME(%d) WHERE id = %d", $this->comment_id, $this->comment_post_id, $this->blog_id, $this->user_id, $this->date_created, $this->id );
578
- } else {
579
- // Save
580
- $sql = $wpdb->prepare( "INSERT INTO {$bp->blogs->table_name_blog_comments} ( comment_id, comment_post_id, blog_id, user_id, date_created ) VALUES ( %d, %d, %d, %d, FROM_UNIXTIME(%d) )", $this->comment_id, $this->comment_post_id, $this->blog_id, $this->user_id, $this->date_created );
581
- }
582
-
583
- if ( !$wpdb->query($sql) )
584
- return false;
585
-
586
- do_action( 'bp_blogs_comment_after_save', $this );
587
-
588
- if ( $this->id )
589
- return $this->id;
590
- else
591
- return $wpdb->insert_id;
592
- }
593
-
594
- /* Static Functions */
595
-
596
- function delete( $comment_id, $blog_id ) {
597
- global $wpdb, $bp, $current_user;
598
-
599
- if ( !$bp->blogs )
600
- bp_blogs_setup_globals();
601
-
602
- return $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->blogs->table_name_blog_comments} WHERE comment_id = %d AND blog_id = %d", $comment_id, $blog_id ) );
603
- }
604
-
605
- function delete_oldest( $user_id = null ) {
606
- global $wpdb, $bp, $current_user;
607
-
608
- if ( !$bp->blogs )
609
- bp_blogs_setup_globals();
610
-
611
- if ( !$user_id )
612
- $user_id = $current_user->ID;
613
-
614
- return $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->blogs->table_name_blog_comments} WHERE user_id = %d ORDER BY date_created ASC LIMIT 1", $user_id ) );
615
- }
616
-
617
- function delete_comments_for_user( $user_id = null ) {
618
- global $wpdb, $bp;
619
-
620
- if ( !$bp->blogs )
621
- bp_blogs_setup_globals();
622
-
623
- if ( !$user_id )
624
- $user_id = $bp->loggedin_user->id;
625
-
626
- return $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->blogs->table_name_blog_comments} WHERE user_id = %d", $user_id ) );
627
- }
628
-
629
- function delete_comments_for_blog( $blog_id ) {
630
- global $wpdb, $bp;
631
-
632
- if ( !$bp->blogs )
633
- bp_blogs_setup_globals();
634
-
635
- return $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->blogs->table_name_blog_comments} WHERE blog_id = %d", $blog_id ) );
636
- }
637
-
638
- function get_comments_for_user( $user_id = null ) {
639
- global $bp, $wpdb;
640
-
641
- if ( !$bp->blogs )
642
- bp_blogs_setup_globals();
643
-
644
- if ( !$user_id )
645
- $user_id = $bp->displayed_user->id;
646
-
647
- // Show the logged in user their comments on hidden blogs, but not to anyone else.
648
- if ( !bp_is_my_profile() ) {
649
- $comment_ids = $wpdb->get_results( $wpdb->prepare( "SELECT c.comment_id, c.blog_id FROM {$bp->blogs->table_name_blog_comments} c LEFT JOIN {$wpdb->base_prefix}blogs b ON c.blog_id = b.blog_id WHERE b.public = 1 AND b.deleted = 0 AND b.archived = '0' AND b.spam = 0 AND b.mature = 0 AND c.user_id = %d ORDER BY c.date_created ASC", $user_id) );
650
- $total_comment_count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(c.comment_id) FROM {$bp->blogs->table_name_blog_comments} c LEFT JOIN {$wpdb->base_prefix}blogs b ON c.blog_id = b.blog_id WHERE b.public = 1 AND b.deleted = 0 AND b.archived = '0' AND b.spam = 0 AND b.mature = 0 AND c.user_id = %d", $user_id) );
651
- } else {
652
- $comment_ids = $wpdb->get_results( $wpdb->prepare( "SELECT c.comment_id, c.blog_id FROM {$bp->blogs->table_name_blog_comments} c LEFT JOIN {$wpdb->base_prefix}blogs b ON c.blog_id = b.blog_id WHERE b.deleted = 0 AND b.archived = '0' AND b.spam = 0 AND b.mature = 0 AND c.user_id = %d ORDER BY c.date_created ASC", $user_id) );
653
-
654
- $total_comment_count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(c.comment_id) FROM {$bp->blogs->table_name_blog_comments} c LEFT JOIN {$wpdb->base_prefix}blogs b ON c.blog_id = b.blog_id WHERE b.deleted = 0 AND b.archived = '0' AND b.spam = 0 AND b.mature = 0 AND c.user_id = %d", $user_id) );
655
- }
656
-
657
- for ( $i = 0; $i < count($comment_ids); $i++ )
658
- $comments[$i] = BP_Blogs_Comment::fetch_comment_content($comment_ids[$i]);
659
-
660
- return array( 'comments' => $comments, 'count' => $total_comment_count );
661
- }
662
-
663
- function fetch_comment_content( $comment_object ) {
664
- switch_to_blog($comment_object->blog_id);
665
- $comment = get_comment($comment_object->comment_id);
666
- $comment->blog_id = $comment_object->blog_id;
667
- $comment->post = &get_post( $comment->comment_post_ID );
668
- restore_current_blog();
669
-
670
- return $comment;
671
- }
672
-
673
- function get_total_recorded_for_user( $user_id = null ) {
674
- global $bp, $wpdb, $current_user;
675
-
676
- if ( !$bp->blogs )
677
- bp_blogs_setup_globals();
678
-
679
- if ( !$user_id )
680
- $user_id = $current_user->ID;
681
-
682
- return $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(comment_id) FROM {$bp->blogs->table_name_blog_comments} WHERE user_id = %d", $user_id ) );
683
- }
684
-
685
- function total_comment_count( $blog_id, $post_id ) {
686
- global $bp, $wpdb;
687
-
688
- if ( !$bp->blogs )
689
- bp_blogs_setup_globals();
690
-
691
- if ( $post_id )
692
- $post_sql = $wpdb->prepare( " AND comment_post_id = %d", $post_id );
693
-
694
- return $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(comment_id) WHERE blog_id = %d{$post_sql}", $blog_id ) );
695
- }
696
-
697
-
698
- function is_recorded( $comment_id, $comment_post_id, $blog_id, $user_id = null ) {
699
- global $bp, $wpdb, $current_user;
700
-
701
- if ( !$bp->blogs )
702
- bp_blogs_setup_globals();
703
-
704
- if ( !$user_id )
705
- $user_id = $current_user->ID;
706
-
707
- return $wpdb->get_var( $wpdb->prepare( "SELECT comment_id FROM {$bp->blogs->table_name_blog_comments} WHERE comment_id = %d AND blog_id = %d AND comment_post_id = %d AND user_id = %d", $comment_id, $blog_id, $comment_post_id, $user_id ) );
708
- }
709
-
710
- }
711
-
712
?>
278
if ( empty( $blog_ids ) )
279
return $paged_blogs;
280
281
+ for ( $i = 0; $i < count( $paged_blogs ); $i++ )
282
+ $paged_blogs[$i]->latest_post = $wpdb->get_row( "SELECT post_title, guid FROM {$wpdb->base_prefix}" . $paged_blogs[$i]->blog_id . "_posts WHERE post_status = 'publish' AND post_type = 'post' AND id != 1 ORDER BY id DESC LIMIT 1" );
283
284
/* Fetch the blog description for each blog (as it may be empty we can't fetch it in the main query). */
285
$blog_descs = $wpdb->get_results( $wpdb->prepare( "SELECT blog_id, meta_value as description FROM {$bp->blogs->table_name_blogmeta} WHERE meta_key = 'description' AND blog_id IN ( {$blog_ids} )" ) );
307
}
308
}
309
310
?>
bp-blogs/bp-blogs-templatetags.php CHANGED
@@ -144,7 +144,7 @@ function bp_has_blogs( $args = '' ) {
144
}
145
146
$blogs_template = new BP_Blogs_Template( $type, $page, $per_page, $max, $user_id, $search_terms );
147
- return $blogs_template->has_blogs();
148
}
149
150
function bp_blogs() {
@@ -467,7 +467,7 @@ function bp_create_blog_link() {
467
global $bp;
468
469
if ( bp_is_my_profile() ) {
470
- echo apply_filters( 'bp_create_blog_link', '<a href="' . $bp->loggedin_user->domain . $bp->blogs->slug . '/create-a-blog">' . __('Create a Blog', 'buddypress') . '</a>' );
471
}
472
}
473
144
}
145
146
$blogs_template = new BP_Blogs_Template( $type, $page, $per_page, $max, $user_id, $search_terms );
147
+ return apply_filters( 'bp_has_blogs', $blogs_template->has_blogs(), &$blogs_template );
148
}
149
150
function bp_blogs() {
467
global $bp;
468
469
if ( bp_is_my_profile() ) {
470
+ echo apply_filters( 'bp_create_blog_link', '<a href="' . $bp->root_domain . '/' . $bp->blogs->slug . '/create">' . __('Create a Blog', 'buddypress') . '</a>' );
471
}
472
}
473
bp-core.php CHANGED
@@ -32,6 +32,7 @@ if ( !defined( 'CUSTOM_USER_META_TABLE' ) )
32
/* Load the files containing functions that we globally will need. */
33
require ( BP_PLUGIN_DIR . '/bp-core/bp-core-catchuri.php' );
34
require ( BP_PLUGIN_DIR . '/bp-core/bp-core-classes.php' );
35
require ( BP_PLUGIN_DIR . '/bp-core/bp-core-cssjs.php' );
36
require ( BP_PLUGIN_DIR . '/bp-core/bp-core-avatars.php' );
37
require ( BP_PLUGIN_DIR . '/bp-core/bp-core-templatetags.php' );
@@ -40,10 +41,6 @@ require ( BP_PLUGIN_DIR . '/bp-core/bp-core-widgets.php' );
40
require ( BP_PLUGIN_DIR . '/bp-core/bp-core-notifications.php' );
41
require ( BP_PLUGIN_DIR . '/bp-core/bp-core-signup.php' );
42
43
- /* Multisite includes built in account activation support. */
44
- if ( bp_core_is_multisite() )
45
- require ( BP_PLUGIN_DIR . '/bp-core/bp-core-activation.php' );
46
-
47
/* If BP_DISABLE_ADMIN_BAR is defined, do not load the global admin bar. */
48
if ( !defined( 'BP_DISABLE_ADMIN_BAR' ) )
49
require ( BP_PLUGIN_DIR . '/bp-core/bp-core-adminbar.php' );
@@ -1664,37 +1661,6 @@ function bp_core_add_illegal_names() {
1664
update_site_option( 'illegal_names', $new );
1665
}
1666
1667
- /**
1668
- * bp_core_email_from_name_filter()
1669
- *
1670
- * Sets the "From" name in emails sent to the name of the site and not "WordPress"
1671
- *
1672
- * @package BuddyPress Core
1673
- * @uses get_blog_option() fetches the value for a meta_key in the wp_X_options table
1674
- * @return The blog name for the root blog
1675
- */
1676
- function bp_core_email_from_name_filter() {
1677
- return apply_filters( 'bp_core_email_from_name_filter', get_blog_option( BP_ROOT_BLOG, 'blogname' ) );
1678
- }
1679
- add_filter( 'wp_mail_from_name', 'bp_core_email_from_name_filter' );
1680
-
1681
-
1682
- /**
1683
- * bp_core_email_from_name_filter()
1684
- *
1685
- * Sets the "From" address in emails sent
1686
- *
1687
- * @package BuddyPress Core
1688
- * @global $current_site Object containing current site metadata
1689
- * @return noreply@sitedomain email address
1690
- */
1691
- function bp_core_email_from_address_filter() {
1692
- $domain = (array) explode( '/', site_url() );
1693
-
1694
- return apply_filters( 'bp_core_email_from_address_filter', __( 'noreply', 'buddypress' ) . '@' . $domain[2] );
1695
- }
1696
- add_filter( 'wp_mail_from', 'bp_core_email_from_address_filter' );
1697
-
1698
/**
1699
* bp_core_delete_account()
1700
*
@@ -1970,48 +1936,6 @@ function bp_core_update_message() {
1970
}
1971
add_action( 'in_plugin_update_message-buddypress/bp-loader.php', 'bp_core_update_message' );
1972
1973
- /**
1974
- * bp_core_filter_parent_theme()
1975
- *
1976
- * Remove social network parent theme from the theme list.
1977
- *
1978
- * @package BuddyPress Core
1979
- */
1980
- function bp_core_filter_parent_theme() {
1981
- global $wp_themes, $pagenow;
1982
-
1983
- if ( is_admin() && 'themes.php' == $pagenow )
1984
- $wp_themes = get_themes();
1985
-
1986
- unset( $wp_themes['BuddyPress Classic Parent'] );
1987
- }
1988
- add_filter( 'admin_menu', 'bp_core_filter_parent_theme' );
1989
-
1990
- /**
1991
- * bp_core_allow_default_theme()
1992
- *
1993
- * On multiblog installations you must first allow themes to be activated and show
1994
- * up on the theme selection screen. This function will let the BuddyPress bundled
1995
- * themes show up on the root blog selection screen and bypass this step. It also
1996
- * means that the themes won't show for selection on other blogs.
1997
- *
1998
- * @package BuddyPress Core
1999
- */
2000
- function bp_core_allow_default_theme( $themes ) {
2001
- global $bp, $current_blog;
2002
-
2003
- if ( !is_site_admin() )
2004
- return $themes;
2005
-
2006
- if ( $current_blog->ID == $bp->root_blog ) {
2007
- $themes['bp-default'] = 1;
2008
- $themes['bp-classic'] = 1;
2009
- }
2010
-
2011
- return $themes;
2012
- }
2013
- add_filter( 'allowed_themes', 'bp_core_allow_default_theme' );
2014
-
2015
/**
2016
* bp_core_activation_notice()
2017
*
@@ -2053,67 +1977,6 @@ function bp_core_activation_notice() {
2053
}
2054
add_action( 'admin_notices', 'bp_core_activation_notice' );
2055
2056
- /**
2057
- * bp_core_filter_comments()
2058
- *
2059
- * Filter the blog post comments array and insert BuddyPress URLs for users.
2060
- *
2061
- * @package BuddyPress Core
2062
- */
2063
- function bp_core_filter_comments( $comments, $post_id ) {
2064
- global $wpdb;
2065
-
2066
- foreach( (array)$comments as $comment ) {
2067
- if ( $comment->user_id )
2068
- $user_ids[] = $comment->user_id;
2069
- }
2070
-
2071
- if ( empty( $user_ids ) )
2072
- return $comments;
2073
-
2074
- $user_ids = implode( ',', $user_ids );
2075
-
2076
- if ( !$userdata = $wpdb->get_results( $wpdb->prepare( "SELECT ID as user_id, user_login, user_nicename FROM {$wpdb->users} WHERE ID IN ({$user_ids})" ) ) )
2077
- return $comments;
2078
-
2079
- foreach( (array)$userdata as $user )
2080
- $users[$user->user_id] = bp_core_get_user_domain( $user->user_id, $user->user_nicename, $user->user_login );
2081
-
2082
- foreach( (array)$comments as $i => $comment ) {
2083
- if ( !empty( $comment->user_id ) ) {
2084
- if ( !empty( $users[$comment->user_id] ) )
2085
- $comments[$i]->comment_author_url = $users[$comment->user_id];
2086
- }
2087
- }
2088
-
2089
- return $comments;
2090
- }
2091
- add_filter( 'comments_array', 'bp_core_filter_comments', 10, 2 );
2092
-
2093
- /**
2094
- * bp_core_login_redirect()
2095
- *
2096
- * When a user logs in, always redirect them back to the previous page. NOT the admin area.
2097
- *
2098
- * @package BuddyPress Core
2099
- */
2100
- function bp_core_login_redirect( $redirect_to ) {
2101
- global $bp, $current_blog;
2102
-
2103
- if ( bp_core_is_multisite() && $current_blog->blog_id != BP_ROOT_BLOG )
2104
- return $redirect_to;
2105
-
2106
- if ( !empty( $_REQUEST['redirect_to'] ) && strpos( $_REQUEST['redirect_to'], 'wp-admin' ) )
2107
- return $redirect_to;
2108
-
2109
- if ( false === strpos( wp_get_referer(), 'wp-login.php' ) && false === strpos( wp_get_referer(), 'activate' ) && empty( $_REQUEST['nr'] ) )
2110
- return wp_get_referer();
2111
-
2112
- return $bp->root_domain;
2113
- }
2114
- add_filter( 'login_redirect', 'bp_core_login_redirect' );
2115
-
2116
-
2117
/********************************************************************************
2118
* Custom Actions
2119
*
32
/* Load the files containing functions that we globally will need. */
33
require ( BP_PLUGIN_DIR . '/bp-core/bp-core-catchuri.php' );
34
require ( BP_PLUGIN_DIR . '/bp-core/bp-core-classes.php' );
35
+ require ( BP_PLUGIN_DIR . '/bp-core/bp-core-filters.php' );
36
require ( BP_PLUGIN_DIR . '/bp-core/bp-core-cssjs.php' );
37
require ( BP_PLUGIN_DIR . '/bp-core/bp-core-avatars.php' );
38
require ( BP_PLUGIN_DIR . '/bp-core/bp-core-templatetags.php' );
41
require ( BP_PLUGIN_DIR . '/bp-core/bp-core-notifications.php' );
42
require ( BP_PLUGIN_DIR . '/bp-core/bp-core-signup.php' );
43
44
/* If BP_DISABLE_ADMIN_BAR is defined, do not load the global admin bar. */
45
if ( !defined( 'BP_DISABLE_ADMIN_BAR' ) )
46
require ( BP_PLUGIN_DIR . '/bp-core/bp-core-adminbar.php' );
1661
update_site_option( 'illegal_names', $new );
1662
}
1663
1664
/**
1665
* bp_core_delete_account()
1666
*
1936
}
1937
add_action( 'in_plugin_update_message-buddypress/bp-loader.php', 'bp_core_update_message' );
1938
1939
/**
1940
* bp_core_activation_notice()
1941
*
1977
}
1978
add_action( 'admin_notices', 'bp_core_activation_notice' );
1979
1980
/********************************************************************************
1981
* Custom Actions
1982
*
bp-core/bp-core-cssjs.php CHANGED
@@ -47,7 +47,7 @@ add_action( 'admin_head', 'bp_core_admin_menu_icon_css' );
47
function bp_core_confirmation_js() {
48
global $current_blog;
49
50
- if ( $current_blog->blog_id != BP_ROOT_BLOG )
51
return false;
52
?>
53
<script type="text/javascript"> jQuery(document).ready( function() { jQuery("a.confirm").click( function() { if ( confirm( '<?php _e( 'Are you sure?', 'buddypress' ) ?>' ) ) return true; else return false; }); });</script>
47
function bp_core_confirmation_js() {
48
global $current_blog;
49
50
+ if ( bp_core_is_multisite() && $current_blog->blog_id != BP_ROOT_BLOG )
51
return false;
52
?>
53
<script type="text/javascript"> jQuery(document).ready( function() { jQuery("a.confirm").click( function() { if ( confirm( '<?php _e( 'Are you sure?', 'buddypress' ) ?>' ) ) return true; else return false; }); });</script>
bp-core/{bp-core-activation.php → bp-core-filters.php} RENAMED
@@ -1,79 +1,118 @@
1
<?php
2
3
- function bp_core_screen_activation() {
4
- global $bp, $wpdb;
5
6
- if ( !bp_core_is_multisite() || BP_ACTIVATION_SLUG != $bp->current_component )
7
- return false;
8
9
- /* Check if an activation key has been passed */
10
- if ( isset( $_GET['key'] ) ) {
11
12
- require_once( ABSPATH . WPINC . '/registration.php' );
13
14
- /* Activate the signup */
15
- $signup = apply_filters( 'bp_core_activate_account', wpmu_activate_signup( $_GET['key'] ) );
16
17
- /* If there was errors, add a message and redirect */
18
- if ( $signup->errors ) {
19
- bp_core_add_message( __( 'There was an error activating your account, please try again.', 'buddypress' ), 'error' );
20
- bp_core_redirect( $bp->root_domain . '/' . BP_ACTIVATION_SLUG );
21
- }
22
23
- /* Set the password */
24
- if ( !empty( $signup['meta']['password'] ) )
25
- $wpdb->update( $wpdb->users, array( 'user_pass' => $signup['meta']['password'] ), array( 'ID' => $signup['user_id'] ), array( '%s' ), array( '%d' ) );
26
27
- /* Set any profile data */
28
- if ( function_exists( 'xprofile_set_field_data' ) ) {
29
30
- if ( !empty( $signup['meta']['profile_field_ids'] ) ) {
31
- $profile_field_ids = explode( ',', $signup['meta']['profile_field_ids'] );
32
33
- foreach( (array)$profile_field_ids as $field_id ) {
34
- $current_field = $signup['meta']["field_{$field_id}"];
35
36
- if ( !empty( $current_field ) )
37
- xprofile_set_field_data( $field_id, $signup['user_id'], $current_field );
38
- }
39
- }
40
41
- }
42
43
- /* Check for an uploaded avatar and move that to the correct user folder */
44
- $hashed_key = wp_hash( $_GET['key'] );
45
46
- /* Check if the avatar folder exists. If it does, move rename it, move it and delete the signup avatar dir */
47
- if ( file_exists( BP_AVATAR_UPLOAD_PATH . '/avatars/signups/' . $hashed_key ) ) {
48
- @rename( BP_AVATAR_UPLOAD_PATH . '/avatars/signups/' . $hashed_key, BP_AVATAR_UPLOAD_PATH . '/avatars/' . $signup['user_id'] );
49
}
50
51
- /* Record the new user in the activity streams */
52
- if ( function_exists( 'bp_activity_add' ) ) {
53
- $userlink = bp_core_get_userlink( $signup['user_id'] );
54
55
- bp_activity_add( array(
56
- 'user_id' => $signup['user_id'],
57
- 'action' => apply_filters( 'bp_core_activity_registered_member_action', sprintf( __( '%s became a registered member', 'buddypress' ), $userlink ), $signup['user_id'] ),
58
- 'component' => 'profile',
59
- 'type' => 'new_member'
60
- ) );
61
- }
62
63
- do_action( 'bp_core_account_activated', &$signup, $_GET['key'] );
64
- wp_cache_delete( 'bp_total_member_count', 'bp' );
65
66
- bp_core_add_message( __( 'Your account is now active!', 'buddypress' ) );
67
68
- $bp->activation_complete = true;
69
- }
70
71
- if ( '' != locate_template( array( 'registration/activate' ), false ) )
72
- bp_core_load_template( apply_filters( 'bp_core_template_activate', 'activate' ) );
73
- else
74
- bp_core_load_template( apply_filters( 'bp_core_template_activate', 'registration/activate' ) );
75
}
76
- add_action( 'wp', 'bp_core_screen_activation', 3 );
77
78
/***
79
* bp_core_filter_user_welcome_email()
1
<?php
2
3
+ /**
4
+ * bp_core_email_from_name_filter()
5
+ *
6
+ * Sets the "From" name in emails sent to the name of the site and not "WordPress"
7
+ *
8
+ * @package BuddyPress Core
9
+ * @uses get_blog_option() fetches the value for a meta_key in the wp_X_options table
10
+ * @return The blog name for the root blog
11
+ */
12
+ function bp_core_email_from_name_filter() {
13
+ return apply_filters( 'bp_core_email_from_name_filter', get_blog_option( BP_ROOT_BLOG, 'blogname' ) );
14
+ }
15
+ add_filter( 'wp_mail_from_name', 'bp_core_email_from_name_filter' );
16
17
+ /**
18
+ * bp_core_email_from_name_filter()
19
+ *
20
+ * Sets the "From" address in emails sent
21
+ *
22
+ * @package BuddyPress Core
23
+ * @global $current_site Object containing current site metadata
24
+ * @return noreply@sitedomain email address
25
+ */
26
+ function bp_core_email_from_address_filter() {
27
+ $domain = (array) explode( '/', site_url() );
28
29
+ return apply_filters( 'bp_core_email_from_address_filter', __( 'noreply', 'buddypress' ) . '@' . $domain[2] );
30
+ }
31
+ add_filter( 'wp_mail_from', 'bp_core_email_from_address_filter' );
32
33
+ /**
34
+ * bp_core_allow_default_theme()
35
+ *
36
+ * On multiblog installations you must first allow themes to be activated and show
37
+ * up on the theme selection screen. This function will let the BuddyPress bundled
38
+ * themes show up on the root blog selection screen and bypass this step. It also
39
+ * means that the themes won't show for selection on other blogs.
40
+ *
41
+ * @package BuddyPress Core
42
+ */
43
+ function bp_core_allow_default_theme( $themes ) {
44
+ global $bp, $current_blog;
45
46
+ if ( !is_site_admin() )
47
+ return $themes;
48
49
+ if ( $current_blog->ID == $bp->root_blog ) {
50
+ $themes['bp-default'] = 1;
51
+ }
52
53
+ return $themes;
54
+ }
55
+ add_filter( 'allowed_themes', 'bp_core_allow_default_theme' );
56
57
+ /**
58
+ * bp_core_filter_comments()
59
+ *
60
+ * Filter the blog post comments array and insert BuddyPress URLs for users.
61
+ *
62
+ * @package BuddyPress Core
63
+ */
64
+ function bp_core_filter_comments( $comments, $post_id ) {
65
+ global $wpdb;
66
67
+ foreach( (array)$comments as $comment ) {
68
+ if ( $comment->user_id )
69
+ $user_ids[] = $comment->user_id;
70
+ }
71
72
+ if ( empty( $user_ids ) )
73
+ return $comments;
74
75
+ $user_ids = implode( ',', $user_ids );
76
77
+ if ( !$userdata = $wpdb->get_results( $wpdb->prepare( "SELECT ID as user_id, user_login, user_nicename FROM {$wpdb->users} WHERE ID IN ({$user_ids})" ) ) )
78
+ return $comments;
79
80
+ foreach( (array)$userdata as $user )
81
+ $users[$user->user_id] = bp_core_get_user_domain( $user->user_id, $user->user_nicename, $user->user_login );
82
83
+ foreach( (array)$comments as $i => $comment ) {
84
+ if ( !empty( $comment->user_id ) ) {
85
+ if ( !empty( $users[$comment->user_id] ) )
86
+ $comments[$i]->comment_author_url = $users[$comment->user_id];
87
}
88
+ }
89
90
+ return $comments;
91
+ }
92
+ add_filter( 'comments_array', 'bp_core_filter_comments', 10, 2 );
93
94
+ /**
95
+ * bp_core_login_redirect()
96
+ *
97
+ * When a user logs in, always redirect them back to the previous page. NOT the admin area.
98
+ *
99
+ * @package BuddyPress Core
100
+ */
101
+ function bp_core_login_redirect( $redirect_to ) {
102
+ global $bp, $current_blog;
103
104
+ if ( bp_core_is_multisite() && $current_blog->blog_id != BP_ROOT_BLOG )
105
+ return $redirect_to;
106
107
+ if ( !empty( $_REQUEST['redirect_to'] ) || strpos( $_REQUEST['redirect_to'], 'wp-admin' ) )
108
+ return $redirect_to;
109
110
+ if ( false === strpos( wp_get_referer(), 'wp-login.php' ) && false === strpos( wp_get_referer(), 'activate' ) && empty( $_REQUEST['nr'] ) )
111
+ return wp_get_referer();
112
113
+ return $bp->root_domain;
114
}
115
+ add_filter( 'login_redirect', 'bp_core_login_redirect' );
116
117
/***
118
* bp_core_filter_user_welcome_email()
bp-core/bp-core-signup.php CHANGED
@@ -1,5 +1,13 @@
1
<?php
2
3
function bp_core_screen_signup() {
4
global $bp, $wpdb;
5
@@ -10,13 +18,6 @@ function bp_core_screen_signup() {
10
if ( is_user_logged_in() )
11
bp_core_redirect( $bp->root_domain );
12
13
- /***
14
- * For backwards compatibility with the old pre 1.1 two theme system, skip this screen function
15
- * if the user is using the old two theme method.
16
- */
17
- if ( file_exists( WP_CONTENT_DIR . '/bp-themes' ) )
18
- return false;
19
-
20
/* If signups are disabled, just re-direct */
21
if ( !bp_get_signup_allowed() )
22
bp_core_redirect( $bp->root_domain );
@@ -32,7 +33,7 @@ function bp_core_screen_signup() {
32
require_once( ABSPATH . WPINC . '/registration.php' );
33
34
/* Check the base account details for problems */
35
- $account_details = wpmu_validate_user_signup( $_POST['signup_username'], $_POST['signup_email'] );
36
37
/* If there are errors with account details, set them for display */
38
if ( !empty( $account_details['errors']->errors['user_name'] ) )
@@ -73,7 +74,7 @@ function bp_core_screen_signup() {
73
$active_signup = $bp->site_options['registration'];
74
75
if ( 'blog' == $active_signup || 'all' == $active_signup ) {
76
- $blog_details = wpmu_validate_blog_signup( $_POST['signup_blog_url'], $_POST['signup_blog_title'] );
77
78
/* If there are errors with blog details, set them for display */
79
if ( !empty( $blog_details['errors']->errors['blogname'] ) )
@@ -125,9 +126,9 @@ function bp_core_screen_signup() {
125
126
$usermeta = apply_filters( 'bp_signup_usermeta', $usermeta );
127
128
- /* Finally, sign up the user and/or blog*/
129
if ( isset( $_POST['signup_with_blog'] ) && bp_core_is_multisite() )
130
- wpmu_signup_blog( $blog_details['domain'], $blog_details['path'], $blog_details['blog_title'], $_POST['signup_username'], $_POST['signup_email'], $usermeta );
131
else {
132
bp_core_signup_user( $_POST['signup_username'], $_POST['signup_password'], $_POST['signup_email'], $usermeta );
133
}
@@ -158,8 +159,10 @@ function bp_core_screen_signup() {
158
/* Hash the key to create the upload folder (added security so people don't sniff the activation key) */
159
$bp->signup->avatar_dir = wp_hash( $bp->signup->key );
160
}
161
- } else
162
- $bp->signup->avatar_dir = wp_hash( $bp->signup->username );
163
164
/* Pass the file to the avatar upload handler */
165
if ( bp_core_avatar_handle_upload( $_FILES, 'bp_core_signup_avatar_upload_dir' ) ) {
@@ -184,59 +187,285 @@ function bp_core_screen_signup() {
184
bp_core_add_message( __( 'There was a problem cropping your avatar, please try uploading it again', 'buddypress' ), 'error' );
185
else
186
bp_core_add_message( __( 'Your new avatar was uploaded successfully', 'buddypress' ) );
187
188
- /* If this is a single WP install, move the avatar to the user's folder since there is no activation process to move it. */
189
- if ( !bp_core_is_multisite() ) {
190
- $user_id = bp_core_get_userid( $_POST['signup_username'] );
191
192
- if ( !empty( $user_id ) && file_exists( BP_AVATAR_UPLOAD_PATH . '/avatars/signups/' . $_POST['signup_avatar_dir'] ) ) {
193
- @rename( BP_AVATAR_UPLOAD_PATH . '/avatars/signups/' . $_POST['signup_avatar_dir'], BP_AVATAR_UPLOAD_PATH . '/avatars/' . $user_id );
194
- }
195
}
196
}
197
- bp_core_load_template( 'registration/register' );
198
}
199
- add_action( 'wp', 'bp_core_screen_signup', 3 );
200
201
- function bp_core_signup_user( $user_login, $user_password, $user_email, $usermeta ) {
202
- global $bp;
203
204
- if ( bp_core_is_multisite() )
205
- return wpmu_signup_user( $user_login, $user_email, $usermeta );
206
207
$errors = new WP_Error();
208
209
- $user_id = wp_create_user( $user_login, $user_password, $user_email );
210
- if ( !$user_id ) {
211
- $errors->add('registerfail', sprintf(__('<strong>ERROR</strong>: Couldn&#8217;t register you... please contact the <a href="mailto:%s">webmaster</a> !'), get_option('admin_email')));
212
- return $errors;
213
}
214
215
- /* Set any profile data */
216
- if ( function_exists( 'xprofile_set_field_data' ) ) {
217
- if ( !empty( $usermeta['profile_field_ids'] ) ) {
218
- $profile_field_ids = explode( ',', $usermeta['profile_field_ids'] );
219
220
- foreach( (array)$profile_field_ids as $field_id ) {
221
- $current_field = $usermeta["field_{$field_id}"];
222
223
- if ( !empty( $current_field ) )
224
- xprofile_set_field_data( $field_id, $user_id, $current_field );
225
}
226
}
227
}
228
229
/* Add a last active entry */
230
update_usermeta( $user_id, 'last_activity', gmdate( "Y-m-d H:i:s" ) );
231
232
- wp_new_user_notification( $user_id, $user_pass );
233
wp_cache_delete( 'bp_total_member_count', 'bp' );
234
235
- $bp->signup->username = $user_login;
236
237
return $user_id;
238
}
239
240
function bp_core_map_user_registration( $user_id ) {
241
/* Only map data when the site admin is adding users, not on registration. */
242
if ( !is_admin() )
@@ -278,6 +507,43 @@ function bp_core_signup_avatar_upload_dir() {
278
return apply_filters( 'bp_core_signup_avatar_upload_dir', array( 'path' => $path, 'url' => $newurl, 'subdir' => $newsubdir, 'basedir' => $newbdir, 'baseurl' => $newburl, 'error' => false ) );
279
}
280
281
/* Kill the wp-signup.php if custom registration signup templates are present */
282
function bp_core_wpsignup_redirect() {
283
if ( false === strpos( $_SERVER['SCRIPT_NAME'], 'wp-signup.php') && $_GET['action'] != 'register' )
1
<?php
2
3
+ /********************************************************************************
4
+ * Screen Functions
5
+ *
6
+ * Screen functions are the controllers of BuddyPress. They will execute when their
7
+ * specific URL is caught. They will first save or manipulate data using business
8
+ * functions, then pass on the user to a template file.
9
+ */
10
+
11
function bp_core_screen_signup() {
12
global $bp, $wpdb;
13
18
if ( is_user_logged_in() )
19
bp_core_redirect( $bp->root_domain );
20
21
/* If signups are disabled, just re-direct */
22
if ( !bp_get_signup_allowed() )
23
bp_core_redirect( $bp->root_domain );
33
require_once( ABSPATH . WPINC . '/registration.php' );
34
35
/* Check the base account details for problems */
36
+ $account_details = bp_core_validate_user_signup( $_POST['signup_username'], $_POST['signup_email'] );
37
38
/* If there are errors with account details, set them for display */
39
if ( !empty( $account_details['errors']->errors['user_name'] ) )
74
$active_signup = $bp->site_options['registration'];
75
76
if ( 'blog' == $active_signup || 'all' == $active_signup ) {
77
+ $blog_details = bp_core_validate_blog_signup( $_POST['signup_blog_url'], $_POST['signup_blog_title'] );
78
79
/* If there are errors with blog details, set them for display */
80
if ( !empty( $blog_details['errors']->errors['blogname'] ) )
126
127
$usermeta = apply_filters( 'bp_signup_usermeta', $usermeta );
128
129
+ /* Finally, sign up the user and/or blog */
130
if ( isset( $_POST['signup_with_blog'] ) && bp_core_is_multisite() )
131
+ bp_core_signup_blog( $blog_details['domain'], $blog_details['path'], $blog_details['blog_title'], $_POST['signup_username'], $_POST['signup_email'], $usermeta );
132
else {
133
bp_core_signup_user( $_POST['signup_username'], $_POST['signup_password'], $_POST['signup_email'], $usermeta );
134
}
159
/* Hash the key to create the upload folder (added security so people don't sniff the activation key) */
160
$bp->signup->avatar_dir = wp_hash( $bp->signup->key );
161
}
162
+ } else {
163
+ $user_id = bp_core_get_userid( $_POST['signup_username'] );
164
+ $bp->signup->avatar_dir = wp_hash( $user_id );
165
+ }
166
167
/* Pass the file to the avatar upload handler */
168
if ( bp_core_avatar_handle_upload( $_FILES, 'bp_core_signup_avatar_upload_dir' ) ) {
187
bp_core_add_message( __( 'There was a problem cropping your avatar, please try uploading it again', 'buddypress' ), 'error' );
188
else
189
bp_core_add_message( __( 'Your new avatar was uploaded successfully', 'buddypress' ) );
190
+ }
191
+ bp_core_load_template( 'registration/register' );
192
+ }
193
+ add_action( 'wp', 'bp_core_screen_signup', 3 );
194
195
+ function bp_core_screen_activation() {
196
+ global $bp, $wpdb;
197
198
+ if ( BP_ACTIVATION_SLUG != $bp->current_component )
199
+ return false;
200
+
201
+ /* Check if an activation key has been passed */
202
+ if ( isset( $_GET['key'] ) ) {
203
+
204
+ require_once( ABSPATH . WPINC . '/registration.php' );
205
+
206
+ /* Activate the signup */
207
+ $user = apply_filters( 'bp_core_activate_account', bp_core_activate_signup( $_GET['key'] ) );
208
+
209
+ /* If there was errors, add a message and redirect */
210
+ if ( $user->errors ) {
211
+ bp_core_add_message( __( 'There was an error activating your account, please try again.', 'buddypress' ), 'error' );
212
+ bp_core_redirect( $bp->root_domain . '/' . BP_ACTIVATION_SLUG );
213
}
214
+
215
+ /* Check for an uploaded avatar and move that to the correct user folder */
216
+ if ( bp_core_is_multisite() )
217
+ $hashed_key = wp_hash( $_GET['key'] );
218
+ else
219
+ $hashed_key = wp_hash( $user );
220
+
221
+ /* Check if the avatar folder exists. If it does, move rename it, move it and delete the signup avatar dir */
222
+ if ( file_exists( BP_AVATAR_UPLOAD_PATH . '/avatars/signups/' . $hashed_key ) )
223
+ @rename( BP_AVATAR_UPLOAD_PATH . '/avatars/signups/' . $hashed_key, BP_AVATAR_UPLOAD_PATH . '/avatars/' . $user );
224
+
225
+ bp_core_add_message( __( 'Your account is now active!', 'buddypress' ) );
226
+
227
+ $bp->activation_complete = true;
228
}
229
+
230
+ if ( '' != locate_template( array( 'registration/activate' ), false ) )
231
+ bp_core_load_template( apply_filters( 'bp_core_template_activate', 'activate' ) );
232
+ else
233
+ bp_core_load_template( apply_filters( 'bp_core_template_activate', 'registration/activate' ) );
234
}
235
+ add_action( 'wp', 'bp_core_screen_activation', 3 );
236
237
238
+ /********************************************************************************
239
+ * Business Functions
240
+ *
241
+ * Business functions are where all the magic happens in BuddyPress. They will
242
+ * handle the actual saving or manipulation of information. Usually they will
243
+ * hand off to a database class for data access, then return
244
+ * true or false on success or failure.
245
+ */
246
+
247
+ function bp_core_validate_user_signup( $user_name, $user_email ) {
248
+ global $wpdb;
249
250
$errors = new WP_Error();
251
+ $user_email = sanitize_email( $user_email );
252
+
253
+ if ( empty( $user_name ) )
254
+ $errors->add( 'user_name', __( 'Please enter a username', 'buddypress' ) );
255
+
256
+ $maybe = array();
257
+ preg_match( "/[a-z0-9]+/", $user_name, $maybe );
258
+
259
+ $db_illegal_names = get_site_option( 'illegal_names' );
260
+ $filtered_illegal_names = apply_filters( 'bp_core_illegal_usernames', array( 'www', 'web', 'root', 'admin', 'main', 'invite', 'administrator', BP_GROUPS_SLUG, BP_MEMBERS_SLUG, BP_FORUMS_SLUG, BP_BLOGS_SLUG, BP_REGISTER_SLUG, BP_ACTIVATION_SLUG ) );
261
+
262
+ $illegal_names = array_merge( (array)$db_illegal_names, (array)$filtered_illegal_names );
263
+ update_site_option( 'illegal_names', $illegal_names );
264
+
265
+ if ( !validate_username( $user_name ) || in_array( $user_name, (array)$illegal_names ) || $user_name != $maybe[0] )
266
+ $errors->add( 'user_name', __( 'Only lowercase letters and numbers allowed', 'buddypress' ) );
267
+
268
+ if( strlen( $user_name ) < 4 )
269
+ $errors->add( 'user_name', __( 'Username must be at least 4 characters', 'buddypress' ) );
270
271
+ if ( strpos( ' ' . $user_name, '_' ) != false )
272
+ $errors->add( 'user_name', __( 'Sorry, usernames may not contain the character "_"!', 'buddypress' ) );
273
+
274
+ /* Is the user_name all numeric? */
275
+ $match = array();
276
+ preg_match( '/[0-9]*/', $user_name, $match );
277
+
278
+ if ( $match[0] == $user_name )
279
+ $errors->add( 'user_name', __( 'Sorry, usernames must have letters too!', 'buddypress' ) );
280
+
281
+ if ( !is_email( $user_email ) )
282
+ $errors->add( 'user_email', __( 'Please check your email address.', 'buddypress' ) );
283
+
284
+ $limited_email_domains = get_site_option( 'limited_email_domains', 'buddypress' );
285
+
286
+ if ( is_array( $limited_email_domains ) && empty( $limited_email_domains ) == false ) {
287
+ $emaildomain = substr( $user_email, 1 + strpos( $user_email, '@' ) );
288
+
289
+ if ( in_array( $emaildomain, (array)$limited_email_domains ) == false )
290
+ $errors->add( 'user_email', __( 'Sorry, that email address is not allowed!', 'buddypress' ) );
291
}
292
293
+ /* Check if the username has been used already. */
294
+ if ( username_exists( $user_name ) )
295
+ $errors->add( 'user_name', __( 'Sorry, that username already exists!', 'buddypress' ) );
296
+
297
+ /* Check if the email address has been used already. */
298
+ if ( email_exists( $user_email ) )
299
+ $errors->add( 'user_email', __( 'Sorry, that email address is already used!', 'buddypress' ) );
300
+
301
+ $result = array( 'user_name' => $user_name, 'user_email' => $user_email, 'errors' => $errors );
302
+
303
+ /* Apply WPMU legacy filter */
304
+ $result = apply_filters( 'wpmu_validate_user_signup', $result );
305
+
306
+ return apply_filters( 'bp_core_validate_user_signup', $result );
307
+ }
308
+
309
+ function bp_core_validate_blog_signup( $blog_url, $blog_title ) {
310
+ if ( !bp_core_is_multisite() || !function_exists( 'wpmu_validate_blog_signup' ) )
311
+ return false;
312
+
313
+ return apply_filters( 'bp_core_validate_blog_signup', wpmu_validate_blog_signup( $blog_url, $blog_title ) );
314
+ }
315
+
316
+ function bp_core_signup_user( $user_login, $user_password, $user_email, $usermeta ) {
317
+ global $bp, $wpdb;
318
+
319
+ /* Multisite installs have their own install procedure */
320
+ if ( bp_core_is_multisite() ) {
321
+ wpmu_signup_user( $user_login, $user_email, $usermeta );
322
+
323
+ } else {
324
+ $errors = new WP_Error();
325
+
326
+ $user_id = wp_insert_user( array(
327
+ 'user_login' => $user_login,
328
+ 'user_pass' => $user_password,
329
+ 'display_name' => sanitize_title( $user_login ),
330
+ 'user_email' => $user_email
331
+ ) );
332
333
+ if ( !$user_id ) {
334
+ $errors->add( 'registerfail', sprintf( __('<strong>ERROR</strong>: Couldn&#8217;t register you... please contact the <a href="mailto:%s">webmaster</a> !', 'buddypress' ), get_option( 'admin_email' ) ) );
335
+ return $errors;
336
+ }
337
+
338
+ /* Update the user status to '2' which we will use as 'not activated' (0 = active, 1 = spam, 2 = not active) */
339
+ $wpdb->query( $wpdb->prepare( "UPDATE $wpdb->users SET user_status = 2 WHERE ID = %d", $user_id ) );
340
+
341
+ /* Set any profile data */
342
+ if ( function_exists( 'xprofile_set_field_data' ) ) {
343
+ if ( !empty( $usermeta['profile_field_ids'] ) ) {
344
+ $profile_field_ids = explode( ',', $usermeta['profile_field_ids'] );
345
+
346
+ foreach( (array)$profile_field_ids as $field_id ) {
347
+ $current_field = $usermeta["field_{$field_id}"];
348
+
349
+ if ( !empty( $current_field ) )
350
+ xprofile_set_field_data( $field_id, $user_id, $current_field );
351
+ }
352
+ }
353
+ }
354
+ }
355
+ $bp->signup->username = $user_login;
356
+
357
+ /***
358
+ * Now generate an activation key and send an email to the user so they can activate their account
359
+ * and validate their email address. Multisite installs send their own email, so this is only for single blog installs.
360
+ */
361
+ if ( !bp_core_is_multisite() ) {
362
+ $activation_key = wp_hash( $user_id );
363
+ update_usermeta( $user_id, 'activation_key', $activation_key );
364
+ bp_core_signup_send_validation_email( $user_id, $activation_key );
365
+ }
366
+
367
+ do_action( 'bp_core_signup_user', $user_id, $user_login, $user_password, $user_email, $usermeta );
368
+
369
+ return $user_id;
370
+ }
371
+
372
+ function bp_core_signup_blog( $blog_domain, $blog_path, $blog_title, $user_name, $user_email, $usermeta ) {
373
+ if ( !bp_core_is_multisite() || !function_exists( 'wpmu_signup_blog' ) )
374
+ return false;
375
+
376
+ return apply_filters( 'bp_core_signup_blog', wpmu_signup_blog( $blog_domain, $blog_path, $blog_title, $user_name, $user_email, $usermeta ) );
377
+ }
378
+
379
+ function bp_core_activate_signup( $key ) {
380
+ global $wpdb;
381
+
382
+ $user = false;
383
+
384
+ /* Multisite installs have their own activation routine */
385
+ if ( bp_core_is_multisite() ) {
386
+ $user = wpmu_activate_signup( $key );
387
+
388
+ /* If there was errors, add a message and redirect */
389
+ if ( $user->errors ) {
390
+ bp_core_add_message( __( 'There was an error activating your account, please try again.', 'buddypress' ), 'error' );
391
+ bp_core_redirect( $bp->root_domain . '/' . BP_ACTIVATION_SLUG );
392
+ }
393
+
394
+ $user_id = $user['user_id'];
395
+
396
+ /* Set any profile data */
397
+ if ( function_exists( 'xprofile_set_field_data' ) ) {
398
+ if ( !empty( $user['meta']['profile_field_ids'] ) ) {
399
+ $profile_field_ids = explode( ',', $user['meta']['profile_field_ids'] );
400
+
401
+ foreach( (array)$profile_field_ids as $field_id ) {
402
+ $current_field = $user['meta']["field_{$field_id}"];
403
404
+ if ( !empty( $current_field ) )
405
+ xprofile_set_field_data( $field_id, $user_id, $current_field );
406
+ }
407
}
408
}
409
+
410
+ } else {
411
+ /* Get the user_id based on the $key */
412
+ $user_id = $wpdb->get_var( $wpdb->prepare( "SELECT user_id FROM $wpdb->usermeta WHERE meta_value = %s", $key ) );
413
+
414
+ if ( empty( $user_id ) )
415
+ return new WP_Error( 'invalid_key', __( 'Invalid activation key', 'buddypress' ) );
416
+
417
+ /* Change the user's status so they become active */
418
+ if ( !$wpdb->query( $wpdb->prepare( "UPDATE $wpdb->users SET user_status = 0 WHERE ID = %d", $user_id ) ) )
419
+ return new WP_Error( 'invalid_key', __( 'Invalid activation key', 'buddypress' ) );
420
+
421
+ /* Notify the site admin of a new user registration */
422
+ wp_new_user_notification( $user_id );
423
+
424
+ /* Remove the activation key meta */
425
+ delete_usermeta( $user_id, 'activation_key' );
426
}
427
428
+ /* Update the user_url and display_name */
429
+ wp_update_user( array( 'ID' => $user_id, 'user_url' => bp_core_get_user_domain( $user_id, sanitize_title( $user_login ), $user_login ), 'display_name' => bp_core_get_user_displayname( $user_id ) ) );
430
+
431
/* Add a last active entry */
432
update_usermeta( $user_id, 'last_activity', gmdate( "Y-m-d H:i:s" ) );
433
434
+ /* Set the password on multisite installs */
435
+ if ( bp_core_is_multisite() && !empty( $user['meta']['password'] ) )
436
+ $wpdb->query( $wpdb->prepare( "UPDATE $wpdb->users SET user_pass = %s WHERE ID = %d", $user['meta']['password'], $user_id ) );
437
+
438
+ /* Delete the total member cache */
439
wp_cache_delete( 'bp_total_member_count', 'bp' );
440
441
+ do_action( 'bp_core_activated_user', $user_id, $key, $user );
442
443
return $user_id;
444
}
445
446
+ function bp_core_new_user_activity( $user ) {
447
+ if ( empty( $user ) || !function_exists( 'bp_activity_add' ) )
448
+ return false;
449
+
450
+ if ( is_array( $user ) )
451
+ $user_id = $user['user_id'];
452
+ else
453
+ $user_id = $user;
454
+
455
+ if ( empty( $user_id ) )
456
+ return false;
457
+
458
+ $userlink = bp_core_get_userlink( $user_id );
459
+
460
+ bp_activity_add( array(
461
+ 'user_id' => $user_id,
462
+ 'action' => apply_filters( 'bp_core_activity_registered_member_action', sprintf( __( '%s became a registered member', 'buddypress' ), $userlink ), $user_id ),
463
+ 'component' => 'profile',
464
+ 'type' => 'new_member'
465
+ ) );
466
+ }
467
+ add_action( 'bp_core_activated_user', 'bp_core_new_user_activity' );
468
+
469
function bp_core_map_user_registration( $user_id ) {
470
/* Only map data when the site admin is adding users, not on registration. */
471
if ( !is_admin() )
507
return apply_filters( 'bp_core_signup_avatar_upload_dir', array( 'path' => $path, 'url' => $newurl, 'subdir' => $newsubdir, 'basedir' => $newbdir, 'baseurl' => $newburl, 'error' => false ) );
508
}
509
510
+ function bp_core_signup_send_validation_email( $user_id, $key ) {
511
+ $activate_url = bp_get_activation_page() ."?key=$key";
512
+ $activate_url = clean_url( $activate_url );
513
+ $admin_email = get_site_option( "admin_email" );
514
+
515
+ if ( empty( $admin_email ) )
516
+ $admin_email = 'noreply@' . $_SERVER['SERVER_NAME'];
517
+
518
+ $from_name = ( '' == get_option( 'blogname' ) ) ? 'BuddyPress' : wp_specialchars( get_option( 'blogname' ) );
519
+ $message_headers = "MIME-Version: 1.0\n" . "From: \"{$from_name}\" <{$admin_email}>\n" . "Content-Type: text/plain; charset=\"" . get_option( 'blog_charset' ) . "\"\n";
520
+ $message = sprintf( __( "Thanks for registering! To complete the activation of your account please click the following link:\n\n%s\n\n", 'buddypress' ), $activate_url );
521
+ $subject = '[' . $from_name . '] ' . __( 'Activate Your Account', 'buddypress' );
522
+
523
+ /* Send the message */
524
+ $to = apply_filters( 'bp_core_activation_signup_user_notification_to', $user_email );
525
+ $subject = apply_filters( 'bp_core_activation_signup_user_notification_subject', $subject );
526
+ $message = apply_filters( 'bp_core_activation_signup_user_notification_message', $message );
527
+
528
+ wp_mail( $to, $subject, $message, $message_headers );
529
+ }
530
+
531
+ /* Stop user accounts logging in that have not been activated (user_status = 2) */
532
+ function bp_core_signup_disable_inactive( $auth_obj, $username ) {
533
+ global $bp, $wpdb;
534
+
535
+ if ( !$user_id = bp_core_get_userid( $username ) )
536
+ return $auth_obj;
537
+
538
+ $user_status = (int) $wpdb->get_var( $wpdb->prepare( "SELECT user_status FROM $wpdb->users WHERE ID = %d", $user_id ) );
539
+
540
+ if ( 2 == $user_status )
541
+ bp_core_redirect( $bp->root_domain );
542
+ else
543
+ return $auth_obj;
544
+ }
545
+ add_filter( 'authenticate', 'bp_core_signup_disable_inactive', 11, 2 );
546
+
547
/* Kill the wp-signup.php if custom registration signup templates are present */
548
function bp_core_wpsignup_redirect() {
549
if ( false === strpos( $_SERVER['SCRIPT_NAME'], 'wp-signup.php') && $_GET['action'] != 'register' )
bp-core/bp-core-templatetags.php CHANGED
@@ -309,8 +309,8 @@ function bp_member_profile_data( $args = '' ) {
309
extract( $r, EXTR_SKIP );
310
311
// Populate the user if it hasn't been already.
312
- if ( empty( $members_template->member->profile_data ) )
313
- $members_template->member = new BP_Core_User( $members_template->member->id );
314
315
$data = xprofile_format_profile_field( $members_template->member->profile_data[$field]['field_type'], $members_template->member->profile_data[$field]['field_data'] );
316
@@ -916,6 +916,12 @@ function bp_get_page_title() {
916
917
} else if ( bp_is_activation_page() ) {
918
$title = __( 'Activate your Account', 'buddypress' );
919
}
920
921
if ( defined( 'BP_ENABLE_MULTIBLOG' ) ) {
@@ -1183,26 +1189,21 @@ function bp_signup_avatar( $args = '' ) {
1183
$r = wp_parse_args( $args, $defaults );
1184
extract( $r, EXTR_SKIP );
1185
1186
- if ( !bp_core_is_multisite() && !empty( $_POST['signup_username'] ) ) {
1187
- $user_id = bp_core_get_userid( $_POST['signup_username'] );
1188
- return apply_filters( 'bp_get_signup_avatar', bp_core_fetch_avatar( array( 'item_id' => $user_id, 'type' => 'full', 'width' => $size, 'height' => $size, 'alt' => $alt, 'class' => $class ) ) );
1189
- } else {
1190
- $signup_avatar_dir = ( !empty( $_POST['signup_avatar_dir'] ) ) ? $_POST['signup_avatar_dir'] : $bp->signup->avatar_dir;
1191
-
1192
- if ( empty( $signup_avatar_dir ) ) {
1193
- if ( empty( $bp->grav_default->user ) ) {
1194
- $default_grav = 'wavatar';
1195
- } else if ( 'mystery' == $bp->grav_default->user ) {
1196
- $default_grav = BP_PLUGIN_URL . '/bp-core/images/mystery-man.jpg';
1197
- } else {
1198
- $default_grav = $bp->grav_default->user;
1199
- }
1200
1201
- $gravatar_url = apply_filters( 'bp_gravatar_url', 'http://www.gravatar.com/avatar/' );
1202
- return apply_filters( 'bp_get_signup_avatar', '<img src="' . $gravatar_url . md5( $_POST['signup_email'] ) . '?d=' . $default_grav . '&amp;s=' . $size ) . '" width="' . $size . '" height="' . $size . '" alt="' . $alt . '" class="' . $class . '" />';
1203
} else {
1204
- return apply_filters( 'bp_get_signup_avatar', bp_core_fetch_avatar( array( 'item_id' => $signup_avatar_dir, 'object' => 'signup', 'avatar_dir' => 'avatars/signups', 'type' => 'full', 'width' => $size, 'height' => $size, 'alt' => $alt, 'class' => $class ) ) );
1205
}
1206
}
1207
}
1208
@@ -1245,7 +1246,7 @@ function bp_account_was_activated() {
1245
}
1246
1247
function bp_registration_needs_activation() {
1248
- return apply_filters( 'bp_registration_needs_activation', bp_core_is_multisite() );
1249
}
1250
1251
function bp_mentioned_user_display_name( $user_id_or_username ) {
@@ -1692,7 +1693,7 @@ function bp_is_user_recent_commments() {
1692
function bp_is_create_blog() {
1693
global $bp;
1694
1695
- if ( BP_BLOGS_SLUG == $bp->current_component && 'create-a-blog' == $bp->current_action )
1696
return true;
1697
1698
return false;
309
extract( $r, EXTR_SKIP );
310
311
// Populate the user if it hasn't been already.
312
+ if ( empty( $members_template->member->profile_data ) && method_exists( 'BP_XProfile_ProfileData', 'get_all_for_user' ) )
313
+ $members_template->member->profile_data = BP_XProfile_ProfileData::get_all_for_user( $members_template->member->id );
314
315
$data = xprofile_format_profile_field( $members_template->member->profile_data[$field]['field_type'], $members_template->member->profile_data[$field]['field_data'] );
316
916
917
} else if ( bp_is_activation_page() ) {
918
$title = __( 'Activate your Account', 'buddypress' );
919
+
920
+ } else if ( bp_is_group_create() ) {
921
+ $title = __( 'Create a Group', 'buddypress' );
922
+
923
+ } else if ( bp_is_create_blog() ) {
924
+ $title = __( 'Create a Blog', 'buddypress' );
925
}
926
927
if ( defined( 'BP_ENABLE_MULTIBLOG' ) ) {
1189
$r = wp_parse_args( $args, $defaults );
1190
extract( $r, EXTR_SKIP );
1191
1192
+ $signup_avatar_dir = ( !empty( $_POST['signup_avatar_dir'] ) ) ? $_POST['signup_avatar_dir'] : $bp->signup->avatar_dir;
1193
1194
+ if ( empty( $signup_avatar_dir ) ) {
1195
+ if ( empty( $bp->grav_default->user ) ) {
1196
+ $default_grav = 'wavatar';
1197
+ } else if ( 'mystery' == $bp->grav_default->user ) {
1198
+ $default_grav = BP_PLUGIN_URL . '/bp-core/images/mystery-man.jpg';
1199
} else {
1200
+ $default_grav = $bp->grav_default->user;
1201
}
1202
+
1203
+ $gravatar_url = apply_filters( 'bp_gravatar_url', 'http://www.gravatar.com/avatar/' );
1204
+ return apply_filters( 'bp_get_signup_avatar', '<img src="' . $gravatar_url . md5( $_POST['signup_email'] ) . '?d=' . $default_grav . '&amp;s=' . $size ) . '" width="' . $size . '" height="' . $size . '" alt="' . $alt . '" class="' . $class . '" />';
1205
+ } else {
1206
+ return apply_filters( 'bp_get_signup_avatar', bp_core_fetch_avatar( array( 'item_id' => $signup_avatar_dir, 'object' => 'signup', 'avatar_dir' => 'avatars/signups', 'type' => 'full', 'width' => $size, 'height' => $size, 'alt' => $alt, 'class' => $class ) ) );
1207
}
1208
}
1209
1246
}
1247
1248
function bp_registration_needs_activation() {
1249
+ return apply_filters( 'bp_registration_needs_activation', true );
1250
}
1251
1252
function bp_mentioned_user_display_name( $user_id_or_username ) {
1693
function bp_is_create_blog() {
1694
global $bp;
1695
1696
+ if ( BP_BLOGS_SLUG == $bp->current_component && 'create' == $bp->current_action )
1697
return true;
1698
1699
return false;
bp-core/bp-core-wpabstraction.php CHANGED
@@ -89,65 +89,3 @@ if ( !function_exists( 'update_blog_status' ) ) {
89
return true;
90
}
91
}
92
-
93
- if ( !function_exists( 'wpmu_validate_user_signup' ) ) {
94
- function wpmu_validate_user_signup( $user_name, $user_email ) {
95
- global $wpdb;
96
-
97
- $errors = new WP_Error();
98
-
99
- $user_email = sanitize_email( $user_email );
100
-
101
- if ( empty( $user_name ) )
102
- $errors->add('user_name', __("Please enter a username"));
103
-
104
- $maybe = array();
105
- preg_match( "/[a-z0-9]+/", $user_name, $maybe );
106
-
107
- $illegal_names = get_site_option( "illegal_names" );
108
- if( is_array( $illegal_names ) == false ) {
109
- $illegal_names = array( "www", "web", "root", "admin", "main", "invite", "administrator" );
110
- add_site_option( "illegal_names", $illegal_names );
111
- }
112
-
113
- if ( !validate_username( $user_name ) || in_array( $user_name, $illegal_names ) == true || $user_name != $maybe[0] ) {
114
- $errors->add('user_name', __("Only lowercase letters and numbers allowed"));
115
- }
116
-
117
- if( strlen( $user_name ) < 4 ) {
118
- $errors->add('user_name', __("Username must be at least 4 characters"));
119
- }
120
-
121
- if ( strpos( " " . $user_name, "_" ) != false )
122
- $errors->add('user_name', __("Sorry, usernames may not contain the character '_'!"));
123
-
124
- // all numeric?
125
- $match = array();
126
- preg_match( '/[0-9]*/', $user_name, $match );
127
- if ( $match[0] == $user_name )
128
- $errors->add('user_name', __("Sorry, usernames must have letters too!"));
129
-
130
- if ( !is_email( $user_email ) )
131
- $errors->add('user_email', __("Please check your email address."));
132
-
133
- $limited_email_domains = get_site_option( 'limited_email_domains' );
134
- if ( is_array( $limited_email_domains ) && empty( $limited_email_domains ) == false ) {
135
- $emaildomain = substr( $user_email, 1 + strpos( $user_email, '@' ) );
136
- if( in_array( $emaildomain, $limited_email_domains ) == false ) {
137
- $errors->add('user_email', __("Sorry, that email address is not allowed!"));
138
- }
139
- }
140
-
141
- // Check if the username has been used already.
142
- if ( username_exists($user_name) )
143
- $errors->add('user_name', __("Sorry, that username already exists!"));
144
-
145
- // Check if the email address has been used already.
146
- if ( email_exists($user_email) )
147
- $errors->add('user_email', __("Sorry, that email address is already used!"));
148
-
149
- $result = array('user_name' => $user_name, 'user_email' => $user_email, 'errors' => $errors);
150
-
151
- return apply_filters('wpmu_validate_user_signup', $result);
152
- }
153
- }
89
return true;
90
}
91
}
bp-forums/bp-forums-templatetags.php CHANGED
@@ -289,7 +289,9 @@ function bp_the_topic_poster_name() {
289
function bp_get_the_topic_poster_name() {
290
global $forum_template;
291
292
- if ( !$name = bp_core_get_userlink( $forum_template->topic->poster_id ) )
293
return __( 'Deleted User', 'buddypress' );
294
295
return apply_filters( 'bp_get_the_topic_poster_name', $name );
289
function bp_get_the_topic_poster_name() {
290
global $forum_template;
291
292
+ $poster_id = ( empty( $forum_template->topic->poster_id ) ) ? $forum_template->topic->topic_poster : $forum_template->topic->poster_id;
293
+
294
+ if ( !$name = bp_core_get_userlink( $poster_id ) )
295
return __( 'Deleted User', 'buddypress' );
296
297
return apply_filters( 'bp_get_the_topic_poster_name', $name );
bp-friends.php CHANGED
@@ -98,7 +98,7 @@ function friends_screen_my_friends() {
98
global $bp;
99
100
// Delete any friendship acceptance notifications for the user when viewing a profile
101
- bp_core_delete_notifications_for_user_by_type( $bp->loggedin_user->id, 'friends', 'friendship_accepted' );
102
103
do_action( 'friends_screen_my_friends' );
104
@@ -133,6 +133,9 @@ function friends_screen_requests() {
133
134
do_action( 'friends_screen_requests' );
135
136
bp_core_load_template( apply_filters( 'friends_template_requests', 'members/single/home' ) );
137
}
138
@@ -317,11 +320,11 @@ function friends_format_notifications( $action, $item_id, $secondary_item_id, $t
317
318
case 'friendship_request':
319
if ( (int)$total_items > 1 ) {
320
- return apply_filters( 'bp_friends_multiple_friendship_request_notification', '<a href="' . $bp->loggedin_user->domain . $bp->friends->slug . '/requests" title="' . __( 'Friendship requests', 'buddypress' ) . '">' . sprintf( __('You have %d pending friendship requests', 'buddypress' ), (int)$total_items ) . '</a>', $total_items );
321
} else {
322
$user_fullname = bp_core_get_user_displayname( $item_id );
323
$user_url = bp_core_get_user_domain( $item_id );
324
- return apply_filters( 'bp_friends_single_friendship_request_notification', '<a href="' . $bp->loggedin_user->domain . $bp->friends->slug . '/requests" title="' . __( 'Friendship requests', 'buddypress' ) . '">' . sprintf( __('You have a friendship request from %s', 'buddypress' ), $user_fullname ) . '</a>', $user_fullname );
325
}
326
break;
327
}
@@ -362,7 +365,7 @@ function friends_add_friend( $initiator_userid, $friend_userid, $force_accept =
362
363
if ( !$force_accept ) {
364
// Add the on screen notification
365
- bp_core_add_notification( $friendship->initiator_user_id, $friendship->friend_user_id, 'friends', 'friendship_request' );
366
367
// Send the email notification
368
require_once( BP_PLUGIN_DIR . '/bp-friends/bp-friends-notifications.php' );
@@ -408,10 +411,10 @@ function friends_accept_friendship( $friendship_id ) {
408
friends_update_friend_totals( $friendship->initiator_user_id, $friendship->friend_user_id );
409
410
/* Remove the friend request notice */
411
- bp_core_delete_notifications_for_user_by_item_id( $friendship->friend_user_id, $friendship->initiator_user_id, 'friends', 'friendship_request' );
412
413
/* Add a friend accepted notice for the initiating user */
414
- bp_core_add_notification( $friendship->friend_user_id, $friendship->initiator_user_id, 'friends', 'friendship_accepted' );
415
416
$initiator_link = bp_core_get_userlink( $friendship->initiator_user_id );
417
$friend_link = bp_core_get_userlink( $friendship->friend_user_id );
@@ -449,7 +452,7 @@ function friends_reject_friendship( $friendship_id ) {
449
450
if ( !$friendship->is_confirmed && BP_Friends_Friendship::reject( $friendship_id ) ) {
451
// Remove the friend request notice
452
- bp_core_delete_notifications_for_user_by_item_id( $friendship->friend_user_id, $friendship->initiator_user_id, 'friends', 'friendship_request' );
453
454
do_action( 'friends_friendship_rejected', $friendship_id, &$friendship );
455
return true;
@@ -597,7 +600,7 @@ function friends_remove_data( $user_id ) {
597
delete_usermeta( $user_id, 'total_friend_count' );
598
599
/* Remove friendship requests FROM user */
600
- bp_core_delete_notifications_from_user( $user_id, $bp->friends->slug, 'friendship_request' );
601
602
do_action( 'friends_remove_data', $user_id );
603
}
@@ -631,7 +634,7 @@ function friends_clear_friend_notifications() {
631
global $bp;
632
633
if ( isset($_GET['new']) )
634
- bp_core_delete_notifications_for_user_by_type( $bp->loggedin_user->id, 'friends', 'friendship_accepted' );
635
}
636
add_action( 'bp_activity_screen_my_activity', 'friends_clear_friend_notifications' );
637
98
global $bp;
99
100
// Delete any friendship acceptance notifications for the user when viewing a profile
101
+ bp_core_delete_notifications_for_user_by_type( $bp->loggedin_user->id, $bp->friends->id, 'friendship_accepted' );
102
103
do_action( 'friends_screen_my_friends' );
104
133
134
do_action( 'friends_screen_requests' );
135
136
+ if ( isset( $_GET['new'] ) )
137
+ bp_core_delete_notifications_for_user_by_type( $bp->loggedin_user->id, $bp->friends->id, 'friendship_request' );
138
+
139
bp_core_load_template( apply_filters( 'friends_template_requests', 'members/single/home' ) );
140
}
141
320
321
case 'friendship_request':
322
if ( (int)$total_items > 1 ) {
323
+ return apply_filters( 'bp_friends_multiple_friendship_request_notification', '<a href="' . $bp->loggedin_user->domain . $bp->friends->slug . '/requests