name = 'sites';
$this->label = __('Sites');
$this->category = __("Relational",'acf');
$this->defaults = array(
'checkbox_select' => 'checkbox',
'site_status' => 'public',
'hide_main' => 'yes',
'allow_null' => 'yes'
);
// do not delete!
parent::__construct();
// settings
$this->settings = array(
'path' => apply_filters('acf/helpers/get_path', __FILE__),
'dir' => apply_filters('acf/helpers/get_dir', __FILE__),
'version' => '1.0.0'
);
}
/*
* create_options()
*
* Create extra options for your field. This is rendered when editing a field.
* The value of $field['name'] can be used (like bellow) to save extra data to the $field
*
* @type action
* @since 3.6
* @date 23/01/13
*
* @param $field - an array holding all the field's data
*/
function create_options($field)
{
// defaults?
$field = array_merge($this->defaults, $field);
// key is needed in the field names to correctly save the data
$key = $field['name'];
// Create Field Options HTML
?>
defaults, $field);
// value must be array
if( !is_array($field['value']) ){
// perhaps this is a default value with new lines in it?
if( strpos($field['value'], "\n") !== false ){
// found multiple lines, explode it
$field['value'] = explode("\n", $field['value']);
}else{
$field['value'] = array( $field['value'] );
}
}
// trim value
$field['value'] = array_map('trim', $field['value']);
if(!is_multisite()){
echo '
' . __('You need to have set up a multisite network for this field to work', 'acf_sites') . '
' . __('No sites found, check your filter settings in the acf field', 'acf_sites') . '
';
}
}
}
/*
* input_admin_enqueue_scripts()
*
* This action is called in the admin_enqueue_scripts action on the edit screen where your field is created.
* Use this action to add css + javascript to assist your create_field() action.
*
* $info http://codex.wordpress.org/Plugin_API/Action_Reference/admin_enqueue_scripts
* @type action
* @since 3.6
* @date 23/01/13
*/
function input_admin_enqueue_scripts()
{
// Note: This function can be removed if not used
// register acf scripts
wp_register_script('acf-input-sites', $this->settings['dir'] . 'js/input.js', array('acf-input'), $this->settings['version']);
wp_register_style('acf-input-sites', $this->settings['dir'] . 'css/input.css', array('acf-input'), $this->settings['version']);
// scripts
wp_enqueue_script(array(
'acf-input-sites',
));
// styles
wp_enqueue_style(array(
'acf-input-sites',
));
}
/*
* format_value_for_api()
*
* This filter is appied to the $value after it is loaded from the db and before it is passed back to the api functions such as the_field
*
* @type filter
* @since 3.6
* @date 23/01/13
*
* @param $value - the value which was loaded from the database
* @param $post_id - the $post_id from which the value was loaded
* @param $field - the field array holding all the field options
*
* @return $value - the modified value
*/
function format_value_for_api($value, $post_id, $field)
{
// defaults?
$field = array_merge($this->defaults, $field);
// make sure even select returns an array, for consistency!
$checkbox_select = $field['checkbox_select'];
$value = ($checkbox_select == 'select' ? array($value) : $value);
// Note: This function can be removed if not used
return $value;
}
}
// create field
new acf_field_sites();
?>