[ 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 8.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_nouveau_get_component_slug( 'messages' ) ) . '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_members_invitations() ) {
 664              $template = 'invitations';
 665          } elseif ( bp_is_user_settings() ) {
 666              $template = 'settings';
 667          }
 668  
 669          bp_nouveau_member_get_template_part( $template );
 670      }
 671  
 672      /**
 673       * Fires after the display of member body content.
 674       *
 675       * @since 1.2.0
 676       */
 677      do_action( 'bp_after_member_body' );
 678  }
 679  
 680  /**
 681   * Use the appropriate Member header and enjoy a template hierarchy
 682   *
 683   * @since 3.0.0
 684   *
 685   * @return string HTML Output
 686   */
 687  function bp_nouveau_member_header_template_part() {
 688      $template = 'member-header';
 689  
 690      if ( bp_displayed_user_use_cover_image_header() ) {
 691          $template = 'cover-image-header';
 692      }
 693  
 694      /**
 695       * Fires before the display of a member's header.
 696       *
 697       * @since 1.2.0
 698       */
 699      do_action( 'bp_before_member_header' );
 700  
 701      // Get the template part for the header
 702      bp_nouveau_member_get_template_part( $template );
 703  
 704      /**
 705       * Fires after the display of a member's header.
 706       *
 707       * @since 1.2.0
 708       */
 709      do_action( 'bp_after_member_header' );
 710  
 711      bp_nouveau_template_notices();
 712  }
 713  
 714  /**
 715   * Get a link to set the Member's default front page and directly
 716   * reach the Customizer section where it's possible to do it.
 717   *
 718   * @since 3.0.0
 719   *
 720   * @return string HTML Output
 721   */
 722  function bp_nouveau_members_get_customizer_option_link() {
 723      return bp_nouveau_get_customizer_link(
 724          array(
 725              'object'    => 'user',
 726              'autofocus' => 'bp_nouveau_user_front_page',
 727              'text'      => __( 'Members default front page', 'buddypress' ),
 728          )
 729      );
 730  }
 731  
 732  /**
 733   * Get a link to set the Member's front page widgets and directly
 734   * reach the Customizer section where it's possible to do it.
 735   *
 736   * @since 3.0.0
 737   *
 738   * @return string HTML Output
 739   */
 740  function bp_nouveau_members_get_customizer_widgets_link() {
 741      return bp_nouveau_get_customizer_link(
 742          array(
 743              'object'    => 'user',
 744              'autofocus' => 'sidebar-widgets-sidebar-buddypress-members',
 745              'text'      => __( '(BuddyPress) Widgets', 'buddypress' ),
 746          )
 747      );
 748  }
 749  
 750  /**
 751   * Display the Member description making sure linefeeds are taking in account
 752   *
 753   * @since 3.0.0
 754   *
 755   * @param int $user_id Optional.
 756   *
 757   * @return string HTML output.
 758   */
 759  function bp_nouveau_member_description( $user_id = 0 ) {
 760      if ( ! $user_id ) {
 761          $user_id = bp_loggedin_user_id();
 762  
 763          if ( bp_displayed_user_id() ) {
 764              $user_id = bp_displayed_user_id();
 765          }
 766      }
 767  
 768      // @todo This hack is too brittle.
 769      add_filter( 'the_author_description', 'make_clickable', 9 );
 770      add_filter( 'the_author_description', 'wpautop' );
 771      add_filter( 'the_author_description', 'wptexturize' );
 772      add_filter( 'the_author_description', 'convert_smilies' );
 773      add_filter( 'the_author_description', 'convert_chars' );
 774      add_filter( 'the_author_description', 'stripslashes' );
 775  
 776      the_author_meta( 'description', $user_id );
 777  
 778      remove_filter( 'the_author_description', 'make_clickable', 9 );
 779      remove_filter( 'the_author_description', 'wpautop' );
 780      remove_filter( 'the_author_description', 'wptexturize' );
 781      remove_filter( 'the_author_description', 'convert_smilies' );
 782      remove_filter( 'the_author_description', 'convert_chars' );
 783      remove_filter( 'the_author_description', 'stripslashes' );
 784  }
 785  
 786  /**
 787   * Display the Edit profile link (temporary).
 788   *
 789   * @since 3.0.0
 790   *
 791   * @todo replace with Ajax feature
 792   *
 793   * @return string HTML Output
 794   */
 795  function bp_nouveau_member_description_edit_link() {
 796      echo bp_nouveau_member_get_description_edit_link();
 797  }
 798  
 799      /**
 800       * Get the Edit profile link (temporary)
 801       * @todo  replace with Ajax featur
 802       *
 803       * @since 3.0.0
 804       *
 805       * @return string HTML Output
 806       */
 807  	function bp_nouveau_member_get_description_edit_link() {
 808          remove_filter( 'edit_profile_url', 'bp_members_edit_profile_url', 10, 3 );
 809  
 810          if ( is_multisite() && ! current_user_can( 'read' ) ) {
 811              $link = get_dashboard_url( bp_displayed_user_id(), 'profile.php' );
 812          } else {
 813              $link = get_edit_profile_url( bp_displayed_user_id() );
 814          }
 815  
 816          add_filter( 'edit_profile_url', 'bp_members_edit_profile_url', 10, 3 );
 817          $link .= '#description';
 818  
 819          return sprintf( '<a href="%1$s">%2$s</a>', esc_url( $link ), esc_html__( 'Edit your bio', 'buddypress' ) );
 820      }
 821  
 822  
 823  /** WP Profile tags **********************************************************/
 824  
 825  /**
 826   * Template tag to wrap all Legacy actions that was used
 827   * before and after the WP User's Profile.
 828   *
 829   * @since 3.0.0
 830   */
 831  function bp_nouveau_wp_profile_hooks( $type = 'before' ) {
 832      if ( 'before' === $type ) {
 833          /**
 834           * Fires before the display of member profile loop content.
 835           *
 836           * @since 1.2.0
 837           */
 838          do_action( 'bp_before_profile_loop_content' );
 839  
 840          /**
 841           * Fires before the display of member profile field content.
 842           *
 843           * @since 1.1.0
 844           */
 845          do_action( 'bp_before_profile_field_content' );
 846      } else {
 847          /**
 848           * Fires after the display of member profile field content.
 849           *
 850           * @since 1.1.0
 851           */
 852          do_action( 'bp_after_profile_field_content' );
 853  
 854          /**
 855           * Fires and displays the profile field buttons.
 856           *
 857           * @since 1.1.0
 858           */
 859          do_action( 'bp_profile_field_buttons' );
 860  
 861          /**
 862           * Fires after the display of member profile loop content.
 863           *
 864           * @since 1.2.0
 865           */
 866          do_action( 'bp_after_profile_loop_content' );
 867      }
 868  }
 869  
 870  /**
 871   * Does the displayed user has WP profile fields?
 872   *
 873   * @since 3.0.0
 874   *
 875   * @return bool True if user has profile fields. False otherwise.
 876   */
 877  function bp_nouveau_has_wp_profile_fields() {
 878      $user_id = bp_displayed_user_id();
 879      if ( ! $user_id ) {
 880          return false;
 881      }
 882  
 883      $user = get_userdata( $user_id );
 884      if ( ! $user ) {
 885          return false;
 886      }
 887  
 888      $fields              = bp_nouveau_get_wp_profile_fields( $user );
 889      $user_profile_fields = array();
 890  
 891      foreach ( $fields as $key => $field ) {
 892          if ( empty( $user->{$key} ) ) {
 893              continue;
 894          }
 895  
 896          $user_profile_fields[] = (object) array(
 897              'id'    => 'wp_' . $key,
 898              'label' => $field,
 899              'data'  => $user->{$key},
 900          );
 901      }
 902  
 903      if ( ! $user_profile_fields ) {
 904          return false;
 905      }
 906  
 907      // Keep it for a later use.
 908      $bp_nouveau                            = bp_nouveau();
 909      $bp_nouveau->members->wp_profile       = $user_profile_fields;
 910      $bp_nouveau->members->wp_profile_index = 0;
 911  
 912      return true;
 913  }
 914  
 915  /**
 916   * Check if there are still profile fields to output.
 917   *
 918   * @since 3.0.0
 919   *
 920   * @return bool True if the profile field exists. False otherwise.
 921   */
 922  function bp_nouveau_wp_profile_fields() {
 923      $bp_nouveau = bp_nouveau();
 924  
 925      if ( isset( $bp_nouveau->members->wp_profile[ $bp_nouveau->members->wp_profile_index ] ) ) {
 926          return true;
 927      }
 928  
 929      $bp_nouveau->members->wp_profile_index = 0;
 930      unset( $bp_nouveau->members->wp_profile_current );
 931  
 932      return false;
 933  }
 934  
 935  /**
 936   * Set the current profile field and iterate into the loop.
 937   *
 938   * @since 3.0.0
 939   */
 940  function bp_nouveau_wp_profile_field() {
 941      $bp_nouveau = bp_nouveau();
 942  
 943      $bp_nouveau->members->wp_profile_current = $bp_nouveau->members->wp_profile[ $bp_nouveau->members->wp_profile_index ];
 944      $bp_nouveau->members->wp_profile_index  += 1;
 945  }
 946  
 947  /**
 948   * Output the WP profile field ID.
 949   *
 950   * @since 3.0.0
 951   */
 952  function bp_nouveau_wp_profile_field_id() {
 953      echo esc_attr( bp_nouveau_get_wp_profile_field_id() );
 954  }
 955      /**
 956       * Get the WP profile field ID.
 957       *
 958       * @since 3.0.0
 959       *
 960       * @return int the profile field ID.
 961       */
 962  	function bp_nouveau_get_wp_profile_field_id() {
 963          $field = bp_nouveau()->members->wp_profile_current;
 964  
 965          /**
 966           * Filters the WP profile field ID used for BuddyPress Nouveau.
 967           *
 968           * @since 3.0.0
 969           *
 970           * @param string $id Field ID.
 971           */
 972          return apply_filters( 'bp_nouveau_get_wp_profile_field_id', $field->id );
 973      }
 974  
 975  /**
 976   * Output the WP profile field label.
 977   *
 978   * @since 3.0.0
 979   */
 980  function bp_nouveau_wp_profile_field_label() {
 981      echo esc_html( bp_nouveau_get_wp_profile_field_label() );
 982  }
 983  
 984      /**
 985       * Get the WP profile label.
 986       *
 987       * @since 3.0.0
 988       *
 989       * @return string the profile field label.
 990       */
 991  	function bp_nouveau_get_wp_profile_field_label() {
 992          $field = bp_nouveau()->members->wp_profile_current;
 993  
 994          /**
 995           * Filters the WP profile field label used for BuddyPress Nouveau.
 996           *
 997           * @since 3.0.0
 998           *
 999           * @param string $label Field label.
1000           */
1001          return apply_filters( 'bp_nouveau_get_wp_profile_field_label', $field->label );
1002      }
1003  
1004  /**
1005   * Output the WP profile field data.
1006   *
1007   * @since 3.0.0
1008   */
1009  function bp_nouveau_wp_profile_field_data() {
1010      $data = bp_nouveau_get_wp_profile_field_data();
1011      $data = make_clickable( $data );
1012  
1013      echo wp_kses(
1014          /**
1015           * Filters a WP profile field value.
1016           *
1017           * @since 3.0.0
1018           *
1019           * @param string $data The profile field data value.
1020           */
1021          apply_filters( 'bp_nouveau_get_wp_profile_field_data', $data ),
1022          array(
1023              'a' => array(
1024                  'href' => true,
1025                  'rel'  => true,
1026              ),
1027          )
1028      );
1029  }
1030  
1031      /**
1032       * Get the WP profile field data.
1033       *
1034       * @since 3.0.0
1035       *
1036       * @return string the profile field data.
1037       */
1038  	function bp_nouveau_get_wp_profile_field_data() {
1039          $field = bp_nouveau()->members->wp_profile_current;
1040          return $field->data;
1041      }
1042  
1043  /**
1044   * Outputs the Invitations bulk actions dropdown list.
1045   *
1046   * @since 8.0.0
1047   */
1048  function bp_nouveau_invitations_bulk_management_dropdown() {
1049      ?>
1050      <div class="select-wrap">
1051  
1052          <label class="bp-screen-reader-text" for="invitation-select">
1053              <?php
1054              esc_html_e( 'Select Bulk Action', 'buddypress' );
1055              ?>
1056          </label>
1057  
1058          <select name="invitation_bulk_action" id="invitation-select">
1059              <option value="" selected="selected"><?php esc_html_e( 'Bulk Actions', 'buddypress' ); ?></option>
1060              <option value="resend"><?php echo esc_html_x( 'Resend', 'button', 'buddypress' ); ?></option>
1061              <option value="cancel"><?php echo esc_html_x( 'Cancel', 'button', 'buddypress' ); ?></option>
1062          </select>
1063  
1064          <span class="select-arrow"></span>
1065  
1066      </div><!-- // .select-wrap -->
1067  
1068      <input type="submit" id="invitation-bulk-manage" class="button action" value="<?php echo esc_attr_x( 'Apply', 'button', 'buddypress' ); ?>">
1069      <?php
1070  }


Generated: Thu Jun 24 01:01:38 2021 Cross-referenced by PHPXref 0.7.1