[ 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 3.0.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       */
  97  	protected function setup_filters() {
  98          add_filter( 'bp_nouveau_register_scripts', 'bp_nouveau_groups_register_scripts', 10, 1 );
  99          add_filter( 'bp_core_get_js_strings', 'bp_nouveau_groups_localize_scripts', 10, 1 );
 100          add_filter( 'groups_create_group_steps', 'bp_nouveau_group_invites_create_steps', 10, 1 );
 101  
 102          $buttons = array(
 103              'groups_leave_group',
 104              'groups_join_group',
 105              'groups_accept_invite',
 106              'groups_reject_invite',
 107              'groups_membership_requested',
 108              'groups_request_membership',
 109              'groups_group_membership',
 110          );
 111  
 112          foreach ( $buttons as $button ) {
 113              add_filter( 'bp_button_' . $button, 'bp_nouveau_ajax_button', 10, 5 );
 114          }
 115  
 116          // Add sections in the BP Template Pack panel of the customizer.
 117          add_filter( 'bp_nouveau_customizer_sections', 'bp_nouveau_groups_customizer_sections', 10, 1 );
 118  
 119          // Add settings into the Groups sections of the customizer.
 120          add_filter( 'bp_nouveau_customizer_settings', 'bp_nouveau_groups_customizer_settings', 10, 1 );
 121  
 122          // Add controls into the Groups sections of the customizer.
 123          add_filter( 'bp_nouveau_customizer_controls', 'bp_nouveau_groups_customizer_controls', 10, 1 );
 124  
 125          // Add the group's default front template to hieararchy if user enabled it (Enabled by default).
 126          add_filter( 'bp_groups_get_front_template', 'bp_nouveau_group_reset_front_template', 10, 2 );
 127  
 128          // Add a new nav item to settings to let users choose their group invites preferences
 129          if ( bp_is_active( 'friends' ) && ! bp_nouveau_groups_disallow_all_members_invites() ) {
 130              add_filter( 'bp_settings_admin_nav', 'bp_nouveau_groups_invites_restriction_admin_nav', 10, 1 );
 131          }
 132      }
 133  
 134      /**
 135       * Add filters to be sure the (BuddyPress) widgets display will be consistent
 136       * with the current group's default front page.
 137       *
 138       * @since 3.0.0
 139       *
 140       * @param string $sidebar_index The Sidebar identifier.
 141       */
 142  	public function group_home_sidebar_set( $sidebar_index = '' ) {
 143          if ( 'sidebar-buddypress-groups' !== $sidebar_index ) {
 144              return;
 145          }
 146  
 147          $this->is_group_home_sidebar = true;
 148  
 149          // Add needed filters.
 150          bp_nouveau_groups_add_home_widget_filters();
 151      }
 152  
 153      /**
 154       * Remove filters to be sure the (BuddyPress) widgets display will no more take
 155       * the current group displayed in account.
 156       *
 157       * @since 3.0.0
 158       *
 159       * @param string $sidebar_index The Sidebar identifier.
 160       */
 161  	public function group_home_sidebar_unset( $sidebar_index = '' ) {
 162          if ( 'sidebar-buddypress-groups' !== $sidebar_index ) {
 163              return;
 164          }
 165  
 166          $this->is_group_home_sidebar = false;
 167  
 168          // Remove no more needed filters.
 169          bp_nouveau_groups_remove_home_widget_filters();
 170      }
 171  }
 172  
 173  /**
 174   * Launch the Groups loader class.
 175   *
 176   * @since 3.0.0
 177   */
 178  function bp_nouveau_groups( $bp_nouveau = null ) {
 179      if ( is_null( $bp_nouveau ) ) {
 180          return;
 181      }
 182  
 183      $bp_nouveau->groups = new BP_Nouveau_Groups();
 184  }
 185  add_action( 'bp_nouveau_includes', 'bp_nouveau_groups', 10, 1 );


Generated: Sun Sep 22 01:01:44 2019 Cross-referenced by PHPXref 0.7.1