Simple Fields API Documentation
Class

simple_fields

class simple_fields

Class to keep all simple fields stuff together a bit better

Constants

DEBUG_ENABLED

Properties

$plugin_foldername_and_filename
$registered_field_types
$ns_key

Methods

init()

Init is where we setup actions and filers and loads stuff and a little bit of this and that

setup_wpml_support()

Init support for WPML translations

array normalize_fieldgroups(array $fieldgroup $field_groups)

Make sure a field group has the correct format It can be wrong because prior to version ?.? the options for a field was not stored in the options array.

register_wpml_strings()

Register strings so they are translateable with WPML

get_string(string $name = '', string $value = '')

Get maybe translated string If WPML is installed and activated then icl_t() is used on the string If WPML is not installed, then it's just returned unmodified

action_pre_get_posts_meta($query)

If sfmetakey is set then that is assumed to be the slugs of a field group and a field and the metakey of the value will be replaced by the metakey value of that simple field-field

debug_panel_insert($panels)

Inserts debug panel to debug bar Called form debug bar filter "debugbarpanels", so will only be run'ed when debug bar is activated

check_upgrade_stuff()

plugins_loaded()

When all plugins have loaded = simple fields has also loaded = safe to add custom field types

string get_slug_pattern()

Gets the pattern that are allowed for slugs

get_slug_title()

Get the title for a slug I.e.

get_connector_by_id(int $connector_id)

Returns a post connector

static  debug($description, $details)

If setting debug = true then output some debug stuff a little here and there Hopefully this saves us some vardump/sfd/echo all the time usage: first set DEBUGENABLED = true in beginning of class then: simplefields("Saved post connector", array("description" => $value, "description n" => $value_n));

settings_admin_head()

Run action if we are on a settings/options page that belongs to Simple Fields

admin_enqueue_scripts($hook)

Enqueue styles and scripts, but on on pages that use simple fields Should speed up the loading of other pages a bit

admin_init()

