[ Index ]

PHP Cross Reference of BuddyPress

title

Body

[close]

/src/bp-xprofile/ -> bp-xprofile-template.php (source)

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


Generated: Tue Jul 16 01:01:43 2019 Cross-referenced by PHPXref 0.7.1