From 2e782e0bf645b2deafba2a4caa6a86f965dc3cfe Mon Sep 17 00:00:00 2001 From: Eclipse Srl Date: Wed, 16 Oct 2019 09:48:20 +0200 Subject: [PATCH] added function udesly_get_authors --- README.txt | 5 ++- includes/misc/blog.php | 68 +++++++++++++++++++++++++++++++++++++++ udesly-adapter-plugin.php | 4 +-- 3 files changed, 74 insertions(+), 3 deletions(-) diff --git a/README.txt b/README.txt index f14c55c..18879ab 100644 --- a/README.txt +++ b/README.txt @@ -4,7 +4,7 @@ Donate link: https://www.udesly.com/ Tags: webflow to wordpress, editor, page builder, layout design, udesly, webflow Requires at least: 5.0 Tested up to: 5.2.3 -Stable tag: 2.0.0.34 +Stable tag: 2.0.0.35 License: GPLv3 or later License URI: https://www.udesly.com/terms-conditions-of-use/#udesly-wordpress-plugin Requires PHP: 5.6.0 @@ -80,6 +80,9 @@ That's all! Absolutely! You can use the Udesly Adapter to create more than one website. == Changelog == += 2.0.0.35 = +* Added function udesly_get_authors + = 2.0.0.34 = * Fixed issue with sanitize template name for ajax pagination diff --git a/includes/misc/blog.php b/includes/misc/blog.php index 7878084..0c3072d 100644 --- a/includes/misc/blog.php +++ b/includes/misc/blog.php @@ -183,4 +183,72 @@ function udesly_get_tag_link_by_slug( $slug ) { return '#'; } +} + +function udesly_get_authors() { + global $wpdb; + + $defaults = array( + 'orderby' => 'name', + 'order' => 'ASC', + 'number' => '', + 'exclude_admin' => false, + 'hide_empty' => true, + 'exclude' => '', + 'include' => '', + ); + + $args = apply_filters('udesly_get_authors_args', $defaults); + + $query_args = wp_array_slice_assoc( $args, array( 'orderby', 'order', 'number', 'exclude', 'include' ) ); + $query_args['fields'] = 'ids'; + $authors = get_users( $query_args ); + + $author_count = array(); + foreach ( (array) $wpdb->get_results( "SELECT DISTINCT post_author, COUNT(ID) AS count FROM $wpdb->posts WHERE " . get_private_posts_cap_sql( 'post' ) . ' GROUP BY post_author' ) as $row ) { + $author_count[ $row->post_author ] = $row->count; + } + + $result = []; + + foreach ( $authors as $author_id ) { + $posts = isset($author_count[$author_id]) ? $author_count[$author_id] : 0; + + if (!$posts && $args['hide_empty']) { + continue; + } + + $author = get_userdata($author_id); + + if (!$author) { + continue; + } + + if ($args['exclude_admin'] && 'admin' === $author->display_name) { + continue; + } + + $result[] = (object) array( + "ID" => $author->ID, + "display_name" => $author->display_name, + "first_name" => $author->first_name, + "last_name" => $author->last_name, + "email" => $author->user_email, + "description" => $author->description, + "website" => $author->user_url, + "facebook" => get_user_meta($author->ID, "facebook", true), + "linkedin" => get_user_meta($author->ID, "linkedin", true), + "youtube" => get_user_meta($author->ID, "youtube", true), + "twitter" => get_user_meta($author->ID, "twitter", true), + "dribble" => get_user_meta($author->ID, "dribble", true), + "instagram" => get_user_meta($author->ID, "instagram", true), + "reddit" => get_user_meta($author->ID, "reddit", true), + "phone" => get_user_meta($author->ID, "phonenumber", true), + "url" => get_author_posts_url($author->ID), + "avatar" => get_avatar_url($author->user_email), + ); + } + + return $result; + } \ No newline at end of file diff --git a/udesly-adapter-plugin.php b/udesly-adapter-plugin.php index 70ec0db..2a293dd 100644 --- a/udesly-adapter-plugin.php +++ b/udesly-adapter-plugin.php @@ -11,7 +11,7 @@ * Plugin Name: Udesly Adapter * Plugin URI: https://www.udesly.com * Description: This is a support plugin for Udesly (Webflow to WordPress converter) that allows you to enable additional features for your theme. - * Version: 2.0.0.34 + * Version: 2.0.0.35 * Author: Udesly * Author URI: https://www.udesly.com * License: GPL-2.0+ @@ -29,7 +29,7 @@ // Constants defined('UDESLY_ADAPTER_PLUGIN_DIRECTORY_PATH') ?: define('UDESLY_ADAPTER_PLUGIN_DIRECTORY_PATH', plugin_dir_path(__FILE__)); defined('UDESLY_ADAPTER_PLUGIN_DIRECTORY_URL') ?: define('UDESLY_ADAPTER_PLUGIN_DIRECTORY_URL', plugin_dir_url(__FILE__)); -defined('UDESLY_ADAPTER_VERSION') ?: define('UDESLY_ADAPTER_VERSION', "2.0.0.34"); +defined('UDESLY_ADAPTER_VERSION') ?: define('UDESLY_ADAPTER_VERSION', "2.0.0.35"); defined('UDESLY_TEXT_DOMAIN') ?: define('UDESLY_TEXT_DOMAIN', "udesly-adapter-plugin"); defined('UDESLY_ADAPTER_PLUGIN_MISC_PATH') ?: define('UDESLY_ADAPTER_PLUGIN_MISC_PATH', plugin_dir_path(__FILE__) . 'includes/misc/');