Call to undefined function add_options_page()

I developed the plugin for my wordpress project. I successfully tested it on my local xampp server with 5.3 php. Then I uploaded my project to the web hosting with php 5.2. First trouble which with I faced off was unsupporting anonymous functions in php 5.2. No issue, I redeclared all functions with names. But then I got error Call to undefined function add_options_page(), which I counldn’t explain. Plz help me guys with your advices

My part of code:

Read More
function mainPage(){
        ///some code
        }

function mainPage2(){

    add_options_page('Submissions of MAIN page contact form', 'Submissions of MAIN page contact form', 'manage_options','ea_submissions2', mainPage());

    }
add_action('admin_menu',mainPage2());

I think something wrong with my funcitons, look through it please.
There is no issue with php 5.2 as I thought, this part of code also doesn’t work with php 5.3! Something wrong with my code

Related posts

Leave a Reply

5 comments

  1. I had a similar problem, turns out I was running a function too early:

    Use admin_init hook instead of init

    Hopefully that helps someone out 😀

  2. This doesn’t work because you have normal function not wrapped in a class, and because add_options_page does not work yet by that time that is why you get the error.

    A fix would be to use an anonymous function in the add action call, but hence that does not work on php 5.2.

    So long story short, this is fixable though, but you shouldn’t run php 5.2 anymore in the first place. PHP 5.5 is already in development and 5.3 is facto standard these days. A solution is to ask your hosting company to upgrade php to at least 5.3 so that you can use anonymous functions and you can hook it to the add action call.

    Or, wrap it all in a class and on the admin init function create the new class.

  3. Aware that this is an old question, this is your problem:

    add_action('admin_menu',mainPage2());
    

    Here you are invoking the mainPage2() function and adding the return value of that function as an argument to the add_action method.

    You should do

    add_action('admin_menu', 'mainPage2');
    

    This way, the mainPage2 function will be called when admin_menu happens.