WordPress : Configurer une page d’option dans l’admin



Cet exemple permet d’ajouter une page d’options pour un theme wordpress.
Le fichier dois s’appeler theme-options.php et doit être placé dans le répertoire functions de votre theme.
Cet exemple est tiré du projet Pubicis-Verbe.

<?php

add_action('admin_menu','verbe_menu_page');

function verbe_menu_page(){
add_theme_page('Verbe Theme Options', 'Theme Option', 'manage_options', 'verbe-theme-option', 'verbe_setting_page');
}

add_action('admin_init', 'verbe_register_setting');

function verbe_register_setting(){

// block footer
register_setting('verbe-group', 'verbe_footer_name');
register_setting('verbe-group', 'verbe_footer_link_name');
register_setting('verbe-group', 'verbe_footer_group');
register_setting('verbe-group', 'verbe_footer_link_group');
register_setting('verbe-group', 'verbe_footer_street');
register_setting('verbe-group', 'verbe_footer_address');
//register_setting('verbe-group', 'verbe_footer_description');
}

function verbe_setting_page(){?>

<div class="wrap">
<?php screen_icon(); ?>
<h2>Verbe Setting Page</h2>
<form id="verbe_setting" method="post" action="options.php" enctype="multipart/form-data">
<?php settings_fields('verbe-group'); ?>
<?php do_settings_sections( 'verbe-group' ); ?>

<table>
<tr>
<td><h3>Block Footer</h3></td>
</tr>
<tr>
<td height="40" width="170">Company</td>
<td><input type="text" name="verbe_footer_name" value="<?php echo get_option('verbe_footer_name'); ?>" size="80" /></td>
</tr>
<tr>
<td height="40" width="170">Link Company</td>
<td><input type="text" name="verbe_footer_link_name" value="<?php echo get_option('verbe_footer_link_name'); ?>" size="80" /></td>
</tr>
<tr>
<td height="40" width="170">Group</td>
<td><input type="text" name="verbe_footer_group" value="<?php echo get_option('verbe_footer_group'); ?>" size="80" /></td>
</tr>
<tr>
<td height="40" width="170">Link Group</td>
<td><input type="text" name="verbe_footer_link_group" value="<?php echo get_option('verbe_footer_link_group'); ?>" size="80" /></td>
</tr>
<tr>
<td height="40" width="170">Street</td>
<td><input type="text" name="verbe_footer_street" value="<?php echo get_option('verbe_footer_street'); ?>" size="80" /></td>
</tr>
<tr>
<td height="40" width="170">Address</td>
<td><input type="text" name="verbe_footer_address" value="<?php echo get_option('verbe_footer_address'); ?>" size="80" /></td>
</tr>
</table>

<input type="hidden" name="update_settings" value="Y" />
<?php submit_button(); ?>
</form>
</div>
<?php
}
?>