WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Why does calling current_user_can() crash WP 2.9.2? (3 posts)

  1. topquarkproductions
    Member
    Posted 4 years ago #

    I don't think I'm doing anything wrong, but I came up to this tonight:

    0) Did a clean install of WordPress 2.9.2
    1) Started writing a new plugin
    2) Put this single line of code in it:
    var_dump(current_user_can('edit_post'));
    3) WordPress 2.9.2 (admin and front end) crashed with the following error:
    Fatal error: Call to undefined function wp_get_current_user() in /Users/trevor/Sites/playground/clean/wp-includes/capabilities.php on line 969

    WARNING: If you try this, be sure you have root privileges to rm -r this plugin:

    In a wp-content/plugins/asdf, place a file called asdf.php with this in it:

    <?php
    /*
    Plugin Name: Asdf
    Plugin URI: http://asdf.com/
    Description: Asdf asdf asdf
    Version: 1
    Author: Top Quark Productions
    */

    var_dump(current_user_can('edit_post'));
    ?>

    Activating the plugin gives me the above error message (front-end and wp-admin):

    Ummm...

    What? How else would I find out if I can put something for the author on the front-end?

    (Note: the header text is copied direct from Akismet, with the names changed to protect the mighty)

    Thanks
    Trevor
    Top Quark Productions
    =====================
    My first published plugin went live at 0.5.0 recently.
    ---------------------
    topCollage arranges photos from the gallery in css-based collages.
    Lots of shortcode options and I'd like to add the ability to jQuery manipulation of those options on the front end. Thus, the call to current_user_can() that's stumping me right now.

  2. topquarkproductions
    Member
    Posted 4 years ago #

    RESOLVED:

    If I change the code in the plugin to:

    <?php
    /*
    Plugin Name: Asdf
    Plugin URI: http://asdf.com/
    Description: Asdf asdf asdf
    Version: 1
    Author: Top Quark Productions
    */

    add_action('admin_head', 'asdf');

    function asdf(){
    var_dump(current_user_can('edit_post'));
    }
    ?>

    ...then everything works fine.

    All fine and dandy, but seems like quite a hole to have a plugin be able to take down the whole shebang.

  3. Ryan Boren
    WordPress Dev
    Posted 4 years ago #

    Plugins must wait until after init before they run anything. admin_head is fired post init, which is why the current_user_can() call works there.

Topic Closed

This topic has been closed to new replies.

About this Topic