get_option( 'posts_per_page' ), 'infinite' => false, 'max_column' => 2, 'show_profile' => true, 'default' => '', ), $atts, 'authors_by_latest_post' ); wp_enqueue_script( 'jquery' ); wp_enqueue_script( 'less', plugin_dir_url( __FILE__ ).'/js/less.min.js', array(), false, true ); wp_enqueue_script( 'riot', plugin_dir_url( __FILE__ ).'/js/riot+compiler.min.js', array(), false, true ); wp_enqueue_script( 'riot_tag', plugin_dir_url( __FILE__ ).'/js/riot_tag.js', array( 'jquery', 'less', 'riot' ), date('Y-m-d-His') ); $paged = get_query_var( 'paged', 1 ); $paged = ( is_numeric( $paged ) && $paged > 0 ) ? $paged : 1; $script = sprintf( 'var resource_url = "%s";', home_url() ); $script = $script . sprintf( 'riot.mount( "div#author-list-%d", "cards" )', $paged ); wp_add_inline_script( 'riot_tag', $script ); $output = sprintf( 'id="author-list-%s" count="%s" per_page="%s" infinite="%s" max_column="%s"', $paged, $paged, esc_html( $atts['per_page'] ), esc_html( $atts['infinite'] ), esc_html( $atts['max_column'] ) ); $output = '
'; return ''; } /** * Get post list. * * @param string $author_id Author ID * @return Post_Query|WP_Error Post list if available, error otherwise. */ static function get_post_query( $author_id = 0, $posts_per_page = 0 ) { if ( $author_id == 0 ) { return new WP_Error( 'ap_no_author', __( 'Author not defined.', 'authors-by-latest-post' ) ); } $query = new WP_Query( apply_filters( 'author_posts_args', array( 'author' => $author_id, 'posts_per_page' => $posts_per_page, 'no_found_rows' => true, 'post_status' => 'publish', 'ignore_sticky_posts' => true, ) ) ); if ( ! $query->have_posts() ) { return new WP_Error( 'ap_no_posts', __( 'Author has no post.', 'authors-by-latest-post' ) ); } foreach( $query->posts as $post ){ $posts[] = array( 'title' => $post->post_title, 'time' => $post->post_date, 'published' => human_time_diff( get_the_time( 'U', $post->ID ) ), 'permalink' => get_the_permalink($post->ID), 'thumbnail' => get_the_post_thumbnail_url( $post->ID, 'medium' ) ); } return $posts; } } new Authors_By_Latest_Post;