← All changes
|
integrations/buddypress/includes/bp-members.php
+1086
-0
7.9.9.2
→
8.0.6
View file →
| @@ -1,0 +1,1086 @@ | ||
| 1 | +<?php | |
| 2 | +/** | |
| 3 | + * BuddyPress Membership | |
| 4 | + * | |
| 5 | + * @package GamiPress\BuddyPress\BuddyPress_Members | |
| 6 | + * @since 1.0.1 | |
| 7 | + */ | |
| 8 | + | |
| 9 | +// Exit if accessed directly | |
| 10 | +if( !defined( 'ABSPATH' ) ) exit; | |
| 11 | + | |
| 12 | +/** | |
| 13 | + * Loads GamiPress_BP_Component Class from bp_init | |
| 14 | + * | |
| 15 | + * @since 1.0.1 | |
| 16 | + */ | |
| 17 | +function gamipress_bp_load_components() { | |
| 18 | + | |
| 19 | + if ( function_exists( 'buddypress' ) && buddypress() && ! buddypress()->maintenance_mode && gamipress_bp_is_active( 'xprofile' ) ) { | |
| 20 | + | |
| 21 | + // Load the component if site pass all checks | |
| 22 | + $GLOBALS['gamipress_points_bp_component'] = new GamiPress_Points_BP_Component(); | |
| 23 | + $GLOBALS['gamipress_achievements_bp_component'] = new GamiPress_Achievements_BP_Component(); | |
| 24 | + $GLOBALS['gamipress_ranks_bp_component'] = new GamiPress_Ranks_BP_Component(); | |
| 25 | + | |
| 26 | + } | |
| 27 | + | |
| 28 | +} | |
| 29 | +add_action( 'bp_init', 'gamipress_bp_load_components', 1 ); | |
| 30 | + | |
| 31 | +/** | |
| 32 | + * Creates a BuddyPress member page for points | |
| 33 | + * | |
| 34 | + * @since 1.0.8 | |
| 35 | + */ | |
| 36 | +function gamipress_bp_points_tab() { | |
| 37 | + | |
| 38 | + add_action( 'bp_template_content', 'gamipress_bp_points_tab_content' ); | |
| 39 | + | |
| 40 | + bp_core_load_template( apply_filters( 'gamipress_bp_points_tab', 'members/single/plugins' ) ); | |
| 41 | + | |
| 42 | +} | |
| 43 | + | |
| 44 | +/** | |
| 45 | + * Displays a member points | |
| 46 | + * | |
| 47 | + * @since 1.0.8 | |
| 48 | + */ | |
| 49 | +function gamipress_bp_points_tab_content() { | |
| 50 | + | |
| 51 | + $points_types_to_show = gamipress_bp_tab_get_points_types(); | |
| 52 | + | |
| 53 | + if ( empty( $points_types_to_show ) ) { | |
| 54 | + return; | |
| 55 | + } | |
| 56 | + | |
| 57 | + $points_types_hide = (bool) gamipress_bp_get_option( 'tab_points_types_hide', false ); | |
| 58 | + | |
| 59 | + foreach ( $points_types_to_show as $key => $point_type_to_show ) { | |
| 60 | + | |
| 61 | + $user_points = gamipress_get_user_points( bp_displayed_user_id(), $point_type_to_show ); | |
| 62 | + | |
| 63 | + if ( $points_types_hide && $user_points <= 0 ) { | |
| 64 | + unset($points_types_to_show[$key]); | |
| 65 | + } | |
| 66 | + } | |
| 67 | + | |
| 68 | + if ( !empty( $points_types_to_show) ){ | |
| 69 | + echo gamipress_points_shortcode( array( | |
| 70 | + 'type' => implode( ',', $points_types_to_show ), | |
| 71 | + 'current_user' => 'no', | |
| 72 | + 'user_id' => bp_displayed_user_id(), | |
| 73 | + 'wpms' => (bool) gamipress_get_option( 'ms_show_all_achievements', false ) ? 'yes' : 'no', | |
| 74 | + ) ); | |
| 75 | + } | |
| 76 | + | |
| 77 | +} | |
| 78 | + | |
| 79 | +/** | |
| 80 | + * Creates a BuddyPress member page for achievements | |
| 81 | + * | |
| 82 | + * @since 1.0.1 | |
| 83 | + */ | |
| 84 | +function gamipress_bp_achievements_tab() { | |
| 85 | + | |
| 86 | + add_action( 'bp_template_content', 'gamipress_bp_achievements_tab_content' ); | |
| 87 | + | |
| 88 | + bp_core_load_template( apply_filters( 'gamipress_bp_achievements_tab', 'members/single/plugins' ) ); | |
| 89 | + | |
| 90 | +} | |
| 91 | + | |
| 92 | +/** | |
| 93 | + * Displays a member achievements | |
| 94 | + * | |
| 95 | + * @since 1.0.1 | |
| 96 | + */ | |
| 97 | +function gamipress_bp_achievements_tab_content() { | |
| 98 | + | |
| 99 | + $achievements_types_to_show = gamipress_bp_tab_get_achievements_types(); | |
| 100 | + | |
| 101 | + // Bail if not types provided | |
| 102 | + if ( empty( $achievements_types_to_show ) ) return; | |
| 103 | + | |
| 104 | + $achievements_tab_title = gamipress_bp_get_option( 'achievements_tab_title', __( 'Achievements', 'gamipress' ) ); | |
| 105 | + $achievements_tab_slug = gamipress_bp_get_option( 'achievements_tab_slug', '' ); | |
| 106 | + | |
| 107 | + // If empty slug generate it from the title | |
| 108 | + if( empty( $achievements_tab_slug ) ) | |
| 109 | + $achievements_tab_slug = sanitize_title( $achievements_tab_title ); | |
| 110 | + | |
| 111 | + $type = ''; | |
| 112 | + $current_uri = $_SERVER['REQUEST_URI']; | |
| 113 | + | |
| 114 | + foreach ( $achievements_types_to_show as $achievement_type ) { | |
| 115 | + | |
| 116 | + // Check if current URI matches any type (need to check the achievements tab slug + achievement type | |
| 117 | + if ( strpos( $current_uri, $achievements_tab_slug . '/' . $achievement_type ) ) { | |
| 118 | + $type = $achievement_type; | |
| 119 | + // Exit on find achievement type | |
| 120 | + break; | |
| 121 | + } | |
| 122 | + } | |
| 123 | + | |
| 124 | + if ( empty( $type ) ) { | |
| 125 | + | |
| 126 | + if( isset( $achievements_types_to_show[0] ) ) { | |
| 127 | + $type = $achievements_types_to_show[0]; | |
| 128 | + } else { | |
| 129 | + return; | |
| 130 | + } | |
| 131 | + } | |
| 132 | + | |
| 133 | + $prefix = 'members_achievements_'; | |
| 134 | + | |
| 135 | + // Setup achievement atts | |
| 136 | + $achievement_atts = array(); | |
| 137 | + | |
| 138 | + // Loop achievement shortcode fields to pass to the shortcode call | |
| 139 | + foreach( GamiPress()->shortcodes['gamipress_achievement']->fields as $field_id => $field_args ) { | |
| 140 | + | |
| 141 | + if( $field_id === 'id' ) { | |
| 142 | + continue; | |
| 143 | + } | |
| 144 | + | |
| 145 | + if( $field_args['type'] === 'checkbox' ) { | |
| 146 | + $achievement_atts[$field_id] = ( (bool) gamipress_bp_get_option( $prefix . $field_id, false ) ? 'yes' : 'no' ); | |
| 147 | + } else { | |
| 148 | + $achievement_atts[$field_id] = gamipress_bp_get_option( $prefix . $field_id, ( isset( $field_args['default'] ) ? $field_args['default'] : '' ) ); | |
| 149 | + } | |
| 150 | + | |
| 151 | + } | |
| 152 | + | |
| 153 | + echo gamipress_achievements_shortcode( array_merge( array( | |
| 154 | + 'type' => $type, | |
| 155 | + 'columns' => gamipress_bp_get_option( $prefix . 'columns', '1' ), | |
| 156 | + 'filter' => 'no', | |
| 157 | + 'filter_value' => 'completed', | |
| 158 | + 'search' => 'no', | |
| 159 | + 'current_user' => 'no', | |
| 160 | + 'user_id' => bp_displayed_user_id(), | |
| 161 | + 'wpms' => (bool) gamipress_get_option( 'ms_show_all_achievements', false ) ? 'yes' : 'no', | |
| 162 | + 'limit' => gamipress_bp_get_option( $prefix . 'limit', '10' ), | |
| 163 | + 'orderby' => gamipress_bp_get_option( $prefix . 'orderby', 'menu_order' ), | |
| 164 | + 'order' => gamipress_bp_get_option( $prefix . 'order', 'ASC' ), | |
| 165 | + 'include' => '', | |
| 166 | + 'exclude' => '', | |
| 167 | + ), $achievement_atts ) ); | |
| 168 | + | |
| 169 | +} | |
| 170 | + | |
| 171 | +/** | |
| 172 | + * Creates a BuddyPress member page for achievements | |
| 173 | + * | |
| 174 | + * @since 1.1.1 | |
| 175 | + */ | |
| 176 | +function gamipress_bp_ranks_tab() { | |
| 177 | + | |
| 178 | + add_action( 'bp_template_content', 'gamipress_bp_ranks_tab_content' ); | |
| 179 | + | |
| 180 | + bp_core_load_template( apply_filters( 'gamipress_bp_ranks_tab', 'members/single/plugins' ) ); | |
| 181 | + | |
| 182 | +} | |
| 183 | + | |
| 184 | +/** | |
| 185 | + * Displays a member ranks | |
| 186 | + * | |
| 187 | + * @since 1.1.1 | |
| 188 | + */ | |
| 189 | +function gamipress_bp_ranks_tab_content() { | |
| 190 | + | |
| 191 | + $ranks_types_to_show = gamipress_bp_tab_get_ranks_types(); | |
| 192 | + | |
| 193 | + if ( empty( $ranks_types_to_show ) ) return; | |
| 194 | + | |
| 195 | + $rank_types_hide = (bool) gamipress_bp_get_option( 'tab_ranks_types_hide', false ); | |
| 196 | + | |
| 197 | + $prefix = 'members_ranks_'; | |
| 198 | + | |
| 199 | + // Setup rank atts | |
| 200 | + $rank_atts = array(); | |
| 201 | + | |
| 202 | + // Loop rank shortcode fields to pass to the shortcode call | |
| 203 | + foreach( GamiPress()->shortcodes['gamipress_rank']->fields as $field_id => $field_args ) { | |
| 204 | + | |
| 205 | + if( $field_id === 'id' ) { | |
| 206 | + continue; | |
| 207 | + } | |
| 208 | + | |
| 209 | + if( $field_args['type'] === 'checkbox' ) { | |
| 210 | + $rank_atts[$field_id] = ( (bool) gamipress_bp_get_option( $prefix . $field_id, false ) ? 'yes' : 'no' ); | |
| 211 | + } else { | |
| 212 | + $rank_atts[$field_id] = gamipress_bp_get_option( $prefix . $field_id, ( isset( $field_args['default'] ) ? $field_args['default'] : '' ) ); | |
| 213 | + } | |
| 214 | + | |
| 215 | + } | |
| 216 | + | |
| 217 | + foreach ( $ranks_types_to_show as $key => $rank_type_to_show ) { | |
| 218 | + | |
| 219 | + $user_rank = gamipress_get_user_rank( bp_displayed_user_id(), $rank_type_to_show ); | |
| 220 | + $user_rank_is_lowest = gamipress_is_lowest_priority_rank( $user_rank->ID ); | |
| 221 | + | |
| 222 | + if ( $rank_types_hide && $user_rank_is_lowest ) { | |
| 223 | + unset($ranks_types_to_show[$key]); | |
| 224 | + } | |
| 225 | + } | |
| 226 | + | |
| 227 | + if ( !empty( $ranks_types_to_show) ){ | |
| 228 | + echo gamipress_ranks_shortcode( array_merge( array( | |
| 229 | + 'type' => implode( ',', $ranks_types_to_show ), | |
| 230 | + 'columns' => gamipress_bp_get_option( $prefix . 'columns', '1' ), | |
| 231 | + 'current_user' => 'no', | |
| 232 | + 'user_id' => bp_displayed_user_id(), | |
| 233 | + 'wpms' => (bool) gamipress_get_option( 'ms_show_all_achievements', false ) ? 'yes' : 'no', | |
| 234 | + 'orderby' => gamipress_bp_get_option( $prefix . 'orderby', 'priority' ), | |
| 235 | + 'order' => gamipress_bp_get_option( $prefix . 'order', 'DESC' ), | |
| 236 | + 'include' => '', | |
| 237 | + 'exclude' => '', | |
| 238 | + ), $rank_atts ) ); | |
| 239 | + } | |
| 240 | + | |
| 241 | +} | |
| 242 | + | |
| 243 | +/** | |
| 244 | + * Displays user information at top | |
| 245 | + * | |
| 246 | + * @since 1.1.1 | |
| 247 | + */ | |
| 248 | +function gamipress_bp_before_member_header() { | |
| 249 | + | |
| 250 | + $user_id = bp_displayed_user_id(); | |
| 251 | + | |
| 252 | + gamipress_bp_user_details_display( $user_id, 'top' ); | |
| 253 | + | |
| 254 | +} | |
| 255 | +add_action( 'bp_before_member_header_meta', 'gamipress_bp_before_member_header' ); | |
| 256 | + | |
| 257 | +/** | |
| 258 | + * Displays user information before activity content | |
| 259 | + * | |
| 260 | + * @since 1.4.2 | |
| 261 | + * | |
| 262 | + * @param string $content | |
| 263 | + * | |
| 264 | + * @return string | |
| 265 | + */ | |
| 266 | +function gamipress_bp_activity_content( $content ) { | |
| 267 | + | |
| 268 | + global $activities_template; | |
| 269 | + | |
| 270 | + if( empty( $activities_template->activity->user_id ) ) { | |
| 271 | + return $content; | |
| 272 | + } | |
| 273 | + | |
| 274 | + $user_id = $activities_template->activity->user_id; | |
| 275 | + | |
| 276 | + ob_start(); | |
| 277 | + gamipress_bp_user_details_display( $user_id, 'activity' ); | |
| 278 | + $details = ob_get_clean(); | |
| 279 | + | |
| 280 | + return $details . $content; | |
| 281 | + | |
| 282 | +} | |
| 283 | +add_filter( 'bp_get_activity_content_body', 'gamipress_bp_activity_content' ); | |
| 284 | + | |
| 285 | +/** | |
| 286 | + * Displays user information for activities with no content | |
| 287 | + * | |
| 288 | + * @since 1.4.2 | |
| 289 | + */ | |
| 290 | +function gamipress_bp_activity_empty_content() { | |
| 291 | + | |
| 292 | + if( bp_activity_has_content() ) { | |
| 293 | + return; | |
| 294 | + } | |
| 295 | + | |
| 296 | + if( function_exists( 'bp_nouveau_activity_has_content' ) ) { | |
| 297 | + if( bp_nouveau_activity_has_content() ) { | |
| 298 | + return; | |
| 299 | + } | |
| 300 | + } | |
| 301 | + | |
| 302 | + gamipress_bp_user_details_display( bp_get_activity_user_id(), 'activity' ); | |
| 303 | + | |
| 304 | +} | |
| 305 | +add_action( 'bp_activity_entry_content', 'gamipress_bp_activity_empty_content', 9 ); | |
| 306 | + | |
| 307 | +/** | |
| 308 | + * Displays user information before activity content | |
| 309 | + * | |
| 310 | + * @since 1.4.2 | |
| 311 | + * | |
| 312 | + * @param string $content | |
| 313 | + * | |
| 314 | + * @return string | |
| 315 | + */ | |
| 316 | +function gamipress_bp_activity_comment_content( $content ) { | |
| 317 | + | |
| 318 | + global $activities_template; | |
| 319 | + | |
| 320 | + if( empty( $activities_template->activity->current_comment->user_id ) ) { | |
| 321 | + return $content; | |
| 322 | + } | |
| 323 | + | |
| 324 | + $user_id = $activities_template->activity->current_comment->user_id; | |
| 325 | + | |
| 326 | + ob_start(); | |
| 327 | + gamipress_bp_user_details_display( $user_id, 'activity' ); | |
| 328 | + $details = ob_get_clean(); | |
| 329 | + | |
| 330 | + return $details . $content; | |
| 331 | + | |
| 332 | +} | |
| 333 | +add_filter( 'bp_activity_comment_content', 'gamipress_bp_activity_comment_content' ); | |
| 334 | + | |
| 335 | +/** | |
| 336 | + * Displays user information on member listing avatar | |
| 337 | + * | |
| 338 | + * @since 1.4.2 | |
| 339 | + * | |
| 340 | + * @param string $avatar | |
| 341 | + * | |
| 342 | + * @return string | |
| 343 | + */ | |
| 344 | +function gamipress_bp_get_member_avatar( $avatar ) { | |
| 345 | + | |
| 346 | + global $members_template; | |
| 347 | + | |
| 348 | + if( empty( $members_template->member->id ) ) { | |
| 349 | + return $avatar; | |
| 350 | + } | |
| 351 | + | |
| 352 | + $user_id = $members_template->member->id; | |
| 353 | + | |
| 354 | + ob_start(); | |
| 355 | + gamipress_bp_user_details_display( $user_id, 'listing' ); | |
| 356 | + $details = ob_get_clean(); | |
| 357 | + | |
| 358 | + if( empty( trim( $details ) ) ) { | |
| 359 | + return $avatar; | |
| 360 | + } | |
| 361 | + | |
| 362 | + /** | |
| 363 | + * Filter available to decide if should append <a> tags to the member avatar details | |
| 364 | + * Note: A tags are to close the member avatar link | |
| 365 | + * | |
| 366 | + * @since 1.4.6 | |
| 367 | + * | |
| 368 | + * @param bool $a_tags | |
| 369 | + * @param string $avatar | |
| 370 | + * @param int $user_id | |
| 371 | + * | |
| 372 | + * @return bool | |
| 373 | + */ | |
| 374 | + $a_tags = apply_filters( 'gamipress_bp_member_avatar_a_tags', true, $avatar, $user_id ); | |
| 375 | + | |
| 376 | + if( $a_tags ) { | |
| 377 | + return $avatar . '</a>' . $details . '<a>'; | |
| 378 | + } else { | |
| 379 | + return $avatar . $details; | |
| 380 | + } | |
| 381 | + | |
| 382 | +} | |
| 383 | +add_filter( 'bp_get_member_avatar', 'gamipress_bp_get_member_avatar' ); | |
| 384 | + | |
| 385 | +/** | |
| 386 | + * Helper function to render the user details | |
| 387 | + * | |
| 388 | + * @since 1.4.2 | |
| 389 | + * | |
| 390 | + * @param int $user_id The user ID | |
| 391 | + * @param string $view The view where is rendering (top|listing|activity) | |
| 392 | + */ | |
| 393 | +function gamipress_bp_user_details_display( $user_id, $view ) { | |
| 394 | + | |
| 395 | + if( absint( $user_id ) === 0 ) { | |
| 396 | + return; | |
| 397 | + } | |
| 398 | + | |
| 399 | + $display_options = array( | |
| 400 | + 'show_points' => false, | |
| 401 | + 'show_achievements' => false, | |
| 402 | + 'show_ranks' => false, | |
| 403 | + ); | |
| 404 | + | |
| 405 | + // Get placements | |
| 406 | + $points_placement = gamipress_bp_get_option( 'points_placement', array() ); | |
| 407 | + $achievements_placement = gamipress_bp_get_option( 'achievements_placement', array() ); | |
| 408 | + $ranks_placement = gamipress_bp_get_option( 'ranks_placement', array() ); | |
| 409 | + | |
| 410 | + if( ! is_array( $points_placement ) ) $points_placement = array( $points_placement ); | |
| 411 | + if( ! is_array( $achievements_placement ) ) $achievements_placement = array( $achievements_placement ); | |
| 412 | + if( ! is_array( $ranks_placement ) ) $ranks_placement = array( $ranks_placement ); | |
| 413 | + | |
| 414 | + // Check if should show or not | |
| 415 | + $display_options['show_points'] = in_array( $view, $points_placement ); | |
| 416 | + $display_options['show_achievements'] = in_array( $view, $achievements_placement ); | |
| 417 | + $display_options['show_ranks'] = in_array( $view, $ranks_placement ); | |
| 418 | + | |
| 419 | + // Points | |
| 420 | + if( $display_options['show_points'] ) { | |
| 421 | + $display_options['points_types_to_show'] = gamipress_bp_members_get_points_types(); | |
| 422 | + $display_options['points_types_hide'] = (bool) gamipress_bp_get_option( 'members_points_types_hide', false ); | |
| 423 | + $display_options['points_types_thumbnail'] = (bool) gamipress_bp_get_option( 'members_points_types_top_thumbnail', false ); | |
| 424 | + $display_options['points_types_thumbnail_size'] = (int) gamipress_bp_get_option( 'members_points_types_top_thumbnail_size', 25 ); | |
| 425 | + $display_options['points_types_label'] = (bool) gamipress_bp_get_option( 'members_points_types_top_label', false ); | |
| 426 | + } | |
| 427 | + | |
| 428 | + // Achievements | |
| 429 | + if( $display_options['show_achievements'] ) { | |
| 430 | + $display_options['achievement_types_to_show'] = gamipress_bp_members_get_achievements_types(); | |
| 431 | + $display_options['achievement_types_thumbnail'] = (bool) gamipress_bp_get_option( 'members_achievements_top_thumbnail', false ); | |
| 432 | + $display_options['achievement_types_thumbnail_size'] = (int) gamipress_bp_get_option( 'members_achievements_top_thumbnail_size', 25 ); | |
| 433 | + $display_options['achievement_types_title'] = (bool) gamipress_bp_get_option( 'members_achievements_top_title', false ); | |
| 434 | + $display_options['achievement_types_link'] = (bool) gamipress_bp_get_option( 'members_achievements_top_link', false ); | |
| 435 | + $display_options['achievement_types_label'] = (bool) gamipress_bp_get_option( 'members_achievements_top_label', false ); | |
| 436 | + $display_options['achievement_types_limit'] = (int) gamipress_bp_get_option( 'members_achievements_top_limit', 10 ); | |
| 437 | + } | |
| 438 | + | |
| 439 | + // Ranks | |
| 440 | + if( $display_options['show_ranks'] ) { | |
| 441 | + $display_options['rank_types_to_show'] = gamipress_bp_members_get_ranks_types(); | |
| 442 | + $display_options['rank_types_hide'] = (bool) gamipress_bp_get_option( 'members_ranks_types_hide', false ); | |
| 443 | + $display_options['rank_types_thumbnail'] = (bool) gamipress_bp_get_option( 'members_ranks_top_thumbnail', false ); | |
| 444 | + $display_options['rank_types_thumbnail_size'] = (int) gamipress_bp_get_option( 'members_ranks_top_thumbnail_size', 25 ); | |
| 445 | + $display_options['rank_types_title'] = (bool) gamipress_bp_get_option( 'members_ranks_top_title', false ); | |
| 446 | + $display_options['rank_types_link'] = (bool) gamipress_bp_get_option( 'members_ranks_top_link', false ); | |
| 447 | + $display_options['rank_types_label'] = (bool) gamipress_bp_get_option( 'members_ranks_top_label', false ); | |
| 448 | + } | |
| 449 | + | |
| 450 | + /** | |
| 451 | + * Filter available to override the display options | |
| 452 | + * | |
| 453 | + * @since 1.4.2 | |
| 454 | + * | |
| 455 | + * @param array $display_options Display options from settings | |
| 456 | + * @param int $user_id The user ID | |
| 457 | + * @param string $view The view where is rendering (top|listing|activity) | |
| 458 | + * | |
| 459 | + * @return array | |
| 460 | + */ | |
| 461 | + $display_options = apply_filters( 'gamipress_bp_user_details_display_options', $display_options, $user_id, $view ); | |
| 462 | + | |
| 463 | + /** | |
| 464 | + * Filter available to override the display options for a specific view | |
| 465 | + * Available views are: top|listing|activity | |
| 466 | + * | |
| 467 | + * @since 1.4.2 | |
| 468 | + * | |
| 469 | + * @param array $display_options Display options from settings | |
| 470 | + * @param int $user_id The user ID | |
| 471 | + * | |
| 472 | + * @return array | |
| 473 | + */ | |
| 474 | + $display_options = apply_filters( "gamipress_bp_user_details_{$view}_display_options", $display_options, $user_id ); | |
| 475 | + | |
| 476 | + // Shorthand | |
| 477 | + $a = $display_options; | |
| 478 | + | |
| 479 | + // Bail if nothing to show | |
| 480 | + if( ! $a['show_points'] && ! $a['show_achievements'] && ! $a['show_ranks'] ) { | |
| 481 | + return; | |
| 482 | + } | |
| 483 | + | |
| 484 | + // On network wide active installs, we need to switch to main blog mostly for posts permalinks and thumbnails | |
| 485 | + $blog_id = gamipress_switch_to_main_site_if_network_wide_active(); | |
| 486 | + | |
| 487 | + ?><div class="gamipress-buddypress-user-details gamipress-buddypress-user-details-<?php echo $view; ?>"><?php | |
| 488 | + | |
| 489 | + // Points | |
| 490 | + if( $a['show_points'] ) { | |
| 491 | + gamipress_bp_user_points_display( $user_id, $a ); | |
| 492 | + } | |
| 493 | + | |
| 494 | + // Achievements | |
| 495 | + if( $a['show_achievements'] ) { | |
| 496 | + gamipress_bp_user_achievements_display( $user_id, $a ); | |
| 497 | + } | |
| 498 | + | |
| 499 | + // Ranks | |
| 500 | + if( $a['show_ranks'] ) { | |
| 501 | + gamipress_bp_user_ranks_display( $user_id, $a ); | |
| 502 | + } | |
| 503 | + | |
| 504 | + ?></div><?php | |
| 505 | + | |
| 506 | + // If switched to blog, return back to que current blog | |
| 507 | + if( $blog_id !== get_current_blog_id() && is_multisite() ) { | |
| 508 | + restore_current_blog(); | |
| 509 | + } | |
| 510 | +} | |
| 511 | + | |
| 512 | +/** | |
| 513 | + * Helper function to render the user points | |
| 514 | + * | |
| 515 | + * @since 1.4.2 | |
| 516 | + * | |
| 517 | + * @param int $user_id The user ID | |
| 518 | + * @param array $display_options The display options | |
| 519 | + */ | |
| 520 | +function gamipress_bp_user_points_display( $user_id, $display_options ) { | |
| 521 | + | |
| 522 | + // Shorthand | |
| 523 | + $a = $display_options; | |
| 524 | + | |
| 525 | + // Setup points types vars | |
| 526 | + $points_types = gamipress_get_points_types(); | |
| 527 | + $points_types_slugs = gamipress_get_points_types_slugs(); | |
| 528 | + | |
| 529 | + // Get points display settings | |
| 530 | + $points_types_to_show = $a['points_types_to_show']; | |
| 531 | + $points_types_hide = $a['points_types_hide']; | |
| 532 | + $thumbnail = (bool) $a['points_types_thumbnail']; | |
| 533 | + $thumbnail_size = (int) $a['points_types_thumbnail_size']; | |
| 534 | + $show_label = (bool) $a['points_types_label']; | |
| 535 | + | |
| 536 | + // Parse thumbnail size | |
| 537 | + $thumbnail_size = ( ( $thumbnail_size > 0 ) ? array( $thumbnail_size, $thumbnail_size ) : 'gamipress-points' ); | |
| 538 | + | |
| 539 | + if( empty( $points_types_to_show ) ) { | |
| 540 | + return; | |
| 541 | + } | |
| 542 | + | |
| 543 | + ob_start(); ?> | |
| 544 | + | |
| 545 | + <div class="gamipress-buddypress-points"> | |
| 546 | + | |
| 547 | + <?php foreach( $points_types_to_show as $points_type_to_show ) : | |
| 548 | + | |
| 549 | + // If points type not registered, skip | |
| 550 | + if( ! in_array( $points_type_to_show, $points_types_slugs ) ) | |
| 551 | + continue; | |
| 552 | + | |
| 553 | + $points_type = $points_types[$points_type_to_show]; | |
| 554 | + $label_position = gamipress_get_points_type_label_position( $points_type_to_show ); | |
| 555 | + $user_points = gamipress_get_user_points( $user_id, $points_type_to_show ); ?> | |
| 556 | + | |
| 557 | + <div class="gamipress-buddypress-points-type gamipress-buddypress-<?php echo $points_type_to_show; ?>"> | |
| 558 | + <?php if ( ! $points_types_hide || $user_points > 0 ) : ?> | |
| 559 | + <?php // The points thumbnail ?> | |
| 560 | + <?php if( $thumbnail ) : | |
| 561 | + $points_thumbnail = gamipress_get_points_type_thumbnail( $points_type_to_show, $thumbnail_size ); ?> | |
| 562 | + | |
| 563 | + <?php if( ! empty( $points_thumbnail ) ) : ?> | |
| 564 | + <span class="activity gamipress-buddypress-points-thumbnail gamipress-buddypress-<?php echo $points_type_to_show; ?>-thumbnail"> | |
| 565 | + <?php echo $points_thumbnail; ?> | |
| 566 | + </span> | |
| 567 | + <?php endif; ?> | |
| 568 | + | |
| 569 | + <?php endif; ?> | |
| 570 | + | |
| 571 | + <?php // The points label (before) ?> | |
| 572 | + <?php if( $show_label && $label_position === 'before' ) : ?> | |
| 573 | + <span class="activity gamipress-buddypress-points-label gamipress-buddypress-<?php echo $points_type_to_show; ?>-label"> | |
| 574 | + <?php echo _n( $points_type['singular_name'], $points_type['plural_name'], $user_points ); ?> | |
| 575 | + </span> | |
| 576 | + <?php endif; ?> | |
| 577 | + | |
| 578 | + <?php // The user points amount ?> | |
| 579 | + <span class="activity gamipress-buddypress-user-points gamipress-buddypress-user-<?php echo $points_type_to_show; ?>"> | |
| 580 | + <?php echo gamipress_format_amount( $user_points, $points_type_to_show ); ?> | |
| 581 | + </span> | |
| 582 | + | |
| 583 | + <?php // The points label (after) ?> | |
| 584 | + <?php if( $show_label && $label_position !== 'before' ) : ?> | |
| 585 | + <span class="activity gamipress-buddypress-points-label gamipress-buddypress-<?php echo $points_type_to_show; ?>-label"> | |
| 586 | + <?php echo _n( $points_type['singular_name'], $points_type['plural_name'], $user_points ); ?> | |
| 587 | + </span> | |
| 588 | + <?php endif; ?> | |
| 589 | + <?php endif; ?> | |
| 590 | + | |
| 591 | + </div> | |
| 592 | + | |
| 593 | + <?php endforeach; ?> | |
| 594 | + </div> | |
| 595 | + | |
| 596 | + <?php $output = ob_get_clean(); | |
| 597 | + | |
| 598 | + /** | |
| 599 | + * Filter to override the user points output | |
| 600 | + * | |
| 601 | + * @since 1.4.6 | |
| 602 | + * | |
| 603 | + * @param string $output The user points output | |
| 604 | + * @param int $user_id The user ID | |
| 605 | + * @param array $display_options The display options | |
| 606 | + * | |
| 607 | + * @return string | |
| 608 | + */ | |
| 609 | + $output = apply_filters( 'gamipress_bp_user_points_display', $output, $user_id, $display_options ); | |
| 610 | + | |
| 611 | + echo $output; | |
| 612 | +} | |
| 613 | + | |
| 614 | +/** | |
| 615 | + * Helper function to render the user achievements | |
| 616 | + * | |
| 617 | + * @since 1.4.2 | |
| 618 | + * | |
| 619 | + * @param int $user_id The user ID | |
| 620 | + * @param array $display_options The display options | |
| 621 | + */ | |
| 622 | +function gamipress_bp_user_achievements_display( $user_id, $display_options ) { | |
| 623 | + | |
| 624 | + // Shorthand | |
| 625 | + $a = $display_options; | |
| 626 | + | |
| 627 | + // Setup achievement types vars | |
| 628 | + $achievement_types = gamipress_get_achievement_types(); | |
| 629 | + $achievement_types_slugs = gamipress_get_achievement_types_slugs(); | |
| 630 | + | |
| 631 | + // Get achievements display settings | |
| 632 | + $achievement_types_to_show = $a['achievement_types_to_show']; | |
| 633 | + $thumbnail = (bool) $a['achievement_types_thumbnail']; | |
| 634 | + $thumbnail_size = (int) $a['achievement_types_thumbnail_size']; | |
| 635 | + $show_title = (bool) $a['achievement_types_title']; | |
| 636 | + $show_link = (bool) $a['achievement_types_link']; | |
| 637 | + $show_label = (bool) $a['achievement_types_label']; | |
| 638 | + $limit = (int) $a['achievement_types_limit']; | |
| 639 | + | |
| 640 | + // Parse thumbnail size | |
| 641 | + $thumbnail_size = ( ( $thumbnail_size > 0 ) ? array( $thumbnail_size, $thumbnail_size ) : 'gamipress-achievement' ); | |
| 642 | + | |
| 643 | + if( empty( $achievement_types_to_show ) ) { | |
| 644 | + return; | |
| 645 | + } | |
| 646 | + | |
| 647 | + ob_start(); ?> | |
| 648 | + | |
| 649 | + <div class="gamipress-buddypress-achievements"> | |
| 650 | + | |
| 651 | + <?php foreach( $achievement_types_to_show as $achievement_type_to_show ) : | |
| 652 | + | |
| 653 | + // If achievements type not registered, skip | |
| 654 | + if( ! in_array( $achievement_type_to_show, $achievement_types_slugs ) ) | |
| 655 | + continue; | |
| 656 | + | |
| 657 | + $achievement_type = $achievement_types[$achievement_type_to_show]; | |
| 658 | + $user_achievements = gamipress_get_user_achievements( array( | |
| 659 | + 'user_id' => $user_id, | |
| 660 | + 'achievement_type' => $achievement_type_to_show, | |
| 661 | + 'groupby' => 'achievement_id', | |
| 662 | + 'limit' => $limit, | |
| 663 | + ) ); | |
| 664 | + | |
| 665 | + // If user has not earned any achievements of this type, skip | |
| 666 | + if( empty( $user_achievements ) ) { | |
| 667 | + continue; | |
| 668 | + } ?> | |
| 669 | + | |
| 670 | + <div class="gamipress-buddypress-user-achievements"> | |
| 671 | + | |
| 672 | + <?php // The achievement type label ?> | |
| 673 | + <?php if( $show_label ) : ?> | |
| 674 | + <span class="activity gamipress-buddypress-achievement-type-label gamipress-buddypress-<?php echo $achievement_type_to_show; ?>-label"> | |
| 675 | + <?php echo $achievement_type['plural_name']; ?>: | |
| 676 | + </span> | |
| 677 | + <?php endif; ?> | |
| 678 | + | |
| 679 | + <?php foreach( $user_achievements as $user_achievement ) : | |
| 680 | + // Skip achievement if not exists | |
| 681 | + if( ! gamipress_get_post( $user_achievement->ID ) ) { | |
| 682 | + continue; | |
| 683 | + } ?> | |
| 684 | + | |
| 685 | + <span id="gamipress-buddypress-achievement-<?php echo $user_achievement->ID; ?>" class="gamipress-buddypress-achievement gamipress-buddypress-<?php echo $achievement_type_to_show; ?>"> | |
| 686 | + | |
| 687 | + <?php // The achievement thumbnail ?> | |
| 688 | + <?php if( $thumbnail ) : | |
| 689 | + $achievement_thumbnail = gamipress_get_achievement_post_thumbnail( $user_achievement->ID, $thumbnail_size ); ?> | |
| 690 | + | |
| 691 | + <?php if( ! empty( $achievement_thumbnail ) ) : ?> | |
| 692 | + | |
| 693 | + <?php // The achievement link ?> | |
| 694 | + <?php if( $show_link ) : ?> | |
| 695 | + <a href="<?php echo get_permalink( $user_achievement->ID ); ?>" title="<?php echo get_the_title( $user_achievement->ID ); ?>" class="activity gamipress-buddypress-achievement-thumbnail gamipress-buddypress-<?php echo $achievement_type_to_show; ?>-thumbnail"> | |
| 696 | + <?php echo $achievement_thumbnail; ?> | |
| 697 | + </a> | |
| 698 | + <?php else : ?> | |
| 699 | + <span title="<?php echo get_the_title( $user_achievement->ID ); ?>" class="activity gamipress-buddypress-achievement-thumbnail gamipress-buddypress-<?php echo $achievement_type_to_show; ?>-thumbnail"> | |
| 700 | + <?php echo $achievement_thumbnail; ?> | |
| 701 | + </span> | |
| 702 | + <?php endif; ?> | |
| 703 | + | |
| 704 | + <?php endif; ?> | |
| 705 | + | |
| 706 | + <?php endif; ?> | |
| 707 | + | |
| 708 | + <?php // The achievement title ?> | |
| 709 | + <?php if( $show_title ) : | |
| 710 | + $achievement_title = get_the_title( $user_achievement->ID ); ?> | |
| 711 | + | |
| 712 | + <?php if( ! empty( $achievement_title ) ) : ?> | |
| 713 | + | |
| 714 | + <?php // The achievement link ?> | |
| 715 | + <?php if( $show_link ) : ?> | |
| 716 | + <a href="<?php echo get_permalink( $user_achievement->ID ); ?>" title="<?php echo get_the_title( $user_achievement->ID ); ?>" class="gamipress-buddypress-achievement-title gamipress-buddypress-<?php echo $achievement_type_to_show; ?>-title"> | |
| 717 | + <?php echo get_the_title( $user_achievement->ID ); ?> | |
| 718 | + </a> | |
| 719 | + <?php else : ?> | |
| 720 | + <span class="activity gamipress-buddypress-achievement-title gamipress-buddypress-<?php echo $achievement_type_to_show; ?>-title"> | |
| 721 | + <?php echo get_the_title( $user_achievement->ID ); ?> | |
| 722 | + </span> | |
| 723 | + <?php endif; ?> | |
| 724 | + | |
| 725 | + <?php endif; ?> | |
| 726 | + | |
| 727 | + <?php endif; ?> | |
| 728 | + | |
| 729 | + </span><!-- .gamipress-buddypress-achievement --> | |
| 730 | + | |
| 731 | + <?php endforeach; ?> | |
| 732 | + | |
| 733 | + </div> | |
| 734 | + | |
| 735 | + <?php endforeach; ?> | |
| 736 | + | |
| 737 | + </div> | |
| 738 | + | |
| 739 | + <?php $output = ob_get_clean(); | |
| 740 | + | |
| 741 | + /** | |
| 742 | + * Filter to override the user achievements output | |
| 743 | + * | |
| 744 | + * @since 1.4.6 | |
| 745 | + * | |
| 746 | + * @param string $output The user achievements output | |
| 747 | + * @param int $user_id The user ID | |
| 748 | + * @param array $display_options The display options | |
| 749 | + * | |
| 750 | + * @return string | |
| 751 | + */ | |
| 752 | + $output = apply_filters( 'gamipress_bp_user_achievements_display', $output, $user_id, $display_options ); | |
| 753 | + | |
| 754 | + echo $output; | |
| 755 | + | |
| 756 | +} | |
| 757 | + | |
| 758 | +/** | |
| 759 | + * Helper function to render the user ranks | |
| 760 | + * | |
| 761 | + * @since 1.4.2 | |
| 762 | + * | |
| 763 | + * @param int $user_id The user ID | |
| 764 | + * @param array $display_options The display options | |
| 765 | + */ | |
| 766 | +function gamipress_bp_user_ranks_display( $user_id, $display_options ) { | |
| 767 | + | |
| 768 | + // Shorthand | |
| 769 | + $a = $display_options; | |
| 770 | + | |
| 771 | + // Setup rank types vars | |
| 772 | + $rank_types = gamipress_get_rank_types(); | |
| 773 | + $rank_types_slugs = gamipress_get_rank_types_slugs(); | |
| 774 | + | |
| 775 | + // Get ranks display settings | |
| 776 | + $rank_types_to_show = $a['rank_types_to_show']; | |
| 777 | + $rank_types_hide = $a['rank_types_hide']; | |
| 778 | + $thumbnail = (bool) $a['rank_types_thumbnail']; | |
| 779 | + $thumbnail_size = (int) $a['rank_types_thumbnail_size']; | |
| 780 | + $show_title = (bool) $a['rank_types_title']; | |
| 781 | + $show_link = (bool) $a['rank_types_link']; | |
| 782 | + $show_label = (bool) $a['rank_types_label']; | |
| 783 | + | |
| 784 | + // Parse thumbnail size | |
| 785 | + $thumbnail_size = ( ( $thumbnail_size > 0 ) ? array( $thumbnail_size, $thumbnail_size ) : 'gamipress-rank' ); | |
| 786 | + | |
| 787 | + if( empty( $rank_types_to_show ) ) { | |
| 788 | + return; | |
| 789 | + } | |
| 790 | + | |
| 791 | + ob_start(); ?> | |
| 792 | + | |
| 793 | + <div class="gamipress-buddypress-ranks"> | |
| 794 | + | |
| 795 | + <?php foreach( $rank_types_to_show as $rank_type_to_show ) : | |
| 796 | + | |
| 797 | + // If rank type not registered, skip | |
| 798 | + if( ! in_array( $rank_type_to_show, $rank_types_slugs ) ) | |
| 799 | + continue; | |
| 800 | + | |
| 801 | + $rank_type = $rank_types[$rank_type_to_show]; | |
| 802 | + $user_rank = gamipress_get_user_rank( $user_id, $rank_type_to_show ); | |
| 803 | + $user_rank_is_lowest = gamipress_is_lowest_priority_rank( $user_rank->ID ); ?> | |
| 804 | + | |
| 805 | + <?php if ( ! $rank_types_hide || ! $user_rank_is_lowest ) : ?> | |
| 806 | + <div class="gamipress-buddypress-rank gamipress-buddypress-<?php echo $rank_type_to_show; ?>"> | |
| 807 | + | |
| 808 | + <?php // The rank type label ?> | |
| 809 | + <?php if( $show_label ) : ?> | |
| 810 | + <span class="activity gamipress-buddypress-rank-label gamipress-buddypress-<?php echo $rank_type_to_show; ?>-label"> | |
| 811 | + <?php echo $rank_type['singular_name']; ?>: | |
| 812 | + </span> | |
| 813 | + <?php endif; ?> | |
| 814 | + | |
| 815 | + <?php // The rank thumbnail ?> | |
| 816 | + <?php if( $thumbnail ) : | |
| 817 | + $rank_thumbnail = gamipress_get_rank_post_thumbnail( $user_rank->ID, $thumbnail_size ); ?> | |
| 818 | + | |
| 819 | + <?php if( ! empty( $rank_thumbnail ) ) : ?> | |
| 820 | + | |
| 821 | + <?php // The rank link ?> | |
| 822 | + <?php if( $show_link ) : ?> | |
| 823 | + <a href="<?php echo get_permalink( $user_rank->ID ); ?>" title="<?php echo $user_rank->post_title; ?>" class="activity gamipress-buddypress-rank-thumbnail gamipress-buddypress-<?php echo $rank_type_to_show; ?>-thumbnail"> | |
| 824 | + <?php echo gamipress_get_rank_post_thumbnail( $user_rank->ID, $thumbnail_size ); ?> | |
| 825 | + </a> | |
| 826 | + <?php else : ?> | |
| 827 | + <span title="<?php echo $user_rank->post_title; ?>" class="activity gamipress-buddypress-rank-thumbnail gamipress-buddypress-<?php echo $rank_type_to_show; ?>-thumbnail"> | |
| 828 | + <?php echo gamipress_get_rank_post_thumbnail( $user_rank->ID, $thumbnail_size ); ?> | |
| 829 | + </span> | |
| 830 | + <?php endif; ?> | |
| 831 | + | |
| 832 | + <?php endif; ?> | |
| 833 | + | |
| 834 | + <?php endif; ?> | |
| 835 | + | |
| 836 | + <?php // The rank title ?> | |
| 837 | + <?php if( $show_title && ! empty( $user_rank->post_title ) ) : ?> | |
| 838 | + | |
| 839 | + <?php // The rank link ?> | |
| 840 | + <?php if( $show_link ) : ?> | |
| 841 | + <a href="<?php echo get_permalink( $user_rank->ID ); ?>" title="<?php echo $user_rank->post_title; ?>" class="activity gamipress-buddypress-rank-title gamipress-buddypress-<?php echo $rank_type_to_show; ?>-title"> | |
| 842 | + <?php echo $user_rank->post_title; ?> | |
| 843 | + </a> | |
| 844 | + <?php else : ?> | |
| 845 | + <span class="activity gamipress-buddypress-rank-title gamipress-buddypress-<?php echo $rank_type_to_show; ?>-title"> | |
| 846 | + <?php echo $user_rank->post_title; ?> | |
| 847 | + </span> | |
| 848 | + <?php endif; ?> | |
| 849 | + | |
| 850 | + <?php endif; ?> | |
| 851 | + | |
| 852 | + </div> | |
| 853 | + <?php endif; ?> | |
| 854 | + | |
| 855 | + <?php endforeach; ?> | |
| 856 | + | |
| 857 | + </div> | |
| 858 | + | |
| 859 | + <?php $output = ob_get_clean(); | |
| 860 | + | |
| 861 | + /** | |
| 862 | + * Filter to override the user ranks output | |
| 863 | + * | |
| 864 | + * @since 1.4.6 | |
| 865 | + * | |
| 866 | + * @param string $output The user ranks output | |
| 867 | + * @param int $user_id The user ID | |
| 868 | + * @param array $display_options The display options | |
| 869 | + * | |
| 870 | + * @return string | |
| 871 | + */ | |
| 872 | + $output = apply_filters( 'gamipress_bp_user_ranks_display', $output, $user_id, $display_options ); | |
| 873 | + | |
| 874 | + echo $output; | |
| 875 | +} | |
| 876 | + | |
| 877 | +/** | |
| 878 | + * Override the achievement earners list to use BP details | |
| 879 | + * | |
| 880 | + * @since 1.0.1 | |
| 881 | + * @updated 1.1.1 Also hook to gamipress_get_rank_earners_list_user for ranks support | |
| 882 | + * | |
| 883 | + * @param string $user_content The list item output for the given user | |
| 884 | + * @param integer $user_id The given user's ID | |
| 885 | + * | |
| 886 | + * @return string The updated user output | |
| 887 | + */ | |
| 888 | +function gamipress_bp_override_earners( $user_content, $user_id ) { | |
| 889 | + | |
| 890 | + $user = new BP_Core_User( $user_id ); | |
| 891 | + | |
| 892 | + return '<li><a href="' . $user->user_url . '">' . $user->avatar_mini . '</a></li>'; | |
| 893 | + | |
| 894 | +} | |
| 895 | +add_filter( 'gamipress_get_achievement_earners_list_user', 'gamipress_bp_override_earners', 10, 2 ); | |
| 896 | +add_filter( 'gamipress_get_rank_earners_list_user', 'gamipress_bp_override_earners', 10, 2 ); | |
| 897 | + | |
| 898 | +/** | |
| 899 | + * Helper function to retrieve the points types configured at members screen | |
| 900 | + * | |
| 901 | + * @since 1.0.8 | |
| 902 | + * | |
| 903 | + * @return array | |
| 904 | + */ | |
| 905 | +function gamipress_bp_members_get_points_types() { | |
| 906 | + | |
| 907 | + $points_types = array(); | |
| 908 | + | |
| 909 | + $points_types_slugs = gamipress_get_points_types_slugs(); | |
| 910 | + | |
| 911 | + $points_types_to_show = gamipress_bp_get_option( 'members_points_types', array() ); | |
| 912 | + | |
| 913 | + foreach( $points_types_to_show as $points_type_slug ) { | |
| 914 | + | |
| 915 | + if( ! in_array( $points_type_slug, $points_types_slugs ) ) { | |
| 916 | + continue; | |
| 917 | + } | |
| 918 | + | |
| 919 | + $points_types[] = $points_type_slug; | |
| 920 | + } | |
| 921 | + | |
| 922 | + return $points_types; | |
| 923 | + | |
| 924 | +} | |
| 925 | + | |
| 926 | +/** | |
| 927 | + * Helper function to retrieve the points types configured at members screen | |
| 928 | + * | |
| 929 | + * @since 1.0.8 | |
| 930 | + * | |
| 931 | + * @return array | |
| 932 | + */ | |
| 933 | +function gamipress_bp_tab_get_points_types() { | |
| 934 | + | |
| 935 | + $points_types = array(); | |
| 936 | + | |
| 937 | + $points_types_slugs = gamipress_get_points_types_slugs(); | |
| 938 | + | |
| 939 | + $points_types_to_show = gamipress_bp_get_option( 'tab_points_types', array() ); | |
| 940 | + | |
| 941 | + foreach( $points_types_to_show as $points_type_slug ) { | |
| 942 | + | |
| 943 | + if( ! in_array( $points_type_slug, $points_types_slugs ) ) { | |
| 944 | + continue; | |
| 945 | + } | |
| 946 | + | |
| 947 | + $points_types[] = $points_type_slug; | |
| 948 | + } | |
| 949 | + | |
| 950 | + return $points_types; | |
| 951 | + | |
| 952 | +} | |
| 953 | + | |
| 954 | +/** | |
| 955 | + * Helper function to retrieve the achievement types configured at members screen | |
| 956 | + * | |
| 957 | + * @since 1.0.5 | |
| 958 | + * | |
| 959 | + * @return array | |
| 960 | + */ | |
| 961 | +function gamipress_bp_members_get_achievements_types() { | |
| 962 | + | |
| 963 | + $achievements_types = array(); | |
| 964 | + | |
| 965 | + $achievement_types_slugs = gamipress_get_achievement_types_slugs(); | |
| 966 | + | |
| 967 | + $achievements_types_to_show = gamipress_bp_get_option( 'members_achievements_types', array() ); | |
| 968 | + | |
| 969 | + foreach( $achievements_types_to_show as $achievement_type_slug ) { | |
| 970 | + | |
| 971 | + // Skip if not registered | |
| 972 | + if( ! in_array( $achievement_type_slug, $achievement_types_slugs ) ) { | |
| 973 | + continue; | |
| 974 | + } | |
| 975 | + | |
| 976 | + $achievements_types[] = $achievement_type_slug; | |
| 977 | + } | |
| 978 | + | |
| 979 | + return $achievements_types; | |
| 980 | + | |
| 981 | +} | |
| 982 | + | |
| 983 | +/** | |
| 984 | + * Helper function to retrieve the achievement types configured on profile tabs | |
| 985 | + * | |
| 986 | + * @since 1.0.5 | |
| 987 | + * | |
| 988 | + * @return array | |
| 989 | + */ | |
| 990 | +function gamipress_bp_tab_get_achievements_types() { | |
| 991 | + | |
| 992 | + $achievements_types = array(); | |
| 993 | + | |
| 994 | + $achievement_types_slugs = gamipress_get_achievement_types_slugs(); | |
| 995 | + | |
| 996 | + $achievements_types_to_show = gamipress_bp_get_option( 'tab_achievements_types', array() ); | |
| 997 | + | |
| 998 | + foreach( $achievements_types_to_show as $achievement_type_slug ) { | |
| 999 | + | |
| 1000 | + // Skip if not registered | |
| 1001 | + if( ! in_array( $achievement_type_slug, $achievement_types_slugs ) ) { | |
| 1002 | + continue; | |
| 1003 | + } | |
| 1004 | + | |
| 1005 | + $achievements_types[] = $achievement_type_slug; | |
| 1006 | + } | |
| 1007 | + | |
| 1008 | + return $achievements_types; | |
| 1009 | + | |
| 1010 | +} | |
| 1011 | + | |
| 1012 | +/** | |
| 1013 | + * Helper function to retrieve the rank types configured at members screen | |
| 1014 | + * | |
| 1015 | + * @since 1.1.1 | |
| 1016 | + * | |
| 1017 | + * @return array | |
| 1018 | + */ | |
| 1019 | +function gamipress_bp_members_get_ranks_types() { | |
| 1020 | + | |
| 1021 | + $ranks_types = array(); | |
| 1022 | + | |
| 1023 | + $rank_types_slugs = gamipress_get_rank_types_slugs(); | |
| 1024 | + | |
| 1025 | + $ranks_types_to_show = gamipress_bp_get_option( 'members_ranks_types', array() ); | |
| 1026 | + | |
| 1027 | + foreach( $ranks_types_to_show as $rank_type_slug ) { | |
| 1028 | + | |
| 1029 | + // Skip if not registered | |
| 1030 | + if( ! in_array( $rank_type_slug, $rank_types_slugs ) ) { | |
| 1031 | + continue; | |
| 1032 | + } | |
| 1033 | + | |
| 1034 | + $ranks_types[] = $rank_type_slug; | |
| 1035 | + } | |
| 1036 | + | |
| 1037 | + return $ranks_types; | |
| 1038 | + | |
| 1039 | +} | |
| 1040 | + | |
| 1041 | +/** | |
| 1042 | + * Helper function to retrieve the rank types configured on profile tabs | |
| 1043 | + * | |
| 1044 | + * @since 1.1.1 | |
| 1045 | + * | |
| 1046 | + * @return array | |
| 1047 | + */ | |
| 1048 | +function gamipress_bp_tab_get_ranks_types() { | |
| 1049 | + | |
| 1050 | + $ranks_types = array(); | |
| 1051 | + | |
| 1052 | + $rank_types_slugs = gamipress_get_rank_types_slugs(); | |
| 1053 | + | |
| 1054 | + $ranks_types_to_show = gamipress_bp_get_option( 'tab_ranks_types', array() ); | |
| 1055 | + | |
| 1056 | + foreach( $ranks_types_to_show as $rank_type_slug ) { | |
| 1057 | + | |
| 1058 | + // Skip if not registered | |
| 1059 | + if( ! in_array( $rank_type_slug, $rank_types_slugs ) ) { | |
| 1060 | + continue; | |
| 1061 | + } | |
| 1062 | + | |
| 1063 | + $ranks_types[] = $rank_type_slug; | |
| 1064 | + } | |
| 1065 | + | |
| 1066 | + return $ranks_types; | |
| 1067 | + | |
| 1068 | +} | |
| 1069 | + | |
| 1070 | +/** | |
| 1071 | + * Display the GamiPress email settings under the member Account > Email Preferences | |
| 1072 | + * | |
| 1073 | + * @since 1.5.2 | |
| 1074 | + */ | |
| 1075 | +function gamipress_bp_notification_settings() { | |
| 1076 | + | |
| 1077 | + if( ! (bool) gamipress_bp_get_option( 'email_settings', false ) ) { | |
| 1078 | + return; | |
| 1079 | + } | |
| 1080 | + | |
| 1081 | + $groups = ( (bool) gamipress_bp_get_option( 'email_groups', false ) ? 'yes' : 'no' ); | |
| 1082 | + $types = ( (bool) gamipress_bp_get_option( 'email_types', false ) ? 'yes' : 'no' ); | |
| 1083 | + | |
| 1084 | + echo do_shortcode( '[gamipress_email_settings current_user="no" user_id="' . bp_displayed_user_id() . '" groups="' . $groups . '" types="' . $types . '"]' ); | |
| 1085 | +} | |
| 1086 | +add_action( 'bp_notification_settings', 'gamipress_bp_notification_settings', 999 ); | |