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


Generated: Thu Jul 9 01:01:31 2020 Cross-referenced by PHPXref 0.7.1