Advertisement
Guest User

Options Page - Me being bad at WP Settings API

a guest
Jun 12th, 2013
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 8.53 KB | None | 0 0
  1. <?php
  2. class vegas{
  3.     public function __construct(){
  4.         if(is_admin()){
  5.         add_action('admin_menu', array($this, 'vegas_add_settings_page'));
  6.         add_action('admin_init', array($this, 'page_init'));
  7.     }
  8.     }
  9.  
  10.   public function vegas_add_settings_page(){
  11.       add_submenu_page('edit.php?post_type=vegasslider', 'Custom Vegas Settings', 'Settings', 'edit_posts', basename(__FILE__), array($this, 'create_vegas_admin_page'));  
  12.         add_action('admin_menu', 'vegas_add_settings_page'); // add the admin options page
  13.  
  14.    }
  15.  public function create_vegas_admin_page(){
  16.         ?>
  17.     <div class="wrap">
  18.         <?php screen_icon(); ?>
  19.         <h2>Vegas Settings</h2>        
  20.         <form method="post" action="options.php">
  21.             <?php
  22.                     // This prints out all hidden setting fields
  23.             settings_fields('vegas_option_group'); 
  24.             do_settings_sections('vegas-setting-admin');
  25.         ?>
  26.             <?php submit_button(); ?>
  27.         </form>
  28.     </div>
  29.     <?php
  30.     }
  31.    
  32.     public function page_init(){       
  33.     register_setting('vegas_option_group', 'fade_key', array($this, 'check_fade'));
  34.   register_setting('vegas_option_group', 'delay_key', array($this, 'check_delay'));
  35.   register_setting('vegas_option_group', 'overlay_key', array($this, 'check_overlay'));
  36.   register_setting('vegas_option_group', 'title_key', array($this, 'check_title'));
  37.   register_setting('vegas_option_group', 'arrows_key', array($this, 'check_arrows'));
  38.   register_setting('vegas_option_group', 'autoplay_key', array($this, 'check_autoplay'));
  39.   register_setting('vegas_option_group', 'global_key', array($this, 'check_global'));
  40.   register_setting('vegas_option_group', 'id_key', array($this, 'check_id'));
  41.        
  42.   add_settings_section(
  43.         'setting_section_id',
  44.         'Setting',
  45.         array($this, 'print_section_info'),
  46.         'vegas-setting-admin'
  47.     ); 
  48.        
  49.     add_settings_field(
  50.         'Fade',
  51.       'Fade (milliseconds):',
  52.         array($this, 'fade_field'),
  53.         'vegas-setting-admin',
  54.         'setting_section_id'           
  55.     );
  56.   add_settings_field(
  57.         'Delay',
  58.       'Delay (milliseconds):',
  59.         array($this, 'delay_field'),
  60.         'vegas-setting-admin',
  61.         'setting_section_id'           
  62.     );
  63.   add_settings_field(
  64.         'Overlay',
  65.       'Overlay (Full Image URL):',
  66.         array($this, 'overlay_field'),
  67.         'vegas-setting-admin',
  68.         'setting_section_id'           
  69.     );
  70.   add_settings_field(
  71.         'Title',
  72.       'Title:',
  73.         array($this, 'title_field'),
  74.         'vegas-setting-admin',
  75.         'setting_section_id'           
  76.     );
  77.   add_settings_field(
  78.         'Arrows',
  79.       'Display Arrows:',
  80.         array($this, 'arrows_field'),
  81.         'vegas-setting-admin',
  82.         'setting_section_id'           
  83.     );
  84.   add_settings_field(
  85.         'Autoplay',
  86.       'Autoplay:',
  87.         array($this, 'autoplay_field'),
  88.         'vegas-setting-admin',
  89.         'setting_section_id'           
  90.     );
  91.   add_settings_field(
  92.         'Global',
  93.       'Global (Adds the slider to every page/post):',
  94.         array($this, 'global_field'),
  95.         'vegas-setting-admin',
  96.         'setting_section_id'           
  97.     );
  98.   add_settings_field(
  99.         'Id',
  100.       'Slider ID (specific to the slider you want to use):',
  101.         array($this, 'id_field'),
  102.         'vegas-setting-admin',
  103.         'setting_section_id'           
  104.     );
  105.     }
  106.    
  107.     public function check_fade($input){
  108.      
  109.         if( isset($input['Fade'])){$Fade = $input['Fade'];}
  110.            
  111.         if( !isset($Fade['Fade']) && isset($input['Fade']) && is_numeric($input['Fade'])){     
  112.         if(get_option('fade') === FALSE){
  113.         add_option('fade', $Fade);
  114.         }else{
  115.         update_option('fade', $Fade);
  116.         }
  117.     }else{
  118.         $Fade = '';
  119.     }
  120.     return $Fade;
  121.     }
  122.  
  123.   public function check_delay($input){
  124.    
  125.     if( isset($input['Delay'])){$Delay = $input['Delay'];}
  126.    
  127.             if( !isset($Delay['Delay']) && isset($input['Delay']) && is_numeric($input['Delay'])){
  128.                 if(get_option('delay') === FALSE){
  129.         add_option('delay', $Delay);
  130.         }else{
  131.         update_option('delay', $Delay);
  132.         }
  133.     }else{
  134.         $Delay = '';
  135.     }
  136.     return $Delay;
  137.     }
  138.  
  139. public function check_overlay($input){
  140.  
  141.   if( isset($input['Overlay'])){$Overlay = $input['Overlay'];   }
  142.  
  143.           if(!isset($Overlay['Overlay']) && isset($input['Overlay']) &&!is_numeric ($input['Overlay'])){               
  144.         if(get_option('overlay') === FALSE){
  145.         add_option('overlay', $Overlay);
  146.         }else{
  147.         update_option('overlay', $Overlay);
  148.         }
  149.     }else{
  150.         $Overlay = '';
  151.     }
  152.     return $Overlay;         
  153.       }
  154.  
  155.   public function check_title($input){
  156.    
  157.     if( isset($input['Title'])){$Title = $input['Title'];   }
  158.    
  159.           if(!isset($Title['Title']) && isset($input['Title']) && !is_numeric ($input['Title'])){              
  160.         if(get_option('title') === FALSE){
  161.         add_option('title', $Title);
  162.         }else{
  163.         update_option('title', $Title);
  164.         }
  165.     }else{
  166.         $Title = '';
  167.     }
  168.     return $Title;       
  169.       }
  170.    
  171.    public function check_arrows($input){
  172.      
  173.    if( isset($input['Arrows'])){$Arrows = $input['Arrows'];     }
  174.      
  175.    
  176.    if ( !isset( $Arrows['arrows'] ) ) {
  177.      $Arrows = 0;
  178.      add_option('arrows', $Arrows);
  179.    }
  180.          
  181.     if ( $input['Arrows'] == 1 ) {
  182.         $Arrows = 1;
  183.       update_option('arrows', $Arrows);
  184.     } else {
  185.         $Arrows = 0;
  186.       update_option('arrows', $Arrows);
  187.     }
  188.    return $Arrows;
  189. }
  190.  
  191.    public function check_autoplay($input){
  192.      
  193.     if( isset($input['Autoplay'])){$Autoplay = $input['Autoplay'];  }
  194.      
  195.     if ( $input['Autoplay'] == 1 ) {
  196.         $Autoplay = 1;
  197.       update_option('autoplay', $Autoplay);
  198.     } else {
  199.         $Autoplay = 0;
  200.       update_option('autoplay', $Autoplay);
  201.     }
  202.    return $Autoplay;
  203. }
  204.        
  205.    public function check_global($input){
  206.      
  207.     if( isset($input['Global'])){$Global = $input['Global'];    }
  208.      
  209.     if ( $input['Global'] == 1 ) {
  210.         $Global = 1;
  211.       update_option('global', $Global);
  212.     } else {
  213.         $Global = 0;
  214.       update_option('global', $Global);
  215.     }
  216.    return $Global;
  217. }
  218.  
  219.     public function check_id($input){
  220.      
  221.       if( isset($input['Id'])){$ID = $input['Id'];  }
  222.    
  223.         if(!isset($ID['Id']) && isset($input['Id']) && is_numeric($input['Id'])){                  
  224.         if(get_option('id') === FALSE){
  225.         add_option('id', $ID);
  226.         }else{
  227.         update_option('id', $ID);
  228.         }
  229.     }else{
  230.         $ID = '';
  231.     }
  232.     return $ID;
  233.     }
  234.  
  235.     public function print_section_info(){
  236.     print 'These settings help define the shortcodes that are generated for you when you create a slide and are used exclusively if you use the global option. Enter your settings below:';
  237.     }
  238.    
  239.     public function fade_field(){
  240.         ?><input type="text" id="fade" name="fade_key[Fade]" value="<?php echo get_option('fade'); ?>" /><?php
  241.     }
  242.     public function delay_field(){
  243.         ?><input type="text" id="delay" name="delay_key[Delay]" value="<?php echo get_option('delay'); ?>" /><?php
  244.     }
  245.     public function overlay_field(){
  246.         ?><input type="text" id="overlay" name="overlay_key[Overlay]" value="<?php echo get_option('overlay'); ?>" /><?php
  247.     }
  248.     public function title_field(){
  249.         ?><input type="text" id="title" name="title_key[Title]" value="<?php echo get_option('title'); ?>" /><?php
  250.     }
  251.     public function arrows_field(){
  252.       $Arrows = get_option('arrows');
  253.       if($Arrows == 1) { $checked = ' checked="checked" '; }
  254.       else{ $checked = '';}
  255.                        echo '<input type="checkbox" id="arrows" name="arrows_key[Arrows]" value="1" '.$checked.' />'; //<333333
  256.     }
  257.     public function autoplay_field(){
  258.       $Autoplay = get_option('autoplay');
  259.       if($Autoplay == 1) { $checked = ' checked="checked" '; }
  260.       else{ $checked = '';}    
  261.                        echo '<input type="checkbox" id="autoplay" name="autoplay_key[Autoplay]" value="1" '.$checked.' />';
  262.     }
  263.     public function global_field(){
  264.       $Global = get_option('global');
  265.       if($Global == 1) { $checked = ' checked="checked" '; }
  266.       else{ $checked = '';}    
  267.                        echo '<input type="checkbox" id="global" name="global_key[Global]" value="1" '.$checked.' />';
  268.     }
  269.     public function id_field(){
  270.       $Global = get_option('global');
  271.         ?><input type="text" id="id" name="id_key[Id]" value="<?php echo get_option('id');?>" <?php if($Global != 1){echo 'disabled="disabled"';} ?> /><br/>
  272. <p>Note: You have to set the global option and save before you can add the id.  Also the id is neccessary if you're going to use the global option.<br/>  You can find the id on the slide page (where you added the photos)</p>
  273. <?php
  274.     }
  275. }
  276.  
  277. $vs_enet = new vegas(); ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement