Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I've got an issue in which my theme's save options routine is being called when a plugin options page (contact form 7) is being saved. This throws an error that points to my "for each" loop inside my theme options save.

Am I doing something wrong here?

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'], "");}
                }
            }
        }
}
share|improve this question
add comment

1 Answer 1

up vote 2 down vote accepted

maybe you have to change the structure of your theme options page and use add_theme_page() to avoid this type of problems

/* 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
    }
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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