WordPress.org

Ready to get started?Download WordPress

Forums

Call to undefined function add_action() (3 posts)

  1. Frank Goossens
    Member
    Posted 3 years ago #

    (repost from plugins-forum)
    --
    I'm the author of a plugin (wp-youtube-lyte) which seems to work on the majority of installations.

    There are however a few instances where a "Call to undefined function add_action() in options.php on line 2" is generated. Indeed, options.php opens with;

    <?php
    add_action('admin_menu', 'lyte_create_menu');
    function lyte_create_menu() {
    ...

    Is there anything wrong with the code? Is there any way to work around this error? Or is this due to (mis-)configuration of the blog instance and so entirely out of my hands?

  2. Mark / t31os
    Moderator
    Posted 3 years ago #

    That's usually what happens when the file is queried directly, and not loaded via WordPress, ie..

    The page was requested like this..

    example.com/wp-content/plugins/YOUR_PLUGIN/options.php

    and not..

    example.com/wp-admin/admin.php?YOUR_PLUGIN/options.php
    or
    example.com/wp-admin/admin.php?options.php

    Depending on what your plugin page URL looks like, it may differ to the two above, but should illustrate the point nonetheless.

    Simple if( !function_exists( 'some_wordpress_function' ) ) die('Direct request message to show.'); should fix that for you ..

  3. Frank Goossens
    Member
    Posted 3 years ago #

    thanks mark, i understand now. guess putting an empty index.html in place will prevent google & others to see directory contents (for those instances where webservers are not configured to disallow directory listing), so they won't try to index the standalone options.php any more.

Topic Closed

This topic has been closed to new replies.

About this Topic