hello i have the next error in an admin option and the line of code is the next one. can you please help me ?

[11-Sep-2021 12:02:43 UTC] PHP Fatal error: Uncaught Error: Call to a member function atp_variable() on null in /var/www/vhosts//theme-options.php:858 Stack trace: #0 /var/www/vhosts/insect.gr/httpdocs/wp-includes/class-wp-hook.php(303): atp_options() #1 /var/www/vhosts/insect.gr/httpdocs/wp-includes/class-wp-hook.php(327): WP_Hook->apply_filters() #2 /var/www/vhosts/insect.gr/httpdocs/wp-includes/plugin.php(470): WP_Hook->do_action() #3 /var/www/vhosts/insect.gr/httpdocs/wp-settings.php(578): do_action() #4 /usr/local/psa/admin/plib/modules/wp-toolkit/vendor/wp-cli/vendor/wp-cli/wp-cli/php/WP_CLI/Runner.php(1291): require('/var/www/vhosts...') #5 /usr/local/psa/admin/plib/modules/wp-toolkit/vendor/wp-cli/vendor/wp-cli/wp-cli/php/WP_CLI/Runner.php(1212): WP_CLI\Runner->load_wordpress() #6 /usr/local/psa/admin/plib/modules/wp-toolkit/vendor/wp-cli/vendor/wp-cli/wp-cli/php/WP_CLI/Bootstrap/LaunchRunner.php(23): WP_CLI\Runner->start() #7 /usr/local/psa/admin/plib/modules/wp-toolkit/vendor/wp-cli/ve in /var/www/vhosts//theme-options.php on line 858

        $iva_of_options[] = array(
        'name'    => 'Select Slider Type',
        'desc'    => 'Select which slider you want to use for the Frontpage of the theme.',
        'id'      => $shortname . '_slider',
        'std'     => 'flexslider',
        'class'   => 'select300',
        'type'    => 'select',
        'options' => $atp_theme->atp_variable( 'slider_type' ),

the whole code is here codeshare.io/zyXYA7

  • What is $atp_theme, did you declare it somewhere. You get the error because you try to call a method, but the variable is not a object, it doesn't seem like it was set at all Sep 11, 2021 at 10:53
  • in the first of line code i have global $iva_of_options, $shortname, $atp_theme; that you mean ? Sep 11, 2021 at 10:55
  • could you show the whole function? it seems like the variable doesn't contain the class instance, so naturally it will not have any methods you can call. The code you added to the question, which is off topic if I'm not mistaken, is not enough to help you with the problem. Sep 11, 2021 at 11:00
  • my all code is here codeshare.io/zyXYA7 Sep 11, 2021 at 11:05
  • i have in other php file the $atp_theme = new ATP_theme(); that you mean ? Sep 11, 2021 at 11:28

1 Answer 1


The error message in your question appears to have been thrown from WP CLI. Based on your other comments the problem is that your theme is not properly declaring a global variable.

Somewhere in your code you have this declared outside a function:

$atp_theme = new ATP_theme();

Then in other parts of your code you have:

global $atp_theme;

When using WordPress via the browser, variables declared outside a function, like $atp_theme in that first line, are global. So you can access them by using global, like in the second line.

The problem is that when using WP CLI, variables declared outside a function are not automatically global. Therefore global $atp_theme is undefined.

To solve this you need to explicitly declare the variable as global when defining it, like this:

global $atp_theme;

$atp_theme = new ATP_theme();

Or this would also work:

$GLOBALS['atp_theme'] = new ATP_theme();
  • maybe the problem is i have 2 $atp_theme in diferent php files one is $atp_theme = new ATP_theme_pest(); and $atp_theme = new ATP_theme(); maybe that confict ? Sep 11, 2021 at 12:22
  • Only if they’re both declared as global. But even then the only reason either would be null is because if the issue I described. A conflict would result in a different error. But look, if you didn’t develop this theme yourself you need to speak to the author. Sep 11, 2021 at 14:09
  • so i have already in functions.php $atp_theme = new ATP_Theme(); and when i add it to declare to the theme-options.php it shows up many errors ??? Sep 21, 2021 at 10:15
  • I never said to do that in my answer. Please read my answer. I have nothing to add. Sep 21, 2021 at 10:51
  • i change the declaration with $GLOBALS['atp_theme'] = new ATP_theme(); or global $atp_theme; $atp_theme = new ATP_theme(); but the error is still there on null Sep 21, 2021 at 12:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.