[ Index ]

PHP Cross Reference of BuddyPress

title

Body

[close]

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

   1  <?php
   2  /**
   3   * BP Nouveau Friends
   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   * Friends Loader class
  14   *
  15   * @since 3.0.0
  16   */
  17  class BP_Nouveau_Friends {
  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      }
  38  
  39      /**
  40       * Include needed files
  41       *
  42       * @since 3.0.0
  43       */
  44  	protected function includes() {
  45          // Test suite requires the AJAX functions early.
  46          if ( function_exists( 'tests_add_filter' ) ) {
  47              require $this->dir . 'ajax.php';
  48  
  49          // Load AJAX code only on AJAX requests.
  50          } else {
  51              add_action( 'admin_init', function() {
  52                  if ( defined( 'DOING_AJAX' ) && true === DOING_AJAX && 0 === strpos( $_REQUEST['action'], 'friends_' ) ) {
  53                      require bp_nouveau()->friends->dir . 'ajax.php';
  54                  }
  55              } );
  56          }
  57      }
  58  
  59      /**
  60       * Register do_action() hooks
  61       *
  62       * @since 3.0.0
  63       */
  64  	protected function setup_actions() {
  65          // Remove BuddyPress action for the members loop
  66          remove_action( 'bp_directory_members_actions', 'bp_member_add_friend_button' );
  67  
  68          // Register the friends Notifications filters
  69          add_action( 'bp_nouveau_notifications_init_filters', array( $this, 'notification_filters' ) );
  70      }
  71  
  72      /**
  73       * Register add_filter() hooks
  74       *
  75       * @since 3.0.0
  76       */
  77  	protected function setup_filters() {
  78          $buttons = array(
  79              'friends_pending',
  80              'friends_is_friend',
  81              'friends_not_friends',
  82              'friends_member_friendship',
  83              'friends_accept_friendship',
  84              'friends_reject_friendship',
  85          );
  86  
  87          foreach ( $buttons as $button ) {
  88              add_filter( 'bp_button_' . $button, 'bp_nouveau_ajax_button', 10, 5 );
  89          }
  90  
  91          // The number formatting is done into the `bp_nouveau_nav_count()` template tag.
  92          remove_filter( 'friends_get_total_friend_count', 'bp_core_number_format' );
  93          remove_filter( 'bp_get_total_friend_count',      'bp_core_number_format' );
  94      }
  95  
  96      /**
  97       * Register notifications filters for the friends component.
  98       *
  99       * @since 3.0.0
 100       */
 101  	public function notification_filters() {
 102          $notifications = array(
 103              array(
 104                  'id'       => 'friendship_accepted',
 105                  'label'    => __( 'Accepted friendship requests', 'buddypress' ),
 106                  'position' => 35,
 107              ),
 108              array(
 109                  'id'       => 'friendship_request',
 110                  'label'    => __( 'Pending friendship requests', 'buddypress' ),
 111                  'position' => 45,
 112              ),
 113          );
 114  
 115          foreach ( $notifications as $notification ) {
 116              bp_nouveau_notifications_register_filter( $notification );
 117          }
 118      }
 119  }
 120  
 121  /**
 122   * Launch the Friends loader class.
 123   *
 124   * @since 3.0.0
 125   */
 126  function bp_nouveau_friends( $bp_nouveau = null ) {
 127      if ( is_null( $bp_nouveau ) ) {
 128          return;
 129      }
 130  
 131      $bp_nouveau->friends = new BP_Nouveau_Friends();
 132  }
 133  add_action( 'bp_nouveau_includes', 'bp_nouveau_friends', 10, 1 );


Generated: Sat Apr 27 01:00:55 2024 Cross-referenced by PHPXref 0.7.1