原文:http://www.bigtail.net/?p=364

wordpress本身已经有文章保护的功能了,无需而外的插件就能实现,关注公众号后获取验证码查看文章。

真的简单到只需要改一点点文字的地步。

打开 wp-includes/post-template.php文件

大概在1560行左右,

function get_the_password_form( $post = 0 ) {
$post = get_post( $post );
$label = 'pwbox-' . ( empty($post->ID) ? rand() : $post->ID );
$output = '<form action="' . esc_url( site_url( 'wp-login.php?action=postpass', 'login_post' ) ) . '" class="post-password-form" method="post">
<p>' . __( 'This content is password protected. To view it please enter your password below:' ) . '</p>
<p><label for="' . $label . '">' . __( 'Password:' ) . ' <input name="post_password" id="' . $label . '" type="password" size="20" /></label> <input type="submit" name="Submit" value="' . esc_attr_x( 'Enter', 'post password form' ) . '" /></p></form>
';

参照我的改改文字,自己加上点样式装饰一下即可

function get_the_password_form( $post = 0 ) {
$post = get_post( $post );
$label = 'pwbox-' . ( empty($post->ID) ? rand() : $post->ID );
$output = '<form action="' . esc_url( site_url( 'wp-login.php?action=postpass', 'login_post' ) ) . '" class="post-password-form" method="post">
<p style="color:#0072d4;background:#eff0f2;padding:5px;">' . __( '本次查询需要验证码,微信扫码关注后发送" <span style="color:red;">验证码</span> "自助获取。<img style="width:90px;height:90px;" src="./uploads/2020/02/qrcode_for_gh_aad834b6d231_258.jpg"/>' ) . '</p>
<p><label for="' . $label . '">' . __( '微信验证码:' ) . ' <input style="border:1px #00cccc  solid;" name="post_password" id="' . $label . '" type="text" size="20" /></label> <input style="background:#00cccc;color:#fff;border:2px #00cccc solid;" type="submit" name="Submit" value="' . esc_attr_x( 'Enter', 'post password form' ) . '" /></p></form>
';
Last modification:February 23rd, 2020 at 10:07 pm
如果觉得我的文章对你有用,请随意赞赏