Created
December 23, 2015 20:06
-
-
Save ryanl4321/7982974b3426b3816b0f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class new_general_setting { | |
private $field_name = false; | |
private $field_label = false; | |
private $field_type = false; | |
function __construct($field_name, $field_label=false, $field_type='text'){ | |
$this->field_name = $field_name; | |
$this->field_label = $field_label ? $field_label : str_replace('_',' ',$field_name); | |
$this->field_type = $field_type; | |
add_filter( 'admin_init' , array( &$this , 'register_fields' ) ); | |
} | |
function register_fields(){ | |
register_setting( 'general', $this->field_name, 'esc_attr' ); | |
add_settings_field($this->field_name, '<label for="'.$this->field_name.'">'.__($this->field_label , $this->field_name ).'</label>' , array(&$this, 'fields_'.$this->field_type) , 'general' ); | |
} | |
function fields_text() { | |
$value = get_option( $this->field_name, '' ); | |
echo '<input type="text" id="'.$this->field_name.'" name="'.$this->field_name.'" value="'.$value.'" style="width:400px;" />'; | |
} | |
function fields_textarea() { | |
$value = get_option( $this->field_name, '' ); | |
echo '<textarea id="'.$this->field_name.'" name="'.$this->field_name.'" style="width:400px;height:100px;">'.$value.'</textarea>'; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is a quick way to add options to the wordpress general settings page
$about_home_setting = new new_general_setting('about_home', 'Home page about','textarea');
$about_home_blue_setting = new new_general_setting('about_home_blue', 'Home page blue large text','text');