[wordpress插件] Authors Autocomplete Meta Box作者自动完成元框

wordpress 插件 文章 2020-02-23 23:50 536 0 全屏看文

AI助手支持GPT4.0

评分
100
描述

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.

将默认的WordPress作者meta框(带有作者下拉列表)替换为允许您通过自动完成功能选择帖子或页面作者的meta框。

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.

大声喊着 ereleases.com 来调试此插件并让我与社区分享。

Thanks, guys.

谢谢你们。

You rock!

你真摇滚!

Lots of thanks to Andrew Kurtis from WebHostingHub Support for providing the Spanish translation.

非常感谢WebHostingHub支持小组的Andrew Kurtis提供西班牙语翻译。

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

authors_autocomplete_mb_allow_user_id

This filter allows you to block users from the autocomplete results according to user id.

通过该过滤器,您可以根据用户ID阻止用户使用自动填充结果。

Return true to allow and false to deny.

返回 true 允许并返回 false 拒绝。

It passes the user id, along with the post ID and post type.

它传递用户ID,以及帖子ID和帖子类型。

Don’t forget: when using a filter, you MUST return something.

别忘了::使用过滤器时,您必须退货。

Here’s an example to help you get started:

这是一个帮助您入门的示例:

  <?php

// return *true* to allow the user and *false* to deny the user from autocomplete results

//返回* true *以允许用户,并返回* false *从自动完成结果中拒绝用户

add_filter( 'authors_autocomplete_mb_allow_user_id', 'filter_authors_autocomplete_mb_allow_user_id', 1, 4 );

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 ) {    

函数filter_authors_autocomplete_mb_allow_user_id($ allow_user_id,$ user_id,$ post_id,$ post_type){    

if ( $user_id == 4 )        

如果($ user_id == 4)        

return false;    

返回false;    

return $allow_user_id;

返回$ allow_user_id;

}

}

?>

?>

authors_autocomplete_mb_allow_user_role

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.

返回 true 允许并返回 false 拒绝。

It passes the user role, along with the post ID and post type.

它传递用户角色以及帖子ID和帖子类型。

Don’t forget: when using a filter, you MUST return something.

别忘了::使用过滤器时,您必须退货。

Here’s an example to help you get started:

这是一个帮助您入门的示例:

  <?php

// return *true* to allow the user and *false* to deny the user from autocomplete results

//返回* true *以允许用户,并返回* false *从自动完成结果中拒绝用户

add_filter( 'authors_autocomplete_mb_allow_user_role', 'filter_authors_autocomplete_mb_allow_user_role', 1, 4 );

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 ) {    

函数filter_authors_autocomplete_mb_allow_user_role($ allow_user_role,$ user_role,$ post_id,$ post_type){    

if ( $user_role == 'administrator' )        

如果($ user_role =='administrator')        

return false;    

返回false;    

return $allow_user_role;

返回$ allow_user_role;

}

}

?>

?>

authors_autocomplete_mb_author_capability

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.

如果用户正在编辑页面,则如果他们具有 edit_pages 的能力,则添加该用户;否则,如果他们具有 edit_posts 的能力,则添加该用户。

p>

>

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.

它传递默认功能以及帖子ID和帖子类型。

Don’t forget: when using a filter, you MUST return something.

别忘了::使用过滤器时,您必须退货。

Here’s an example to help you get started:

这是一个帮助您入门的示例:

  <?php

// changing the author capability according to post type

//根据帖子类型更改作者功能

add_filter( 'authors_autocomplete_mb_author_capability', 'filter_authors_autocomplete_mb_author_capability', 1, 3 );

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 ) {    

函数filter_authors_autocomplete_mb_author_capability($ author_capability,$ post_id,$ post_type){    

if ( $post_type == 'movies' )        

如果($ post_type =='电影')        

return 'edit_movies';    

返回'edit_movies';    

return $author_capability;

返回$ author_capability;

}

}

?>

?>

authors_autocomplete_mb_custom_user_search_user_ids

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?

是否要使用自动完成框来搜索除默认的user_login,display_name和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.

使用此过滤器可以运行所需的任何搜索,并仅从结果中返回用户ID。

It passes a blank array to get you started, the search term, post ID and post type.

它传递一个空白数组,以帮助您入门,搜索词,帖子ID和帖子类型。

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:

以下是我的一个示例,该示例帮助用户搜索其 CIMY用户额外字段

>

>

  <?php

// search CIMY User Extra Fields with search term and return user IDs

//使用搜索词搜索CIMY用户额外字段并返回用户ID

add_filter( 'authors_autocomplete_mb_custom_user_search_user_ids', 'authors_autocomplete_custom_user_search', 1, 4 );

add_filter('authors_autocomplete_mb_custom_user_search_user_ids','authors_autocomplete_custom_user_search',1,4);

function authors_autocomplete_custom_user_search( $user_ids, $search_term, $post_id, $post_type ) {   

函数authors_autocomplete_custom_user_search($ user_ids,$ search_term,$ post_id,$ post_type){   

global $wpdb;   

全局$ wpdb;   

return $wpdb->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 '%

返回$ wpdb-> get_col(“从$ wpdb-> users用户中选择SELECT users.ID,cimy_uef_data.VALUE

$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" );

$ 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“);

}

}

?>

?>

安装步骤

    1. Upload ‘authors-autocomplete-meta-box’ to the ‘/wp-content/plugins/’ directory.
    2. 将“ authors-autocomplete-meta-box”上传到“ / wp-content / plugins /”目录。

    3. Activate the plugin through the ‘Plugins’ menu in WordPress.
    4. 通过WordPress中的“插件”菜单激活插件。

    5. Start finding and selecting a post or page’s author like a boss.
    6. 开始查找并选择帖子或专页的作者,例如老板。

下载地址
https://downloads.wordpress.org/plugin/authors-autocomplete-meta-box.1.2.zip
-EOF-

AI助手支持GPT4.0