Advertisement
Guest User

wp plugin settings

a guest
Jul 4th, 2012
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.58 KB | None | 0 0
  1.         // === ADMIN OPTIONS === //
  2.         // add the options page under Settings
  3.         function admin_page() {
  4.             add_options_page('Exifography Options', 'Exifography Options', 'manage_options', 'exifography', array( &$this, 'options_page' ));
  5.         }
  6.        
  7.         // render the admin page
  8.         function options_page() {
  9.         ?>
  10. <div>
  11.     <h2><?php _e('Exifography Options', 'exifography'); ?></h2>
  12.     <p><?php _e('For instructions and support please visit the <a target="_blank" href="http://www.kristarella.com/thesography">Thesography plugin page</a>.', 'thesography'); ?></p>
  13.     <form action="options.php" method="post">
  14.     <?php settings_fields($this->exif_options); ?>
  15.     <?php do_settings_sections('plugin_options'); ?>
  16.    
  17.     <input name="Submit" type="submit" value="<?php esc_attr_e('Save Changes'); ?>" />
  18.     </form>
  19. </div>
  20.         <?php
  21.         }
  22.        
  23.         // add the admin settings to the database and page
  24.         function options_init(){
  25.             register_setting( $this->exif_options, $this->exif_options, array(&$this,'options_validate') );
  26.             add_settings_section('default_display', __('Default EXIF', 'exifography'), array(&$this,'defaults'), 'plugin_options');
  27.             add_settings_section('auto_display', __('Auto insert into post', 'exifography'), array(&$this,'auto'), 'plugin_options');
  28.             add_settings_section('custom_html', __('Custom HTML', 'exifography'), array(&$this,'html'), 'plugin_options');
  29.             // exif fields settings inputs
  30.             foreach ($this->fields as $key => $value) {
  31.                 add_settings_field('exif-field-'.$key, $value, array(&$this,'default_fields'), 'exifography', 'default_display', $key);
  32.             }
  33.             // auto insert settings fields
  34.             add_settings_field('auto_insert', __('Automatically display exif','exifography'), array(&$this,'auto_field'), 'exifography', 'auto_display');
  35.             // custom HTML settings fields
  36.             foreach ($this->html_options as $key => $value) {
  37.                 add_settings_field($key, $value, array(&$this,'html_fields'), 'exifography', 'custom_html', $key);
  38.             }
  39.            
  40.             wp_enqueue_style( 'exif_admin_style', WP_PLUGIN_URL . '/' . str_replace(basename( __FILE__),"",plugin_basename(__FILE__)) . 'styles/admin.css' );
  41.         }
  42.        
  43.         // render options sections
  44.         function defaults() {
  45. ?>
  46. <p><?php _e("Set these to create default options for every post. This is useful when <strong>most</strong> of your posts will be displaying EXIF for <strong>a single photo</strong>, and if you're not adding EXIF manually via shortcodes or custom functions.", 'exifography'); ?></p>
  47. <?php
  48.         }
  49.         function auto() {
  50. ?>
  51. <p><?php _e("Use this option to automatically insert the EXIF for the first image attached to your post.", 'exifography'); ?></p>
  52. <?php  
  53.         }
  54.         function html() {
  55. ?>
  56. <p><?php _e('This is the HTML used to display your exif data. IDs and classes can be used for styling.', 'thesography'); ?></p>
  57. <?php
  58.         }
  59.        
  60.         // render inputs
  61.         function default_fields($key) {
  62.             $options = $this->get_options();
  63.             print_r($options);
  64.             if(strpos($options['exif_fields'], $key) !== false)
  65.                 $checked = 'checked="checked"';
  66.             echo '<input id="exif-field-'.$key.'" value="'.$key.'" type="checkbox" name="exif_fields[]" '.$checked.' />';
  67.         }
  68.         function auto_field() {
  69.             $options = $this->get_options();
  70.             if($options['auto_insert'])
  71.                 $checked = 'checked="checked"';
  72.             echo '<input id="auto_insert" type="checkbox" name="auto_insert" '.$checked.' />';
  73.         }
  74.         function html_fields($key) {
  75.             $options = $this->get_options();
  76.             echo '<input type="text" id="'.$key.'" name="'.$key.'" value="'.stripslashes($options[$key]).'" class="regular-text code" />';
  77.         }
  78.        
  79.         // validate options
  80.         function options_validate($inputs) {
  81.             return $inputs;
  82.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement