/** * Adds custom rewrite rules for the plugin. * * @since 1.0.0 * @access public * @return void */ function ccp_rewrite_rules() { $project_type = ccp_get_project_post_type(); $author_slug = ccp_get_author_rewrite_slug(); // Where to place the rewrite rules. If no rewrite base, put them at the bottom. $after = ccp_get_author_rewrite_base() ? 'top' : 'bottom'; add_rewrite_rule($author_slug . '/([^/]+)/page/?([0-9]{1,})/?$', 'index.php?post_type=' . $project_type . '&author_name=$matches[1]&paged=$matches[2]', $after); add_rewrite_rule($author_slug . '/([^/]+)/?$', 'index.php?post_type=' . $project_type . '&author_name=$matches[1]', $after); }
/** * Returns the author portfolio archive URL. * * @since 1.0.0 * @access public * @param int $user_id * @global object $wp_rewrite * @global object $authordata * @return string */ function ccp_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(ccp_get_author_rewrite_slug()) . $nicename)); } else { $url = add_query_arg(array('post_type' => ccp_get_project_post_type(), 'author_name' => $nicename), home_url('/')); } } return apply_filters('ccp_get_author_url', $url, $user_id); }