1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
<?php
namespace SIW\Compatibility;
class Password_Protected {
public static function init() {
if ( ! class_exists( '\Password_Protected' ) ) {
return;
}
$self = new self();
add_filter( 'password_protected_before_login_form', [ $self, 'set_login_message' ] );
add_action( 'password_protected_login_head', [ $self, 'remove_shake_js'] );
add_filter( 'password_protected_is_active', [ $self, 'process_whitelisted_ips' ] );
add_filter( 'password_protected_secure_password_protected_cookie', [ $self, 'set_secure_cookie'], 10, 2 );
}
public function set_login_message() {
$site_url = 'https://www.siw.nl';
?>
<p class="message">
<b><?php esc_html_e( 'Welkom op de testsite van SIW.','siw' )?></b><br />
<?php esc_html_e( 'Voer het wachtwoord in om toegang te krijgen.', 'siw' )?><br /><br />
<?php printf( wp_kses_post( __( 'Klik <a href="%s">hier</a> om naar de echte website van SIW te gaan.', 'siw' ) ), esc_url( $site_url ) );?>
</p>
<?php
}
public function remove_shake_js() {
remove_action( 'password_protected_login_head', 'wp_shake_js', 12 );
}
public function process_whitelisted_ips( bool $is_active ) {
$ip_whitelist = siw_get_option('ip_whitelist');
if ( is_array( $ip_whitelist ) && isset( $_SERVER['REMOTE_ADDR'] ) && in_array( $_SERVER['REMOTE_ADDR'], $ip_whitelist ) ) {
$is_active = false;
}
return $is_active;
}
public function set_secure_cookie( bool $secure_cookie, bool $secure_connection ) {
return $secure_connection;
}
}