Bumped by Community user
    Bumped by Community user
4 deleted 2050 characters in body; edited title
source | link

Problem when adding a custom theme options Theme option page doesn't save options

I am trying to practice adding theme options page using settings API but unfortunately the code i have written according to the codex doesn't work properly. When i tested the code no errors generated and i still can savebut the pe_logope_bannar_heading option field while can't with the other options like pe_color_scheme and pe_bannar_headingbe saveed , So would you please help me find where the problem is in the following code

<?php
  /*
  Plugin Name: PE Theme Options 2<?php
  Plugin URI: https://prosentra.com*
  Description:  Adds a theme Option page
 Plugin VersionName: 1.0.0
  Author:Test Mohammadoption Omarpage
  Author URI: https://prosentra.com
  Text Domain: pe-themetest-optionsoption-2page
  License: GPL2
  */

  $options = get_option('pe_theme_options');

  function reg_settings(){
        register_setting('pe_theme_options','pe_theme_options', 'pe_validate_settings');
        add_settings_section('pe_main_settings','Main Settings', 'pe_main_settings_cb''', __FILE__);
add_settings_field('pe_bannar_heading', 'Bannar Heading:', 'pe_bannar_heading_setting', __FILE__, 'pe_main_settings');
add_settings_field('pe_logo', 'Your Logo:', 'pe_logo_setting', __FILE__, 'pe_main_settings');
add_settings_field('pe_color_scheme''pe_bannar_heading', 'Your Desired'Bannar ColorHeading:', 'pe_color_scheme_setting''pe_bannar_heading_setting', __FILE__, 'pe_main_settings');
 }

 add_action('admin_init','reg_settings');

 function pe_validate_settings($plugin_options){
    global $options;
        if(!empty($_FILES['pe_logo_upload']['tmp_name'])){}

                $overide = array('test_form' => false);
                $file = wp_handle_uploadadd_action($_FILES['pe_logo_upload']'admin_init', $overide'reg_settings');
                $plugin_options['pe_logo'] = $file['url'];  
       function }elseif(issetpe_bannar_heading_setting($options['pe_logo'])){
                $plugin_options['pe_logo'] = $options['pe_logo'];
        }else{
            $plugin_options = '';
        }
            return $plugin_options;


    }

  $options function= pe_main_settings_cbget_option('pe_theme_options'){
        //Optional;?>
    }

    function pe_bannar_heading_setting(){ global $options;?>
        <input name="pe_bannar_heading" type="text" value="<?php  if(isset($options['pe_bannar_heading'])) echo $options['pe_bannar_heading'] ?>" />
    <?php }

   function pe_logo_setting(){
    global $options;
        echo "<input type='file' name='pe_logo_upload'><br><br>";
        if(isset($options['pe_logo'])){ ?>
            <img src="<?php echo $options['pe_logo'] ?>" alt="" height="150 px" width ="150 px">

            <?php  }else{
                //
                }
    }

  function pe_color_scheme_settingpe_add_menu_page(){
        global $options;
       add_options_page('Theme $itemsOptions', ='Theme array('Red'Options', 'Black''administrator', 'Yellow'__FILE__ , 'display_options_page');
        echo '<select name="pe_color_scheme">';
     }

   foreach add_action($items as $item'admin_menu','pe_add_menu_page'){;
        
    function if(issetdisplay_options_page($options['pe_color_scheme'])){ 

             $selected = ($options['pe_color_scheme'] ===$options $item= get_option('pe_theme_options') ;? 'selected="selected"' : '';
            }else{>
                $selected =<div '';class="wrap">
            }
          <h2>Yellow Blog ?>Options</h2>
            <option value="<?php echo $item ;?>" <?php echo $selected; ?>><?php<form echoaction="options.php" $itemmethod="post" ;?><enctype="multipart/option>form-data">
        <?php   }
        echo '</select>';
    }

function display_options_page(){
   global $options;<?>
        <divphp class="wrap">
            <h2>Yellow Blog Options</h2>
            <form action="options.php" method="post" enctype="multipart/form-data">settings_fields('pe_theme_options');
                <?php 
                    settings_fieldsdo_settings_sections('pe_theme_options'__FILE__);
                    do_settings_sections(__FILE__);
                    submit_button( 'Save Settings' );
                    print_r($options) ;
                ?>
            </form>
        </div>  
<?php   }
form>
    function pe_add_menu_page(){
        add_options_page('Theme Options', 'Theme Options', 'administrator', __FILE__</div> , 'display_options_page');
    }
 <?php  add_action('admin_menu','pe_add_menu_page');


 ?>}

Problem when adding a custom theme options page

I am trying to practice adding theme options page using settings API but unfortunately the code i have written according to the codex doesn't work properly. When i tested the code no errors generated and i still can save the pe_logo option field while can't with the other options like pe_color_scheme and pe_bannar_heading , So would you please help me find where the problem is in the following code

