name = 'sites'; /* * label (string) Multiple words, can include spaces, visible when selecting a field type */ $this->label = __( 'Sites', 'acf-sites' ); /* * category (string) basic | content | choice | relational | jquery | layout | CUSTOM GROUP NAME */ $this->category = 'relational'; /* * defaults (array) Array of default settings which are merged into the field object. These are used later in settings */ $this->defaults = array( 'field_type' => 'checkbox', 'status' => 'all', 'hide_main' => 1, 'allow_null' => 0, 'return_value' => 'id', 'site__not_in' => '', ); /* * settings (array) Store plugin settings (url, path, version) as a reference for later use with assets */ $this->settings = $settings; // do not delete! parent::__construct(); } /* * render_field_settings() * * Create extra settings for your field. These are visible when editing a field * * @type action * @since 3.6 * @date 23/01/13 * * @param $field (array) the $field being edited * @return n/a */ public function render_field_settings( $field ) { /* * acf_render_field_setting * * This function will create a setting for your field. Simply pass the $field parameter and an array of field settings. * The array of settings does not require a `value` or `prefix`; These settings are found from the $field array. * * More than one setting can be added by copy/paste the above code. * Please note that you must also have a matching $defaults value for the field name (font_size) */ acf_render_field_setting( $field, array( 'label' => __( 'Appearance','acf-sites' ), 'instructions' => __( 'Select the appearance of this field','acf-sites' ), 'type' => 'select', 'name' => 'field_type', 'optgroup' => true, 'choices' => array( __( 'Multiple Values','acf-sites' ) => array( 'checkbox' => __( 'Checkbox', 'acf-sites' ), 'multi_select' => __( 'Multi Select', 'acf-sites' ), ), __( 'Single Value', 'acf-sites' ) => array( 'radio' => __( 'Radio Buttons', 'acf-sites' ), 'select' => _x( 'Select', 'noun', 'acf-sites' ), ), ), )); acf_render_field_setting( $field, array( 'label' => __( 'Allow null','acf-sites' ), 'instructions' => '', 'type' => 'radio', 'name' => 'allow_null', 'layout' => 'horizontal', 'choices' => array( 1 => __( 'Yes' ), 0 => __( 'No' ), ), )); acf_render_field_setting( $field, array( 'label' => __( 'Site status','acf-sites' ), 'instructions' => __( 'WordPress currently only support limiting to single status.','acf-sites' ), 'type' => 'radio', 'name' => 'status', 'layout' => 'horizontal', 'choices' => array( 'all' => __( 'All', 'acf-sites' ), 'public' => __( 'Public', 'acf-sites' ), 'archived' => __( 'Archived', 'acf-sites' ), 'mature' => __( 'Mature', 'acf-sites' ), 'spam' => __( 'Spam', 'acf-sites' ), 'deleted' => __( 'Deleted', 'acf-sites' ), ), )); acf_render_field_setting( $field, array( 'label' => __( 'Hide main site','acf-sites' ), 'instructions' => '', 'type' => 'radio', 'name' => 'hide_main', 'layout' => 'horizontal', 'choices' => array( 1 => __( 'Yes' ), 0 => __( 'No' ), ), )); acf_render_field_setting( $field, array( 'label' => __( 'Exclude sites','acf-sites' ), 'instructions' => __( 'Comma separated site IDs','acf-sites' ), 'type' => 'text', 'name' => 'site__not_in', )); acf_render_field_setting( $field, array( 'label' => __( 'Return value','acf-sites' ), 'instructions' => __( 'Specify the value returned','acf-sites' ), 'type' => 'radio', 'name' => 'return_value', 'layout' => 'horizontal', 'choices' => array( 'id' => __( 'Site ID', 'acf-sites' ), 'name' => __( 'Site name', 'acf-sites' ), 'url' => __( 'Site URL', 'acf-sites' ), 'all' => __( 'All (Array)', 'acf-sites' ), ), )); } /* * render_field() * * Create the HTML interface for your field * * @param $field (array) the $field being rendered * * @type action * @since 3.6 * @date 23/01/13 * * @param $field (array) the $field being edited * @return n/a */ public function render_field( $field ) { // value must be array $field['value'] = acf_get_array( $field['value'] ); /** * This field requires multisite to work. */ if ( ! is_multisite() ) { echo '
' . __( 'You need to have set up a multisite network for this field to work', 'acf-sites' ) . '
'; return; } /** * Setup query. */ global $wpdb; $args = array(); if ( $field['hide_main'] ) { $args['offset'] = 1; } if ( 'all' != $field['status'] ) { $args[ $field['status'] ] = '1'; } if ( '' != $field['site__not_in'] ) { $excluded_sites = explode( ',', $field['site__not_in'] ); $excluded_sites_2 = explode( ', ', $field['site__not_in'] ); $excluded_merged = array_merge( $excluded_sites, $excluded_sites_2 ); $args['site__not_in'] = $excluded_merged; } $sites = get_sites( $args ); if ( empty( $sites ) ) { echo '' . __( 'No sites found with the current field settings.', 'acf-sites' ) . '
'; } // vars $div = array( 'class' => 'acf-sites-field acf-soh', 'data-type' => $field['field_type'], ); ?>