[ Index ]

PHP Cross Reference of BuddyPress

title

Body

[close]

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

   1  <?php
   2  /**
   3   * Members functions
   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   * Enqueue the members scripts
  14   *
  15   * @since 3.0.0
  16   */
  17  function bp_nouveau_members_enqueue_scripts() {
  18      // Neutralize Ajax when using BuddyPress Groups & member widgets on default front page
  19      if ( ! bp_is_user_front() || ! bp_nouveau_get_appearance_settings( 'user_front_page' ) ) {
  20          return;
  21      }
  22  
  23      wp_add_inline_style(
  24          'bp-nouveau', '
  25          #member-front-widgets #groups-list-options,
  26          #member-front-widgets #members-list-options,
  27          #member-front-widgets #friends-list-options {
  28              display: none;
  29          }
  30      '
  31      );
  32  }
  33  
  34  /**
  35   * Get the nav items for the Members directory
  36   *
  37   * @since 3.0.0
  38   *
  39   * @return array An associative array of nav items.
  40   */
  41  function bp_nouveau_get_members_directory_nav_items() {
  42      $nav_items = array();
  43  
  44      $nav_items['all'] = array(
  45          'component' => 'members',
  46          'slug'      => 'all', // slug is used because BP_Core_Nav requires it, but it's the scope
  47          'li_class'  => array(),
  48          'link'      => bp_get_members_directory_permalink(),
  49          'text'      => __( 'All Members', 'buddypress' ),
  50          'count'     => bp_get_total_member_count(),
  51          'position'  => 5,
  52      );
  53  
  54      if ( is_user_logged_in() ) {
  55          // If friends component is active and the user has friends
  56          if ( bp_is_active( 'friends' ) && bp_get_total_friend_count( bp_loggedin_user_id() ) ) {
  57              $nav_items['personal'] = array(
  58                  'component' => 'members',
  59                  'slug'      => 'personal', // slug is used because BP_Core_Nav requires it, but it's the scope
  60                  'li_class'  => array(),
  61                  'link'      => bp_loggedin_user_domain() . bp_get_friends_slug() . '/my-friends/',
  62                  'text'      => __( 'My Friends', 'buddypress' ),
  63                  'count'     => bp_get_total_friend_count( bp_loggedin_user_id() ),
  64                  'position'  => 15,
  65              );
  66          }
  67      }
  68  
  69      // Check for the deprecated hook :
  70      $extra_nav_items = bp_nouveau_parse_hooked_dir_nav( 'bp_members_directory_member_types', 'members', 20 );
  71      if ( ! empty( $extra_nav_items ) ) {
  72          $nav_items = array_merge( $nav_items, $extra_nav_items );
  73      }
  74  
  75      /**
  76       * Use this filter to introduce your custom nav items for the members directory.
  77       *
  78       * @since 3.0.0
  79       *
  80       * @param array $nav_items The list of the members directory nav items.
  81       */
  82      return apply_filters( 'bp_nouveau_get_members_directory_nav_items', $nav_items );
  83  }
  84  
  85  /**
  86   * Get Dropdown filters for the members component
  87   *
  88   * @since 3.0.0
  89   *
  90   * @param string $context Optional.
  91   *
  92   * @return array the filters
  93   */
  94  function bp_nouveau_get_members_filters( $context = '' ) {
  95      if ( 'group' !== $context ) {
  96          $filters = array(
  97              'active' => __( 'Last Active', 'buddypress' ),
  98              'newest' => __( 'Newest Registered', 'buddypress' ),
  99          );
 100  
 101          if ( bp_is_active( 'xprofile' ) ) {
 102              $filters['alphabetical'] = __( 'Alphabetical', 'buddypress' );
 103          }
 104  
 105          $action = 'bp_members_directory_order_options';
 106  
 107          if ( 'friends' === $context ) {
 108              $action = 'bp_member_friends_order_options';
 109          }
 110      } else {
 111          $filters = array(
 112              'last_joined'  => __( 'Newest', 'buddypress' ),
 113              'first_joined' => __( 'Oldest', 'buddypress' ),
 114          );
 115  
 116          if ( bp_is_active( 'activity' ) ) {
 117              $filters['group_activity'] = __( 'Group Activity', 'buddypress' );
 118          }
 119  
 120          $filters['alphabetical'] = __( 'Alphabetical', 'buddypress' );
 121          $action                  = 'bp_groups_members_order_options';
 122      }
 123  
 124      /**
 125       * Recommended, filter here instead of adding an action to 'bp_members_directory_order_options'
 126       *
 127       * @since 3.0.0
 128       *
 129       * @param array  the members filters.
 130       * @param string the context.
 131       */
 132      $filters = apply_filters( 'bp_nouveau_get_members_filters', $filters, $context );
 133  
 134      return bp_nouveau_parse_hooked_options( $action, $filters );
 135  }
 136  
 137  /**
 138   * Catch the arguments for buttons
 139   *
 140   * @since 3.0.0
 141   *
 142   * @param array $buttons The arguments of the button that BuddyPress is about to create.
 143   *
 144   * @return array An empty array to stop the button creation process.
 145   */
 146  function bp_nouveau_members_catch_button_args( $button = array() ) {
 147      /*
 148       * Globalize the arguments so that we can use it
 149       * in bp_nouveau_get_member_header_buttons().
 150       */
 151      bp_nouveau()->members->button_args = $button;
 152  
 153      // return an empty array to stop the button creation process
 154      return array();
 155  }
 156  
 157  /**
 158   * Catch the content hooked to the do_action hooks in single member header
 159   * and in the members loop.
 160   *
 161   * @since 3.0.0
 162   * @since 6.0.0 Replace wrongly positioned `bp_directory_members_item`
 163   *              with `bp_directory_members_item_meta`
 164   *
 165   * @return string|false HTML Output if hooked. False otherwise.
 166   */
 167  function bp_nouveau_get_hooked_member_meta() {
 168      ob_start();
 169  
 170      if ( ! empty( $GLOBALS['members_template'] ) ) {
 171          /**
 172           * Fires inside the display of metas in the directory member item.
 173           *
 174           * @since 6.0.0
 175           */
 176          do_action( 'bp_directory_members_item_meta' );
 177  
 178      // It's the user's header
 179      } else {
 180          /**
 181           * Fires after the group header actions section.
 182           *
 183           * If you'd like to show specific profile fields here use:
 184           * bp_member_profile_data( 'field=About Me' ); -- Pass the name of the field
 185           *
 186           * @since 1.2.0
 187           */
 188          do_action( 'bp_profile_header_meta' );
 189      }
 190  
 191      $output = ob_get_clean();
 192  
 193      if ( ! empty( $output ) ) {
 194          return $output;
 195      }
 196  
 197      return false;
 198  }
 199  
 200  /**
 201   * Add the default user front template to the front template hierarchy
 202   *
 203   * @since 3.0.0
 204   *
 205   * @param array $templates The list of templates for the front.php template part.
 206   *
 207   * @return array The same list with the default front template if needed.
 208   */
 209  function bp_nouveau_member_reset_front_template( $templates = array() ) {
 210      $use_default_front = bp_nouveau_get_appearance_settings( 'user_front_page' );
 211  
 212      // Setting the front template happens too early, so we need this!
 213      if ( is_customize_preview() ) {
 214          $use_default_front = bp_nouveau_get_temporary_setting( 'user_front_page', $use_default_front );
 215      }
 216  
 217      if ( ! empty( $use_default_front ) ) {
 218          array_push( $templates, 'members/single/default-front.php' );
 219      }
 220  
 221      /**
 222       * Filters the BuddyPress Nouveau template hierarchy after resetting front template for members.
 223       *
 224       * @since 3.0.0
 225       *
 226       * @param array $templates Array of templates.
 227       */
 228      return apply_filters( '_bp_nouveau_member_reset_front_template', $templates );
 229  }
 230  
 231  /**
 232   * Only locate global user's front templates
 233   *
 234   * @since 3.0.0
 235   *
 236   * @param array $templates The User's front template hierarchy.
 237   *
 238   * @return array Only the global front templates.
 239   */
 240  function bp_nouveau_member_restrict_user_front_templates( $templates = array() ) {
 241      return array_intersect( array(
 242          'members/single/front.php',
 243          'members/single/default-front.php',
 244      ), $templates );
 245  }
 246  
 247  /**
 248   * Locate a single member template into a specific hierarchy.
 249   *
 250   * @since 3.0.0
 251   *
 252   * @param string $template The template part to get (eg: activity, groups...).
 253   *
 254   * @return string The located template.
 255   */
 256  function bp_nouveau_member_locate_template_part( $template = '' ) {
 257      $displayed_user = bp_get_displayed_user();
 258      $bp_nouveau     = bp_nouveau();
 259  
 260      if ( ! $template || empty( $displayed_user->id ) ) {
 261          return '';
 262      }
 263  
 264      // Use a global to avoid requesting the hierarchy for each template
 265      if ( ! isset( $bp_nouveau->members->displayed_user_hierarchy ) ) {
 266          $bp_nouveau->members->displayed_user_hierarchy = array(
 267              'members/single/%s-id-' . (int) $displayed_user->id . '.php',
 268              'members/single/%s-nicename-' . sanitize_file_name( $displayed_user->userdata->user_nicename ) . '.php',
 269          );
 270  
 271          /*
 272           * Check for member types and add it to the hierarchy
 273           *
 274           * Make sure to register your member
 275           * type using the hook 'bp_register_member_types'
 276           */
 277          if ( bp_get_member_types() ) {
 278              $displayed_user_member_type = bp_get_member_type( $displayed_user->id );
 279              if ( ! $displayed_user_member_type ) {
 280                  $displayed_user_member_type = 'none';
 281              }
 282  
 283              $bp_nouveau->members->displayed_user_hierarchy[] = 'members/single/%s-member-type-' . sanitize_file_name( $displayed_user_member_type ) . '.php';
 284          }
 285  
 286          // And the regular one
 287          $bp_nouveau->members->displayed_user_hierarchy[] = 'members/single/%s.php';
 288      }
 289  
 290      $templates = array();
 291  
 292      // Loop in the hierarchy to fill it for the requested template part
 293      foreach ( $bp_nouveau->members->displayed_user_hierarchy as $part ) {
 294          $templates[] = sprintf( $part, $template );
 295      }
 296  
 297      /**
 298       * Filters the found template parts for the member template part locating functionality.
 299       *
 300       * @since 3.0.0
 301       *
 302       * @param array $templates Array of found templates.
 303       */
 304      return bp_locate_template( apply_filters( 'bp_nouveau_member_locate_template_part', $templates ), false, true );
 305  }
 306  
 307  /**
 308   * Load a single member template part
 309   *
 310   * @since 3.0.0
 311   *
 312   * @param string $template The template part to get (eg: activity, groups...).
 313   *
 314   * @return string HTML output.
 315   */
 316  function bp_nouveau_member_get_template_part( $template = '' ) {
 317      $located = bp_nouveau_member_locate_template_part( $template );
 318  
 319      if ( false !== $located ) {
 320          $slug = str_replace( '.php', '', $located );
 321          $name = null;
 322  
 323          /**
 324           * Let plugins adding an action to bp_get_template_part get it from here.
 325           *
 326           * @since 3.0.0
 327           *
 328           * @param string $slug Template part slug requested.
 329           * @param string $name Template part name requested.
 330           */
 331          do_action( 'get_template_part_' . $slug, $slug, $name );
 332  
 333          load_template( $located, true );
 334      }
 335  
 336      return $located;
 337  }
 338  
 339  /**
 340   * Display the User's WordPress bio info into the default front page?
 341   *
 342   * @since 3.0.0
 343   *
 344   * @return bool True to display. False otherwise.
 345   */
 346  function bp_nouveau_members_wp_bio_info() {
 347      $user_settings = bp_nouveau_get_appearance_settings();
 348  
 349      return ! empty( $user_settings['user_front_page'] ) && ! empty( $user_settings['user_front_bio'] );
 350  }
 351  
 352  /**
 353   * Are we inside the Current user's default front page sidebar?
 354   *
 355   * @since 3.0.0
 356   *
 357   * @return bool True if in the group's home sidebar. False otherwise.
 358   */
 359  function bp_nouveau_member_is_home_widgets() {
 360      return ( true === bp_nouveau()->members->is_user_home_sidebar );
 361  }
 362  
 363  /**
 364   * Filter the Latest activities Widget to only keep the one of displayed user
 365   *
 366   * @since 3.0.0
 367   *
 368   * @param array $args The Activities Template arguments.
 369   *
 370   * @return array The Activities Template arguments.
 371   */
 372  function bp_nouveau_member_activity_widget_overrides( $args = array() ) {
 373      return array_merge( $args, array(
 374          'user_id' => bp_displayed_user_id(),
 375      ) );
 376  }
 377  
 378  /**
 379   * Filter the Groups widget to only keep the groups the displayed user is a member of.
 380   *
 381   * @since 3.0.0
 382   *
 383   * @param array $args The Groups Template arguments.
 384   *
 385   * @return array The Groups Template arguments.
 386   */
 387  function bp_nouveau_member_groups_widget_overrides( $args = array() ) {
 388      return array_merge( $args, array(
 389          'user_id' => bp_displayed_user_id(),
 390      ) );
 391  }
 392  
 393  /**
 394   * Filter the Members widgets to only keep members of the displayed group.
 395   *
 396   * @since 3.0.0
 397   *
 398   * @param array $args The Members Template arguments.
 399   *
 400   * @return array The Members Template arguments.
 401   */
 402  function bp_nouveau_member_members_widget_overrides( $args = array() ) {
 403      // Do nothing for the friends widget
 404      if ( ! empty( $args['user_id'] ) && (int) $args['user_id'] === (int) bp_displayed_user_id() ) {
 405          return $args;
 406      }
 407  
 408      return array_merge( $args, array(
 409          'include' => bp_displayed_user_id(),
 410      ) );
 411  }
 412  
 413  /**
 414   * Init the Member's default front page filters as we're in the sidebar
 415   *
 416   * @since 3.0.0
 417   */
 418  function bp_nouveau_members_add_home_widget_filters() {
 419      add_filter( 'bp_nouveau_activity_widget_query', 'bp_nouveau_member_activity_widget_overrides', 10, 1 );
 420      add_filter( 'bp_before_has_groups_parse_args', 'bp_nouveau_member_groups_widget_overrides', 10, 1 );
 421      add_filter( 'bp_before_has_members_parse_args', 'bp_nouveau_member_members_widget_overrides', 10, 1 );
 422  
 423      /**
 424       * Fires after Nouveau adds its members home widget filters.
 425       *
 426       * @since 3.0.0
 427       */
 428      do_action( 'bp_nouveau_members_add_home_widget_filters' );
 429  }
 430  
 431  /**
 432   * Remove the Member's default front page filters as we're no more in the sidebar
 433   *
 434   * @since 3.0.0
 435   */
 436  function bp_nouveau_members_remove_home_widget_filters() {
 437      remove_filter( 'bp_nouveau_activity_widget_query', 'bp_nouveau_member_activity_widget_overrides', 10, 1 );
 438      remove_filter( 'bp_before_has_groups_parse_args', 'bp_nouveau_member_groups_widget_overrides', 10, 1 );
 439      remove_filter( 'bp_before_has_members_parse_args', 'bp_nouveau_member_members_widget_overrides', 10, 1 );
 440  
 441      /**
 442       * Fires after Nouveau removes its members home widget filters.
 443       *
 444       * @since 3.0.0
 445       */
 446      do_action( 'bp_nouveau_members_remove_home_widget_filters' );
 447  }
 448  
 449  /**
 450   * Get the WP Profile fields for all or a specific user
 451   *
 452   * @since 3.0.0
 453   *
 454   * @param WP_User $user The user object. Optional.
 455   *
 456   * @return array The list of WP Profile fields
 457   */
 458  function bp_nouveau_get_wp_profile_fields( $user = null ) {
 459      /**
 460       * Filters the contact methods to be included in the WP Profile fields for a specific user.
 461       *
 462       * Provide a chance for plugins to avoid showing the contact methods they're adding on front end.
 463       *
 464       * @since 3.0.0
 465       *
 466       * @param array   $value Array of user contact methods.
 467       * @param WP_User $user  WordPress user to get contact methods for.
 468       */
 469      $contact_methods = (array) apply_filters( 'bp_nouveau_get_wp_profile_field', wp_get_user_contact_methods( $user ), $user );
 470  
 471      $wp_fields = array(
 472          'display_name'     => __( 'Name', 'buddypress' ),
 473          'user_description' => __( 'About Me', 'buddypress' ),
 474          'user_url'         => __( 'Website', 'buddypress' ),
 475      );
 476  
 477      return array_merge( $wp_fields, $contact_methods );
 478  }
 479  
 480  /**
 481   * Build the Member's nav for the our customizer control.
 482   *
 483   * @since 3.0.0
 484   *
 485   * @return array The Members single item primary nav ordered.
 486   */
 487  function bp_nouveau_member_customizer_nav() {
 488      add_filter( '_bp_nouveau_member_reset_front_template', 'bp_nouveau_member_restrict_user_front_templates', 10, 1 );
 489  
 490      if ( bp_displayed_user_get_front_template( buddypress()->loggedin_user ) ) {
 491          buddypress()->members->nav->add_nav(
 492              array(
 493                  'name'     => _x( 'Home', 'Member Home page', 'buddypress' ),
 494                  'slug'     => 'front',
 495                  'position' => 5,
 496              )
 497          );
 498      }
 499  
 500      remove_filter( '_bp_nouveau_member_reset_front_template', 'bp_nouveau_member_restrict_user_front_templates', 10, 1 );
 501  
 502      $nav = buddypress()->members->nav;
 503  
 504      // Eventually reset the order.
 505      bp_nouveau_set_nav_item_order( $nav, bp_nouveau_get_appearance_settings( 'user_nav_order' ) );
 506  
 507      return $nav->get_primary();
 508  }


Generated: Wed Aug 12 01:01:32 2020 Cross-referenced by PHPXref 0.7.1