• Hy,

    I’m trying to do a page option for my theme, who allow user to display a text in the home page.

    Code:

    <?php
    
    add_action('admin_menu' , 'theme_options');
    
    // FUNCTION THEME OPTIONS ////////////////////////////////////////////////////
    //////////////////////////////////////////////////////////////////////////////
    function theme_options()
    {
    	// à l'initialisation de l'administration
    	// on informe WordPress des options de notre thème
    	register_setting( 'my_theme', 'quick_description' ); // Quick description
    
    	// ADD MENU ///////////////////////////////////////////////////////////////
    	///////////////////////////////////////////////////////////////////////////
    	add_menu_page(
    		'Options du thème', // Page title
    		'Options', // Page name in Admin MENU
    		'administrator',   // le rôle d'utilisateur requis pour voir cette page
    		'theme-options-page',  // Unique page ID
    		'pageOptionsDesciption'   // Function name
    	);
    
    	// SUB MENU ///////////////////////////////////////////////////////////////
    	///////////////////////////////////////////////////////////////////////////
    	add_submenu_page(
    		'theme-options-page', // Parent Menu
    		'Description', // Page title
    		'Description', // Page name in Admin MENU
    		'administrator',   // le rôle d'utilisateur requis pour voir cette page
    		'theme-options-page',  // Unique page ID
    		'pageOptionsDesciption'   // Function name
    	);
    
    }
    
    // FUNCTION DESCRIPTION ///////////////////////////////////////////////////////////////////////////
    ///////////////////////////////////////////////////////////////////////////////////////////////////
    function pageOptionsDesciption(){
    	// Check that the user is allowed to update options
    	if (!current_user_can('manage_options')) {
    	    wp_die('You do not have sufficient permissions to access this page.');
    	}
    	else
    	{			
    
    		if(isset($_GET['settings-updated']))
    		{
    
    			// DATA processing ///////////////////////////////////////////////////////
    			//////////////////////////////////////////////////////////////////////////
    			$name_option = 'quick_description';
    			$post_value = $_POST[$name_option];
    
    			if(empty($post_value)){
    				delete_option($name_option);
    			}
    			else{
    				update_option($name_option, $value);
    			}
    			// MESSAGE////////////////////////////////////////////////////////////////
    			//////////////////////////////////////////////////////////////////////////
    			?><div  class="updated fade"><p><strong>Saved</strong></p></div><?php
    
    		}
    
    		// DISPLAY PAGE //////////////////////////////////////////////////////////////
    		//////////////////////////////////////////////////////////////////////////////
    		?>
    			<div class="wrap">
    				<h2>Options</h2>
    				<hr/>
    
    				<form method="POST" action="options.php">
    					<?php
    
    						settings_fields( 'my_theme' );
    					?>
    
    					<h3>Rapide description sur la page d'accueil du site</h3>
    					<table class="form-table">
    						<tr>
    							<td style="padding:0;" >
    								<textarea id="quick_description" name="quick_description" rows="10" cols="100%"><?php echo get_option( 'quick_description' ,'Ici votre rapide description'); ?></textarea>
    							</td>
    						</tr>
    					</table>
    
    					<p class="submit">
    						<input type="submit"  class="button-primary" value="update" />
    					</p>
    				</form>
    			</div>
    		<?php
    	}
    
    }

    The problem is that the fonction save nothing in the Data base.
    I don’t know where is my mistake.

    Thanks in advance for your help.

The topic ‘Theme option problem’ is closed to new replies.