Skip to content

Commit

Permalink
Added support for different return values
Browse files Browse the repository at this point in the history
Now able to return either ID, Name or Site URL
  • Loading branch information
Jonathan de Jong committed Oct 22, 2014
1 parent a07e9d1 commit 82af18e
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 4 deletions.
43 changes: 43 additions & 0 deletions acf-sites-v4.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,27 @@ function create_options($field)
?>
</td>
</tr>
<tr class="field_option field_option_<?php echo $this->name; ?>">
<td class="label">
<label><?php _e("Return value", 'acf'); ?></label>
<p class="description"><?php _e("", 'acf'); ?></p>
</td>
<td>
<?php
do_action('acf/create_field', array(
'type' => 'radio',
'name' => 'fields[' . $key . '][return_value]',
'value' => $field['return_value'],
'layout' => 'horizontal',
'choices' => array(
'id' => __('ID'),
'name' => __('Name'),
'siteurl' => __('URL')
)
));
?>
</td>
</tr>


<?php
Expand Down Expand Up @@ -304,6 +325,28 @@ function format_value_for_api($value, $post_id, $field)
// make sure even select returns an array, for consistency!
$checkbox_select = $field['checkbox_select'];
$value = ($checkbox_select == 'select' ? array($value) : $value);


$returnvalue = $field['return_value'];
if($returnvalue == 'id'){
return $value;
}elseif($returnvalue == 'name'){
$new_value = array();
if($value){
foreach($value as $site_id){
$new_value[] = get_blog_details($site_id)->blogname;
}
return $new_value;
}
}elseif($returnvalue == 'siteurl'){
$new_value = array();
if($value){
foreach($value as $site_id){
$new_value[] = get_blog_details($site_id)->siteurl;
}
return $new_value;
}
}

// Note: This function can be removed if not used
return $value;
Expand Down
41 changes: 37 additions & 4 deletions acf-sites-v5.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ function render_field_settings( $field ) {
'layout' => 'horizontal',
'choices' => array(
'yes' => __('Yes'),
'no' => __('No'),
'no' => __('No')
)
));

Expand All @@ -135,7 +135,20 @@ function render_field_settings( $field ) {
'layout' => 'horizontal',
'choices' => array(
'yes' => __('Yes'),
'no' => __('No'),
'no' => __('No')
)
));

acf_render_field_setting( $field, array(
'label' => __('Return value','acf-sites'),
'instructions' => __('','acf-sites'),
'type' => 'radio',
'name' => 'return_value',
'layout' => 'horizontal',
'choices' => array(
'id' => __('ID'),
'name' => __('Name'),
'siteurl' => __('URL')
)
));

Expand Down Expand Up @@ -402,13 +415,33 @@ function field_group_admin_head() {
* @param $field (array) the field array holding all the field options
* @return $value
*/
/*
function load_value( $value, $post_id, $field ) {

$returnvalue = $field['return_value'];
if($returnvalue == 'id'){
return $value;
}elseif($returnvalue == 'name'){
$new_value = array();
if($value){
foreach($value as $site_id){
$new_value[] = get_blog_details($site_id)->blogname;
}
return $new_value;
}
}elseif($returnvalue == 'siteurl'){
$new_value = array();
if($value){
foreach($value as $site_id){
$new_value[] = get_blog_details($site_id)->siteurl;
}
return $new_value;
}
}

return $value;

}
*/




Expand Down

0 comments on commit 82af18e

Please sign in to comment.