Changeset 4269
- Timestamp:
- 10/19/2016 07:09:38 PM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-bbp-user-badges/inc/class-plugin.php
r4205 r4269 52 52 public function bbp_loaded() { 53 53 // Add class to div containing reply. 54 add_filter( 'bbp_get_topic_class', array( $this, 'bbp_get_topic_class' ), 10, 2 ); 54 55 add_filter( 'bbp_get_reply_class', array( $this, 'bbp_get_reply_class' ), 10, 2 ); 55 56 56 57 // Add badge before reply author info. 57 add_action( 'bbp_theme_before_reply_author_details', array( $this, 'add_user_badges' ) ); 58 } 59 60 protected function get_author_badge_info() { 58 add_action( 'bbp_theme_before_topic_author_details', array( $this, 'show_topic_author_badge' ) ); 59 add_action( 'bbp_theme_before_reply_author_details', array( $this, 'show_reply_author_badge' ) ); 60 } 61 62 /** 63 * Return information about the resource item author if they merit a badge. 64 * 65 * Author badge is only applicable in support or reviews forums for a plugin 66 * or theme to which the author is listed as a committer or a contributor. 67 * 68 * @access protected 69 * 70 * @param string $item_type The type of thing whose author is being checked 71 * for badge info. One of 'topic' or 'reply'. 72 * @param int $item_id The ID of the item getting badge assigned. 73 * @return array|false Associative array with keys 'type', 'slug', and 74 * 'user_login' if author merits a badge, else false. 75 */ 76 protected function get_author_badge_info( $item_type, $item_id ) { 61 77 if ( ! class_exists( '\WordPressdotorg\Forums\Plugin' ) ) { 62 return ;78 return false; 63 79 } 64 80 … … 69 85 ); 70 86 71 $forum_id = bbp_get_reply_forum_id(); 72 $topic_id = bbp_get_reply_topic_id(); 87 if ( 'topic' === $item_type ) { 88 $forum_id = bbp_get_topic_forum_id(); 89 $topic_id = $item_id; 90 $user_id = bbp_get_topic_author_id(); 91 } else { 92 $forum_id = bbp_get_reply_forum_id(); 93 $topic_id = bbp_get_reply_topic_id(); 94 $user_id = bbp_get_reply_author_id(); 95 } 73 96 74 97 if ( ! in_array( $forum_id, $badgeable_forums ) ) { 75 return; 98 return false; 99 } 100 101 if ( ! $user_id ) { 102 return false; 76 103 } 77 104 78 105 $slugs = $types = array(); 79 80 $user_id = bbp_get_reply_author_id();81 if ( ! $user_id ) {82 return;83 }84 106 85 107 $user_login = get_user_by( 'id', $user_id )->user_login; … … 100 122 // Else not a type of concern. 101 123 else { 102 return ;124 return false; 103 125 } 104 126 … … 111 133 112 134 if ( ! $slugs ) { 113 return ;135 return false; 114 136 } 115 137 … … 121 143 } 122 144 145 /** 146 * Amends the provided classes for a given topic with badge-related classes. 147 * 148 * @param array $classes Array of existing classes. 149 * @param int $topic_id The ID of the topic. 150 * @return array 151 */ 152 public function bbp_get_topic_class( $classes, $topic_id ) { 153 return $this->get_badge_class( $classes, 'topic', $topic_id ); 154 } 155 156 /** 157 * Amends the provided classes for a given reply with badge-related classes. 158 * 159 * @param array $classes Array of existing classes. 160 * @param int $reply_id The ID of the reply. 161 * @return array 162 */ 123 163 public function bbp_get_reply_class( $classes, $reply_id ) { 164 return $this->get_badge_class( $classes, 'reply', $reply_id ); 165 } 166 167 /** 168 * Amends the provided classes with badge-related classes. 169 * 170 * Possible badge classes: 171 * - by-moderator (Note: will always be added if author is a moderator) 172 * - by-plugin-author 173 * - by-plugin-contributor 174 * - by-theme-author 175 * - by-theme-contributor 176 * 177 * @access protected 178 * 179 * @param array $classes Array of existing classes. 180 * @param string $item_type The type of thing getting badge assigned. One of 'topic' or 'reply'. 181 * @param int $item_id The ID of the item getting badge assigned. 182 * @return array 183 */ 184 protected function get_badge_class( $classes, $item_type, $item_id ) { 124 185 // Class related to moderators. 125 186 if ( $this->is_user_moderator() ) { … … 128 189 129 190 // Class related to plugin and theme authors/contributors. 130 if ( $info = $this->get_author_badge_info( ) ) {191 if ( $info = $this->get_author_badge_info( $item_type, $item_id ) ) { 131 192 if ( $this->is_user_author( $info['user_login'], $info['type'], $info['slug'] ) ) { 132 193 $contrib_type = 'author'; … … 146 207 147 208 /** 148 * Display author badge if reply author is in support or reviews forum for 149 * the plugin/theme they contribute to. 150 */ 151 public function add_user_badges() { 152 $output = $this->get_author_badge(); 209 * Display badge for topic author if they merit a badge. 210 */ 211 public function show_topic_author_badge() { 212 $this->show_user_badge( 'topic', bbp_get_topic_id() ); 213 } 214 215 /** 216 * Display badge for reply author if they merit a badge. 217 */ 218 public function show_reply_author_badge() { 219 $this->show_user_badge( 'reply', bbp_get_reply_id() ); 220 } 221 222 /** 223 * Display badge if the author merits a badge. 224 * 225 * @access protected 226 * 227 * @param string $item_type The type of thing getting badge assigned. One of 'topic' or 'reply'. 228 * @param int $item_id The ID of the item getting badge assigned. 229 */ 230 protected function show_user_badge( $item_type, $item_id ) { 231 $output = $this->get_author_badge( $item_type, $item_id ); 153 232 154 233 // Don't assign moderator badge if already assigning author badge. … … 162 241 } 163 242 243 /** 244 * Returns the HTML formatted badge. 245 * 246 * @param $type string The type of badge. 247 * @param $label string The label for the badge. 248 * @param $help string Optional. Help/descriptive text for the badge. 249 * @return string 250 */ 164 251 protected function format_badge( $type, $label, $help = '' ) { 165 252 $output = ''; … … 178 265 } 179 266 180 protected function get_author_badge() { 181 if ( ! $info = $this->get_author_badge_info() ) { 182 return; 267 /** 268 * Get badge if the author merits a badge for being a plugin/theme author or 269 * contributor. 270 * 271 * @access protected 272 * 273 * @param string $item_type The type of thing getting badge assigned. One of 274 * 'topic' or 'reply'. 275 * @param int $item_id The ID of the item getting badge assigned. 276 * @return array|false Associative array with keys 'type', 'slug', and 277 * 'user_login' if author merits a badge, else null. 278 */ 279 protected function get_author_badge( $item_type, $item_id ) { 280 if ( ! $info = $this->get_author_badge_info( $item_type, $item_id ) ) { 281 return false; 183 282 } 184 283 … … 208 307 } 209 308 309 /** 310 * Get badge if the author merits a badge for being a moderator. 311 * 312 * @access protected 313 * 314 * @return array|false Associative array with keys 'type', 'slug', and 315 * 'user_login' if author merits a badge, else false. 316 */ 210 317 protected function get_moderator_badge() { 211 318 $label = $help = null;
Note: See TracChangeset
for help on using the changeset viewer.