[ Index ]

PHP Cross Reference of BuddyPress

title

Body

[close]

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

   1  <?php
   2  /**
   3   * BP Nouveau Groups
   4   *
   5   * @since 3.0.0
   6   * @version 6.1.0
   7   */
   8  
   9  // Exit if accessed directly.
  10  defined( 'ABSPATH' ) || exit;
  11  
  12  /**
  13   * Groups Loader class
  14   *
  15   * @since 3.0.0
  16   */
  17  class BP_Nouveau_Groups {
  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                   = trailingslashit( dirname( __FILE__ ) );
  37          $this->is_group_home_sidebar = false;
  38      }
  39  
  40      /**
  41       * Include needed files
  42       *
  43       * @since 3.0.0
  44       */
  45  	protected function includes() {
  46          require $this->dir . 'functions.php';
  47          require $this->dir . 'classes.php';
  48          require $this->dir . 'template-tags.php';
  49  
  50          // Test suite requires the AJAX functions early.
  51          if ( function_exists( 'tests_add_filter' ) ) {
  52              require $this->dir . 'ajax.php';
  53  
  54          // Load AJAX code only on AJAX requests.
  55          } else {
  56              add_action( 'admin_init', function() {
  57                  if ( defined( 'DOING_AJAX' ) && true === DOING_AJAX && 0 === strpos( $_REQUEST['action'], 'groups_' ) ) {
  58                      require bp_nouveau()->groups->dir . 'ajax.php';
  59                  }
  60              } );
  61          }
  62      }
  63  
  64      /**
  65       * Register do_action() hooks
  66       *
  67       * @since 3.0.0
  68       */
  69  	protected function setup_actions() {
  70          if ( ! is_admin() || ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) {
  71              add_action( 'groups_setup_nav', 'bp_nouveau_group_setup_nav' );
  72          }
  73  
  74          add_action( 'bp_nouveau_enqueue_scripts', 'bp_nouveau_groups_enqueue_scripts' );
  75  
  76          // Avoid Notices for BuddyPress Legacy Backcompat
  77          remove_action( 'bp_groups_directory_group_filter', 'bp_group_backcompat_create_nav_item', 1000 );
  78  
  79          // Register the Groups Notifications filters
  80          add_action( 'bp_nouveau_notifications_init_filters', 'bp_nouveau_groups_notification_filters' );
  81  
  82          // Actions to check whether we are in the Group's default front page sidebar
  83          add_action( 'dynamic_sidebar_before', array( $this, 'group_home_sidebar_set' ), 10, 1 );
  84          add_action( 'dynamic_sidebar_after', array( $this, 'group_home_sidebar_unset' ), 10, 1 );
  85  
  86          // Add a new nav item to settings to let users choose their group invites preferences
  87          if ( bp_is_active( 'friends' ) && ! bp_nouveau_groups_disallow_all_members_invites() ) {
  88              add_action( 'bp_settings_setup_nav', 'bp_nouveau_groups_invites_restriction_nav' );
  89          }
  90      }
  91  
  92      /**
  93       * Register add_filter() hooks
  94       *
  95       * @since 3.0.0
  96       * @since 6.0.0 Removes the BP Core number formatting filter on total groups count.
  97       */
  98  	protected function setup_filters() {
  99          add_filter( 'bp_nouveau_register_scripts', 'bp_nouveau_groups_register_scripts', 10, 1 );
 100          add_filter( 'bp_core_get_js_strings', 'bp_nouveau_groups_localize_scripts', 10, 1 );
 101          add_filter( 'groups_create_group_steps', 'bp_nouveau_group_invites_create_steps', 10, 1 );
 102  
 103          $buttons = array(
 104              'groups_leave_group',
 105              'groups_join_group',
 106              'groups_accept_invite',
 107              'groups_reject_invite',
 108              'groups_membership_requested',
 109              'groups_request_membership',
 110              'groups_group_membership',
 111          );
 112  
 113          foreach ( $buttons as $button ) {
 114              add_filter( 'bp_button_' . $button, 'bp_nouveau_ajax_button', 10, 5 );
 115          }
 116  
 117          // Add sections in the BP Template Pack panel of the customizer.
 118          add_filter( 'bp_nouveau_customizer_sections', 'bp_nouveau_groups_customizer_sections', 10, 1 );
 119  
 120          // Add settings into the Groups sections of the customizer.
 121          add_filter( 'bp_nouveau_customizer_settings', 'bp_nouveau_groups_customizer_settings', 10, 1 );
 122  
 123          // Add controls into the Groups sections of the customizer.
 124          add_filter( 'bp_nouveau_customizer_controls', 'bp_nouveau_groups_customizer_controls', 10, 1 );
 125  
 126          // Add the group's default front template to hieararchy if user enabled it (Enabled by default).
 127          add_filter( 'bp_groups_get_front_template', 'bp_nouveau_group_reset_front_template', 10, 2 );
 128  
 129          // Add a new nav item to settings to let users choose their group invites preferences
 130          if ( bp_is_active( 'friends' ) && ! bp_nouveau_groups_disallow_all_members_invites() ) {
 131              add_filter( 'bp_settings_admin_nav', 'bp_nouveau_groups_invites_restriction_admin_nav', 10, 1 );
 132          }
 133  
 134          // The number formatting is done into the `bp_nouveau_nav_count()` template tag.
 135          remove_filter( 'bp_get_total_group_count', 'bp_core_number_format' );
 136          remove_filter( 'bp_get_total_group_count_for_user', 'bp_core_number_format' );
 137      }
 138  
 139      /**
 140       * Add filters to be sure the (BuddyPress) widgets display will be consistent
 141       * with the current group's default front page.
 142       *
 143       * @since 3.0.0
 144       *
 145       * @param string $sidebar_index The Sidebar identifier.
 146       */
 147  	public function group_home_sidebar_set( $sidebar_index = '' ) {
 148          if ( 'sidebar-buddypress-groups' !== $sidebar_index ) {
 149              return;
 150          }
 151  
 152          $this->is_group_home_sidebar = true;
 153  
 154          // Add needed filters.
 155          bp_nouveau_groups_add_home_widget_filters();
 156      }
 157  
 158      /**
 159       * Remove filters to be sure the (BuddyPress) widgets display will no more take
 160       * the current group displayed in account.
 161       *
 162       * @since 3.0.0
 163       *
 164       * @param string $sidebar_index The Sidebar identifier.
 165       */
 166  	public function group_home_sidebar_unset( $sidebar_index = '' ) {
 167          if ( 'sidebar-buddypress-groups' !== $sidebar_index ) {
 168              return;
 169          }
 170  
 171          $this->is_group_home_sidebar = false;
 172  
 173          // Remove no more needed filters.
 174          bp_nouveau_groups_remove_home_widget_filters();
 175      }
 176  }
 177  
 178  /**
 179   * Launch the Groups loader class.
 180   *
 181   * @since 3.0.0
 182   */
 183  function bp_nouveau_groups( $bp_nouveau = null ) {
 184      if ( is_null( $bp_nouveau ) ) {
 185          return;
 186      }
 187  
 188      $bp_nouveau->groups = new BP_Nouveau_Groups();
 189  }
 190  add_action( 'bp_nouveau_includes', 'bp_nouveau_groups', 10, 1 );


Generated: Sun Nov 24 01:00:53 2024 Cross-referenced by PHPXref 0.7.1