检查是否在”密码保护”页面上*仅*输入了正确的WordPress发布密码

我只想在用户未输入正确密码的情况下将自定义字段设置为隐藏。

如果输入了密码, 并且没有设置密码, 则post_password_required()返回false。

有没有一种方法可以检查:

  1. 该帖子首先受密码保护
  2. 输入了正确的密码。

我只希望在受密码保护的页面上发生这种情况。


#1


你只需确保$ post对象上存在post_password, 否则将返回一个空字符串:

if( $post->post_password && !post_password_required() ){
    // Post Password is actually defined in the first place, // and `post_password_required()` is returning true
}

来源:

https://www.srcmini02.com/64883.html

微信公众号
手机浏览(小程序)

Warning: get_headers(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(): Failed to enable crypto in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(https://static.shanhubei.com/qrcode/qrcode_viewid_41191.jpg): failed to open stream: operation failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57
0
分享到:
没有账号? 忘记密码?