[WordPress] 外掛分享: Authors Autocomplete Meta Box

首頁外掛目錄 › Authors Autocomplete Meta Box
WordPress 外掛 Authors Autocomplete Meta Box 的封面圖片
⚠ 此外掛已下架 — 不再更新維護,建議勿安裝。
100+
安裝啟用
★★★★★
5/5 分(5 則評價)
4490 天前
最後更新
問題解決
WordPress 3.3+ v1.2 上架:2013-05-22

內容簡介

這個外掛將預設的WordPress作者欄位(包含作者下拉式選單)替換為一個可透過自動完成來選擇文章或頁面作者的欄位。

當你擁有許多作者且厭倦捲動長長的作者下拉式選單時,這個外掛可以很方便。

鳴謝

非常感謝ereleases.com外包這個外掛,讓我能與社群分享。你們真棒!

同時也感謝Andrew Kurtis來自WebHostingHub Support提供的西班牙語翻譯。

過濾器

過濾器可以很方便的針對特定項目在每個網站上進行客製化。我是一個絕對的高手,因此我經常使用動作以及過濾器來嵌入我使用的插件。以下是一些非常有幫助的過濾器,讓你能夠按照自己的意願設定作者的自動完成欄位。

authors_autocomplete_mb_allow_user_id

這個過濾器讓你可以阻止使用者根據使用者ID在自動完成的清單中顯示限制;返回true允許顯示,false則是不允許顯示。

它會傳遞使用者ID以及文章ID和文章類型,不要忘記:當使用過濾器時,一定要返回一些東西。這裡有一個例子可以幫助你入門:

<?php

// 返回 * true *,以允許使用者顯示;返回 * false * 以拒絕使用者顯示到自動完成的結果中
add_filter('authors_autocomplete_mb_allow_user_id','filter_authors_autocomplete_mb_allow_user_id',1,4);
function filter_authors_autocomplete_mb_allow_user_id ($allow_user_id,$user_id,$post_id,$post_type) {
     如果($user_id == 4)
        返回false;
     返回$allow_user_id;
}
?>

authors_autocomplete_mb_allow_user_role

這個過濾器讓你可以根據使用者角色阻止使用者在自動完成清單中的顯示;返回true允許顯示,false則是不允許。

它會傳遞使用者角色以及文章ID和文章類型,不要忘記:當使用過濾器時,一定要返回一些東西。這裡有一個例子可以幫助你入門:

<?php

// 返回 * true *,以允許使用者顯示;返回 * false * 以阻止使用者顯示到自動完成的結果中
add_filter('authors_autocomplete_mb_allow_user_role', 'filter_authors_autocomplete_mb_allow_user_role',1,4);
function filter_authors_autocomplete_mb_allow_user_role ($allow_user_role,$user_role,$post_id,$post_type) {
    如果($user_role == 'administrator')
        返回false;
    返回$allow_user_role;
}
?>

authors_autocomplete_mb_author_capability

當檢查使用者是否擁有作者權限以及是否應將其包含在自動完成的結果中時,外掛會檢查使用者的能力。如果使用者正在編輯頁面,則只會在他們具有edit_pages能力時加入使用者;否則,如果使用者具有edit_posts權力,他們將被加入使用者,如果你想更改作者權限能力,這個過濾器就是為你而設的。它會傳遞預設能力,以及文章ID和文章類型。不要忘記:當使用過濾器時,必須返回東西。這裡有一個例子可以幫助你入門:

<?php
// 根據文章類型更改作者靈活性
add_filter('authors_autocomplete_mb_author_capability','filter_authors_autocomplete_mb_author_capability',1,3);
function filter_authors_autocomplete_mb_author_capability ($author_capability,$post_id,$post_type) {
    如果($post_type == 'movies')
        返回'edit_movies';
    返回$author_capability;
}
?>

外掛標籤

開發者團隊

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

① 下載 ZIP → 後台「外掛 › 安裝外掛 › 上傳外掛」
② 後台搜尋「Authors Autocomplete Meta Box」→ 直接安裝(推薦)
📦 歷史版本下載

原文外掛簡介

Replaces the default WordPress Author meta box (that has an author dropdown) with a meta box that allows you to select the post’s, or page’s, author via Autocomplete.
Can really come in handy if you have a lot of authors and are tired of scrolling through that long author dropdown.
Credits
Big shoutout to ereleases.com for commissioning this plugin and letting me share it with the community. Thanks, guys. You rock!
Lots of thanks to Andrew Kurtis from WebHostingHub Support for providing the Spanish translation.
Filters
Filters can really come in handy to nail down specific customizations on a site by site basis. I am what you would consider a power user so I’m a big fan of actions and filters and try to incorporate them into my plugins as much as possible. Here are some pretty helpful filters to get your authors autocomplete meta box working just the way you like.
authors_autocomplete_mb_allow_user_id
This filter allows you to block users from the autocomplete results according to user id. Return true to allow and false to deny.
It passes the user id, along with the post ID and post type. Don’t forget: when using a filter, you MUST return something. Here’s an example to help you get started:

authors_autocomplete_mb_allow_user_role
This filter allows you to block users from the autocomplete results according to user role. Return true to allow and false to deny.
It passes the user role, along with the post ID and post type. Don’t forget: when using a filter, you MUST return something. Here’s an example to help you get started:

authors_autocomplete_mb_author_capability
When checking to see if a user has author privileges, and should therefore be included in the autocomplete results, the plugin checks the user’s capabilities. If the user is editing a page, then the user is added if they have the capability to edit_pages, otherwise the user is added if they have the capability to edit_posts.
If you would like to change the author privilege capability, then this filter is for you. It passes the default capability, along with the post ID and post type. Don’t forget: when using a filter, you MUST return something. Here’s an example to help you get started:

authors_autocomplete_mb_custom_user_search_user_ids
Want the autocomplete box to search information besides the default user_login, display_name and user_email? This is the filter for you.
Use this filter to run whatever search you like and simply return the user IDs from your results.
It passes a blank array to get you started, the search term, post ID and post type. Don’t forget: when using a filter, you MUST return something.
Here’s an example from me helping a user search their CIMY User Extra Fields:
get_col( "SELECT users.ID, cimy_uef_data.VALUE FROM $wpdb->users users LEFT JOIN {$wpdb->prefix}cimy_uef_data cimy_uef_data ON cimy_uef_data.USER_ID = users.ID WHERE ( cimy_uef_data.VALUE LIKE '%$search_term%' OR users.user_login LIKE '%$search_term%' OR users.display_name LIKE '%$search_term%' OR users.user_email LIKE '%$search_term%' ) ORDER BY users.ID ASC" );
}
?>

延伸相關外掛

文章
Filter
Apply Filters
Mastodon