前言介紹
- 這款 WordPress 外掛「Page Keys」是 2015-03-05 上架。
- 目前有 10 個安裝啟用數。
- 上一次更新是 2023-05-25,距離現在已有 708 天。超過一年沒更新,安裝要確認版本是否可用。以及後續維護問題!
- 外掛最低要求 WordPress 3.5.0 以上版本才可以安裝。
- 尚未有人給過這款外掛評分。
- 還沒有人在論壇上發問,可能目前使用數不多,還沒有什麼大問題。
外掛協作開發者
tfrommen |
外掛標籤
內容簡介
此外掛可以註冊頁面鍵值,分配實際的 WordPress 頁面給它們,並透過各個獨立的鍵值存取這些頁面。
你是否曾經想要從樣板檔案內存取特定的頁面?當然,你可以透過標題來查詢。但是如果有人想要重新命名這個頁面呢?好吧,那我們可以選擇使用 slug。但是如果有人想要編輯 slug 以符合新標題呢?對,我知道,這是不好的想法。但是那個人可能不知道,或者根本不在乎。好吧,那麼讓我們使用頁面 ID 吧。噢,等等,現在那個人不小心永久刪除了那個頁面。在前端網站經過某個瀏覽者之後,那個人建立了一個新的頁面,標題和 slug 都和原始頁面完全相同。但是那個頁面仍舊不會顯示。
這就是 Page Keys 發揮作用的時候了。
用法
這個外掛的目的就是提供一種透過唯一而獨立的鍵值來存取特定頁面的方法。而這很簡單。在 Page Keys 管理頁面上,你可以加入任意多個獨特的頁面鍵值。對於每一個頁面鍵值,你可以選擇一個(已發佈的)頁面。點選「儲存變更」按鈕,就完成了。
假如你現在想要從你的佈景主題樣板檔案內存取一個特定的頁面。在定義了頁面鍵值、並分配了那個頁面後,你可以透過呼叫 get_page_by_key( $key ) 來取得相應的 WP_Post 物件。如果你已經在全域命名空間內定義了一個同名的函式,你必須自己設定這樣的函式。原則上,這只是其中一個可以在這個外掛的 functions.php 檔案內找到的複製品。
篩選器
為了自訂這個外掛的某些方面,它提供了幾個篩選器。下列是這些篩選器的簡短描述和有關如何修改預設行為的程式碼範例。只需將相應的程式碼片段放在你的佈景主題的 functions.php 檔案或自訂外掛內,或其它適當的地方即可。
edit_page_keys_capability
編輯頁面鍵值是受到限制的,預設的限制權限是 edit_published_pages。這樣設計的原因在於,使用者如果能夠編輯已發佈的頁面(例如,將其狀態更改為草稿),就隱含著他能夠破壞任何映射到該頁面的頁面鍵值。
/**
* 篩選需要編輯頁面鍵值的權限。
*
* @param string $capability 需要編輯頁面鍵值的權限。
*/
add_filter( 'edit_page_keys_capability', function() {
return 'manage_options';
} );
list_page_keys_capability
存取外掛的設定頁面也是受到限制的。為了區分那些只能看到現有頁面鍵值及其相應頁面的使用者和那些能夠編輯頁面鍵值的使用者,此處有兩種單獨的權限。預設意味著存取設定頁面需要的權限是 edit_pages。
/**
* 篩選需要列出頁面鍵值的權限。
*
* @param string $capability 需要列出頁面鍵值的權限。
*/
add_filter( 'list_page_keys_capability', function() {
return 'read';
} );
page_keys_show_admin_notice
根據你使用此外掛的方式,通知你有未指派頁面的頁面鍵值的管理提示可能比較惱人。令人高興的是,你可以透過篩選器來關閉此提醒。
add_filter( 'page_keys_show_admin_notice', '__return_false' );
原文外掛簡介
Register page keys, assign actual WordPress pages to them, and access each of these pages by its individual key.
Have you ever wanted to access a specific page from inside a template file? Of course, you could query it by its title. But what if someone wanted to rename the page? Okay, so we choose the slug. But maybe that someone also thought editing the slug as well to make it fit the new title was a very good idea. Yes, I know, it is not. But that someone either didn’t know, or didn’t care. Okay, so let’s use the page ID. Oh, wait, now that someone, by mistake, permanently deleted that page. After having visited the frontend that someone created a new page, with the exact same title and the exact same slug as the original page. But that damn page still won’t show.
This is exactly when Page Keys kicks in.
Usage
What this plugin is all about is providing a means to accessing specific pages by unique and therefore individual keys. And doing this is quite simple. On the Page Keys admin page, you can add as many unique page keys as you like. For each of these page keys, you then select a (published) page. Hit the Save Changes button, and you’re done already.
Suppose you now want to access a specific page in one of your theme’s template file. After having defined a page key and having assigned a page to it, you can get the according WP_Post object by calling get_page_by_key( $key ). In the rare case where you already have a function of that name defined within the global namespace, you would have to set up such a function by yourself. In principle, this is just a copy of what you can find in the functions.php file of this plugin.
Filters
In order to customize certain aspects of the plugin, it provides you with several filters. For each of these, a short description as well as a code example on how to alter the default behavior is given below. Just put the according code snippet in your theme’s functions.php file or your customization plugin, or to some other appropriate place.
edit_page_keys_capability
Editing the page keys is restricted to a certain capability, which is by default edit_published_pages. The reason for this choice lies with the fact that user, who is capable of editing a published page (e.g., changing its status to draft), implicitly is able to compromise any page key mapped to the page.
/**
* Filter the capability required to edit the page keys.
*
* @param string $capability Capability required to edit the page keys.
*/
add_filter( 'edit_page_keys_capability', function() {
return 'manage_options';
} );
list_page_keys_capability
Accessing the plugin’s settings page is restricted, too. In order to distinguish between users who are only allowed to see the existing page keys as well as their respective page, and users, who are able to edit page keys, there are two individual capabilities. The default for accessing the settings page is edit_pages.
/**
* Filter the capability required to list the page keys.
*
* @param string $capability Capability required to list the page keys.
*/
add_filter( 'list_page_keys_capability', function() {
return 'read';
} );
page_keys_show_admin_notice
Depending on how exactly you are working with the plugin, the admin notice informing you about page keys that don’t have a page assigned might be more annoying than helping. Gladly, there is a filter to turn this off.
add_filter( 'page_keys_show_admin_notice', '__return_false' );
Contribution
To contribute to this plugin, please see its GitHub repository.
If you have a feature request, or if you have developed the feature already, please feel free to use the Issues and/or Pull Requests section.
Of course, you can also provide me with translations if you would like to use the plugin in another not yet included language.
各版本下載點
- 方法一:點下方版本號的連結下載 ZIP 檔案後,登入網站後台左側選單「外掛」的「安裝外掛」,然後選擇上方的「上傳外掛」,把下載回去的 ZIP 外掛打包檔案上傳上去安裝與啟用。
- 方法二:透過「安裝外掛」的畫面右方搜尋功能,搜尋外掛名稱「Page Keys」來進行安裝。
(建議使用方法二,確保安裝的版本符合當前運作的 WordPress 環境。
延伸相關外掛(你可能也想知道)
WP Keyboard Style Key Symbol 》這個外掛可以幫助我們在 WordPress 文章和頁面中添加鍵盤風格的按鍵符號。, 人們常常在尋找鍵盤快捷鍵,因此網站所有者總是提供快捷鍵。然而,問題來了,大多...。
WP Auto Salts 》輕量級的 WordPress 外掛,可為網站增加額外的安全性。, WP Auto Salts 會每週更新 wp-config.php 中的安全性鹽和密鑰。, 注意:確保 wp-config.php 中的鍵和...。
ShowKeys 》這個外掛可以輕鬆輸出鍵盤快速鍵。, ShowKeys 網站, 翻譯, , 英文 - 預設語言, 德文 - de_DE = 在 /language 資料夾中, 。
Protected Registration 》這是一個功能強大的外掛程式,能夠保護您的 WordPress 註冊頁面。, 為什麼需要這個外掛程式?, 許多 WordPress 使用者使用額外的欄位外掛程式,而其中大部分...。
Prev-Next Keyboard Navigation 》Prev-Next Keyboard Navigation 外掛會加入 JavaScript 讓你可以使用 J/K 鍵來快速移動至索引和存檔頁面上的文章。, 在此外掛中,所謂的「文章」定義為具有「...。
Keys to Admin 》此外掛提供了從部落格簡單進入後臺管理介面的捷徑,並不會在您的網頁中加入任何干擾性的連結。當您在部落格頁面(而不是在輸入欄位中)輸入指定文字,此外掛...。
Voce Group Keys 》提供使用函數生成用於快取的字串。鍵是根據傳入的名稱和零個或多個群組生成的。提供相同的名稱和群組會返回相同的鍵,直到整個快取被清除或特定群組的快取被...。
Keypress-list 》 Keypress-list (快速鍵清單) 是一個外掛,允許使用者使用鍵盤快速鍵執行 JavaScript/jQuery 代碼或函數。, 在管理區中,您可以指定使用什麼快速鍵啟動什麼動...。