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 ?>

'radio', 'name' => 'fields[' . $key . '][checkbox_select]', 'value' => $field['checkbox_select'], 'layout' => 'horizontal', 'choices' => array( 'checkbox' => __('Checkbox (allows multiple)'), 'select' => __('Select'), ) )); ?>

'radio', 'name' => 'fields[' . $key . '][site_status]', 'value' => $field['site_status'], 'layout' => 'horizontal', 'choices' => array( 'public' => __('Public'), 'archived' => __('Archived'), 'mature' => __('Mature'), 'spam' => __('Spam'), 'deleted' => __('Deleted') ) )); ?>

'radio', 'name' => 'fields[' . $key . '][hide_main]', 'value' => $field['hide_main'], 'layout' => 'horizontal', 'choices' => array( 'yes' => __('Yes'), 'no' => __('No'), ) )); ?>

'radio', 'name' => 'fields[' . $key . '][allow_null]', 'value' => $field['allow_null'], 'layout' => 'horizontal', 'choices' => array( 'yes' => __('Yes'), 'no' => __('No'), ) )); ?> 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') . '

'; }else{ $checkbox_select = $field['checkbox_select']; $site_status = $field['site_status']; $hide_main = $field['hide_main']; $allow_null = $field['allow_null']; global $wpdb; $args = array(); $args[$site_status] = true; if($hide_main == 'yes'){ $args['offset'] = 1; } $sites = wp_get_sites($args); if(!empty($sites)){ // we have some sites echo ''; if($checkbox_select == 'select'){ echo ''; }else if($checkbox_select == 'checkbox'){ foreach($sites as $site){ $atts = ''; if( in_array($site['blog_id'], $field['value']) ){ $atts = 'checked="checked"'; } if( isset($field['disabled']) && in_array($key, $field['disabled']) ){ $atts .= ' disabled="true"'; } $sitedetails = get_blog_details(array('blog_id' => $site['blog_id'])); echo ''; } } }else{ echo '

' . __('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(); ?>