BP_Live_Notification_Helper

Plugin Name: BuddyPress Live Notification Plugin URI: https://buddydev.com/plugins/buddypress-live-notification/ Version: 2.0.2 Description: Adds a Facebook Like realtime notification for user on a BuddyPress based social network Author: BuddyDev Author URI: https://buddydev.com License: GPL.

Defined (1)

The class is defined in the following location(s).

/bp-live-notification.php  
  1. class BP_Live_Notification_Helper { 
  2. /** 
  3. * @var BP_Live_Notification_Helper 
  4. */ 
  5. private static $instance; 
  6.  
  7. private $url; 
  8. private $path; 
  9.  
  10. private function __construct() { 
  11.  
  12. $this->url = plugin_dir_url( __FILE__ ); 
  13. $this->path = plugin_dir_path( __FILE__ ); 
  14.  
  15. add_action( 'bp_include', array( $this, 'load' ) ); 
  16.  
  17. add_action( 'bp_loaded', array( $this, 'load_textdomain' ) ); 
  18.  
  19. add_action( 'bp_enqueue_scripts', array( $this, 'load_css' ) ); 
  20. add_action( 'bp_enqueue_scripts', array( $this, 'load_js' ) ); 
  21.  
  22. add_action( 'wp_head', array( $this, 'add_js_global' ) ); 
  23.  
  24.  
  25. /** 
  26. * @return BP_Live_Notification_Helper 
  27. */ 
  28. public static function get_instance() { 
  29.  
  30. if ( ! isset( self::$instance ) ) { 
  31. self::$instance = new self(); 
  32.  
  33. return self::$instance; 
  34.  
  35.  
  36.  
  37. /** 
  38. * Load core files 
  39. */ 
  40. public function load() { 
  41.  
  42. if ( ! $this->is_active() ) { 
  43. return; 
  44.  
  45.  
  46. $files = array( 
  47. 'functions.php',  
  48. 'ajax.php',  
  49. ); 
  50.  
  51.  
  52. foreach ( $files as $file ) { 
  53. require_once $this->path . $file; 
  54.  
  55. /** 
  56. * Load translation file 
  57. */ 
  58. public function load_textdomain() { 
  59. load_plugin_textdomain( 'bp-live-notification', false, dirname( plugin_basename(__FILE__ ) ) .'/languages' ); 
  60.  
  61. public function get_js_settings() { 
  62.  
  63. return apply_filters( 'bpln_get_js_settings', array( 
  64. 'timeout' => 10,  
  65. //timeou in 10 seconds 
  66. 'last_notified' => bpln_get_latest_notification_id(),  
  67. //please do not change last_notified as we use it to filter the new notifications 
  68. ) ); 
  69.  
  70. /** 
  71. * Load required js 
  72. */ 
  73. public function load_js() { 
  74.  
  75. if ( ! $this->is_active() ) { 
  76. return; 
  77.  
  78. if ( ! is_user_logged_in() || is_admin() && bpln_disable_in_dashboard() ) { 
  79. return; 
  80.  
  81. wp_register_script( 'achtung_js', $this->url . 'assets/vendors/achtung/ui.achtung.min.js', array( 'jquery' ) ); 
  82.  
  83. wp_register_script( 'bpln_js', $this->url . 'assets/js/bpln.js', array( 'jquery', 'json2', 'heartbeat' ) ); 
  84.  
  85. wp_enqueue_script( 'achtung_js' ); 
  86. wp_enqueue_script( 'bpln_js' );//I am not adding achtung_js as a dependency to avoid the condition when the achtung_js will be replaced by some other library and bpln_js won't load  
  87.  
  88. /** 
  89. * Load CSS file 
  90. */ 
  91. public function load_css() { 
  92.  
  93. if ( ! $this->is_active() ) { 
  94. return; 
  95.  
  96. if ( ! is_user_logged_in() || is_admin() && bpln_disable_in_dashboard() ) { 
  97. return; 
  98.  
  99. wp_register_style( 'achtung_css', $this->url . 'assets/vendors/achtung/ui.achtung.css' ); 
  100. wp_enqueue_style( 'achtung_css' ); 
  101.  
  102.  
  103. /** 
  104. * Add global bpln object 
  105. */ 
  106. public function add_js_global() { 
  107. ?> 
  108. <script type="text/javascript"> 
  109. var bpln = <?php echo json_encode( $this->get_js_settings() );?>; 
  110. </script> 
  111.  
  112. <?php 
  113.  
  114.  
  115. public function is_active() { 
  116.  
  117. if ( bp_is_active( 'notifications' ) ) { 
  118. return true; 
  119.  
  120. return false; 
  121.  
  122.