简体   繁体   English

仅当文件属于WordPress中已发布的帖子/页面时才允许访问文件

[英]Allow file access only if they belong to a published post/page in WordPress

I need to know if there is a plugin that limits access to uploaded files based on the status of the post/page they are related to. 我需要知道是否有一个插件可以根据与之相关的帖子/页面的状态来限制对上载文件的访问。

In other words, when I upload an image into a post but the post is not published, I need WordPress to not allow access to that image until I'm switching the post to Published. 换句话说,当我将图像上传到帖子中但帖子未发布时,我需要WordPress在将帖子切换为发布之前不允许访问该图像。

I can code this myself so please let me know if there is a plugin already so I can save time. 我可以自己编写代码,所以请告诉我是否已经有插件,这样可以节省时间。

well, I do not know of any specific plugin that will do that , but what you will need to do is actually change the .htaccess direct access file permissions in order to achieve URL restrictions. 好吧,我不知道会使用哪种特定的插件,但是您实际上需要更改.htaccess直接访问文件权限以实现URL限制。

There is a very nice article written by Stephan Harris that treats this issue in wordpress with several methods . 史蒂芬•哈里斯(Stephan Harris)写的一篇非常不错的文章用几种方法在wordpress中处理这个问题。

http://www.stephenharris.info/2012/restricting-direct-access-to-files-in-wordpress/ http://www.stephenharris.info/2012/restricting-direct-access-to-files-in-wordpress/

In his article, Stephan Harris mentioned those method to prevent direct access . 史蒂芬·哈里斯(Stephan Harris)在他的文章中提到了防止直接访问的方法。 I still find it difficult to imagine a case where this will be needed on a published / not published basis . 我仍然很难想象在公开/未公开的基础上需要这样做的情况。

But still - you can easily check for post-status (with get_post_status() )and apply it in his script / methods to achieve what you want . 但是仍然-您可以轻松地检查后状态(使用get_post_status() )并将其应用到他的脚本/方法中,以实现所需的功能。 look in particular at the method where he redirects ALL the (IMAGE) request to go through the index.php - there you can easily insert a permission check. 特别查看他重定向所有(IMAGE)请求以通过index.php的方法-在这里您可以轻松地插入权限检查。

A second method that you can apply is to CHANGE the upload folder , thus making it more difficult for people to "guess" , as you said, the URL. 您可以使用的第二种方法是更改​​上载文件夹,从而使人们更难以“猜测” URL(如您所说)。 That can be done on a post-by-post basis (every post different folder) or by a random string . 可以逐个地(每个不同的文件夹)或随机字符串来完成。

you can do that by a variety of ways, one of which is described here : 您可以通过多种方式来执行此操作,此处描述了其中一种:

http://codex.wordpress.org/Function_Reference/wp_upload_dir http://codex.wordpress.org/Function_Reference/wp_upload_dir

or simply use a plugins like THIS ONE that will give a folder name based on a post title . 或者简单使用像THIS ONE这样的插件,该插件将根据帖子的标题给出文件夹名称。 which is unknown to the non-authorized user until it is published.) 在未经授权的用户发布之前是未知的。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 更新Wordpress中已发布的帖子/页面 - Updating published post/page in wordpress 如何仅通过Wordpress中的表单允许页面访问 - How to allow page access ONLY by form in Wordpress 仅允许登录的WordPress Admin访问页面(WordPress核心外部) - Only allow logged in WordPress Admin to access page (outside of WordPress core) Wordpress 钩子用于新发布的帖子,可以访问帖子元数据 - Wordpress hook for newly published post that can access to post metadata WordPress Ajax发布到同一页面-仅具有管理面板访问权限 - Wordpress ajax post to same page - with only admin panel access 在WordPress网站中,只有任意三个帖子可以访问,然后重定向到注册页面 - in WordPress site only any three post are access then redirect to register page 只允许用户从 Wordpress 访问外部页面(将 rest 重定向到 wordpress 网站) - HTACCESS - Only allow users to access an external page from Wordpress (redirect the rest to the wordpress website) - HTACCESS WordPress:仅当今天发布帖子时才显示特定的Div - Wordpress: Display Particular Div Only If Post Was Published Today 只允许访客在 wordpress 上看到 1 个帖子 - Allow visitor see only 1 post on wordpress 仅允许Wordpress访问视频文件 - Only allow Wordpress the access to Video files
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM