[WordPress] 外掛分享: If File Exists

WordPress 外掛 If File Exists 的封面圖片。

前言介紹

  • 這款 WordPress 外掛「If File Exists」是 2009-06-11 上架。
  • 目前有 10 個安裝啟用數。
  • 上一次更新是 2025-04-18,距離現在已有 16 天。
  • 外掛最低要求 WordPress 2.7 以上版本才可以安裝。
  • 有 1 人給過評分。
  • 還沒有人在論壇上發問,可能目前使用數不多,還沒有什麼大問題。

外掛協作開發者

coffee2code |

外掛標籤

file | exists | existence | filesystem | coffee2code |

內容簡介

這個外掛提供了 c2c_if_file_exists()、c2c_if_theme_file_exists()、c2c_if_plugin_file_exists() 函數,用來檢查檔案是否存在,並可回傳 true/false 或顯示包含檔案資訊的字串。

若未傳送格式字串,這些函數會回傳簡單的布林值(true 或 false),指示特定檔案是否存在。
否則,傳送給它的格式字串將用於構建回應字串,可以自定義顯示檔案資訊(例如檔案名稱、檔案網址或檔案路徑)。若 $echo 參數為 true,該字串將在網頁上顯示。無論 $echo 的值為何,該回應字串都會被函數返回。

預設情況下,c2c_if_file_exists() 假設您要查找相對於預設的 WordPress 上傳目錄的檔案。如果要搜索其他目錄,請將它作為 $dir 參數指定。c2c_if_theme_file_exists() 假設您要查找相對於當前啟用主題的主目錄的檔案。c2c_if_plugin_file_exists() 則假設您要查找相對於包含 WordPress 外掛的目錄的檔案。

連結: 外掛主頁 | WordPress 外掛目錄頁 | GitHub | 作者主頁

開發人員文件

開發人員文件可在 DEVELOPER-DOCS.md 中找到。該文件涵蓋了外掛提供的模板標記和鉤子。

總的來說,這些是外掛提供的模板標記:

c2c_if_file_exists() :檢查文件是否存在,回傳 true/false 或顯示包含檔案資訊的字串。
c2c_if_plugin_file_exists() :檢查文件是否存在(相對於外掛目錄),回傳 true/false 或顯示包含檔案資訊的字串。
c2c_if_theme_file_exists() :檢查文件是否存在(相對於目前啟用的主題目錄),回傳 true/false 或顯示包含檔案資訊的字串。如果目前主題是子主題,則函數將首先檢查子主題的目錄中是否存在該檔案,如果找不到,則再檢查父主題的目錄中是否存在。

這些是外掛提供的鉤子:

c2c_if_file_exists :篩選器,允許使用另一種方法安全地調用 c2c_if_file_exists(),以便在停用或刪除該外掛時,您對函數的調用不會在您的網站中引起錯誤。
c2c_if_plugin_file_exists :篩選器,允許使用另一種方法安全地調用 c2c_if_plugin_file_exists(),以便在停用或刪除該外掛時,您對函數的調用不會在您的網站中引起錯誤。
c2c_if_theme_file_exists :篩選器,允許使用另一種方法安全地調用 c2c_if_theme_file_exists(),以便在停用或刪除該外掛時,您對函數的調用不會在您的網站中引起錯誤。

原文外掛簡介

This plugin provides the functions c2c_if_file_exists(), c2c_if_theme_file_exists(), c2c_if_plugin_file_exists() that check if a file exists and either return true/false or display a string containing information about the file.

If a format string is not passed to it, the functions returns a simple boolean (true or false) indicating if the specified file exists.
Otherwise, the format string provided to it will be used to construct a response string, which can be customized to display information about the file (such as directory, extension, name, path, size, or url). If the $echo argument is true, that string is displayed on the page. Regardless of the value of $echo, the response string is returned by the function.

By default, c2c_if_file_exists() assumes you are looking for the file relative to the default WordPress upload directory. If you wish to search another directory, specify it as the $dir argument. c2c_if_theme_file_exists() assumes you are looking for a file relative to the currently active theme’s home directory. c2c_if_plugin_file_exists() assumes you are looking for a file relative to the directory that contains WordPress plugins.
Links: Plugin Homepage | Plugin Directory Page | GitHub | Author Homepage
Developer Documentation
Developer documentation can be found in DEVELOPER-DOCS.md. That documentation covers the template tags and hooks provided by the plugin.
As an overview, these are the template tags provided by the plugin:

c2c_if_file_exists() : Checks if a file exists and returns true/false or displays a string containing information about the file.
c2c_if_plugin_file_exists() : Checks if a file exists (relative to the plugins directory) and returns true/false or displays a string containing information about the file.
c2c_if_theme_file_exists() : Checks if a file exists (relative to the current theme’s directory) and returns true/false or displays a string containing information about the file. If the current theme is a child theme, then the function will check if the file exists first in the child theme’s directory, and if not there, then it will check the parent theme’s directory.

These are the hooks provided by the plugin:

c2c_if_file_exists : Filter that allows use of an alternative approach to safely invoke c2c_if_file_exists() in such a way that if the plugin were deactivated or deleted, then your calls to the function won’t cause errors in your site.
c2c_if_plugin_file_exists : Filter that allows use of an alternative approach to safely invoke c2c_if_plugin_file_exists() in such a way that if the plugin were deactivated or deleted, then your calls to the function won’t cause errors in your site.
c2c_if_theme_file_exists : Filter that allows use of an alternative approach to safely invoke c2c_if_theme_file_exists() in such a way that if the plugin were deactivated or deleted, then your calls to the function won’t cause errors in your site.

各版本下載點

  • 方法一:點下方版本號的連結下載 ZIP 檔案後,登入網站後台左側選單「外掛」的「安裝外掛」,然後選擇上方的「上傳外掛」,把下載回去的 ZIP 外掛打包檔案上傳上去安裝與啟用。
  • 方法二:透過「安裝外掛」的畫面右方搜尋功能,搜尋外掛名稱「If File Exists」來進行安裝。

(建議使用方法二,確保安裝的版本符合當前運作的 WordPress 環境。


2.0 | 2.1 | 2.2 | 2.3 | 2.4 | 1.0.1 | 1.0.3 | 2.1.1 | 2.1.2 | 2.1.3 | 2.2.1 | 2.2.2 | 2.2.3 | 2.2.4 | 2.2.5 | 2.2.6 | 2.2.7 | 2.2.8 | 2.2.9 | 2.3.1 | 2.3.2 | trunk | 2.2.10 |

延伸相關外掛(你可能也想知道)

暫無相關外掛推薦。

文章
Filter
Mastodon