[WordPress] 外掛分享: JVM Protected Media

首頁外掛目錄 › JVM Protected Media
全新外掛
安裝啟用
尚無評分
1267 天前
最後更新
問題解決
WordPress 4.4.1+ v1.0.6 上架:2018-02-20

內容簡介

使用鉤子保護所有媒體檔案的存取權並實施自己的自訂檔案存取規則。適用於具備 mod rewrite 的 Apache 或透過一些自訂配置的 Nginx。不支援多站點。此外掛程式更多的是一個開發工具,用來定義自己的自訂檔案存取規則。

對於 Nginx,您需要修改設定檔,因為 Nginx 無法處理 .htaccess 檔案。請添加以下程式碼:

location ~ "^/wp-content/uploads/(.*)$" {
rewrite ^/wp-content/uploads(/.*\.\w+)$ /index.php?jvm_protected_media_file=$1;
}

鉤子

若沒有自訂鉤子,所有檔案存取都會被禁用。使用鉤子處理自己的檔案存取規則是必須的。以下是一個簡單的範例,可放在您的 functions.php 中:

function my_file_access_rule($file_info) {
// 在這裡實作您自己的邏輯
$userHasAccess = true;

if($userHasAccess) {
// 如果使用者有權存取檔案,則傳送檔案輸出
JVM_Protected_Media::send_file_output($file_info['path']);
}
}

add_action( 'jvm_protected_media_file', 'my_file_access_rule');

jvm_protected_media_file 鉤子有一個帶有以下檔案資訊的參數:

Array
(
[id] => 檔案的 ID
[url] => 檔案的完整 URL
[path] => 檔案的完整路徑
[is_resized_image] => 布林值(如果請求的檔案是圖片縮略圖或圖片的調整大小版本,則為 true)
)

鉤子

可用的鉤子:

jvm_protected_media_loaded(當外掛程式加載時觸發)
jvm_protected_media_file(當有檔案被請求時觸發)

函式

要將檔案的輸出傳送到您的函式時,可以呼叫:

JVM_Protected_Media::send_file_output($fullPathToFile)

外掛標籤

開發者團隊

⬇ 下載最新版 (v1.0.6) 或搜尋安裝

① 下載 ZIP → 後台「外掛 › 安裝外掛 › 上傳外掛」
② 後台搜尋「JVM Protected Media」→ 直接安裝(推薦)

原文外掛簡介

Protect access to all your media files and implement your own custom file access rules using a hook. Works for apache with mod rewrite or nginx with some custom configuration. No Multisite support. This plugin is more or less a development tool for defining your own custom file access rules.
For nginx you will need to modify the config file as nginx does not handle .htacess files. Add the following code:
location ~ "^/wp-content/uploads/(.*)$" {
rewrite ^/wp-content/uploads(/.*\.\w+)$ /index.php?jvm_protected_media_file=$1;
}

Hooks
Without a custom hook all file access will be disabled. The user will see the 404 page for all requested files. Adding a hook is needed to handle your own file access rules. A simple example that could go into your functions.php:
function my_file_access_rule($file_info) {
// Implement your own logic here
$userHasAccess = true;

if($userHasAccess) {
// Send the file output if users has access to the file
JVM_Protected_Media::send_file_output($file_info['path']);
}
}

add_action( 'jvm_protected_media_file', 'my_file_access_rule');

The jvm_protected_media_file action has one parameter with the following file information:
Array
(
[id] => id_of_the_file
[url] => full/url/to/your/file
[path] => full/path/to/your/file
[is_resized_image] => bool (true if the requested file is a image thumbnail or resized version of an image)
)

Actions
Available actions:

jvm_protected_media_loaded (fires as soon as the plugin is loaded)
jvm_protected_media_file (fires when a file is requested)

Functions
To send the output of a file to you can call:
JVM_Protected_Media::send_file_output($fullPathToFile)

延伸相關外掛

文章
Filter
Mastodon