• Resolved topquarkproductions

    (@topquarkproductions)


    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: https://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.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter topquarkproductions

    (@topquarkproductions)

    RESOLVED:

    If I change the code in the plugin to:

    <?php
    /*
    Plugin Name: Asdf
    Plugin URI: https://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.

    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.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Why does calling current_user_can() crash WP 2.9.2?’ is closed to new replies.