Created
October 7, 2012 09:07
-
-
Save bonny/3847600 to your computer and use it in GitHub Desktop.
Simple Fields minimal field extension example
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 | |
add_action("plugins_loaded", "init_simple_fields_field_minimalexample"); | |
function init_simple_fields_field_minimalexample() { | |
class simple_fields_field_minimalexample extends simple_fields_field { | |
public $key = "minimalexample", $name = "Minimalistic example field"; | |
function __construct() { | |
parent::__construct(); | |
} | |
function options_output($existing_vals) { | |
return sprintf(' | |
<p> | |
<label>Default name</label> | |
<span class="description">Enter a name that will be shown as default</span> | |
<input type="text" name="%1$s" value="%2$s"> | |
</p>', | |
$this->get_options_name("textDefaultName"), isset($existing_vals["textDefaultName"]) ? esc_attr($existing_vals["textDefaultName"]) : "" | |
); | |
} | |
function edit_output($saved_values, $options) { | |
return sprintf('<input type="text" name="%1$s" value="%2$s">', $this->get_options_name("name"), empty($saved_values["name"]) ? esc_attr($options["textDefaultName"]) : esc_attr($saved_values["name"])); | |
} | |
} | |
simple_fields::register_field_type("simple_fields_field_minimalexample"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment