get_author_posts_url

The timeline below displays how wordpress function get_author_posts_url has changed across different WordPress versions. If a version is not listed, refer to the next available version below.

WordPress Version: 6.1

/**
 * Retrieves the URL to the author page for the user with the ID provided.
 *
 * @since 2.1.0
 *
 * @global WP_Rewrite $wp_rewrite WordPress rewrite component.
 *
 * @param int    $author_id       Author ID.
 * @param string $author_nicename Optional. The author's nicename (slug). Default empty.
 * @return string The URL to the author's page.
 */
function get_author_posts_url($author_id, $author_nicename = '')
{
    global $wp_rewrite;
    $author_id = (int) $author_id;
    $link = $wp_rewrite->get_author_permastruct();
    if (empty($link)) {
        $file = home_url('/');
        $link = $file . '?author=' . $author_id;
    } else {
        if ('' === $author_nicename) {
            $user = get_userdata($author_id);
            if (!empty($user->user_nicename)) {
                $author_nicename = $user->user_nicename;
            }
        }
        $link = str_replace('%author%', $author_nicename, $link);
        $link = home_url(user_trailingslashit($link));
    }
    /**
     * Filters the URL to the author's page.
     *
     * @since 2.1.0
     *
     * @param string $link            The URL to the author's page.
     * @param int    $author_id       The author's ID.
     * @param string $author_nicename The author's nice name.
     */
    $link = apply_filters('author_link', $link, $author_id, $author_nicename);
    return $link;
}

WordPress Version: 5.5

/**
 * Retrieve the URL to the author page for the user with the ID provided.
 *
 * @since 2.1.0
 *
 * @global WP_Rewrite $wp_rewrite WordPress rewrite component.
 *
 * @param int    $author_id       Author ID.
 * @param string $author_nicename Optional. The author's nicename (slug). Default empty.
 * @return string The URL to the author's page.
 */
function get_author_posts_url($author_id, $author_nicename = '')
{
    global $wp_rewrite;
    $auth_ID = (int) $author_id;
    $link = $wp_rewrite->get_author_permastruct();
    if (empty($link)) {
        $file = home_url('/');
        $link = $file . '?author=' . $auth_ID;
    } else {
        if ('' === $author_nicename) {
            $user = get_userdata($author_id);
            if (!empty($user->user_nicename)) {
                $author_nicename = $user->user_nicename;
            }
        }
        $link = str_replace('%author%', $author_nicename, $link);
        $link = home_url(user_trailingslashit($link));
    }
    /**
     * Filters the URL to the author's page.
     *
     * @since 2.1.0
     *
     * @param string $link            The URL to the author's page.
     * @param int    $author_id       The author's ID.
     * @param string $author_nicename The author's nice name.
     */
    $link = apply_filters('author_link', $link, $author_id, $author_nicename);
    return $link;
}

WordPress Version: 5.3

/**
 * Retrieve the URL to the author page for the user with the ID provided.
 *
 * @since 2.1.0
 *
 * @global WP_Rewrite $wp_rewrite WordPress rewrite component.
 *
 * @param int    $author_id       Author ID.
 * @param string $author_nicename Optional. The author's nicename (slug). Default empty.
 * @return string The URL to the author's page.
 */
function get_author_posts_url($author_id, $author_nicename = '')
{
    global $wp_rewrite;
    $auth_ID = (int) $author_id;
    $link = $wp_rewrite->get_author_permastruct();
    if (empty($link)) {
        $file = home_url('/');
        $link = $file . '?author=' . $auth_ID;
    } else {
        if ('' == $author_nicename) {
            $user = get_userdata($author_id);
            if (!empty($user->user_nicename)) {
                $author_nicename = $user->user_nicename;
            }
        }
        $link = str_replace('%author%', $author_nicename, $link);
        $link = home_url(user_trailingslashit($link));
    }
    /**
     * Filters the URL to the author's page.
     *
     * @since 2.1.0
     *
     * @param string $link            The URL to the author's page.
     * @param int    $author_id       The author's id.
     * @param string $author_nicename The author's nice name.
     */
    $link = apply_filters('author_link', $link, $author_id, $author_nicename);
    return $link;
}

WordPress Version: 4.6

/**
 * Retrieve the URL to the author page for the user with the ID provided.
 *
 * @since 2.1.0
 *
 * @global WP_Rewrite $wp_rewrite
 *
 * @param int    $author_id       Author ID.
 * @param string $author_nicename Optional. The author's nicename (slug). Default empty.
 * @return string The URL to the author's page.
 */
