logo
Ask your WordPress questions! Pay money and get answers fast! (more info)

Warning: Please do not give out any FTP or ssh credentials to anyone, unless you trust them completely. Giving out login details is dangerous.

If the asker does not get an answer then they have 10 days to request a refund.

$-2
Switch theme based upon if_user_can, need fix for WP 3.1

WPEngineer wrote a function two years ago to switch themes based upon a number of variables. As of 3.1 this code no longer works, it breaks the theme display. I need this script updated to work with the latest version.

The public theme name should be inserted via an Options Framework variable while the if_user_can answer remains constant.

So for example:
$themedir = of_get_option('optf_themedir', 'twentyten' );

function fb_user_theme( $template = '' ) {
if ( current_user_can('edit_options') ) {
$template = 'onlyiol';
}
else {
$template = $themedir;
}
return $template;

}
add_filter('template', 'fb_user_theme');
add_filter('stylesheet', 'fb_user_theme');

Matt Taylor | 05/17/11 at 8:47am Edit


(2) Possible Answers Submitted...

Note: Matt Taylor felt their question was unanswered, so we granted them a refund.

Note: Matt Taylor requested a refund. They offered this explanation:

"This question deserves a refund because it was never answered."

If no one challenges a refund request, then they are automatically granted and proccessed after 48 hours. Admins of this site only review refund requests if someone challenges the request. If you are curious about how we handled previous refund requests, you may read over all refund requests and their challenges.

See a chronological view of answers?

Warning: Please do not give out any FTP or ssh credentials to anyone, unless you trust them completely. Giving out login details is dangerous.

  • avatar
    Last edited:
    05/17/11
    9:22am
    Utkarsh Kukreti says:

    You need to move the $themedir assignment inside the function.

    function fb_user_theme( $template = '' ) {
    $themedir = of_get_option('optf_themedir', 'twentyten' );
    if ( current_user_can('edit_options') ) {
    $template = 'onlyiol';
    }
    else {
    $template = $themedir;
    }
    return $template;
    }

    add_filter('template', 'fb_user_theme');
    add_filter('stylesheet', 'fb_user_theme');

    • 05/17/11 9:34am

      Matt Taylor says:

      I tried it in and out and as a hard-coded variable but the theme is still breaking.

      With your snippet the active theme (as set in the Appearance tab) is being displayed to users with permission and visitors without the permission only see a blank page.

      I attached a screenshot of what the has-permission user is seeing

      Attached Image

    • 05/17/11 9:39am

      Utkarsh Kukreti says:

      Please add

      var_dump($themedir);


      just after

      $themedir = of_get_option('optf_themedir', 'twentyten' );

    • 05/17/11 9:39am

      Utkarsh Kukreti says:

      (for debugging).

    • 05/17/11 9:51am

      Matt Taylor says:

      string(14) "certifiedcars2" string(14) "certifiedcars2" string(14) "certifiedcars2" string(14) "certifiedcars2" string(14) "certifiedcars2"

      Attached Image

  • avatar
    Last edited:
    05/18/11
    8:44am
    Just Me says:

    Did you apply the changes to both themes?

    • 05/18/11 8:47am

      Matt Taylor says:

      Yes, the function is called via a mu plugin.

    • 05/18/11 2:57pm

      Just Me says:

      if you hardcode the twentyten and use the var_dump does it return the right phrase then?

This question has expired.





Current status of this question: Refunded



Warning: Please do not give out any FTP or ssh credentials to anyone, unless you trust them completely. Giving out login details is dangerous.

If the asker does not get an answer then they have 10 days to request a refund.