Skip to content


Subversion checkout URL

You can clone with
Download ZIP


role-{rolename}.php fix #12

wants to merge 3 commits into from

1 participant


Problem: role-{rolename}.php was not working in any context

Solution: Changed parameter within cfct_username_to_id() to retrieve a user object via the proper username (login) instead of the ID using the get_user_by() function. Confirmed working in all contexts.


This doesn't appear to work when using default permalinks. Investigating further.


Slug parameter failed in cfct_username_to_id() when the site is using default permalinks. Updated cfct_choose_general_template_role() to use post object's author (ID) variable if one is set and avoiding use of cfct_username_to_id(), but falling back if no author is set.

Confirmed functionality of role-{rolename}.php with both default and fancy permalinks and both single- and multi-word usernames. Ready for merge.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Apr 10, 2013
  1. Changed paramter to use user slug - usernames with a space weren't wo…

    Craig Freeman committed
    …rking with user login
  2. Using post object's author (ID) variable if set

    Craig Freeman committed
This page is out of date. Refresh to see the latest.
Showing with 13 additions and 2 deletions.
  1. +13 −2 utility.php
15 utility.php
@@ -506,8 +506,19 @@ function cfct_choose_general_template_type($dir, $files) {
function cfct_choose_general_template_role($dir, $files) {
$files = cfct_role_templates($dir, $files);
if (count($files)) {
+ $userid = get_query_var('author');
$username = get_query_var('author_name');
- $user = new WP_User(cfct_username_to_id($username));
+ if (isset($userid)) {
+ $user = new WP_User($userid);
+ }
+ elseif (isset($username)) {
+ $user = new WP_User(cfct_username_to_id($username));
+ }
+ else {
+ return false;
+ }
if (!empty($user->user_login)) {
if (count($user->roles)) {
foreach ($user->roles as $role) {
@@ -1383,7 +1394,7 @@ function cfct_cat_id_to_slug($id) {
function cfct_username_to_id($username) {
- $user = get_user_by('ID', $username);
+ $user = get_user_by('slug', $username);
return (isset($user->ID) ? $user->ID : 0);
Something went wrong with that request. Please try again.