function get_author_posts_url($author_id, $author_nicename = '')
{
    global $wp_rewrite;
    $auth_ID = (int) $author_id;
    $link = $wp_rewrite->get_author_permastruct();
    if (empty($link)) {
        $file = home_url('/');
        $link = $file . '?author=' . $auth_ID;
    } else {
        if ('' == $author_nicename) {
            $user = get_userdata($author_id);
            if (!empty($user->user_nicename)) {
                $author_nicename = $user->user_nicename;
            }
        }
        $link = str_replace('%author%', $author_nicename, $link);
        $link = home_url(user_trailingslashit($link));
    }
    /**
     * Filters the URL to the author's page.
     *
     * @since 2.1.0
     *
     * @param string $link            The URL to the author's page.
     * @param int    $author_id       The author's id.
     * @param string $author_nicename The author's nice name.
     */
    $link = apply_filters('author_link', $link, $author_id, $author_nicename);
    return $link;
}

WordPress Version: 4.5

/**
 * Retrieve the URL to the author page for the user with the ID provided.
 *
 * @since 2.1.0
 *
 * @global WP_Rewrite $wp_rewrite
 *
 * @param int    $author_id       Author ID.
 * @param string $author_nicename Optional. The author's nicename (slug). Default empty.
 * @return string The URL to the author's page.
 */
function get_author_posts_url($author_id, $author_nicename = '')
{
    global $wp_rewrite;
    $auth_ID = (int) $author_id;
    $link = $wp_rewrite->get_author_permastruct();
    if (empty($link)) {
        $file = home_url('/');
        $link = $file . '?author=' . $auth_ID;
    } else {
        if ('' == $author_nicename) {
            $user = get_userdata($author_id);
            if (!empty($user->user_nicename)) {
                $author_nicename = $user->user_nicename;
            }
        }
        $link = str_replace('%author%', $author_nicename, $link);
        $link = home_url(user_trailingslashit($link));
    }
    /**
     * Filter the URL to the author's page.
     *
     * @since 2.1.0
     *
     * @param string $link            The URL to the author's page.
     * @param int    $author_id       The author's id.
     * @param string $author_nicename The author's nice name.
     */
    $link = apply_filters('author_link', $link, $author_id, $author_nicename);
    return $link;
}

WordPress Version: 4.3

/**
 * Retrieve the URL to the author page for the user with the ID provided.
 *
 * @since 2.1.0
 *
 * @global WP_Rewrite $wp_rewrite
 *
 * @return string The URL to the author's page.
 */
function get_author_posts_url($author_id, $author_nicename = '')
{
    global $wp_rewrite;
    $auth_ID = (int) $author_id;
    $link = $wp_rewrite->get_author_permastruct();
    if (empty($link)) {
        $file = home_url('/');
        $link = $file . '?author=' . $auth_ID;
    } else {
        if ('' == $author_nicename) {
            $user = get_userdata($author_id);
            if (!empty($user->user_nicename)) {
                $author_nicename = $user->user_nicename;
            }
        }
        $link = str_replace('%author%', $author_nicename, $link);
        $link = home_url(user_trailingslashit($link));
    }
    /**
     * Filter the URL to the author's page.
     *
     * @since 2.1.0
     *
     * @param string $link            The URL to the author's page.
     * @param int    $author_id       The author's id.
     * @param string $author_nicename The author's nice name.
     */
    $link = apply_filters('author_link', $link, $author_id, $author_nicename);
    return $link;
}

WordPress Version: 3.7

/**
 * Retrieve the URL to the author page for the user with the ID provided.
 *
 * @since 2.1.0
 * @uses $wp_rewrite WP_Rewrite
 * @return string The URL to the author's page.
 */
function get_author_posts_url($author_id, $author_nicename = '')
{
    global $wp_rewrite;
    $auth_ID = (int) $author_id;
    $link = $wp_rewrite->get_author_permastruct();
    if (empty($link)) {
        $file = home_url('/');
        $link = $file . '?author=' . $auth_ID;
    } else {
        if ('' == $author_nicename) {
            $user = get_userdata($author_id);
            if (!empty($user->user_nicename)) {
                $author_nicename = $user->user_nicename;
            }
        }
        $link = str_replace('%author%', $author_nicename, $link);
        $link = home_url(user_trailingslashit($link));
    }
    /**
     * Filter the URL to the author's page.
     *
     * @since 2.1.0
     *
     * @param string $link            The URL to the author's page.
     * @param int    $author_id       The author's id.
     * @param string $author_nicename The author's nice name.
     */
    $link = apply_filters('author_link', $link, $author_id, $author_nicename);
    return $link;
}