我遇到了一个问题,在保存插件选项页面(联系表单7)时,我的主题的保存选项例程被调用。这会引发一个错误,指向我的主题选项保存中的“for each”循环。
我做错什么了吗?
add_action(\'admin_menu\', \'mytheme_admin\');
/* ADMIN PANEL
**********************************/
function mytheme_admin()
{
global $themename, $shortname, $options;
if (isset($_REQUEST[\'action\']) && \'save\' == $_REQUEST[\'action\'])
{
foreach ($options as $value)
{
if( isset( $value[\'id\'] ) && isset( $_REQUEST[$value[\'id\']] ) )
{
update_option( $value[\'id\'], stripslashes($_REQUEST[$value[\'id\']]) );
}
else
{
if(isset($value[\'id\'])) {update_option( $value[\'id\'], "");}
}
}
}
}
最合适的回答,由SO网友:Tribalpixel 整理而成
也许你必须改变主题选项页面的结构并使用add_theme_page() 避免此类问题
/* REGISTER THEME OPTION PAGE */
if ( ! function_exists( \'RMH_admin_menu\' ) ):
function RMH_admin_menu() {
global $theme_name;
add_theme_page( \'Opções para o tema \'.$theme_name, \'Temas Opções\', \'edit_theme_options\', \'RMH-theme-options\', \'RMH_theme_options\' );
}
add_action( \'admin_menu\', \'RMH_admin_menu\' );
endif;
/* DISPLAY PAGE OPTIONS*/
function RMH_theme_options() {
global $theme_name;
?>
<div class="wrap">
<div><br></div>
<h2>Opções para o tema <span class="theme-option-name"><?php echo $theme_name; ?><span></h2>
<form method="post" action="options.php">
<?php wp_nonce_field( \'update-options\' ); ?>
<?php settings_fields( \'RMH-theme-options\' ); ?>
<?php do_settings_sections( \'RMH-theme-options\' ); ?>
<?php submit_button(); ?>
</form>
</div>
<?php
}