[ 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 9.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           * @since 9.0.0 Adds the `$args` parameter to the filter.
 470           *
 471           * @param array  $buttons The list of buttons.
 472           * @param int    $user_id The displayed user ID.
 473           * @param string $type    Whether we're displaying a members loop or a user's page
 474           * @param array  $args    Button arguments.
 475           */
 476          $buttons_group = apply_filters( 'bp_nouveau_get_members_buttons', $buttons, $user_id, $type, $args );
 477          if ( ! $buttons_group ) {
 478              return $buttons;
 479          }
 480  
 481          // It's the first entry of the loop, so build the Group and sort it
 482          if ( ! isset( bp_nouveau()->members->member_buttons ) || ! is_a( bp_nouveau()->members->member_buttons, 'BP_Buttons_Group' ) ) {
 483              $sort = true;
 484              bp_nouveau()->members->member_buttons = new BP_Buttons_Group( $buttons_group );
 485  
 486          // It's not the first entry, the order is set, we simply need to update the Buttons Group
 487          } else {
 488              $sort = false;
 489              bp_nouveau()->members->member_buttons->update( $buttons_group );
 490          }
 491  
 492          $return = bp_nouveau()->members->member_buttons->get( $sort );
 493  
 494          if ( ! $return ) {
 495              return array();
 496          }
 497  
 498          /**
 499           * Leave a chance to adjust the $return
 500           *
 501           * @since 3.0.0
 502           *
 503           * @param array  $return  The list of buttons ordered.
 504           * @param int    $user_id The displayed user ID.
 505           * @param string $type    Whether we're displaying a members loop or a user's page
 506           */
 507          do_action_ref_array( 'bp_nouveau_return_members_buttons', array( &$return, $user_id, $type ) );
 508  
 509          return $return;
 510      }
 511  
 512  /**
 513   * Does the member has meta.
 514   *
 515   * @since 3.0.0
 516   *
 517   * @return bool True if the member has meta. False otherwise.
 518   */
 519  function bp_nouveau_member_has_meta() {
 520      return (bool) bp_nouveau_get_member_meta();
 521  }
 522  
 523  /**
 524   * Display the member meta.
 525   *
 526   * @since 3.0.0
 527   *
 528   * @return string HTML Output.
 529   */
 530  function bp_nouveau_member_meta() {
 531      echo join( "\n", bp_nouveau_get_member_meta() );
 532  }
 533  
 534      /**
 535       * Get the member meta.
 536       *
 537       * @since 3.0.0
 538       *
 539       * @return array The member meta.
 540       */
 541  	function bp_nouveau_get_member_meta() {
 542          $meta    = array();
 543          $is_loop = false;
 544  
 545          if ( ! empty( $GLOBALS['members_template']->member ) ) {
 546              $member  = $GLOBALS['members_template']->member;
 547              $is_loop = true;
 548          } else {
 549              $member = bp_get_displayed_user();
 550          }
 551  
 552          if ( empty( $member->id ) ) {
 553              return $meta;
 554          }
 555  
 556          if ( empty( $member->template_meta ) ) {
 557              // It's a single user's header
 558              if ( ! $is_loop ) {
 559                  $meta['last_activity'] = sprintf(
 560                      '<span class="activity">%s</span>',
 561                      esc_html( bp_get_last_activity( bp_displayed_user_id() ) )
 562                  );
 563  
 564              // We're in the members loop
 565              } else {
 566                  $meta = array(
 567                      'last_activity' => sprintf( '%s', bp_get_member_last_active() ),
 568                  );
 569              }
 570  
 571              // Make sure to include hooked meta.
 572              $extra_meta = bp_nouveau_get_hooked_member_meta();
 573  
 574              if ( $extra_meta ) {
 575                  $meta['extra'] = $extra_meta;
 576              }
 577  
 578              /**
 579               * Filter to add/remove Member meta.
 580               *
 581               * @since 3.0.0
 582               *
 583               * @param array  $meta    The list of meta to output.
 584               * @param object $member  The member object
 585               * @param bool   $is_loop True if in the members loop. False otherwise.
 586               */
 587              $member->template_meta = apply_filters( 'bp_nouveau_get_member_meta', $meta, $member, $is_loop );
 588          }
 589  
 590          return $member->template_meta;
 591      }
 592  
 593  /**
 594   * Check if some extra content needs to be displayed into the members directory.
 595   *
 596   * @since 6.0.0
 597   *
 598   * @return bool True if some extra content needs to be displayed into the members directory.
 599   *              False otherwise.
 600   */
 601  function bp_nouveau_member_has_extra_content() {
 602      /**
 603       * Filter here to display the extra content not only into the Members directory.
 604       *
 605       * @since 6.0.0
 606       *
 607       * @param bool $value True if on the Members directory page.
 608       *                    False otherwise.
 609       */
 610      $members_directory_only = (bool) apply_filters( 'bp_nouveau_member_extra_content_in_members_directory', bp_is_members_directory() );
 611  
 612      // Check if some extra content needs to be included into the item of the loop.
 613      $has_action = (bool) has_action( 'bp_directory_members_item' );
 614  
 615      return $members_directory_only && $has_action;
 616  }
 617  
 618  /**
 619   * Displays extra content for each item of a members loop.
 620   *
 621   * @since 6.0.0
 622   */
 623  function bp_nouveau_member_extra_content() {
 624      /**
 625       * Fires inside the display of a members loop member item.
 626       *
 627       * @since 1.1.0
 628       */
 629      do_action( 'bp_directory_members_item' );
 630  }
 631  
 632  /**
 633   * Load the appropriate content for the single member pages
 634   *
 635   * @since 3.0.0
 636   */
 637  function bp_nouveau_member_template_part() {
 638      /**
 639       * Fires before the display of member body content.
 640       *
 641       * @since 1.2.0
 642       */
 643      do_action( 'bp_before_member_body' );
 644  
 645      if ( bp_is_user_front() ) {
 646          bp_displayed_user_front_template_part();
 647  
 648      } else {
 649          $template = 'plugins';
 650  
 651          if ( bp_is_user_activity() ) {
 652              $template = 'activity';
 653          } elseif ( bp_is_user_blogs() ) {
 654              $template = 'blogs';
 655          } elseif ( bp_is_user_friends() ) {
 656              $template = 'friends';
 657          } elseif ( bp_is_user_groups() ) {
 658              $template = 'groups';
 659          } elseif ( bp_is_user_messages() ) {
 660              $template = 'messages';
 661          } elseif ( bp_is_user_profile() ) {
 662              $template = 'profile';
 663          } elseif ( bp_is_user_notifications() ) {
 664              $template = 'notifications';
 665          } elseif ( bp_is_user_members_invitations() ) {
 666              $template = 'invitations';
 667          } elseif ( bp_is_user_settings() ) {
 668              $template = 'settings';
 669          }
 670  
 671          bp_nouveau_member_get_template_part( $template );
 672      }
 673  
 674      /**
 675       * Fires after the display of member body content.
 676       *
 677       * @since 1.2.0
 678       */
 679      do_action( 'bp_after_member_body' );
 680  }
 681  
 682  /**
 683   * Use the appropriate Member header and enjoy a template hierarchy
 684   *
 685   * @since 3.0.0
 686   *
 687   * @return string HTML Output
 688   */
 689  function bp_nouveau_member_header_template_part() {
 690      $template = 'member-header';
 691  
 692      if ( bp_displayed_user_use_cover_image_header() ) {
 693          $template = 'cover-image-header';
 694      }
 695  
 696      /**
 697       * Fires before the display of a member's header.
 698       *
 699       * @since 1.2.0
 700       */
 701      do_action( 'bp_before_member_header' );
 702  
 703      // Get the template part for the header
 704      bp_nouveau_member_get_template_part( $template );
 705  
 706      /**
 707       * Fires after the display of a member's header.
 708       *
 709       * @since 1.2.0
 710       */
 711      do_action( 'bp_after_member_header' );
 712  
 713      bp_nouveau_template_notices();
 714  }
 715  
 716  /**
 717   * Get a link to set the Member's default front page and directly
 718   * reach the Customizer section where it's possible to do it.
 719   *
 720   * @since 3.0.0
 721   *
 722   * @return string HTML Output
 723   */
 724  function bp_nouveau_members_get_customizer_option_link() {
 725      return bp_nouveau_get_customizer_link(
 726          array(
 727              'object'    => 'user',
 728              'autofocus' => 'bp_nouveau_user_front_page',
 729              'text'      => __( 'Members default front page', 'buddypress' ),
 730          )
 731      );
 732  }
 733  
 734  /**
 735   * Get a link to set the Member's front page widgets and directly
 736   * reach the Customizer section where it's possible to do it.
 737   *
 738   * @since 3.0.0
 739   *
 740   * @return string HTML Output
 741   */
 742  function bp_nouveau_members_get_customizer_widgets_link() {
 743      return bp_nouveau_get_customizer_link(
 744          array(
 745              'object'    => 'user',
 746              'autofocus' => 'sidebar-widgets-sidebar-buddypress-members',
 747              'text'      => __( '(BuddyPress) Widgets', 'buddypress' ),
 748          )
 749      );
 750  }
 751  
 752  /**
 753   * Display the Member description making sure linefeeds are taking in account
 754   *
 755   * @since 3.0.0
 756   *
 757   * @param int $user_id Optional.
 758   *
 759   * @return string HTML output.
 760   */
 761  function bp_nouveau_member_description( $user_id = 0 ) {
 762      if ( ! $user_id ) {
 763          $user_id = bp_loggedin_user_id();
 764  
 765          if ( bp_displayed_user_id() ) {
 766              $user_id = bp_displayed_user_id();
 767          }
 768      }
 769  
 770      // @todo This hack is too brittle.
 771      add_filter( 'the_author_description', 'make_clickable', 9 );
 772      add_filter( 'the_author_description', 'wpautop' );
 773      add_filter( 'the_author_description', 'wptexturize' );
 774      add_filter( 'the_author_description', 'convert_smilies' );
 775      add_filter( 'the_author_description', 'convert_chars' );
 776      add_filter( 'the_author_description', 'stripslashes' );
 777  
 778      the_author_meta( 'description', $user_id );
 779  
 780      remove_filter( 'the_author_description', 'make_clickable', 9 );
 781      remove_filter( 'the_author_description', 'wpautop' );
 782      remove_filter( 'the_author_description', 'wptexturize' );
 783      remove_filter( 'the_author_description', 'convert_smilies' );
 784      remove_filter( 'the_author_description', 'convert_chars' );
 785      remove_filter( 'the_author_description', 'stripslashes' );
 786  }
 787  
 788  /**
 789   * Display the Edit profile link (temporary).
 790   *
 791   * @since 3.0.0
 792   *
 793   * @todo replace with Ajax feature
 794   *
 795   * @return string HTML Output
 796   */
 797  function bp_nouveau_member_description_edit_link() {
 798      echo bp_nouveau_member_get_description_edit_link();
 799  }
 800  
 801      /**
 802       * Get the Edit profile link (temporary)
 803       * @todo  replace with Ajax featur
 804       *
 805       * @since 3.0.0
 806       *
 807       * @return string HTML Output
 808       */
 809  	function bp_nouveau_member_get_description_edit_link() {
 810          remove_filter( 'edit_profile_url', 'bp_members_edit_profile_url', 10, 3 );
 811  
 812          if ( is_multisite() && ! current_user_can( 'read' ) ) {
 813              $link = get_dashboard_url( bp_displayed_user_id(), 'profile.php' );
 814          } else {
 815              $link = get_edit_profile_url( bp_displayed_user_id() );
 816          }
 817  
 818          add_filter( 'edit_profile_url', 'bp_members_edit_profile_url', 10, 3 );
 819          $link .= '#description';
 820  
 821          return sprintf( '<a href="%1$s">%2$s</a>', esc_url( $link ), esc_html__( 'Edit your bio', 'buddypress' ) );
 822      }
 823  
 824  
 825  /** WP Profile tags **********************************************************/
 826  
 827  /**
 828   * Template tag to wrap all Legacy actions that was used
 829   * before and after the WP User's Profile.
 830   *
 831   * @since 3.0.0
 832   */
 833  function bp_nouveau_wp_profile_hooks( $type = 'before' ) {
 834      if ( 'before' === $type ) {
 835          /**
 836           * Fires before the display of member profile loop content.
 837           *
 838           * @since 1.2.0
 839           */
 840          do_action( 'bp_before_profile_loop_content' );
 841  
 842          /**
 843           * Fires before the display of member profile field content.
 844           *
 845           * @since 1.1.0
 846           */
 847          do_action( 'bp_before_profile_field_content' );
 848      } else {
 849          /**
 850           * Fires after the display of member profile field content.
 851           *
 852           * @since 1.1.0
 853           */
 854          do_action( 'bp_after_profile_field_content' );
 855  
 856          /**
 857           * Fires and displays the profile field buttons.
 858           *
 859           * @since 1.1.0
 860           */
 861          do_action( 'bp_profile_field_buttons' );
 862  
 863          /**
 864           * Fires after the display of member profile loop content.
 865           *
 866           * @since 1.2.0
 867           */
 868          do_action( 'bp_after_profile_loop_content' );
 869      }
 870  }
 871  
 872  /**
 873   * Does the displayed user has WP profile fields?
 874   *
 875   * @since 3.0.0
 876   *
 877   * @return bool True if user has profile fields. False otherwise.
 878   */
 879  function bp_nouveau_has_wp_profile_fields() {
 880      $user_id = bp_displayed_user_id();
 881      if ( ! $user_id ) {
 882          return false;
 883      }
 884  
 885      $user = get_userdata( $user_id );
 886      if ( ! $user ) {
 887          return false;
 888      }
 889  
 890      $fields              = bp_nouveau_get_wp_profile_fields( $user );
 891      $user_profile_fields = array();
 892  
 893      foreach ( $fields as $key => $field ) {
 894          if ( empty( $user->{$key} ) ) {
 895              continue;
 896          }
 897  
 898          $user_profile_fields[] = (object) array(
 899              'id'    => 'wp_' . $key,
 900              'label' => $field,
 901              'data'  => $user->{$key},
 902          );
 903      }
 904  
 905      if ( ! $user_profile_fields ) {
 906          return false;
 907      }
 908  
 909      // Keep it for a later use.
 910      $bp_nouveau                            = bp_nouveau();
 911      $bp_nouveau->members->wp_profile       = $user_profile_fields;
 912      $bp_nouveau->members->wp_profile_index = 0;
 913  
 914      return true;
 915  }
 916  
 917  /**
 918   * Check if there are still profile fields to output.
 919   *
 920   * @since 3.0.0
 921   *
 922   * @return bool True if the profile field exists. False otherwise.
 923   */
 924  function bp_nouveau_wp_profile_fields() {
 925      $bp_nouveau = bp_nouveau();
 926  
 927      if ( isset( $bp_nouveau->members->wp_profile[ $bp_nouveau->members->wp_profile_index ] ) ) {
 928          return true;
 929      }
 930  
 931      $bp_nouveau->members->wp_profile_index = 0;
 932      unset( $bp_nouveau->members->wp_profile_current );
 933  
 934      return false;
 935  }
 936  
 937  /**
 938   * Set the current profile field and iterate into the loop.
 939   *
 940   * @since 3.0.0
 941   */
 942  function bp_nouveau_wp_profile_field() {
 943      $bp_nouveau = bp_nouveau();
 944  
 945      $bp_nouveau->members->wp_profile_current = $bp_nouveau->members->wp_profile[ $bp_nouveau->members->wp_profile_index ];
 946      $bp_nouveau->members->wp_profile_index  += 1;
 947  }
 948  
 949  /**
 950   * Output the WP profile field ID.
 951   *
 952   * @since 3.0.0
 953   */
 954  function bp_nouveau_wp_profile_field_id() {
 955      echo esc_attr( bp_nouveau_get_wp_profile_field_id() );
 956  }
 957      /**
 958       * Get the WP profile field ID.
 959       *
 960       * @since 3.0.0
 961       *
 962       * @return int the profile field ID.
 963       */
 964  	function bp_nouveau_get_wp_profile_field_id() {
 965          $field = bp_nouveau()->members->wp_profile_current;
 966  
 967          /**
 968           * Filters the WP profile field ID used for BuddyPress Nouveau.
 969           *
 970           * @since 3.0.0
 971           *
 972           * @param string $id Field ID.
 973           */
 974          return apply_filters( 'bp_nouveau_get_wp_profile_field_id', $field->id );
 975      }
 976  
 977  /**
 978   * Output the WP profile field label.
 979   *
 980   * @since 3.0.0
 981   */
 982  function bp_nouveau_wp_profile_field_label() {
 983      echo esc_html( bp_nouveau_get_wp_profile_field_label() );
 984  }
 985  
 986      /**
 987       * Get the WP profile label.
 988       *
 989       * @since 3.0.0
 990       *
 991       * @return string the profile field label.
 992       */
 993  	function bp_nouveau_get_wp_profile_field_label() {
 994          $field = bp_nouveau()->members->wp_profile_current;
 995  
 996          /**
 997           * Filters the WP profile field label used for BuddyPress Nouveau.
 998           *
 999           * @since 3.0.0
1000           *
1001           * @param string $label Field label.
1002           */
1003          return apply_filters( 'bp_nouveau_get_wp_profile_field_label', $field->label );
1004      }
1005  
1006  /**
1007   * Output the WP profile field data.
1008   *
1009   * @since 3.0.0
1010   */
1011  function bp_nouveau_wp_profile_field_data() {
1012      $data = bp_nouveau_get_wp_profile_field_data();
1013      $data = make_clickable( $data );
1014  
1015      echo wp_kses(
1016          /**
1017           * Filters a WP profile field value.
1018           *
1019           * @since 3.0.0
1020           *
1021           * @param string $data The profile field data value.
1022           */
1023          apply_filters( 'bp_nouveau_get_wp_profile_field_data', $data ),
1024          array(
1025              'a' => array(
1026                  'href' => true,
1027                  'rel'  => true,
1028              ),
1029          )
1030      );
1031  }
1032  
1033      /**
1034       * Get the WP profile field data.
1035       *
1036       * @since 3.0.0
1037       *
1038       * @return string the profile field data.
1039       */
1040  	function bp_nouveau_get_wp_profile_field_data() {
1041          $field = bp_nouveau()->members->wp_profile_current;
1042          return $field->data;
1043      }
1044  
1045  /**
1046   * Outputs the Invitations bulk actions dropdown list.
1047   *
1048   * @since 8.0.0
1049   */
1050  function bp_nouveau_invitations_bulk_management_dropdown() {
1051      ?>
1052      <div class="select-wrap">
1053  
1054          <label class="bp-screen-reader-text" for="invitation-select">
1055              <?php
1056              esc_html_e( 'Select Bulk Action', 'buddypress' );
1057              ?>
1058          </label>
1059  
1060          <select name="invitation_bulk_action" id="invitation-select">
1061              <option value="" selected="selected"><?php esc_html_e( 'Bulk Actions', 'buddypress' ); ?></option>
1062              <option value="resend"><?php echo esc_html_x( 'Resend', 'button', 'buddypress' ); ?></option>
1063              <option value="cancel"><?php echo esc_html_x( 'Cancel', 'button', 'buddypress' ); ?></option>
1064          </select>
1065  
1066          <span class="select-arrow"></span>
1067  
1068      </div><!-- // .select-wrap -->
1069  
1070      <input type="submit" id="invitation-bulk-manage" class="button action" value="<?php echo esc_attr_x( 'Apply', 'button', 'buddypress' ); ?>">
1071      <?php
1072  }


Generated: Fri Sep 24 01:01:36 2021 Cross-referenced by PHPXref 0.7.1