/loader.php

  1. <?php 
  2. /** 
  3. Plugin Name: BuddyPress Activity Privacy 
  4. Plugin URI:  
  5. Description: Add the ability for members to choose who can read/see his activities and media files. 
  6. Version: 1.3.8 
  7. Requires at least: WP 3.4, BuddyPress 1.5 
  8. Tested up to: BuddyPress 1.5, 2.2.1 
  9. License: GNU General Public License 2.0 (GPL) http://www.gnu.org/licenses/gpl.html 
  10. Author: Meg@Info 
  11. Author URI: http://profiles.wordpress.org/megainfo  
  12. Network: true 
  13. Text Domain: bp-activity-privacy 
  14. Domain Path: /languages 
  15. */ 
  16.  
  17. // Exit if accessed directly 
  18. if ( !defined( 'ABSPATH' ) ) exit; 
  19.  
  20. /************************************************************************************************************* 
  21. --- BuddyPress Activity Privacy 1.3.7 --- 
  22. *************************************************************************************************************/ 
  23.  
  24. // Define a constant that can be checked to see if the component is installed or not. 
  25. define( 'BP_ACTIVITY_PRIVACY_IS_INSTALLED', 1 ); 
  26.  
  27. // Define a constant that will hold the current version number of the component 
  28. // This can be useful if you need to run update scripts or do compatibility checks in the future 
  29. define( 'BP_ACTIVITY_PRIVACY_VERSION', '1.3.8' ); 
  30.  
  31. // Define a constant that we can use to construct file paths throughout the component 
  32. define( 'BP_ACTIVITY_PRIVACY_PLUGIN_DIR', dirname( __FILE__ ) ); 
  33.  
  34. //define ( 'BP_ACTIVITY_PRIVACY_DB_VERSION', '1.0' ); 
  35.  
  36. define( 'BP_ACTIVITY_PRIVACY_PLUGIN_FILE_LOADER', __FILE__ ); 
  37.  
  38. // Define a constant that we can use as plugin url 
  39. define( 'BP_ACTIVITY_PRIVACY_PLUGIN_URL', plugin_dir_url( __FILE__ ) ); 
  40.  
  41. // Define a constant that we can use as plugin basename 
  42. define( 'BP_ACTIVITY_PRIVACY_PLUGIN_BASENAME', plugin_basename( __FILE__ ) ); 
  43.  
  44. define( 'BP_ACTIVITY_PRIVACY_PLUGIN_DIR_PATH', plugin_dir_path( __FILE__ ) ); 
  45.  
  46. /** 
  47. * textdomain loader. 
  48. * 
  49. * Checks WP_LANG_DIR for the .mo file first, then the plugin's language folder. 
  50. * Allows for a custom language file other than those packaged with the plugin. 
  51. * 
  52. * @uses load_textdomain() Loads a .mo file into WP 
  53. * @uses load_plugin_textdomain() Loads a .mo file into languages folder on plugin 
  54. */  
  55. function bp_activity_privacy_load_textdomain() { 
  56. $mofile = sprintf( 'buddypress-activity-privacy-%s.mo', get_locale() ); 
  57.  
  58. $mofile_global = trailingslashit( WP_LANG_DIR ) . $mofile; 
  59. $mofile_local = BP_ACTIVITY_PRIVACY_PLUGIN_DIR_PATH . 'languages/' . $mofile; 
  60.  
  61. if ( is_readable( $mofile_global ) ) { 
  62. return load_textdomain( 'bp-activity-privacy', $mofile_global ); 
  63. } elseif ( is_readable( $mofile_local ) ) { 
  64. //return load_plugin_textdomain( 'bp-activity-privacy', false, $mofile_local ); 
  65. return load_textdomain( 'bp-activity-privacy', $mofile_local ); 
  66. else 
  67. return false; 
  68. add_action( 'plugins_loaded', 'bp_activity_privacy_load_textdomain' ); 
  69.  
  70. /** 
  71. * Check the config for multisite 
  72. */ 
  73. function bp_activity_privacy_check_config() { 
  74. global $bp; 
  75.  
  76. $config = array( 
  77. 'blog_status' => false,  
  78. 'network_active' => false,  
  79. 'network_status' => true  
  80. ); 
  81. if ( get_current_blog_id() == bp_get_root_blog_id() ) { 
  82. $config['blog_status'] = true; 
  83.  
  84. $network_plugins = get_site_option( 'active_sitewide_plugins', array() ); 
  85.  
  86. // No Network plugins 
  87. if ( empty( $network_plugins ) ) 
  88.  
  89. // Looking for BuddyPress and bp-activity plugin 
  90. $check[] = $bp->basename; 
  91. $check[] = BP_ACTIVITY_PRIVACY_PLUGIN_BASENAME; 
  92.  
  93. // Are they active on the network ? 
  94. $network_active = array_diff( $check, array_keys( $network_plugins ) ); 
  95.  
  96. // If result is 1, your plugin is network activated 
  97. // and not BuddyPress or vice & versa. Config is not ok 
  98. if ( count( $network_active ) == 1 ) 
  99. $config['network_status'] = false; 
  100.  
  101. // We need to know if the plugin is network activated to choose the right 
  102. // notice ( admin or network_admin ) to display the warning message. 
  103. $config['network_active'] = isset( $network_plugins[ BP_ACTIVITY_PRIVACY_PLUGIN_BASENAME ] ); 
  104.  
  105. // if BuddyPress config is different than bp-activity plugin 
  106. if ( !$config['blog_status'] || !$config['network_status'] ) { 
  107.  
  108. $warnings = array(); 
  109. if ( !bp_core_do_network_admin() && !$config['blog_status'] ) { 
  110. $warnings[] = __( 'Buddypress Activity Privacy requires to be activated on the blog where BuddyPress is activated.', 'bp-activity-privacy' ); 
  111.  
  112. if ( bp_core_do_network_admin() && !$config['network_status'] ) { 
  113. $warnings[] = __( 'Buddypress Activity Privacy and BuddyPress need to share the same network configuration.', 'bp-activity-privacy' ); 
  114.  
  115. if ( ! empty( $warnings ) ) : 
  116. ?> 
  117. <div id="message" class="error"> 
  118. <?php foreach ( $warnings as $warning ) : ?> 
  119. <p><?php echo esc_html( $warning ) ; ?></p> 
  120. <?php endforeach ; ?> 
  121. </div> 
  122. <?php 
  123. endif; 
  124.  
  125. // Display a warning message in network admin or admin 
  126. add_action( $config['network_active'] ? 'network_admin_notices' : 'admin_notices', $warning ); 
  127.  
  128. return false; 
  129. }  
  130. return true; 
  131.  
  132.  
  133. /** Only load the component if BuddyPress is loaded and initialized. */ 
  134. function bp_activity_privacy_init() { 
  135. // Because our loader file uses BP_Component, it requires BP 1.5 or greater. 
  136. //if ( version_compare( BP_VERSION, '1.3', '>' ) ) 
  137. if ( bp_activity_privacy_check_config() ) 
  138. require( dirname( __FILE__ ) . '/includes/bp-activity-privacy-loader.php' ); 
  139. add_action( 'bp_include', 'bp_activity_privacy_init' ); 
  140.  
  141. /** Put setup procedures to be run when the plugin is activated in the following function */ 
  142. function bp_activity_privacy_activate() { 
  143. // check if buddypress is active 
  144. if ( ! defined( 'BP_VERSION' ) ) { 
  145. die( _e( 'You cannot enable BuddyPress Activity Privacy because <strong>BuddyPress</strong> is not active. Please install and activate BuddyPress before trying to activate Buddypress Activity Privacy again.' , 'bp-activity-privacy' ) ); 
  146.  
  147. // Add the transient to redirect 
  148. set_transient( '_bp_activity_privacy_activation_redirect', true, 30 ); 
  149.  
  150. do_action( 'bp_activity_privacy_activation' ); 
  151.  
  152. register_activation_hook( __FILE__, 'bp_activity_privacy_activate' ); 
  153.  
  154. /** On deacativation, clean up anything your component has added. */ 
  155. function bp_activity_privacy_deactivate() { 
  156. /** You might want to delete any options or tables that your component created. */ 
  157. do_action( 'bp_activity_privacy_deactivation' );  
  158. register_deactivation_hook( __FILE__, 'bp_activity_privacy_deactivate' ); 
.