';
echo '
';
if($field['instructions']) echo '
' . $field['instructions'] . '
';
$field['name'] = 'fields[' . $field['key'] . ']';
$this->create_field($field);
echo '
';
}
}
}
/*--------------------------------------------------------------------------------------
*
* ajax_acf_location
*
* @author Elliot Condon
* @since 3.1.6
*
*-------------------------------------------------------------------------------------*/
function ajax_acf_location($options = array())
{
// defaults
$defaults = array(
'key' => null,
'value' => null,
'param' => null,
);
// Is AJAX call?
if(isset($_POST['action']) && $_POST['action'] == "acf_location")
{
$options = array_merge($defaults, $_POST);
}
else
{
$options = array_merge($defaults, $options);
}
// some case's have the same outcome
if($options['param'] == "page_parent")
{
$options['param'] = "page";
}
$choices = array();
$optgroup = false;
switch($options['param'])
{
case "post_type":
$choices = get_post_types(array('public' => true));
unset($choices['attachment']);
break;
case "page":
$pages = get_pages('sort_column=menu_order&sort_order=desc');
foreach($pages as $page)
{
$value = '';
$ancestors = get_ancestors($page->ID, 'page');
if($ancestors)
{
foreach($ancestors as $a)
{
$value .= '– ';
}
}
$value .= get_the_title($page->ID);
$choices[$page->ID] = $value;
}
break;
case "page_type" :
$choices = array(
'parent' => 'Parent Page',
'child' => 'Child Page',
);
break;
case "page_template" :
$choices = array(
'default' => 'Default Template',
);
$templates = get_page_templates();
foreach($templates as $k => $v)
{
$choices[$v] = $k;
}
break;
case "post" :
$posts = get_posts( array('numberposts' => '-1' ));
foreach($posts as $v)
{
$choices[$v->ID] = $v->post_title;
}
break;
case "post_category" :
$category_ids = get_all_category_ids();
foreach($category_ids as $cat_id)
{
$cat_name = get_cat_name($cat_id);
$choices[$cat_id] = $cat_name;
}
break;
case "post_format" :
/*$choices = array(
'0' => 'Standard',
'aside' => 'Aside',
'link' => 'Link',
'gallery' => 'Gallery',
'status' => 'Status',
'quote' => 'Quote',
'image' => 'Image',
);*/
$choices = get_post_format_strings();
break;
case "user_type" :
global $wp_roles;
$choices = $wp_roles->get_names();
break;
case "options_page" :
$choices = array(
'Options' => 'Options',
);
$custom = apply_filters('acf_register_options_page',array());
if(!empty($custom))
{
$choices = array();
foreach($custom as $c)
{
$choices[$c['title']] = $c['title'];
}
}
break;
case "taxonomy" :
$choices = $this->get_taxonomies_for_select();
$optgroup = true;
break;
}
$this->create_field(array(
'type' => 'select',
'name' => 'location[rules][' . $options['key'] . '][value]',
'value' => $options['value'],
'choices' => $choices,
'optgroup' => $optgroup,
));
// ajax?
if(isset($_POST['action']) && $_POST['action'] == "acf_location")
{
die();
}
}
}
?>