Rename and improve fictioneer_get_publishing_authors()
This commit is contained in:
parent
0f5e864324
commit
eb2d4c7a95
@ -3381,16 +3381,25 @@ if ( ! function_exists( 'mb_strlen' ) ) {
|
||||
/**
|
||||
* Returns all authors with published posts
|
||||
*
|
||||
* Note: Qualified post types are fcn_story, fcn_chapter, fcn_recommendation, and post.
|
||||
* Note: Qualified post types are fcn_story, fcn_chapter, fcn_recommendation,
|
||||
* and post. The result is cached for 12 hours as Transient.
|
||||
*
|
||||
* @return array Array of WP_User objects.
|
||||
* @link https://developer.wordpress.org/reference/functions/get_users/
|
||||
*
|
||||
* @param array $args Optional. Array of additional query arguments.
|
||||
*
|
||||
* @return array Array of WP_User object, stdClass objects, or IDs.
|
||||
*/
|
||||
|
||||
function fictioneer_get_all_publishing_authors() {
|
||||
function fictioneer_get_publishing_authors( $args = [] ) {
|
||||
static $authors = null;
|
||||
|
||||
if ( ! $authors && $transient = get_transient( 'fictioneer_search_all_authors' ) ) {
|
||||
$key = 'fictioneer_publishing_authors_' . md5( serialize( $args ) );
|
||||
|
||||
if ( ! $authors && $transient = get_transient( $key ) ) {
|
||||
$authors = $transient;
|
||||
|
||||
error_log( json_encode( $authors ) );
|
||||
}
|
||||
|
||||
if ( $authors ) {
|
||||
@ -3398,12 +3407,13 @@ function fictioneer_get_all_publishing_authors() {
|
||||
}
|
||||
|
||||
$authors = get_users(
|
||||
array(
|
||||
'has_published_posts' => ['fcn_story', 'fcn_chapter', 'fcn_recommendation', 'post']
|
||||
array_merge(
|
||||
array( 'has_published_posts' => ['fcn_story', 'fcn_chapter', 'fcn_recommendation', 'post'] ),
|
||||
$args
|
||||
)
|
||||
);
|
||||
|
||||
set_transient( 'fictioneer_search_all_authors', $authors, DAY_IN_SECONDS );
|
||||
set_transient( $key, $authors, 12 * HOUR_IN_SECONDS );
|
||||
|
||||
return $authors;
|
||||
}
|
||||
|
@ -50,7 +50,7 @@ if ( $show_advanced ) {
|
||||
array( 'keep_case' => 1 )
|
||||
);
|
||||
|
||||
$all_authors = fictioneer_get_all_publishing_authors();
|
||||
$all_authors = fictioneer_get_publishing_authors( array( 'fields' => array( 'ID', 'display_name' ) ) );
|
||||
$skip_author_keywords = count( $all_authors ) > FICTIONEER_AUTHOR_KEYWORD_SEARCH_LIMIT;
|
||||
|
||||
$queried_authors_in = sanitize_text_field( $_GET['authors'] ?? 0 );
|
||||
@ -86,16 +86,6 @@ if ( $show_advanced ) {
|
||||
}
|
||||
|
||||
if ( ! $skip_author_keywords ) {
|
||||
// Manually prime author caches
|
||||
// See: https://developer.wordpress.org/reference/functions/update_post_author_caches/
|
||||
if ( function_exists( 'cache_users' ) ) {
|
||||
$author_ids = wp_list_pluck( $all_authors, 'ID' );
|
||||
$author_ids = array_map( 'absint', $author_ids );
|
||||
$author_ids = array_unique( array_filter( $author_ids ) );
|
||||
|
||||
cache_users( $author_ids );
|
||||
}
|
||||
|
||||
foreach ( $all_authors as $author ) {
|
||||
$author_key = base64_encode( mb_strtolower( $author->display_name, 'UTF-8' ) );
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user