[ Index ]

PHP Cross Reference of BuddyPress

title

Body

[close]

/src/bp-templates/bp-nouveau/includes/members/ -> template-tags.php (source)

   1  <?php
   2  /**
   3   * Members template tags
   4   *
   5   * @since 3.0.0
   6   * @version 3.1.0
   7   */
   8  
   9  // Exit if accessed directly.
  10  defined( 'ABSPATH' ) || exit;
  11  
  12  /**
  13   * Template tag to wrap all Legacy actions that was used
  14   * before the members directory content
  15   *
  16   * @since 3.0.0
  17   */
  18  function bp_nouveau_before_members_directory_content() {
  19      /**
  20       * Fires at the begining of the templates BP injected content.
  21       *
  22       * @since 2.3.0
  23       */
  24      do_action( 'bp_before_directory_members_page' );
  25  
  26      /**
  27       * Fires before the display of the members.
  28       *
  29       * @since 1.1.0
  30       */
  31      do_action( 'bp_before_directory_members' );
  32  
  33      /**
  34       * Fires before the display of the members content.
  35       *
  36       * @since 1.1.0
  37       */
  38      do_action( 'bp_before_directory_members_content' );
  39  
  40      /**
  41       * Fires before the display of the members list tabs.
  42       *
  43       * @since 1.8.0
  44       */
  45      do_action( 'bp_before_directory_members_tabs' );
  46  }
  47  
  48  /**
  49   * Template tag to wrap all Legacy actions that was used
  50   * after the members directory content
  51   *
  52   * @since 3.0.0
  53   */
  54  function bp_nouveau_after_members_directory_content() {
  55      /**
  56       * Fires and displays the members content.
  57       *
  58       * @since 1.1.0
  59       */
  60      do_action( 'bp_directory_members_content' );
  61  
  62      /**
  63       * Fires after the display of the members content.
  64       *
  65       * @since 1.1.0
  66       */
  67      do_action( 'bp_after_directory_members_content' );
  68  
  69      /**
  70       * Fires after the display of the members.
  71       *
  72       * @since 1.1.0
  73       */
  74      do_action( 'bp_after_directory_members' );
  75  
  76      /**
  77       * Fires at the bottom of the members directory template file.
  78       *
  79       * @since 1.5.0
  80       */
  81      do_action( 'bp_after_directory_members_page' );
  82  }
  83  
  84  /**
  85   * Fire specific hooks into the single members templates
  86   *
  87   * @since 3.0.0
  88   *
  89   * @param string $when   'before' or 'after'
  90   * @param string $suffix Use it to add terms at the end of the hook name
  91   */
  92  function bp_nouveau_member_hook( $when = '', $suffix = '' ) {
  93      $hook = array( 'bp' );
  94  
  95      if ( $when ) {
  96          $hook[] = $when;
  97      }
  98  
  99      // It's a member hook
 100      $hook[] = 'member';
 101  
 102      if ( $suffix ) {
 103          $hook[] = $suffix;
 104      }
 105  
 106      bp_nouveau_hook( $hook );
 107  }
 108  
 109  /**
 110   * Template tag to wrap the notification settings hook
 111   *
 112   * @since 3.0.0
 113   */
 114  function bp_nouveau_member_email_notice_settings() {
 115      /**
 116       * Fires at the top of the member template notification settings form.
 117       *
 118       * @since 1.0.0
 119       */
 120      do_action( 'bp_notification_settings' );
 121  }
 122  
 123  /**
 124   * Output the action buttons for the displayed user profile
 125   *
 126   * @since 3.0.0
 127   *
 128   * @param array $args See bp_nouveau_wrapper() for the description of parameters.
 129   */
 130  function bp_nouveau_member_header_buttons( $args = array() ) {
 131      $bp_nouveau = bp_nouveau();
 132  
 133      if ( bp_is_user() ) {
 134          $args['type'] = 'profile';
 135      } else {
 136          $args['type'] = 'header';// we have no real need for this 'type' on header actions
 137      }
 138  
 139      $output = join( ' ', bp_nouveau_get_members_buttons( $args ) );
 140  
 141      /**
 142       * On the member's header we need to reset the group button's global
 143       * once displayed as the friends component will use the member's loop
 144       */
 145      if ( ! empty( $bp_nouveau->members->member_buttons ) ) {
 146          unset( $bp_nouveau->members->member_buttons );
 147      }
 148  
 149      ob_start();
 150      /**
 151       * Fires in the member header actions section.
 152       *
 153       * @since 1.2.6
 154       */
 155      do_action( 'bp_member_header_actions' );
 156      $output .= ob_get_clean();
 157  
 158      if ( ! $output ) {
 159          return;
 160      }
 161  
 162      if ( ! $args ) {
 163          $args = array(
 164              'id'      => 'item-buttons',
 165              'classes' => false,
 166          );
 167      }
 168  
 169      bp_nouveau_wrapper( array_merge( $args, array( 'output' => $output ) ) );
 170  }
 171  
 172  /**
 173   * Output the action buttons in member loops
 174   *
 175   * @since 3.0.0
 176   *
 177   * @param array $args See bp_nouveau_wrapper() for the description of parameters.
 178   */
 179  function bp_nouveau_members_loop_buttons( $args = array() ) {
 180      if ( empty( $GLOBALS['members_template'] ) ) {
 181          return;
 182      }
 183  
 184      $args['type'] = 'loop';
 185      $action       = 'bp_directory_members_actions';
 186  
 187      // Specific case for group members.
 188      if ( bp_is_active( 'groups' ) && bp_is_group_members() ) {
 189          $args['type'] = 'group_member';
 190          $action       = 'bp_group_members_list_item_action';
 191  
 192      } elseif ( bp_is_active( 'friends' ) && bp_is_user_friend_requests() ) {
 193          $args['type'] = 'friendship_request';
 194          $action       = 'bp_friend_requests_item_action';
 195      }
 196  
 197      $output = join( ' ', bp_nouveau_get_members_buttons( $args ) );
 198  
 199      ob_start();
 200      /**
 201       * Fires inside the members action HTML markup to display actions.
 202       *
 203       * @since 1.1.0
 204       */
 205      do_action( $action );
 206      $output .= ob_get_clean();
 207  
 208      if ( ! $output ) {
 209          return;
 210      }
 211  
 212      bp_nouveau_wrapper( array_merge( $args, array( 'output' => $output ) ) );
 213  }
 214  
 215      /**
 216       * Get the action buttons for the displayed user profile
 217       *
 218       * @since 3.0.0
 219       *
 220       * @return array
 221       */
 222  	function bp_nouveau_get_members_buttons( $args ) {
 223          $buttons = array();
 224          $type = ( ! empty( $args['type'] ) ) ? $args['type'] : '';
 225  
 226          // @todo Not really sure why BP Legacy needed to do this...
 227          if ( 'profile' === $type && is_admin() && ! ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) {
 228              return $buttons;
 229          }
 230  
 231          $user_id = bp_displayed_user_id();
 232  
 233          if ( 'loop' === $type || 'friendship_request' === $type ) {
 234              $user_id = bp_get_member_user_id();
 235          } elseif ( 'group_member' === $type ) {
 236              $user_id = bp_get_group_member_id();
 237          }
 238  
 239          if ( ! $user_id ) {
 240              return $buttons;
 241          }
 242  
 243          /*
 244           * If the 'container' is set to 'ul'
 245           * set a var $parent_element to li
 246           * otherwise simply pass any value found in args
 247           * or set var false.
 248           */
 249          $parent_element = false;
 250  
 251          if ( ! empty( $args['container'] ) && 'ul' === $args['container']  ) {
 252              $parent_element = 'li';
 253          } elseif ( ! empty( $args['parent_element'] ) ) {
 254              $parent_element = $args['parent_element'];
 255          }
 256  
 257          /*
 258           * If we have a arg value for $button_element passed through
 259           * use it to default all the $buttons['button_element'] values
 260           * otherwise default to 'a' (anchor)
 261           * Or override & hardcode the 'element' string on $buttons array.
 262           *
 263           * Icons sets a class for icon display if not using the button element
 264           */
 265          $icons = '';
 266          if ( ! empty( $args['button_element'] ) ) {
 267              $button_element = $args['button_element'] ;
 268          } else {
 269              $button_element = 'button';
 270              $icons = ' icons';
 271          }
 272  
 273          // If we pass through parent classes add them to $button array
 274          $parent_class = '';
 275          if ( ! empty( $args['parent_attr']['class'] ) ) {
 276              $parent_class = $args['parent_attr']['class'];
 277          }
 278  
 279          if ( bp_is_active( 'friends' ) ) {
 280              // It's the member's friendship requests screen
 281              if ( 'friendship_request' === $type ) {
 282                  $buttons = array(
 283                      'accept_friendship' => array(
 284                          'id'                => 'accept_friendship',
 285                          'position'          => 5,
 286                          'component'         => 'friends',
 287                          'must_be_logged_in' => true,
 288                          'parent_element'    => $parent_element,
 289                          'link_text'         => _x( 'Accept', 'button', 'buddypress' ),
 290                          'parent_attr'       => array(
 291                              'id'    => '',
 292                              'class' => $parent_class ,
 293                          ),
 294                          'button_element'    => $button_element,
 295                          'button_attr'       => array(
 296                              'class'           => 'button accept',
 297                              'rel'             => '',
 298                          ),
 299                      ), 'reject_friendship' => array(
 300                          'id'                => 'reject_friendship',
 301                          'position'          => 15,
 302                          'component'         => 'friends',
 303                          'must_be_logged_in' => true,
 304                          'parent_element'    => $parent_element,
 305                          'link_text'         => _x( 'Reject', 'button', 'buddypress' ),
 306                          'parent_attr'       => array(
 307                              'id'    => '',
 308                              'class' => $parent_class,
 309                          ),
 310                          'button_element'    => $button_element,
 311                          'button_attr'       => array (
 312                              'class'           => 'button reject',
 313                              'rel'             => '',
 314                          ),
 315                      ),
 316                  );
 317  
 318                  // If button element set add nonce link to data attr
 319                  if ( 'button' === $button_element ) {
 320                      $buttons['accept_friendship']['button_attr']['data-bp-nonce'] = bp_get_friend_accept_request_link();
 321                      $buttons['reject_friendship']['button_attr']['data-bp-nonce'] = bp_get_friend_reject_request_link();
 322                  } else {
 323                      $buttons['accept_friendship']['button_attr']['href'] = bp_get_friend_accept_request_link();
 324                      $buttons['reject_friendship']['button_attr']['href'] = bp_get_friend_reject_request_link();
 325                  }
 326  
 327              // It's any other members screen
 328              } else {
 329                  /*
 330                   * This filter workaround is waiting for a core adaptation
 331                   * so that we can directly get the friends button arguments
 332                   * instead of the button.
 333                   *
 334                   * See https://buddypress.trac.wordpress.org/ticket/7126
 335                   */
 336                  add_filter( 'bp_get_add_friend_button', 'bp_nouveau_members_catch_button_args', 100, 1 );
 337  
 338                  bp_get_add_friend_button( $user_id );
 339  
 340                  remove_filter( 'bp_get_add_friend_button', 'bp_nouveau_members_catch_button_args', 100, 1 );
 341  
 342                  if ( isset( bp_nouveau()->members->button_args ) && bp_nouveau()->members->button_args ) {
 343                      $button_args = bp_nouveau()->members->button_args;
 344  
 345                      $buttons['member_friendship'] = array(
 346                          'id'                => 'member_friendship',
 347                          'position'          => 5,
 348                          'component'         => $button_args['component'],
 349                          'must_be_logged_in' => $button_args['must_be_logged_in'],
 350                          'block_self'        => $button_args['block_self'],
 351                          'parent_element'    => $parent_element,
 352                          'link_text'         => $button_args['link_text'],
 353                          'parent_attr'       => array(
 354                              'id'    => $button_args['wrapper_id'],
 355                              'class' => $parent_class . ' ' . $button_args['wrapper_class'],
 356                          ),
 357                          'button_element'    => $button_element,
 358                          'button_attr'       => array(
 359                              'id'    => $button_args['link_id'],
 360                              'class' => $button_args['link_class'],
 361                              'rel'   => $button_args['link_rel'],
 362                              'title' => '',
 363                          ),
 364                      );
 365  
 366                      // If button element set add nonce link to data attr
 367                      if ( 'button' === $button_element && 'awaiting_response' !== $button_args['id'] ) {
 368                          $buttons['member_friendship']['button_attr']['data-bp-nonce'] = $button_args['link_href'];
 369                      } else {
 370                          $buttons['member_friendship']['button_element'] = 'a';
 371                          $buttons['member_friendship']['button_attr']['href'] = $button_args['link_href'];
 372                      }
 373  
 374                      unset( bp_nouveau()->members->button_args );
 375                  }
 376              }
 377          }
 378  
 379          // Only add The public and private messages when not in a loop
 380          if ( 'profile' === $type ) {
 381              if ( bp_is_active( 'activity' ) && bp_activity_do_mentions() ) {
 382                  /*
 383                   * This filter workaround is waiting for a core adaptation
 384                   * so that we can directly get the public message button arguments
 385                   * instead of the button.
 386                   *
 387                   * See https://buddypress.trac.wordpress.org/ticket/7126
 388                   */
 389                  add_filter( 'bp_get_send_public_message_button', 'bp_nouveau_members_catch_button_args', 100, 1 );
 390  
 391                  bp_get_send_public_message_button();
 392  
 393                  remove_filter( 'bp_get_send_public_message_button', 'bp_nouveau_members_catch_button_args', 100, 1 );
 394  
 395                  if ( isset( bp_nouveau()->members->button_args ) && bp_nouveau()->members->button_args ) {
 396                      $button_args = bp_nouveau()->members->button_args;
 397  
 398                      /*
 399                       * This button should remain as an anchor link.
 400                       * Hardcode the use of anchor elements if button arg passed in for other elements.
 401                       */
 402                      $buttons['public_message'] = array(
 403                          'id'                => $button_args['id'],
 404                          'position'          => 15,
 405                          'component'         => $button_args['component'],
 406                          'must_be_logged_in' => $button_args['must_be_logged_in'],
 407                          'block_self'        => $button_args['block_self'],
 408                          'parent_element'    => $parent_element,
 409                          'button_element'    => 'a',
 410                          'link_text'         => $button_args['link_text'],
 411                          'parent_attr'       => array(
 412                              'id'    => $button_args['wrapper_id'],
 413                              'class' => $parent_class,
 414                          ),
 415                          'button_attr'       => array(
 416                              'href'             => $button_args['link_href'],
 417                              'id'               => '',
 418                              'class'            => $button_args['link_class'],
 419                          ),
 420                      );
 421                      unset( bp_nouveau()->members->button_args );
 422                  }
 423              }
 424  
 425              if ( bp_is_active( 'messages' ) ) {
 426                  /**
 427                   * This filter workaround is waiting for a core adaptation
 428                   * so that we can directly get the private messages button arguments
 429                   * instead of the button.
 430                   * @see https://buddypress.trac.wordpress.org/ticket/7126
 431                   */
 432                  add_filter( 'bp_get_send_message_button_args', 'bp_nouveau_members_catch_button_args', 100, 1 );
 433  
 434                  bp_get_send_message_button();
 435  
 436                  remove_filter( 'bp_get_send_message_button_args', 'bp_nouveau_members_catch_button_args', 100, 1 );
 437  
 438                  if ( isset( bp_nouveau()->members->button_args ) && bp_nouveau()->members->button_args ) {
 439                      $button_args = bp_nouveau()->members->button_args;
 440  
 441                      /*
 442                       * This button should remain as an anchor link.
 443                       * Hardcode the use of anchor elements if button arg passed in for other elements.
 444                       */
 445                      $buttons['private_message'] = array(
 446                          'id'                => $button_args['id'],
 447                          'position'          => 25,
 448                          'component'         => $button_args['component'],
 449                          'must_be_logged_in' => $button_args['must_be_logged_in'],
 450                          'block_self'        => $button_args['block_self'],
 451                          'parent_element'    => $parent_element,
 452                          'button_element'    => 'a',
 453                          'link_text'         => $button_args['link_text'],
 454                          'parent_attr'       => array(
 455                              'id'    => $button_args['wrapper_id'],
 456                              'class' => $parent_class,
 457                          ),
 458                          'button_attr'       => array(
 459                              'href'  => trailingslashit( bp_loggedin_user_domain() . bp_get_messages_slug() ) . 'compose?r=' . bp_core_get_username( $user_id ),
 460                              'id'    => false,
 461                              'class' => $button_args['link_class'],
 462                              'rel'   => '',
 463                              'title' => '',
 464                              ),
 465                      );
 466  
 467                      unset( bp_nouveau()->members->button_args );
 468                  }
 469              }
 470          }
 471  
 472          /**
 473           * Filter to add your buttons, use the position argument to choose where to insert it.
 474           *
 475           * @since 3.0.0
 476           *
 477           * @param array  $buttons The list of buttons.
 478           * @param int    $user_id The displayed user ID.
 479           * @param string $type    Whether we're displaying a members loop or a user's page
 480           */
 481          $buttons_group = apply_filters( 'bp_nouveau_get_members_buttons', $buttons, $user_id, $type );
 482          if ( ! $buttons_group ) {
 483              return $buttons;
 484          }
 485  
 486          // It's the first entry of the loop, so build the Group and sort it
 487          if ( ! isset( bp_nouveau()->members->member_buttons ) || ! is_a( bp_nouveau()->members->member_buttons, 'BP_Buttons_Group' ) ) {
 488              $sort = true;
 489              bp_nouveau()->members->member_buttons = new BP_Buttons_Group( $buttons_group );
 490  
 491          // It's not the first entry, the order is set, we simply need to update the Buttons Group
 492          } else {
 493              $sort = false;
 494              bp_nouveau()->members->member_buttons->update( $buttons_group );
 495          }
 496  
 497          $return = bp_nouveau()->members->member_buttons->get( $sort );
 498  
 499          if ( ! $return ) {
 500              return array();
 501          }
 502  
 503          /**
 504           * Leave a chance to adjust the $return
 505           *
 506           * @since 3.0.0
 507           *
 508           * @param array  $return  The list of buttons ordered.
 509           * @param int    $user_id The displayed user ID.
 510           * @param string $type    Whether we're displaying a members loop or a user's page
 511           */
 512          do_action_ref_array( 'bp_nouveau_return_members_buttons', array( &$return, $user_id, $type ) );
 513  
 514          return $return;
 515      }
 516  
 517  /**
 518   * Does the member has meta.
 519   *
 520   * @since 3.0.0
 521   *
 522   * @return bool True if the member has meta. False otherwise.
 523   */
 524  function bp_nouveau_member_has_meta() {
 525      return (bool) bp_nouveau_get_member_meta();
 526  }
 527  
 528  /**
 529   * Display the member meta.
 530   *
 531   * @since 3.0.0
 532   *
 533   * @return string HTML Output.
 534   */
 535  function bp_nouveau_member_meta() {
 536      echo join( "\n", bp_nouveau_get_member_meta() );
 537  }
 538  
 539      /**
 540       * Get the member meta.
 541       *
 542       * @since 3.0.0
 543       *
 544       * @return array The member meta.
 545       */
 546  	function bp_nouveau_get_member_meta() {
 547          $meta    = array();
 548          $is_loop = false;
 549  
 550          if ( ! empty( $GLOBALS['members_template']->member ) ) {
 551              $member  = $GLOBALS['members_template']->member;
 552              $is_loop = true;
 553          } else {
 554              $member = bp_get_displayed_user();
 555          }
 556  
 557          if ( empty( $member->id ) ) {
 558              return $meta;
 559          }
 560  
 561          if ( empty( $member->template_meta ) ) {
 562              // It's a single user's header
 563              if ( ! $is_loop ) {
 564                  $meta['last_activity'] = sprintf(
 565                      '<span class="activity">%s</span>',
 566                      esc_html( bp_get_last_activity( bp_displayed_user_id() ) )
 567                  );
 568  
 569              // We're in the members loop
 570              } else {
 571                  $meta = array(
 572                      'last_activity' => sprintf( '%s', bp_get_member_last_active() ),
 573                  );
 574              }
 575  
 576              // Make sure to include hooked meta.
 577              $extra_meta = bp_nouveau_get_hooked_member_meta();
 578  
 579              if ( $extra_meta ) {
 580                  $meta['extra'] = $extra_meta;
 581              }
 582  
 583              /**
 584               * Filter to add/remove Member meta.
 585               *
 586               * @since 3.0.0
 587               *
 588               * @param array  $meta    The list of meta to output.
 589               * @param object $member  The member object
 590               * @param bool   $is_loop True if in the members loop. False otherwise.
 591               */
 592              $member->template_meta = apply_filters( 'bp_nouveau_get_member_meta', $meta, $member, $is_loop );
 593          }
 594  
 595          return $member->template_meta;
 596      }
 597  
 598  /**
 599   * Load the appropriate content for the single member pages
 600   *
 601   * @since 3.0.0
 602   */
 603  function bp_nouveau_member_template_part() {
 604      /**
 605       * Fires before the display of member body content.
 606       *
 607       * @since 1.2.0
 608       */
 609      do_action( 'bp_before_member_body' );
 610  
 611      if ( bp_is_user_front() ) {
 612          bp_displayed_user_front_template_part();
 613  
 614      } else {
 615          $template = 'plugins';
 616  
 617          if ( bp_is_user_activity() ) {
 618              $template = 'activity';
 619          } elseif ( bp_is_user_blogs() ) {
 620              $template = 'blogs';
 621          } elseif ( bp_is_user_friends() ) {
 622              $template = 'friends';
 623          } elseif ( bp_is_user_groups() ) {
 624              $template = 'groups';
 625          } elseif ( bp_is_user_messages() ) {
 626              $template = 'messages';
 627          } elseif ( bp_is_user_profile() ) {
 628              $template = 'profile';
 629          } elseif ( bp_is_user_notifications() ) {
 630              $template = 'notifications';
 631          } elseif ( bp_is_user_settings() ) {
 632              $template = 'settings';
 633          }
 634  
 635          bp_nouveau_member_get_template_part( $template );
 636      }
 637  
 638      /**
 639       * Fires after the display of member body content.
 640       *
 641       * @since 1.2.0
 642       */
 643      do_action( 'bp_after_member_body' );
 644  }
 645  
 646  /**
 647   * Use the appropriate Member header and enjoy a template hierarchy
 648   *
 649   * @since 3.0.0
 650   *
 651   * @return string HTML Output
 652   */
 653  function bp_nouveau_member_header_template_part() {
 654      $template = 'member-header';
 655  
 656      if ( bp_displayed_user_use_cover_image_header() ) {
 657          $template = 'cover-image-header';
 658      }
 659  
 660      /**
 661       * Fires before the display of a member's header.
 662       *
 663       * @since 1.2.0
 664       */
 665      do_action( 'bp_before_member_header' );
 666  
 667      // Get the template part for the header
 668      bp_nouveau_member_get_template_part( $template );
 669  
 670      /**
 671       * Fires after the display of a member's header.
 672       *
 673       * @since 1.2.0
 674       */
 675      do_action( 'bp_after_member_header' );
 676  
 677      bp_nouveau_template_notices();
 678  }
 679  
 680  /**
 681   * Get a link to set the Member's default front page and directly
 682   * reach the Customizer section where it's possible to do it.
 683   *
 684   * @since 3.0.0
 685   *
 686   * @return string HTML Output
 687   */
 688  function bp_nouveau_members_get_customizer_option_link() {
 689      return bp_nouveau_get_customizer_link(
 690          array(
 691              'object'    => 'user',
 692              'autofocus' => 'bp_nouveau_user_front_page',
 693              'text'      => __( 'Members default front page', 'buddypress' ),
 694          )
 695      );
 696  }
 697  
 698  /**
 699   * Get a link to set the Member's front page widgets and directly
 700   * reach the Customizer section where it's possible to do it.
 701   *
 702   * @since 3.0.0
 703   *
 704   * @return string HTML Output
 705   */
 706  function bp_nouveau_members_get_customizer_widgets_link() {
 707      return bp_nouveau_get_customizer_link(
 708          array(
 709              'object'    => 'user',
 710              'autofocus' => 'sidebar-widgets-sidebar-buddypress-members',
 711              'text'      => __( '(BuddyPress) Widgets', 'buddypress' ),
 712          )
 713      );
 714  }
 715  
 716  /**
 717   * Display the Member description making sure linefeeds are taking in account
 718   *
 719   * @since 3.0.0
 720   *
 721   * @param int $user_id Optional.
 722   *
 723   * @return string HTML output.
 724   */
 725  function bp_nouveau_member_description( $user_id = 0 ) {
 726      if ( ! $user_id ) {
 727          $user_id = bp_loggedin_user_id();
 728  
 729          if ( bp_displayed_user_id() ) {
 730              $user_id = bp_displayed_user_id();
 731          }
 732      }
 733  
 734      // @todo This hack is too brittle.
 735      add_filter( 'the_author_description', 'make_clickable', 9 );
 736      add_filter( 'the_author_description', 'wpautop' );
 737      add_filter( 'the_author_description', 'wptexturize' );
 738      add_filter( 'the_author_description', 'convert_smilies' );
 739      add_filter( 'the_author_description', 'convert_chars' );
 740      add_filter( 'the_author_description', 'stripslashes' );
 741  
 742      the_author_meta( 'description', $user_id );
 743  
 744      remove_filter( 'the_author_description', 'make_clickable', 9 );
 745      remove_filter( 'the_author_description', 'wpautop' );
 746      remove_filter( 'the_author_description', 'wptexturize' );
 747      remove_filter( 'the_author_description', 'convert_smilies' );
 748      remove_filter( 'the_author_description', 'convert_chars' );
 749      remove_filter( 'the_author_description', 'stripslashes' );
 750  }
 751  
 752  /**
 753   * Display the Edit profile link (temporary).
 754   *
 755   * @since 3.0.0
 756   *
 757   * @todo replace with Ajax feature
 758   *
 759   * @return string HTML Output
 760   */
 761  function bp_nouveau_member_description_edit_link() {
 762      echo bp_nouveau_member_get_description_edit_link();
 763  }
 764  
 765      /**
 766       * Get the Edit profile link (temporary)
 767       * @todo  replace with Ajax featur
 768       *
 769       * @since 3.0.0
 770       *
 771       * @return string HTML Output
 772       */
 773  	function bp_nouveau_member_get_description_edit_link() {
 774          remove_filter( 'edit_profile_url', 'bp_members_edit_profile_url', 10, 3 );
 775  
 776          if ( is_multisite() && ! current_user_can( 'read' ) ) {
 777              $link = get_dashboard_url( bp_displayed_user_id(), 'profile.php' );
 778          } else {
 779              $link = get_edit_profile_url( bp_displayed_user_id() );
 780          }
 781  
 782          add_filter( 'edit_profile_url', 'bp_members_edit_profile_url', 10, 3 );
 783          $link .= '#description';
 784  
 785          return sprintf( '<a href="%1$s">%2$s</a>', esc_url( $link ), esc_html__( 'Edit your bio', 'buddypress' ) );
 786      }
 787  
 788  
 789  /** WP Profile tags **********************************************************/
 790  
 791  /**
 792   * Template tag to wrap all Legacy actions that was used
 793   * before and after the WP User's Profile.
 794   *
 795   * @since 3.0.0
 796   */
 797  function bp_nouveau_wp_profile_hooks( $type = 'before' ) {
 798      if ( 'before' === $type ) {
 799          /**
 800           * Fires before the display of member profile loop content.
 801           *
 802           * @since 1.2.0
 803           */
 804          do_action( 'bp_before_profile_loop_content' );
 805  
 806          /**
 807           * Fires before the display of member profile field content.
 808           *
 809           * @since 1.1.0
 810           */
 811          do_action( 'bp_before_profile_field_content' );
 812      } else {
 813          /**
 814           * Fires after the display of member profile field content.
 815           *
 816           * @since 1.1.0
 817           */
 818          do_action( 'bp_after_profile_field_content' );
 819  
 820          /**
 821           * Fires and displays the profile field buttons.
 822           *
 823           * @since 1.1.0
 824           */
 825          do_action( 'bp_profile_field_buttons' );
 826  
 827          /**
 828           * Fires after the display of member profile loop content.
 829           *
 830           * @since 1.2.0
 831           */
 832          do_action( 'bp_after_profile_loop_content' );
 833      }
 834  }
 835  
 836  /**
 837   * Does the displayed user has WP profile fields?
 838   *
 839   * @since 3.0.0
 840   *
 841   * @return bool True if user has profile fields. False otherwise.
 842   */
 843  function bp_nouveau_has_wp_profile_fields() {
 844      $user_id = bp_displayed_user_id();
 845      if ( ! $user_id ) {
 846          return false;
 847      }
 848  
 849      $user = get_userdata( $user_id );
 850      if ( ! $user ) {
 851          return false;
 852      }
 853  
 854      $fields              = bp_nouveau_get_wp_profile_fields( $user );
 855      $user_profile_fields = array();
 856  
 857      foreach ( $fields as $key => $field ) {
 858          if ( empty( $user->{$key} ) ) {
 859              continue;
 860          }
 861  
 862          $user_profile_fields[] = (object) array(
 863              'id'    => 'wp_' . $key,
 864              'label' => $field,
 865              'data'  => $user->{$key},
 866          );
 867      }
 868  
 869      if ( ! $user_profile_fields ) {
 870          return false;
 871      }
 872  
 873      // Keep it for a later use.
 874      $bp_nouveau                            = bp_nouveau();
 875      $bp_nouveau->members->wp_profile       = $user_profile_fields;
 876      $bp_nouveau->members->wp_profile_index = 0;
 877  
 878      return true;
 879  }
 880  
 881  /**
 882   * Check if there are still profile fields to output.
 883   *
 884   * @since 3.0.0
 885   *
 886   * @return bool True if the profile field exists. False otherwise.
 887   */
 888  function bp_nouveau_wp_profile_fields() {
 889      $bp_nouveau = bp_nouveau();
 890  
 891      if ( isset( $bp_nouveau->members->wp_profile[ $bp_nouveau->members->wp_profile_index ] ) ) {
 892          return true;
 893      }
 894  
 895      $bp_nouveau->members->wp_profile_index = 0;
 896      unset( $bp_nouveau->members->wp_profile_current );
 897  
 898      return false;
 899  }
 900  
 901  /**
 902   * Set the current profile field and iterate into the loop.
 903   *
 904   * @since 3.0.0
 905   */
 906  function bp_nouveau_wp_profile_field() {
 907      $bp_nouveau = bp_nouveau();
 908  
 909      $bp_nouveau->members->wp_profile_current = $bp_nouveau->members->wp_profile[ $bp_nouveau->members->wp_profile_index ];
 910      $bp_nouveau->members->wp_profile_index  += 1;
 911  }
 912  
 913  /**
 914   * Output the WP profile field ID.
 915   *
 916   * @since 3.0.0
 917   */
 918  function bp_nouveau_wp_profile_field_id() {
 919      echo esc_attr( bp_nouveau_get_wp_profile_field_id() );
 920  }
 921      /**
 922       * Get the WP profile field ID.
 923       *
 924       * @since 3.0.0
 925       *
 926       * @return int the profile field ID.
 927       */
 928  	function bp_nouveau_get_wp_profile_field_id() {
 929          $field = bp_nouveau()->members->wp_profile_current;
 930  
 931          /**
 932           * Filters the WP profile field ID used for BuddyPress Nouveau.
 933           *
 934           * @since 3.0.0
 935           *
 936           * @param string $id Field ID.
 937           */
 938          return apply_filters( 'bp_nouveau_get_wp_profile_field_id', $field->id );
 939      }
 940  
 941  /**
 942   * Output the WP profile field label.
 943   *
 944   * @since 3.0.0
 945   */
 946  function bp_nouveau_wp_profile_field_label() {
 947      echo esc_html( bp_nouveau_get_wp_profile_field_label() );
 948  }
 949  
 950      /**
 951       * Get the WP profile label.
 952       *
 953       * @since 3.0.0
 954       *
 955       * @return string the profile field label.
 956       */
 957  	function bp_nouveau_get_wp_profile_field_label() {
 958          $field = bp_nouveau()->members->wp_profile_current;
 959  
 960          /**
 961           * Filters the WP profile field label used for BuddyPress Nouveau.
 962           *
 963           * @since 3.0.0
 964           *
 965           * @param string $label Field label.
 966           */
 967          return apply_filters( 'bp_nouveau_get_wp_profile_field_label', $field->label );
 968      }
 969  
 970  /**
 971   * Output the WP profile field data.
 972   *
 973   * @since 3.0.0
 974   */
 975  function bp_nouveau_wp_profile_field_data() {
 976      $data = bp_nouveau_get_wp_profile_field_data();
 977      $data = make_clickable( $data );
 978  
 979      echo wp_kses(
 980          /**
 981           * Filters a WP profile field value.
 982           *
 983           * @since 3.0.0
 984           *
 985           * @param string $data The profile field data value.
 986           */
 987          apply_filters( 'bp_nouveau_get_wp_profile_field_data', $data ),
 988          array(
 989              'a' => array(
 990                  'href' => true,
 991                  'rel'  => true,
 992              ),
 993          )
 994      );
 995  }
 996  
 997      /**
 998       * Get the WP profile field data.
 999       *
1000       * @since 3.0.0
1001       *
1002       * @return string the profile field data.
1003       */
1004  	function bp_nouveau_get_wp_profile_field_data() {
1005          $field = bp_nouveau()->members->wp_profile_current;
1006          return $field->data;
1007      }


Generated: Fri Oct 18 01:01:36 2019 Cross-referenced by PHPXref 0.7.1