How Can We Help?

You are here:
< Back

Get a list of guest authors

gap_get_all_authors($as_array = false, $posts_per_page = null, $orderby = null, $order=nul)

$as_array true/false -An array is returned in either case.  When set to false, returns an array of post objects.. When set to true, returns an array of guest author names with the id as key
$posts_per_page  – number of guest authors to return. By default, all guest authors are returned.
$orderby – order of the list. Default is title. 
$order – desc – descending, asc-ascending.

 

Get All Authors

gap_get_all_authors()

Returns a list of all authors / users and guest authors, ordered by title., indexed by ‘u’ + key if the author is a WordPress user or ‘g’ + key if the author is a guest author. 

gap_extract_author( $authorid )

$authorid – an author id from the array returned  gap_get_all_authors

Returns an author id  object from the above list without a ‘g’ or a ‘u’.

$author->letter  //’g’ or ‘u’
$author->author_id   //the id

Get the Guest Author Link

gap_get_guest_author_link( $id,  $url = ”) //Get the url for the guest author

$id – the Guest Author Id (required)
$url – existing url (optional)

This function returns either the permalink or the website url depending on the settings.

 

gap_get_the_guest_author_posts_url( $authorid,  $class=”, $id = ”)

$authorid – the Guest Author Id
$class – hyperlink class
$id – hyperlink id

This function returns hyperlink from above function with the author name as text

Guest Author Permalink

gap_get_guest_author_permalink($id)

$id – The Guest Author Id

Returns the permalink for the guest author post.

 

Guest Author Website

gap_get_guest_author_website($id)
$id = guest author id
 

This function returns the authors website if it is set.

Guest Author Avatar

gap_get_guest_avatar($id=0, $imagesize=null) //get the guest author avatar html

$id = guest author id. If set to zero, the current post is used.
$imagesize = wordpress size (thumbnail/medium/large)

Returns the html code for the guest author avatar

gap_get_guest_avatar_url($id, $imagesize=’thumbnail’) //get the url to the guest author avatar

$id = guest author id 
$imagesizewordpress size (thumbnail/medium/large)

Returns the url for the guest author.

gap_get_guest_avatar_by_authorid($authorid, $imagesize = null)

$authorid – Guest author id
$imagesizewordpress size (thumbnail/medium/large)

Returns the avatar html for a specific author id (called by gap_get_guest_author)

Check an Archive Query 

gap_is_guest_author_query()

Checks to see if the current query is a guest author query.

Returns true if the current query is a guest archive query.

User Archive Queries

Generate a query for a user with guest authors stripped.

gap_wordpress_user_archive_query( $id, $args )

$id = user id
$args = additional WordPress query arguments.

Returns posts for the specific user

gap_guest_author_archive_query( $id, $args )

$id = Guest Author id
$args = additional WordPress query arguments

Returns posts from enabled post types for the specific Guest Author. 

Get Author Metadata

gap_get_guest_author_meta($guest_id = null, $meta_key, $single=true)

$guest_id – Guest Author Id. If this is not set, the id is retrieved from the post
$meta_key – the meta key
$single – true/ return a single value (set get_post_meta)

Returns the meta value 

gap_guest_author_email($id = null)

$id – the guest author id. If not entered, the value will be determined based on the current post

returns the authors email address.

Get the Author Website LInk

gap_guest_author_link(id=null)

$id – the guest author id. If not entered, the value will be determined based on the current post

returns the authors website url

 

Get the Author Name

ap_guest_author_name( $id = null )

$id – the guest author id. If not entered, the value will be determined based on the current post

returns the authors name

 

Get the Author Description/Bio

function gap_guest_author_description( $id = null )

$id – the guest author id. If not entered, the value will be determined based on the current post

returns the authors description

Get the Author Data for Guest Author

gap_get_guest_author_by_id($authorid) 

$authorid -Guest Author Id
returns a WordPress authordata object

gap_get_guest_author_by_post($postid) 

$postid – the post id
returns a WordPress authordata object if the post is an guest author post.

Misc Functions to get the Guest Author

 

gap_get_guest_author_by_title( $title) 

gets the author by author name

$title  – author name

returns the a guest author custom post type

gap_get_guest_author_by_sql($title) 

Essentially the same as above but uses SQL instead of a query.

$title = author name

returns guest author post

gap_get_guest_author_id( $post_id = null)

get the guest author id from the current post or a selected post id

$post_id – specific post id. When null uses the curren tpost

Returns a guest author id if the post has a guest author

 

Override the Guest Author 

guest_author_disable() – disables guest author functionality and saves all global variables.

