[wp-hackers] checking roles in a plugin?
Ozh
ozh at planetozh.com
Fri Sep 7 06:37:36 GMT 2007
On 9/7/07, Mindshare Studios <info at mindsharestudios.com> wrote:
> Hi again,
>
> Here's an even more concise example of my issue, when I activate this plugin
> all bets are off - blank white screen. Why would this be killing WP?
>
> <?php
> /*
> Plugin Name:poop
> */
>
> if ( current_user_can('edit_posts') ) {
> //stuff
> }
>
> ?>
>
> Damian
>
Actually, it's not producing a blank page, but an error. I bet you
have WP-Cache activated, which indeed shows blank page instead of
fatal errors, due to its output buffering.
The problem is that current_user_can() relies on wp_get_current_user()
which is a pluggable function, ie functions that are loaded *after*
the plugins.
You need to let everything load first, then test if current user can.
Something like:
<?php
/*
Plugin Name:poop reloaded
*/
function letsdoit() {
if ( current_user_can('edit_posts') ) {
die('OMGKTHXBYE');
}
}
add_action('init','letsdoit');
?>
--
http://FrenchFragFactory.net ~ Daily Quake News
http://planetOzh.com ~ Useless Blog & Code
More information about the wp-hackers
mailing list