如何更改var$failed\\u login\\u limit=“2”;var$lockout_duration=“10”;使用wp设置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();
检查我的完整代码
函数jeba\\u wp\\u latest\\u jquery\\u d(){wp\\u enqueue\\u script(\'jquery\');}add\\u action(\'init\',\'jeba\\u wp\\u latest\\u jquery\\u d\');
如果(!class\\u exists(\'Jeba\\u Limit\\u Login\\u Attempts\'){class Jeba\\u Limit\\u Login\\u 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\';
}
}
}
新建Jeba\\u Limit\\u Login\\u Attempts();
函数jeba\\u options\\u 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\\u action(\'admin\\u menu\',\'jeba\\u options\\u page\');
函数jeba\\u register\\u settings(){register\\u setting(\'bappiscroll\\u up\\u p\\u options\',\'jeba\\u demo\\u options\\u default\',\'jeba\\u validate\\u options\');}
添加\\u操作(“admin\\u init”,“jeba\\u register\\u settings”);
$jeba\\u demo\\u options\\u default=数组(\'jeba\\u use\\u demo\'=>5,\'jeba\\u use\\u demo\\u two\'=>1800,);
if ( is_admin() ) :
函数jebal\\u options\\u page\\u function(){?>
向上滚动设置
<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。添加验证选项。函数jeba\\u validate\\u options($input){全局$jeba\\u demo\\u options\\u default,$jeba\\u control\\u radio\\u 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;
返回$输入;}
endif; //3. EndIf is_admin()
函数jeba\\u use\\u activator(){global$jeba\\u demo\\u options\\u default;
$bappiscroll\\u up\\u settings=get\\u option(\'jeba\\u demo\\u options\\u default\',\'$jeba\\u demo\\u options\\u 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
}
添加\\u action(\'wp\\u head\',\'jeba\\u use\\u activator\');