The MU forums have moved to WordPress.org

Including files in plugins breaks site... (4 posts)

  1. saggybawlz
    Member
    Posted 14 years ago #

    When I include a file like so:

    require_once(ABSPATH . 'wp-admin/includes/admin.php');
    require_once (ABSPATH . 'wp-admin/includes/dashboard.php');

    It breaks my site, and gives me an error:

    Fatal error: Call to undefined function wp_get_current_user() in /www/websites/mysite.com/wp-includes/capabilities.php on line 926

    Also, is it good practice to use a class structure when developing a plugin? It seems to open a ton of errors..

  2. codefix3r
    Member
    Posted 14 years ago #

    If you are developing a plugin, you don't need to include WordPress core files. You instead use hooks and functions provided for you (look at the WordPress Codex for more on these).

    If you explain why you are trying to include the files, we might be able to help you find the right way to do what you are trying to do.

  3. saggybawlz
    Member
    Posted 14 years ago #

    The problems arise only when I use a class structure to develop a plugin. For example, lets say I want to create a widget on the dashboard.

    wp_add_dashboard_widget('widgetId', __('Title'), $this->widgetContent());

    Two problems here. First off, I would get an unknown function error on wp_add_dashboard_widget() function. Second, I would call widgetContent() function like this: $this->widgetContent(), and it would throw an error saying first parameter should be a valid call back. I need to write out the parameters like this only.

    wp_add_dashboard_widget('widgetId', __('Title'), 'widgetContent');

    I took everything out of the class, now it all works properly. So I guess using a class is a bad idea. It would be great if I could extend some wp class and access to all the functions.

  4. DeannaS
    Member
    Posted 14 years ago #

    Using classes in your plugins is a good idea. You're probably just not setting the globals that you need inside the class or something. Hard to debug without more information. But, there shouldn't be anything you can do outside a class that you can't do inside a class if you're using it correctly.

About this Topic

  • Started 14 years ago by saggybawlz
  • Latest reply from DeannaS