<?php
  /*
  Plugin Name: PE Theme Options 2
  Plugin URI: https://prosentra.com
  Description:  Adds a theme Option page
  Version: 1.0.0
  Author: Mohammad Omar
  Author URI: https://prosentra.com
  Text Domain: pe-theme-options-2
  License: GPL2
  */

  $options = get_option('pe_theme_options');

  function reg_settings(){
      register_setting('pe_theme_options','pe_theme_options', 'pe_validate_settings');
add_settings_section('pe_main_settings','Main Settings', 'pe_main_settings_cb', __FILE__);
add_settings_field('pe_bannar_heading', 'Bannar Heading:', 'pe_bannar_heading_setting', __FILE__, 'pe_main_settings');
add_settings_field('pe_logo', 'Your Logo:', 'pe_logo_setting', __FILE__, 'pe_main_settings');
add_settings_field('pe_color_scheme', 'Your Desired Color:', 'pe_color_scheme_setting', __FILE__, 'pe_main_settings');
 }

 add_action('admin_init','reg_settings');

 function pe_validate_settings($plugin_options){
    global $options;
        if(!empty($_FILES['pe_logo_upload']['tmp_name'])){

                $overide = array('test_form' => false);
                $file = wp_handle_upload($_FILES['pe_logo_upload'], $overide);
                $plugin_options['pe_logo'] = $file['url'];  
        }elseif(isset($options['pe_logo'])){
                $plugin_options['pe_logo'] = $options['pe_logo'];
        }else{
            $plugin_options = '';
        }
            return $plugin_options;


    }

   function pe_main_settings_cb(){
        //Optional
    }

    function pe_bannar_heading_setting(){ global $options;?>
        <input name="pe_bannar_heading" type="text" value="<?php  if(isset($options['pe_bannar_heading'])) echo $options['pe_bannar_heading'] ?>" />
    <?php }

   function pe_logo_setting(){
    global $options;
        echo "<input type='file' name='pe_logo_upload'><br><br>";
        if(isset($options['pe_logo'])){ ?>
            <img src="<?php echo $options['pe_logo'] ?>" alt="" height="150 px" width ="150 px">

            <?php  }else{
                //
                }
    }

  function pe_color_scheme_setting(){
        global $options;
        $items = array('Red', 'Black', 'Yellow');
        echo '<select name="pe_color_scheme">';
        foreach ($items as $item){
            if(isset($options['pe_color_scheme'])){
             $selected = ($options['pe_color_scheme'] === $item ) ? 'selected="selected"' : '';
            }else{
                $selected = '';
            }
            ?>
            <option value="<?php echo $item ;?>" <?php echo $selected; ?>><?php echo $item ;?></option>
        <?php   }
        echo '</select>';
    }

function display_options_page(){
   global $options;?>
        <div class="wrap">
            <h2>Yellow Blog Options</h2>
            <form action="options.php" method="post" enctype="multipart/form-data">
                <?php 
                    settings_fields('pe_theme_options');
                    do_settings_sections(__FILE__);
                    submit_button( 'Save Settings' );
                    print_r($options) ;
                ?>
            </form>
        </div>  
<?php   }

    function pe_add_menu_page(){
        add_options_page('Theme Options', 'Theme Options', 'administrator', __FILE__ , 'display_options_page');
    }
   add_action('admin_menu','pe_add_menu_page');


 ?>

Theme option page doesn't save options

I am trying to practice adding theme options page using settings API but unfortunately the code i have written according to the codex doesn't work properly. When i tested the code no errors generated but the pe_bannar_heading option can't be saveed , So would you please help me find where the problem is in the following code

    <?php
    /*
    Plugin Name: Test option page
    Text Domain: test-option-page
    */

    function reg_settings(){
        register_setting('pe_theme_options','pe_theme_options');
        add_settings_section('pe_main_settings','Main Settings', '', __FILE__);
        add_settings_field('pe_bannar_heading', 'Bannar Heading:', 'pe_bannar_heading_setting', __FILE__, 'pe_main_settings');
    }

    add_action('admin_init','reg_settings');

    function pe_bannar_heading_setting(){ 

                $options = get_option('pe_theme_options');?>
                <input name="pe_bannar_heading" type="text" value="<?php if(isset($options['pe_bannar_heading'])) echo $options['pe_bannar_heading'] ?>"/>

            <?php }

    function pe_add_menu_page(){
                add_options_page('Theme Options', 'Theme Options', 'administrator', __FILE__ , 'display_options_page');
            }

    add_action('admin_menu','pe_add_menu_page');
 
    function display_options_page(){ 

                $options = get_option('pe_theme_options');?>
                <div class="wrap">
                    <h2>Yellow Blog Options</h2>
                    <form action="options.php" method="post" enctype="multipart/form-data">
                        <?php 
                            settings_fields('pe_theme_options');
                            do_settings_sections(__FILE__);
                            submit_button( 'Save Settings' );
                        ?>
                    </form>
                </div>  
    <?php   }
3 added 3 characters in body
source | link
2 edited tags
| link
1
source | link