[ Index ]

PHP Cross Reference of BuddyPress

title

Body

[close]

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

   1  <?php
   2  /**
   3   * BP Nouveau Members
   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   * Members Loader class
  14   *
  15   * @since 3.0.0
  16   */
  17  class BP_Nouveau_Members {
  18      /**
  19       * Constructor
  20       *
  21       * @since 3.0.0
  22       */
  23  	public function __construct() {
  24          $this->setup_globals();
  25          $this->includes();
  26          $this->setup_actions();
  27          $this->setup_filters();
  28      }
  29  
  30      /**
  31       * Globals
  32       *
  33       * @since 3.0.0
  34       */
  35  	protected function setup_globals() {
  36          $this->dir                  = dirname( __FILE__ );
  37          $this->is_user_home_sidebar = false;
  38      }
  39  
  40      /**
  41       * Include needed files
  42       *
  43       * @since 3.0.0
  44       */
  45  	protected function includes() {
  46          require( trailingslashit( $this->dir ) . 'functions.php' );
  47          require( trailingslashit( $this->dir ) . 'template-tags.php' );
  48      }
  49  
  50      /**
  51       * Register do_action() hooks
  52       *
  53       * @since 3.0.0
  54       */
  55  	protected function setup_actions() {
  56          $ajax_actions = array(
  57              array(
  58                  'members_filter' => array(
  59                      'function' => 'bp_nouveau_ajax_object_template_loader',
  60                      'nopriv'   => true,
  61                  ),
  62              ),
  63          );
  64  
  65          foreach ( $ajax_actions as $ajax_action ) {
  66              $action = key( $ajax_action );
  67  
  68              add_action( 'wp_ajax_' . $action, $ajax_action[ $action ]['function'] );
  69  
  70              if ( ! empty( $ajax_action[ $action ]['nopriv'] ) ) {
  71                  add_action( 'wp_ajax_nopriv_' . $action, $ajax_action[ $action ]['function'] );
  72              }
  73          }
  74  
  75          add_action( 'bp_nouveau_enqueue_scripts', 'bp_nouveau_members_enqueue_scripts' );
  76  
  77          // Actions to check whether we are in the member's default front page sidebar
  78          add_action( 'dynamic_sidebar_before', array( $this, 'user_home_sidebar_set' ), 10, 1 );
  79          add_action( 'dynamic_sidebar_after', array( $this, 'user_home_sidebar_unset' ), 10, 1 );
  80      }
  81  
  82      /**
  83       * Register add_filter() hooks
  84       *
  85       * @since 3.0.0
  86       * @since 6.0.0 Removes the BP Core number formatting filter on total members count.
  87       */
  88  	protected function setup_filters() {
  89          // Add the default-front to User's front hierarchy if user enabled it (Enabled by default).
  90          add_filter( 'bp_displayed_user_get_front_template', 'bp_nouveau_member_reset_front_template', 10, 1 );
  91  
  92          // The number formatting is done into the `bp_nouveau_nav_count()` template tag.
  93          remove_filter( 'bp_get_total_member_count', 'bp_core_number_format' );
  94      }
  95  
  96      /**
  97       * Add filters to be sure the (BuddyPress) widgets display will be consistent
  98       * with the displayed user's default front page.
  99       *
 100       * @since 3.0.0
 101       *
 102       * @param string $sidebar_index The Sidebar identifier.
 103       */
 104  	public function user_home_sidebar_set( $sidebar_index = '' ) {
 105          if ( 'sidebar-buddypress-members' !== $sidebar_index ) {
 106              return;
 107          }
 108  
 109          $this->is_user_home_sidebar = true;
 110  
 111          // Add needed filters.
 112          bp_nouveau_members_add_home_widget_filters();
 113      }
 114  
 115      /**
 116       * Remove filters to be sure the (BuddyPress) widgets display will no more take
 117       * the displayed user in account.
 118       *
 119       * @since 3.0.0
 120       *
 121       * @param  string $sidebar_index The Sidebar identifier.
 122       */
 123  	public function user_home_sidebar_unset( $sidebar_index = '' ) {
 124          if ( 'sidebar-buddypress-members' !== $sidebar_index ) {
 125              return;
 126          }
 127  
 128          $this->is_user_home_sidebar = false;
 129  
 130          // Remove no more needed filters.
 131          bp_nouveau_members_remove_home_widget_filters();
 132      }
 133  }
 134  
 135  /**
 136   * Launch the Members loader class.
 137   *
 138   * @since 3.0.0
 139   */
 140  function bp_nouveau_members( $bp_nouveau = null ) {
 141      if ( is_null( $bp_nouveau ) ) {
 142          return;
 143      }
 144  
 145      $bp_nouveau->members = new BP_Nouveau_Members();
 146  }
 147  add_action( 'bp_nouveau_includes', 'bp_nouveau_members', 5, 1 );


Generated: Sat Jul 4 01:01:33 2020 Cross-referenced by PHPXref 0.7.1