[ 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 3.0.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  
  92      /**
  93       * Register notifications filters for the friends component.
  94       *
  95       * @since 3.0.0
  96       */
  97  	public function notification_filters() {
  98          $notifications = array(
  99              array(
 100                  'id'       => 'friendship_accepted',
 101                  'label'    => __( 'Accepted friendship requests', 'buddypress' ),
 102                  'position' => 35,
 103              ),
 104              array(
 105                  'id'       => 'friendship_request',
 106                  'label'    => __( 'Pending friendship requests', 'buddypress' ),
 107                  'position' => 45,
 108              ),
 109          );
 110  
 111          foreach ( $notifications as $notification ) {
 112              bp_nouveau_notifications_register_filter( $notification );
 113          }
 114      }
 115  }
 116  
 117  /**
 118   * Launch the Friends loader class.
 119   *
 120   * @since 3.0.0
 121   */
 122  function bp_nouveau_friends( $bp_nouveau = null ) {
 123      if ( is_null( $bp_nouveau ) ) {
 124          return;
 125      }
 126  
 127      $bp_nouveau->friends = new BP_Nouveau_Friends();
 128  }
 129  add_action( 'bp_nouveau_includes', 'bp_nouveau_friends', 10, 1 );


Generated: Mon Oct 21 01:01:35 2019 Cross-referenced by PHPXref 0.7.1