| @@ -1,0 +1,730 @@ | ||
| 1 | +<?php | |
| 2 | +/** | |
| 3 | + * User Profile | |
| 4 | + * | |
| 5 | + * @package GamiPress\PeepSo\User_Profile | |
| 6 | + * @since 1.0.0 | |
| 7 | + */ | |
| 8 | +// Exit if accessed directly | |
| 9 | +if( !defined( 'ABSPATH' ) ) exit; | |
| 10 | + | |
| 11 | +function gamipress_peepso_load_profile_actions() { | |
| 12 | + | |
| 13 | + // Bail if we are at admin area | |
| 14 | + if( is_admin() ) return; | |
| 15 | + | |
| 16 | + $points_tab_title = gamipress_peepso_get_option( 'points_tab_title', __( 'Points', 'gamipress' ) ); | |
| 17 | + $points_tab_slug = gamipress_peepso_get_option( 'points_tab_slug', '' ); | |
| 18 | + | |
| 19 | + // If empty slug generate it from the title | |
| 20 | + if( empty( $points_tab_slug ) ) { | |
| 21 | + $points_tab_slug = sanitize_title( $points_tab_title ); | |
| 22 | + } | |
| 23 | + | |
| 24 | + // Register the points segment action | |
| 25 | + add_action( "peepso_profile_segment_{$points_tab_slug}", 'gamipress_peepso_profile_segment' ); | |
| 26 | + | |
| 27 | + $achievements_tab_title = gamipress_peepso_get_option( 'achievements_tab_title', __( 'Achievements', 'gamipress' ) ); | |
| 28 | + $achievements_tab_slug = gamipress_peepso_get_option( 'achievements_tab_slug', '' ); | |
| 29 | + | |
| 30 | + // If empty slug generate it from the title | |
| 31 | + if( empty( $achievements_tab_slug ) ) { | |
| 32 | + $achievements_tab_slug = sanitize_title( $achievements_tab_title ); | |
| 33 | + } | |
| 34 | + | |
| 35 | + // Register the achievements segment action | |
| 36 | + add_action( "peepso_profile_segment_{$achievements_tab_slug}", 'gamipress_peepso_profile_segment' ); | |
| 37 | + | |
| 38 | + $ranks_tab_title = gamipress_peepso_get_option( 'ranks_tab_title', __( 'Ranks', 'gamipress' ) ); | |
| 39 | + $ranks_tab_slug = gamipress_peepso_get_option( 'ranks_tab_slug', '' ); | |
| 40 | + | |
| 41 | + // If empty slug generate it from the title | |
| 42 | + if( empty( $ranks_tab_slug ) ) { | |
| 43 | + $ranks_tab_slug = sanitize_title( $ranks_tab_title ); | |
| 44 | + } | |
| 45 | + | |
| 46 | + // Register the ranks segment action | |
| 47 | + add_action( "peepso_profile_segment_{$ranks_tab_slug}", 'gamipress_peepso_profile_segment' ); | |
| 48 | + | |
| 49 | +} | |
| 50 | +add_filter( 'init', 'gamipress_peepso_load_profile_actions' ); | |
| 51 | + | |
| 52 | +/** | |
| 53 | + * Add new user navigation profile links | |
| 54 | + * | |
| 55 | + * @since 1.0.0 | |
| 56 | + * | |
| 57 | + * @param array $links Array of current navigation links | |
| 58 | + * | |
| 59 | + * @return array | |
| 60 | + */ | |
| 61 | +function gamipress_peepso_navigation_profile( $links ) { | |
| 62 | + | |
| 63 | + // Points tab | |
| 64 | + $points_placement = gamipress_peepso_get_option( 'points_placement', '' ); | |
| 65 | + | |
| 66 | + if( in_array( $points_placement, array( 'tab', 'both' ) ) ) { | |
| 67 | + | |
| 68 | + $points_tab_title = gamipress_peepso_get_option( 'points_tab_title', __( 'Points', 'gamipress' ) ); | |
| 69 | + $points_tab_slug = gamipress_peepso_get_option( 'points_tab_slug', '' ); | |
| 70 | + | |
| 71 | + // If empty slug generate it from the title | |
| 72 | + if( empty( $points_tab_slug ) ) { | |
| 73 | + $points_tab_slug = sanitize_title( $points_tab_title ); | |
| 74 | + } | |
| 75 | + | |
| 76 | + $links['points'] = array( | |
| 77 | + 'href' => $points_tab_slug, | |
| 78 | + 'label'=> $points_tab_title, | |
| 79 | + 'icon' => gamipress_peepso_get_option( 'points_tab_icon', 'ps-icon-star' ) | |
| 80 | + ); | |
| 81 | + | |
| 82 | + } | |
| 83 | + | |
| 84 | + // Achievements tab | |
| 85 | + $achievements_placement = gamipress_peepso_get_option( 'achievements_placement', '' ); | |
| 86 | + | |
| 87 | + if( in_array( $achievements_placement, array( 'tab', 'both' ) ) ) { | |
| 88 | + | |
| 89 | + $achievements_tab_title = gamipress_peepso_get_option( 'achievements_tab_title', __( 'Achievements', 'gamipress' ) ); | |
| 90 | + $achievements_tab_slug = gamipress_peepso_get_option( 'achievements_tab_slug', '' ); | |
| 91 | + | |
| 92 | + // If empty slug generate it from the title | |
| 93 | + if( empty( $achievements_tab_slug ) ) { | |
| 94 | + $achievements_tab_slug = sanitize_title( $achievements_tab_title ); | |
| 95 | + } | |
| 96 | + | |
| 97 | + $links['achievements'] = array( | |
| 98 | + 'href' => $achievements_tab_slug, | |
| 99 | + 'label'=> $achievements_tab_title, | |
| 100 | + 'icon' => gamipress_peepso_get_option( 'achievements_tab_icon', 'ps-icon-certificate' ) | |
| 101 | + ); | |
| 102 | + | |
| 103 | + } | |
| 104 | + | |
| 105 | + // Ranks tab | |
| 106 | + $ranks_placement = gamipress_peepso_get_option( 'ranks_placement', '' ); | |
| 107 | + | |
| 108 | + if( in_array( $ranks_placement, array( 'tab', 'both' ) ) ) { | |
| 109 | + | |
| 110 | + $ranks_tab_title = gamipress_peepso_get_option( 'ranks_tab_title', __( 'Ranks', 'gamipress' ) ); | |
| 111 | + $ranks_tab_slug = gamipress_peepso_get_option( 'ranks_tab_slug', '' ); | |
| 112 | + | |
| 113 | + // If empty slug generate it from the title | |
| 114 | + if( empty( $ranks_tab_slug ) ) { | |
| 115 | + $ranks_tab_slug = sanitize_title( $ranks_tab_title ); | |
| 116 | + } | |
| 117 | + | |
| 118 | + $links['ranks'] = array( | |
| 119 | + 'href' => $ranks_tab_slug, | |
| 120 | + 'label'=> $ranks_tab_title, | |
| 121 | + 'icon' => gamipress_peepso_get_option( 'ranks_tab_icon', 'ps-icon-award' ) | |
| 122 | + ); | |
| 123 | + | |
| 124 | + } | |
| 125 | + | |
| 126 | + return $links; | |
| 127 | + | |
| 128 | +} | |
| 129 | +add_filter( 'peepso_navigation_profile', 'gamipress_peepso_navigation_profile' ); | |
| 130 | + | |
| 131 | +/** | |
| 132 | + * Common render in user profile | |
| 133 | + * | |
| 134 | + * @since 1.0.0 | |
| 135 | + */ | |
| 136 | +function gamipress_peepso_profile_segment() { | |
| 137 | + | |
| 138 | + $current_filter = gamipress_peepso_profile_current_filter(); | |
| 139 | + | |
| 140 | + $profile = PeepSoProfileShortcode::get_instance(); | |
| 141 | + $user_id = PeepSoUrlSegments::get_view_id( $profile->get_view_user_id() ); | |
| 142 | + | |
| 143 | + ?> | |
| 144 | + | |
| 145 | + <div class="peepso ps-page-profile ps-page-gamipress"> | |
| 146 | + | |
| 147 | + <?php PeepSoTemplate::exec_template('general','navbar'); ?> | |
| 148 | + | |
| 149 | + <?php PeepSoTemplate::exec_template('profile', 'focus', array('current'=>'badges')); ?> | |
| 150 | + | |
| 151 | + <section id="mainbody" class="ps-page-unstyled"> | |
| 152 | + | |
| 153 | + <section id="component" role="article" class="ps-clearfix"> | |
| 154 | + | |
| 155 | + <?php do_action( "gamipress_{$current_filter}_content", $user_id ); ?> | |
| 156 | + | |
| 157 | + </section><!--end component--> | |
| 158 | + | |
| 159 | + </section><!--end mainbody--> | |
| 160 | + | |
| 161 | + </div><!--end row--> | |
| 162 | + <?php PeepSoTemplate::exec_template('activity', 'dialogs'); ?> | |
| 163 | + | |
| 164 | + <?php | |
| 165 | + | |
| 166 | +} | |
| 167 | + | |
| 168 | +/** | |
| 169 | + * Return the user custom segment slug as a common segment slug | |
| 170 | + * | |
| 171 | + * @since 1.0.4 | |
| 172 | + * | |
| 173 | + * @return string | |
| 174 | + */ | |
| 175 | +function gamipress_peepso_profile_current_filter() { | |
| 176 | + | |
| 177 | + $current_filter = current_filter(); | |
| 178 | + | |
| 179 | + // Check if is the points tab | |
| 180 | + $points_tab_title = gamipress_peepso_get_option( 'points_tab_title', __( 'Points', 'gamipress' ) ); | |
| 181 | + $points_tab_slug = gamipress_peepso_get_option( 'points_tab_slug', '' ); | |
| 182 | + | |
| 183 | + // If empty slug generate it from the title | |
| 184 | + if( empty( $points_tab_slug ) ) { | |
| 185 | + $points_tab_slug = sanitize_title( $points_tab_title ); | |
| 186 | + } | |
| 187 | + | |
| 188 | + if( $current_filter === "peepso_profile_segment_{$points_tab_slug}" ) { | |
| 189 | + return 'peepso_profile_segment_points'; | |
| 190 | + } | |
| 191 | + | |
| 192 | + // Check if is the achievements tab | |
| 193 | + $achievements_tab_title = gamipress_peepso_get_option( 'achievements_tab_title', __( 'Achievements', 'gamipress' ) ); | |
| 194 | + $achievements_tab_slug = gamipress_peepso_get_option( 'achievements_tab_slug', '' ); | |
| 195 | + | |
| 196 | + // If empty slug generate it from the title | |
| 197 | + if( empty( $achievements_tab_slug ) ) { | |
| 198 | + $achievements_tab_slug = sanitize_title( $achievements_tab_title ); | |
| 199 | + } | |
| 200 | + | |
| 201 | + if( $current_filter === "peepso_profile_segment_{$achievements_tab_slug}" ) { | |
| 202 | + return 'peepso_profile_segment_achievements'; | |
| 203 | + } | |
| 204 | + | |
| 205 | + // Check if is the ranks tab | |
| 206 | + $ranks_tab_title = gamipress_peepso_get_option( 'ranks_tab_title', __( 'Ranks', 'gamipress' ) ); | |
| 207 | + $ranks_tab_slug = gamipress_peepso_get_option( 'ranks_tab_slug', '' ); | |
| 208 | + | |
| 209 | + // If empty slug generate it from the title | |
| 210 | + if( empty( $ranks_tab_slug ) ) { | |
| 211 | + $ranks_tab_slug = sanitize_title( $ranks_tab_title ); | |
| 212 | + } | |
| 213 | + | |
| 214 | + if( $current_filter === "peepso_profile_segment_{$ranks_tab_slug}" ) { | |
| 215 | + return 'peepso_profile_segment_ranks'; | |
| 216 | + } | |
| 217 | + | |
| 218 | + return $current_filter; | |
| 219 | + | |
| 220 | +} | |
| 221 | + | |
| 222 | +/** | |
| 223 | + * Render points in user profile | |
| 224 | + * | |
| 225 | + * @since 1.0.0 | |
| 226 | + * | |
| 227 | + * @param int $user_id Displayed user ID | |
| 228 | + */ | |
| 229 | +function gamipress_peepso_profile_points_content( $user_id ) { | |
| 230 | + | |
| 231 | + $points_types_to_show = gamipress_peepso_profile_get_points_types(); | |
| 232 | + | |
| 233 | + if ( empty( $points_types_to_show ) ) { | |
| 234 | + return; | |
| 235 | + } | |
| 236 | + | |
| 237 | + echo gamipress_points_shortcode( array( | |
| 238 | + 'type' => implode( ',', $points_types_to_show ), | |
| 239 | + 'current_user' => 'no', | |
| 240 | + 'user_id' => $user_id, | |
| 241 | + 'wpms' => (bool) gamipress_get_option( 'ms_show_all_achievements', false ) ? 'yes' : 'no', | |
| 242 | + ) ); | |
| 243 | + | |
| 244 | +} | |
| 245 | +add_action( 'gamipress_peepso_profile_segment_points_content', 'gamipress_peepso_profile_points_content' ); | |
| 246 | + | |
| 247 | +/** | |
| 248 | + * Render achievements in user profile | |
| 249 | + * | |
| 250 | + * @since 1.0.0 | |
| 251 | + * | |
| 252 | + * @param int $user_id Displayed user ID | |
| 253 | + */ | |
| 254 | +function gamipress_peepso_profile_achievements_content( $user_id ) { | |
| 255 | + | |
| 256 | + $achievements_types_to_show = gamipress_peepso_profile_get_achievements_types(); | |
| 257 | + | |
| 258 | + if ( empty( $achievements_types_to_show ) ) { | |
| 259 | + return; | |
| 260 | + } | |
| 261 | + | |
| 262 | + $prefix = 'profile_achievements_'; | |
| 263 | + | |
| 264 | + // Setup achievement atts | |
| 265 | + $achievement_atts = array(); | |
| 266 | + | |
| 267 | + // Loop achievement shortcode fields to pass to the shortcode call | |
| 268 | + foreach( GamiPress()->shortcodes['gamipress_achievement']->fields as $field_id => $field_args ) { | |
| 269 | + | |
| 270 | + if( $field_id === 'id' ) { | |
| 271 | + continue; | |
| 272 | + } | |
| 273 | + | |
| 274 | + if( $field_args['type'] === 'checkbox' ) { | |
| 275 | + $achievement_atts[$field_id] = ( (bool) gamipress_peepso_get_option( $prefix . $field_id, false ) ? 'yes' : 'no' ); | |
| 276 | + } else { | |
| 277 | + $achievement_atts[$field_id] = gamipress_peepso_get_option( $prefix . $field_id, ( isset( $field_args['default'] ) ? $field_args['default'] : '' ) ); | |
| 278 | + } | |
| 279 | + | |
| 280 | + } | |
| 281 | + | |
| 282 | + echo gamipress_achievements_shortcode( array_merge( array( | |
| 283 | + 'type' => implode( ',', $achievements_types_to_show ), | |
| 284 | + 'columns' => gamipress_peepso_get_option( $prefix . 'columns', '1' ), | |
| 285 | + 'filter' => 'no', | |
| 286 | + 'filter_value' => 'completed', | |
| 287 | + 'search' => 'no', | |
| 288 | + 'current_user' => 'no', | |
| 289 | + 'user_id' => $user_id, | |
| 290 | + 'wpms' => (bool) gamipress_get_option( 'ms_show_all_achievements', false ) ? 'yes' : 'no', | |
| 291 | + 'limit' => gamipress_peepso_get_option( $prefix . 'limit', '10' ), | |
| 292 | + 'orderby' => gamipress_peepso_get_option( $prefix . 'orderby', 'menu_order' ), | |
| 293 | + 'order' => gamipress_peepso_get_option( $prefix . 'order', 'ASC' ), | |
| 294 | + 'include' => '', | |
| 295 | + 'exclude' => '', | |
| 296 | + ), $achievement_atts ) ); | |
| 297 | + | |
| 298 | +} | |
| 299 | +add_action( 'gamipress_peepso_profile_segment_achievements_content', 'gamipress_peepso_profile_achievements_content' ); | |
| 300 | + | |
| 301 | +/** | |
| 302 | + * Render ranks in user profile | |
| 303 | + * | |
| 304 | + * @since 1.0.0 | |
| 305 | + * | |
| 306 | + * @param int $user_id Displayed user ID | |
| 307 | + */ | |
| 308 | +function gamipress_peepso_profile_ranks_content( $user_id ) { | |
| 309 | + | |
| 310 | + $ranks_types_to_show = gamipress_peepso_profile_get_ranks_types(); | |
| 311 | + | |
| 312 | + if ( empty( $ranks_types_to_show ) ) { | |
| 313 | + return; | |
| 314 | + } | |
| 315 | + | |
| 316 | + $prefix = 'profile_ranks_'; | |
| 317 | + | |
| 318 | + // Setup rank atts | |
| 319 | + $rank_atts = array(); | |
| 320 | + | |
| 321 | + // Loop rank shortcode fields to pass to the shortcode call | |
| 322 | + foreach( GamiPress()->shortcodes['gamipress_rank']->fields as $field_id => $field_args ) { | |
| 323 | + | |
| 324 | + if( $field_id === 'id' ) { | |
| 325 | + continue; | |
| 326 | + } | |
| 327 | + | |
| 328 | + if( $field_args['type'] === 'checkbox' ) { | |
| 329 | + $rank_atts[$field_id] = ( (bool) gamipress_peepso_get_option( $prefix . $field_id, false ) ? 'yes' : 'no' ); | |
| 330 | + } else { | |
| 331 | + $rank_atts[$field_id] = gamipress_peepso_get_option( $prefix . $field_id, ( isset( $field_args['default'] ) ? $field_args['default'] : '' ) ); | |
| 332 | + } | |
| 333 | + | |
| 334 | + } | |
| 335 | + | |
| 336 | + echo gamipress_ranks_shortcode( array_merge( array( | |
| 337 | + 'type' => implode( ',', $ranks_types_to_show ), | |
| 338 | + 'columns' => gamipress_peepso_get_option( $prefix . 'columns', '1' ), | |
| 339 | + 'current_user' => 'no', | |
| 340 | + 'user_id' => $user_id, | |
| 341 | + 'wpms' => (bool) gamipress_get_option( 'ms_show_all_achievements', false ) ? 'yes' : 'no', | |
| 342 | + 'orderby' => gamipress_peepso_get_option( $prefix . 'orderby', 'priority' ), | |
| 343 | + 'order' => gamipress_peepso_get_option( $prefix . 'order', 'DESC' ), | |
| 344 | + 'include' => '', | |
| 345 | + 'exclude' => '', | |
| 346 | + ), $rank_atts ) ); | |
| 347 | + | |
| 348 | +} | |
| 349 | +add_action( 'gamipress_peepso_profile_segment_ranks_content', 'gamipress_peepso_profile_ranks_content' ); | |
| 350 | + | |
| 351 | +/** | |
| 352 | + * Display user information at top | |
| 353 | + * | |
| 354 | + * @since 1.0.0 | |
| 355 | + * | |
| 356 | + * @param int $user_id Displayed user ID | |
| 357 | + */ | |
| 358 | +function gamipress_peepso_after_render_user_name( $user_id ) { | |
| 359 | + | |
| 360 | + /* ------------------------------- | |
| 361 | + * Points | |
| 362 | + ------------------------------- */ | |
| 363 | + | |
| 364 | + $points_placement = gamipress_peepso_get_option( 'points_placement', '' ); | |
| 365 | + | |
| 366 | + if( $points_placement === 'top' || $points_placement === 'both' ) { | |
| 367 | + | |
| 368 | + // Setup points types vars | |
| 369 | + $points_types = gamipress_get_points_types(); | |
| 370 | + $points_types_slugs = gamipress_get_points_types_slugs(); | |
| 371 | + | |
| 372 | + // Get points display settings | |
| 373 | + $points_types_to_show = gamipress_peepso_profile_get_points_types(); | |
| 374 | + $points_types_thumbnail = (bool) gamipress_peepso_get_option( 'profile_points_types_top_thumbnail', false ); | |
| 375 | + $points_types_thumbnail_size = (int) gamipress_peepso_get_option( 'profile_points_types_top_thumbnail_size', 25 ); | |
| 376 | + $points_types_label = (bool) gamipress_peepso_get_option( 'profile_points_types_top_label', false ); | |
| 377 | + | |
| 378 | + // Parse thumbnail size | |
| 379 | + if( $points_types_thumbnail_size > 0 ) { | |
| 380 | + $points_types_thumbnail_size = array( $points_types_thumbnail_size, $points_types_thumbnail_size ); | |
| 381 | + } else { | |
| 382 | + $points_types_thumbnail_size = 'gamipress-points'; | |
| 383 | + } | |
| 384 | + | |
| 385 | + if( ! empty( $points_types_to_show ) ) : ?> | |
| 386 | + | |
| 387 | + <div class="gamipress-peepso-points"> | |
| 388 | + | |
| 389 | + <?php foreach( $points_types_to_show as $points_type_to_show ) : | |
| 390 | + | |
| 391 | + // If points type not registered, skip | |
| 392 | + if( ! in_array( $points_type_to_show, $points_types_slugs ) ) | |
| 393 | + continue; | |
| 394 | + | |
| 395 | + $points_type = $points_types[$points_type_to_show]; | |
| 396 | + $user_points = gamipress_get_user_points( $user_id, $points_type_to_show ); ?> | |
| 397 | + | |
| 398 | + <div class="gamipress-peepso-points-type gamipress-peepso-<?php echo $points_type_to_show; ?>"> | |
| 399 | + | |
| 400 | + <?php // The points thumbnail ?> | |
| 401 | + <?php if( $points_types_thumbnail ) : ?> | |
| 402 | + | |
| 403 | + <span class="gamipress-peepso-points-thumbnail gamipress-peepso-<?php echo $points_type_to_show; ?>-thumbnail"> | |
| 404 | + <?php echo gamipress_get_points_type_thumbnail( $points_type_to_show, $points_types_thumbnail_size ); ?> | |
| 405 | + </span> | |
| 406 | + | |
| 407 | + <?php endif; ?> | |
| 408 | + | |
| 409 | + <?php // The user points amount ?> | |
| 410 | + <span class="gamipress-peepso-user-points gamipress-peepso-user-<?php echo $points_type_to_show; ?>"> | |
| 411 | + <?php echo gamipress_format_points( $user_points, $points_type_to_show ); ?> | |
| 412 | + </span> | |
| 413 | + | |
| 414 | + <?php // The points label ?> | |
| 415 | + <?php if( $points_types_label ) : ?> | |
| 416 | + | |
| 417 | + <span class="gamipress-peepso-points-label gamipress-peepso-<?php echo $points_type_to_show; ?>-label"> | |
| 418 | + <?php echo _n( $points_type['singular_name'], $points_type['plural_name'], $user_points ); ?> | |
| 419 | + </span> | |
| 420 | + | |
| 421 | + <?php endif; ?> | |
| 422 | + | |
| 423 | + </div> | |
| 424 | + | |
| 425 | + <?php endforeach; ?> | |
| 426 | + </div> | |
| 427 | + <?php endif; | |
| 428 | + | |
| 429 | + } | |
| 430 | + | |
| 431 | + /* ------------------------------- | |
| 432 | + * Achievements | |
| 433 | + ------------------------------- */ | |
| 434 | + | |
| 435 | + $achievements_placement = gamipress_peepso_get_option( 'achievements_placement', '' ); | |
| 436 | + | |
| 437 | + if( $achievements_placement === 'top' || $achievements_placement === 'both' ) { | |
| 438 | + | |
| 439 | + // Setup achievement types vars | |
| 440 | + $achievement_types = gamipress_get_achievement_types(); | |
| 441 | + $achievement_types_slugs = gamipress_get_achievement_types_slugs(); | |
| 442 | + | |
| 443 | + // Get achievements display settings | |
| 444 | + $achievement_types_to_show = gamipress_peepso_profile_get_achievements_types(); | |
| 445 | + $achievement_types_thumbnail = (bool) gamipress_peepso_get_option( 'profile_achievements_top_thumbnail', false ); | |
| 446 | + $achievement_types_thumbnail_size = (int) gamipress_peepso_get_option( 'profile_achievements_top_thumbnail_size', 25 ); | |
| 447 | + $achievement_types_title = (bool) gamipress_peepso_get_option( 'profile_achievements_top_title', false ); | |
| 448 | + $achievement_types_link = (bool) gamipress_peepso_get_option( 'profile_achievements_top_link', false ); | |
| 449 | + $achievement_types_label = (bool) gamipress_peepso_get_option( 'profile_achievements_top_label', false ); | |
| 450 | + $achievement_types_limit = (int) gamipress_peepso_get_option( 'profile_achievements_top_limit', 10 ); | |
| 451 | + | |
| 452 | + // Parse thumbnail size | |
| 453 | + if( $achievement_types_thumbnail_size > 0 ) { | |
| 454 | + $achievement_types_thumbnail_size = array( $achievement_types_thumbnail_size, $achievement_types_thumbnail_size ); | |
| 455 | + } else { | |
| 456 | + $achievement_types_thumbnail_size = 'gamipress-achievement'; | |
| 457 | + } | |
| 458 | + | |
| 459 | + if( ! empty( $achievement_types_to_show ) ) : ?> | |
| 460 | + | |
| 461 | + <div class="gamipress-peepso-achievements"> | |
| 462 | + | |
| 463 | + <?php foreach( $achievement_types_to_show as $achievement_type_to_show ) : | |
| 464 | + | |
| 465 | + // If achievements type not registered, skip | |
| 466 | + if( ! in_array( $achievement_type_to_show, $achievement_types_slugs ) ) | |
| 467 | + continue; | |
| 468 | + | |
| 469 | + $achievement_type = $achievement_types[$achievement_type_to_show]; | |
| 470 | + $user_achievements = gamipress_get_user_achievements( array( | |
| 471 | + 'user_id' => $user_id, | |
| 472 | + 'achievement_type' => $achievement_type_to_show, | |
| 473 | + 'groupby' => 'achievement_id', | |
| 474 | + 'limit' => $achievement_types_limit | |
| 475 | + ) ); | |
| 476 | + | |
| 477 | + // If user has not earned any achievements of this type, skip | |
| 478 | + if( empty( $user_achievements ) ) { | |
| 479 | + continue; | |
| 480 | + } ?> | |
| 481 | + | |
| 482 | + <div class="gamipress-peepso-achievement gamipress-peepso-<?php echo $achievement_type_to_show; ?>"> | |
| 483 | + | |
| 484 | + <?php // The achievement type label ?> | |
| 485 | + <?php if( $achievement_types_label ) : ?> | |
| 486 | + <span class="gamipress-peepso-achievement-type-label gamipress-peepso-<?php echo $achievement_type_to_show; ?>-label"> | |
| 487 | + <?php echo $achievement_type['plural_name']; ?>: | |
| 488 | + </span> | |
| 489 | + <?php endif; ?> | |
| 490 | + | |
| 491 | + <?php // Lets to get just the achievement thumbnail and title | |
| 492 | + foreach( $user_achievements as $user_achievement ) : ?> | |
| 493 | + | |
| 494 | + <?php // The achievement thumbnail ?> | |
| 495 | + <?php if( $achievement_types_thumbnail ) : ?> | |
| 496 | + | |
| 497 | + <?php // The achievement link ?> | |
| 498 | + <?php if( $achievement_types_link ) : ?> | |
| 499 | + | |
| 500 | + <a href="<?php echo get_permalink( $user_achievement->ID ); ?>" title="<?php echo get_the_title( $user_achievement->ID ); ?>" class="gamipress-peepso-achievement-thumbnail gamipress-peepso-<?php echo $achievement_type_to_show; ?>-thumbnail"> | |
| 501 | + <?php echo gamipress_get_achievement_post_thumbnail( $user_achievement->ID, $achievement_types_thumbnail_size ); ?> | |
| 502 | + </a> | |
| 503 | + | |
| 504 | + <?php else : ?> | |
| 505 | + | |
| 506 | + <span title="<?php echo get_the_title( $user_achievement->ID ); ?>" class="gamipress-peepso-achievement-thumbnail gamipress-peepso-<?php echo $achievement_type_to_show; ?>-thumbnail"> | |
| 507 | + <?php echo gamipress_get_achievement_post_thumbnail( $user_achievement->ID, $achievement_types_thumbnail_size ); ?> | |
| 508 | + </span> | |
| 509 | + | |
| 510 | + <?php endif; ?> | |
| 511 | + | |
| 512 | + <?php endif; ?> | |
| 513 | + | |
| 514 | + <?php // The achievement title ?> | |
| 515 | + <?php if( $achievement_types_title ) : ?> | |
| 516 | + | |
| 517 | + <?php // The achievement link ?> | |
| 518 | + <?php if( $achievement_types_link ) : ?> | |
| 519 | + | |
| 520 | + <a href="<?php echo get_permalink( $user_achievement->ID ); ?>" title="<?php echo get_the_title( $user_achievement->ID ); ?>" class="gamipress-peepso-achievement-title gamipress-peepso-<?php echo $achievement_type_to_show; ?>-title"> | |
| 521 | + <?php echo get_the_title( $user_achievement->ID ); ?> | |
| 522 | + </a> | |
| 523 | + | |
| 524 | + <?php else : ?> | |
| 525 | + | |
| 526 | + <span class="gamipress-peepso-achievement-title gamipress-peepso-<?php echo $achievement_type_to_show; ?>-title"> | |
| 527 | + <?php echo get_the_title( $user_achievement->ID ); ?> | |
| 528 | + </span> | |
| 529 | + | |
| 530 | + <?php endif; ?> | |
| 531 | + | |
| 532 | + <?php endif; ?> | |
| 533 | + | |
| 534 | + <?php endforeach; ?> | |
| 535 | + | |
| 536 | + </div> | |
| 537 | + | |
| 538 | + <?php endforeach; ?> | |
| 539 | + | |
| 540 | + </div> | |
| 541 | + | |
| 542 | + <?php endif; | |
| 543 | + | |
| 544 | + } | |
| 545 | + | |
| 546 | + /* ------------------------------- | |
| 547 | + * Ranks | |
| 548 | + ------------------------------- */ | |
| 549 | + | |
| 550 | + $ranks_placement = gamipress_peepso_get_option( 'ranks_placement', '' ); | |
| 551 | + | |
| 552 | + if( $ranks_placement === 'top' || $ranks_placement === 'both' ) { | |
| 553 | + | |
| 554 | + // Setup rank types vars | |
| 555 | + $rank_types = gamipress_get_rank_types(); | |
| 556 | + $rank_types_slugs = gamipress_get_rank_types_slugs(); | |
| 557 | + | |
| 558 | + // Get ranks display settings | |
| 559 | + $rank_types_to_show = gamipress_peepso_profile_get_ranks_types(); | |
| 560 | + $rank_types_thumbnail = (bool) gamipress_peepso_get_option( 'profile_ranks_top_thumbnail', false ); | |
| 561 | + $rank_types_thumbnail_size = (int) gamipress_peepso_get_option( 'profile_ranks_top_thumbnail_size', 25 ); | |
| 562 | + $rank_types_title = (bool) gamipress_peepso_get_option( 'profile_ranks_top_title', false ); | |
| 563 | + $rank_types_link = (bool) gamipress_peepso_get_option( 'profile_ranks_top_link', false ); | |
| 564 | + $rank_types_label = (bool) gamipress_peepso_get_option( 'profile_ranks_top_label', false ); | |
| 565 | + | |
| 566 | + // Parse thumbnail size | |
| 567 | + if( $rank_types_thumbnail_size > 0 ) { | |
| 568 | + $rank_types_thumbnail_size = array( $rank_types_thumbnail_size, $rank_types_thumbnail_size ); | |
| 569 | + } else { | |
| 570 | + $rank_types_thumbnail_size = 'gamipress-rank'; | |
| 571 | + } | |
| 572 | + | |
| 573 | + if( ! empty( $rank_types_to_show ) ) : ?> | |
| 574 | + | |
| 575 | + <div class="gamipress-peepso-ranks"> | |
| 576 | + | |
| 577 | + <?php foreach( $rank_types_to_show as $rank_type_to_show ) : | |
| 578 | + | |
| 579 | + // If rank type not registered, skip | |
| 580 | + if( ! in_array( $rank_type_to_show, $rank_types_slugs ) ) | |
| 581 | + continue; | |
| 582 | + | |
| 583 | + $rank_type = $rank_types[$rank_type_to_show]; | |
| 584 | + $user_rank = gamipress_get_user_rank( $user_id, $rank_type_to_show ); ?> | |
| 585 | + | |
| 586 | + <div class="gamipress-peepso-rank gamipress-peepso-<?php echo $rank_type_to_show; ?>"> | |
| 587 | + | |
| 588 | + <?php // The rank type label ?> | |
| 589 | + <?php if( $rank_types_label ) : ?> | |
| 590 | + <span class="gamipress-peepso-rank-label gamipress-peepso-<?php echo $rank_type_to_show; ?>-label"> | |
| 591 | + <?php echo $rank_type['singular_name']; ?>: | |
| 592 | + </span> | |
| 593 | + <?php endif; ?> | |
| 594 | + | |
| 595 | + <?php // The rank thumbnail ?> | |
| 596 | + <?php if( $rank_types_thumbnail ) : ?> | |
| 597 | + | |
| 598 | + <?php // The rank link ?> | |
| 599 | + <?php if( $rank_types_link ) : ?> | |
| 600 | + | |
| 601 | + <a href="<?php echo get_permalink( $user_rank->ID ); ?>" title="<?php echo $user_rank->post_title; ?>" class="gamipress-peepso-rank-thumbnail gamipress-peepso-<?php echo $rank_type_to_show; ?>-thumbnail"> | |
| 602 | + <?php echo gamipress_get_rank_post_thumbnail( $user_rank->ID, $rank_types_thumbnail_size ); ?> | |
| 603 | + </a> | |
| 604 | + | |
| 605 | + <?php else : ?> | |
| 606 | + | |
| 607 | + <span title="<?php echo $user_rank->post_title; ?>" class="gamipress-peepso-rank-thumbnail gamipress-peepso-<?php echo $rank_type_to_show; ?>-thumbnail"> | |
| 608 | + <?php echo gamipress_get_rank_post_thumbnail( $user_rank->ID, $rank_types_thumbnail_size ); ?> | |
| 609 | + </span> | |
| 610 | + | |
| 611 | + <?php endif; ?> | |
| 612 | + | |
| 613 | + <?php endif; ?> | |
| 614 | + | |
| 615 | + <?php // The rank title ?> | |
| 616 | + <?php if( $rank_types_title ) : ?> | |
| 617 | + | |
| 618 | + <?php // The rank link ?> | |
| 619 | + <?php if( $rank_types_link ) : ?> | |
| 620 | + | |
| 621 | + <a href="<?php echo get_permalink( $user_rank->ID ); ?>" title="<?php echo $user_rank->post_title; ?>" class="gamipress-peepso-rank-title gamipress-peepso-<?php echo $rank_type_to_show; ?>-title"> | |
| 622 | + <?php echo $user_rank->post_title; ?> | |
| 623 | + </a> | |
| 624 | + | |
| 625 | + <?php else : ?> | |
| 626 | + | |
| 627 | + <span class="gamipress-peepso-rank-title gamipress-peepso-<?php echo $rank_type_to_show; ?>-title"> | |
| 628 | + <?php echo $user_rank->post_title; ?> | |
| 629 | + </span> | |
| 630 | + | |
| 631 | + <?php endif; ?> | |
| 632 | + | |
| 633 | + <?php endif; ?> | |
| 634 | + | |
| 635 | + </div> | |
| 636 | + | |
| 637 | + <?php endforeach; ?> | |
| 638 | + </div> | |
| 639 | + <?php endif; | |
| 640 | + | |
| 641 | + } | |
| 642 | + | |
| 643 | +} | |
| 644 | +add_action( 'peepso_profile_cover_full_after_name', 'gamipress_peepso_after_render_user_name' ); | |
| 645 | + | |
| 646 | +/** | |
| 647 | + * Helper function to retrieve the points types configured at profile screen | |
| 648 | + * | |
| 649 | + * @since 1.0.8 | |
| 650 | + * | |
| 651 | + * @return array | |
| 652 | + */ | |
| 653 | +function gamipress_peepso_profile_get_points_types() { | |
| 654 | + | |
| 655 | + $points_types = array(); | |
| 656 | + | |
| 657 | + $points_types_slugs = gamipress_get_points_types_slugs(); | |
| 658 | + | |
| 659 | + $points_types_to_show = gamipress_peepso_get_option( 'profile_points_types', array() ); | |
| 660 | + | |
| 661 | + foreach( $points_types_to_show as $points_type_slug ) { | |
| 662 | + | |
| 663 | + if( ! in_array( $points_type_slug, $points_types_slugs ) ) { | |
| 664 | + continue; | |
| 665 | + } | |
| 666 | + | |
| 667 | + $points_types[] = $points_type_slug; | |
| 668 | + } | |
| 669 | + | |
| 670 | + return $points_types; | |
| 671 | + | |
| 672 | +} | |
| 673 | + | |
| 674 | +/** | |
| 675 | + * Helper function to retrieve the achievement types configured at profile screen | |
| 676 | + * | |
| 677 | + * @since 1.0.5 | |
| 678 | + * | |
| 679 | + * @return array | |
| 680 | + */ | |
| 681 | +function gamipress_peepso_profile_get_achievements_types() { | |
| 682 | + | |
| 683 | + $achievements_types = array(); | |
| 684 | + | |
| 685 | + $achievement_types_slugs = gamipress_get_achievement_types_slugs(); | |
| 686 | + | |
| 687 | + $achievements_types_to_show = gamipress_peepso_get_option( 'profile_achievements_types', array() ); | |
| 688 | + | |
| 689 | + foreach( $achievements_types_to_show as $achievement_type_slug ) { | |
| 690 | + | |
| 691 | + // Skip if not registered | |
| 692 | + if( ! in_array( $achievement_type_slug, $achievement_types_slugs ) ) { | |
| 693 | + continue; | |
| 694 | + } | |
| 695 | + | |
| 696 | + $achievements_types[] = $achievement_type_slug; | |
| 697 | + } | |
| 698 | + | |
| 699 | + return $achievements_types; | |
| 700 | + | |
| 701 | +} | |
| 702 | + | |
| 703 | +/** | |
| 704 | + * Helper function to retrieve the rank types configured at profile screen | |
| 705 | + * | |
| 706 | + * @since 1.1.1 | |
| 707 | + * | |
| 708 | + * @return array | |
| 709 | + */ | |
| 710 | +function gamipress_peepso_profile_get_ranks_types() { | |
| 711 | + | |
| 712 | + $ranks_types = array(); | |
| 713 | + | |
| 714 | + $rank_types_slugs = gamipress_get_rank_types_slugs(); | |
| 715 | + | |
| 716 | + $ranks_types_to_show = gamipress_peepso_get_option( 'profile_ranks_types', array() ); | |
| 717 | + | |
| 718 | + foreach( $ranks_types_to_show as $rank_type_slug ) { | |
| 719 | + | |
| 720 | + // Skip if not registered | |
| 721 | + if( ! in_array( $rank_type_slug, $rank_types_slugs ) ) { | |
| 722 | + continue; | |
| 723 | + } | |
| 724 | + | |
| 725 | + $ranks_types[] = $rank_type_slug; | |
| 726 | + } | |
| 727 | + | |
| 728 | + return $ranks_types; | |
| 729 | + | |
| 730 | +} | |