Simple Fields simple_fields_register_field_group(), simple_fields_register_post_connector(), simple_fields_register_post_type_default() examples See http://simple-fields.com/ for more info.

  • Download Gist
1-simple-fields-register-field-group-small-example.php
PHP
1 2 3 4 5 6 7 8 9 10 11 12 13 14
<?php
 
// Minimal amount of code
// to create a new field group
// with one field
simple_fields_register_field_group('attachment', array(
'name' => 'Attachment',
'fields' => array(
array(
'name' => 'File',
'slug' => "file",
"type" => "file"
)
)));
2-simple-fields-register-field-group-big-example.php
PHP
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190
<?php
 
// Big example of simple_fields_register_field_group()
 
/**
* Adds a new field group
*
* Usage:
* simple_fields_register_field_group( string unique_field_group_slug, array field_group_options );
*
* Field_group_options:
*
* array (
* 'name' => 'Name of field group',
* 'description' => "A short description of the field group",
* 'repeatable' => TRUE or FALSE if the field group should be repeatable,
* 'fields' => array of fields,
* 'deleted' => TRUE or FALSE,
* "gui_view" => "list", // "list" or "table". Table view is a bit more compact.
* "fields" => array(
* "name" => "The name of your field",
* "slug" => "A unique slug for your field",
* "description" => "An optional description for your field",
* "type" => "text", // the type of field. text, textarea, dropdown, file, etc.
* "deleted" => false, // if the field is deleted or not
* "options" => array(
* "enable_extended_return_values" => true
* // options depending on the field type.
* // see below for examples for each field type
* )
* )
* ),
*
*
* @param string $slug the slug of this field group. must be unique.
* @param array $new_field_group settings/options for the new group
* @return array the new field group as an array
*/
simple_fields_register_field_group('test',
array (
'name' => 'Test field group',
'description' => "Test field description",
'repeatable' => 1,
"gui_view" => "table", // list | table
'fields' => array(
array(
'slug' => "my_text_field_slug",
'name' => 'Test text',
'description' => 'Text description',
'type' => 'text'
),
array(
'slug' => "my_textarea_field_slug",
'name' => 'Test textarea',
'description' => 'Textarea description',
'type' => 'textarea',
'type_textarea_options' => array('use_html_editor' => 1)
),
array(
'slug' => "my_checkbox_field_slug",
'name' => 'Test checkbox',
'description' => 'Checkbox description',
'type' => 'checkbox',
'type_checkbox_options' => array('checked_by_default' => 1)
),
array(
'slug' => "my_radiobutton_field_slug",
'name' => 'Test radiobutton',
'description' => 'Radiobutton description',
'type' => 'radiobutton',
'type_radiobutton_options' => array(
array("value" => "Yes"),
array("value" => "No")
)
),
array(
'slug' => "my_dropdown_field_slug",
'name' => 'Test dropdown',
'description' => 'Dropdown description',
'type' => 'dropdown',
'options' => array(
"enable_multiple" => false,
"values" => array(
array(
"num" => 0,
"value" => "First value in the dropdown"
),
array(
"num" => 1,
"value" => "Second value"
)
)
)
),
array(
'slug' => "my_file_field_slug",
'name' => 'Test file',
'description' => 'File description',
'type' => 'file'
),
array(
'slug' => "my_post_field_slug",
'name' => 'Test post',
'description' => 'Post description',
'type' => 'post',
'options' => array(
"enable_extended_return_values" => true,
"enabled_post_types" => array("post")
)
),
array(
'slug' => "my_taxonomy_field_slug",
'name' => 'Test taxonomy',
'description' => 'Taxonomy description',
'type' => 'taxonomy',
'options' => array(
"enable_extended_return_values" => true,
"enabled_taxonomies" => array("category")
)
),
array(
'slug' => "my_taxonomyterm_field_slug",
'name' => 'Test taxonomy term',
'description' => 'Taxonomy term description',
'type' => 'taxonomyterm',
'options' => array(
"enable_extended_return_values" => true,
"enabled_taxonomy" => "category"
)
),
array(
'slug' => "my_color_field_slug",
'name' => 'Test color selector',
'description' => 'Color selector description',
'type' => 'color'
),
array(
'slug' => "my_date_field_slug",
'name' => 'Test date selector',
'description' => 'Date selector description',
'type' => 'date',
'type_date_options' => array('use_time' => 1)
),
array(
'slug' => "my_date2_field_slug",
'name' => 'Test date selector',
'description' => 'Date v2 selector description',
'type' => 'date_v2',
"options" => array(
"date_v2" => array(
"show" => "on_click",
"show_as" => "datetime",
"default_date" => "today"
)
)
),
array(
'slug' => "my_user_field_slug",
'name' => 'Test user selector',
'description' => 'User selector description',
'type' => 'user'
)
)
)
);
 
// function simple_fields_register_post_connector($unique_name = "", $new_post_connector = array()) {
simple_fields_register_post_connector('test_connector',
array (
'name' => "A test connector",
'field_groups' => array(
array(
'slug' => 'test',
'context' => 'normal', // 'normal', 'advanced', or 'side'
'priority' => 'default' // 'high', 'core', 'default' or 'low'
)
),
// post_types can also be string, if only one post type is to be connected
'post_types' => array('post', "my_custom_post_type"),
"hide_editor" => false // true or false, hides the standard wp editor if true
)
);
 
/**
* Sets the default post connector for a post type
*
* @param $post_type_connector = connector id (int) or slug (string) or string __inherit__
*
*/
simple_fields_register_post_type_default('test_connector', 'post');

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.