All\r\n[authors_page counter=\"post\"]";
$UserRoles = get_roles();
foreach( $UserRoles as $RoleKey =>$RoleName ) {
$Contents[] = "
$RoleName
\r\n[authors_page role=\"$RoleKey\" counter=\"post\"]";
}
$Content = join("\r\n\r\n",$Contents);
return $Content;
}
function uvd_aup_remove()
{
//$the_page_id = get_option('uvd_aup_page_id');
//wp_delete_post($the_page_id);
delete_option('uvd_aup_page_id');
}
function uvd_aup_render_authors_page( $role = null, $post_counter = '' )
{
global $wp_query;
//set valid role
$roles = get_roles_keys();
$role_lower = strtolower( $role );
$roles_lower = array_map('strtolower',$roles);
if ( !in_array( $role_lower, $roles_lower ) ) $role = '';
$Permalink = get_permalink();
if (isset($wp_query->query_vars['author_login']) && $author = get_user_by('login',urldecode($wp_query->query_vars['author_login'])))
{
$ShowAuthorBiography = true;
if( !empty( $role ) ) {
$AuthorRoles = $author->roles;
$AuthorRolesLower = array_map('strtolower',$AuthorRoles);
if( !in_array($role_lower, $AuthorRolesLower )) $ShowAuthorBiography = false;
}
if( $ShowAuthorBiography ) {
$html = '<<Back';
$html .= do_shortcode( '[wp_biographia user='.urldecode($wp_query->query_vars['author_login']).']' );
return $html;
}
}
$args = array(
'blog_id' => $GLOBALS['blog_id'],
'role' => $role,
'orderby' => 'post_count',
'order' => 'DESC',
);
$authors = get_users( $args );
$clear_css = 'border:none; background:transparent; border:none; margin:0; padding:0;';
$html = '
';
$max_column_count = 4;
$columns_count = 0;
foreach ( $authors as $author) {
$columns_count++;
if ( $columns_count % $max_column_count == 1 ) {
$html .= '';
}
include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
if ( is_plugin_active('wp-biographia/wp-biographia.php') )
{
$url = $Permalink;
$url .= strpos( $Permalink, '?' ) === false ? '?' : '&';
$url .= 'author_login='.urlencode($author->user_login);
}
else
$url = get_author_posts_url( $author->ID, $author->user_nicename );
$html .= '';
$post_counter_html = '';
if( !empty( $post_counter ) ) {
$counter = count_user_posts( $author->ID );
if( 'post' === $post_counter ) {
$post_counter_html = '(' . $counter . ')';
} else {
$post_counter_html = str_replace( '%post%', $counter, $post_counter );
}
}
$html .= '' .get_avatar($author->ID).' '.$author->display_name.' ' . $post_counter_html . ' | ';
//$html .= '' .get_avatar($author->ID).'
'.$author->display_name.'';
if ( $columns_count % $max_column_count == 0 || $columns_count == sizeof($authors) ) {
$html .= '
';
}
}
$html .= '
';
return $html;
}
add_filter('query_vars', 'my_add_query_vars');
function my_add_query_vars($public_query_vars ) {
$public_query_vars[] = 'author_login';
return $public_query_vars;
}
add_shortcode( 'authors_page', 'uvd_aup_shortcode' );
function uvd_aup_shortcode( $atts )
{
$role = isset( $atts['role']) ? $atts['role'] : null;
$post_counter = isset( $atts['counter']) ? $atts['counter'] : '';
return uvd_aup_render_authors_page( $role, $post_counter );
}
function get_roles_keys() {
$Roles = get_roles();
$RoleKeys = array_keys( $Roles );
return $RoleKeys;
}
function get_roles() {
/**
* @var WP_Roles
*/
global $wp_roles;
if ( !isset( $wp_roles ) ) $wp_roles = new WP_Roles();
$Roles = $wp_roles->get_names();
return $Roles;
}