【问题标题】:WordPress quick access link for protected page受保护页面的 WordPress 快速访问链接
【发布时间】:2021-04-03 17:30:31
【问题描述】:

我正在尝试为受保护页面创建快速访问链接。例如,如果此人前往http://example.com/post/?password=PASSWORD,他们将直接进入,无需输入密码。

到目前为止,我已经为“the_content”添加了过滤器,用于检查帖子是否受保护,并将来自 url 的值与帖子密码进行比较。

这部分工作正常,但之后我如何返回内容?有什么方法可以模拟密码表单提交,或者以某种方式获取内容?

function render_content_or_not_to_render( $content ) {
    global $post;
    if ( post_password_required() ) {
        if ( $_GET['password'] == $post->post_password ) {
            return $content; // this way it just returns the password form
        } else {
            return get_the_password_form();
        }
    }
}
add_filter( 'the_content', 'render_content_or_not_to_render' );

【问题讨论】:

  • 这暴露了主要的安全漏洞,尤其是当密码作为 URL 的一部分缓存在所有搜索引擎上时。您仍然必须能够在 URL 中传递用户的用户名和密码,并将其解析为对 Wordpress 的请求以允许访问。

标签: wordpress password-protection


【解决方案1】:

为“post_password_required”添加的过滤器可以完成工作。不确定安全性,请将此视为菜鸟解决方案。

function modof_post_password_required( $post = null ){
    global $post;
    if ( $_GET['password'] == $post->post_password ) {
        return false;
    } else {
        return true;
    }   
}
add_filter( 'post_password_required', 'modof_post_password_required', 0 );

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-06-10
    • 2021-11-04
    • 2012-11-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多