Stuff that is being runned only when in admin (i.e.

set_plugin_row_meta($links, $file)

Add settings link to plugin page Hopefully this helps some people to find the settings page quicker

get_post_connector_attached_types()

Return an array of the post types that we have set up post connectors for

mixed get_default_connector_for_post_type(string $post_type)

Get default connector for a post type If no connector has been set, none is returned

admin_footer()

Output HTML for dialog in bottom

post_dbx_post_sidebar()

output nonce

save_postdata($post_id = null, $post = null)

Saves simple fields data when post is being saved

metabox_fieldgroup_add()

adds a fieldgroup through ajax = also fetch defaults called when clicking "+ add" in post edit screen

meta_box_output_one_field_group($field_group_id, $num_in_set, $post_id, $use_defaults)

Output the html for a field group in the meta box on the post edit screen Also called from ajax when clicking "+ add"

admin_head()

Head of admin area - Add meta box with info about currently selected connector + options to choose another one - Add meta boxes with field groups

meta_box_output($post_connector_field_id, $post_id)

print out fields for a meta box

array get_post_connectors()

Returns all defined post connectors

get_post_type_defaults()

Returns

array get_field_groups($include_deleted $include_deleted = true)

Returns all defined field groups

array get_field_group(int $group_id)

Get a field group

false get_field_in_group(int $field_group, mixed $field_id)

Returns a field from a field group

edit_post_side_field_settings()

meta box in sidebar in post edit screen let user select post connector to use for current post

id get_selected_connector_for_post(object $post)

get selected post connector for a post a post has a post connector, or no connector this function will return the inherited connector if post is set to inherit connector unless it's the top most post since then nere are no more to inherit should not return be none then?

connector get_post_connector_by_slug(string $post_slug)

Get post connector by its slug

get_pages($args)

Code from Admin Menu Tree Page View

admin_head_select_file()

File browser dialog: hide some things there to make it more clean and user friendly

media_send_to_editor($html, $id)

used from file selector popup send the selected file to simple fields

media_upload_form_url($url)

if we have simple fields args in GET, make sure our simple fields-stuff are added to the form

media_upload_tabs($arr_tabs)

remove gallery and remote url tab in file select also remove some

post_admin_init()

In file dialog: Change "insert into post" to something better

hijack_thickbox_text($translated_text, $source_text, $domain)

field_type_post_dialog_load()

Field type: post Fetch content for field type post dialog via AJAX Used for field type post Called from ajax with action wpajaxsimplefieldsfieldtypepostdialogload Ajax defined in scripts.js -> $("a.simple-fields-metabox-field-post-select")

field_group_add_field_template($fieldID, $field_group_in_edit = null)

Returns the output for a new or existing field with all it's options Used in options screen / admin screen

field_group_add_field()

Called from AJAX call to add a field group to the post in edit

options_page()

Output all stuff for the options page

admin_menu()

Add the admin menu page for simple fields If you want to hide this for some reason (maybe you are a theme developer that want to use simple fields, but not show the options page to your users) you can add a filter like this:

array get_post_connectors_for_post_type($post_type)

Gets the post connectors for a post type

_register_field_type($field_type_name)

array get_options()

Get all options

save_options($new_options)

Save options

maybe_add_debug_info()

If debug option is enabled then output debug-box by hooking onto the_content

simple_fields_content_debug_output($the_content, $args = '')

Outputs the names of the post connectors attached to the post you view + outputs the values

get_extended_return_values_for_field(mixed $field, mixed $field_value)

Retrieve and return extended return values for a field type Only used for internal/built in file types.

mixed get_field_group_by_slug($field_group_slug, $include_deleted = false)

Gets a field group using it's slug.

get_meta_key_num_added($field_group_id = null, $field_group_slug = null)

Get meta key name for the custom field used for determine how many fields that has been added to a post hm...

string get_meta_key($field_group_id = NULL, $field_id = NULL, $num_in_set, $field_group_slug = '', $field_slug = '')

Get meta key name for a field id + field group id combination

mixed get_field_by_slug(string $field_slug = '', string $fieldgroup_slug = '')

Returns a field from a fieldgroup using their slugs

clear_caches()

Clear the key used for wpcacheget and wpcacheset Run this when options etc have been changed so fresh values are fetched upon next get

mixed. get_core_field_type_by_key(string $str_field_key = '')

Bool field_type_is_core($str_field_key = '')

Check if field type with key $strfieldtype is one of the core ones

array get_core_field_types()

Get a list of all core field types Core = all field types that are not extensions Core field types use old and less smart way of storing options

options_page_save()

array get_html_text_types()

Get the html input types that we show in text field type

get_options_nav_tabs($subpage)

Get tabs for options output

promote_ep_on_nav_tabs()

Promote Earth People

array get_field_by_fieldgroup_and_slug_string(string $string)

Retrive a field by a string in the format / used when fieldgroups and fields need to be passed as string

bool is_wpml_active()

Check if wpml is active

set_post_connector_from_template($connector_to_use, $post)

Look for post connector defined in template Format in template is:

post_has_template_connector($post)

Returns true if post has a template connector defined

string get_post_connector_from_template(string $template)

string wp_kses($string, $allowed_html, $allowed_protocols = array(), $skip_normalize_entities = false)

Filters content and keeps only allowable HTML elements.

Details

at line 57
public init()

Init is where we setup actions and filers and loads stuff and a little bit of this and that

at line 155
public setup_wpml_support()

Init support for WPML translations

at line 183
public array normalize_fieldgroups(array $fieldgroup $field_groups)

Make sure a field group has the correct format It can be wrong because prior to version ?.? the options for a field was not stored in the options array.

but nowadays we assume it is. so..if it's not: fix that!

Parameters

array $fieldgroup $field_groups Field group to normalize

Return Value

array $fieldgroup Normalized/fixed field group

at line 283
public register_wpml_strings()

Register strings so they are translateable with WPML

at line 375
public get_string(string $name = '', string $value = '')

Get maybe translated string If WPML is installed and activated then icl_t() is used on the string If WPML is not installed, then it's just returned unmodified

Parameters

string $name Name to use in icl_t
string $value Value to use in icl_t

at line 392
public action_pre_get_posts_meta($query)

If sfmetakey is set then that is assumed to be the slugs of a field group and a field and the metakey of the value will be replaced by the metakey value of that simple field-field

Parameters

$query

at line 414
public debug_panel_insert($panels)

Inserts debug panel to debug bar Called form debug bar filter "debugbarpanels", so will only be run'ed when debug bar is activated

Parameters

$panels

at line 434
public check_upgrade_stuff()

at line 463
public plugins_loaded()

When all plugins have loaded = simple fields has also loaded = safe to add custom field types

at line 471
public string get_slug_pattern()

Gets the pattern that are allowed for slugs

Return Value

string

at line 481
public get_slug_title()

Get the title for a slug I.e.

the help text that the input field will show when the slug pattern is not matched

at line 489
public get_connector_by_id(int $connector_id)

Returns a post connector

Parameters

int $connector_id

at line 507
static public debug($description, $details)

If setting debug = true then output some debug stuff a little here and there Hopefully this saves us some vardump/sfd/echo all the time usage: first set DEBUGENABLED = true in beginning of class then: simplefields("Saved post connector", array("description" => $value, "description n" => $value_n));

Parameters

$description
$details

at line 524
public settings_admin_head()

Run action if we are on a settings/options page that belongs to Simple Fields

at line 546
public admin_enqueue_scripts($hook)

Enqueue styles and scripts, but on on pages that use simple fields Should speed up the loading of other pages a bit

Parameters

$hook

at line 632
public admin_init()

Stuff that is being runned only when in admin (i.e.

not on front of site)

at line 642
public set_plugin_row_meta($links, $file)

Add settings link to plugin page Hopefully this helps some people to find the settings page quicker

Parameters

$links
$file

at line 669
public get_post_connector_attached_types()

Return an array of the post types that we have set up post connectors for

Format of return:

Array ( [0] => post [1] => page [2] => testposttype )

at line 688
public mixed get_default_connector_for_post_type(string $post_type)

Get default connector for a post type If no connector has been set, none is returned

Parameters

string $post_type

Return Value

mixed int connector id or string none or inherit

Output HTML for dialog in bottom

at line 709
public post_dbx_post_sidebar()

output nonce

at line 718
public save_postdata($post_id = null, $post = null)

Saves simple fields data when post is being saved

Parameters

$post_id
$post

at line 923
public metabox_fieldgroup_add()

adds a fieldgroup through ajax = also fetch defaults called when clicking "+ add" in post edit screen

at line 942
public meta_box_output_one_field_group($field_group_id, $num_in_set, $post_id, $use_defaults)

Output the html for a field group in the meta box on the post edit screen Also called from ajax when clicking "+ add"

Parameters

$field_group_id
$num_in_set
$post_id
$use_defaults

at line 1680
public admin_head()

Head of admin area - Add meta box with info about currently selected connector + options to choose another one - Add meta boxes with field groups

at line 1764
public meta_box_output($post_connector_field_id, $post_id)

print out fields for a meta box

Parameters

$post_connector_field_id
$post_id

at line 1910
public array get_post_connectors()

Returns all defined post connectors

Return Value

array

at line 1983
public get_post_type_defaults()

Returns

at line 2003
public array get_field_groups($include_deleted $include_deleted = true)

Returns all defined field groups

Parameters

$include_deleted $include_deleted should deletd fieldgroups and fields also be included? defaults to true for backwards compat

Return Value

array

at line 2146
public array get_field_group(int $group_id)

Get a field group

Example: global $sf; $myfieldgroupid = 10; $fieldgroupinfo = $sf->getfieldgroup( $myfieldgroupid ); sfd( $fieldgroupinfo , '$fieldgroup_info' );

Parameters

int $group_id

Return Value

array with field group or false if field group is not found

at line 2179
public false get_field_in_group(int $field_group, mixed $field_id)

Returns a field from a field group

Parameters

int $field_group
mixed $field_id id or name of field

Return Value

false on error

at line 2208
public edit_post_side_field_settings()

meta box in sidebar in post edit screen let user select post connector to use for current post

at line 2329
public id get_selected_connector_for_post(object $post)

get selected post connector for a post a post has a post connector, or no connector this function will return the inherited connector if post is set to inherit connector unless it's the top most post since then nere are no more to inherit should not return be none then?

Parameters

object $post or int post id

Return Value

id or string none

at line 2396
public connector get_post_connector_by_slug(string $post_slug)

Get post connector by its slug

Parameters

string $post_slug

Return Value

connector if found, false if not

at line 2408
public get_pages($args)

Code from Admin Menu Tree Page View

Parameters

$args

at line 2469
public admin_head_select_file()

File browser dialog: hide some things there to make it more clean and user friendly

at line 2489
public media_send_to_editor($html, $id)

used from file selector popup send the selected file to simple fields

Parameters

$html
$id

at line 2540
public media_upload_form_url($url)

if we have simple fields args in GET, make sure our simple fields-stuff are added to the form

Parameters

$url

at line 2556
public media_upload_tabs($arr_tabs)

remove gallery and remote url tab in file select also remove some

Parameters

$arr_tabs

at line 2573
public post_admin_init()

In file dialog: Change "insert into post" to something better

Code inspired by/gracefully stolen from http://mondaybynoon.com/2010/10/12/attachments-1-5/#comment-27524

at line 2579
public hijack_thickbox_text($translated_text, $source_text, $domain)

Parameters

$translated_text
$source_text
$domain

at line 2596
public field_type_post_dialog_load()

Field type: post Fetch content for field type post dialog via AJAX Used for field type post Called from ajax with action wpajaxsimplefieldsfieldtypepostdialogload Ajax defined in scripts.js -> $("a.simple-fields-metabox-field-post-select")

at line 2688
public field_group_add_field_template($fieldID, $field_group_in_edit = null)

Returns the output for a new or existing field with all it's options Used in options screen / admin screen

Parameters

$fieldID
$field_group_in_edit

at line 3306
public field_group_add_field()

Called from AJAX call to add a field group to the post in edit

at line 3319
public options_page()

Output all stuff for the options page

at line 3335
public admin_menu()

Add the admin menu page for simple fields If you want to hide this for some reason (maybe you are a theme developer that want to use simple fields, but not show the options page to your users) you can add a filter like this:

add_filter("simple-fields-add-admin-menu", function($bool) { return FALSE; });

at line 3351
public array get_post_connectors_for_post_type($post_type)

Gets the post connectors for a post type

Parameters

$post_type

Return Value

array

at line 3378
public _register_field_type($field_type_name)

Parameters

$field_type_name

at line 3387
public array get_options()

Get all options

Return Value

array

at line 3399
public save_options($new_options)

Save options

Parameters

$new_options

at line 3412
public maybe_add_debug_info()

If debug option is enabled then output debug-box by hooking onto the_content

at line 3433
public simple_fields_content_debug_output($the_content, $args = '')

Outputs the names of the post connectors attached to the post you view + outputs the values

Parameters

$the_content
$args

at line 3611
public get_extended_return_values_for_field(mixed $field, mixed $field_value)

Retrieve and return extended return values for a field type Only used for internal/built in file types.

Parameters

mixed $field array or string or int or whatever with field info
mixed $field_value the saved value

at line 3869
public mixed get_field_group_by_slug($field_group_slug, $include_deleted = false)

Gets a field group using it's slug.

Deleted field groups are not included

Parameters

$field_group_slug
$include_deleted

Return Value

mixed array with field group info if field groups exists, false if does not exist

at line 3939
public get_meta_key_num_added($field_group_id = null, $field_group_slug = null)

Get meta key name for the custom field used for determine how many fields that has been added to a post hm...

this is the same as getmetakey but with the field id "added" instead of a real id? i think so...

Parameters

$field_group_id
$field_group_slug

at line 3985
public string get_meta_key($field_group_id = NULL, $field_id = NULL, $num_in_set, $field_group_slug = '', $field_slug = '')

Get meta key name for a field id + field group id combination

Parameters

$field_group_id
$field_id
$num_in_set
$field_group_slug
$field_slug

Return Value

string

at line 4027
public mixed get_field_by_slug(string $field_slug = '', string $fieldgroup_slug = '')

Returns a field from a fieldgroup using their slugs

Parameters

string $field_slug
string $fieldgroup_slug

Return Value

mixed Array with field info if field is found, false if not found

at line 4049
public clear_caches()

Clear the key used for wpcacheget and wpcacheset Run this when options etc have been changed so fresh values are fetched upon next get

at line 4090
public mixed. get_core_field_type_by_key(string $str_field_key = '')

Parameters

string $str_field_key Key of field type to get

Return Value

mixed. Returns false if field is not found. Returns array with field info if field is found.

at line 4109
public Bool field_type_is_core($str_field_key = '')

Check if field type with key $strfieldtype is one of the core ones

Parameters

$str_field_key

Return Value

Bool

at line 4129
public array get_core_field_types()

Get a list of all core field types Core = all field types that are not extensions Core field types use old and less smart way of storing options

Return Value

array with all field types

at line 4187
public options_page_save()

at line 4362
public array get_html_text_types()

Get the html input types that we show in text field type

Return Value

array

at line 4430
public get_options_nav_tabs($subpage)

Get tabs for options output

Parameters

$subpage

at line 4444
public promote_ep_on_nav_tabs()

Promote Earth People

at line 4490
public array get_field_by_fieldgroup_and_slug_string(string $string)

Retrive a field by a string in the format / used when fieldgroups and fields need to be passed as string

Parameters

string $string

Return Value

array field info or false if field not found

at line 4513
public bool is_wpml_active()

Check if wpml is active

Return Value

bool

at line 4529
public set_post_connector_from_template($connector_to_use, $post)

Look for post connector defined in template Format in template is:

Simple Fields Connector: useMeAsThePostConnector

Hooked into action simplefieldsgetselectedconnectorforpost

Parameters

$connector_to_use
$post

at line 4545
public post_has_template_connector($post)

Returns true if post has a template connector defined

Parameters

$post

at line 4558
public string get_post_connector_from_template(string $template)

Parameters

string $template template filename

Return Value

string Slug of post connector. Empty if no one set

at line 4585
public string wp_kses($string, $allowed_html, $allowed_protocols = array(), $skip_normalize_entities = false)

Filters content and keeps only allowable HTML elements.

This is the same function as built into WP, but with optional allowing of keeping "&"

Parameters

$string
$allowed_html
$allowed_protocols
$skip_normalize_entities

Return Value

string Filtered content with only allowed HTML elements