How can I change var $failed_login_limit = "2"; var $lockout_duration = "10"; value by using wp setting api?
if ( ! class_exists( 'Jeba_Limit_Login_Attempts' ) ) { class Jeba_Limit_Login_Attempts { var $failed_login_limit = "2"; //Number of authentification accepted var $lockout_duration = "10"; //Stop authentification process for 30 minutes: 60*30 = 1800 var $transient_name = 'attempted_login'; //Transient used public function __construct() { add_filter( 'authenticate', array( $this, 'check_attempted_login' ), 30, 3 ); add_action( 'wp_login_failed', array( $this, 'login_failed' ), 10, 1 ); } /** * Lock login attempts of failed login limit is reached */ public function check_attempted_login( $user, $username, $password ) { if ( get_transient( $this->transient_name ) ) { $datas = get_transient( $this->transient_name ); if ( $datas['tried'] >= $this->failed_login_limit ) { $until = get_option( '_transient_timeout_' . $this->transient_name ); $time = $this->when( $until ); //Display error message to the user when limit is reached return new WP_Error( 'too_many_tried', sprintf( __( '<strong>ERROR</strong>: You have reached authentification limit, you will be able to try again in %1$s.' ) , $time ) ); } } return $user; } /** * Add transient */ public function login_failed( $username ) { if ( get_transient( $this->transient_name ) ) { $datas = get_transient( $this->transient_name ); $datas['tried']++; if ( $datas['tried'] <= $this->failed_login_limit ) set_transient( $this->transient_name, $datas , $this->lockout_duration ); } else { $datas = array( 'tried' => 1 ); set_transient( $this->transient_name, $datas , $this->lockout_duration ); } } /** * Return difference between 2 given dates * @param int $time Date as Unix timestamp * @return string Return string */ private function when( $time ) { if ( ! $time ) return; $right_now = time(); $diff = abs( $right_now - $time ); $second = 1; $minute = $second * 60; $hour = $minute * 60; $day = $hour * 24; if ( $diff < $minute ) return floor( $diff / $second ) . ' secondes'; if ( $diff < $minute * 2 ) return "about 1 minute ago"; if ( $diff < $hour ) return floor( $diff / $minute ) . ' minutes'; if ( $diff < $hour * 2 ) return 'about 1 hour'; return floor( $diff / $hour ) . ' hours'; } } } //Enable it: new Jeba_Limit_Login_Attempts();
Check my full code
function jeba_wp_latest_jquery_d() { wp_enqueue_script('jquery'); } add_action('init', 'jeba_wp_latest_jquery_d');
if ( ! class_exists( 'Jeba_Limit_Login_Attempts' ) ) { class Jeba_Limit_Login_Attempts {
var $failed_login_limit = "2"; //Number of authentification accepted var $lockout_duration = "10"; //Stop authentification process for 30 minutes: 60*30 = 1800 var $transient_name = 'attempted_login'; //Transient used public function __construct() { add_filter( 'authenticate', array( $this, 'check_attempted_login' ), 30, 3 ); add_action( 'wp_login_failed', array( $this, 'login_failed' ), 10, 1 ); } public function check_attempted_login( $user, $username, $password ) { if ( get_transient( $this->transient_name ) ) { $datas = get_transient( $this->transient_name ); if ( $datas['tried'] >= $this->failed_login_limit ) { $until = get_option( '_transient_timeout_' . $this->transient_name ); $time = $this->when( $until ); return new WP_Error( 'too_many_tried', sprintf( __( '<strong>ERROR</strong>: You have reached authentification limit, you will be able to try again in %1$s.' ) , $time ) ); } } return $user; } public function login_failed( $username ) { if ( get_transient( $this->transient_name ) ) { $datas = get_transient( $this->transient_name ); $datas['tried']++; if ( $datas['tried'] <= $this->failed_login_limit ) set_transient( $this->transient_name, $datas , $this->lockout_duration ); } else { $datas = array( 'tried' => 1 ); set_transient( $this->transient_name, $datas , $this->lockout_duration ); } } private function when( $time ) { if ( ! $time ) return; $right_now = time(); $diff = abs( $right_now - $time ); $second = 1; $minute = $second * 60; $hour = $minute * 60; $day = $hour * 24; if ( $diff < $minute ) return floor( $diff / $second ) . ' secondes'; if ( $diff < $minute * 2 ) return "about 1 minute ago"; if ( $diff < $hour ) return floor( $diff / $minute ) . ' minutes'; if ( $diff < $hour * 2 ) return 'about 1 hour'; return floor( $diff / $hour ) . ' hours'; } }
}
new Jeba_Limit_Login_Attempts();
function jeba_options_page(){
add_options_page( 'jeba_manu_title', 'jeba menu', 'manage_options', 'jeba-option-page', 'jebal_options_page_function', plugins_url( 'myplugin/images/icon.png' ),8 );
} add_action('admin_menu','jeba_options_page');
function jeba_register_settings() { register_setting( 'bappiscroll_up_p_options', 'jeba_demo_options_default', 'jeba_validate_options' ); }
add_action( 'admin_init', 'jeba_register_settings' );
$jeba_demo_options_default = array( 'jeba_use_demo' => 5, 'jeba_use_demo_two' => 1800, );
if ( is_admin() ) :
function jebal_options_page_function(){?>
scroll up setting
<form action="options.php" method="post">
<table class="form-table"> <tbody> <tr valign="top"> <th scope="row"><label for="jeba_use_demo">scroll Distance</label></th> <td> <input type="text" class="" value="<?php echo stripslashes($settings['jeba_use_demo']); ?>" id="jeba_use_demo" name="jeba_demo_options_default[jeba_use_demo]"/><p class="description">Distance from top/bottom before showing element (px)<br/>Best position is 200px to 300px</p> </td> </tr> <tr valign="top"> <th scope="row"><label for="jeba_use_demo_two">scroll Speed</label></th> <td> <input type="text" class="" value="<?php echo stripslashes($settings['jeba_use_demo_two']); ?>" id="jeba_use_demo_two" name="jeba_demo_options_default[jeba_use_demo_two]"/><p class="description">You can add your scroll Speed<br/>Speed back to top (ms) like auto,200,300,400</p> </td> </tr> </tbody>
<?php }
// 7. Add validate options. function jeba_validate_options( $input ) { global $jeba_demo_options_default,$jeba_control_radio_mode;
$settings = get_option( 'jeba_demo_options_default', $jeba_demo_options_default ); $prev=$settings['layout_only']; if(!array_key_exists($input['layout_only'],$jeba_control_radio_mode)) $input['layout_only']=$prev;
return $input; }
endif; //3. EndIf is_admin()
function jeba_use_activator(){ global $jeba_demo_options_default;
$bappiscroll_up_settings=get_option('jeba_demo_options_default','$jeba_demo_options_default');
$failed_login_limit = $bappiscroll_up_settings['jeba_use_demo'];; //Number of authentification accepted $lockout_duration = $bappiscroll_up_settings['jeba_use_demo_two'];; //Stop authentification process for 30 minutes: 60*30 = 1800
}
add_action('wp_head','jeba_use_activator');