Ticket #2299: forum-subscriptions.3.diff
File forum-subscriptions.3.diff, 70.4 KB (added by , 10 years ago) |
---|
-
includes/admin/tools.php
158 158 */ 159 159 function bbp_admin_repair_list() { 160 160 $repair_list = array( 161 0 => array( 'bbp-sync-topic-meta', __( 'Recalculate the parent topic for each post', 'bbpress' ), 'bbp_admin_repair_topic_meta' ), 162 5 => array( 'bbp-sync-forum-meta', __( 'Recalculate the parent forum for each post', 'bbpress' ), 'bbp_admin_repair_forum_meta' ), 163 10 => array( 'bbp-sync-forum-visibility', __( 'Recalculate private and hidden forums', 'bbpress' ), 'bbp_admin_repair_forum_visibility' ), 164 15 => array( 'bbp-sync-all-topics-forums', __( 'Recalculate last activity in each topic and forum', 'bbpress' ), 'bbp_admin_repair_freshness' ), 165 20 => array( 'bbp-sync-all-topics-sticky', __( 'Recalculate the sticky relationship of each topic', 'bbpress' ), 'bbp_admin_repair_sticky' ), 166 25 => array( 'bbp-group-forums', __( 'Repair BuddyPress Group Forum relationships', 'bbpress' ), 'bbp_admin_repair_group_forum_relationship' ), 167 30 => array( 'bbp-forum-topics', __( 'Count topics in each forum', 'bbpress' ), 'bbp_admin_repair_forum_topic_count' ), 168 35 => array( 'bbp-forum-replies', __( 'Count replies in each forum', 'bbpress' ), 'bbp_admin_repair_forum_reply_count' ), 169 40 => array( 'bbp-topic-replies', __( 'Count replies in each topic', 'bbpress' ), 'bbp_admin_repair_topic_reply_count' ), 170 45 => array( 'bbp-topic-voices', __( 'Count voices in each topic', 'bbpress' ), 'bbp_admin_repair_topic_voice_count' ), 171 50 => array( 'bbp-topic-hidden-replies', __( 'Count spammed & trashed replies in each topic', 'bbpress' ), 'bbp_admin_repair_topic_hidden_reply_count' ), 172 55 => array( 'bbp-user-topics', __( 'Count topics for each user', 'bbpress' ), 'bbp_admin_repair_user_topic_count' ), 173 60 => array( 'bbp-user-replies', __( 'Count replies for each user', 'bbpress' ), 'bbp_admin_repair_user_reply_count' ), 174 65 => array( 'bbp-user-favorites', __( 'Remove trashed topics from user favorites', 'bbpress' ), 'bbp_admin_repair_user_favorites' ), 175 70 => array( 'bbp-user-subscriptions', __( 'Remove trashed topics from user subscriptions', 'bbpress' ), 'bbp_admin_repair_user_subscriptions' ), 176 75 => array( 'bbp-user-role-map', __( 'Remap existing users to default forum roles', 'bbpress' ), 'bbp_admin_repair_user_roles' ) 161 0 => array( 'bbp-sync-topic-meta', __( 'Recalculate the parent topic for each post', 'bbpress' ), 'bbp_admin_repair_topic_meta' ), 162 5 => array( 'bbp-sync-forum-meta', __( 'Recalculate the parent forum for each post', 'bbpress' ), 'bbp_admin_repair_forum_meta' ), 163 10 => array( 'bbp-sync-forum-visibility', __( 'Recalculate private and hidden forums', 'bbpress' ), 'bbp_admin_repair_forum_visibility' ), 164 15 => array( 'bbp-sync-all-topics-forums', __( 'Recalculate last activity in each topic and forum', 'bbpress' ), 'bbp_admin_repair_freshness' ), 165 20 => array( 'bbp-sync-all-topics-sticky', __( 'Recalculate the sticky relationship of each topic', 'bbpress' ), 'bbp_admin_repair_sticky' ), 166 25 => array( 'bbp-group-forums', __( 'Repair BuddyPress Group Forum relationships', 'bbpress' ), 'bbp_admin_repair_group_forum_relationship' ), 167 30 => array( 'bbp-forum-topics', __( 'Count topics in each forum', 'bbpress' ), 'bbp_admin_repair_forum_topic_count' ), 168 35 => array( 'bbp-forum-replies', __( 'Count replies in each forum', 'bbpress' ), 'bbp_admin_repair_forum_reply_count' ), 169 40 => array( 'bbp-topic-replies', __( 'Count replies in each topic', 'bbpress' ), 'bbp_admin_repair_topic_reply_count' ), 170 45 => array( 'bbp-topic-voices', __( 'Count voices in each topic', 'bbpress' ), 'bbp_admin_repair_topic_voice_count' ), 171 50 => array( 'bbp-topic-hidden-replies', __( 'Count spammed & trashed replies in each topic', 'bbpress' ), 'bbp_admin_repair_topic_hidden_reply_count' ), 172 55 => array( 'bbp-user-topics', __( 'Count topics for each user', 'bbpress' ), 'bbp_admin_repair_user_topic_count' ), 173 60 => array( 'bbp-user-replies', __( 'Count replies for each user', 'bbpress' ), 'bbp_admin_repair_user_reply_count' ), 174 65 => array( 'bbp-user-favorites', __( 'Remove trashed topics from user favorites', 'bbpress' ), 'bbp_admin_repair_user_favorites' ), 175 70 => array( 'bbp-user-subscriptions', __( 'Remove trashed topics from user subscriptions', 'bbpress' ), 'bbp_admin_repair_user_subscriptions' ), 176 75 => array( 'bbp-user-forum-subscriptions', __( 'Remove trashed forums from user subscriptions', 'bbpress' ), 'bbp_admin_repair_user_forum_subscriptions' ), 177 80 => array( 'bbp-user-role-map', __( 'Remap existing users to default forum roles', 'bbpress' ), 'bbp_admin_repair_user_roles' ) 177 178 ); 178 179 ksort( $repair_list ); 179 180 … … 646 647 } 647 648 648 649 /** 649 * Clean the users' subscriptions650 * Clean the users' topic subscriptions 650 651 * 651 652 * @since bbPress (r2668) 652 653 * … … 707 708 } 708 709 709 710 /** 711 * Clean the users' forum subscriptions 712 * 713 * @since bbPress (r5155) 714 * 715 * @uses bbp_get_forum_post_type() To get the topic post type 716 * @uses wpdb::query() To run our recount sql queries 717 * @uses is_wp_error() To check if the executed query returned {@link WP_Error} 718 * @return array An array of the status code and the message 719 */ 720 function bbp_admin_repair_user_forum_subscriptions() { 721 global $wpdb; 722 723 $statement = __( 'Removing trashed forums from user subscriptions… %s', 'bbpress' ); 724 $result = __( 'Failed!', 'bbpress' ); 725 $key = $wpdb->prefix . '_bbp_forum_subscriptions'; 726 $users = $wpdb->get_results( "SELECT `user_id`, `meta_value` AS `subscriptions` FROM `{$wpdb->usermeta}` WHERE `meta_key` = '{$key}';" ); 727 728 if ( is_wp_error( $users ) ) 729 return array( 1, sprintf( $statement, $result ) ); 730 731 $forums = $wpdb->get_col( "SELECT `ID` FROM `{$wpdb->posts}` WHERE `post_type` = '" . bbp_get_forum_post_type() . "' AND `post_status` = '" . bbp_get_public_status_id() . "';" ); 732 if ( is_wp_error( $forums ) ) 733 return array( 2, sprintf( $statement, $result ) ); 734 735 $values = array(); 736 foreach ( $users as $user ) { 737 if ( empty( $user->subscriptions ) || !is_string( $user->subscriptions ) ) 738 continue; 739 740 $subscriptions = array_intersect( $forums, explode( ',', $user->subscriptions ) ); 741 if ( empty( $subscriptions ) || !is_array( $subscriptions ) ) 742 continue; 743 744 $subscriptions_joined = implode( ',', $subscriptions ); 745 $values[] = "('{$user->user_id}', '{$key}', '{$subscriptions_joined}')"; 746 747 // Cleanup 748 unset( $subscriptions, $subscriptions_joined ); 749 } 750 751 if ( !count( $values ) ) { 752 $result = __( 'Nothing to remove!', 'bbpress' ); 753 return array( 0, sprintf( $statement, $result ) ); 754 } 755 756 $sql_delete = "DELETE FROM `{$wpdb->usermeta}` WHERE `meta_key` = '{$key}';"; 757 if ( is_wp_error( $wpdb->query( $sql_delete ) ) ) 758 return array( 4, sprintf( $statement, $result ) ); 759 760 foreach ( array_chunk( $values, 10000 ) as $chunk ) { 761 $chunk = "\n" . implode( ",\n", $chunk ); 762 $sql_insert = "INSERT INTO `{$wpdb->usermeta}` (`user_id`, `meta_key`, `meta_value`) VALUES $chunk;"; 763 if ( is_wp_error( $wpdb->query( $sql_insert ) ) ) { 764 return array( 5, sprintf( $statement, $result ) ); 765 } 766 } 767 768 return array( 0, sprintf( $statement, __( 'Complete!', 'bbpress' ) ) ); 769 } 770 771 /** 710 772 * This repair tool will map each user of the current site to their respective 711 773 * forums role. By default, Admins will be Key Masters, and every other role 712 774 * will be the default role defined in Settings > Forums (Participant). -
includes/common/functions.php
982 982 /** Subscriptions *************************************************************/ 983 983 984 984 /** 985 * Sends notification emails for new posts985 * Sends notification emails for new replies to subscribed topics 986 986 * 987 987 * Gets new post's ID and check if there are subscribed users to that topic, and 988 988 * if there are, send notifications … … 992 992 * @param int $reply_id ID of the newly made reply 993 993 * @uses bbp_is_subscriptions_active() To check if the subscriptions are active 994 994 * @uses bbp_get_reply_id() To validate the reply ID 995 * @uses bbp_get_topic_id() To validate the topic ID 996 * @uses bbp_get_forum_id() To validate the forum ID 995 997 * @uses bbp_get_reply() To get the reply 996 * @uses bbp_get_reply_topic_id() To get the topic ID of the reply997 998 * @uses bbp_is_reply_published() To make sure the reply is published 998 999 * @uses bbp_get_topic_id() To validate the topic ID 999 1000 * @uses bbp_get_topic() To get the reply's topic 1000 1001 * @uses bbp_is_topic_published() To make sure the topic is published 1001 * @uses get_the_author_meta() To get theauthor's display name1002 * @uses do_action() Calls 'bbp_pre_notify_subscribers' with the reply id and1003 * topic id 1002 * @uses bbp_get_reply_author_display_name() To get the reply author's display name 1003 * @uses do_action() Calls 'bbp_pre_notify_subscribers' with the reply id, 1004 * topic id and user id 1004 1005 * @uses bbp_get_topic_subscribers() To get the topic subscribers 1005 1006 * @uses apply_filters() Calls 'bbp_subscription_mail_message' with the 1006 * message, reply id, topic id and user id 1007 * message, reply id, topic id and user id 1008 * @uses apply_filters() Calls 'bbp_subscription_mail_title' with the 1009 * topic title, reply id, topic id and user id 1010 * @uses apply_filters() Calls 'bbp_subscription_mail_headers' 1007 1011 * @uses get_userdata() To get the user data 1008 1012 * @uses wp_mail() To send the mail 1009 * @uses do_action() Calls 'bbp_post_notify_subscribers' with the reply id 1010 * and topicid1013 * @uses do_action() Calls 'bbp_post_notify_subscribers' with the reply id, 1014 * topic id and user id 1011 1015 * @return bool True on success, false on failure 1012 1016 */ 1013 1017 function bbp_notify_subscribers( $reply_id = 0, $topic_id = 0, $forum_id = 0, $anonymous_data = false, $reply_author = 0 ) { … … 1036 1040 1037 1041 /** User ******************************************************************/ 1038 1042 1039 // Get subscribers and bail if empty1043 // Get topic subscribers and bail if empty 1040 1044 $user_ids = bbp_get_topic_subscribers( $topic_id, true ); 1041 1045 if ( empty( $user_ids ) ) 1042 1046 return false; … … 1108 1112 return true; 1109 1113 } 1110 1114 1115 /** 1116 * Sends notification emails for new topics to subscribed forums 1117 * 1118 * @since bbPress (r5155) 1119 * 1120 * Gets new post's ID and check if there are subscribed users to that topic, and 1121 * if there are, send notifications 1122 * 1123 * @since bbPress (r5155) 1124 * 1125 * @param int $topic_id ID of the newly made reply 1126 * @uses bbp_is_subscriptions_active() To check if the subscriptions are active 1127 * @uses bbp_get_topic_id() To validate the topic ID 1128 * @uses bbp_get_forum_id() To validate the forum ID 1129 * @uses bbp_is_topic_published() To make sure the topic is published 1130 * @uses bbp_get_forum_subscribers() To get the forum subscribers 1131 * @uses bbp_get_topic_author_display_name() To get the topic author's display name 1132 * @uses do_action() Calls 'bbp_pre_notify_forum_subscribers' with the topic id, 1133 * forum id and user id 1134 * @uses apply_filters() Calls 'bbp_forum_subscription_mail_message' with the 1135 * message, topic id, forum id and user id 1136 * @uses apply_filters() Calls 'bbp_forum_subscription_mail_title' with the 1137 * topic title, topic id, forum id and user id 1138 * @uses apply_filters() Calls 'bbp_forum_subscription_mail_headers' 1139 * @uses get_userdata() To get the user data 1140 * @uses wp_mail() To send the mail 1141 * @uses do_action() Calls 'bbp_post_notify_forum_subscribers' with the topic, 1142 * id, forum id and user id 1143 * @return bool True on success, false on failure 1144 */ 1145 function bbp_notify_forum_subscribers( $topic_id = 0, $forum_id = 0, $anonymous_data = false, $topic_author = 0 ) { 1146 1147 // Bail if subscriptions are turned off 1148 if ( !bbp_is_subscriptions_active() ) 1149 return false; 1150 1151 /** Validation ************************************************************/ 1152 1153 $topic_id = bbp_get_topic_id( $topic_id ); 1154 $forum_id = bbp_get_forum_id( $forum_id ); 1155 1156 /** Topic *****************************************************************/ 1157 1158 // Bail if topic is not published 1159 if ( ! bbp_is_topic_published( $topic_id ) ) 1160 return false; 1161 1162 /** User ******************************************************************/ 1163 1164 // Get forum subscribers and bail if empty 1165 $user_ids = bbp_get_forum_subscribers( $forum_id, true ); 1166 if ( empty( $user_ids ) ) 1167 return false; 1168 1169 // Poster name 1170 $topic_author_name = bbp_get_topic_author_display_name( $topic_id ); 1171 1172 /** Mail ******************************************************************/ 1173 1174 do_action( 'bbp_pre_notify_forum_subscribers', $topic_id, $forum_id, $user_ids ); 1175 1176 // Remove filters from reply content and topic title to prevent content 1177 // from being encoded with HTML entities, wrapped in paragraph tags, etc... 1178 remove_all_filters( 'bbp_get_topic_content' ); 1179 remove_all_filters( 'bbp_get_topic_title' ); 1180 1181 // Strip tags from text 1182 $topic_title = strip_tags( bbp_get_topic_title( $topic_id ) ); 1183 $topic_content = strip_tags( bbp_get_topic_content( $topic_id ) ); 1184 $topic_url = get_permalink( $topic_id ); 1185 $blog_name = wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES ); 1186 1187 // Loop through users 1188 foreach ( (array) $user_ids as $user_id ) { 1189 1190 // Don't send notifications to the person who made the post 1191 if ( !empty( $topic_author ) && (int) $user_id === (int) $topic_author ) 1192 continue; 1193 1194 // For plugins to filter messages per reply/topic/user 1195 $message = sprintf( __( '%1$s wrote: 1196 1197 %2$s 1198 1199 Topic Link: %3$s 1200 1201 ----------- 1202 1203 You are receiving this email because you subscribed to a forum. 1204 1205 Login and visit the topic to unsubscribe from these emails.', 'bbpress' ), 1206 1207 $topic_author_name, 1208 $topic_content, 1209 $topic_url 1210 ); 1211 $message = apply_filters( 'bbp_forum_subscription_mail_message', $message, $topic_id, $forum_id, $user_id ); 1212 if ( empty( $message ) ) 1213 continue; 1214 1215 // For plugins to filter titles per reply/topic/user 1216 $subject = apply_filters( 'bbp_forum_subscription_mail_title', '[' . $blog_name . '] ' . $topic_title, $topic_id, $forum_id, $user_id ); 1217 if ( empty( $subject ) ) 1218 continue; 1219 1220 // Custom headers 1221 $headers = apply_filters( 'bbp_forum_subscription_mail_headers', array() ); 1222 1223 // Get user data of this user 1224 $user = get_userdata( $user_id ); 1225 1226 // Send notification email 1227 wp_mail( $user->user_email, $subject, $message, $headers ); 1228 } 1229 1230 do_action( 'bbp_post_notify_forum_subscribers', $topic_id, $forum_id, $user_ids ); 1231 1232 return true; 1233 } 1234 1111 1235 /** Login *********************************************************************/ 1112 1236 1113 1237 /** -
includes/common/template.php
2344 2344 return apply_filters( 'bbp_get_breadcrumb', $trail, $crumbs, $r ); 2345 2345 } 2346 2346 2347 /** Forum Subscriptions ******************************************************/ 2348 2349 /** 2350 * Output the forum subscription link 2351 * 2352 * @since bbPress (r5155) 2353 * 2354 * @uses bbp_get_forum_subscription_link() 2355 */ 2356 function bbp_forum_subscription_link( $args = array() ) { 2357 echo bbp_get_forum_subscription_link( $args ); 2358 } 2359 2360 /** 2361 * Get the forum subscription link 2362 * 2363 * @since bbPress (r5155) 2364 * 2365 * @uses bbp_parse_args() 2366 * @uses bbp_get_user_subscribe_link() 2367 * @uses apply_filters() Calls 'bbp_get_forum_subscribe_link' 2368 */ 2369 function bbp_get_forum_subscription_link( $args = array() ) { 2370 2371 // Parse args 2372 $r = bbp_parse_args( $args, array( 2373 2374 // Forum 2375 'forum_id' => 0, 2376 2377 // User 2378 'user_id' => 0, 2379 2380 // HTML 2381 'before' => '<div class="bbp-forum-subscription"><p>', 2382 'after' => '</p></div>', 2383 2384 // Text 2385 'subscribe' => __( 'Subscribe to Forum', 'bbpress' ), 2386 'unsubscribe' => __( 'Unsubscribe from Forum', 'bbpress' ), 2387 2388 ), 'get_forum_subscribe_link' ); 2389 2390 $link = $r['before']; 2391 2392 $link .= bbp_get_user_subscribe_link( array( 2393 'before' => '', 2394 'subscribe' => $r['subscribe'], 2395 'unsubscribe' => $r['unsubscribe'] 2396 ) ); 2397 2398 $link .= $r['after']; 2399 2400 return apply_filters( 'bbp_get_forum_subscribe_link', $link, $r ); 2401 } 2402 2347 2403 /** Topic Tags ***************************************************************/ 2348 2404 2349 2405 /** -
includes/core/actions.php
37 37 * 38 38 * v--WordPress Actions v--bbPress Sub-actions 39 39 */ 40 add_action( 'plugins_loaded', 'bbp_loaded', 41 add_action( 'init', 'bbp_init', 42 add_action( 'parse_query', 'bbp_parse_query', 43 add_action( 'widgets_init', 'bbp_widgets_init', 44 add_action( 'generate_rewrite_rules', 'bbp_generate_rewrite_rules', 45 add_action( 'wp_enqueue_scripts', 'bbp_enqueue_scripts', 46 add_action( 'wp_head', 'bbp_head', 47 add_action( 'wp_footer', 'bbp_footer', 48 add_action( 'set_current_user', 'bbp_setup_current_user', 49 add_action( 'setup_theme', 'bbp_setup_theme', 50 add_action( 'after_setup_theme', 'bbp_after_setup_theme', 51 add_action( 'template_redirect', 'bbp_template_redirect', 52 add_action( 'login_form_login', 'bbp_login_form_login', 53 add_action( 'profile_update', 'bbp_profile_update', 54 add_action( 'user_register', 'bbp_user_register', 40 add_action( 'plugins_loaded', 'bbp_loaded', 10 ); 41 add_action( 'init', 'bbp_init', 0 ); // Early for bbp_register 42 add_action( 'parse_query', 'bbp_parse_query', 2 ); // Early for overrides 43 add_action( 'widgets_init', 'bbp_widgets_init', 10 ); 44 add_action( 'generate_rewrite_rules', 'bbp_generate_rewrite_rules', 10 ); 45 add_action( 'wp_enqueue_scripts', 'bbp_enqueue_scripts', 10 ); 46 add_action( 'wp_head', 'bbp_head', 10 ); 47 add_action( 'wp_footer', 'bbp_footer', 10 ); 48 add_action( 'set_current_user', 'bbp_setup_current_user', 10 ); 49 add_action( 'setup_theme', 'bbp_setup_theme', 10 ); 50 add_action( 'after_setup_theme', 'bbp_after_setup_theme', 10 ); 51 add_action( 'template_redirect', 'bbp_template_redirect', 8 ); // Before BuddyPress's 10 [BB2225] 52 add_action( 'login_form_login', 'bbp_login_form_login', 10 ); 53 add_action( 'profile_update', 'bbp_profile_update', 10, 2 ); // user_id and old_user_data 54 add_action( 'user_register', 'bbp_user_register', 10 ); 55 55 56 56 /** 57 57 * bbp_loaded - Attached to 'plugins_loaded' above … … 118 118 add_action( 'bbp_register', 'bbp_register_shortcodes', 10 ); 119 119 120 120 // Autoembeds 121 add_action( 'bbp_init', 'bbp_reply_content_autoembed', 8 122 add_action( 'bbp_init', 'bbp_topic_content_autoembed', 8 121 add_action( 'bbp_init', 'bbp_reply_content_autoembed', 8 ); 122 add_action( 'bbp_init', 'bbp_topic_content_autoembed', 8 ); 123 123 124 124 /** 125 125 * bbp_ready - attached to end 'bbp_init' above … … 224 224 // Subscriptions 225 225 add_action( 'bbp_trash_topic', 'bbp_remove_topic_from_all_subscriptions' ); 226 226 add_action( 'bbp_delete_topic', 'bbp_remove_topic_from_all_subscriptions' ); 227 add_action( 'bbp_trash_forum', 'bbp_remove_forum_from_all_subscriptions' ); 228 add_action( 'bbp_delete_forum', 'bbp_remove_forum_from_all_subscriptions' ); 227 229 add_action( 'bbp_new_reply', 'bbp_notify_subscribers', 11, 5 ); 230 add_action( 'bbp_new_topic', 'bbp_notify_forum_subscribers', 11, 4 ); 228 231 229 232 // Sticky 230 233 add_action( 'bbp_trash_topic', 'bbp_unstick_topic' ); … … 297 300 add_action( 'bbp_post_request', 'bbp_new_topic_handler', 10 ); 298 301 299 302 // Theme-side GET requests 300 add_action( 'bbp_get_request', 'bbp_toggle_topic_handler', 1 ); 301 add_action( 'bbp_get_request', 'bbp_toggle_reply_handler', 1 ); 302 add_action( 'bbp_get_request', 'bbp_favorites_handler', 1 ); 303 add_action( 'bbp_get_request', 'bbp_subscriptions_handler', 1 ); 304 add_action( 'bbp_get_request', 'bbp_search_results_redirect', 10 ); 303 add_action( 'bbp_get_request', 'bbp_toggle_topic_handler', 1 ); 304 add_action( 'bbp_get_request', 'bbp_toggle_reply_handler', 1 ); 305 add_action( 'bbp_get_request', 'bbp_favorites_handler', 1 ); 306 add_action( 'bbp_get_request', 'bbp_subscriptions_handler', 1 ); 307 add_action( 'bbp_get_request', 'bbp_forum_subscriptions_handler', 1 ); 308 add_action( 'bbp_get_request', 'bbp_search_results_redirect', 10 ); 305 309 306 310 // Maybe convert the users password 307 311 add_action( 'bbp_login_form_login', 'bbp_user_maybe_convert_pass' ); -
includes/forums/functions.php
961 961 return true; 962 962 } 963 963 964 /** Subscriptions *************************************************/ 965 966 /** 967 * Remove a deleted forum from all users' subscriptions 968 * 969 * @since bbPress (r5155) 970 * 971 * @param int $forum_id Get the forum ID to remove 972 * @uses bbp_is_subscriptions_active() To check if the subscriptions are active 973 * @uses bbp_get_forum_id To get the forum id 974 * @uses bbp_get_forum_subscribers() To get the forum subscribers 975 * @uses bbp_remove_user_subscription() To remove the user subscription 976 */ 977 function bbp_remove_forum_from_all_subscriptions( $forum_id = 0 ) { 978 979 // Subscriptions are not active 980 if ( ! bbp_is_subscriptions_active() ) 981 return; 982 983 $forum_id = bbp_get_forum_id( $forum_id ); 984 985 // Bail if no forum 986 if ( empty( $forum_id ) ) 987 return; 988 989 // Get users 990 $users = (array) bbp_get_forum_subscribers( $forum_id ); 991 992 // Users exist 993 if ( !empty( $users ) ) { 994 995 // Loop through users 996 foreach ( $users as $user ) { 997 998 // Remove each user 999 bbp_remove_user_subscription( $user, $forum_id ); 1000 } 1001 } 1002 } 1003 964 1004 /** Count Bumpers *************************************************************/ 965 1005 966 1006 /** -
includes/forums/template.php
442 442 } 443 443 444 444 /** 445 * Output checked value of forum subscription 446 * 447 * @since bbPress (r5155) 448 * 449 * @uses bbp_get_form_forum_subscribed() To get the subscribed checkbox value 450 */ 451 function bbp_form_forum_subscribed() { 452 echo bbp_get_form_forum_subscribed(); 453 } 454 /** 455 * Return checked value of forum subscription 456 * 457 * @since bbPress (r5155) 458 * 459 * @uses bbp_is_forum_edit() To check if it's the forum edit page 460 * @uses bbp_get_global_post_field() To get current post author 461 * @uses bbp_get_current_user_id() To get the current user id 462 * @uses bbp_is_user_subscribed() To check if the user is subscribed to 463 * the forum 464 * @uses apply_filters() Calls 'bbp_get_form_forum_subscribed' with the 465 * option 466 * @return string Checked value of forum subscription 467 */ 468 function bbp_get_form_forum_subscribed() { 469 470 // Get _POST data 471 if ( bbp_is_post_request() && isset( $_POST['bbp_forum_subscription'] ) ) { 472 $forum_subscribed = (bool) $_POST['bbp_forum_subscription']; 473 474 // Get edit data 475 } elseif ( bbp_is_forum_edit() || bbp_is_reply_edit() ) { 476 477 // Get current posts author 478 $post_author = bbp_get_global_post_field( 'post_author', 'raw' ); 479 480 // Post author is not the current user 481 if ( bbp_get_current_user_id() !== $post_author ) { 482 $forum_subscribed = bbp_is_user_subscribed( $post_author ); 483 484 // Post author is the current user 485 } else { 486 $forum_subscribed = bbp_is_user_subscribed( bbp_get_current_user_id() ); 487 } 488 489 // Get current status 490 } elseif ( bbp_is_single_forum() ) { 491 $forum_subscribed = bbp_is_user_subscribed( bbp_get_current_user_id() ); 492 493 // No data 494 } else { 495 $forum_subscribed = false; 496 } 497 498 // Get checked output 499 $checked = checked( $forum_subscribed, true, false ); 500 501 return apply_filters( 'bbp_get_form_forum_subscribed', $checked, $forum_subscribed ); 502 } 503 504 /** 445 505 * Output the forums last active ID 446 506 * 447 507 * @since bbPress (r2860) -
includes/topics/functions.php
2200 2200 * 2201 2201 * @since bbPress (r2652) 2202 2202 * 2203 * @param int $topic_id Topic ID to remove 2203 * @param int $topic_id Get the topic id to remove 2204 * @uses bbp_get_topic_id To get the topic id 2204 2205 * @uses bbp_get_topic_favoriters() To get the topic's favoriters 2205 2206 * @uses bbp_remove_user_favorite() To remove the topic from user's favorites 2206 2207 */ … … 2231 2232 * 2232 2233 * @since bbPress (r2652) 2233 2234 * 2234 * @param int $topic_id Topic IDto remove2235 * @param int $topic_id Get the topic id to remove 2235 2236 * @uses bbp_is_subscriptions_active() To check if the subscriptions are active 2237 * @uses bbp_get_topic_id To get the topic id 2236 2238 * @uses bbp_get_topic_subscribers() To get the topic subscribers 2237 2239 * @uses bbp_remove_user_subscription() To remove the user subscription 2238 2240 */ -
includes/users/functions.php
163 163 * Return the raw database count of topics by a user 164 164 * 165 165 * @since bbPress (r3633) 166 * 166 167 * @global WPDB $wpdb 167 168 * @uses bbp_get_user_id() 168 169 * @uses get_posts_by_author_sql() … … 187 188 * Return the raw database count of replies by a user 188 189 * 189 190 * @since bbPress (r3633) 191 * 190 192 * @global WPDB $wpdb 191 193 * @uses bbp_get_user_id() 192 194 * @uses get_posts_by_author_sql() … … 313 315 $favorites = bbp_get_user_favorites_topic_ids( $user_id ); 314 316 315 317 if ( !empty( $favorites ) ) { 316 318 317 319 // Checking a specific topic id 318 320 if ( !empty( $topic_id ) ) { 319 321 $topic = bbp_get_topic( $topic_id ); … … 412 414 /** 413 415 * Handles the front end adding and removing of favorite topics 414 416 * 417 * @since bbPress (rXXXX) 418 * 415 419 * @param string $action The requested action to compare this function to 416 420 * @uses bbp_get_user_id() To get the user id 417 421 * @uses bbp_verify_nonce_request() To verify the nonce and check the request … … 512 516 /** Subscriptions *************************************************************/ 513 517 514 518 /** 519 * Get the users who have subscribed to the forum 520 * 521 * @since bbPress (r5155) 522 * 523 * @param int $forum_id Optional. forum id 524 * @global WPDB $wpdb 525 * @uses bbp_get_forum_id() To get the forum id 526 * @uses wpdb::get_col() To execute our query and get the column back 527 * @uses apply_filters() Calls 'bbp_get_forum_subscribers' with the subscribers 528 * @return array|bool Results if the forum has any subscribers, otherwise false 529 */ 530 function bbp_get_forum_subscribers( $forum_id = 0 ) { 531 $forum_id = bbp_get_forum_id( $forum_id ); 532 if ( empty( $forum_id ) ) 533 return; 534 535 global $wpdb; 536 537 $key = $wpdb->prefix . '_bbp_forum_subscriptions'; 538 $users = wp_cache_get( 'bbp_get_forum_subscribers_' . $forum_id, 'bbpress_users' ); 539 if ( false === $users ) { 540 $users = $wpdb->get_col( "SELECT user_id FROM {$wpdb->usermeta} WHERE meta_key = '{$key}' and FIND_IN_SET('{$forum_id}', meta_value) > 0" ); 541 wp_cache_set( 'bbp_get_forum_subscribers_' . $forum_id, $users, 'bbpress_users' ); 542 } 543 544 return apply_filters( 'bbp_get_forum_subscribers', $users ); 545 } 546 547 /** 515 548 * Get the users who have subscribed to the topic 516 549 * 517 550 * @since bbPress (r2668) 518 551 * 519 552 * @param int $topic_id Optional. Topic id 553 * @global WPDB $wpdb 520 554 * @uses wpdb::get_col() To execute our query and get the column back 555 * @uses bbp_get_topic_id() To get the topic id 521 556 * @uses apply_filters() Calls 'bbp_get_topic_subscribers' with the subscribers 522 557 * @return array|bool Results if the topic has any subscribers, otherwise false 523 558 */ … … 547 582 * @uses bbp_get_user_subscribed_topic_ids() To get the user's subscriptions 548 583 * @uses bbp_has_topics() To get the topics 549 584 * @uses apply_filters() Calls 'bbp_get_user_subscriptions' with the topic query 550 * 585 * and user id 551 586 * @return array|bool Results if user has subscriptions, otherwise false 552 587 */ 553 588 function bbp_get_user_subscriptions( $user_id = 0 ) { … … 569 604 } 570 605 571 606 /** 607 * Get a user's subscribed forum ids 608 * 609 * @since bbPress (r5155) 610 * 611 * @param int $user_id Optional. User id 612 * @uses bbp_get_user_id() To get the user id 613 * @uses get_user_option() To get the user's subscriptions 614 * @uses apply_filters() Calls 'bbp_get_user_subscribed_forum_ids' with 615 * the subscriptions and user id 616 * @return array|bool Results if user has subscriptions, otherwise false 617 */ 618 function bbp_get_user_subscribed_forum_ids( $user_id = 0 ) { 619 $user_id = bbp_get_user_id( $user_id ); 620 if ( empty( $user_id ) ) 621 return false; 622 623 $subscriptions = get_user_option( '_bbp_forum_subscriptions', $user_id ); 624 $subscriptions = array_filter( wp_parse_id_list( $subscriptions ) ); 625 626 return (array) apply_filters( 'bbp_get_user_subscribed_forum_ids', $subscriptions, $user_id ); 627 } 628 629 /** 572 630 * Get a user's subscribed topics' ids 573 631 * 574 632 * @since bbPress (r2668) … … 577 635 * @uses bbp_get_user_id() To get the user id 578 636 * @uses get_user_option() To get the user's subscriptions 579 637 * @uses apply_filters() Calls 'bbp_get_user_subscribed_topic_ids' with 580 * 638 * the subscriptions and user id 581 639 * @return array|bool Results if user has subscriptions, otherwise false 582 640 */ 583 641 function bbp_get_user_subscribed_topic_ids( $user_id = 0 ) { … … 592 650 } 593 651 594 652 /** 653 * Check if in a user's subscription list or not 654 * 655 * @since bbPress (r2688) 656 * 657 * @param int $user_id Optional. User id 658 * @param int $object_id Optional. Forum or Topic id 659 * @uses get_post() To get the post object 660 * @uses bbp_get_forum_post_type() To get the forum post type 661 * @uses bbp_get_user_subscribed_forum_ids() To get the user's forum subscriptions 662 * @uses bbp_get_topic_post_type() To get the topic post type 663 * @uses bbp_get_user_subscribed_topic_ids() To get the user's topic subscriptions 664 * @uses apply_filters() Calls 'bbp_is_user_subscribed' with the bool, user id, 665 * forum/topic id and subsriptions 666 * @return bool True if the forum or topic is in user's subscriptions, otherwise false 667 */ 668 function bbp_is_user_subscribed( $user_id = 0, $object_id = 0 ) { 669 if ( empty( $user_id ) || empty( $object_id ) ) 670 return false; 671 672 $object = get_post( $object_id ); 673 if( ! $object ) 674 return false; 675 676 $post_type = $object->post_type; 677 678 switch( $post_type ) { 679 680 case bbp_get_forum_post_type() : 681 682 $subscriptions = bbp_get_user_subscribed_forum_ids( $user_id ); 683 $retval = bbp_is_user_subscribed_to_forum( $user_id, $object_id ); 684 break; 685 686 case bbp_get_topic_post_type() : 687 default : 688 689 $subscriptions = bbp_get_user_subscribed_topic_ids( $user_id ); 690 $retval = bbp_is_user_subscribed_to_topic( $user_id, $object_id ); 691 break; 692 } 693 694 return (bool) apply_filters( 'bbp_is_user_subscribed', $retval, $user_id, $object_id, $subscriptions ); 695 } 696 697 /** 698 * Check if a forum is in user's subscription list or not 699 * 700 * @since bbPress (r5155) 701 * 702 * @param int $user_id Optional. User id 703 * @param int $forum_id Optional. Forum id 704 * @uses bbp_get_user_id() To get the user id 705 * @uses bbp_get_user_subscribed_forum_ids() To get the user's subscriptions 706 * @uses bbp_get_forum() To get the forum 707 * @uses bbp_get_forum_id() To get the forum id 708 * @uses apply_filters() Calls 'bbp_is_user_subscribed_to_forum' with the bool, 709 * user id, forum id and subsriptions 710 * @return bool True if the forum is in user's subscriptions, otherwise false 711 */ 712 function bbp_is_user_subscribed_to_forum( $user_id = 0, $forum_id = 0 ) { 713 714 // Validate user 715 $user_id = bbp_get_user_id( $user_id, true, true ); 716 if ( empty( $user_id ) ) 717 return false; 718 719 $retval = false; 720 $subscriptions = bbp_get_user_subscribed_forum_ids( $user_id ); 721 722 if ( ! empty( $subscriptions ) ) { 723 724 // Checking a specific forum id 725 if ( ! empty( $forum_id ) ) { 726 $forum = bbp_get_forum( $forum_id ); 727 $forum_id = ! empty( $forum ) ? $forum->ID : 0; 728 729 // Using the global forum id 730 } elseif ( bbp_get_forum_id() ) { 731 $forum_id = bbp_get_forum_id(); 732 733 // Use the current post id 734 } elseif ( ! bbp_get_forum_id() ) { 735 $forum_id = get_the_ID(); 736 } 737 738 // Is forum_id in the user's favorites 739 if ( ! empty( $forum_id ) ) { 740 $retval = in_array( $forum_id, $subscriptions ); 741 } 742 } 743 744 return (bool) apply_filters( 'bbp_is_user_subscribed_to_forum', (bool) $retval, $user_id, $forum_id, $subscriptions ); 745 } 746 747 /** 595 748 * Check if a topic is in user's subscription list or not 596 749 * 597 750 * @since bbPress (r2668) … … 602 755 * @uses bbp_get_user_subscribed_topic_ids() To get the user's subscriptions 603 756 * @uses bbp_get_topic() To get the topic 604 757 * @uses bbp_get_topic_id() To get the topic id 605 * @uses apply_filters() Calls 'bbp_is_user_subscribed ' with the bool, user id,606 * 758 * @uses apply_filters() Calls 'bbp_is_user_subscribed_to_topic' with the bool, 759 * user id, topic id and subsriptions 607 760 * @return bool True if the topic is in user's subscriptions, otherwise false 608 761 */ 609 function bbp_is_user_subscribed ( $user_id = 0, $topic_id = 0 ) {762 function bbp_is_user_subscribed_to_topic( $user_id = 0, $topic_id = 0 ) { 610 763 611 764 // Validate user 612 765 $user_id = bbp_get_user_id( $user_id, true, true ); … … 616 769 $retval = false; 617 770 $subscriptions = bbp_get_user_subscribed_topic_ids( $user_id ); 618 771 619 if ( ! empty( $subscriptions ) ) {772 if ( ! empty( $subscriptions ) ) { 620 773 621 774 // Checking a specific topic id 622 if ( ! empty( $topic_id ) ) {623 $topic 624 $topic_id = ! empty( $topic ) ? $topic->ID : 0;775 if ( ! empty( $topic_id ) ) { 776 $topic = bbp_get_topic( $topic_id ); 777 $topic_id = ! empty( $topic ) ? $topic->ID : 0; 625 778 626 779 // Using the global topic id 627 780 } elseif ( bbp_get_topic_id() ) { … … 633 786 } 634 787 635 788 // Is topic_id in the user's favorites 636 if ( ! empty( $topic_id ) ) {789 if ( ! empty( $topic_id ) ) { 637 790 $retval = in_array( $topic_id, $subscriptions ); 638 791 } 639 792 } 640 793 641 return (bool) apply_filters( 'bbp_is_user_subscribed ', (bool) $retval, $user_id, $topic_id, $subscriptions );794 return (bool) apply_filters( 'bbp_is_user_subscribed_to_topic', (bool) $retval, $user_id, $topic_id, $subscriptions ); 642 795 } 643 796 644 797 /** 798 * Add to user's subscriptions 799 * 800 * @since bbPress (r2668) 801 * 802 * @param int $user_id Optional. User id 803 * @param int $object_id Optional. Forum or Topic id 804 * @uses get_post() To get the post object 805 * @uses bbp_get_forum_post_type() To get the forum post type 806 * @uses bbp_get_user_subscribed_forum_ids() To get the user's forum subscriptions 807 * @uses bbp_get_topic_post_type() To get the topic post type 808 * @uses bbp_get_user_subscribed_topic_ids() To get the user's topic subscriptions 809 * @uses update_user_option() To update the user's subscriptions 810 * @uses do_action() Calls 'bbp_add_user_subscription' with the user, 811 * Forum/Topic id and post type 812 * @return bool Always true 813 */ 814 function bbp_add_user_subscription( $user_id = 0, $object_id = 0 ) { 815 if ( empty( $user_id ) || empty( $object_id ) ) 816 return false; 817 818 $object = get_post( $object_id ); 819 if( ! $object ) 820 return false; 821 822 $post_type = $object->post_type; 823 824 switch( $post_type ) { 825 826 case bbp_get_forum_post_type() : 827 828 $subscriptions = bbp_get_user_subscribed_forum_ids( $user_id ); 829 830 if ( ! in_array( $object_id, $subscriptions ) ) { 831 $subscriptions[] = $object_id; 832 $subscriptions = implode( ',', wp_parse_id_list( array_filter( $subscriptions ) ) ); 833 update_user_option( $user_id, '_bbp_forum_subscriptions', $subscriptions ); 834 835 wp_cache_delete( 'bbp_get_forum_subscribers_' . $object_id, 'bbpress_users' ); 836 } 837 838 break; 839 840 case bbp_get_topic_post_type() : 841 default : 842 843 $subscriptions = bbp_get_user_subscribed_topic_ids( $user_id ); 844 845 if ( ! in_array( $object_id, $subscriptions ) ) { 846 $subscriptions[] = $object_id; 847 $subscriptions = implode( ',', wp_parse_id_list( array_filter( $subscriptions ) ) ); 848 update_user_option( $user_id, '_bbp_subscriptions', $subscriptions ); 849 850 wp_cache_delete( 'bbp_get_topic_subscribers_' . $object_id, 'bbpress_users' ); 851 } 852 853 break; 854 } 855 856 do_action( 'bbp_add_user_subscription', $user_id, $object_id, $post_type ); 857 858 return true; 859 } 860 861 /** 862 * Add a forum to user's subscriptions 863 * 864 * @since bbPress (r5155) 865 * 866 * @param int $user_id Optional. User id 867 * @param int $forum_id Optional. forum id 868 * @uses bbp_get_forum() To get the forum 869 * @uses bbp_get_user_subscribed_forum_ids() To get the user's subscriptions 870 * @uses update_user_option() To update the user's subscriptions 871 * @uses do_action() Calls 'bbp_add_user_forum_subscription' with the user & forum id 872 * @return bool Always true 873 */ 874 function bbp_add_user_forum_subscription( $user_id = 0, $forum_id = 0 ) { 875 if ( empty( $user_id ) || empty( $forum_id ) ) 876 return false; 877 878 $forum = bbp_get_forum( $forum_id ); 879 if ( empty( $forum ) ) 880 return false; 881 882 $subscriptions = (array) bbp_get_user_subscribed_forum_ids( $user_id ); 883 if ( !in_array( $forum_id, $subscriptions ) ) { 884 $subscriptions[] = $forum_id; 885 $subscriptions = implode( ',', wp_parse_id_list( array_filter( $subscriptions ) ) ); 886 update_user_option( $user_id, '_bbp_forum_subscriptions', $subscriptions ); 887 888 wp_cache_delete( 'bbp_get_forum_subscribers_' . $forum_id, 'bbpress_users' ); 889 } 890 891 do_action( 'bbp_add_user_forum_subscription', $user_id, $forum_id ); 892 893 return true; 894 } 895 896 /** 645 897 * Add a topic to user's subscriptions 646 898 * 647 899 * @since bbPress (r2668) … … 648 900 * 649 901 * @param int $user_id Optional. User id 650 902 * @param int $topic_id Optional. Topic id 903 * @uses bbp_get_topic() To get the topic 651 904 * @uses bbp_get_user_subscribed_topic_ids() To get the user's subscriptions 652 * @uses bbp_get_topic() To get the topic653 905 * @uses update_user_option() To update the user's subscriptions 654 * @uses do_action() Calls 'bbp_add_user_ subscription' with the user & topic id906 * @uses do_action() Calls 'bbp_add_user_topic_subscription' with the user & topic id 655 907 * @return bool Always true 656 908 */ 657 function bbp_add_user_ subscription( $user_id = 0, $topic_id = 0 ) {909 function bbp_add_user_topic_subscription( $user_id = 0, $topic_id = 0 ) { 658 910 if ( empty( $user_id ) || empty( $topic_id ) ) 659 911 return false; 660 912 … … 671 923 wp_cache_delete( 'bbp_get_topic_subscribers_' . $topic_id, 'bbpress_users' ); 672 924 } 673 925 674 do_action( 'bbp_add_user_ subscription', $user_id, $topic_id );926 do_action( 'bbp_add_user_topic_subscription', $user_id, $topic_id ); 675 927 676 928 return true; 677 929 } 678 930 679 931 /** 932 * Remove from user's subscriptions 933 * 934 * @since bbPress (r2668) 935 * 936 * @param int $user_id Optional. User id 937 * @param int $object_id Optional. Forum or Topic id 938 * @uses get_post_type() To get the post type 939 * @uses bbp_get_forum_post_type() To get the forum post type 940 * @uses bbp_get_topic_post_type() To get the topic post type 941 * @uses bbp_remove_user_forum_subscription() To remove the user's subscription 942 * @uses bbp_remove_user_topic_subscription() To remove the user's subscription 943 * @uses do_action() Calls 'bbp_remove_user_subscription' with the user id and 944 * forum/topic id 945 * @return bool True if the topic was removed from user's subscriptions, 946 * otherwise false 947 */ 948 function bbp_remove_user_subscription( $user_id = 0, $object_id = 0 ) { 949 if ( empty( $user_id ) || empty( $object_id ) ) 950 return false; 951 952 $post_type = get_post_type( $object_id ); 953 954 switch( $post_type ) { 955 956 case bbp_get_forum_post_type() : 957 958 bbp_remove_user_forum_subscription( $user_id, $object_id ); 959 960 break; 961 962 case bbp_get_topic_post_type() : 963 default : 964 965 bbp_remove_user_topic_subscription( $user_id, $object_id ); 966 967 break; 968 } 969 970 do_action( 'bbp_remove_user_subscription', $user_id, $object_id, $post_type ); 971 972 return true; 973 } 974 975 /** 976 * Remove a forum from user's subscriptions 977 * 978 * @since bbPress (r5155) 979 * 980 * @param int $user_id Optional. User id 981 * @param int $forum_id Optional. forum id 982 * @uses bbp_get_user_subscribed_forum_ids() To get the user's subscriptions 983 * @uses update_user_option() To update the user's subscriptions 984 * @uses delete_user_option() To delete the user's subscriptions meta 985 * @uses do_action() Calls 'bbp_remove_user_forum_subscription' with the user id and 986 * forum id 987 * @return bool True if the forum was removed from user's subscriptions, 988 * otherwise false 989 */ 990 function bbp_remove_user_forum_subscription( $user_id, $forum_id ) { 991 if ( empty( $user_id ) || empty( $forum_id ) ) 992 return false; 993 994 $subscriptions = (array) bbp_get_user_subscribed_forum_ids( $user_id ); 995 996 if ( empty( $subscriptions ) ) 997 return false; 998 999 $pos = array_search( $forum_id, $subscriptions ); 1000 if ( is_numeric( $pos ) ) { 1001 array_splice( $subscriptions, $pos, 1 ); 1002 $subscriptions = array_filter( $subscriptions ); 1003 1004 if ( !empty( $subscriptions ) ) { 1005 $subscriptions = implode( ',', wp_parse_id_list( $subscriptions ) ); 1006 update_user_option( $user_id, '_bbp_forum_subscriptions', $subscriptions ); 1007 } else { 1008 delete_user_option( $user_id, '_bbp_forum_subscriptions' ); 1009 } 1010 1011 wp_cache_delete( 'bbp_get_forum_subscribers_' . $forum_id, 'bbpress_users' ); 1012 } 1013 1014 do_action( 'bbp_remove_user_forum_subscription', $user_id, $forum_id ); 1015 1016 return true; 1017 } 1018 1019 /** 680 1020 * Remove a topic from user's subscriptions 681 1021 * 682 1022 * @since bbPress (r2668) … … 686 1026 * @uses bbp_get_user_subscribed_topic_ids() To get the user's subscriptions 687 1027 * @uses update_user_option() To update the user's subscriptions 688 1028 * @uses delete_user_option() To delete the user's subscriptions meta 689 * @uses do_action() Calls 'bbp_remove_user_ subscription' with the user id and1029 * @uses do_action() Calls 'bbp_remove_user_topic_subscription' with the user id and 690 1030 * topic id 691 1031 * @return bool True if the topic was removed from user's subscriptions, 692 1032 * otherwise false 693 1033 */ 694 function bbp_remove_user_ subscription( $user_id, $topic_id ) {1034 function bbp_remove_user_topic_subscription( $user_id, $topic_id ) { 695 1035 if ( empty( $user_id ) || empty( $topic_id ) ) 696 1036 return false; 697 1037 … … 715 1055 wp_cache_delete( 'bbp_get_topic_subscribers_' . $topic_id, 'bbpress_users' ); 716 1056 } 717 1057 718 do_action( 'bbp_remove_user_ subscription', $user_id, $topic_id );1058 do_action( 'bbp_remove_user_topic_subscription', $user_id, $topic_id ); 719 1059 720 1060 return true; 721 1061 } 722 1062 723 1063 /** 1064 * Handles the front end subscribing and unsubscribing forums 1065 * 1066 * @since bbPress (r5155) 1067 * 1068 * @param string $action The requested action to compare this function to 1069 * @uses bbp_is_subscriptions_active() To check if the subscriptions are active 1070 * @uses bbp_get_user_id() To get the user id 1071 * @uses bbp_verify_nonce_request() To verify the nonce and check the request 1072 * @uses current_user_can() To check if the current user can edit the user 1073 * @uses bbPress:errors:add() To log the error messages 1074 * @uses bbp_is_user_subscribed() To check if the forum is in user's 1075 * subscriptions 1076 * @uses bbp_remove_user_subscription() To remove the user subscription 1077 * @uses bbp_add_user_subscription() To add the user subscription 1078 * @uses do_action() Calls 'bbp_subscriptions_handler' with success, user id, 1079 * forum id and action 1080 * @uses bbp_is_subscription() To check if it's the subscription page 1081 * @uses bbp_get_subscription_permalink() To get the subscription page link 1082 * @uses bbp_get_user_profile_url() To get the user profile link 1083 * @uses bbp_get_forum_permalink() To get the forum permalink 1084 * @uses wp_safe_redirect() To redirect to the url 1085 */ 1086 function bbp_forum_subscriptions_handler( $action = '' ) { 1087 1088 if ( !bbp_is_subscriptions_active() ) 1089 return false; 1090 1091 // Bail if no forum ID is passed 1092 if ( empty( $_GET['forum_id'] ) ) 1093 return; 1094 1095 // Setup possible get actions 1096 $possible_actions = array( 1097 'bbp_subscribe', 1098 'bbp_unsubscribe', 1099 ); 1100 1101 // Bail if actions aren't meant for this function 1102 if ( !in_array( $action, $possible_actions ) ) 1103 return; 1104 1105 // Get required data 1106 $user_id = bbp_get_user_id( 0, true, true ); 1107 $forum_id = intval( $_GET['forum_id'] ); 1108 1109 // Check for empty forum 1110 if ( empty( $forum_id ) ) { 1111 bbp_add_error( 'bbp_subscription_forum_id', __( '<strong>ERROR</strong>: No forum was found! Which forum are you subscribing/unsubscribing to?', 'bbpress' ) ); 1112 1113 // Check nonce 1114 } elseif ( ! bbp_verify_nonce_request( 'toggle-subscription_' . $forum_id ) ) { 1115 bbp_add_error( 'bbp_subscription_forum_id', __( '<strong>ERROR</strong>: Are you sure you wanted to do that?', 'bbpress' ) ); 1116 1117 // Check current user's ability to edit the user 1118 } elseif ( !current_user_can( 'edit_user', $user_id ) ) { 1119 bbp_add_error( 'bbp_subscription_permissions', __( '<strong>ERROR</strong>: You don\'t have the permission to edit favorites of that user!', 'bbpress' ) ); 1120 } 1121 1122 // Bail if we have errors 1123 if ( bbp_has_errors() ) 1124 return; 1125 1126 /** No errors *************************************************************/ 1127 1128 $is_subscription = bbp_is_user_subscribed( $user_id, $forum_id ); 1129 $success = false; 1130 1131 if ( true === $is_subscription && 'bbp_unsubscribe' === $action ) 1132 $success = bbp_remove_user_subscription( $user_id, $forum_id ); 1133 elseif ( false === $is_subscription && 'bbp_subscribe' === $action ) 1134 $success = bbp_add_user_subscription( $user_id, $forum_id ); 1135 1136 // Do additional subscriptions actions 1137 do_action( 'bbp_subscriptions_handler', $success, $user_id, $forum_id, $action ); 1138 1139 // Success! 1140 if ( true === $success ) { 1141 1142 // Redirect back from whence we came 1143 if ( bbp_is_subscriptions() ) { 1144 $redirect = bbp_get_subscriptions_permalink( $user_id ); 1145 } elseif ( bbp_is_single_user() ) { 1146 $redirect = bbp_get_user_profile_url(); 1147 } elseif ( is_singular( bbp_get_forum_post_type() ) ) { 1148 $redirect = bbp_get_forum_permalink( $forum_id ); 1149 } elseif ( is_single() || is_page() ) { 1150 $redirect = get_permalink(); 1151 } else { 1152 $redirect = get_permalink( $forum_id ); 1153 } 1154 1155 wp_safe_redirect( $redirect ); 1156 1157 // For good measure 1158 exit(); 1159 1160 // Fail! Handle errors 1161 } elseif ( true === $is_subscription && 'bbp_unsubscribe' === $action ) { 1162 bbp_add_error( 'bbp_unsubscribe', __( '<strong>ERROR</strong>: There was a problem unsubscribing from that forum!', 'bbpress' ) ); 1163 } elseif ( false === $is_subscription && 'bbp_subscribe' === $action ) { 1164 bbp_add_error( 'bbp_subscribe', __( '<strong>ERROR</strong>: There was a problem subscribing to that forum!', 'bbpress' ) ); 1165 } 1166 } 1167 1168 /** 724 1169 * Handles the front end subscribing and unsubscribing topics 725 1170 * 1171 * @since bbPress (rXXXX) 1172 * 726 1173 * @param string $action The requested action to compare this function to 727 1174 * @uses bbp_is_subscriptions_active() To check if the subscriptions are active 728 1175 * @uses bbp_get_user_id() To get the user id … … 730 1177 * @uses current_user_can() To check if the current user can edit the user 731 1178 * @uses bbPress:errors:add() To log the error messages 732 1179 * @uses bbp_is_user_subscribed() To check if the topic is in user's 733 * 1180 * subscriptions 734 1181 * @uses bbp_remove_user_subscription() To remove the user subscription 735 1182 * @uses bbp_add_user_subscription() To add the user subscription 736 1183 * @uses do_action() Calls 'bbp_subscriptions_handler' with success, user id, 737 1184 * topic id and action 738 1185 * @uses bbp_is_subscription() To check if it's the subscription page 739 * @uses bbp_get_subscription_link() To get the subscription page link 1186 * @uses bbp_get_subscription_permalink() To get the subscription page link 1187 * @uses bbp_get_user_profile_url() To get the user profile link 740 1188 * @uses bbp_get_topic_permalink() To get the topic permalink 741 1189 * @uses wp_safe_redirect() To redirect to the url 742 1190 */ … … 827 1275 /** 828 1276 * Handles the front end user editing 829 1277 * 1278 * @since bbPress (rXXXX) 1279 * 830 1280 * @param string $action The requested action to compare this function to 831 1281 * @uses is_multisite() To check if it's a multisite 832 1282 * @uses bbp_is_user_home() To check if the user is at home (the display page 833 * 1283 * is the one of the logged in user) 834 1284 * @uses get_option() To get the displayed user's new email id option 835 1285 * @uses wpdb::prepare() To sanitize our sql query 836 1286 * @uses wpdb::get_var() To execute our query and get back the variable … … 968 1418 * @return array|bool Results if the user has created topics, otherwise false 969 1419 */ 970 1420 function bbp_get_user_topics_started( $user_id = 0 ) { 971 1421 972 1422 // Validate user 973 1423 $user_id = bbp_get_user_id( $user_id ); 974 1424 if ( empty( $user_id ) ) … … 993 1443 * @return array|bool Results if the user has created topics, otherwise false 994 1444 */ 995 1445 function bbp_get_user_replies_created( $user_id = 0 ) { 996 1446 997 1447 // Validate user 998 1448 $user_id = bbp_get_user_id( $user_id ); 999 1449 if ( empty( $user_id ) ) … … 1013 1463 * Get the total number of users on the forums 1014 1464 * 1015 1465 * @since bbPress (r2769) 1466 * 1016 1467 * @uses count_users() To execute our query and get the var back 1017 1468 * @uses apply_filters() Calls 'bbp_get_total_users' with number of users 1018 1469 * @return int Total number of users … … 1031 1482 * which a user can edit another user (or themselves.) If these conditions are 1032 1483 * met. We assume a user cannot perform this task, and look for ways they can 1033 1484 * earn the ability to access this template. 1034 * 1485 * 1035 1486 * @since bbPress (r3605) 1036 1487 * 1037 1488 * @uses bbp_is_topic_edit() … … 1099 1550 * Convert passwords from previous platfrom encryption to WordPress encryption. 1100 1551 * 1101 1552 * @since bbPress (r3813) 1553 * 1102 1554 * @global WPDB $wpdb 1103 1555 */ 1104 1556 function bbp_user_maybe_convert_pass() { -
includes/users/template.php
612 612 } 613 613 614 614 /** Anonymous Fields **********************************************************/ 615 615 616 616 /** 617 617 * Output the author disylay-name of a topic or reply. 618 618 * … … 1027 1027 * - unsubscribe: Unsubscribe text 1028 1028 * - user_id: User id 1029 1029 * - topic_id: Topic id 1030 * - forum_id: Forum id 1030 1031 * - before: Before the link 1031 1032 * - after: After the link 1032 1033 * @param int $user_id Optional. User id 1033 1034 * @param bool $wrap Optional. If you want to wrap the link in <span id="subscription-toggle">. 1035 * @uses bbp_is_subscriptions_active() to check if subscriptions are active 1034 1036 * @uses bbp_get_user_id() To get the user id 1037 * @uses bbp_get_user_id() To get the user id 1038 * @uses bbp_get_topic_id() To get the topic id 1039 * @uses bbp_get_forum_id() To get the forum id 1035 1040 * @uses current_user_can() To check if the current user can edit user 1036 * @uses bbp_ get_topic_id() To get the topic id1037 * @uses bbp_is_user_subscribed () To check if the user is subscribed1041 * @uses bbp_is_user_subscribed_to_forum() To check if the user is subscribed to the forum 1042 * @uses bbp_is_user_subscribed_to_topic() To check if the user is subscribed to the topic 1038 1043 * @uses bbp_is_subscriptions() To check if it's the subscriptions page 1039 1044 * @uses bbp_get_subscriptions_permalink() To get subscriptions link 1040 1045 * @uses bbp_get_topic_permalink() To get topic link … … 1043 1048 * @return string Permanent link to topic 1044 1049 */ 1045 1050 function bbp_get_user_subscribe_link( $args = '', $user_id = 0, $wrap = true ) { 1046 if ( ! bbp_is_subscriptions_active() )1051 if ( ! bbp_is_subscriptions_active() ) 1047 1052 return; 1048 1053 1049 1054 // Parse arguments against default values … … 1052 1057 'unsubscribe' => __( 'Unsubscribe', 'bbpress' ), 1053 1058 'user_id' => 0, 1054 1059 'topic_id' => 0, 1060 'forum_id' => 0, 1055 1061 'before' => ' | ', 1056 1062 'after' => '' 1057 1063 ), 'get_user_subscribe_link' ); 1058 1064 1059 // Validate user and topic ID's 1060 $user_id = bbp_get_user_id( $r['user_id'], true, true ); 1061 $topic_id = bbp_get_topic_id( $r['topic_id'] ); 1062 if ( empty( $user_id ) || empty( $topic_id ) ) { 1065 // Validate user and object ID's 1066 $user_id = bbp_get_user_id( $r['user_id'], true, true ); 1067 $topic_id = bbp_get_topic_id( $r['topic_id'] ); 1068 $forum_id = bbp_get_forum_id( $r['forum_id'] ); 1069 if ( empty( $user_id ) || ( empty( $topic_id ) && empty( $forum_id ) ) ) { 1063 1070 return false; 1064 1071 } 1065 1072 1066 1073 // No link if you can't edit yourself 1067 if ( ! current_user_can( 'edit_user', (int) $user_id ) ) {1074 if ( ! current_user_can( 'edit_user', (int) $user_id ) ) { 1068 1075 return false; 1069 1076 } 1070 1077 1071 // Decide which link to show 1072 $is_subscribed = bbp_is_user_subscribed( $user_id, $topic_id ); 1073 if ( !empty( $is_subscribed ) ) { 1074 $text = $r['unsubscribe']; 1075 $query_args = array( 'action' => 'bbp_unsubscribe', 'topic_id' => $topic_id ); 1076 } else { 1077 $text = $r['subscribe']; 1078 $query_args = array( 'action' => 'bbp_subscribe', 'topic_id' => $topic_id ); 1079 } 1078 // Check if viewing a single forum 1079 if( empty( $topic_id ) && ! empty( $forum_id ) ) { 1080 1080 1081 // Create the link based where the user is and if the user is 1082 // subscribed already 1083 if ( bbp_is_subscriptions() ) { 1084 $permalink = bbp_get_subscriptions_permalink( $user_id ); 1085 } elseif ( bbp_is_single_topic() || bbp_is_single_reply() ) { 1086 $permalink = bbp_get_topic_permalink( $topic_id ); 1081 // Decide which link to show 1082 $is_subscribed = bbp_is_user_subscribed_to_forum( $user_id, $forum_id ); 1083 if ( ! empty( $is_subscribed ) ) { 1084 $text = $r['unsubscribe']; 1085 $query_args = array( 'action' => 'bbp_unsubscribe', 'forum_id' => $forum_id ); 1086 } else { 1087 $text = $r['subscribe']; 1088 $query_args = array( 'action' => 'bbp_subscribe', 'forum_id' => $forum_id ); 1089 } 1090 1091 // Create the link based where the user is and if the user is 1092 // subscribed already 1093 if ( bbp_is_subscriptions() ) { 1094 $permalink = bbp_get_subscriptions_permalink( $user_id ); 1095 } elseif ( bbp_is_single_forum() || bbp_is_single_reply() ) { 1096 $permalink = bbp_get_forum_permalink( $forum_id ); 1097 } else { 1098 $permalink = get_permalink(); 1099 } 1100 1101 $url = esc_url( wp_nonce_url( add_query_arg( $query_args, $permalink ), 'toggle-subscription_' . $forum_id ) ); 1102 $sub = $is_subscribed ? ' class="is-subscribed"' : ''; 1103 $html = sprintf( '%s<span id="subscribe-%d" %s><a href="%s" class="subscription-toggle" data-forum="%d">%s</a></span>%s', $r['before'], $forum_id, $sub, $url, $forum_id, $text, $r['after'] ); 1104 1105 // Initial output is wrapped in a span, ajax output is hooked to this 1106 if ( !empty( $wrap ) ) { 1107 $html = '<span id="subscription-toggle">' . $html . '</span>'; 1108 } 1109 1087 1110 } else { 1088 $permalink = get_permalink();1089 }1090 1111 1091 $url = esc_url( wp_nonce_url( add_query_arg( $query_args, $permalink ), 'toggle-subscription_' . $topic_id ) ); 1092 $sub = $is_subscribed ? ' class="is-subscribed"' : ''; 1093 $html = sprintf( '%s<span id="subscribe-%d" %s><a href="%s" class="subscription-toggle" data-topic="%d">%s</a></span>%s', $r['before'], $topic_id, $sub, $url, $topic_id, $text, $r['after'] ); 1112 // Decide which link to show 1113 $is_subscribed = bbp_is_user_subscribed_to_topic( $user_id, $topic_id ); 1114 if ( ! empty( $is_subscribed ) ) { 1115 $text = $r['unsubscribe']; 1116 $query_args = array( 'action' => 'bbp_unsubscribe', 'topic_id' => $topic_id ); 1117 } else { 1118 $text = $r['subscribe']; 1119 $query_args = array( 'action' => 'bbp_subscribe', 'topic_id' => $topic_id ); 1120 } 1094 1121 1095 // Initial output is wrapped in a span, ajax output is hooked to this 1096 if ( !empty( $wrap ) ) { 1097 $html = '<span id="subscription-toggle">' . $html . '</span>'; 1122 // Create the link based where the user is and if the user is 1123 // subscribed already 1124 if ( bbp_is_subscriptions() ) { 1125 $permalink = bbp_get_subscriptions_permalink( $user_id ); 1126 } elseif ( bbp_is_single_topic() || bbp_is_single_reply() ) { 1127 $permalink = bbp_get_topic_permalink( $topic_id ); 1128 } else { 1129 $permalink = get_permalink(); 1130 } 1131 1132 $url = esc_url( wp_nonce_url( add_query_arg( $query_args, $permalink ), 'toggle-subscription_' . $topic_id ) ); 1133 $sub = $is_subscribed ? ' class="is-subscribed"' : ''; 1134 $html = sprintf( '%s<span id="subscribe-%d" %s><a href="%s" class="subscription-toggle" data-topic="%d">%s</a></span>%s', $r['before'], $topic_id, $sub, $url, $topic_id, $text, $r['after'] ); 1135 1136 // Initial output is wrapped in a span, ajax output is hooked to this 1137 if ( !empty( $wrap ) ) { 1138 $html = '<span id="subscription-toggle">' . $html . '</span>'; 1139 } 1140 1098 1141 } 1099 1142 1100 1143 // Return the link -
templates/default/bbpress-functions.php
84 84 85 85 /** Scripts ***********************************************************/ 86 86 87 add_action( 'bbp_enqueue_scripts', array( $this, 'enqueue_styles' ) ); // Enqueue theme CSS 88 add_action( 'bbp_enqueue_scripts', array( $this, 'enqueue_scripts' ) ); // Enqueue theme JS 89 add_filter( 'bbp_enqueue_scripts', array( $this, 'localize_topic_script' ) ); // Enqueue theme script localization 90 add_action( 'bbp_head', array( $this, 'head_scripts' ) ); // Output some extra JS in the <head> 91 add_action( 'bbp_ajax_favorite', array( $this, 'ajax_favorite' ) ); // Handles the ajax favorite/unfavorite 92 add_action( 'bbp_ajax_subscription', array( $this, 'ajax_subscription' ) ); // Handles the ajax subscribe/unsubscribe 87 add_action( 'bbp_enqueue_scripts', array( $this, 'enqueue_styles' ) ); // Enqueue theme CSS 88 add_action( 'bbp_enqueue_scripts', array( $this, 'enqueue_scripts' ) ); // Enqueue theme JS 89 add_filter( 'bbp_enqueue_scripts', array( $this, 'localize_topic_script' ) ); // Enqueue theme script localization 90 add_action( 'bbp_head', array( $this, 'head_scripts' ) ); // Output some extra JS in the <head> 91 add_action( 'bbp_ajax_favorite', array( $this, 'ajax_favorite' ) ); // Handles the topic ajax favorite/unfavorite 92 add_action( 'bbp_ajax_subscription', array( $this, 'ajax_subscription' ) ); // Handles the topic ajax subscribe/unsubscribe 93 add_action( 'bbp_ajax_forum_subscription', array( $this, 'ajax_forum_subscription' ) ); // Handles the forum ajax subscribe/unsubscribe 93 94 94 95 /** Template Wrappers *************************************************/ 95 96 … … 168 169 * 169 170 * @since bbPress (r3732) 170 171 * 172 * @uses bbp_is_single_forum() To check if it's the forum page 171 173 * @uses bbp_is_single_topic() To check if it's the topic page 174 * @uses bbp_thread_replies() To check if threaded replies are enabled 172 175 * @uses bbp_is_single_user_edit() To check if it's the profile edit page 173 176 * @uses wp_enqueue_script() To enqueue the scripts 174 177 */ … … 179 182 wp_enqueue_script( 'jquery' ); 180 183 } 181 184 185 // Forum-specific scripts 186 if ( bbp_is_single_forum() ) { 187 188 // Forum subscribe/unsubscribe 189 wp_enqueue_script( 'bbpress-forum', $this->url . 'js/forum.js', array( 'jquery' ), $this->version ); 190 } 191 182 192 // Topic-specific scripts 183 193 if ( bbp_is_single_topic() ) { 184 194 … … 285 295 * 286 296 * @since bbPress (r3732) 287 297 * 298 * @uses bbp_is_single_forum() To check if it's the forum page 288 299 * @uses bbp_is_single_topic() To check if it's the topic page 289 300 * @uses is_user_logged_in() To check if user is logged in 290 301 * @uses bbp_get_current_user_id() To get the current user id 302 * @uses bbp_get_forum_id() To get the forum id 291 303 * @uses bbp_get_topic_id() To get the topic id 292 304 * @uses bbp_get_favorites_permalink() To get the favorites permalink 293 305 * @uses bbp_is_user_favorite() To check if the topic is in user's favorites … … 298 310 */ 299 311 public function localize_topic_script() { 300 312 301 // Bail if not viewing a single topic 302 if ( !bbp_is_single_topic() ) 303 return; 313 if( bbp_is_single_forum() ) { 304 314 305 wp_localize_script( 'bbpress-topic', 'bbpTopicJS', array( 306 'bbp_ajaxurl' => bbp_get_ajax_url(), 307 'generic_ajax_error' => __( 'Something went wrong. Refresh your browser and try again.', 'bbpress' ), 308 'is_user_logged_in' => is_user_logged_in(), 309 'fav_nonce' => wp_create_nonce( 'toggle-favorite_' . get_the_ID() ), 310 'subs_nonce' => wp_create_nonce( 'toggle-subscription_' . get_the_ID() ) 311 ) ); 315 wp_localize_script( 'bbpress-forum', 'bbpForumJS', array( 316 'bbp_ajaxurl' => bbp_get_ajax_url(), 317 'generic_ajax_error' => __( 'Something went wrong. Refresh your browser and try again.', 'bbpress' ), 318 'is_user_logged_in' => is_user_logged_in(), 319 'subs_nonce' => wp_create_nonce( 'toggle-subscription_' . get_the_ID() ) 320 ) ); 321 } 322 323 if ( bbp_is_single_topic() ) { 324 325 wp_localize_script( 'bbpress-topic', 'bbpTopicJS', array( 326 'bbp_ajaxurl' => bbp_get_ajax_url(), 327 'generic_ajax_error' => __( 'Something went wrong. Refresh your browser and try again.', 'bbpress' ), 328 'is_user_logged_in' => is_user_logged_in(), 329 'fav_nonce' => wp_create_nonce( 'toggle-favorite_' . get_the_ID() ), 330 'subs_nonce' => wp_create_nonce( 'toggle-subscription_' . get_the_ID() ) 331 ) ); 332 } 312 333 } 313 334 314 335 /** 336 * AJAX handler to Subscribe/Unsubscribe a user from a forum 337 * 338 * @since bbPress (r5155) 339 * 340 * @uses bbp_is_subscriptions_active() To check if the subscriptions are active 341 * @uses bbp_is_user_logged_in() To check if user is logged in 342 * @uses bbp_get_current_user_id() To get the current user id 343 * @uses current_user_can() To check if the current user can edit the user 344 * @uses bbp_get_forum() To get the forum 345 * @uses wp_verify_nonce() To verify the nonce 346 * @uses bbp_is_user_subscribed() To check if the forum is in user's subscriptions 347 * @uses bbp_remove_user_subscriptions() To remove the forum from user's subscriptions 348 * @uses bbp_add_user_subscriptions() To add the forum from user's subscriptions 349 * @uses bbp_ajax_response() To return JSON 350 */ 351 public function ajax_forum_subscription() { 352 353 // Bail if subscriptions are not active 354 if ( !bbp_is_subscriptions_active() ) { 355 bbp_ajax_response( false, __( 'Subscriptions are no longer active.', 'bbpress' ), 300 ); 356 } 357 358 // Bail if user is not logged in 359 if ( !is_user_logged_in() ) { 360 bbp_ajax_response( false, __( 'Please login to subscribe to this forum.', 'bbpress' ), 301 ); 361 } 362 363 // Get user and forum data 364 $user_id = bbp_get_current_user_id(); 365 $id = intval( $_POST['id'] ); 366 367 // Bail if user cannot add favorites for this user 368 if ( !current_user_can( 'edit_user', $user_id ) ) { 369 bbp_ajax_response( false, __( 'You do not have permission to do this.', 'bbpress' ), 302 ); 370 } 371 372 // Get the forum 373 $forum = bbp_get_forum( $id ); 374 375 // Bail if forum cannot be found 376 if ( empty( $forum ) ) { 377 bbp_ajax_response( false, __( 'The forum could not be found.', 'bbpress' ), 303 ); 378 } 379 380 // Bail if user did not take this action 381 if ( !isset( $_POST['nonce'] ) || !wp_verify_nonce( $_POST['nonce'], 'toggle-subscription_' . $forum->ID ) ) { 382 bbp_ajax_response( false, __( 'Are you sure you meant to do that?', 'bbpress' ), 304 ); 383 } 384 385 // Take action 386 $status = bbp_is_user_subscribed( $user_id, $forum->ID ) ? bbp_remove_user_subscription( $user_id, $forum->ID ) : bbp_add_user_subscription( $user_id, $forum->ID ); 387 388 // Bail if action failed 389 if ( empty( $status ) ) { 390 bbp_ajax_response( false, __( 'The request was unsuccessful. Please try again.', 'bbpress' ), 305 ); 391 } 392 393 // Put subscription attributes in convenient array 394 $attrs = array( 395 'forum_id' => $forum->ID, 396 'user_id' => $user_id 397 ); 398 399 // Action succeeded 400 bbp_ajax_response( true, bbp_get_forum_subscription_link( $attrs, $user_id, false ), 200 ); 401 } 402 403 /** 315 404 * AJAX handler to add or remove a topic from a user's favorites 316 405 * 317 406 * @since bbPress (r3732) 318 407 * 408 * @uses bbp_is_favorites_active() To check if favorites are active 409 * @uses bbp_is_user_logged_in() To check if user is logged in 319 410 * @uses bbp_get_current_user_id() To get the current user id 320 411 * @uses current_user_can() To check if the current user can edit the user 321 412 * @uses bbp_get_topic() To get the topic … … 383 474 * @since bbPress (r3732) 384 475 * 385 476 * @uses bbp_is_subscriptions_active() To check if the subscriptions are active 477 * @uses bbp_is_user_logged_in() To check if user is logged in 386 478 * @uses bbp_get_current_user_id() To get the current user id 387 479 * @uses current_user_can() To check if the current user can edit the user 388 480 * @uses bbp_get_topic() To get the topic -
templates/default/bbpress/content-archive-forum.php
23 23 24 24 <?php bbp_breadcrumb(); ?> 25 25 26 <?php bbp_forum_subscription_link(); ?> 27 26 28 <?php do_action( 'bbp_template_before_forums_index' ); ?> 27 29 28 30 <?php if ( bbp_has_forums() ) : ?> -
templates/default/bbpress/content-single-forum.php
13 13 14 14 <?php bbp_breadcrumb(); ?> 15 15 16 <?php bbp_forum_subscription_link(); ?> 17 16 18 <?php do_action( 'bbp_template_before_single_forum' ); ?> 17 19 18 20 <?php if ( post_password_required() ) : ?> -
templates/default/css/bbpress-rtl.css
173 173 margin: 8px 0; 174 174 padding: 0; 175 175 text-transform: none; 176 } 176 } 177 177 178 #bbpress-forums div.bbp-forum-author, 178 #bbpress-forums div.bbp-forum-author, 179 179 #bbpress-forums div.bbp-topic-author, 180 180 #bbpress-forums div.bbp-reply-author { 181 181 float: right; … … 183 183 width: 115px; 184 184 } 185 185 186 #bbpress-forums div.bbp-forum-author img.avatar, 186 #bbpress-forums div.bbp-forum-author img.avatar, 187 187 #bbpress-forums div.bbp-topic-author img.avatar, 188 188 #bbpress-forums div.bbp-reply-author img.avatar { 189 189 border: none; … … 250 250 padding: 8px; 251 251 } 252 252 253 div.bbp-forum-header, 253 div.bbp-forum-header, 254 254 div.bbp-topic-header, 255 255 div.bbp-reply-header { 256 256 border-top: 1px solid #ddd; … … 398 398 text-align: left; 399 399 } 400 400 401 /* =Breadcrumb and Tags401 /* =Breadcrumb, Forum Subscription Link and Tags 402 402 -------------------------------------------------------------- */ 403 403 404 404 div.bbp-breadcrumb { … … 415 415 margin-bottom: 10px 416 416 } 417 417 418 #bbpress-forums div.bbp-forum-subscription { 419 float: left; 420 } 421 418 422 #bbpress-forums div.bbp-topic-tags { 419 423 float: left; 420 424 } … … 473 477 width: 50%; 474 478 } 475 479 476 .bbp-forum-header a.bbp-forum-permalink, 480 .bbp-forum-header a.bbp-forum-permalink, 477 481 .bbp-topic-header a.bbp-topic-permalink, 478 482 .bbp-reply-header a.bbp-reply-permalink { 479 483 float: left; … … 1181 1185 display: inline-block; 1182 1186 margin-right: 0; 1183 1187 word-wrap: break-word; 1184 } 1188 } 1185 1189 #bbpress-forums div.bbp-reply-author img.avatar { 1186 1190 position: absolute; 1187 1191 top: 15px; … … 1204 1208 div.bbp-submit-wrapper { 1205 1209 float: right; 1206 1210 } 1207 #bbpress-forums fieldset.bbp-form { 1211 #bbpress-forums fieldset.bbp-form { 1208 1212 padding: 0 10px 10px; 1209 1213 } 1210 1214 #bbpress-forums #bbp-user-body { … … 1299 1303 #bbpress-forums li.bbp-header li.bbp-topic-reply-count, 1300 1304 #bbpress-forums li.bbp-body li.bbp-topic-voice-count, 1301 1305 #bbpress-forums li.bbp-body li.bbp-topic-reply-count, 1302 #bbpress-forums li.bbp-footer div.bbp-reply-author, 1306 #bbpress-forums li.bbp-footer div.bbp-reply-author, 1303 1307 #bbpress-forums li.bbp-footer div.bbp-reply-content { 1304 1308 width: 45%; 1305 1309 } … … 1313 1317 width: 100%; 1314 1318 } 1315 1319 #bbpress-forums li.bbp-header li.bbp-forum-freshness, 1316 #bbpress-forums li.bbp-header li.bbp-topic-freshness { 1320 #bbpress-forums li.bbp-header li.bbp-topic-freshness { 1317 1321 text-align: center; 1318 1322 } 1319 1323 #bbpress-forums li.bbp-body li.bbp-topic-freshness, … … 1338 1342 #bbpress-forums div.bbp-reply-author img.avatar { 1339 1343 width: 40px; 1340 1344 height: auto; 1341 } 1345 } 1342 1346 } 1347 No newline at end of file -
templates/default/css/bbpress.css
398 398 text-align: right; 399 399 } 400 400 401 /* =Breadcrumb and Tags401 /* =Breadcrumb, Forum Subscription Link and Tags 402 402 -------------------------------------------------------------- */ 403 403 404 404 div.bbp-breadcrumb { … … 415 415 margin-bottom: 10px 416 416 } 417 417 418 #bbpress-forums div.bbp-forum-subscription { 419 float: right; 420 } 421 418 422 #bbpress-forums div.bbp-topic-tags { 419 423 float: right; 420 424 }