Plugin option page
-
Hi,
I’m trying to write my very first plugin, based on the Codex example.
It’s a slider plugin and I would like to add some settings like arrows color, autoplay etc…What I’ve done so far is working, but I would like to know how I can add some default values to my option fields. So far, when the plugin is activated, all option fields are empty…
for example I have this settings field for dots color :
add_settings_field( 'slks_dots', __('Dots Color','slick-slider'), array( $this, 'slks_dots_callback' ), 'slick-slider-admin', 'slks_setting_section_colors' );and the callback :
public function slks_dots_callback() { printf( '<input type="text" id="slks_dots" name="slks_option_name[slks_dots]" value="%s" placeholder="#333333" />', isset( $this->options['slks_dots'] ) ? esc_attr( $this->options['slks_dots']) : '' ); }How can I have ‘#333333’ as a default value to start with ??
Next question, the checbox fields.
I want to have some checboxes returning a true/false value, for example “Enable Auto Play”my settings field :
add_settings_field( 'slks_autoplay', __('Auto Play','slick-slider'), array( $this, 'slks_autoplay_callback' ), 'slick-slider-admin', 'slks_setting_section_animation' );the callback :
public function slks_autoplay_callback() { printf( '<input id="%1$s" name="slks_option_name[%1$s]" type="checkbox" %2$s /> <label for="%1$s">Enable Auto Play</label>', 'slks_autoplay', checked (isset( $this->options['slks_autoplay'] ), true, false ) ); }It’s working but I do not have a default value. when the box is checked, I have a value of 0 returned, when the box is unchecked, no value at all (null)
and I would like this box to be checked on startup, so the value can be “true” (and “false” if unchecked by the user)here is a pastebin of my entire code : http://pastebin.com/U6iDRZkf
Thanks !
The topic ‘Plugin option page’ is closed to new replies.