PHP Class Fieldmanager_Options, vip-mu-plugins-public

Inheritance: extends Fieldmanager_Field
Show file Open project: Automattic/vip-mu-plugins-public Class Usage Examples

Public Properties

Property Type Description
$data array Full option data, allows grouping
$first_element array Always prepend this element to the $data
$grouped boolean Is the data grouped? E.g. should we use
$multiple boolean Allow multiple selections?
$options array Shortcut to data which allows a simple associative array
$options_template string Path to an options template to load.

Public Methods

Method Description
__construct ( string $label = '', mixed $options = [] ) Add CSS, construct parent
add_options ( array $options ) : void Add options
form_data_element ( $data_row, mixed $value ) A single element for a single bit of data, e.g. '
form_data_elements ( mixed $value ) : string Generate form elements.
option_selected ( string $current_option, array $options, string $attribute ) : string Helper for output functions to toggle a selected options
preload_alter_values ( array $values ) Alter values before rendering
presave ( mixed $value, $current_value = [] ) : sanitized Presave function, which handles sanitization and validation
presave_all ( $values, $current_values ) : mixed[] Override presave_all to handle special cases associated with multiple options fields.
presave_alter_values ( int[] $values, int[] $current_values = [] ) : int[] Presave hook to set taxonomy data, maybe
sanitize ( array | string $value ) : array | string Sanitize function that can handle arrays as well as string values.

Protected Methods

Method Description
add_meta_boxes_to_remove ( &$meta_boxes_to_remove ) : array Helper function to get the list of default meta boxes to remove.
add_option_data ( string $name, mixed $value, string $group = null, string | integer $group_id = null ) : void Add option data to the data attribute of this object

Method Details

__construct() public method

Add CSS, construct parent
public __construct ( string $label = '', mixed $options = [] )
$label string
$options mixed

add_meta_boxes_to_remove() protected method

If $remove_default_meta_boxes is true and the datasource is Fieldmanager_Datasource_Term, this will return a list of all default meta boxes for the specified taxonomies. We only need to return id and context since the page will be handled by the list of post types provided to add_meta_box. Otherwise, this will just return an empty array.
protected add_meta_boxes_to_remove ( &$meta_boxes_to_remove ) : array
return array list of meta boxes to remove

add_option_data() protected method

Add option data to the data attribute of this object
protected add_option_data ( string $name, mixed $value, string $group = null, string | integer $group_id = null ) : void
$name string
$value mixed
$group string
$group_id string | integer
return void

add_options() public method

Add options
public add_options ( array $options ) : void
$options array
return void

form_data_element() public method

A single element for a single bit of data, e.g. '
public form_data_element ( $data_row, mixed $value )
$value mixed

form_data_elements() public method

Generate form elements.
public form_data_elements ( mixed $value ) : string
$value mixed
return string HTML

option_selected() public method

Helper for output functions to toggle a selected options
public option_selected ( string $current_option, array $options, string $attribute ) : string
$current_option string this option
$options array all valid options
$attribute string
return string $attribute on match, empty on failure.

preload_alter_values() public method

Alter values before rendering
public preload_alter_values ( array $values )
$values array

presave() public method

Presave function, which handles sanitization and validation
public presave ( mixed $value, $current_value = [] ) : sanitized
$value mixed If a single field expects to manage an array, it must override presave()
return sanitized values.

presave_all() public method

Override presave_all to handle special cases associated with multiple options fields.
public presave_all ( $values, $current_values ) : mixed[]
return mixed[] sanitized values

presave_alter_values() public method

Presave hook to set taxonomy data, maybe
public presave_alter_values ( int[] $values, int[] $current_values = [] ) : int[]
$values int[]
$current_values int[]
return int[] $values

sanitize() public method

Sanitize function that can handle arrays as well as string values.
public sanitize ( array | string $value ) : array | string
$value array | string
return array | string Sanitized $value

Property Details

$data public property

Full option data, allows grouping
public array $data
return array

$first_element public property

Always prepend this element to the $data
public array $first_element
return array

$grouped public property

Is the data grouped? E.g. should we use
public bool $grouped
return boolean

$multiple public property

Allow multiple selections?
public bool $multiple
return boolean

$options public property

Shortcut to data which allows a simple associative array
public array $options
return array

$options_template public property

Path to an options template to load.
public string $options_template
return string