Load_Base_Url(); # Handle Activation and Deactivation of the plugin Register_Activation_Hook(__FILE__, Array($this, 'Plugin_Activation')); Register_Deactivation_Hook(__FILE__, Array($this, 'Plugin_Deactivation')); # Register Filter and Actions Add_Action('init', Array($this, 'Load_TextDomain')); Add_Action('edit_user_profile', Array($this, 'Print_Status_Edit_Field')); Add_Action('edit_user_profile_update', Array($this, 'Save_User_Account_Status')); Add_filter('manage_users_columns', Array($this, 'User_Table_Columns')); Add_Filter('manage_users_custom_column', Array($this, 'User_Table_Row'), 10, 3); Add_Action('load-users.php', Array($this, 'Enqueue_Backend_Scripts')); Add_Action('load-users.php', Array($this, 'Handle_Lock_Unlock_Request')); Add_Filter('authenticate', Array($this, 'User_Authenticate'), 999); Add_Filter('allow_password_reset', Array($this, 'Allow_Password_Reset'), 999, 2); Add_Filter('views_users', Array($this, 'Print_Lock_Limit_Notice')); Add_Action('time_to_reset_account_locks', Array($this, 'Reset_Account_Locks')); # Add to GLOBALs $GLOBALS[__CLASS__] = $this; } function Load_Base_Url(){ $absolute_plugin_folder = RealPath(DirName(__FILE__)); If (StrPos($absolute_plugin_folder, ABSPATH) === 0) $this->base_url = Get_Bloginfo('wpurl').'/'.SubStr($absolute_plugin_folder, Strlen(ABSPATH)); Else $this->base_url = Plugins_Url(BaseName(DirName(__FILE__))); $this->base_url = Str_Replace("\\", '/', $this->base_url); # Windows Workaround } function Load_TextDomain(){ $locale = Apply_Filters( 'plugin_locale', get_locale(), __CLASS__ ); Load_TextDomain (__CLASS__, DirName(__FILE__).'/language/' . $locale . '.mo'); } function t ($text, $context = Null){ # Translates the string $text with context $context If (Empty($context)) return Translate ($text, __CLASS__); Else return Translate_With_GetText_Context ($text, $context, __CLASS__); } function Plugin_Activation(){ If (!WP_Next_Scheduled('time_to_reset_account_locks')) WP_Schedule_Event(Time() + 24 * 3600, 'daily', 'time_to_reset_account_locks'); } function Plugin_Deactivation(){ WP_Clear_Scheduled_Hook('time_to_reset_account_locks'); } function Enqueue_Backend_Scripts(){ WP_Enqueue_Style('account-lock-backend', $this->base_url.'/css/backend.css'); } function Handle_Lock_Unlock_Request(){ If (Current_User_Can('edit_users')){ If (IsSet($_GET['lock'])){ $this->Lock_Account($_GET['lock']); WP_Redirect(Remove_Query_Arg('lock')); Exit; } If (IsSet($_GET['unlock'])){ $this->Unlock_Account($_GET['unlock']); WP_Redirect(Remove_Query_Arg('unlock')); Exit; } } } function Lock_Account($user_id){ Update_User_Meta($user_id, 'account_locked', True); Do_Action('lock_account', $user_id); } function Unlock_Account($user_id){ Delete_User_Meta($user_id, 'account_locked'); Do_Action('unlock_account', $user_id); } function Is_Account_Locked($user_id){ return Get_User_Meta($user_id, 'account_locked', True); } function Print_Status_Edit_Field($user){ $locked = $this->Is_Account_Locked($user->data->ID); ?>
Get_Lock_Limit_Notice() ?>