| 9 | | // Exit if accessed directly. |
| 10 | | defined( 'ABSPATH' ) || exit; |
| 11 | | |
| 12 | | /** |
| 13 | | * Fire specific hooks at various places of templates |
| 14 | | * |
| 15 | | * @since 1.0.0 |
| 16 | | * |
| 17 | | * @param array $pieces The list of terms of the hook to join. |
| 18 | | */ |
| 19 | | function bp_nouveau_hook( $pieces = array() ) { |
| 20 | | if ( ! $pieces ) { |
| 21 | | return; |
| 22 | | } |
| 23 | | |
| 24 | | $bp_prefix = reset( $pieces ); |
| 25 | | if ( 'bp' !== $bp_prefix ) { |
| 26 | | array_unshift( $pieces, 'bp' ); |
| 27 | | } |
| 28 | | |
| 29 | | $hook = join( '_', $pieces ); |
| 30 | | |
| 31 | | do_action( $hook ); |
| 32 | | } |
| 33 | | |
| 34 | | /** |
| 35 | | * Fire plugin hooks in the plugins.php template (Groups and Members single items) |
| 36 | | * |
| 37 | | * @since 1.0.0 |
| 38 | | * |
| 39 | | * @param string The suffix of the hook. |
| 40 | | */ |
| 41 | | function bp_nouveau_plugin_hook( $suffix = '' ) { |
| 42 | | if ( ! $suffix ) { |
| 43 | | return; |
| 44 | | } |
| 45 | | |
| 46 | | bp_nouveau_hook( array( |
| 47 | | 'bp', |
| 48 | | 'template', |
| 49 | | $suffix, |
| 50 | | ) ); |
| 51 | | } |
| 52 | | |
| 53 | | /** |
| 54 | | * Fire friend hooks |
| 55 | | * |
| 56 | | * @todo Move this into bp-nouveau/includes/friends/template-tags.php |
| 57 | | * once we'll need other friends template tags. |
| 58 | | * |
| 59 | | * @since 1.0.0 |
| 60 | | * |
| 61 | | * @param string The suffix of the hook. |
| 62 | | */ |
| 63 | | function bp_nouveau_friend_hook( $suffix = '' ) { |
| 64 | | if ( ! $suffix ) { |
| 65 | | return; |
| 66 | | } |
| 67 | | |
| 68 | | bp_nouveau_hook( array( |
| 69 | | 'bp', |
| 70 | | 'friend', |
| 71 | | $suffix, |
| 72 | | ) ); |
| 73 | | } |
| 74 | | |
| 75 | | /** |
| 76 | | * Add classes to style the template notice/feedback message |
| 77 | | * |
| 78 | | * @since 1.0.0 |
| 79 | | */ |
| 80 | | function bp_nouveau_template_message_classes() { |
| 81 | | $classes = array( 'bp-feedback', 'bp-messages' ); |
| 82 | | |
| 83 | | if ( ! empty( bp_nouveau()->template_message['message'] ) ) { |
| 84 | | $classes[] = 'bp-template-notice'; |
| 85 | | } |
| 86 | | |
| 87 | | $classes[] = bp_nouveau_get_template_message_type(); |
| 88 | | echo join( ' ', array_map( 'sanitize_html_class', $classes ) ); |
| 89 | | } |
| 90 | | |
| 91 | | /** |
| 92 | | * Get the template notice/feedback message type |
| 93 | | * |
| 94 | | * @since 1.0.0 |
| 95 | | * |
| 96 | | * @return string The type of the notice. Defaults to error. |
| 97 | | */ |
| 98 | | function bp_nouveau_get_template_message_type() { |
| 99 | | $bp_nouveau = bp_nouveau(); |
| 100 | | $type = 'error'; |
| 101 | | |
| 102 | | if ( ! empty( $bp_nouveau->template_message['type'] ) ) { |
| 103 | | $type = $bp_nouveau->template_message['type']; |
| 104 | | } elseif ( ! empty( $bp_nouveau->user_feedback['type'] ) ) { |
| 105 | | $type = $bp_nouveau->user_feedback['type']; |
| 106 | | } |
| 107 | | |
| 108 | | return $type; |
| 109 | | } |
| 110 | | |
| 111 | | /** |
| 112 | | * Checks if a template notice/feedback message is set |
| 113 | | * |
| 114 | | * @since 1.0.0 |
| 115 | | * |
| 116 | | * @return bool True if a template notice is set. False otherwise. |
| 117 | | */ |
| 118 | | function bp_nouveau_has_template_message() { |
| 119 | | $bp_nouveau = bp_nouveau(); |
| 120 | | |
| 121 | | if ( empty( $bp_nouveau->template_message['message'] ) && empty( $bp_nouveau->user_feedback ) ) { |
| 122 | | return false; |
| 123 | | } |
| 124 | | |
| 125 | | return true; |
| 126 | | } |
| 127 | | |
| 128 | | /** |
| 129 | | * Checks if the template notice/feedback message needs a dismiss button |
| 130 | | * |
| 131 | | * |
| 132 | | * @todo Dismiss button re-worked to try and prevent buttons on general |
| 133 | | * BP template notices - Nouveau user_feedback key needs review. |
| 134 | | * |
| 135 | | * |
| 136 | | * @since 1.0.0 |
| 137 | | * |
| 138 | | * @return bool True if a template notice needs a dismiss button. False otherwise. |
| 139 | | */ |
| 140 | | function bp_nouveau_has_dismiss_button() { |
| 141 | | $bp_nouveau = bp_nouveau(); |
| 142 | | |
| 143 | | // BP template notices - set 'dismiss' true for a type in `bp_nouveau_template_notices()` |
| 144 | | if ( ! empty( $bp_nouveau->template_message['message'] ) && true === $bp_nouveau->template_message['dismiss'] ) { |
| 145 | | return true; |
| 146 | | } |
| 147 | | |
| 148 | | // Test for isset as value may be bool or string i.e 'clear' |
| 149 | | if ( isset( $bp_nouveau->user_feedback['dismiss'] ) ) { |
| 150 | | return true; |
| 151 | | } |
| 152 | | |
| 153 | | return false; |
| 154 | | } |
| 155 | | |
| 156 | | /** |
| 157 | | * Ouptut the dismiss type. |
| 158 | | * $type is used to set the data-attr for the button. |
| 159 | | * 'clear' is tested for & used to remove cookies, if set, in buddypress-nouveau.js. |
| 160 | | * Currently template_notices(BP) will take $type = 'clear' if button set to true. |
| 161 | | * |
| 162 | | * @since 1.0.0 |
| 163 | | */ |
| 164 | | function bp_nouveau_dismiss_button_type() { |
| 165 | | $bp_nouveau = bp_nouveau(); |
| 166 | | $type = 'clear'; |
| 167 | | |
| 168 | | if ( ! empty( $bp_nouveau->user_feedback['dismiss'] ) ) { |
| 169 | | $type = $bp_nouveau->user_feedback['dismiss']; |
| 170 | | } |
| 171 | | |
| 172 | | echo esc_attr( $type ); |
| 173 | | } |
| 174 | | |
| 175 | | /** |
| 176 | | * Displays a template notice/feedback message. |
| 177 | | * |
| 178 | | * @since 1.0.0 |
| 179 | | */ |
| 180 | | function bp_nouveau_template_message() { |
| 181 | | echo bp_nouveau_get_template_message(); |
| 182 | | } |
| 183 | | |
| 184 | | /** |
| 185 | | * Get the template notice/feedback message and make sure core filter is applied. |
| 186 | | * |
| 187 | | * @since 1.0.0 |
| 188 | | * |
| 189 | | * @return string HTML Output. |
| 190 | | */ |
| 191 | | function bp_nouveau_get_template_message() { |
| 192 | | $bp_nouveau = bp_nouveau(); |
| 193 | | |
| 194 | | if ( ! empty( $bp_nouveau->user_feedback['message'] ) ) { |
| 195 | | $user_feedback = $bp_nouveau->user_feedback['message']; |
| 196 | | |
| 197 | | // @TODO: why is this treated differently? |
| 198 | | foreach ( array( 'wp_kses_data', 'wp_unslash', 'wptexturize', 'convert_smilies', 'convert_chars' ) as $filter ) { |
| 199 | | $user_feedback = call_user_func( $filter, $user_feedback ); |
| 200 | | } |
| 201 | | |
| 202 | | return '<p>' . $user_feedback . '</p>'; |
| 203 | | |
| 204 | | } elseif ( ! empty( $bp_nouveau->template_message['message'] ) ) { |
| 205 | | /** |
| 206 | | * Filters the 'template_notices' feedback message content. |
| 207 | | * |
| 208 | | * @since 1.5.5 (BuddyPress) |
| 209 | | * |
| 210 | | * @param string $template_message Feedback message content. |
| 211 | | * @param string $type The type of message being displayed. |
| 212 | | * Either 'updated' or 'error'. |
| 213 | | */ |
| 214 | | return apply_filters( 'bp_core_render_message_content', $bp_nouveau->template_message['message'], bp_nouveau_get_template_message_type() ); |
| 215 | | } |
| 216 | | } |
| 217 | | |
| 218 | | /** |
| 219 | | * Template tag to display feedback notices to users, if there are to display |
| 220 | | * |
| 221 | | * @since 1.0.0 |
| 222 | | */ |
| 223 | | function bp_nouveau_template_notices() { |
| 224 | | $bp = buddypress(); |
| 225 | | $bp_nouveau = bp_nouveau(); |
| 226 | | |
| 227 | | if ( ! empty( $bp->template_message ) ) { |
| 228 | | // Clone BuddyPress template message to avoid altering it. |
| 229 | | $template_message = array( 'message' => $bp->template_message ); |
| 230 | | |
| 231 | | if ( ! empty( $bp->template_message_type ) ) { |
| 232 | | $template_message['type'] = $bp->template_message_type; |
| 233 | | } |
| 234 | | |
| 235 | | // Adds a 'dimiss' (button) key to array - set true/false. |
| 236 | | // defaulting to false. |
| 237 | | $template_message['dismiss'] = false; |
| 238 | | |
| 239 | | // Set dismiss button true for sitewide notices |
| 240 | | if( 'bp-sitewide-notice' == $template_message['type'] ) { |
| 241 | | $template_message['dismiss'] = true; |
| 242 | | } |
| 243 | | |
| 244 | | $bp_nouveau->template_message = $template_message; |
| 245 | | bp_get_template_part( 'common/notices/template-notices' ); |
| 246 | | |
| 247 | | // Reset just after rendering it. |
| 248 | | $bp_nouveau->template_message = array(); |
| 249 | | |
| 250 | | /** |
| 251 | | * Fires after the display of any template_notices feedback messages. |
| 252 | | * |
| 253 | | * @since 1.1.0 |
| 254 | | */ |
| 255 | | do_action( 'bp_core_render_message' ); |
| 256 | | } |
| 257 | | |
| 258 | | /** |
| 259 | | * Fires towards the top of template pages for notice display. |
| 260 | | * |
| 261 | | * @since 1.0.0 |
| 262 | | */ |
| 263 | | do_action( 'template_notices' ); |
| 264 | | } |
| 265 | | |
| 266 | | /** |
| 267 | | * Displays a feedback message to the user. |
| 268 | | * |
| 269 | | * @since 1.0.0 |
| 270 | | * |
| 271 | | * @param string $feedback_id The ID of the message to display |
| 272 | | */ |
| 273 | | function bp_nouveau_user_feedback( $feedback_id = '' ) { |
| 274 | | if ( ! isset( $feedback_id ) ) { |
| 275 | | return; |
| 276 | | } |
| 277 | | |
| 278 | | $bp_nouveau = bp_nouveau(); |
| 279 | | $feedback = bp_nouveau_get_user_feedback( $feedback_id ); |
| 280 | | |
| 281 | | if ( ! $feedback ) { |
| 282 | | return; |
| 283 | | } |
| 284 | | |
| 285 | | if ( ! empty( $feedback['before'] ) ) { |
| 286 | | do_action( $feedback['before'] ); |
| 287 | | } |
| 288 | | |
| 289 | | $bp_nouveau->user_feedback = $feedback; |
| 290 | | |
| 291 | | bp_get_template_part( |
| 292 | | /** |
| 293 | | * Filter here if you wish to use a different templates than the notice one. |
| 294 | | * |
| 295 | | * @since 1.0.0 |
| 296 | | * |
| 297 | | * @param string path to your template part. |
| 298 | | */ |
| 299 | | apply_filters( 'bp_nouveau_user_feedback_template', 'common/notices/template-notices' ) |
| 300 | | ); |
| 301 | | |
| 302 | | if ( ! empty( $feedback['after'] ) ) { |
| 303 | | do_action( $feedback['after'] ); |
| 304 | | } |
| 305 | | |
| 306 | | // Reset the feedback message. |
| 307 | | $bp_nouveau->user_feedback =array(); |
| 308 | | } |
| 309 | | |
| 310 | | /** |
| 311 | | * Template tag to wrap the before component loop |
| 312 | | * |
| 313 | | * @since 1.0.0 |
| 314 | | */ |
| 315 | | function bp_nouveau_before_loop() { |
| 316 | | $component = bp_current_component(); |
| 317 | | |
| 318 | | if ( bp_is_group() ) { |
| 319 | | $component = bp_current_action(); |
| 320 | | } |
| 321 | | |
| 322 | | /** |
| 323 | | * Fires before the start of the component loop. |
| 324 | | * |
| 325 | | * @since 1.2.0 |
| 326 | | */ |
| 327 | | do_action( "bp_before_{$component}_loop" ); |
| 328 | | } |
| 329 | | |
| 330 | | /** |
| 331 | | * Template tag to wrap the after component loop |
| 332 | | * |
| 333 | | * @since 1.0.0 |
| 334 | | */ |
| 335 | | function bp_nouveau_after_loop() { |
| 336 | | $component = bp_current_component(); |
| 337 | | |
| 338 | | if ( bp_is_group() ) { |
| 339 | | $component = bp_current_action(); |
| 340 | | } |
| 341 | | |
| 342 | | /** |
| 343 | | * Fires after the finish of the component loop. |
| 344 | | * |
| 345 | | * @since 1.2.0 |
| 346 | | */ |
| 347 | | do_action( "bp_after_{$component}_loop" ); |
| 348 | | } |
| 349 | | |
| 350 | | /** |
| 351 | | * Pagination for loops |
| 352 | | * |
| 353 | | * @param string $position |
| 354 | | * |
| 355 | | * @since 1.0.0 |
| 356 | | */ |
| 357 | | function bp_nouveau_pagination( $position ) { |
| 358 | | $component = bp_current_component(); |
| 359 | | |
| 360 | | // @TODO: How is this ever going to occur? |
| 361 | | if ( ! bp_is_active( $component ) ) { |
| 362 | | return; |
| 363 | | } |
| 364 | | |
| 365 | | $screen = 'dir'; |
| 366 | | $pagination_type = $component; |
| 367 | | |
| 368 | | if ( bp_is_user() ) { |
| 369 | | $screen = 'user'; |
| 370 | | |
| 371 | | } elseif ( bp_is_group() ) { |
| 372 | | $screen = 'group'; |
| 373 | | $pagination_type = bp_current_action(); |
| 374 | | |
| 375 | | if ( bp_is_group_admin_page() ) { |
| 376 | | $pagination_type = bp_action_variable( 0 ); |
| 377 | | } |
| 378 | | } |
| 379 | | |
| 380 | | switch( $pagination_type ) { |
| 381 | | case 'blogs' : |
| 382 | | $pag_count = bp_get_blogs_pagination_count(); |
| 383 | | $pag_links = bp_get_blogs_pagination_links(); |
| 384 | | $top_hook = 'bp_before_directory_blogs_list'; |
| 385 | | $bottom_hook = 'bp_after_directory_blogs_list'; |
| 386 | | $page_arg = $GLOBALS['blogs_template']->pag_arg; |
| 387 | | break; |
| 388 | | |
| 389 | | case 'members' : |
| 390 | | case 'friends' : |
| 391 | | case 'manage-members' : |
| 392 | | $pag_count = bp_get_members_pagination_count(); |
| 393 | | $pag_links = bp_get_members_pagination_links(); |
| 394 | | |
| 395 | | // Groups single items are not using these hooks |
| 396 | | if ( ! bp_is_group() ) { |
| 397 | | $top_hook = 'bp_before_directory_members_list'; |
| 398 | | $bottom_hook = 'bp_after_directory_members_list'; |
| 399 | | } |
| 400 | | |
| 401 | | $page_arg = $GLOBALS['members_template']->pag_arg; |
| 402 | | break; |
| 403 | | |
| 404 | | case 'groups' : |
| 405 | | $pag_count = bp_get_groups_pagination_count(); |
| 406 | | $pag_links = bp_get_groups_pagination_links(); |
| 407 | | $top_hook = 'bp_before_directory_groups_list'; |
| 408 | | $bottom_hook = 'bp_after_directory_groups_list'; |
| 409 | | $page_arg = $GLOBALS['groups_template']->pag_arg; |
| 410 | | break; |
| 411 | | |
| 412 | | case 'notifications' : |
| 413 | | $pag_count = bp_get_notifications_pagination_count(); |
| 414 | | $pag_links = bp_get_notifications_pagination_links(); |
| 415 | | $top_hook = ''; |
| 416 | | $bottom_hook = ''; |
| 417 | | $page_arg = buddypress()->notifications->query_loop->pag_arg; |
| 418 | | break; |
| 419 | | |
| 420 | | case 'membership-requests' : |
| 421 | | $pag_count = bp_get_group_requests_pagination_count(); |
| 422 | | $pag_links = bp_get_group_requests_pagination_links(); |
| 423 | | $top_hook = ''; |
| 424 | | $bottom_hook = ''; |
| 425 | | $page_arg = $GLOBALS['requests_template']->pag_arg; |
| 426 | | break; |
| 427 | | } |
| 428 | | |
| 429 | | $count_class = sprintf( '%1$s-%2$s-count-%3$s', $pagination_type, $screen, $position ); |
| 430 | | $links_class = sprintf( '%1$s-%2$s-links-%3$s', $pagination_type, $screen, $position ); |
| 431 | | ?> |
| 432 | | |
| 433 | | <?php if ( 'bottom' === $position && isset( $bottom_hook ) ) { |
| 434 | | /** |
| 435 | | * Fires after the component directory list. |
| 436 | | * |
| 437 | | * @since 1.1.0 |
| 438 | | */ |
| 439 | | do_action( $bottom_hook ); |
| 440 | | }; |
| 441 | | ?> |
| 442 | | |
| 443 | | <div class="<?php echo esc_attr( 'bp-pagination ' . sanitize_html_class( $position ) ); ?>" data-bp-pagination="<?php echo esc_attr( $page_arg ); ?>"> |
| 444 | | |
| 445 | | <?php if ( $pag_count ) : ?> |
| 446 | | <div class="<?php echo esc_attr( 'pag-count ' . sanitize_html_class( $position ) ); ?>"> |
| 447 | | |
| 448 | | <p class="pag-data"> |
| 449 | | <?php echo esc_html( $pag_count ); ?> |
| 450 | | </p> |
| 451 | | |
| 452 | | </div> |
| 453 | | <?php endif; ?> |
| 454 | | |
| 455 | | <?php if ( $pag_links ) : ?> |
| 456 | | <div class="<?php echo esc_attr( 'bp-pagination-links ' . sanitize_html_class( $position ) ); ?>"> |
| 457 | | |
| 458 | | <p class="pag-data"> |
| 459 | | <?php echo wp_kses_post( $pag_links ); ?> |
| 460 | | </p> |
| 461 | | |
| 462 | | </div> |
| 463 | | <?php endif; ?> |
| 464 | | |
| 465 | | </div> |
| 466 | | |
| 467 | | <?php if ( 'top' === $position && isset( $top_hook ) ) { |
| 468 | | /** |
| 469 | | * Fires before the component directory list. |
| 470 | | * |
| 471 | | * @since 1.1.0 |
| 472 | | */ |
| 473 | | do_action( $top_hook ); |
| 474 | | }; |
| 475 | | } |
| 476 | | |
| 477 | | /** |
| 478 | | * Display the component's loop classes |
| 479 | | * |
| 480 | | * @since 1.0.0 |
| 481 | | * |
| 482 | | * @return string CSS class attributes (escaped). |
| 483 | | */ |
| 484 | | function bp_nouveau_loop_classes() { |
| 485 | | echo esc_attr( bp_nouveau_get_loop_classes() ); |
| 486 | | } |
| 487 | | |
| 488 | | /** |
| 489 | | * Get the component's loop classes |
| 490 | | * |
| 491 | | * @since 1.0.0 |
| 492 | | * |
| 493 | | * @return string space separated value of classes. |
| 494 | | */ |
| 495 | | function bp_nouveau_get_loop_classes() { |
| 496 | | $bp_nouveau = bp_nouveau(); |
| 497 | | |
| 498 | | // @todo: this function could do with passing args so we can pass simple strings in or array of strings |
| 499 | | |
| 500 | | // The $component is faked if it's the single group member loop |
| 501 | | if ( ! bp_is_directory() && ( bp_is_group() && 'members' === bp_current_action() ) ) { |
| 502 | | $component = 'members_group'; |
| 503 | | } elseif ( ! bp_is_directory() && ( bp_is_user() && 'my-friends' === bp_current_action() ) ) { |
| 504 | | $component = 'members_friends'; |
| 505 | | } else { |
| 506 | | $component = sanitize_key( bp_current_component() ); |
| 507 | | } |
| 508 | | |
| 509 | | $classes = array( |
| 510 | | 'item-list', |
| 511 | | sprintf( '%s-list', str_replace( '_', '-', $component ) ), |
| 512 | | 'bp-list', |
| 513 | | ); |
| 514 | | |
| 515 | | if ( bp_is_user() && 'my-friends' === bp_current_action() ) { |
| 516 | | $classes[] = 'members-list'; |
| 517 | | } |
| 518 | | |
| 519 | | $available_components = array( |
| 520 | | 'members' => true, |
| 521 | | 'groups' => true, |
| 522 | | 'blogs' => true, |
| 523 | | |
| 524 | | /* |
| 525 | | * Technically not a component but allows us to check the single group members loop as a seperate loop. |
| 526 | | */ |
| 527 | | 'members_group' => true, |
| 528 | | 'members_friends' => true, |
| 529 | | ); |
| 530 | | |
| 531 | | // Only the available components supports custom layouts. |
| 532 | | if ( ! empty( $available_components[ $component ] ) && ( bp_is_directory() || bp_is_group() || bp_is_user() ) ) { |
| 533 | | $customizer_option = sprintf( '%s_layout', $component ); |
| 534 | | $layout_prefs = bp_nouveau_get_temporary_setting( |
| 535 | | $customizer_option, |
| 536 | | bp_nouveau_get_appearance_settings( $customizer_option ) |
| 537 | | ); |
| 538 | | |
| 539 | | if ( $layout_prefs && (int) $layout_prefs > 1 ) { |
| 540 | | $grid_classes = bp_nouveau_customizer_grid_choices( 'classes' ); |
| 541 | | |
| 542 | | if ( isset( $grid_classes[ $layout_prefs ] ) ) { |
| 543 | | $classes = array_merge( $classes, array( |
| 544 | | 'grid', |
| 545 | | $grid_classes[ $layout_prefs ], |
| 546 | | ) ); |
| 547 | | } |
| 548 | | |
| 549 | | // Set the global for a later use. |
| 550 | | $bp_nouveau->{$component}->loop_layout = $layout_prefs; |
| 551 | | } |
| 552 | | } |
| 553 | | |
| 554 | | /** |
| 555 | | * Filter to edit/add classes. |
| 556 | | * |
| 557 | | * NB: you can also directly add classes into the template parts. |
| 558 | | * |
| 559 | | * @since 1.0.0 |
| 560 | | * |
| 561 | | * @param array $classes The list of classes. |
| 562 | | * @param string $component The current component's loop. |
| 563 | | */ |
| 564 | | $class_list = (array) apply_filters( 'bp_nouveau_get_loop_classes', $classes, $component ); |
| 565 | | |
| 566 | | return join( ' ', array_map( 'sanitize_html_class', $class_list ) ); |
| 567 | | } |
| 568 | | |
| 569 | | |
| 570 | | /** |
| 571 | | * Checks if the layout preferences is set to grid (2 or more columns). |
| 572 | | * |
| 573 | | * @since 1.0.0 |
| 574 | | * |
| 575 | | * @return bool True if loop is displayed in grid mod. False otherwise. |
| 576 | | */ |
| 577 | | function bp_nouveau_loop_is_grid() { |
| 578 | | $bp_nouveau = bp_nouveau(); |
| 579 | | $component = sanitize_key( bp_current_component() ); |
| 580 | | |
| 581 | | return ! empty( $bp_nouveau->{$component}->loop_layout ) && $bp_nouveau->{$component}->loop_layout > 1; |
| 582 | | } |
| 583 | | |
| 584 | | /** |
| 585 | | * Returns the number of columns of the layout preferences. |
| 586 | | * |
| 587 | | * @since 1.0.0 |
| 588 | | * |
| 589 | | * @return int The number of columns. |
| 590 | | */ |
| 591 | | function bp_nouveau_loop_get_grid_columns() { |
| 592 | | $bp_nouveau = bp_nouveau(); |
| 593 | | $component = sanitize_key( bp_current_component() ); |
| 594 | | |
| 595 | | $columns = 1; |
| 596 | | |
| 597 | | if ( ! empty( $bp_nouveau->{$component}->loop_layout ) ) { |
| 598 | | $columns = (int) $bp_nouveau->{$component}->loop_layout; |
| 599 | | } |
| 600 | | |
| 601 | | /** |
| 602 | | * Filter number of columns for this grid. |
| 603 | | * |
| 604 | | * @since 1.0.0 |
| 605 | | * |
| 606 | | * @param int $columns The number of columns. |
| 607 | | */ |
| 608 | | return (int) apply_filters( 'bp_nouveau_loop_get_grid_columns', $columns ); |
| 609 | | } |
| 610 | | |
| 611 | | /** |
| 612 | | * Return a bool check for component directory layout. |
| 613 | | * Checks if activity, members, groups, blogs has the vert nav layout selected |
| 614 | | * |
| 615 | | * @since 1.0.0 |
| 616 | | * |
| 617 | | * @return bool. |
| 618 | | */ |
| 619 | | function bp_dir_is_vert_layout() { |
| 620 | | $bp_nouveau = bp_nouveau(); |
| 621 | | $component = sanitize_key( bp_current_component() ); |
| 622 | | |
| 623 | | return (bool) $bp_nouveau->{$component}->directory_vertical_layout; |
| 624 | | } |
| 625 | | |
| 626 | | /** |
| 627 | | * Get the full size avatar args. |
| 628 | | * |
| 629 | | * @since 1.0.0 |
| 630 | | * |
| 631 | | * @return array The avatar arguments. |
| 632 | | */ |
| 633 | | function bp_nouveau_avatar_args() { |
| 634 | | /** |
| 635 | | * Filter arguments for full-size avatars. |
| 636 | | * |
| 637 | | * @param array $args |
| 638 | | */ |
| 639 | | return apply_filters( 'bp_nouveau_avatar_args', array( |
| 640 | | 'type' => 'full', |
| 641 | | 'width' => bp_core_avatar_full_width(), |
| 642 | | 'height' => bp_core_avatar_full_height(), |
| 643 | | ) ); |
| 644 | | } |
| 645 | | |
| 646 | | |
| 647 | | /** Template Tags for BuddyPress navigations **********************************/ |
| 648 | | |
| 649 | | /* |
| 650 | | * This is the BP Nouveau Navigation Loop. |
| 651 | | * |
| 652 | | * It can be used by any object using the |
| 653 | | * BP_Core_Nav API introduced in BuddyPress 2.6.0. |
| 654 | | */ |
| 655 | | |
| 656 | | /** |
| 657 | | * Init the Navigation Loop and check it has items. |
| 658 | | * |
| 659 | | * @since 1.0.0 |
| 660 | | * |
| 661 | | * @param array $args { |
| 662 | | * Array of arguments. |
| 663 | | * |
| 664 | | * @type string $type The type of Nav to get (primary or secondary) |
| 665 | | * Default 'primary'. Required. |
| 666 | | * @type string $object The object to get the nav for (eg: 'directory', 'group_manage', |
| 667 | | * or any custom object). Default ''. Optional |
| 668 | | * @type bool $user_has_access Used by the secondary member's & group's nav. Default true. Optional. |
| 669 | | * @type bool $show_for_displayed_user Used by the primary member's nav. Default true. Optional. |
| 670 | | * } |
| 671 | | * |
| 672 | | * @return bool True if the Nav contains items. False otherwise. |
| 673 | | */ |
| 674 | | function bp_nouveau_has_nav( $args = array() ) { |
| 675 | | $bp_nouveau = bp_nouveau(); |
| 676 | | |
| 677 | | $n = wp_parse_args( $args, array( |
| 678 | | 'type' => 'primary', |
| 679 | | 'object' => '', |
| 680 | | 'user_has_access' => true, |
| 681 | | 'show_for_displayed_user' => true, |
| 682 | | ) ); |
| 683 | | |
| 684 | | if ( empty( $n['type'] ) ) { |
| 685 | | return false; |
| 686 | | } |
| 687 | | |
| 688 | | $nav = array(); |
| 689 | | $bp_nouveau->displayed_nav = ''; |
| 690 | | $bp_nouveau->object_nav = $n['object']; |
| 691 | | |
| 692 | | if ( bp_is_directory() || 'directory' === $bp_nouveau->object_nav ) { |
| 693 | | $bp_nouveau->displayed_nav = 'directory'; |
| 694 | | $nav = $bp_nouveau->directory_nav->get_primary(); |
| 695 | | |
| 696 | | // So far it's only possible to build a Group nav when displaying it. |
| 697 | | } elseif ( bp_is_group() ) { |
| 698 | | $bp_nouveau->displayed_nav = 'groups'; |
| 699 | | $parent_slug = bp_get_current_group_slug(); |
| 700 | | $group_nav = buddypress()->groups->nav; |
| 701 | | |
| 702 | | if ( 'group_manage' === $bp_nouveau->object_nav && bp_is_group_admin_page() ) { |
| 703 | | $parent_slug .= '_manage'; |
| 704 | | |
| 705 | | /** |
| 706 | | * If it's not the Admin tabs, reorder the Group's nav according to the |
| 707 | | * customizer setting. |
| 708 | | */ |
| 709 | | } else { |
| 710 | | bp_nouveau_set_nav_item_order( $group_nav, bp_nouveau_get_appearance_settings( 'group_nav_order' ), $parent_slug ); |
| 711 | | } |
| 712 | | |
| 713 | | $nav = $group_nav->get_secondary( array( |
| 714 | | 'parent_slug' => $parent_slug, |
| 715 | | 'user_has_access' => (bool) $n['user_has_access'], |
| 716 | | ) ); |
| 717 | | |
| 718 | | // Build the nav for the displayed user |
| 719 | | } elseif ( bp_is_user() ) { |
| 720 | | $bp_nouveau->displayed_nav = 'personal'; |
| 721 | | $user_nav = buddypress()->members->nav; |
| 722 | | |
| 723 | | if ( 'secondary' === $n['type'] ) { |
| 724 | | $nav = $user_nav->get_secondary( array( |
| 725 | | 'parent_slug' => bp_current_component(), |
| 726 | | 'user_has_access' => (bool) $n['user_has_access'], |
| 727 | | ) ); |
| 728 | | |
| 729 | | } else { |
| 730 | | $args = array(); |
| 731 | | |
| 732 | | if ( true === (bool) $n['show_for_displayed_user'] && ! bp_is_my_profile() ) { |
| 733 | | $args = array( 'show_for_displayed_user' => true ); |
| 734 | | } |
| 735 | | |
| 736 | | // Reorder the user's primary nav according to the customizer setting. |
| 737 | | bp_nouveau_set_nav_item_order( $user_nav, bp_nouveau_get_appearance_settings( 'user_nav_order' ) ); |
| 738 | | |
| 739 | | $nav = $user_nav->get_primary( $args ); |
| 740 | | } |
| 741 | | |
| 742 | | } elseif ( ! empty( $bp_nouveau->object_nav ) ) { |
| 743 | | $bp_nouveau->displayed_nav = $bp_nouveau->object_nav; |
| 744 | | |
| 745 | | /** |
| 746 | | * Use the filter to use your specific Navigation. |
| 747 | | * Use the $n param to check for your custom object. |
| 748 | | * |
| 749 | | * @since 1.0.0 |
| 750 | | * |
| 751 | | * @param array $nav The list of item navigations generated by the BP_Core_Nav API. |
| 752 | | * @param array $n The arguments of the Navigation loop. |
| 753 | | */ |
| 754 | | $nav = apply_filters( 'bp_nouveau_get_nav', $nav, $n ); |
| 755 | | } |
| 756 | | |
| 757 | | $bp_nouveau->sorted_nav = array_values( $nav ); |
| 758 | | |
| 759 | | if ( 0 === count( $bp_nouveau->sorted_nav ) || ! $bp_nouveau->displayed_nav ) { |
| 760 | | unset( $bp_nouveau->sorted_nav, $bp_nouveau->displayed_nav, $bp_nouveau->object_nav ); |
| 761 | | |
| 762 | | return false; |
| 763 | | } |
| 764 | | |
| 765 | | $bp_nouveau->current_nav_index = 0; |
| 766 | | return true; |
| 767 | | } |
| 768 | | |
| 769 | | /** |
| 770 | | * Checks there are still nav items to display. |
| 771 | | * |
| 772 | | * @since 1.0.0 |
| 773 | | * |
| 774 | | * @return bool True if there are still items to display. False otherwise. |
| 775 | | */ |
| 776 | | function bp_nouveau_nav_items() { |
| 777 | | $bp_nouveau = bp_nouveau(); |
| 778 | | |
| 779 | | if ( isset( $bp_nouveau->sorted_nav[ $bp_nouveau->current_nav_index ] ) ) { |
| 780 | | return true; |
| 781 | | } |
| 782 | | |
| 783 | | $bp_nouveau->current_nav_index = 0; |
| 784 | | unset( $bp_nouveau->current_nav_item ); |
| 785 | | |
| 786 | | return false; |
| 787 | | } |
| 788 | | |
| 789 | | /** |
| 790 | | * Sets the current nav item and prepare the navigation loop to iterate to next one. |
| 791 | | * |
| 792 | | * @since 1.0.0 |
| 793 | | */ |
| 794 | | function bp_nouveau_nav_item() { |
| 795 | | $bp_nouveau = bp_nouveau(); |
| 796 | | |
| 797 | | $bp_nouveau->current_nav_item = $bp_nouveau->sorted_nav[ $bp_nouveau->current_nav_index ]; |
| 798 | | $bp_nouveau->current_nav_index += 1; |
| 799 | | } |
| 800 | | |
| 801 | | /** |
| 802 | | * Displays the nav item ID. |
| 803 | | * |
| 804 | | * @since 1.0.0 |
| 805 | | */ |
| 806 | | function bp_nouveau_nav_id() { |
| 807 | | echo esc_attr( bp_nouveau_get_nav_id() ); |
| 808 | | } |
| 809 | | |
| 810 | | /** |
| 811 | | * Retrieve the ID attribute of the current nav item. |
| 812 | | * |
| 813 | | * @since 1.0.0 |
| 814 | | * |
| 815 | | * @return string the ID attribute. |
| 816 | | */ |
| 817 | | function bp_nouveau_get_nav_id() { |
| 818 | | $bp_nouveau = bp_nouveau(); |
| 819 | | $nav_item = $bp_nouveau->current_nav_item; |
| 820 | | |
| 821 | | if ( 'directory' === $bp_nouveau->displayed_nav ) { |
| 822 | | $id = sprintf( '%1$s-%2$s', $nav_item->component, $nav_item->slug ); |
| 823 | | } elseif ( 'groups' === $bp_nouveau->displayed_nav || 'personal' === $bp_nouveau->displayed_nav ) { |
| 824 | | $id = sprintf( '%1$s-%2$s-li', $nav_item->css_id, $bp_nouveau->displayed_nav ); |
| 825 | | } else { |
| 826 | | $id = $nav_item->slug; |
| 827 | | } |
| 828 | | |
| 829 | | /** |
| 830 | | * Filter to edit the ID attribute of the nav. |
| 831 | | * |
| 832 | | * @since 1.0.0 |
| 833 | | * |
| 834 | | * @param string $id The ID attribute of the nav. |
| 835 | | * @param object $nav_item The current nav item object. |
| 836 | | * @param string $value The current nav in use (eg: 'directory', 'groups', 'personal', etc..). |
| 837 | | */ |
| 838 | | return apply_filters( 'bp_nouveau_get_nav_id', $id, $nav_item, $bp_nouveau->displayed_nav ); |
| 839 | | } |
| 840 | | |
| 841 | | /** |
| 842 | | * Displays the nav item classes. |
| 843 | | * |
| 844 | | * @since 1.0.0 |
| 845 | | */ |
| 846 | | function bp_nouveau_nav_classes() { |
| 847 | | echo esc_attr( bp_nouveau_get_nav_classes() ); |
| 848 | | } |
| 849 | | |
| 850 | | /** |
| 851 | | * Retrieve a space separated list of classes for the current nav item. |
| 852 | | * |
| 853 | | * @since 1.0.0 |
| 854 | | * |
| 855 | | * @return string List of classes. |
| 856 | | */ |
| 857 | | function bp_nouveau_get_nav_classes() { |
| 858 | | $bp_nouveau = bp_nouveau(); |
| 859 | | $nav_item = $bp_nouveau->current_nav_item; |
| 860 | | $classes = array(); |
| 861 | | |
| 862 | | if ( 'directory' === $bp_nouveau->displayed_nav && ! empty( $nav_item->li_class ) ) { |
| 863 | | $classes = (array) $nav_item->li_class; |
| 864 | | } elseif ( 'groups' === $bp_nouveau->displayed_nav || 'personal' === $bp_nouveau->displayed_nav ) { |
| 865 | | $classes = array( 'bp-' . $bp_nouveau->displayed_nav . '-tab' ); |
| 866 | | $selected = bp_current_action(); |
| 867 | | |
| 868 | | // User's primary nav |
| 869 | | if ( ! empty( $nav_item->primary ) ) { |
| 870 | | $selected = bp_current_component(); |
| 871 | | |
| 872 | | // Group Admin Tabs. |
| 873 | | } elseif ( 'group_manage' === $bp_nouveau->object_nav ) { |
| 874 | | $selected = bp_action_variable( 0 ); |
| 875 | | $classes = array( 'bp-' . $bp_nouveau->displayed_nav . '-admin-tab' ); |
| 876 | | |
| 877 | | // If we are here, it's the member's subnav |
| 878 | | } elseif ( 'personal' === $bp_nouveau->displayed_nav ) { |
| 879 | | $classes = array( 'bp-' . $bp_nouveau->displayed_nav . '-sub-tab' ); |
| 880 | | } |
| 881 | | |
| 882 | | if ( $nav_item->slug === $selected ) { |
| 883 | | $classes = array_merge( $classes, array( 'current', 'selected' ) ); |
| 884 | | } |
| 885 | | } |
| 886 | | |
| 887 | | if ( ! empty( $classes ) ) { |
| 888 | | $classes = array_map( 'sanitize_html_class', $classes ); |
| 889 | | } |
| 890 | | |
| 891 | | /** |
| 892 | | * Filter to edit/add classes. |
| 893 | | * |
| 894 | | * NB: you can also directly add classes into the template parts. |
| 895 | | * |
| 896 | | * @since 1.0.0 |
| 897 | | * |
| 898 | | * @param string $value A space separated list of classes. |
| 899 | | * @param array $classes The list of classes. |
| 900 | | * @param object $nav_item The current nav item object. |
| 901 | | * @param string $value The current nav in use (eg: 'directory', 'groups', 'personal', etc..). |
| 902 | | */ |
| 903 | | $classes_list = apply_filters( 'bp_nouveau_get_classes', join( ' ', $classes ), $classes, $nav_item, $bp_nouveau->displayed_nav ); |
| 904 | | if ( ! $classes_list ) { |
| 905 | | $classes_list = ''; |
| 906 | | } |
| 907 | | |
| 908 | | return $classes_list; |
| 909 | | } |
| 910 | | |
| 911 | | /** |
| 912 | | * Displays the nav item scope. |
| 913 | | * |
| 914 | | * @since 1.0.0 |
| 915 | | */ |
| 916 | | function bp_nouveau_nav_scope() { |
| 917 | | echo bp_nouveau_get_nav_scope(); // Escaped by bp_get_form_field_attributes(). |
| 918 | | } |
| 919 | | |
| 920 | | /** |
| 921 | | * Retrieve the specific scope for the current nav item. |
| 922 | | * |
| 923 | | * @since 1.0.0 |
| 924 | | * |
| 925 | | * @return string the specific scope of the nav. |
| 926 | | */ |
| 927 | | function bp_nouveau_get_nav_scope() { |
| 928 | | $bp_nouveau = bp_nouveau(); |
| 929 | | $nav_item = $bp_nouveau->current_nav_item; |
| 930 | | $scope = array(); |
| 931 | | |
| 932 | | if ( 'directory' === $bp_nouveau->displayed_nav ) { |
| 933 | | $scope = array( 'data-bp-scope' => $nav_item->slug ); |
| 934 | | |
| 935 | | } elseif ( 'personal' === $bp_nouveau->displayed_nav && ! empty( $nav_item->secondary ) ) { |
| 936 | | $scope = array( 'data-bp-user-scope' => $nav_item->slug ); |
| 937 | | |
| 938 | | } else { |
| 939 | | /** |
| 940 | | * Filter to add your own scope. |
| 941 | | * |
| 942 | | * @since 1.0.0 |
| 943 | | * |
| 944 | | * @param array $scope Contains the key and the value for your scope. |
| 945 | | * @param object $nav_item The current nav item object. |
| 946 | | * @param string $value The current nav in use (eg: 'directory', 'groups', 'personal', etc..). |
| 947 | | */ |
| 948 | | $scope = apply_filters( 'bp_nouveau_set_nav_scope', $scope, $nav_item, $bp_nouveau->displayed_nav ); |
| 949 | | } |
| 950 | | |
| 951 | | if ( ! $scope ) { |
| 952 | | return ''; |
| 953 | | } |
| 954 | | |
| 955 | | return bp_get_form_field_attributes( 'scope', $scope ); |
| 956 | | } |
| 957 | | |
| 958 | | /** |
| 959 | | * Displays the nav item URL. |
| 960 | | * |
| 961 | | * @since 1.0.0 |
| 962 | | */ |
| 963 | | function bp_nouveau_nav_link() { |
| 964 | | echo esc_url( bp_nouveau_get_nav_link() ); |
| 965 | | } |
| 966 | | |
| 967 | | /** |
| 968 | | * Retrieve the URL for the current nav item. |
| 969 | | * |
| 970 | | * @since 1.0.0 |
| 971 | | * |
| 972 | | * @return string The URL for the nav item. |
| 973 | | */ |
| 974 | | function bp_nouveau_get_nav_link() { |
| 975 | | $bp_nouveau = bp_nouveau(); |
| 976 | | $nav_item = $bp_nouveau->current_nav_item; |
| 977 | | |
| 978 | | $link = '#'; |
| 979 | | if ( ! empty( $nav_item->link ) ) { |
| 980 | | $link = $nav_item->link; |
| 981 | | } |
| 982 | | |
| 983 | | if ( 'personal' === $bp_nouveau->displayed_nav && ! empty( $nav_item->primary ) ) { |
| 984 | | if ( bp_loggedin_user_domain() ) { |
| 985 | | $link = str_replace( bp_loggedin_user_domain(), bp_displayed_user_domain(), $link ); |
| 986 | | } else { |
| 987 | | $link = trailingslashit( bp_displayed_user_domain() . $link ); |
| 988 | | } |
| 989 | | } |
| 990 | | |
| 991 | | /** |
| 992 | | * Filter to edit the URL of the nav item. |
| 993 | | * |
| 994 | | * @since 1.0.0 |
| 995 | | * |
| 996 | | * @param string $link The URL for the nav item. |
| 997 | | * @param object $nav_item The current nav item object. |
| 998 | | * @param string $value The current nav in use (eg: 'directory', 'groups', 'personal', etc..). |
| 999 | | */ |
| 1000 | | return apply_filters( 'bp_nouveau_get_nav_link', $link, $nav_item, $bp_nouveau->displayed_nav ); |
| 1001 | | } |
| 1002 | | |
| 1003 | | /** |
| 1004 | | * Displays the nav item link ID. |
| 1005 | | * |
| 1006 | | * @since 1.0.0 |
| 1007 | | */ |
| 1008 | | function bp_nouveau_nav_link_id() { |
| 1009 | | echo esc_attr( bp_nouveau_get_nav_link_id() ); |
| 1010 | | } |
| 1011 | | |
| 1012 | | /** |
| 1013 | | * Retrieve the id attribute of the link for the current nav item. |
| 1014 | | * |
| 1015 | | * @since 1.0.0 |
| 1016 | | * |
| 1017 | | * @return string The link id for the nav item. |
| 1018 | | */ |
| 1019 | | function bp_nouveau_get_nav_link_id() { |
| 1020 | | $bp_nouveau = bp_nouveau(); |
| 1021 | | $nav_item = $bp_nouveau->current_nav_item; |
| 1022 | | $link_id = ''; |
| 1023 | | |
| 1024 | | if ( ( 'groups' === $bp_nouveau->displayed_nav || 'personal' === $bp_nouveau->displayed_nav ) && ! empty( $nav_item->css_id ) ) { |
| 1025 | | $link_id = $nav_item->css_id; |
| 1026 | | |
| 1027 | | if ( ! empty( $nav_item->primary ) && 'personal' === $bp_nouveau->displayed_nav ) { |
| 1028 | | $link_id = 'user-' . $link_id; |
| 1029 | | } |
| 1030 | | } else { |
| 1031 | | $link_id = $nav_item->slug; |
| 1032 | | } |
| 1033 | | |
| 1034 | | /** |
| 1035 | | * Filter to edit the link id attribute of the nav. |
| 1036 | | * |
| 1037 | | * @since 1.0.0 |
| 1038 | | * |
| 1039 | | * @param string $link_id The link id attribute for the nav item. |
| 1040 | | * @param object $nav_item The current nav item object. |
| 1041 | | * @param string $value The current nav in use (eg: 'directory', 'groups', 'personal', etc..). |
| 1042 | | */ |
| 1043 | | return apply_filters( 'bp_nouveau_get_nav_link_id', $link_id, $nav_item, $bp_nouveau->displayed_nav ); |
| 1044 | | } |
| 1045 | | |
| 1046 | | /** |
| 1047 | | * Displays the nav item link title. |
| 1048 | | * |
| 1049 | | * @since 1.0.0 |
| 1050 | | */ |
| 1051 | | function bp_nouveau_nav_link_title() { |
| 1052 | | echo esc_attr( bp_nouveau_get_nav_link_title() ); |
| 1053 | | } |
| 1054 | | |
| 1055 | | /** |
| 1056 | | * Retrieve the title attribute of the link for the current nav item. |
| 1057 | | * |
| 1058 | | * @since 1.0.0 |
| 1059 | | * |
| 1060 | | * @return string The link title for the nav item. |
| 1061 | | */ |
| 1062 | | function bp_nouveau_get_nav_link_title() { |
| 1063 | | $bp_nouveau = bp_nouveau(); |
| 1064 | | $nav_item = $bp_nouveau->current_nav_item; |
| 1065 | | $title = ''; |
| 1066 | | |
| 1067 | | if ( 'directory' === $bp_nouveau->displayed_nav && ! empty( $nav_item->title ) ) { |
| 1068 | | $title = $nav_item->title; |
| 1069 | | |
| 1070 | | } elseif ( |
| 1071 | | ( 'groups' === $bp_nouveau->displayed_nav || 'personal' === $bp_nouveau->displayed_nav ) |
| 1072 | | && |
| 1073 | | ! empty( $nav_item->name ) |
| 1074 | | ) { |
| 1075 | | $title = $nav_item->name; |
| 1076 | | } |
| 1077 | | |
| 1078 | | /** |
| 1079 | | * Filter to edit the link title attribute of the nav. |
| 1080 | | * |
| 1081 | | * @since 1.0.0 |
| 1082 | | * |
| 1083 | | * @param string $title The link title attribute for the nav item. |
| 1084 | | * @param object $nav_item The current nav item object. |
| 1085 | | * @param string $value The current nav in use (eg: 'directory', 'groups', 'personal', etc..). |
| 1086 | | */ |
| 1087 | | return apply_filters( 'bp_nouveau_get_nav_link_title', $title, $nav_item, $bp_nouveau->displayed_nav ); |
| 1088 | | } |
| 1089 | | |
| 1090 | | /** |
| 1091 | | * Displays the nav item link html text. |
| 1092 | | * |
| 1093 | | * @since 1.0.0 |
| 1094 | | */ |
| 1095 | | function bp_nouveau_nav_link_text() { |
| 1096 | | echo esc_html( bp_nouveau_get_nav_link_text() ); |
| 1097 | | } |
| 1098 | | |
| 1099 | | /** |
| 1100 | | * Retrieve the html text of the link for the current nav item. |
| 1101 | | * |
| 1102 | | * @since 1.0.0 |
| 1103 | | * |
| 1104 | | * @return string The html text for the nav item. |
| 1105 | | */ |
| 1106 | | function bp_nouveau_get_nav_link_text() { |
| 1107 | | $bp_nouveau = bp_nouveau(); |
| 1108 | | $nav_item = $bp_nouveau->current_nav_item; |
| 1109 | | $link_text = ''; |
| 1110 | | |
| 1111 | | if ( 'directory' === $bp_nouveau->displayed_nav && ! empty( $nav_item->text ) ) { |
| 1112 | | $link_text = $nav_item->text; |
| 1113 | | |
| 1114 | | } elseif ( |
| 1115 | | ( 'groups' === $bp_nouveau->displayed_nav || 'personal' === $bp_nouveau->displayed_nav ) |
| 1116 | | && |
| 1117 | | ! empty( $nav_item->name ) |
| 1118 | | ) { |
| 1119 | | $link_text = _bp_strip_spans_from_title( $nav_item->name ); |
| 1120 | | } |
| 1121 | | |
| 1122 | | /** |
| 1123 | | * Filter to edit the html text of the nav. |
| 1124 | | * |
| 1125 | | * @since 1.0.0 |
| 1126 | | * |
| 1127 | | * @param string $link_text The html text of the nav item. |
| 1128 | | * @param object $nav_item The current nav item object. |
| 1129 | | * @param string $value The current nav in use (eg: 'directory', 'groups', 'personal', etc..). |
| 1130 | | */ |
| 1131 | | return apply_filters( 'bp_nouveau_get_nav_link_text', $link_text, $nav_item, $bp_nouveau->displayed_nav ); |
| 1132 | | } |
| 1133 | | |
| 1134 | | /** |
| 1135 | | * Checks if the nav item has a count attribute. |
| 1136 | | * |
| 1137 | | * @since 1.0.0 |
| 1138 | | * |
| 1139 | | * @return bool |
| 1140 | | */ |
| 1141 | | function bp_nouveau_nav_has_count() { |
| 1142 | | $bp_nouveau = bp_nouveau(); |
| 1143 | | $nav_item = $bp_nouveau->current_nav_item; |
| 1144 | | $count = false; |
| 1145 | | |
| 1146 | | if ( 'directory' === $bp_nouveau->displayed_nav ) { |
| 1147 | | $count = $nav_item->count; |
| 1148 | | } elseif ( 'groups' === $bp_nouveau->displayed_nav && 'members' === $nav_item->slug ) { |
| 1149 | | $count = 0 !== (int) groups_get_current_group()->total_member_count; |
| 1150 | | } elseif ( 'personal' === $bp_nouveau->displayed_nav && ! empty( $nav_item->primary ) ) { |
| 1151 | | $count = (bool) strpos( $nav_item->name, '="count"' ); |
| 1152 | | } |
| 1153 | | |
| 1154 | | /** |
| 1155 | | * Filter to edit whether the nav has a count attribute. |
| 1156 | | * |
| 1157 | | * @since 1.0.0 |
| 1158 | | * |
| 1159 | | * @param bool $value True if the nav has a count attribute. False otherwise |
| 1160 | | * @param object $nav_item The current nav item object. |
| 1161 | | * @param string $value The current nav in use (eg: 'directory', 'groups', 'personal', etc..). |
| 1162 | | */ |
| 1163 | | return (bool) apply_filters( 'bp_nouveau_nav_has_count', false !== $count, $nav_item, $bp_nouveau->displayed_nav ); |
| 1164 | | } |
| 1165 | | |
| 1166 | | /** |
| 1167 | | * Displays the nav item count attribute. |
| 1168 | | * |
| 1169 | | * @since 1.0.0 |
| 1170 | | */ |
| 1171 | | function bp_nouveau_nav_count() { |
| 1172 | | echo esc_html( number_format_i18n( bp_nouveau_get_nav_count() ) ); |
| 1173 | | } |
| 1174 | | |
| 1175 | | /** |
| 1176 | | * Retrieve the count attribute for the current nav item. |
| 1177 | | * |
| 1178 | | * @since 1.0.0 |
| 1179 | | * |
| 1180 | | * @return int The count attribute for the nav item. |
| 1181 | | */ |
| 1182 | | function bp_nouveau_get_nav_count() { |
| 1183 | | $bp_nouveau = bp_nouveau(); |
| 1184 | | $nav_item = $bp_nouveau->current_nav_item; |
| 1185 | | $count = 0; |
| 1186 | | |
| 1187 | | if ( 'directory' === $bp_nouveau->displayed_nav ) { |
| 1188 | | $count = (int) $nav_item->count; |
| 1189 | | |
| 1190 | | } elseif ( 'groups' === $bp_nouveau->displayed_nav && 'members' === $nav_item->slug ) { |
| 1191 | | $count = groups_get_current_group()->total_member_count; |
| 1192 | | |
| 1193 | | // @todo imho BuddyPress shouldn't add html tags inside Nav attributes... |
| 1194 | | } elseif ( 'personal' === $bp_nouveau->displayed_nav && ! empty( $nav_item->primary ) ) { |
| 1195 | | $span = strpos( $nav_item->name, '<span' ); |
| 1196 | | |
| 1197 | | // Grab count out of the <span> element. |
| 1198 | | if ( false !== $span ) { |
| 1199 | | $count_start = strpos( $nav_item->name, '>', $span ) + 1; |
| 1200 | | $count_end = strpos( $nav_item->name, '<', $count_start ); |
| 1201 | | $count = (int) substr( $nav_item->name, $count_start, $count_end - $count_start ); |
| 1202 | | } |
| 1203 | | } |
| 1204 | | |
| 1205 | | /** |
| 1206 | | * Filter to edit the count attribute for the nav item. |
| 1207 | | * |
| 1208 | | * @since 1.0.0 |
| 1209 | | * |
| 1210 | | * @param int $count The count attribute for the nav item. |
| 1211 | | * @param object $nav_item The current nav item object. |
| 1212 | | * @param string $value The current nav in use (eg: 'directory', 'groups', 'personal', etc..). |
| 1213 | | */ |
| 1214 | | return (int) apply_filters( 'bp_nouveau_get_nav_count', $count, $nav_item, $bp_nouveau->displayed_nav ); |
| 1215 | | } |
| 1216 | | |
| 1217 | | /** Template tags specific to the Directory navs ******************************/ |
| 1218 | | |
| 1219 | | /** |
| 1220 | | * Displays the directory nav class. |
| 1221 | | * |
| 1222 | | * @since 1.0.0 |
| 1223 | | */ |
| 1224 | | function bp_nouveau_directory_type_navs_class() { |
| 1225 | | echo esc_attr( bp_nouveau_get_directory_type_navs_class() ); |
| 1226 | | } |
| 1227 | | |
| 1228 | | /** |
| 1229 | | * Provides default nav wrapper classes. |
| 1230 | | * |
| 1231 | | * Gets the directory component nav class. |
| 1232 | | * Gets user selection Customizer options. |
| 1233 | | * |
| 1234 | | * @since 1.0.0 |
| 1235 | | * |
| 1236 | | * @return string |
| 1237 | | */ |
| 1238 | | function bp_nouveau_get_directory_type_navs_class() { |
| 1239 | | $component = sanitize_key( bp_current_component() ); |
| 1240 | | |
| 1241 | | // If component is 'blogs' we need to access options as 'Sites'. |
| 1242 | | if ('blogs' === $component) { |
| 1243 | | $component = 'sites'; |
| 1244 | | }; |
| 1245 | | |
| 1246 | | $customizer_option = sprintf( '%s_dir_tabs', $component ); |
| 1247 | | $nav_style = bp_nouveau_get_temporary_setting( $customizer_option, bp_nouveau_get_appearance_settings( $customizer_option ) ); |
| 1248 | | $tab_style = ''; |
| 1249 | | |
| 1250 | | if ( 1 === $nav_style ) { |
| 1251 | | $tab_style = $component . '-nav-tabs'; |
| 1252 | | } |
| 1253 | | |
| 1254 | | $nav_wrapper_classes = array( |
| 1255 | | sprintf( '%s-type-navs', $component ), |
| 1256 | | 'main-navs', |
| 1257 | | 'bp-navs', |
| 1258 | | 'dir-navs', |
| 1259 | | $tab_style |
| 1260 | | ); |
| 1261 | | |
| 1262 | | /** |
| 1263 | | * Filter to edit/add classes. |
| 1264 | | * |
| 1265 | | * NB: you can also directly add classes to the class attr. |
| 1266 | | * |
| 1267 | | * @since 1.0.0 |
| 1268 | | * |
| 1269 | | * @param array $nav_wrapper_classes The list of classes. |
| 1270 | | */ |
| 1271 | | $nav_wrapper_classes = (array) apply_filters( 'bp_nouveau_get_directory_type_navs_class', $nav_wrapper_classes ); |
| 1272 | | |
| 1273 | | return join( ' ', array_map( 'sanitize_html_class', $nav_wrapper_classes ) ); |
| 1274 | | } |
| 1275 | | |
| 1276 | | /** |
| 1277 | | * Displays the directory nav item list class. |
| 1278 | | * |
| 1279 | | * @since 1.0.0 |
| 1280 | | */ |
| 1281 | | function bp_nouveau_directory_list_class() { |
| 1282 | | echo esc_attr( bp_nouveau_get_directory_list_class() ); |
| 1283 | | } |
| 1284 | | |
| 1285 | | /** |
| 1286 | | * Gets the directory nav item list class. |
| 1287 | | * |
| 1288 | | * @since 1.0.0 |
| 1289 | | */ |
| 1290 | | function bp_nouveau_get_directory_list_class() { |
| 1291 | | return sanitize_html_class( sprintf( '%s-nav', bp_current_component() ) ); |
| 1292 | | } |
| 1293 | | |
| 1294 | | /** |
| 1295 | | * Displays the directory nav item object (data-bp attribute). |
| 1296 | | * |
| 1297 | | * @since 1.0.0 |
| 1298 | | */ |
| 1299 | | function bp_nouveau_directory_nav_object() { |
| 1300 | | $obj = bp_nouveau_get_directory_nav_object(); |
| 1301 | | |
| 1302 | | if ( ! is_null( $obj ) ) { |
| 1303 | | echo esc_attr( $obj ); |
| 1304 | | } |
| 1305 | | } |
| 1306 | | |
| 1307 | | /** |
| 1308 | | * Gets the directory nav item object. |
| 1309 | | * |
| 1310 | | * @see BP_Component::setup_nav(). |
| 1311 | | * |
| 1312 | | * @since 1.0.0 |
| 1313 | | * |
| 1314 | | * @return array |
| 1315 | | */ |
| 1316 | | function bp_nouveau_get_directory_nav_object() { |
| 1317 | | $nav_item = bp_nouveau()->current_nav_item; |
| 1318 | | |
| 1319 | | if ( ! $nav_item->component ) { |
| 1320 | | return null; |
| 1321 | | } |
| 1322 | | |
| 1323 | | return $nav_item->component; |
| 1324 | | } |
| 1325 | | |
| 1326 | | |
| 1327 | | /** Template tags for the single item navs ***********************************/ |
| 1328 | | |
| 1329 | | /** |
| 1330 | | * Output main BuddyPress container classes. |
| 1331 | | * |
| 1332 | | * @since 1.0.0 |
| 1333 | | * |
| 1334 | | * @return string CSS classes |
| 1335 | | */ |
| 1336 | | function bp_nouveau_container_classes() { |
| 1337 | | echo esc_attr( bp_nouveau_get_container_classes() ); |
| 1338 | | } |
| 1339 | | |
| 1340 | | /** |
| 1341 | | * Returns the main BuddyPress container classes. |
| 1342 | | * |
| 1343 | | * @since 1.0.0 |
| 1344 | | * |
| 1345 | | * @return string CSS classes |
| 1346 | | */ |
| 1347 | | function bp_nouveau_get_container_classes() { |
| 1348 | | $classes = array( 'buddypress-wrap' ); |
| 1349 | | $component = bp_current_component(); |
| 1350 | | $bp_nouveau = bp_nouveau(); |
| 1351 | | $member_type_class = ''; |
| 1352 | | |
| 1353 | | if ( bp_is_user() ) { |
| 1354 | | $customizer_option = 'user_nav_display'; |
| 1355 | | $component = 'members'; |
| 1356 | | $user_type = bp_get_member_type( bp_displayed_user_id() ); |
| 1357 | | $member_type_class = ( $user_type )? $user_type : ''; |
| 1358 | | |
| 1359 | | } elseif ( bp_is_group() ) { |
| 1360 | | $customizer_option = 'group_nav_display'; |
| 1361 | | |
| 1362 | | } elseif ( bp_is_directory() ) { |
| 1363 | | switch ( $component ) { |
| 1364 | | case 'activity': |
| 1365 | | $customizer_option = 'activity_dir_layout'; |
| 1366 | | break; |
| 1367 | | |
| 1368 | | case 'members': |
| 1369 | | $customizer_option = 'members_dir_layout'; |
| 1370 | | break; |
| 1371 | | |
| 1372 | | case 'groups': |
| 1373 | | $customizer_option = 'groups_dir_layout'; |
| 1374 | | break; |
| 1375 | | |
| 1376 | | case 'blogs': |
| 1377 | | $customizer_option = 'sites_dir_layout'; |
| 1378 | | break; |
| 1379 | | |
| 1380 | | default: |
| 1381 | | $customizer_option = ''; |
| 1382 | | break; |
| 1383 | | } |
| 1384 | | |
| 1385 | | } else { |
| 1386 | | $customizer_option = apply_filters( 'bp_nouveau_single_item_display_settings_id', '' ); |
| 1387 | | } |
| 1388 | | |
| 1389 | | if ( $member_type_class ) { |
| 1390 | | $classes[] = $member_type_class; |
| 1391 | | } |
| 1392 | | |
| 1393 | | // Provide a class token to acknowledge additional extended profile fields added to default account reg screen |
| 1394 | | if ( 'register' === bp_current_component() && bp_is_active( 'xprofile' ) && bp_nouveau_base_account_has_xprofile()) { |
| 1395 | | $classes[] = 'extended-default-reg'; |
| 1396 | | } |
| 1397 | | |
| 1398 | | // Add classes according to site owners preferences. These are options set via Customizer. |
| 1399 | | |
| 1400 | | // These are general site wide Cust options falling outside component checks |
| 1401 | | $general_settings = bp_nouveau_get_temporary_setting( 'avatar_style', bp_nouveau_get_appearance_settings( 'avatar_style' ) ); |
| 1402 | | if ( $general_settings ) { |
| 1403 | | $classes[] = 'round-avatars'; |
| 1404 | | } |
| 1405 | | |
| 1406 | | // Set via earlier switch for component check to provide correct option key. |
| 1407 | | if ( $customizer_option ) { |
| 1408 | | $layout_prefs = bp_nouveau_get_temporary_setting( $customizer_option, bp_nouveau_get_appearance_settings( $customizer_option ) ); |
| 1409 | | |
| 1410 | | if ( $layout_prefs && (int) $layout_prefs === 1 && ( bp_is_user() || bp_is_group() ) ) { |
| 1411 | | $classes[] = 'bp-single-vert-nav'; |
| 1412 | | $classes[] = 'bp-vertical-navs'; |
| 1413 | | } |
| 1414 | | |
| 1415 | | if ( $layout_prefs && bp_is_directory() ) { |
| 1416 | | $classes[] = 'bp-dir-vert-nav'; |
| 1417 | | $classes[] = 'bp-vertical-navs'; |
| 1418 | | $bp_nouveau->{$component}->directory_vertical_layout = $layout_prefs; |
| 1419 | | } |
| 1420 | | } |
| 1421 | | |
| 1422 | | $class = array_map( 'sanitize_html_class', $classes ); |
| 1423 | | |
| 1424 | | return apply_filters( 'bp_nouveau_get_container_classes', join( ' ', $class ), $classes ); |
| 1425 | | } |
| 1426 | | |
| 1427 | | /** |
| 1428 | | * Output single item nav container classes |
| 1429 | | * |
| 1430 | | * @since 1.0.0 |
| 1431 | | * |
| 1432 | | * @return string CSS classes |
| 1433 | | */ |
| 1434 | | function bp_nouveau_single_item_nav_classes() { |
| 1435 | | echo esc_attr( bp_nouveau_get_single_item_nav_classes() ); |
| 1436 | | } |
| 1437 | | |
| 1438 | | /** |
| 1439 | | * Returns the single item nav container classes |
| 1440 | | * |
| 1441 | | * @since 1.0.0 |
| 1442 | | * |
| 1443 | | * @return string CSS classes |
| 1444 | | */ |
| 1445 | | function bp_nouveau_get_single_item_nav_classes() { |
| 1446 | | $classes = array( 'main-navs', 'no-ajax', 'bp-navs', 'single-screen-navs' ); |
| 1447 | | $component = bp_current_component(); |
| 1448 | | $bp_nouveau = bp_nouveau(); |
| 1449 | | |
| 1450 | | // @todo wasn't able to get $customizer_option to pass a string to get_settings |
| 1451 | | // this is a temp workaround but differs from earlier dir approach- bad! |
| 1452 | | if ( bp_is_group() ) { |
| 1453 | | $nav_tabs = bp_nouveau_get_temporary_setting( 'group_nav_tabs', bp_nouveau_get_appearance_settings( 'group_nav_tabs' ) ); |
| 1454 | | |
| 1455 | | } elseif ( bp_is_user() ) { |
| 1456 | | $nav_tabs = bp_nouveau_get_temporary_setting( 'user_nav_tabs', bp_nouveau_get_appearance_settings( 'user_nav_tabs' ) ); |
| 1457 | | } |
| 1458 | | |
| 1459 | | if ( bp_is_group() && 1 === $nav_tabs) { |
| 1460 | | $classes[] = 'group-nav-tabs'; |
| 1461 | | } elseif ( bp_is_user() && 1 === $nav_tabs ) { |
| 1462 | | $classes[] = 'user-nav-tabs'; |
| 1463 | | } |
| 1464 | | |
| 1465 | | if ( bp_is_user() ) { |
| 1466 | | $component = 'members'; |
| 1467 | | $menu_type = 'users-nav'; |
| 1468 | | } else { |
| 1469 | | $menu_type = 'groups-nav'; |
| 1470 | | } |
| 1471 | | |
| 1472 | | $customizer_option = ( bp_is_user() )? 'user_nav_display' : 'group_nav_display'; |
| 1473 | | |
| 1474 | | $layout_prefs = bp_nouveau_get_temporary_setting( $customizer_option, bp_nouveau_get_appearance_settings( $customizer_option ) ); |
| 1475 | | |
| 1476 | | // Set the global for a later use - this is moved from the `bp_nouveau_get_container_classes() |
| 1477 | | // But was set as a check for this array class addition. |
| 1478 | | $bp_nouveau->{$component}->single_primary_nav_layout = $layout_prefs; |
| 1479 | | |
| 1480 | | if ( 1 === $layout_prefs ) { |
| 1481 | | $classes[] = 'vertical'; |
| 1482 | | } |
| 1483 | | |
| 1484 | | $classes[] = $menu_type; |
| 1485 | | $class = array_map( 'sanitize_html_class', $classes ); |
| 1486 | | |
| 1487 | | return apply_filters( 'bp_nouveau_get_single_item_nav_classes', join( ' ', $class ), $classes ); |
| 1488 | | } |
| 1489 | | |
| 1490 | | /** |
| 1491 | | * Output single item subnav container classes. |
| 1492 | | * |
| 1493 | | * @since 1.0.0 |
| 1494 | | * |
| 1495 | | * @return string CSS classes |
| 1496 | | */ |
| 1497 | | function bp_nouveau_single_item_subnav_classes() { |
| 1498 | | echo esc_attr( bp_nouveau_get_single_item_subnav_classes() ); |
| 1499 | | } |
| 1500 | | |
| 1501 | | /** |
| 1502 | | * Returns the single item subnav container classes. |
| 1503 | | * |
| 1504 | | * @since 1.0.0 |
| 1505 | | * |
| 1506 | | * @return string CSS classes |
| 1507 | | */ |
| 1508 | | function bp_nouveau_get_single_item_subnav_classes() { |
| 1509 | | $classes = array( 'bp-navs', 'bp-subnavs', 'no-ajax' ); |
| 1510 | | |
| 1511 | | // Set user or group class string |
| 1512 | | if ( bp_is_user() ) { |
| 1513 | | $classes[] = 'user-subnav'; |
| 1514 | | } |
| 1515 | | |
| 1516 | | if ( bp_is_group() ) { |
| 1517 | | $classes[] = 'group-subnav'; |
| 1518 | | } |
| 1519 | | |
| 1520 | | if ( bp_is_group() && 'send-invites' === bp_current_action() ) { |
| 1521 | | $classes[] = 'bp-invites-nav'; |
| 1522 | | } |
| 1523 | | |
| 1524 | | $customizer_option = ( bp_is_user() )? 'user_subnav_tabs' : 'group_subnav_tabs'; |
| 1525 | | $nav_tabs = bp_nouveau_get_temporary_setting( $customizer_option, bp_nouveau_get_appearance_settings( $customizer_option ) ); |
| 1526 | | |
| 1527 | | if ( bp_is_user() && 1 === $nav_tabs ) { |
| 1528 | | $classes[] = 'tabbed-links'; |
| 1529 | | } |
| 1530 | | |
| 1531 | | if ( bp_is_group() && 1 === $nav_tabs ) { |
| 1532 | | $classes[] = 'tabbed-links'; |
| 1533 | | } |
| 1534 | | |
| 1535 | | $class = array_map( 'sanitize_html_class', $classes ); |
| 1536 | | |
| 1537 | | return apply_filters( 'bp_nouveau_get_single_item_subnav_classes', join( ' ', $class ), $classes ); |
| 1538 | | } |
| 1539 | | |
| 1540 | | /** |
| 1541 | | * Output the groups create steps classes. |
| 1542 | | * |
| 1543 | | * @since 1.0.0 |
| 1544 | | * |
| 1545 | | * @return string CSS classes |
| 1546 | | */ |
| 1547 | | function bp_nouveau_groups_create_steps_classes() { |
| 1548 | | echo esc_attr( bp_nouveau_get_group_create_steps_classes() ); |
| 1549 | | } |
| 1550 | | |
| 1551 | | /** |
| 1552 | | * Returns the groups create steps customizer option choice class. |
| 1553 | | * |
| 1554 | | * @since 1.0.0 |
| 1555 | | * |
| 1556 | | * @return string CSS classes |
| 1557 | | */ |
| 1558 | | function bp_nouveau_get_group_create_steps_classes() { |
| 1559 | | $classes = array( 'bp-navs', 'group-create-links', 'no-ajax' ); |
| 1560 | | $nav_tabs = bp_nouveau_get_temporary_setting( 'groups_create_tabs', bp_nouveau_get_appearance_settings( 'groups_create_tabs' ) ); |
| 1561 | | |
| 1562 | | if ( 1 === $nav_tabs ) { |
| 1563 | | $classes[] = 'tabbed-links'; |
| 1564 | | } |
| 1565 | | |
| 1566 | | $class = array_map( 'sanitize_html_class', $classes ); |
| 1567 | | |
| 1568 | | return apply_filters( 'bp_nouveau_get_group_create_steps_classes', join( ' ', $class ), $classes ); |
| 1569 | | } |
| 1570 | | |
| 1571 | | |
| 1572 | | /** Template tags for the object search **************************************/ |
| 1573 | | |
| 1574 | | /** |
| 1575 | | * Get the search primary object |
| 1576 | | * |
| 1577 | | * @since 1.0.0 |
| 1578 | | * |
| 1579 | | * @param string $object Optional. The primary object. |
| 1580 | | * |
| 1581 | | * @return string The primary object. |
| 1582 | | */ |
| 1583 | | function bp_nouveau_get_search_primary_object( $object = '' ) { |
| 1584 | | if ( bp_is_user() ) { |
| 1585 | | $object = 'member'; |
| 1586 | | } elseif ( bp_is_group() ) { |
| 1587 | | $object = 'group'; |
| 1588 | | } elseif ( bp_is_directory() ) { |
| 1589 | | $object = 'dir'; |
| 1590 | | } else { |
| 1591 | | $object = apply_filters( 'bp_nouveau_get_search_primary_object', $object ); |
| 1592 | | } |
| 1593 | | |
| 1594 | | return $object; |
| 1595 | | } |
| 1596 | | |
| 1597 | | /** |
| 1598 | | * Get The list of search objects (primary + secondary). |
| 1599 | | * |
| 1600 | | * @since 1.0.0 |
| 1601 | | * |
| 1602 | | * @param array $objects Optional. The list of objects. |
| 1603 | | * |
| 1604 | | * @return array The list of objects. |
| 1605 | | */ |
| 1606 | | function bp_nouveau_get_search_objects( $objects = array() ) { |
| 1607 | | $primary = bp_nouveau_get_search_primary_object(); |
| 1608 | | if ( ! $primary ) { |
| 1609 | | return $objects; |
| 1610 | | } |
| 1611 | | |
| 1612 | | $objects = array( |
| 1613 | | 'primary' => $primary, |
| 1614 | | ); |
| 1615 | | |
| 1616 | | if ( 'member' === $primary || 'dir' === $primary ) { |
| 1617 | | $objects['secondary'] = bp_current_component(); |
| 1618 | | } elseif ( 'group' === $primary ) { |
| 1619 | | $objects['secondary'] = bp_current_action(); |
| 1620 | | } else { |
| 1621 | | $objects = apply_filters( 'bp_nouveau_get_search_objects', $objects ); |
| 1622 | | } |
| 1623 | | |
| 1624 | | return $objects; |
| 1625 | | } |
| 1626 | | |
| 1627 | | /** |
| 1628 | | * Output the search form container classes. |
| 1629 | | * |
| 1630 | | * @since 1.0.0 |
| 1631 | | */ |
| 1632 | | function bp_nouveau_search_container_class() { |
| 1633 | | $objects = bp_nouveau_get_search_objects(); |
| 1634 | | $class = join( '-search ', array_map( 'sanitize_html_class', $objects ) ) . '-search'; |
| 1635 | | |
| 1636 | | echo esc_attr( $class ); |
| 1637 | | } |
| 1638 | | |
| 1639 | | /** |
| 1640 | | * Output a selector ID. |
| 1641 | | * |
| 1642 | | * @since 1.0.0 |
| 1643 | | * |
| 1644 | | * @param string $suffix Optional. A string to append at the end of the ID. |
| 1645 | | * @param string $sep Optional. The separator to use between each token. |
| 1646 | | * |
| 1647 | | * @return string The selector ID. |
| 1648 | | */ |
| 1649 | | function bp_nouveau_search_selector_id( $suffix = '', $sep = '-' ) { |
| 1650 | | $id = join( $sep, array_merge( bp_nouveau_get_search_objects(), (array) $suffix ) ); |
| 1651 | | echo esc_attr( $id ); |
| 1652 | | } |
| 1653 | | |
| 1654 | | /** |
| 1655 | | * Output the name attribute of a selector. |
| 1656 | | * |
| 1657 | | * @since 1.0.0 |
| 1658 | | * |
| 1659 | | * @param string $suffix Optional. A string to append at the end of the name. |
| 1660 | | * @param string $sep Optional. The separator to use between each token. |
| 1661 | | * |
| 1662 | | * @return string The name attribute of a selector. |
| 1663 | | */ |
| 1664 | | function bp_nouveau_search_selector_name( $suffix = '', $sep = '_' ) { |
| 1665 | | $objects = bp_nouveau_get_search_objects(); |
| 1666 | | |
| 1667 | | if ( isset( $objects['secondary'] ) && ! $suffix ) { |
| 1668 | | $name = bp_core_get_component_search_query_arg( $objects['secondary'] ); |
| 1669 | | } else { |
| 1670 | | $name = join( $sep, array_merge( $objects, (array) $suffix ) ); |
| 1671 | | } |
| 1672 | | |
| 1673 | | echo esc_attr( $name ); |
| 1674 | | } |
| 1675 | | |
| 1676 | | /** |
| 1677 | | * Output the default search text for the search object |
| 1678 | | * |
| 1679 | | * @since 1.0.0 |
| 1680 | | * |
| 1681 | | * @param string $text Optional. The default search text for the search object. |
| 1682 | | * @param string $is_attr Optional. True if it's to be output inside an attribute. False Otherwise. |
| 1683 | | * |
| 1684 | | * @return string The default search text. |
| 1685 | | * |
| 1686 | | * @todo 28/09/17 added 'empty( $text )' check to $object query as it wasn't returning output as expected & not returning user set params |
| 1687 | | * This may require further examination - hnla |
| 1688 | | */ |
| 1689 | | function bp_nouveau_search_default_text( $text = '', $is_attr = true ) { |
| 1690 | | $objects = bp_nouveau_get_search_objects(); |
| 1691 | | |
| 1692 | | if ( ! empty( $objects['secondary'] ) && empty( $text ) ) { |
| 1693 | | $text = bp_get_search_default_text( $objects['secondary'] ); |
| 1694 | | } |
| 1695 | | |
| 1696 | | if ( $is_attr ) { |
| 1697 | | echo esc_attr( $text ); |
| 1698 | | } else { |
| 1699 | | echo esc_html( $text ); |
| 1700 | | } |
| 1701 | | } |
| 1702 | | |
| 1703 | | /** |
| 1704 | | * Get the search form template part and fire some do_actions if needed. |
| 1705 | | * |
| 1706 | | * @since 1.0.0 |
| 1707 | | */ |
| 1708 | | function bp_nouveau_search_form() { |
| 1709 | | bp_get_template_part( 'common/search/search-form' ); |
| 1710 | | |
| 1711 | | $objects = bp_nouveau_get_search_objects(); |
| 1712 | | if ( empty( $objects['primary'] ) || empty( $objects['secondary'] ) ) { |
| 1713 | | return; |
| 1714 | | } |
| 1715 | | |
| 1716 | | if ( 'dir' === $objects['primary'] ) { |
| 1717 | | if ( 'activity' === $objects['secondary'] ) { |
| 1718 | | /** |
| 1719 | | * Fires before the display of the activity syndication options. |
| 1720 | | * |
| 1721 | | * @since 1.2.0 (BuddyPress) |
| 1722 | | */ |
| 1723 | | do_action( 'bp_activity_syndication_options' ); |
| 1724 | | |
| 1725 | | } elseif ( 'blogs' === $objects['secondary'] ) { |
| 1726 | | /** |
| 1727 | | * Fires inside the unordered list displaying blog sub-types. |
| 1728 | | * |
| 1729 | | * @since 1.5.0 (BuddyPress) |
| 1730 | | */ |
| 1731 | | do_action( 'bp_blogs_directory_blog_sub_types' ); |
| 1732 | | |
| 1733 | | } elseif ( 'groups' === $objects['secondary'] ) { |
| 1734 | | /** |
| 1735 | | * Fires inside the groups directory group types. |
| 1736 | | * |
| 1737 | | * @since 1.2.0 (BuddyPress) |
| 1738 | | */ |
| 1739 | | do_action( 'bp_groups_directory_group_types' ); |
| 1740 | | |
| 1741 | | } elseif ( 'members' === $objects['secondary'] ) { |
| 1742 | | /** |
| 1743 | | * Fires inside the members directory member sub-types. |
| 1744 | | * |
| 1745 | | * @since 1.5.0 (BuddyPress) |
| 1746 | | */ |
| 1747 | | do_action( 'bp_members_directory_member_sub_types' ); |
| 1748 | | } |
| 1749 | | |
| 1750 | | } elseif ( 'group' === $objects['primary'] && 'activity' === $objects['secondary'] ) { |
| 1751 | | /** |
| 1752 | | * Fires inside the syndication options list, after the RSS option. |
| 1753 | | * |
| 1754 | | * @since 1.2.0 (BuddyPress) |
| 1755 | | */ |
| 1756 | | do_action( 'bp_group_activity_syndication_options' ); |
| 1757 | | } |
| 1758 | | } |
| 1759 | | |
| 1760 | | |
| 1761 | | /** Template tags for the directory & user/group screen filters **********************************/ |
| 1762 | | |
| 1763 | | /** |
| 1764 | | * Get the current component or action. |
| 1765 | | * |
| 1766 | | * If on single group screens we need to switch from component to bp_current_action() to add the correct |
| 1767 | | * IDs/labels for group/activity & similar screens. |
| 1768 | | * |
| 1769 | | * @since 1.0.0 |
| 1770 | | */ |
| 1771 | | function bp_nouveau_current_object() { |
| 1772 | | /* |
| 1773 | | * If we're looking at groups single screens we need to factor in current action |
| 1774 | | * to avoid the component check adding the wrong id for the main dir e.g 'groups' instead of 'activity'. |
| 1775 | | * We also need to check for group screens to adjust the id's for prefixes. |
| 1776 | | */ |
| 1777 | | $component = array(); |
| 1778 | | |
| 1779 | | if ( bp_is_group() ) { |
| 1780 | | $component['members_select'] = 'groups_members-order-select'; |
| 1781 | | $component['members_order_by'] = 'groups_members-order-by'; |
| 1782 | | $component['object'] = bp_current_action(); |
| 1783 | | $component['data_filter'] = 'group_' . bp_current_action(); |
| 1784 | | |
| 1785 | | } else { |
| 1786 | | $component['members_select'] = 'members-order-select'; |
| 1787 | | $component['members_order_by'] = 'members-order-by'; |
| 1788 | | $component['object'] = bp_current_component(); |
| 1789 | | $component['data_filter'] = bp_current_component(); |
| 1790 | | } |
| 1791 | | |
| 1792 | | return $component; |
| 1793 | | } |
| 1794 | | |
| 1795 | | /** |
| 1796 | | * Output data filter container's ID attribute value. |
| 1797 | | * |
| 1798 | | * @since 1.0.0 |
| 1799 | | */ |
| 1800 | | function bp_nouveau_filter_container_id() { |
| 1801 | | echo esc_attr( bp_nouveau_get_filter_container_id() ); |
| 1802 | | } |
| 1803 | | |
| 1804 | | /** |
| 1805 | | * Get data filter container's ID attribute value. |
| 1806 | | * |
| 1807 | | * @since 1.0.0 |
| 1808 | | * |
| 1809 | | * @param string |
| 1810 | | */ |
| 1811 | | function bp_nouveau_get_filter_container_id() { |
| 1812 | | $component = bp_nouveau_current_object(); |
| 1813 | | |
| 1814 | | $ids = array( |
| 1815 | | 'members' => $component['members_select'], |
| 1816 | | 'friends' => 'members-friends-select', |
| 1817 | | 'notifications' => 'notifications-filter-select', |
| 1818 | | 'activity' => 'activity-filter-select', |
| 1819 | | 'groups' => 'groups-order-select', |
| 1820 | | 'blogs' => 'blogs-order-select', |
| 1821 | | ); |
| 1822 | | |
| 1823 | | if ( isset( $ids[ $component['object'] ] ) ) { |
| 1824 | | return apply_filters( 'bp_nouveau_get_filter_container_id', $ids[ $component['object'] ] ); |
| 1825 | | } |
| 1826 | | |
| 1827 | | return ''; |
| 1828 | | } |
| 1829 | | |
| 1830 | | /** |
| 1831 | | * Output data filter's ID attribute value. |
| 1832 | | * |
| 1833 | | * @since 1.0.0 |
| 1834 | | */ |
| 1835 | | function bp_nouveau_filter_id() { |
| 1836 | | echo esc_attr( bp_nouveau_get_filter_id() ); |
| 1837 | | } |
| 1838 | | |
| 1839 | | /** |
| 1840 | | * Get data filter's ID attribute value. |
| 1841 | | * |
| 1842 | | * @since 1.0.0 |
| 1843 | | * |
| 1844 | | * @param string |
| 1845 | | */ |
| 1846 | | function bp_nouveau_get_filter_id() { |
| 1847 | | $component = bp_nouveau_current_object(); |
| 1848 | | |
| 1849 | | $ids = array( |
| 1850 | | 'members' => $component['members_order_by'], |
| 1851 | | 'friends' => 'members-friends', |
| 1852 | | 'notifications' => 'notifications-filter-by', |
| 1853 | | 'activity' => 'activity-filter-by', |
| 1854 | | 'groups' => 'groups-order-by', |
| 1855 | | 'blogs' => 'blogs-order-by', |
| 1856 | | ); |
| 1857 | | |
| 1858 | | if ( isset( $ids[ $component['object'] ] ) ) { |
| 1859 | | return apply_filters( 'bp_nouveau_get_filter_id', $ids[ $component['object'] ] ); |
| 1860 | | } |
| 1861 | | |
| 1862 | | return ''; |
| 1863 | | } |
| 1864 | | |
| 1865 | | /** |
| 1866 | | * Output data filter's label. |
| 1867 | | * |
| 1868 | | * @since 1.0.0 |
| 1869 | | */ |
| 1870 | | function bp_nouveau_filter_label() { |
| 1871 | | echo esc_html( bp_nouveau_get_filter_label() ); |
| 1872 | | } |
| 1873 | | |
| 1874 | | /** |
| 1875 | | * Get data filter's label. |
| 1876 | | * |
| 1877 | | * @since 1.0.0 |
| 1878 | | * |
| 1879 | | * @param string |
| 1880 | | */ |
| 1881 | | function bp_nouveau_get_filter_label() { |
| 1882 | | $component = bp_nouveau_current_object(); |
| 1883 | | $label = __( 'Order By:', 'buddypress' ); |
| 1884 | | |
| 1885 | | if ( 'activity' === $component['object'] || 'friends' === $component['object'] ) { |
| 1886 | | $label = __( 'Show:', 'buddypress' ); |
| 1887 | | } |
| 1888 | | |
| 1889 | | return apply_filters( 'bp_nouveau_get_filter_label', $label ); |
| 1890 | | } |
| 1891 | | |
| 1892 | | /** |
| 1893 | | * Output data filter's data-bp-filter attribute value. |
| 1894 | | * |
| 1895 | | * @since 1.0.0 |
| 1896 | | */ |
| 1897 | | function bp_nouveau_filter_component() { |
| 1898 | | $component = bp_nouveau_current_object(); |
| 1899 | | echo esc_attr( $component['data_filter'] ); |
| 1900 | | } |
| 1901 | | |
| 1902 | | /** |
| 1903 | | * Output the <option> of the data filter's <select> element. |
| 1904 | | * |
| 1905 | | * @since 1.0.0 |
| 1906 | | */ |
| 1907 | | function bp_nouveau_filter_options() { |
| 1908 | | echo bp_nouveau_get_filter_options(); // Escaped in inner functions. |
| 1909 | | } |
| 1910 | | |
| 1911 | | /** |
| 1912 | | * Get the <option> of the data filter's <select> element. |
| 1913 | | * |
| 1914 | | * @since 1.0.0 |
| 1915 | | * |
| 1916 | | * @return string |
| 1917 | | */ |
| 1918 | | function bp_nouveau_get_filter_options() { |
| 1919 | | $output = ''; |
| 1920 | | |
| 1921 | | if ( 'notifications' === bp_current_component() ) { |
| 1922 | | $output = bp_nouveau_get_notifications_filters(); |
| 1923 | | |
| 1924 | | } else { |
| 1925 | | $filters = bp_nouveau_get_component_filters(); |
| 1926 | | |
| 1927 | | foreach ( $filters as $key => $value ) { |
| 1928 | | $output .= sprintf( '<option value="%1$s">%2$s</option>%3$s', |
| 1929 | | esc_attr( $key ), |
| 1930 | | esc_html( $value ), |
| 1931 | | PHP_EOL |
| 1932 | | ); |
| 1933 | | } |
| 1934 | | } |
| 1935 | | |
| 1936 | | return $output; |
| 1937 | | } |
| 1938 | | |
| 1939 | | |
| 1940 | | /** Template tags for the Customizer ******************************************/ |
| 1941 | | |
| 1942 | | /** |
| 1943 | | * Get a link to reach a specific section into the customizer |
| 1944 | | * |
| 1945 | | * @since 1.0.0 |
| 1946 | | * |
| 1947 | | * @param array $args Optional. The argument to customize the Customizer link. |
| 1948 | | * |
| 1949 | | * @return string HTML. |
| 1950 | | */ |
| 1951 | | function bp_nouveau_get_customizer_link( $args = array() ) { |
| 1952 | | $r = bp_parse_args( $args, array( |
| 1953 | | 'capability' => 'bp_moderate', |
| 1954 | | 'object' => 'user', |
| 1955 | | 'item_id' => 0, |
| 1956 | | 'autofocus' => '', |
| 1957 | | 'text' => '', |
| 1958 | | ), 'nouveau_get_customizer_link' ); |
| 1959 | | |
| 1960 | | if ( empty( $r['capability'] ) || empty( $r['autofocus'] ) || empty( $r['text'] ) ) { |
| 1961 | | return ''; |
| 1962 | | } |
| 1963 | | |
| 1964 | | if ( ! bp_current_user_can( $r['capability'] ) ) { |
| 1965 | | return ''; |
| 1966 | | } |
| 1967 | | |
| 1968 | | $url = ''; |
| 1969 | | |
| 1970 | | if ( bp_is_user() ) { |
| 1971 | | $url = rawurlencode( bp_displayed_user_domain() ); |
| 1972 | | |
| 1973 | | } elseif ( bp_is_group() ) { |
| 1974 | | $url = rawurlencode( bp_get_group_permalink( groups_get_current_group() ) ); |
| 1975 | | |
| 1976 | | } elseif ( ! empty( $r['object'] ) && ! empty( $r['item_id'] ) ) { |
| 1977 | | if ( 'user' === $r['object'] ) { |
| 1978 | | $url = rawurlencode( bp_core_get_user_domain( $r['item_id'] ) ); |
| 1979 | | |
| 1980 | | } elseif ( 'group' === $r['object'] ) { |
| 1981 | | $group = groups_get_group( array( 'group_id' => $r['item_id'] ) ); |
| 1982 | | |
| 1983 | | if ( ! empty( $group->id ) ) { |
| 1984 | | $url = rawurlencode( bp_get_group_permalink( $group ) ); |
| 1985 | | } |
| 1986 | | } |
| 1987 | | } |
| 1988 | | |
| 1989 | | if ( ! $url ) { |
| 1990 | | return ''; |
| 1991 | | } |
| 1992 | | |
| 1993 | | $customizer_link = add_query_arg( array( |
| 1994 | | 'autofocus[section]' => $r['autofocus'], |
| 1995 | | 'url' => $url, |
| 1996 | | ), admin_url( 'customize.php' ) ); |
| 1997 | | |
| 1998 | | return sprintf( '<a href="%1$s">%2$s</a>', esc_url( $customizer_link ), esc_html( $r['text'] ) ); |
| 1999 | | } |
| 2000 | | |
| 2001 | | /** Template tags for signup forms *******************************************/ |
| 2002 | | |
| 2003 | | /** |
| 2004 | | * Fire specific hooks into the register template |
| 2005 | | * |
| 2006 | | * @since 1.0.0 |
| 2007 | | * |
| 2008 | | * @param string $when 'before' or 'after' |
| 2009 | | * @param string $prefix Use it to add terms before the hook name |
| 2010 | | */ |
| 2011 | | function bp_nouveau_signup_hook( $when = '', $prefix = '' ) { |
| 2012 | | $hook = array( 'bp' ); |
| 2013 | | |
| 2014 | | if ( ! $when ) { |
| 2015 | | $hook[] = $when; |
| 2016 | | } |
| 2017 | | |
| 2018 | | if ( ! $prefix ) { |
| 2019 | | if ( 'page' === $prefix ) { |
| 2020 | | $hook[] = 'register'; |
| 2021 | | } elseif ( 'steps' === $prefix ) { |
| 2022 | | $hook[] = 'signup'; |
| 2023 | | } |
| 2024 | | |
| 2025 | | $hook[] = $prefix; |
| 2026 | | } |
| 2027 | | |
| 2028 | | if ( 'page' !== $prefix && 'steps' !== $prefix ) { |
| 2029 | | $hook[] = 'fields'; |
| 2030 | | } |
| 2031 | | |
| 2032 | | bp_nouveau_hook( $hook ); |
| 2033 | | } |
| 2034 | | |
| 2035 | | /** |
| 2036 | | * Fire specific hooks into the activate template |
| 2037 | | * |
| 2038 | | * @since 1.0.0 |
| 2039 | | * |
| 2040 | | * @param string $when 'before' or 'after' |
| 2041 | | * @param string $prefix Use it to add terms before the hook name |
| 2042 | | */ |
| 2043 | | function bp_nouveau_activation_hook( $when = '', $suffix = '' ) { |
| 2044 | | $hook = array( 'bp' ); |
| 2045 | | |
| 2046 | | if ( ! $when ) { |
| 2047 | | $hook[] = $when; |
| 2048 | | } |
| 2049 | | |
| 2050 | | $hook[] = 'activate'; |
| 2051 | | |
| 2052 | | if ( ! $suffix ) { |
| 2053 | | $hook[] = $suffix; |
| 2054 | | } |
| 2055 | | |
| 2056 | | if ( 'page' === $suffix ) { |
| 2057 | | $hook[2] = 'activation'; |
| 2058 | | } |
| 2059 | | |
| 2060 | | bp_nouveau_hook( $hook ); |
| 2061 | | } |
| 2062 | | |
| 2063 | | /** |
| 2064 | | * Output the signup form for the requested section |
| 2065 | | * |
| 2066 | | * @since 1.0.0 |
| 2067 | | * |
| 2068 | | * @param string $section Optional. The section of fields to get 'account_details' or 'blog_details'. |
| 2069 | | * Default: 'account_details'. |
| 2070 | | */ |
| 2071 | | function bp_nouveau_signup_form( $section = 'account_details' ) { |
| 2072 | | $fields = bp_nouveau_get_signup_fields( $section ); |
| 2073 | | if ( ! $fields ) { |
| 2074 | | return; |
| 2075 | | } |
| 2076 | | |
| 2077 | | foreach ( $fields as $name => $attributes ) { |
| 2078 | | list( $label, $required, $value, $attribute_type, $type, $class ) = array_values( $attributes ); |
| 2079 | | |
| 2080 | | if ( $required ) { |
| 2081 | | $required = ' ' . _x( '(required)', 'signup required field', 'buddypress' ); |
| 2082 | | } |
| 2083 | | |
| 2084 | | // Text fields are using strings, radios are using their inputs |
| 2085 | | $label_output = '<label for="%1$s">%2$s</label>'; |
| 2086 | | $id = $name; |
| 2087 | | |
| 2088 | | // Output the label for regular fields |
| 2089 | | if ( 'radio' !== $type ) { |
| 2090 | | printf( $label_output, esc_attr( $name ), esc_html( sprintf( $label, $required ) ) ); |
| 2091 | | |
| 2092 | | if ( ! empty( $value ) && is_callable( $value ) ) { |
| 2093 | | $value = call_user_func( $value ); |
| 2094 | | } |
| 2095 | | |
| 2096 | | // Handle the specific case of Site's privacy differently |
| 2097 | | } elseif ( 'signup_blog_privacy_private' !== $name ) { |
| 2098 | | ?> |
| 2099 | | <span class="label"> |
| 2100 | | <?php esc_html_e( 'I would like my site to appear in search engines, and in public listings around this network.', 'buddypress' ); ?> |
| 2101 | | </span> |
| 2102 | | <?php |
| 2103 | | } |
| 2104 | | |
| 2105 | | // Set the additional attributes |
| 2106 | | if ( $attribute_type ) { |
| 2107 | | $existing_attributes = array(); |
| 2108 | | |
| 2109 | | if ( ! empty( $required ) ) { |
| 2110 | | $existing_attributes = array( 'aria-required' => 'true' ); |
| 2111 | | |
| 2112 | | /** |
| 2113 | | * The blog section is hidden, so let's avoid a browser warning |
| 2114 | | * and deal with the Blog section in Javascript. |
| 2115 | | */ |
| 2116 | | if ( $section !== 'blog_details' ) { |
| 2117 | | $existing_attributes['required'] = 'required'; |
| 2118 | | } |
| 2119 | | } |
| 2120 | | |
| 2121 | | $attribute_type = ' ' . bp_get_form_field_attributes( $attribute_type, $existing_attributes ); |
| 2122 | | } |
| 2123 | | |
| 2124 | | // Specific case for Site's privacy |
| 2125 | | if ( 'signup_blog_privacy_public' === $name || 'signup_blog_privacy_private' === $name ) { |
| 2126 | | $name = 'signup_blog_privacy'; |
| 2127 | | $submitted = bp_get_signup_blog_privacy_value(); |
| 2128 | | |
| 2129 | | if ( ! $submitted ) { |
| 2130 | | $submitted = 'public'; |
| 2131 | | } |
| 2132 | | |
| 2133 | | $attribute_type = ' ' . checked( $value, $submitted, false ); |
| 2134 | | } |
| 2135 | | |
| 2136 | | if ( ! empty( $class ) ) { |
| 2137 | | // In case people are adding classes.. |
| 2138 | | $classes = explode( ' ', $class ); |
| 2139 | | $class = ' class="' . esc_attr( join( ' ', array_map( 'sanitize_html_class', $classes ) ) ) . '"'; |
| 2140 | | } |
| 2141 | | |
| 2142 | | // Do not fire the do_action to display errors for the private radio. |
| 2143 | | if ( 'private' !== $value ) { |
| 2144 | | /** |
| 2145 | | * Fires and displays any member registration field errors. |
| 2146 | | * |
| 2147 | | * @since 1.1.0 (BuddyPress) |
| 2148 | | */ |
| 2149 | | do_action( "bp_{$name}_errors" ); |
| 2150 | | } |
| 2151 | | |
| 2152 | | // Set the input. |
| 2153 | | $field_output = sprintf( '<input type="%1$s" name="%2$s" id="%3$s" %4$s value="%5$s" %6$s />', |
| 2154 | | esc_attr( $type ), |
| 2155 | | esc_attr( $name ), |
| 2156 | | esc_attr( $id ), |
| 2157 | | $class, // Constructed safely above. |
| 2158 | | esc_attr( $value ), |
| 2159 | | $attribute_type // Constructed safely above. |
| 2160 | | ); |
| 2161 | | |
| 2162 | | // Not a radio, let's output the field |
| 2163 | | if ( 'radio' !== $type ) { |
| 2164 | | if ( 'signup_blog_url' !== $name ) { |
| 2165 | | print( $field_output ); // Constructed safely above. |
| 2166 | | |
| 2167 | | // If it's the signup blog url, it's specific to Multisite config. |
| 2168 | | } elseif ( is_subdomain_install() ) { |
| 2169 | | // Constructed safely above. |
| 2170 | | printf( '%1$s %2$s . %3$s', |
| 2171 | | is_ssl() ? 'https://' : 'http://', |
| 2172 | | $field_output, |
| 2173 | | bp_signup_get_subdomain_base() |
| 2174 | | ); |
| 2175 | | |
| 2176 | | // Subfolders! |
| 2177 | | } else { |
| 2178 | | printf( '%1$s %2$s', |
| 2179 | | home_url( '/' ), |
| 2180 | | $field_output // Constructed safely above. |
| 2181 | | ); |
| 2182 | | } |
| 2183 | | |
| 2184 | | // It's a radio, let's output the field inside the label |
| 2185 | | } else { |
| 2186 | | // $label_output and $field_output are constructed safely above. |
| 2187 | | printf( $label_output, esc_attr( $name ), $field_output . ' ' . esc_html( $label ) ); |
| 2188 | | } |
| 2189 | | |
| 2190 | | // Password strength is restricted to the signup_password field |
| 2191 | | if ( 'signup_password' === $name ) : ?> |
| 2192 | | <div id="pass-strength-result"></div> |
| 2193 | | <?php endif ; |
| 2194 | | } |
| 2195 | | |
| 2196 | | /** |
| 2197 | | * Fires and displays any extra member registration details fields. |
| 2198 | | * |
| 2199 | | * @since 1.9.0 (BuddyPress) |
| 2200 | | */ |
| 2201 | | do_action( "bp_{$section}_fields" ); |
| 2202 | | } |
| 2203 | | |
| 2204 | | /** |
| 2205 | | * Output a submit button and the nonce for the requested action. |
| 2206 | | * |
| 2207 | | * @since 1.0.0 |
| 2208 | | * |
| 2209 | | * @param string $action The action to get the submit button for. Required. |
| 2210 | | */ |
| 2211 | | function bp_nouveau_submit_button( $action ) { |
| 2212 | | $submit_data = bp_nouveau_get_submit_button( $action ); |
| 2213 | | if ( empty( $submit_data['attributes'] ) || empty( $submit_data['nonce'] ) ) { |
| 2214 | | return; |
| 2215 | | } |
| 2216 | | |
| 2217 | | if ( ! empty( $submit_data['before'] ) ) { |
| 2218 | | do_action( $submit_data['before'] ); |
| 2219 | | } |
| 2220 | | |
| 2221 | | // Output the submit button. |
| 2222 | | printf( ' |
| 2223 | | <div class="submit"> |
| 2224 | | <input type="submit" %s/> |
| 2225 | | </div>', |
| 2226 | | bp_get_form_field_attributes( 'submit', $submit_data['attributes'] ) // Safe. |
| 2227 | | ); |
| 2228 | | |
| 2229 | | wp_nonce_field( $submit_data['nonce'] ); |
| 2230 | | |
| 2231 | | if ( ! empty( $submit_data['after'] ) ) { |
| 2232 | | do_action( $submit_data['after'] ); |
| 2233 | | } |
| 2234 | | } |
| | 3 | Thanks @keshabee removed as this is a little too much to display and have the file and function locally. |