Esempio n. 1
0
/**
 * Adds custom rewrite rules for the plugin.
 *
 * @since  1.0.0
 * @access public
 * @return void
 */
function thds_rewrite_rules()
{
    $theme_type = thds_get_theme_post_type();
    $author_slug = thds_get_author_rewrite_slug();
    // Where to place the rewrite rules.  If no rewrite base, put them at the bottom.
    $after = thds_get_author_rewrite_base() ? 'top' : 'bottom';
    add_rewrite_rule($author_slug . '/([^/]+)/page/?([0-9]{1,})/?$', 'index.php?post_type=' . $theme_type . '&author_name=$matches[1]&paged=$matches[2]', $after);
    add_rewrite_rule($author_slug . '/([^/]+)/?$', 'index.php?post_type=' . $theme_type . '&author_name=$matches[1]', $after);
}
Esempio n. 2
0
/**
 * Returns the author archive URL.
 *
 * @since  1.0.0
 * @access public
 * @param  int     $user_id
 * @global object  $wp_rewrite
 * @global object  $authordata
 * @return string
 */
function thds_get_author_url($user_id = 0)
{
    global $wp_rewrite, $authordata;
    $url = '';
    // If no user ID, see if there's some author data we can get it from.
    if (!$user_id && is_object($authordata)) {
        $user_id = $authordata->ID;
    }
    // If we have a user ID, build the URL.
    if ($user_id) {
        // Get the author's nicename.
        $nicename = get_the_author_meta('user_nicename', $user_id);
        // Pretty permalinks.
        if ($wp_rewrite->using_permalinks()) {
            $url = home_url(user_trailingslashit(trailingslashit(thds_get_author_rewrite_slug()) . $nicename));
        } else {
            $url = add_query_arg(array('post_type' => thds_get_theme_post_type(), 'author_name' => $nicename), home_url('/'));
        }
    }
    return apply_filters('thds_get_author_url', $url, $user_id);
}