• Resolved Flo1231

    (@flo1231)


    Hello everyone

    I’m building a plugin at the moment. In the “index”-page (the one with the information about the plugin) I use require_once. When I want to activate the plugin, a fatal error is thrown:
    Plugin could not be activated because it triggered a fatal error.
    No more information is shown.

    I commented all the lines except require_once plugins_url('/php/hooks.php', __FILE__); out and checked the path. Still triggering a fatal error. The problem has to be the require_once command but I don’t know what to do about it. I have used this command in the exact same context, file and version of WordPress before and it worked back then.

Viewing 7 replies - 1 through 7 (of 7 total)
  • I think you have an extra slash.

    require_once plugins_url('php/hooks.php', __FILE__);

    Try this method Flo1231

    $plugin_url = WP_PLUGIN_URL . '/' . basename(dirname(__FILE__));
    require_once "$plugin_dir/FOLDER/FILE_NAME.php";

    Hi @a2ztechnologies,

    Actually, using any of the WordPress defined constants is never a good idea.

    1) WP_PLUGIN_URL does not take into account SSL.
    2) If the default plugins directory location is altered (for whatever reason); this will fail.

    It’s much better to use This Method.

    From the Constants Codex:

    These should not be used directly by plugins or themes, but are listed here for completeness.

    Ok Josh (WP Edit).,

    But i refer fome plugin which is WordPress approved that contains code like this (refer this one for example https://wordpress.org/plugins/iwp-client/)

    Anyway thanks for your advice

    Sure. I’m not saying it’s illegal 🙂 But somewhere along the way; those developers are going to encounter users with specific use-case scenarios; and will have to update their code.

    Example
    Example
    Example

    From the plugin you mentioned above (probably related):
    https://wordpress.org/support/topic/usage-of-iwp-client-under-serure-conditions-sftp-and-others?replies=1

    Perhaps not so much a big deal for a single user managing their own website. But for developers of themes/plugins… it’s just not a good idea.

    Thank you for your openness 🙂

    Thread Starter Flo1231

    (@flo1231)

    Josh

    As I said, I checked the URL. The output is the same, with or without the extra slash. Anyway, as the codex says plugins_url() returns the URL with a trailing slash, I’ll consider that and change my code accordingly.

    However, the error is still there.

    Thread Starter Flo1231

    (@flo1231)

    Problem solved. require_once needs a path, not an URL.

Viewing 7 replies - 1 through 7 (of 7 total)

The topic ‘Fatal error with no additional information thrown upon plugin activation’ is closed to new replies.