[ 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 3.1.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   *
 163   * @return string|false HTML Output if hooked. False otherwise.
 164   */
 165  function bp_nouveau_get_hooked_member_meta() {
 166      ob_start();
 167  
 168      if ( ! empty( $GLOBALS['members_template'] ) ) {
 169          /**
 170           * Fires inside the display of a directory member item.
 171           *
 172           * @since 1.1.0
 173           */
 174          do_action( 'bp_directory_members_item' );
 175  
 176      // It's the user's header
 177      } else {
 178          /**
 179           * Fires after the group header actions section.
 180           *
 181           * If you'd like to show specific profile fields here use:
 182           * bp_member_profile_data( 'field=About Me' ); -- Pass the name of the field
 183           *
 184           * @since 1.2.0
 185           */
 186          do_action( 'bp_profile_header_meta' );
 187      }
 188  
 189      $output = ob_get_clean();
 190  
 191      if ( ! empty( $output ) ) {
 192          return $output;
 193      }
 194  
 195      return false;
 196  }
 197  
 198  /**
 199   * Add the default user front template to the front template hierarchy
 200   *
 201   * @since 3.0.0
 202   *
 203   * @param array $templates The list of templates for the front.php template part.
 204   *
 205   * @return array The same list with the default front template if needed.
 206   */
 207  function bp_nouveau_member_reset_front_template( $templates = array() ) {
 208      $use_default_front = bp_nouveau_get_appearance_settings( 'user_front_page' );
 209  
 210      // Setting the front template happens too early, so we need this!
 211      if ( is_customize_preview() ) {
 212          $use_default_front = bp_nouveau_get_temporary_setting( 'user_front_page', $use_default_front );
 213      }
 214  
 215      if ( ! empty( $use_default_front ) ) {
 216          array_push( $templates, 'members/single/default-front.php' );
 217      }
 218  
 219      /**
 220       * Filters the BuddyPress Nouveau template hierarchy after resetting front template for members.
 221       *
 222       * @since 3.0.0
 223       *
 224       * @param array $templates Array of templates.
 225       */
 226      return apply_filters( '_bp_nouveau_member_reset_front_template', $templates );
 227  }
 228  
 229  /**
 230   * Only locate global user's front templates
 231   *
 232   * @since 3.0.0
 233   *
 234   * @param array $templates The User's front template hierarchy.
 235   *
 236   * @return array Only the global front templates.
 237   */
 238  function bp_nouveau_member_restrict_user_front_templates( $templates = array() ) {
 239      return array_intersect( array(
 240          'members/single/front.php',
 241          'members/single/default-front.php',
 242      ), $templates );
 243  }
 244  
 245  /**
 246   * Locate a single member template into a specific hierarchy.
 247   *
 248   * @since 3.0.0
 249   *
 250   * @param string $template The template part to get (eg: activity, groups...).
 251   *
 252   * @return string The located template.
 253   */
 254  function bp_nouveau_member_locate_template_part( $template = '' ) {
 255      $displayed_user = bp_get_displayed_user();
 256      $bp_nouveau     = bp_nouveau();
 257  
 258      if ( ! $template || empty( $displayed_user->id ) ) {
 259          return '';
 260      }
 261  
 262      // Use a global to avoid requesting the hierarchy for each template
 263      if ( ! isset( $bp_nouveau->members->displayed_user_hierarchy ) ) {
 264          $bp_nouveau->members->displayed_user_hierarchy = array(
 265              'members/single/%s-id-' . sanitize_file_name( $displayed_user->id ) . '.php',
 266              'members/single/%s-nicename-' . sanitize_file_name( $displayed_user->userdata->user_nicename ) . '.php',
 267          );
 268  
 269          /*
 270           * Check for member types and add it to the hierarchy
 271           *
 272           * Make sure to register your member
 273           * type using the hook 'bp_register_member_types'
 274           */
 275          if ( bp_get_member_types() ) {
 276              $displayed_user_member_type = bp_get_member_type( $displayed_user->id );
 277              if ( ! $displayed_user_member_type ) {
 278                  $displayed_user_member_type = 'none';
 279              }
 280  
 281              $bp_nouveau->members->displayed_user_hierarchy[] = 'members/single/%s-member-type-' . sanitize_file_name( $displayed_user_member_type ) . '.php';
 282          }
 283  
 284          // And the regular one
 285          $bp_nouveau->members->displayed_user_hierarchy[] = 'members/single/%s.php';
 286      }
 287  
 288      $templates = array();
 289  
 290      // Loop in the hierarchy to fill it for the requested template part
 291      foreach ( $bp_nouveau->members->displayed_user_hierarchy as $part ) {
 292          $templates[] = sprintf( $part, $template );
 293      }
 294  
 295      /**
 296       * Filters the found template parts for the member template part locating functionality.
 297       *
 298       * @since 3.0.0
 299       *
 300       * @param array $templates Array of found templates.
 301       */
 302      return bp_locate_template( apply_filters( 'bp_nouveau_member_locate_template_part', $templates ), false, true );
 303  }
 304  
 305  /**
 306   * Load a single member template part
 307   *
 308   * @since 3.0.0
 309   *
 310   * @param string $template The template part to get (eg: activity, groups...).
 311   *
 312   * @return string HTML output.
 313   */
 314  function bp_nouveau_member_get_template_part( $template = '' ) {
 315      $located = bp_nouveau_member_locate_template_part( $template );
 316  
 317      if ( false !== $located ) {
 318          $slug = str_replace( '.php', '', $located );
 319          $name = null;
 320  
 321          /**
 322           * Let plugins adding an action to bp_get_template_part get it from here.
 323           *
 324           * @since 3.0.0
 325           *
 326           * @param string $slug Template part slug requested.
 327           * @param string $name Template part name requested.
 328           */
 329          do_action( 'get_template_part_' . $slug, $slug, $name );
 330  
 331          load_template( $located, true );
 332      }
 333  
 334      return $located;
 335  }
 336  
 337  /**
 338   * Display the User's WordPress bio info into the default front page?
 339   *
 340   * @since 3.0.0
 341   *
 342   * @return bool True to display. False otherwise.
 343   */
 344  function bp_nouveau_members_wp_bio_info() {
 345      $user_settings = bp_nouveau_get_appearance_settings();
 346  
 347      return ! empty( $user_settings['user_front_page'] ) && ! empty( $user_settings['user_front_bio'] );
 348  }
 349  
 350  /**
 351   * Are we inside the Current user's default front page sidebar?
 352   *
 353   * @since 3.0.0
 354   *
 355   * @return bool True if in the group's home sidebar. False otherwise.
 356   */
 357  function bp_nouveau_member_is_home_widgets() {
 358      return ( true === bp_nouveau()->members->is_user_home_sidebar );
 359  }
 360  
 361  /**
 362   * Filter the Latest activities Widget to only keep the one of displayed user
 363   *
 364   * @since 3.0.0
 365   *
 366   * @param array $args The Activities Template arguments.
 367   *
 368   * @return array The Activities Template arguments.
 369   */
 370  function bp_nouveau_member_activity_widget_overrides( $args = array() ) {
 371      return array_merge( $args, array(
 372          'user_id' => bp_displayed_user_id(),
 373      ) );
 374  }
 375  
 376  /**
 377   * Filter the Groups widget to only keep the groups the displayed user is a member of.
 378   *
 379   * @since 3.0.0
 380   *
 381   * @param array $args The Groups Template arguments.
 382   *
 383   * @return array The Groups Template arguments.
 384   */
 385  function bp_nouveau_member_groups_widget_overrides( $args = array() ) {
 386      return array_merge( $args, array(
 387          'user_id' => bp_displayed_user_id(),
 388      ) );
 389  }
 390  
 391  /**
 392   * Filter the Members widgets to only keep members of the displayed group.
 393   *
 394   * @since 3.0.0
 395   *
 396   * @param array $args The Members Template arguments.
 397   *
 398   * @return array The Members Template arguments.
 399   */
 400  function bp_nouveau_member_members_widget_overrides( $args = array() ) {
 401      // Do nothing for the friends widget
 402      if ( ! empty( $args['user_id'] ) && (int) $args['user_id'] === (int) bp_displayed_user_id() ) {
 403          return $args;
 404      }
 405  
 406      return array_merge( $args, array(
 407          'include' => bp_displayed_user_id(),
 408      ) );
 409  }
 410  
 411  /**
 412   * Init the Member's default front page filters as we're in the sidebar
 413   *
 414   * @since 3.0.0
 415   */
 416  function bp_nouveau_members_add_home_widget_filters() {
 417      add_filter( 'bp_nouveau_activity_widget_query', 'bp_nouveau_member_activity_widget_overrides', 10, 1 );
 418      add_filter( 'bp_before_has_groups_parse_args', 'bp_nouveau_member_groups_widget_overrides', 10, 1 );
 419      add_filter( 'bp_before_has_members_parse_args', 'bp_nouveau_member_members_widget_overrides', 10, 1 );
 420  
 421      /**
 422       * Fires after Nouveau adds its members home widget filters.
 423       *
 424       * @since 3.0.0
 425       */
 426      do_action( 'bp_nouveau_members_add_home_widget_filters' );
 427  }
 428  
 429  /**
 430   * Remove the Member's default front page filters as we're no more in the sidebar
 431   *
 432   * @since 3.0.0
 433   */
 434  function bp_nouveau_members_remove_home_widget_filters() {
 435      remove_filter( 'bp_nouveau_activity_widget_query', 'bp_nouveau_member_activity_widget_overrides', 10, 1 );
 436      remove_filter( 'bp_before_has_groups_parse_args', 'bp_nouveau_member_groups_widget_overrides', 10, 1 );
 437      remove_filter( 'bp_before_has_members_parse_args', 'bp_nouveau_member_members_widget_overrides', 10, 1 );
 438  
 439      /**
 440       * Fires after Nouveau removes its members home widget filters.
 441       *
 442       * @since 3.0.0
 443       */
 444      do_action( 'bp_nouveau_members_remove_home_widget_filters' );
 445  }
 446  
 447  /**
 448   * Get the WP Profile fields for all or a specific user
 449   *
 450   * @since 3.0.0
 451   *
 452   * @param WP_User $user The user object. Optional.
 453   *
 454   * @return array The list of WP Profile fields
 455   */
 456  function bp_nouveau_get_wp_profile_fields( $user = null ) {
 457      /**
 458       * Filters the contact methods to be included in the WP Profile fields for a specific user.
 459       *
 460       * Provide a chance for plugins to avoid showing the contact methods they're adding on front end.
 461       *
 462       * @since 3.0.0
 463       *
 464       * @param array   $value Array of user contact methods.
 465       * @param WP_User $user  WordPress user to get contact methods for.
 466       */
 467      $contact_methods = (array) apply_filters( 'bp_nouveau_get_wp_profile_field', wp_get_user_contact_methods( $user ), $user );
 468  
 469      $wp_fields = array(
 470          'display_name'     => __( 'Name', 'buddypress' ),
 471          'user_description' => __( 'About Me', 'buddypress' ),
 472          'user_url'         => __( 'Website', 'buddypress' ),
 473      );
 474  
 475      return array_merge( $wp_fields, $contact_methods );
 476  }
 477  
 478  /**
 479   * Build the Member's nav for the our customizer control.
 480   *
 481   * @since 3.0.0
 482   *
 483   * @return array The Members single item primary nav ordered.
 484   */
 485  function bp_nouveau_member_customizer_nav() {
 486      add_filter( '_bp_nouveau_member_reset_front_template', 'bp_nouveau_member_restrict_user_front_templates', 10, 1 );
 487  
 488      if ( bp_displayed_user_get_front_template( buddypress()->loggedin_user ) ) {
 489          buddypress()->members->nav->add_nav(
 490              array(
 491                  'name'     => _x( 'Home', 'Member Home page', 'buddypress' ),
 492                  'slug'     => 'front',
 493                  'position' => 5,
 494              )
 495          );
 496      }
 497  
 498      remove_filter( '_bp_nouveau_member_reset_front_template', 'bp_nouveau_member_restrict_user_front_templates', 10, 1 );
 499  
 500      $nav = buddypress()->members->nav;
 501  
 502      // Eventually reset the order.
 503      bp_nouveau_set_nav_item_order( $nav, bp_nouveau_get_appearance_settings( 'user_nav_order' ) );
 504  
 505      return $nav->get_primary();
 506  }


Generated: Sat Sep 21 01:01:46 2019 Cross-referenced by PHPXref 0.7.1