Changeset 5156 for trunk/includes/users/template.php
- Timestamp:
- 11/20/2013 07:50:55 PM (12 years ago)
- File:
-
- 1 edited
-
trunk/includes/users/template.php (modified) (9 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/includes/users/template.php
r5126 r5156 613 613 614 614 /** Anonymous Fields **********************************************************/ 615 615 616 616 /** 617 617 * Output the author disylay-name of a topic or reply. … … 886 886 */ 887 887 function bbp_get_user_favorites_link( $args = '', $user_id = 0, $wrap = true ) { 888 if ( ! bbp_is_favorites_active() )888 if ( ! bbp_is_favorites_active() ) { 889 889 return false; 890 } 890 891 891 892 // Parse arguments against default values … … 907 908 908 909 // No link if you can't edit yourself 909 if ( ! current_user_can( 'edit_user', (int) $user_id ) ) {910 if ( ! current_user_can( 'edit_user', (int) $user_id ) ) { 910 911 return false; 911 912 } … … 913 914 // Decide which link to show 914 915 $is_fav = bbp_is_user_favorite( $user_id, $topic_id ); 915 if ( ! empty( $is_fav ) ) {916 if ( ! empty( $is_fav ) ) { 916 917 $text = $r['favorited']; 917 918 $query_args = array( 'action' => 'bbp_favorite_remove', 'topic_id' => $topic_id ); … … 936 937 937 938 // Initial output is wrapped in a span, ajax output is hooked to this 938 if ( ! empty( $wrap ) ) {939 if ( ! empty( $wrap ) ) { 939 940 $html = '<span id="favorite-toggle">' . $html . '</span>'; 940 941 } … … 1019 1020 } 1020 1021 /** 1021 * Return the link to subscribe/unsubscribe from a topic1022 * Return the link to subscribe/unsubscribe from a forum or topic 1022 1023 * 1023 1024 * @since bbPress (r2668) … … 1028 1029 * - user_id: User id 1029 1030 * - topic_id: Topic id 1031 * - forum_id: Forum id 1030 1032 * - before: Before the link 1031 1033 * - after: After the link 1032 1034 * @param int $user_id Optional. User id 1033 1035 * @param bool $wrap Optional. If you want to wrap the link in <span id="subscription-toggle">. 1036 * @uses bbp_is_subscriptions_active() to check if subscriptions are active 1034 1037 * @uses bbp_get_user_id() To get the user id 1038 * @uses bbp_get_user_id() To get the user id 1039 * @uses bbp_get_topic_id() To get the topic id 1040 * @uses bbp_get_forum_id() To get the forum id 1035 1041 * @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 subscribed1042 * @uses bbp_is_user_subscribed_to_forum() To check if the user is subscribed to the forum 1043 * @uses bbp_is_user_subscribed_to_topic() To check if the user is subscribed to the topic 1038 1044 * @uses bbp_is_subscriptions() To check if it's the subscriptions page 1039 1045 * @uses bbp_get_subscriptions_permalink() To get subscriptions link … … 1044 1050 */ 1045 1051 function bbp_get_user_subscribe_link( $args = '', $user_id = 0, $wrap = true ) { 1046 if ( ! bbp_is_subscriptions_active() )1052 if ( ! bbp_is_subscriptions_active() ) { 1047 1053 return; 1054 } 1048 1055 1049 1056 // Parse arguments against default values … … 1053 1060 'user_id' => 0, 1054 1061 'topic_id' => 0, 1062 'forum_id' => 0, 1055 1063 'before' => ' | ', 1056 1064 'after' => '' 1057 1065 ), 'get_user_subscribe_link' ); 1058 1066 1059 // Validate user and topicID's1067 // Validate user and object ID's 1060 1068 $user_id = bbp_get_user_id( $r['user_id'], true, true ); 1061 1069 $topic_id = bbp_get_topic_id( $r['topic_id'] ); 1062 if ( empty( $user_id ) || empty( $topic_id ) ) { 1070 $forum_id = bbp_get_forum_id( $r['forum_id'] ); 1071 if ( empty( $user_id ) || ( empty( $topic_id ) && empty( $forum_id ) ) ) { 1063 1072 return false; 1064 1073 } 1065 1074 1066 1075 // No link if you can't edit yourself 1067 if ( ! current_user_can( 'edit_user', (int) $user_id ) ) {1076 if ( ! current_user_can( 'edit_user', (int) $user_id ) ) { 1068 1077 return false; 1069 1078 } 1070 1079 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 ); 1080 // Check if viewing a single forum 1081 if ( empty( $topic_id ) && ! empty( $forum_id ) ) { 1082 1083 // Decide which link to show 1084 $is_subscribed = bbp_is_user_subscribed_to_forum( $user_id, $forum_id ); 1085 if ( ! empty( $is_subscribed ) ) { 1086 $text = $r['unsubscribe']; 1087 $query_args = array( 'action' => 'bbp_unsubscribe', 'forum_id' => $forum_id ); 1088 } else { 1089 $text = $r['subscribe']; 1090 $query_args = array( 'action' => 'bbp_subscribe', 'forum_id' => $forum_id ); 1091 } 1092 1093 // Create the link based where the user is and if the user is 1094 // subscribed already 1095 if ( bbp_is_subscriptions() ) { 1096 $permalink = bbp_get_subscriptions_permalink( $user_id ); 1097 } elseif ( bbp_is_single_forum() || bbp_is_single_reply() ) { 1098 $permalink = bbp_get_forum_permalink( $forum_id ); 1099 } else { 1100 $permalink = get_permalink(); 1101 } 1102 1103 $url = esc_url( wp_nonce_url( add_query_arg( $query_args, $permalink ), 'toggle-subscription_' . $forum_id ) ); 1104 $sub = $is_subscribed ? ' class="is-subscribed"' : ''; 1105 $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'] ); 1106 1107 // Initial output is wrapped in a span, ajax output is hooked to this 1108 if ( !empty( $wrap ) ) { 1109 $html = '<span id="subscription-toggle">' . $html . '</span>'; 1110 } 1111 1076 1112 } else { 1077 $text = $r['subscribe']; 1078 $query_args = array( 'action' => 'bbp_subscribe', 'topic_id' => $topic_id ); 1079 } 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 ); 1087 } else { 1088 $permalink = get_permalink(); 1089 } 1090 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'] ); 1094 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>'; 1113 1114 // Decide which link to show 1115 $is_subscribed = bbp_is_user_subscribed_to_topic( $user_id, $topic_id ); 1116 if ( ! empty( $is_subscribed ) ) { 1117 $text = $r['unsubscribe']; 1118 $query_args = array( 'action' => 'bbp_unsubscribe', 'topic_id' => $topic_id ); 1119 } else { 1120 $text = $r['subscribe']; 1121 $query_args = array( 'action' => 'bbp_subscribe', 'topic_id' => $topic_id ); 1122 } 1123 1124 // Create the link based where the user is and if the user is 1125 // subscribed already 1126 if ( bbp_is_subscriptions() ) { 1127 $permalink = bbp_get_subscriptions_permalink( $user_id ); 1128 } elseif ( bbp_is_single_topic() || bbp_is_single_reply() ) { 1129 $permalink = bbp_get_topic_permalink( $topic_id ); 1130 } else { 1131 $permalink = get_permalink(); 1132 } 1133 1134 $url = esc_url( wp_nonce_url( add_query_arg( $query_args, $permalink ), 'toggle-subscription_' . $topic_id ) ); 1135 $sub = $is_subscribed ? ' class="is-subscribed"' : ''; 1136 $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'] ); 1137 1138 // Initial output is wrapped in a span, ajax output is hooked to this 1139 if ( !empty( $wrap ) ) { 1140 $html = '<span id="subscription-toggle">' . $html . '</span>'; 1141 } 1098 1142 } 1099 1143
Note: See TracChangeset
for help on using the changeset viewer.