纯代码实现的密码访问插件

自己手撸的一个密码访问的插件,开启后,全站都需要登录才能操作,包括后台、前台等。极其精简,样子如下。主要用了cookies实现的。

图片[1]-纯代码实现的密码访问插件 - KEKC博客-KEKC博客

代码如下:

<?php
/**
 * Plugin Name:       临时插件
 * Description:       密码访问
 * Version:           1.0.0
 */

add_action( 'init', 'post_pw_sess_expire' );
    function post_pw_sess_expire() {
        if(@$_POST['password_protected_pass'] == 'qazwsx'){
            setcookie('wp-passwd', 'qazwsx', -1, '/');
        }

        
    $html = '<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="en-US">
<head>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>My WordPress</title>

<link rel=\'stylesheet\' id=\'dashicons-css\' href=\'/wp-includes/css/dashicons.min.css?ver=6.2.2\' type=\'text/css\' media=\'all\' />
<link rel=\'stylesheet\' id=\'buttons-css\' href=\'/wp-includes/css/buttons.min.css?ver=6.2.2\' type=\'text/css\' media=\'all\' />
<link rel=\'stylesheet\' id=\'forms-css\' href=\'/wp-admin/css/forms.min.css?ver=6.2.2\' type=\'text/css\' media=\'all\' />
<link rel=\'stylesheet\' id=\'l10n-css\' href=\'/wp-admin/css/l10n.min.css?ver=6.2.2\' type=\'text/css\' media=\'all\' />
<link rel=\'stylesheet\' id=\'login-css\' href=\'/wp-admin/css/login.min.css?ver=6.2.2\' type=\'text/css\' media=\'all\' />

<style media="screen">
.password-protected-text-below { display: inline-block; text-align: center; margin-top: 30px;}
.password-protected-text-above { text-align: center; margin-bottom: 10px;}
</style>

<meta name=\'robots\' content=\'max-image-preview:large, noindex, follow\' />
		<meta name="viewport" content="width=device-width" />
		
</head>
<body class="login login-password-protected login-action-password-protected-login wp-core-ui">

<div id="login">
	<form name="loginform" id="loginform" action="" method="post">
				<p>
			<label for="password_protected_pass">Password</label>
			<input type="password" name="password_protected_pass" id="password_protected_pass" class="input" value="" size="20" tabindex="20" />
		</p>
				
		<p class="submit">
			<input type="submit" name="wp-submit" id="wp-submit" class="button button-primary button-large" value="Go" tabindex="100" />
		</p>
				
	</form>

	
</div>

<script>
try{document.getElementById(\'password_protected_pass\').focus();}catch(e){}
if(typeof wpOnload==\'function\')wpOnload();
</script>


<div class="clear"></div>


</body>
</html>';
    if ( !isset($_COOKIE['wp-passwd']) ){
        echo @$html;
        exit;
    }
}
© 版权声明
THE END
喜欢就支持一下吧
点赞5 分享