guest_author_enable() – re-enables guest author functionality and resets all global variables.

Use these functions to override the guest author. This may be necessary in some themes. 

The code below bypasses the guest author avatar and only retrieves the user avatar.

guest_author_disable();
get_avatar( get_current_user_id(), 100 ) //now get the original avatar
guest_author_enable();

 

Override userdata.

In version 3.0+, the author query for guest author post archives now returns the guest author data in the queried object field. You can add this code to your custom theme functions or override the pluggable get_userdata function by adding this code.

if ( is_author() )
{  
      
   global $wp_query;
   if ( isset($wp_query) && $wp_query->is_guest_author )
   {
            if ($wp_query->is_guest_author)
            {
                $userdata = $wp_query->get_queried_object();
            }
   }
}

Get a list of guest authors

($as_array = false, $posts_per_page = null, $orderby = null, $order=nul)

$as_array true/false -An array is returned in either case.  When set to false, returns an array of post objects.. When set to true, returns an array of guest author names
$posts_per_page  – number of guest authors to return. By default, all guest authors are returned.
$orderby – order of the list. Default is title. 
$order – desc – descending, asc-ascending.

 

gap_get_guest_authors

gap_get_all_authors

Guest Author Link

gap_get_guest_author_link( $id,  $url = ”) //Get the url for the guest author

$id – the Guest Author Id (required)
$url – existing url (optional)

This function returns either the permalink or the website url depending on the settings.

Guest Author Permalink

gap_get_guest_author_permalink($id)

$id – The Guest Author Id

Returns the permalink.

Guest Author Avatar

gap_get_guest_avatar($id) //get the guest author avatar html

gap_get_guest_avatar_url($id) //get the url to the guest author avatar

Override the Guest Author Avatar in a post

To override the guest author avatar within a post, you need to set the guest_author_post_id to 0 or null before calling the function to get the avatar.

global $guest_author_post_id;     //global variable
$guest_author_save = $guest_author_post_id; //save the value
$guest_author_post_id=0; //clear the post id      
get_avatar( get_current_user_id(), 100 ) //now get the original avatar
$guest_author_post_id = $guest_author_save; //set the guest author post id back to what it was

Guest Author Helper Class

As of version 3.0, A helper class, guest-author-class.php is included with the plugin that allows you to get the userdata for a guest author. This file is located in the /helpers directory.

guest_author_class
object_id – (optional) default = current post id. This value can be any custom post id or a guest author id.
getauthor – (optional) default = false. Sets the value $class->authordata to the authors userdata.

guest_author_class( $object_id, $true );

Get the author data for the current post:

-Use the guest author class-
$class= guest_author_class( null, true );
$authordata = $class->authordata;
-or the global functions below -

Get authordata by author id

$authorid – the id for the author. Optional when an object id was sent to the class constructor..

$authorid = $class->get_guest_author_by_id ($authorid); 
-or the global function -
$authorid = gap_get_guest_author_by_id ($authorid);

Get authordata by post id

$post_id = the id for the post. Optional when an object id was sent to the class constructor.

$authurdata = $class->get_guest_author_by_post($post_id = null)
-or the global function-
authordata = gap_get_guest_author_by_post ( $post_id = null );

Get the guest id from a post

$post_id – the id for the post. Optional when an object id was sent to the class constructor.

$guest_id = $class->get_guest_author_id ($postid  = null);
-or the global function-
$guest_id = gap_get_guest_author_id($postid = null);

Get a meta value from the guest author

Possible meta values:

guest_author_website_link
guest_author_gravatar_email
‘facebook’, ‘twitter’, ‘linkedin’, ‘google-plus’, ‘googleplus’, ‘youtube’, ‘instagram’, ‘tumblr’, ‘pinterest’

The guest_id can be set to null to use the id that was set when the class was created. That information is based on the post id.

$meta_value = $class->get_guest_author_meta( $guest_id , $meta_key , $single=true )
-or the global function-
gap_get_guest_author_meta ($guest_id, $meta_key, $single=true);

Get the guest author website, email, description, name

These functions get an authors website, email, description or name.
The guest_id can be set to null to use the id that was set when the class was created. That information is based on the post id.
guest_id is optional if the object id was set in the class constructor.

$website = $class->guest_author_link($guest_id) -or the global function- gap_guest_author_link($guest_id);
$email = $class->guest_author_email($guest_id) -or the global function- gap_guest_author_email($guest_id);
$description = $class->guest_author_description($guest_id) -or the global function- gap_guest_author_description($guest_id);
$name = $class->guest_author_name($guest_id) -or the global function- gap_guest_author_name($guest_id);