WordPress.org

Make WordPress Core

Ticket #5290: author-template-the_author_role.diff

File author-template-the_author_role.diff, 1.2 KB (added by Kafkaesqui, 10 years ago)

Patch to author-template.php adding the_author_role() / get_the_author_role() .

  • wp-includes/author-template.php

     
    322322}
    323323
    324324/**
     325 * Get the account role of the author of the current post in the Loop.
     326 * @global object $wpdb WordPress database layer.
     327 * @global object $wp_roles avaliable account roles and capabilities.
     328 * @global object $authordata the current author's DB object.
     329 * @return string The author's account role.
     330 */
     331function get_the_author_role() {
     332        global $wpdb, $wp_roles, $authordata;
     333
     334        if ( !isset($wp_roles) )
     335                $wp_roles = new WP_Roles();
     336
     337        foreach($wp_roles->role_names as $role => $Role) {
     338                $caps = $wpdb->prefix . 'capabilities';
     339                if (array_key_exists($role, $authordata->$caps))
     340                        return $Role;
     341        }
     342}
     343
     344/**
     345 * Echo the account role of the author of the current post in the Loop.
     346 * @see get_the_author_role()
     347 * @return null
     348 */
     349function the_author_role() {
     350        echo get_the_author_role();
     351}
     352
     353/**
    325354 * get_the_author_posts() - Get the number of posts by the author of the current post in the Loop.
    326355 *
    327356 * @since 1.5
     
    500529        echo $return;
    501530}
    502531
    503 ?>
    504  No newline at end of file
     532?>