0

我知道很多关于此的问题,我尝试阅读,但在我的 Wordpress 上仍然收到此错误消息:

“从第 225 行 /home/forthemde/public_html/wp-content/themes/mayadeep/admin/admin.php 中的空值创建默认对象”

这里的代码admin.php和:

 function upfw_setup_theme_options(){
     $up_options_db = get_option('up_themes_'.UPTHEMES_SHORT_NAME);
     global $up_options;
     //Check if options are stored properly
     if( isset($up_options_db) && is_array($up_options_db) ):
         //Check array to an object
         foreach ($up_options_db as $k => $v) {
                 $up_options -> {$k} = $v;
         }
     else:
         do_action('upfw_theme_activation');
     endif;
 }
 add_action('upfw_theme_init','upfw_setup_theme_options',10);
 add_action('upfw_admin_init','upfw_setup_theme_options',100);

第 225 行在这里:

 $up_options -> {$k} = $v;

我尝试自己修复,但没有结果。请帮助我,非常感谢您的帮助。

问候。

4

1 回答 1

0

此错误是因为global $up_options未定义全局对象。

尝试var_dump $up_options,它可能为空。

还要检查您是否正确拼写了变量名。

运行此代码,并检查输出:

function upfw_setup_theme_options(){
     $up_options_db = get_option('up_themes_'.UPTHEMES_SHORT_NAME);
     global $up_options;

 $up_options = new stdClass();

     //Check if options are stored properly
     if( isset($up_options_db) && is_array($up_options_db) ):
         //Check array to an object
         foreach ($up_options_db as $k => $v) {
                 $up_options -> {$k} = $v;
         }
     else:
         do_action('upfw_theme_activation');
     endif;
 }
 add_action('upfw_theme_init','upfw_setup_theme_options');
 add_action('upfw_admin_init','upfw_setup_theme_options');
于 2013-09-17T23:58:18.203 回答