在wordpress中加载页面时,我收到以下错误。我该如何防止这种情况发生?
Notice: Undefined index: activated in /home3/answ/public_html/wp-content/themes/tipztheme/functions.php on line 582
Notice: Undefined index: preview in /home3/answ/public_html/wp-content/themes/tipztheme/functions.php on line 582
这是导致错误的第508行上的代码。508线是 if ( $_GET['activated'] == 'true' || $_GET['preview'] == 1 )
,非常感谢您的帮助!
Plugin Name: DDThemes - Logo Options
Plugin URI: http://www.designdisease.com/
*/
//ADD OPTION PAGE
add_action('admin_menu', 'ddthemes_admin');
//UPON ACTIVATION OR PREVIEWED
if ( $_GET['activated'] == 'true' || $_GET['preview'] == 1 )
{
ddthemes_setup();
}
function ddthemes_admin()
{
/* PROCESS OPTION SAVING HERE */
if ( 'save' == $_REQUEST['action'] )
{
if ( $_REQUEST['savetype'] == 'header' )
{
update_option( 'ddthemes_header', $_REQUEST['ddthemes_header']);
}
}
/* SHOW THEME CUSTOMIZE PAGE HERE */
add_theme_page(__('Logo Options'), __('Logo Options'), 'edit_themes', basename(__FILE__), 'ddthemes_headeropt_page');}
出现此错误是因为您的PHP错误报告设置。当您的变量设置不正确时,它就会出现。老实说,这不是什么大不了的事,这很好;=)为了解决这个问题,你有两个选项:选项一是在使用变量之前设置变量,并添加一些伪值,例如:
if (!isset($_REQUEST['savetype']))
{
//If not set add some dummy value
$_REQUEST['savetype'] = "undefine";
}
if ( $_REQUEST['savetype'] == 'header' )
{
update_option( 'ddthemes_header', $_REQUEST['ddthemes_header']);
}
另一个解决方案是在php.ini中修改(抑制错误报告)并插入以下行:
<?php error_reporting (E_ALL ^ E_NOTICE); ?>
另一个解决方案也是支持错误报告,但这次在wp-config.php中改为:define('WP_DEBUG', true);
添加define('WP_DEBUG', false);
有趣的是,我今天也遇到了同样的问题,第一个选择对我有效:)希望它能帮助。。。干杯