[ Index ] |
PHP Cross Reference of BuddyPress |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * BuddyPress XProfile Template Tags. 4 * 5 * @package BuddyPress 6 * @subpackage XProfileTemplate 7 * @since 1.5.0 8 */ 9 10 // Exit if accessed directly. 11 defined( 'ABSPATH' ) || exit; 12 13 /** 14 * Query for XProfile groups and fields. 15 * 16 * @since 1.0.0 17 * @since 2.4.0 Introduced `$member_type` argument. 18 * @since 8.0.0 Introduced `$hide_field_types` & `$signup_fields_only` arguments. 19 * 20 * @global object $profile_template 21 * @see BP_XProfile_Group::get() for full description of `$args` array. 22 * 23 * @param array|string $args { 24 * Array of arguments. See BP_XProfile_Group::get() for full description. Those arguments whose defaults differ 25 * from that method are described here: 26 * @type int $user_id Default: ID of the displayed user. 27 * @type string|array $member_type Default: 'any'. 28 * @type int|bool $profile_group_id Default: false. 29 * @type bool $hide_empty_groups Default: true. 30 * @type bool $hide_empty_fields Defaults to true on the Dashboard, on a user's Edit Profile page, 31 * or during registration. Otherwise false. 32 * @type bool $fetch_fields Default: true. 33 * @type bool $fetch_field_data Default: true. 34 * @type bool $fetch_visibility_level Defaults to true when an admin is viewing a profile, or when a user is 35 * viewing her own profile, or during registration. Otherwise false. 36 * @type int[]|bool $exclude_groups Default: false. 37 * @type int[]|bool $exclude_fields Default: false. 38 * @type string[] $hide_field_types Default: empty array. 39 * @type bool $signup_fields_only Default: false. 40 * @type bool $update_meta_cache Default: true. 41 * } 42 * 43 * @return bool 44 */ 45 function bp_has_profile( $args = '' ) { 46 global $profile_template; 47 48 // Only show empty fields if we're on the Dashboard, or we're on a user's 49 // profile edit page, or this is a registration page. 50 $hide_empty_fields_default = ( ! is_network_admin() && ! is_admin() && ! bp_is_user_profile_edit() && ! bp_is_register_page() ); 51 52 // We only need to fetch visibility levels when viewing your own profile. 53 if ( bp_is_my_profile() || bp_current_user_can( 'bp_moderate' ) || bp_is_register_page() ) { 54 $fetch_visibility_level_default = true; 55 } else { 56 $fetch_visibility_level_default = false; 57 } 58 59 // Parse arguments. 60 $r = bp_parse_args( 61 $args, 62 array( 63 'user_id' => bp_displayed_user_id(), 64 'member_type' => 'any', 65 'profile_group_id' => false, 66 'hide_empty_groups' => true, 67 'hide_empty_fields' => $hide_empty_fields_default, 68 'fetch_fields' => true, 69 'fetch_field_data' => true, 70 'fetch_visibility_level' => $fetch_visibility_level_default, 71 'exclude_groups' => false, // Comma-separated list of profile field group IDs to exclude. 72 'exclude_fields' => false, // Comma-separated list of profile field IDs to exclude. 73 'hide_field_types' => array(), // List of field types to hide from profile fields loop. 74 'signup_fields_only' => false, // Whether to only return signup fields. 75 'update_meta_cache' => true, 76 ), 77 'has_profile' 78 ); 79 80 // Populate the template loop global. 81 $profile_template = new BP_XProfile_Data_Template( $r ); 82 83 /** 84 * Filters whether or not a group has a profile to display. 85 * 86 * @since 1.1.0 87 * @since 2.6.0 Added the `$r` parameter. 88 * 89 * @param bool $has_groups Whether or not there are group profiles to display. 90 * @param string $profile_template Current profile template being used. 91 * @param array $r Array of arguments passed into the BP_XProfile_Data_Template class. 92 */ 93 return apply_filters( 'bp_has_profile', $profile_template->has_groups(), $profile_template, $r ); 94 } 95 96 /** 97 * Start off the profile groups. 98 * 99 * @since 1.0.0 100 * 101 * @return mixed 102 */ 103 function bp_profile_groups() { 104 global $profile_template; 105 return $profile_template->profile_groups(); 106 } 107 108 /** 109 * Set up the profile groups. 110 * 111 * @since 1.0.0 112 * 113 * @return mixed 114 */ 115 function bp_the_profile_group() { 116 global $profile_template; 117 return $profile_template->the_profile_group(); 118 } 119 120 /** 121 * Whether or not the group has fields to display. 122 * 123 * @since 1.0.0 124 * 125 * @return mixed 126 */ 127 function bp_profile_group_has_fields() { 128 global $profile_template; 129 return $profile_template->has_fields(); 130 } 131 132 /** 133 * Output the class attribute for a field. 134 * 135 * @since 1.0.0 136 * 137 * @param mixed $class Extra classes to append to class attribute. 138 * Pass multiple class names as an array or 139 * space-delimited string. 140 */ 141 function bp_field_css_class( $class = false ) { 142 echo bp_get_field_css_class( $class ); 143 } 144 145 /** 146 * Return the class attribute for a field. 147 * 148 * @since 1.1.0 149 * 150 * @param string|bool $class Extra classes to append to class attribute. 151 * @return string 152 */ 153 function bp_get_field_css_class( $class = false ) { 154 global $profile_template; 155 156 $css_classes = array(); 157 158 if ( ! empty( $class ) ) { 159 if ( ! is_array( $class ) ) { 160 $class = preg_split( '#\s+#', $class ); 161 } 162 $css_classes = array_map( 'sanitize_html_class', $class ); 163 } 164 165 // Set a class with the field ID. 166 $css_classes[] = 'field_' . $profile_template->field->id; 167 168 // Set a class with the field name (sanitized). 169 $css_classes[] = 'field_' . sanitize_title( $profile_template->field->name ); 170 171 // Set a class indicating whether the field is required or optional. 172 if ( ! empty( $profile_template->field->is_required ) ) { 173 $css_classes[] = 'required-field'; 174 } else { 175 $css_classes[] = 'optional-field'; 176 } 177 178 // Add the field visibility level. 179 $css_classes[] = 'visibility-' . esc_attr( bp_get_the_profile_field_visibility_level() ); 180 181 if ( $profile_template->current_field % 2 == 1 ) { 182 $css_classes[] = 'alt'; 183 } 184 185 $css_classes[] = 'field_type_' . sanitize_title( $profile_template->field->type ); 186 187 /** 188 * Filters the field classes to be applied to a field. 189 * 190 * @since 1.1.0 191 * 192 * @param array $css_classes Array of classes to be applied to field. Passed by reference. 193 */ 194 $css_classes = apply_filters_ref_array( 'bp_field_css_classes', array( &$css_classes ) ); 195 196 /** 197 * Filters the class HTML attribute to be used on a field. 198 * 199 * @since 1.1.0 200 * 201 * @param string $value class HTML attribute with imploded classes. 202 */ 203 return apply_filters( 'bp_get_field_css_class', ' class="' . implode( ' ', $css_classes ) . '"' ); 204 } 205 206 /** 207 * Whether or not the XProfile field has data to display. 208 * 209 * @since 1.0.0 210 * 211 * @global object $profile_template 212 * 213 * @return mixed 214 */ 215 function bp_field_has_data() { 216 global $profile_template; 217 218 /** 219 * Filters whether or not the XProfile field has data to display. 220 * 221 * @since 2.8.0 222 * 223 * @param bool $value Whether or not there is data to display. 224 * @param object $profile_template Profile template object. 225 * @param string $value Profile field being displayed. 226 * @param string $value Profile field ID being displayed. 227 */ 228 return apply_filters( 'bp_field_has_data', $profile_template->field_has_data, $profile_template, $profile_template->field, $profile_template->field->id ); 229 } 230 231 /** 232 * Whether or not the XProfile field has public data to display. 233 * 234 * @since 1.0.0 235 * 236 * @global object $profile_template 237 * 238 * @return bool 239 */ 240 function bp_field_has_public_data() { 241 global $profile_template; 242 243 /** 244 * Filters whether or not the XProfile field has public data to display. 245 * 246 * @since 2.8.0 247 * 248 * @param bool $value Whether or not there is public data to display. 249 * @param object $profile_template Profile template object. 250 * @param string $value Profile field being displayed. 251 * @param string $value Profile field ID being displayed. 252 */ 253 return apply_filters( 'bp_field_has_public_data', ( ! empty( $profile_template->field_has_data ) ), $profile_template, $profile_template->field, $profile_template->field->id ); 254 } 255 256 /** 257 * Output the XProfile group ID. 258 * 259 * @since 1.0.0 260 */ 261 function bp_the_profile_group_id() { 262 echo bp_get_the_profile_group_id(); 263 } 264 265 /** 266 * Return the XProfile group ID. 267 * 268 * @since 1.1.0 269 * 270 * @return int 271 */ 272 function bp_get_the_profile_group_id() { 273 global $group; 274 275 /** 276 * Filters the XProfile group ID. 277 * 278 * @since 1.1.0 279 * 280 * @param int $id ID for the profile group. 281 */ 282 return (int) apply_filters( 'bp_get_the_profile_group_id', $group->id ); 283 } 284 285 /** 286 * Output the XProfile group name. 287 * 288 * @since 1.0.0 289 */ 290 function bp_the_profile_group_name() { 291 echo bp_get_the_profile_group_name(); 292 } 293 294 /** 295 * Return the XProfile group name. 296 * 297 * @since 1.0.0 298 * 299 * @return string 300 */ 301 function bp_get_the_profile_group_name() { 302 global $group; 303 304 /** 305 * Filters the XProfile group name. 306 * 307 * @since 1.0.0 308 * 309 * @param string $name Name for the profile group. 310 */ 311 return apply_filters( 'bp_get_the_profile_group_name', $group->name ); 312 } 313 314 /** 315 * Output the XProfile group slug. 316 * 317 * @since 1.1.0 318 */ 319 function bp_the_profile_group_slug() { 320 echo bp_get_the_profile_group_slug(); 321 } 322 323 /** 324 * Return the XProfile group slug. 325 * 326 * @since 1.1.0 327 * 328 * @return string 329 */ 330 function bp_get_the_profile_group_slug() { 331 global $group; 332 333 /** 334 * Filters the XProfile group slug. 335 * 336 * @since 1.1.0 337 * 338 * @param string $value Slug for the profile group. 339 */ 340 return apply_filters( 'bp_get_the_profile_group_slug', sanitize_title( $group->name ) ); 341 } 342 343 /** 344 * Output the XProfile group description. 345 * 346 * @since 1.0.0 347 */ 348 function bp_the_profile_group_description() { 349 echo bp_get_the_profile_group_description(); 350 } 351 352 /** 353 * Return the XProfile group description. 354 * 355 * @since 1.0.0 356 * 357 * @return string 358 */ 359 function bp_get_the_profile_group_description() { 360 global $group; 361 362 /** 363 * Filters the XProfile group description. 364 * 365 * @since 1.0.0 366 * 367 * @param string $description Description for the profile group. 368 */ 369 return apply_filters( 'bp_get_the_profile_group_description', $group->description ); 370 } 371 372 /** 373 * Output the XProfile group edit form action. 374 * 375 * @since 1.1.0 376 */ 377 function bp_the_profile_group_edit_form_action() { 378 echo bp_get_the_profile_group_edit_form_action(); 379 } 380 381 /** 382 * Return the XProfile group edit form action. 383 * 384 * @since 1.1.0 385 * 386 * @return string 387 */ 388 function bp_get_the_profile_group_edit_form_action() { 389 global $group; 390 391 // Build the form action URL. 392 $form_action = trailingslashit( bp_displayed_user_domain() . bp_get_profile_slug() . '/edit/group/' . $group->id ); 393 394 /** 395 * Filters the action for the XProfile group edit form. 396 * 397 * @since 1.1.0 398 * 399 * @param string $value URL for the action attribute on the 400 * profile group edit form. 401 */ 402 return apply_filters( 'bp_get_the_profile_group_edit_form_action', $form_action ); 403 } 404 405 /** 406 * Output the XProfile group field IDs. 407 * 408 * @since 1.1.0 409 */ 410 function bp_the_profile_group_field_ids() { 411 echo bp_get_the_profile_group_field_ids(); 412 } 413 414 /** 415 * Return the XProfile group field IDs. 416 * 417 * @since 1.1.0 418 * 419 * @return string 420 */ 421 function bp_get_the_profile_group_field_ids() { 422 global $group; 423 424 $field_ids = ''; 425 426 if ( !empty( $group->fields ) ) { 427 foreach ( (array) $group->fields as $field ) { 428 $field_ids .= $field->id . ','; 429 } 430 } 431 432 return substr( $field_ids, 0, -1 ); 433 } 434 435 /** 436 * Output a comma-separated list of field IDs that are to be submitted on profile edit. 437 * 438 * @since 2.1.0 439 */ 440 function bp_the_profile_field_ids() { 441 echo bp_get_the_profile_field_ids(); 442 } 443 /** 444 * Generate a comma-separated list of field IDs that are to be submitted on profile edit. 445 * 446 * @since 2.1.0 447 * 448 * @return string 449 */ 450 function bp_get_the_profile_field_ids() { 451 global $profile_template; 452 453 $field_ids = array(); 454 foreach ( $profile_template->groups as $group ) { 455 if ( ! empty( $group->fields ) ) { 456 $field_ids = array_merge( $field_ids, wp_list_pluck( $group->fields, 'id' ) ); 457 } 458 } 459 460 $field_ids = implode( ',', wp_parse_id_list( $field_ids ) ); 461 462 /** 463 * Filters the comma-separated list of field IDs. 464 * 465 * @since 2.1.0 466 * 467 * @param string $field_ids Comma-separated field IDs. 468 */ 469 return apply_filters( 'bp_get_the_profile_field_ids', $field_ids ); 470 } 471 472 /** 473 * Return the XProfile fields. 474 * 475 * @since 1.0.0 476 * 477 * @return mixed 478 */ 479 function bp_profile_fields() { 480 global $profile_template; 481 return $profile_template->profile_fields(); 482 } 483 484 /** 485 * Sets up the XProfile field. 486 * 487 * @since 1.0.0 488 * 489 * @return mixed 490 */ 491 function bp_the_profile_field() { 492 global $profile_template; 493 return $profile_template->the_profile_field(); 494 } 495 496 /** 497 * Output the XProfile field ID. 498 * 499 * @since 1.1.0 500 */ 501 function bp_the_profile_field_id() { 502 echo bp_get_the_profile_field_id(); 503 } 504 505 /** 506 * Return the XProfile field ID. 507 * 508 * @since 1.1.0 509 * 510 * @return int 511 */ 512 function bp_get_the_profile_field_id() { 513 global $field; 514 515 /** 516 * Filters the XProfile field ID. 517 * 518 * @since 1.1.0 519 * 520 * @param int $id ID for the profile field. 521 */ 522 return (int) apply_filters( 'bp_get_the_profile_field_id', $field->id ); 523 } 524 525 /** 526 * Outputs the XProfile field name. 527 * 528 * @since 1.0.0 529 */ 530 function bp_the_profile_field_name() { 531 echo bp_get_the_profile_field_name(); 532 } 533 534 /** 535 * Returns the XProfile field name. 536 * 537 * @since 1.0.0 538 * 539 * @return string 540 */ 541 function bp_get_the_profile_field_name() { 542 global $field; 543 544 /** 545 * Filters the XProfile field name. 546 * 547 * @since 1.0.0 548 * 549 * @param string $name Name for the profile field. 550 */ 551 return apply_filters( 'bp_get_the_profile_field_name', $field->name ); 552 } 553 554 /** 555 * Outputs the XProfile field value. 556 * 557 * @since 1.0.0 558 */ 559 function bp_the_profile_field_value() { 560 echo bp_get_the_profile_field_value(); 561 } 562 563 /** 564 * Returns the XProfile field value. 565 * 566 * @since 1.0.0 567 * 568 * @return string 569 */ 570 function bp_get_the_profile_field_value() { 571 global $field; 572 573 $field->data->value = bp_unserialize_profile_field( $field->data->value ); 574 575 /** 576 * Filters the XProfile field value. 577 * 578 * @since 1.0.0 579 * 580 * @param string $value Value for the profile field. 581 * @param string $type Type for the profile field. 582 * @param int $id ID for the profile field. 583 */ 584 return apply_filters( 'bp_get_the_profile_field_value', $field->data->value, $field->type, $field->id ); 585 } 586 587 /** 588 * Outputs the XProfile field edit value. 589 * 590 * @since 1.1.0 591 */ 592 function bp_the_profile_field_edit_value() { 593 echo bp_get_the_profile_field_edit_value(); 594 } 595 596 /** 597 * Returns the XProfile field edit value. 598 * 599 * @since 1.1.0 600 * 601 * @return string 602 */ 603 function bp_get_the_profile_field_edit_value() { 604 global $field; 605 606 // Make sure field data object exists. 607 if ( ! isset( $field->data ) ) { 608 $field->data = new stdClass; 609 } 610 611 // Default to empty value. 612 if ( ! isset( $field->data->value ) ) { 613 $field->data->value = ''; 614 } 615 616 // Was a new value posted? If so, use it instead. 617 if ( isset( $_POST['field_' . $field->id] ) ) { 618 619 // This is sanitized via the filter below (based on the field type). 620 $field->data->value = $_POST['field_' . $field->id]; 621 } 622 623 /** 624 * Filters the XProfile field edit value. 625 * 626 * @since 1.1.0 627 * 628 * @param string $field_value Current field edit value. 629 * @param string $type Type for the profile field. 630 * @param int $id ID for the profile field. 631 */ 632 return apply_filters( 'bp_get_the_profile_field_edit_value', $field->data->value, $field->type, $field->id ); 633 } 634 635 /** 636 * Outputs the XProfile field type. 637 * 638 * @since 1.1.0 639 */ 640 function bp_the_profile_field_type() { 641 echo bp_get_the_profile_field_type(); 642 } 643 644 /** 645 * Returns the XProfile field type. 646 * 647 * @since 1.1.0 648 * 649 * @return string 650 */ 651 function bp_get_the_profile_field_type() { 652 global $field; 653 654 /** 655 * Filters the XProfile field type. 656 * 657 * @since 1.1.0 658 * 659 * @param string $type Type for the profile field. 660 */ 661 return apply_filters( 'bp_the_profile_field_type', $field->type ); 662 } 663 664 /** 665 * Outputs the XProfile field description. 666 * 667 * @since 1.1.0 668 */ 669 function bp_the_profile_field_description() { 670 echo bp_get_the_profile_field_description(); 671 } 672 673 /** 674 * Returns the XProfile field description. 675 * 676 * @since 1.1.0 677 * 678 * @return string 679 */ 680 function bp_get_the_profile_field_description() { 681 global $field; 682 683 /** 684 * Filters the XProfile field description. 685 * 686 * @since 1.1.0 687 * 688 * @param string $description Description for the profile field. 689 */ 690 return apply_filters( 'bp_get_the_profile_field_description', $field->description ); 691 } 692 693 /** 694 * Outputs the XProfile field input name. 695 * 696 * @since 1.1.0 697 */ 698 function bp_the_profile_field_input_name() { 699 echo bp_get_the_profile_field_input_name(); 700 } 701 702 /** 703 * Returns the XProfile field input name. 704 * 705 * @since 1.1.0 706 * 707 * @return string 708 */ 709 function bp_get_the_profile_field_input_name() { 710 global $field; 711 712 /** 713 * Filters the profile field input name. 714 * 715 * @since 1.1.0 716 * 717 * @param string $value Value used for the name attribute on an input. 718 */ 719 return apply_filters( 'bp_get_the_profile_field_input_name', 'field_' . $field->id ); 720 } 721 722 /** 723 * Returns the action name for any signup errors related to this profile field. 724 * 725 * In the registration templates, signup errors are pulled from the global 726 * object and rendered at actions that look like 'bp_field_12_errors'. This 727 * function allows the action name to be easily concatenated and called in the 728 * following fashion: 729 * do_action( bp_get_the_profile_field_errors_action() ); 730 * 731 * @since 1.8.0 732 * 733 * @return string The _errors action name corresponding to this profile field. 734 */ 735 function bp_get_the_profile_field_errors_action() { 736 global $field; 737 return 'bp_field_' . $field->id . '_errors'; 738 } 739 740 /** 741 * Displays field options HTML for field types of 'selectbox', 'multiselectbox', 742 * 'radio', 'checkbox', and 'datebox'. 743 * 744 * @since 1.1.0 745 * 746 * @param array $args Specify type for datebox. Allowed 'day', 'month', 'year'. 747 */ 748 function bp_the_profile_field_options( $args = array() ) { 749 echo bp_get_the_profile_field_options( $args ); 750 } 751 /** 752 * Retrieves field options HTML for field types of 'selectbox', 'multiselectbox', 'radio', 'checkbox', and 'datebox'. 753 * 754 * @since 1.1.0 755 * 756 * 757 * @param array $args { 758 * Array of optional arguments. 759 * @type string|bool $type Type of datebox. False if it's not a 760 * datebox, otherwise 'day, 'month', or 'year'. Default: false. 761 * @type int $user_id ID of the user whose profile values should be 762 * used when rendering options. Default: displayed user. 763 * } 764 * 765 * @return string $vaue Field options markup. 766 */ 767 function bp_get_the_profile_field_options( $args = array() ) { 768 global $field; 769 770 $args = bp_parse_args( 771 $args, 772 array( 773 'type' => false, 774 'user_id' => bp_displayed_user_id(), 775 ), 776 'get_the_profile_field_options' 777 ); 778 779 /** 780 * In some cases, the $field global is not an instantiation of the BP_XProfile_Field class. 781 * However, we have to make sure that all data originally in $field gets merged back in, after reinstantiation. 782 */ 783 if ( ! method_exists( $field, 'get_children' ) ) { 784 $field_obj = xprofile_get_field( $field->id, null, false ); 785 786 foreach ( $field as $field_prop => $field_prop_value ) { 787 if ( ! isset( $field_obj->{$field_prop} ) ) { 788 $field_obj->{$field_prop} = $field_prop_value; 789 } 790 } 791 792 $field = $field_obj; 793 } 794 795 ob_start(); 796 $field->type_obj->edit_field_options_html( $args ); 797 $html = ob_get_contents(); 798 ob_end_clean(); 799 800 return $html; 801 } 802 803 /** 804 * Render whether or not a profile field is required. 805 * 806 * @since 1.1.0 807 */ 808 function bp_the_profile_field_is_required() { 809 echo bp_get_the_profile_field_is_required(); 810 } 811 812 /** 813 * Return whether or not a profile field is required. 814 * 815 * @since 1.1.0 816 * 817 * @return bool 818 */ 819 function bp_get_the_profile_field_is_required() { 820 global $field; 821 822 $retval = false; 823 824 if ( isset( $field->is_required ) ) { 825 $retval = $field->is_required; 826 } 827 828 /** 829 * Filters whether or not a profile field is required. 830 * 831 * @since 1.1.0 832 * @since 2.8.0 Added field ID. 833 * 834 * @param bool $retval Whether or not the field is required. 835 * @param string $value Field ID that may be required. 836 */ 837 return (bool) apply_filters( 'bp_get_the_profile_field_is_required', $retval, $field->id ); 838 } 839 840 /** 841 * Output the visibility level of this field. 842 * 843 * @since 1.6.0 844 */ 845 function bp_the_profile_field_visibility_level() { 846 echo bp_get_the_profile_field_visibility_level(); 847 } 848 849 /** 850 * Return the visibility level of this field. 851 * 852 * @since 1.6.0 853 * 854 * @return string 855 */ 856 function bp_get_the_profile_field_visibility_level() { 857 global $field; 858 859 // On the registration page, values stored in POST should take 860 // precedence over default visibility, so that submitted values 861 // are not lost on failure. 862 if ( bp_is_register_page() && ! empty( $_POST['field_' . $field->id . '_visibility'] ) ) { 863 $retval = esc_attr( $_POST['field_' . $field->id . '_visibility'] ); 864 } else { 865 $retval = ! empty( $field->visibility_level ) ? $field->visibility_level : 'public'; 866 } 867 868 /** 869 * Filters the profile field visibility level. 870 * 871 * @since 1.6.0 872 * 873 * @param string $retval Field visibility level. 874 */ 875 return apply_filters( 'bp_get_the_profile_field_visibility_level', $retval ); 876 } 877 878 /** 879 * Echo the visibility level label of this field. 880 * 881 * @since 1.6.0 882 */ 883 function bp_the_profile_field_visibility_level_label() { 884 echo bp_get_the_profile_field_visibility_level_label(); 885 } 886 887 /** 888 * Return the visibility level label of this field. 889 * 890 * @since 1.6.0 891 * 892 * @return string 893 */ 894 function bp_get_the_profile_field_visibility_level_label() { 895 global $field; 896 897 // On the registration page, values stored in POST should take 898 // precedence over default visibility, so that submitted values 899 // are not lost on failure. 900 if ( bp_is_register_page() && ! empty( $_POST['field_' . $field->id . '_visibility'] ) ) { 901 $level = esc_html( $_POST['field_' . $field->id . '_visibility'] ); 902 } else { 903 $level = ! empty( $field->visibility_level ) ? $field->visibility_level : 'public'; 904 } 905 906 $fields = bp_xprofile_get_visibility_levels(); 907 908 /** 909 * Filters the profile field visibility level label. 910 * 911 * @since 1.6.0 912 * @since 2.6.0 Added the `$level` parameter. 913 * 914 * @param string $retval Field visibility level label. 915 * @param string $level Field visibility level. 916 */ 917 return apply_filters( 'bp_get_the_profile_field_visibility_level_label', $fields[ $level ]['label'], $level ); 918 } 919 920 /** 921 * Return unserialized profile field data, and combine any array items into a 922 * comma-separated string. 923 * 924 * @since 1.0.0 925 * 926 * @param string $value Content to maybe unserialize. 927 * @return string 928 */ 929 function bp_unserialize_profile_field( $value ) { 930 if ( is_serialized($value) ) { 931 $field_value = @unserialize($value); 932 $field_value = implode( ', ', $field_value ); 933 return $field_value; 934 } 935 936 return $value; 937 } 938 939 /** 940 * Output XProfile field data. 941 * 942 * @since 1.2.0 943 * 944 * @param string|array $args Array of arguments for field data. See {@link bp_get_profile_field_data} 945 */ 946 function bp_profile_field_data( $args = '' ) { 947 echo bp_get_profile_field_data( $args ); 948 } 949 950 /** 951 * Return XProfile field data. 952 * 953 * @since 1.2.0 954 * 955 * @param string|array $args { 956 * Array of arguments for field data. 957 * 958 * @type string|int|bool $field Field identifier. 959 * @type int $user_id ID of the user to get field data for. 960 * } 961 * @return mixed 962 */ 963 function bp_get_profile_field_data( $args = '' ) { 964 965 $r = bp_parse_args( 966 $args, 967 array( 968 'field' => false, // Field name or ID. 969 'user_id' => bp_displayed_user_id(), 970 ) 971 ); 972 973 /** 974 * Filters the profile field data. 975 * 976 * @since 1.2.0 977 * @since 2.6.0 Added the `$r` parameter. 978 * 979 * @param mixed $value Profile data for a specific field for the user. 980 * @param array $r Array of parsed arguments. 981 */ 982 return apply_filters( 'bp_get_profile_field_data', xprofile_get_field_data( $r['field'], $r['user_id'] ), $r ); 983 } 984 985 /** 986 * Get all profile field groups. 987 * 988 * @since 2.1.0 989 * 990 * @return array $groups 991 */ 992 function bp_profile_get_field_groups() { 993 994 $groups = wp_cache_get( 'all', 'bp_xprofile_groups' ); 995 if ( false === $groups ) { 996 $groups = bp_xprofile_get_groups( array( 'fetch_fields' => true ) ); 997 wp_cache_set( 'all', $groups, 'bp_xprofile_groups' ); 998 } 999 1000 /** 1001 * Filters all profile field groups. 1002 * 1003 * @since 2.1.0 1004 * 1005 * @param array $groups Array of available profile field groups. 1006 */ 1007 return apply_filters( 'bp_profile_get_field_groups', $groups ); 1008 } 1009 1010 /** 1011 * Check if there is more than one group of fields for the profile being edited. 1012 * 1013 * @since 2.1.0 1014 * 1015 * @return bool True if there is more than one profile field group. 1016 */ 1017 function bp_profile_has_multiple_groups() { 1018 $has_multiple_groups = count( (array) bp_profile_get_field_groups() ) > 1; 1019 1020 /** 1021 * Filters if there is more than one group of fields for the profile being edited. 1022 * 1023 * @since 2.1.0 1024 * 1025 * @param bool $has_multiple_groups Whether or not there are multiple groups. 1026 */ 1027 return (bool) apply_filters( 'bp_profile_has_multiple_groups', $has_multiple_groups ); 1028 } 1029 1030 /** 1031 * Output the tabs to switch between profile field groups. 1032 * 1033 * @since 1.0.0 1034 */ 1035 function bp_profile_group_tabs() { 1036 echo bp_get_profile_group_tabs(); 1037 1038 /** 1039 * Fires at the end of the tab output for switching between profile field 1040 * groups. This action is in a strange place for legacy reasons. 1041 * 1042 * @since 1.0.0 1043 */ 1044 do_action( 'xprofile_profile_group_tabs' ); 1045 } 1046 1047 /** 1048 * Return the XProfile group tabs. 1049 * 1050 * @since 2.3.0 1051 * 1052 * @return string 1053 */ 1054 function bp_get_profile_group_tabs() { 1055 1056 // Get field group data. 1057 $groups = bp_profile_get_field_groups(); 1058 $group_name = bp_get_profile_group_name(); 1059 $tabs = array(); 1060 1061 // Loop through field groups and put a tab-lst together. 1062 for ( $i = 0, $count = count( $groups ); $i < $count; ++$i ) { 1063 1064 // Setup the selected class. 1065 $selected = ''; 1066 if ( $group_name === $groups[ $i ]->name ) { 1067 $selected = ' class="current"'; 1068 } 1069 1070 // Skip if group has no fields. 1071 if ( empty( $groups[ $i ]->fields ) ) { 1072 continue; 1073 } 1074 1075 // Build the profile field group link. 1076 $link = trailingslashit( bp_displayed_user_domain() . bp_get_profile_slug() . '/edit/group/' . $groups[ $i ]->id ); 1077 1078 // Add tab to end of tabs array. 1079 $tabs[] = sprintf( 1080 '<li %1$s><a href="%2$s">%3$s</a></li>', 1081 $selected, 1082 esc_url( $link ), 1083 esc_html( apply_filters( 'bp_get_the_profile_group_name', $groups[ $i ]->name ) ) 1084 ); 1085 } 1086 1087 /** 1088 * Filters the tabs to display for profile field groups. 1089 * 1090 * @since 1.5.0 1091 * 1092 * @param array $tabs Array of tabs to display. 1093 * @param array $groups Array of profile groups. 1094 * @param string $group_name Name of the current group displayed. 1095 */ 1096 $tabs = apply_filters( 'xprofile_filter_profile_group_tabs', $tabs, $groups, $group_name ); 1097 1098 return join( '', $tabs ); 1099 } 1100 1101 /** 1102 * Output the XProfile group name. 1103 * 1104 * @since 1.0.0 1105 * 1106 * @param bool $deprecated Deprecated boolean parameter. 1107 * 1108 * @return string|null 1109 */ 1110 function bp_profile_group_name( $deprecated = true ) { 1111 if ( ! $deprecated ) { 1112 return bp_get_profile_group_name(); 1113 } else { 1114 echo bp_get_profile_group_name(); 1115 } 1116 } 1117 1118 /** 1119 * Return the XProfile group name. 1120 * 1121 * @since 1.0.0 1122 * 1123 * @return string 1124 */ 1125 function bp_get_profile_group_name() { 1126 1127 // Check action variable. 1128 $group_id = bp_action_variable( 1 ); 1129 if ( empty( $group_id ) || ! is_numeric( $group_id ) ) { 1130 $group_id = 1; 1131 } 1132 1133 // Check for cached group. 1134 $group = new BP_XProfile_Group( $group_id ); 1135 1136 /** 1137 * Filters the profile group name. 1138 * 1139 * @since 1.0.0 1140 * @since 2.6.0 Added the `$group_id` parameter 1141 * 1142 * @param string $name Name of the profile group. 1143 * @param int $group_id ID of the profile group. 1144 */ 1145 return apply_filters( 'bp_get_profile_group_name', $group->name, $group_id ); 1146 } 1147 1148 /** 1149 * Render a formatted string displaying when a profile was last updated. 1150 * 1151 * @since 1.0.0 1152 */ 1153 function bp_profile_last_updated() { 1154 1155 $last_updated = bp_get_profile_last_updated(); 1156 1157 if ( empty( $last_updated ) ) { 1158 _e( 'Profile not recently updated.', 'buddypress' ); 1159 } else { 1160 echo $last_updated; 1161 } 1162 } 1163 1164 /** 1165 * Return a formatted string displaying when a profile was last updated. 1166 * 1167 * @since 1.0.0 1168 * 1169 * @return bool|string 1170 */ 1171 function bp_get_profile_last_updated() { 1172 1173 $last_updated = bp_get_user_meta( bp_displayed_user_id(), 'profile_last_updated', true ); 1174 1175 if ( ! empty( $last_updated ) ) { 1176 1177 /** 1178 * Filters the formatted string used to display when a profile was last updated. 1179 * 1180 * @since 1.0.0 1181 * 1182 * @param string $value Formatted last updated indicator string. 1183 */ 1184 return apply_filters( 1185 'bp_get_profile_last_updated', 1186 /* translators: %s: last activity timestamp (e.g. "active 1 hour ago") */ 1187 sprintf( __( 'Profile updated %s', 'buddypress' ), bp_core_time_since( strtotime( $last_updated ) ) ) 1188 ); 1189 } 1190 1191 return false; 1192 } 1193 1194 /** 1195 * Display the current profile group ID. 1196 * 1197 * @since 1.1.0 1198 */ 1199 function bp_current_profile_group_id() { 1200 echo bp_get_current_profile_group_id(); 1201 } 1202 1203 /** 1204 * Return the current profile group ID. 1205 * 1206 * @since 1.1.0 1207 * 1208 * @return int 1209 */ 1210 function bp_get_current_profile_group_id() { 1211 $profile_group_id = bp_action_variable( 1 ); 1212 if ( empty( $profile_group_id ) ) { 1213 $profile_group_id = 1; 1214 } 1215 1216 /** 1217 * Filters the current profile group ID. 1218 * 1219 * Possible values are admin/profile/edit/[group-id]. 1220 * 1221 * @since 1.1.0 1222 * 1223 * @param int $profile_group_id Current profile group ID. 1224 */ 1225 return (int) apply_filters( 'bp_get_current_profile_group_id', $profile_group_id ); 1226 } 1227 1228 /** 1229 * Render an edit profile button. 1230 * 1231 * @since 1.0.0 1232 */ 1233 function bp_edit_profile_button() { 1234 bp_button( array( 1235 'id' => 'edit_profile', 1236 'component' => 'xprofile', 1237 'must_be_logged_in' => true, 1238 'block_self' => true, 1239 'link_href' => trailingslashit( bp_displayed_user_domain() . bp_get_profile_slug() . '/edit' ), 1240 'link_class' => 'edit', 1241 'link_text' => __( 'Edit Profile', 'buddypress' ), 1242 ) ); 1243 } 1244 1245 /** Visibility ****************************************************************/ 1246 1247 /** 1248 * Echo the field visibility radio buttons. 1249 * 1250 * @since 1.6.0 1251 * 1252 * @param array|string $args Args for the radio buttons. See {@link bp_profile_get_visibility_radio_buttons} 1253 */ 1254 function bp_profile_visibility_radio_buttons( $args = '' ) { 1255 echo bp_profile_get_visibility_radio_buttons( $args ); 1256 } 1257 /** 1258 * Return the field visibility radio buttons. 1259 * 1260 * @since 1.6.0 1261 * 1262 * @param array|string $args { 1263 * Args for the radio buttons. 1264 * 1265 * @type int $field_id ID of the field to render. 1266 * @type string $before Markup to render before the field. 1267 * @type string $after Markup to render after the field. 1268 * @type string $before_radio Markup to render before the radio button. 1269 * @type string $after_radio Markup to render after the radio button. 1270 * @type string $class Class to apply to the field markup. 1271 * } 1272 * @return string $retval 1273 */ 1274 function bp_profile_get_visibility_radio_buttons( $args = '' ) { 1275 1276 // Parse optional arguments. 1277 $r = bp_parse_args( 1278 $args, 1279 array( 1280 'field_id' => bp_get_the_profile_field_id(), 1281 'before' => '<div class="radio">', 1282 'after' => '</div>', 1283 'before_radio' => '', 1284 'after_radio' => '', 1285 'class' => 'bp-xprofile-visibility', 1286 ), 1287 'xprofile_visibility_radio_buttons' 1288 ); 1289 1290 // Empty return value, filled in below if a valid field ID is found. 1291 $retval = ''; 1292 1293 // Only do-the-do if there's a valid field ID. 1294 if ( ! empty( $r['field_id'] ) ) : 1295 1296 // Start the output buffer. 1297 ob_start(); 1298 1299 // Output anything before. 1300 echo $r['before']; ?> 1301 1302 <?php if ( bp_current_user_can( 'bp_xprofile_change_field_visibility' ) ) : ?> 1303 1304 <?php foreach( bp_xprofile_get_visibility_levels() as $level ) : ?> 1305 1306 <?php printf( $r['before_radio'], esc_attr( $level['id'] ) ); ?> 1307 1308 <label for="<?php echo esc_attr( 'see-field_' . $r['field_id'] . '_' . $level['id'] ); ?>"> 1309 <input type="radio" id="<?php echo esc_attr( 'see-field_' . $r['field_id'] . '_' . $level['id'] ); ?>" name="<?php echo esc_attr( 'field_' . $r['field_id'] . '_visibility' ); ?>" value="<?php echo esc_attr( $level['id'] ); ?>" <?php checked( $level['id'], bp_get_the_profile_field_visibility_level() ); ?> /> 1310 <span class="field-visibility-text"><?php echo esc_html( $level['label'] ); ?></span> 1311 </label> 1312 1313 <?php echo $r['after_radio']; ?> 1314 1315 <?php endforeach; ?> 1316 1317 <?php endif; 1318 1319 // Output anything after. 1320 echo $r['after']; 1321 1322 // Get the output buffer and empty it. 1323 $retval = ob_get_clean(); 1324 endif; 1325 1326 /** 1327 * Filters the radio buttons for setting visibility. 1328 * 1329 * @since 1.6.0 1330 * 1331 * @param string $retval HTML output for the visibility radio buttons. 1332 * @param array $r Parsed arguments to be used with display. 1333 * @param array $args Original passed in arguments to be used with display. 1334 */ 1335 return apply_filters( 'bp_profile_get_visibility_radio_buttons', $retval, $r, $args ); 1336 } 1337 1338 /** 1339 * Output the XProfile field visibility select list for settings. 1340 * 1341 * @since 2.0.0 1342 * 1343 * @param array|string $args Args for the select list. See {@link bp_profile_get_settings_visibility_select} 1344 */ 1345 function bp_profile_settings_visibility_select( $args = '' ) { 1346 echo bp_profile_get_settings_visibility_select( $args ); 1347 } 1348 /** 1349 * Return the XProfile field visibility select list for settings. 1350 * 1351 * @since 2.0.0 1352 * 1353 * @param array|string $args { 1354 * Args for the select list. 1355 * 1356 * @type int $field_id ID of the field to render. 1357 * @type string $before Markup to render before the field. 1358 * @type string $before_controls markup before form controls. 1359 * @type string $after Markup to render after the field. 1360 * @type string $after_controls Markup after the form controls. 1361 * @type string $class Class to apply to the field markup. 1362 * @type string $label_class Class to apply for the label element. 1363 * @type string $notoggle_tag Markup element to use for notoggle tag. 1364 * @type string $notoggle_class Class to apply to the notoggle element. 1365 * } 1366 * @return string $retval 1367 */ 1368 function bp_profile_get_settings_visibility_select( $args = '' ) { 1369 1370 // Parse optional arguments. 1371 $r = bp_parse_args( 1372 $args, 1373 array( 1374 'field_id' => bp_get_the_profile_field_id(), 1375 'before' => '', 1376 'before_controls' => '', 1377 'after' => '', 1378 'after_controls' => '', 1379 'class' => 'bp-xprofile-visibility', 1380 'label_class' => 'bp-screen-reader-text', 1381 'notoggle_tag' => 'span', 1382 'notoggle_class' => 'field-visibility-settings-notoggle', 1383 ), 1384 'xprofile_settings_visibility_select' 1385 ); 1386 1387 // Empty return value, filled in below if a valid field ID is found. 1388 $retval = ''; 1389 1390 // Only do-the-do if there's a valid field ID. 1391 if ( ! empty( $r['field_id'] ) ) : 1392 1393 // Start the output buffer. 1394 ob_start(); 1395 1396 // Output anything before. 1397 echo $r['before']; ?> 1398 1399 <?php if ( bp_current_user_can( 'bp_xprofile_change_field_visibility' ) ) : ?> 1400 1401 <?php echo $r['before_controls']; ?> 1402 1403 <label for="<?php echo esc_attr( 'field_' . $r['field_id'] ) ; ?>_visibility" class="<?php echo esc_attr( $r['label_class'] ); ?>"><?php 1404 /* translators: accessibility text */ 1405 _e( 'Select visibility', 'buddypress' ); 1406 ?></label> 1407 <select class="<?php echo esc_attr( $r['class'] ); ?>" name="<?php echo esc_attr( 'field_' . $r['field_id'] ) ; ?>_visibility" id="<?php echo esc_attr( 'field_' . $r['field_id'] ) ; ?>_visibility"> 1408 1409 <?php foreach ( bp_xprofile_get_visibility_levels() as $level ) : ?> 1410 1411 <option value="<?php echo esc_attr( $level['id'] ); ?>" <?php selected( $level['id'], bp_get_the_profile_field_visibility_level() ); ?>><?php echo esc_html( $level['label'] ); ?></option> 1412 1413 <?php endforeach; ?> 1414 1415 </select> 1416 1417 <?php echo $r['after_controls']; ?> 1418 1419 <?php else : ?> 1420 1421 <<?php echo esc_html( $r['notoggle_tag'] ); ?> class="<?php echo esc_attr( $r['notoggle_class'] ); ?>"><?php bp_the_profile_field_visibility_level_label(); ?></<?php echo esc_html( $r['notoggle_tag'] ); ?>> 1422 1423 <?php endif; 1424 1425 // Output anything after. 1426 echo $r['after']; 1427 1428 // Get the output buffer and empty it. 1429 $retval = ob_get_clean(); 1430 endif; 1431 1432 /** 1433 * Filters the dropdown list for setting visibility. 1434 * 1435 * @since 2.0.0 1436 * 1437 * @param string $retval HTML output for the visibility dropdown list. 1438 * @param array $r Parsed arguments to be used with display. 1439 * @param array $args Original passed in arguments to be used with display. 1440 */ 1441 return apply_filters( 'bp_profile_settings_visibility_select', $retval, $r, $args ); 1442 } 1443 1444 /** 1445 * Output the 'required' markup in extended profile field labels. 1446 * 1447 * @since 2.4.0 1448 */ 1449 function bp_the_profile_field_required_label() { 1450 echo bp_get_the_profile_field_required_label(); 1451 } 1452 1453 /** 1454 * Return the 'required' markup in extended profile field labels. 1455 * 1456 * @since 2.4.0 1457 * 1458 * @return string HTML for the required label. 1459 */ 1460 function bp_get_the_profile_field_required_label() { 1461 $retval = ''; 1462 1463 if ( bp_get_the_profile_field_is_required() ) { 1464 $translated_string = __( '(required)', 'buddypress' ); 1465 1466 $retval = ' <span class="bp-required-field-label">'; 1467 $retval .= apply_filters( 'bp_get_the_profile_field_required_label', $translated_string, bp_get_the_profile_field_id() ); 1468 $retval .= '</span>'; 1469 1470 } 1471 1472 return $retval; 1473 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Thu Nov 21 01:00:57 2024 | Cross-referenced by PHPXref 0.7.1 |