/bp-disable-activation-loader.php

  1. <?php 
  2. /** 
  3. Plugin Name: BP Disable Activation Reloaded 
  4. Plugin URI: http://www.timersys.com/plugins-wordpress/bp-disable-activation-reloaded 
  5. Description: Disable the activation email and authentificate the user. Also redirect to a page if selected . Based on BP Disable Activation from John Lynn 
  6. Version: 1.2.1 
  7. Author: timersys 
  8. Author URI: http://www.timersys.com 
  9. Requires at least: BuddyPress 1.7 
  10. Tested up to: BuddyPress 2.0.2+wp 3.9.2 
  11. License: MIT License 
  12. Text Domain: dar 
  13. Domain Path: languages 
  14. */ 
  15.  
  16. /** 
  17.   
  18. ********** 
  19. * License 
  20. **************************************************************************** 
  21. * Copyright (C) 2011-2013 Damian Logghe and contributors 
  22. * 
  23. * Permission is hereby granted, free of charge, to any person obtaining 
  24. * a copy of this software and associated documentation files (the 
  25. * "Software"), to deal in the Software without restriction, including 
  26. * without limitation the rights to use, copy, modify, merge, publish,  
  27. * distribute, sublicense, and/or sell copies of the Software, and to 
  28. * permit persons to whom the Software is furnished to do so, subject to 
  29. * the following conditions: 
  30. * 
  31. * The above copyright notice and this permission notice shall be 
  32. * included in all copies or substantial portions of the Software. 
  33. * 
  34. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,  
  35. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 
  36. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 
  37. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 
  38. * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 
  39. * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 
  40. * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 
  41. ****************************************************************************/ 
  42. /*** 
  43. Copyright (C) 2009 John Lynn(crashutah.com) 
  44.   
  45. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or any later version. 
  46.   
  47. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. 
  48.   
  49. You should have received a copy of the GNU General Public License along with this program; if not, see <http://www.gnu.org/licenses>. 
  50.   
  51. */ 
  52.  
  53. /*** 
  54. Credit goes to AndyPeatling for most of the initial code 
  55. */ 
  56.  
  57. /*** 
  58. Word of Caution: Use this Plugin at your own risk. The email activation can be one way to keep spammers from registering on your site. Make sure you're looking at other options to prevent spammers if you use this plugin to remove the email activation. 
  59.   
  60. */ 
  61.  
  62.  
  63. // Exit if accessed directly 
  64. if ( !defined( 'ABSPATH' ) ) exit; 
  65.  
  66. require(dirname (__FILE__).'/WP_Plugin_Base.class.php'); 
  67.  
  68. class BP_Disable_Activation_Reloaded extends WP_Plugin_Base 
  69.  
  70.  
  71. protected $_options; 
  72. var $_credits; 
  73. var $_defaults; 
  74. protected $sections; 
  75.  
  76. private static $instance = null; 
  77.  
  78. /**--------------------------------------------* 
  79. * Constructor 
  80. *--------------------------------------------*/ 
  81.  
  82. /** 
  83. * Creates or returns an instance of this class. 
  84. * 
  85. * @return Foo A single instance of this class. 
  86. */ 
  87. public static function get_instance() { 
  88.  
  89. if ( null == self::$instance ) { 
  90. self::$instance = new self; 
  91.  
  92. return self::$instance; 
  93.  
  94. } // end get_instance; 
  95.  
  96. function __construct() { 
  97.  
  98. $this->WPB_PREFIX = 'dar'; 
  99. $this->WPB_SLUG = 'bp-disable-activation-reloaded'; // Need to match plugin folder name 
  100. $this->WPB_PLUGIN_NAME = 'BP Disable Activation Reloaded'; 
  101. $this->WPB_VERSION = '1.2.1'; 
  102. $this->PLUGIN_FILE = plugin_basename(__FILE__); 
  103. $this->options_name = 'dar_settings'; 
  104.  
  105. $this->sections['general'] = __( 'Main Settings', $this->WPB_PREFIX ); 
  106.  
  107. //activation hook 
  108. register_activation_hook( __FILE__, array(&$this, 'activate' ));  
  109.  
  110. //deactivation hook 
  111. register_deactivation_hook( __FILE__, array(&$this, 'deactivate' ));  
  112.  
  113. //admin menu 
  114. add_action( 'admin_menu', array(&$this, 'register_menu' ) ); 
  115.  
  116. //load js and css  
  117. add_action( 'init', array(&$this, 'load_scripts' ), 50 );  
  118.  
  119. add_action( 'bp_init', array(&$this, 'my_plugin_init' )); 
  120.  
  121. $this->loadOptions(); 
  122. #$this->upgradePlugin(); 
  123.  
  124. #$this->setDefaults(); 
  125.  
  126.  
  127. parent::__construct(); 
  128.  
  129.  
  130.  
  131. }  
  132.  
  133. /** 
  134. * Load the plugin once BuddyPress is loaded 
  135. */ 
  136. function my_plugin_init() { 
  137.  
  138.  
  139. /**The Functions to automatically activate for Single WP Installs*/ 
  140. if ( !is_multisite() ) { 
  141. add_action( 'bp_core_signup_user' , array(&$this, 'disable_validation' )); 
  142. add_filter( 'bp_registration_needs_activation' , array(&$this, 'fix_signup_form_validation_text' )); 
  143. add_filter( 'bp_core_signup_send_activation_key', array(&$this, 'disable_activation_email' )); 
  144. else 
  145. //Remove filters which notifies users 
  146. remove_filter( 'wpmu_signup_user_notification' , 'bp_core_activation_signup_user_notification', 1, 4 ); 
  147.  
  148. add_filter( 'wpmu_signup_user_notification' , array(&$this, 'cc_auto_activate_on_user_signup'), 1, 4 ); 
  149. # add_action( 'signup_finished' , array(&$this, "cc_auto_activate_finished"); 
  150. }  
  151. if( isset($_GET['page']) && 'bp-disable-activation-reloaded' == $_GET['page'] && !empty( $_GET['fix_pending_users'] ) ) { 
  152. global $wpdb; 
  153.  
  154. $users = $wpdb->get_results( "SELECT activation_key, user_login FROM {$wpdb->prefix}signups WHERE active = '0' "); 
  155.  
  156. foreach ($users as $user) { 
  157. bp_core_activate_signup($user->activation_key); 
  158. BP_Signup::validate($user->activation_key); 
  159.  
  160. //fix roles 
  161. $user_id = $wpdb->get_var( "SELECT ID FROM $wpdb->users WHERE user_login = '$user->user_login'"); 
  162.  
  163. $u = new WP_User( $user_id ); 
  164. $u->add_role( 'subscriber' ); 
  165.  
  166. }  
  167. function disable_validation( $user_id ) { 
  168. global $wpdb; 
  169.  
  170. $options = $this->_options; 
  171.  
  172. //Hook if you want to do something before the activation 
  173. do_action('bp_disable_activation_before_activation'); 
  174.  
  175. $activation_key = get_user_meta($user_id, 'activation_key', true); 
  176. $activate = apply_filters('bp_core_activate_account', bp_core_activate_signup($activation_key)); 
  177. BP_Signup::validate($activation_key); 
  178. $wpdb->query( $wpdb->prepare( "UPDATE $wpdb->users SET user_status = 0 WHERE ID = %d", $user_id ) ); 
  179.  
  180. //Add note on Activity Stream 
  181. if ( function_exists( 'bp_activity_add' ) ) { 
  182. $userlink = bp_core_get_userlink( $user_id ); 
  183.  
  184. bp_activity_add( array( 
  185. 'user_id' => $user_id,  
  186. 'action' => apply_filters( 'bp_core_activity_registered_member', sprintf( __( '%s became a registered member', 'buddypress' ), $userlink ), $user_id ),  
  187. 'component' => 'profile',  
  188. 'type' => 'new_member' 
  189. ) ); 
  190.  
  191. //Send email to admin 
  192. wp_new_user_notification( $user_id ); 
  193. // Remove the activation key meta 
  194. delete_user_meta( $user_id, 'activation_key' ); 
  195. // Delete the total member cache 
  196. wp_cache_delete( 'bp_total_member_count', 'bp' ); 
  197.  
  198. //Hook if you want to do something before the login 
  199. do_action('bp_disable_activation_before_login'); 
  200.  
  201.  
  202. if( $options['enable_login'] == 'true' ) 
  203. //Automatically log the user in . 
  204. //Thanks to Justin Klein's wp-fb-autoconnect plugin for the basic code to login automatically 
  205. $user_info = get_userdata($user_id); 
  206. wp_set_auth_cookie($user_id); 
  207.  
  208. do_action('wp_signon', $user_info->user_login); 
  209.  
  210. //Hook if you want to do something after the login 
  211. do_action('bp_disable_activation_after_login'); 
  212.  
  213. $redirection = apply_filters('dar_redirection_url', $options['redirection']); 
  214.  
  215. if( $redirection != '' ) 
  216. wp_safe_redirect($redirection); 
  217. die(); 
  218.  
  219.  
  220.  
  221. function fix_signup_form_validation_text() { 
  222. return false; 
  223.  
  224.  
  225. function disable_activation_email() { 
  226. return false; 
  227.  
  228.  
  229.  
  230. /**START Functions to automatically activate for WPMU (multi-site) Installs (Activates User and Blogs)*/ 
  231.  
  232. /** 
  233. Credit for most of the WPMU code goes to Brajesh Singh and his plugin "BP Auto activate User and Blog at Signup" 
  234. */ 
  235.  
  236.  
  237. function cc_auto_activate_on_user_signup($user, $user_email, $key, $meta) { 
  238. //only multisite part will be executed 
  239. $user_id = bp_core_activate_signup($key); 
  240.  
  241. $options = $this->_options; 
  242.  
  243. if( $options['enable_login'] == 'true' ) 
  244. //Automatically log the user in . 
  245. //Thanks to Justin Klein's wp-fb-autoconnect plugin for the basic code to login automatically 
  246. $user_info = get_userdata($user_id); 
  247. wp_set_auth_cookie($user_id); 
  248.  
  249. do_action('wp_signon', $user_info->user_login); 
  250.  
  251. //Hook if you want to do something after the login 
  252. do_action('bp_disable_activation_after_login'); 
  253.  
  254. $redirection = apply_filters('dar_redirection_url', $options['redirection']); 
  255.  
  256. if( $redirection != '' ) 
  257. wp_safe_redirect($redirection); 
  258. die(); 
  259.  
  260.  
  261. /** 
  262. * Check technical requirements before activating the plugin.  
  263. * WordPress 3.0 or newer required 
  264. */ 
  265. function activate() 
  266. parent::activate(); 
  267.  
  268.  
  269. do_action( $this->WPB_PREFIX.'_activate' ); 
  270.  
  271.  
  272. }  
  273.  
  274. /** 
  275. * Run when plugin is deactivated 
  276. * WordPress 3.0 or newer required 
  277. */ 
  278. function deactivate() 
  279.  
  280.  
  281. do_action( $this->WPB_PREFIX.'_deactivate' ); 
  282.  
  283.  
  284.  
  285. /** 
  286. * function that register the menu link in the settings menu and editor section inside the option page 
  287. */ 
  288. function register_menu() 
  289. #add_options_page( 'WP Plugin Base', 'WP Plugin Base', 'manage_options', WPB_SLUG , array(&$this, 'options_page') ); 
  290. add_menu_page( 'BP DAR', 'BP DAR', 'manage_options', $this->WPB_SLUG , array(&$this, 'display_page') ); 
  291.  
  292.  
  293.  
  294. /** 
  295. * Load scripts and styles 
  296. */ 
  297. function load_scripts() 
  298. if(!is_admin()) 
  299.  
  300. #wp_enqueue_script('wsi-js', plugins_url( 'assets/js/wsi.js', __FILE__ ), array('jquery'), $this->WPB_VERSION, true); 
  301. #wp_enqueue_style('wsi-css', plugins_url( 'assets/css/style.css', __FILE__ ) , '', $this->WPB_VERSION, 'all' ); 
  302. #wp_localize_script( 'jquery', 'WsiMyAjax', array( 'url' => site_url( 'wp-login.php' ), 'admin_url' => admin_url( 'admin-ajax.php' ), 'nonce' => wp_create_nonce( 'wsi-ajax-nonce' ) ) ); 
  303. #wp_enqueue('codemirror'); 
  304.  
  305.  
  306.  
  307.  
  308.  
  309.  
  310. /** 
  311. * Load options to use later 
  312. */  
  313. function loadOptions() 
  314.  
  315. $this->_options = get_option($this->WPB_PREFIX.'_settings', $this->_defaults); 
  316.  
  317.  
  318.  
  319. /** 
  320. * loads plugins defaults 
  321. */ 
  322. function setDefaults() 
  323. $this->_defaults = array( 'version' => $this->WPB_VERSION );  
  324.  
  325.  
  326.  
  327.  
  328. BP_Disable_Activation_Reloaded::get_instance(); 
  329.  
  330.  
  331.  
  332.  
  333. ?> 
.