1. <?php
  2.  
  3. /**
  4.  * @author Frank
  5.  * @copyright 2012
  6.  */
  7.  function imagements_admin_add_page(){
  8.     add_options_page('imagements options menu', 'imagements', 'manage_options', 'imagements', 'imagements_menu_options');
  9.  }
  10.  
  11. function imagements_admin_init(){
  12. add_settings_section('imagements_main', 'imagements ', 'imagements_section_text', 'imagements');
  13. register_setting('option_width', 'max_width', 'imagements_options_validate' );
  14. register_setting('option_height', 'max_height', 'imagements_options_validate' );
  15. add_settings_field('option_width', 'max_width', 'imagements_option_width', 'imagements', 'imagements_main');
  16. add_settings_field('option_height', 'max_height', 'imagements_option_height', 'imagements', 'imagements_main');
  17. }
  18.  
  19. function imagements_options_validate($input){
  20.     if(! is_numeric($input['max_width'])){
  21.         $input['max width'] = 300;
  22.     }
  23.     if(! is_numeric($input['max_height'])){
  24.         $input['max_height'] = 300;
  25.     }
  26. return $input;
  27. }
  28.  
  29. function imagements_option_width(){
  30.     $option = get_option('max_width');
  31.     echo "<input id='max_width' name='imagements_options[max_width]' size='40' type='text' value='$option' />";
  32. }
  33.  
  34. function imagements_option_height(){
  35.     $option = get_option('max_height');
  36.     echo "<input id='max_height' name='imagements_options[max_height]' size='40' type='text' value='$option' />";
  37.    
  38. }
  39.  
  40. function imagements_section_text(){
  41.     echo __('<p>here you can set the settings of the imagements plugin</p>');    
  42. }
  43.  
  44. function imagements_menu_options()
  45. {
  46.  
  47. ?>
  48. <div class="wrap">
  49. <h2>imagements options</h2>
  50. <form method="post" action="options.php">
  51. <?php
  52.  
  53.     settings_fields('option_width');
  54.     settings_fields('option_height');
  55.     do_settings_sections('imagements');
  56.  
  57. ?>
  58.     <input name="Submit" type="submit" value="<?php
  59.     $buttontext = __('Save Changes');
  60.     esc_attr_e($buttontext);
  61.  
  62. ?>" />
  63. </form>
  64. </div>
  65. <?php
  66.  
  67. }
  68.  
  69. ?>