本文整理汇总了PHP中acf_in_array函数的典型用法代码示例。如果您正苦于以下问题:PHP acf_in_array函数的具体用法?PHP acf_in_array怎么用?PHP acf_in_array使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了acf_in_array函数的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: render_field
function render_field($field)
{
// decode value (convert to array)
$field['value'] = acf_get_array($field['value'], false);
// hiden input
acf_hidden_input(array('type' => 'hidden', 'name' => $field['name']));
// vars
$i = 0;
$li = '';
$all_checked = true;
// checkbox saves an array
$field['name'] .= '[]';
// foreach choices
if (!empty($field['choices'])) {
foreach ($field['choices'] as $value => $label) {
// increase counter
$i++;
// vars
$atts = array('type' => 'checkbox', 'id' => $field['id'], 'name' => $field['name'], 'value' => $value);
// is choice selected?
if (in_array($value, $field['value'])) {
$atts['checked'] = 'checked';
} else {
$all_checked = false;
}
if (isset($field['disabled']) && acf_in_array($value, $field['disabled'])) {
$atts['disabled'] = 'disabled';
}
// each input ID is generated with the $key, however, the first input must not use $key so that it matches the field's label for attribute
if ($i > 1) {
$atts['id'] .= '-' . $value;
}
// append HTML
$li .= '<li><label><input ' . acf_esc_attr($atts) . '/>' . $label . '</label></li>';
}
// toggle all
if ($field['toggle']) {
// vars
$label = __("Toggle All", 'acf');
$atts = array('type' => 'checkbox', 'class' => 'acf-checkbox-toggle');
// custom label
if (is_string($field['toggle'])) {
$label = $field['toggle'];
}
// checked
if ($all_checked) {
$atts['checked'] = 'checked';
}
// append HTML
$li = '<li><label><input ' . acf_esc_attr($atts) . '/>' . $label . '</label></li>' . $li;
}
}
// class
$field['class'] .= ' acf-checkbox-list';
$field['class'] .= $field['layout'] == 'horizontal' ? ' acf-hl' : ' acf-bl';
// return
echo '<ul ' . acf_esc_attr(array('class' => $field['class'])) . '>' . $li . '</ul>';
}
示例2: render_field
function render_field($field)
{
// decode value (convert to array)
$field['value'] = acf_force_type_array($field['value']);
// hiden input
acf_hidden_input(array('type' => 'hidden', 'name' => $field['name']));
// vars
$i = 0;
// class
$field['class'] .= ' acf-checkbox-list';
$field['class'] .= $field['layout'] == 'horizontal' ? ' acf-hl' : ' acf-bl';
// e
$e = '<ul ' . acf_esc_attr(array('class' => $field['class'])) . '>';
// checkbox saves an array
$field['name'] .= '[]';
// foreach choices
if (!empty($field['choices'])) {
foreach ($field['choices'] as $value => $label) {
// increase counter
$i++;
// vars
$atts = array('type' => 'checkbox', 'id' => $field['id'], 'name' => $field['name'], 'value' => $value);
if (in_array($value, $field['value'])) {
$atts['checked'] = 'checked';
}
if (isset($field['disabled']) && acf_in_array($value, $field['disabled'])) {
$atts['disabled'] = 'disabled';
}
// each input ID is generated with the $key, however, the first input must not use $key so that it matches the field's label for attribute
if ($i > 1) {
$atts['id'] .= '-' . $value;
}
$e .= '<li><label><input ' . acf_esc_attr($atts) . '/>' . $label . '</label></li>';
}
}
$e .= '</ul>';
// return
echo $e;
}
示例3: get_valid_relationship_field
function get_valid_relationship_field($field)
{
// force array
$field['post_type'] = acf_get_array($field['post_type']);
$field['taxonomy'] = acf_get_array($field['taxonomy']);
// remove 'all' from post_type
if (acf_in_array('all', $field['post_type'])) {
$field['post_type'] = array();
}
// remove 'all' from taxonomy
if (acf_in_array('all', $field['taxonomy'])) {
$field['taxonomy'] = array();
}
// save_format is now return_format
if (!empty($field['result_elements'])) {
$field['elements'] = acf_extract_var($field, 'result_elements');
}
// return
return $field;
}
示例4: render_field
function render_field($field)
{
// vars
$i = 0;
$checked = false;
// class
$field['class'] .= ' acf-radio-list';
$field['class'] .= $field['layout'] == 'horizontal' ? ' acf-hl' : ' acf-bl';
// e
$e = '<ul ' . acf_esc_attr(array('class' => $field['class'])) . '>';
// other choice
if ($field['other_choice']) {
// vars
$input = array('type' => 'text', 'name' => $field['name'], 'value' => '', 'disabled' => 'disabled');
// select other choice if value is not a valid choice
if (!isset($field['choices'][$field['value']])) {
unset($input['disabled']);
$input['value'] = $field['value'];
$field['value'] = 'other';
}
$field['choices']['other'] = '</label><input type="text" ' . acf_esc_attr($input) . ' /><label>';
}
// require choices
if (!empty($field['choices'])) {
// select first choice if value is not a valid choice
if (!isset($field['choices'][$field['value']])) {
$field['value'] = key($field['choices']);
}
// foreach choices
foreach ($field['choices'] as $value => $label) {
// increase counter
$i++;
// vars
$atts = array('type' => 'radio', 'id' => $field['id'], 'name' => $field['name'], 'value' => $value);
if (strval($value) === strval($field['value'])) {
$atts['checked'] = 'checked';
$checked = true;
}
if (isset($field['disabled']) && acf_in_array($value, $field['disabled'])) {
$atts['disabled'] = 'disabled';
}
// each input ID is generated with the $key, however, the first input must not use $key so that it matches the field's label for attribute
if ($i > 1) {
$atts['id'] .= '-' . $value;
}
$e .= '<li><label><input ' . acf_esc_attr($atts) . '/>' . $label . '</label></li>';
}
}
$e .= '</ul>';
echo $e;
}
示例5: get_valid_user_field
function get_valid_user_field($field)
{
// remove 'all' from roles
if (acf_in_array('all', $field['role'])) {
$field['role'] = '';
}
// field_type removed in favour of multiple
if (!empty($field['field_type'])) {
// extract vars
$field_type = acf_extract_var($field, 'field_type');
// multiple
if ($field_type === 'multi_select') {
$field['multiple'] = true;
}
}
// return
return $field;
}
示例6: render_field
function render_field($field)
{
// vars
$i = 0;
$e = '';
$ul = array('class' => 'acf-radio-list', 'data-allow_null' => $field['allow_null'], 'data-other_choice' => $field['other_choice']);
// append to class
$ul['class'] .= ' ' . ($field['layout'] == 'horizontal' ? 'acf-hl' : 'acf-bl');
$ul['class'] .= ' ' . $field['class'];
// select value
$checked = '';
$value = strval($field['value']);
// selected choice
if (isset($field['choices'][$value])) {
$checked = $value;
// custom choice
} elseif ($field['other_choice'] && $value !== '') {
$checked = 'other';
// allow null
} elseif ($field['allow_null']) {
// do nothing
// select first input by default
} else {
$checked = key($field['choices']);
}
// ensure $checked is a string (could be an int)
$checked = strval($checked);
// other choice
if ($field['other_choice']) {
// vars
$input = array('type' => 'text', 'name' => $field['name'], 'value' => '', 'disabled' => 'disabled', 'class' => 'acf-disabled');
// select other choice if value is not a valid choice
if ($checked === 'other') {
unset($input['disabled']);
$input['value'] = $field['value'];
}
// append other choice
$field['choices']['other'] = '</label><input type="text" ' . acf_esc_attr($input) . ' /><label>';
}
// bail early if no choices
if (empty($field['choices'])) {
return;
}
// hiden input
$e .= acf_get_hidden_input(array('name' => $field['name']));
// open
$e .= '<ul ' . acf_esc_attr($ul) . '>';
// foreach choices
foreach ($field['choices'] as $value => $label) {
// ensure value is a string
$value = strval($value);
$class = '';
// increase counter
$i++;
// vars
$atts = array('type' => 'radio', 'id' => $field['id'], 'name' => $field['name'], 'value' => $value);
// checked
if ($value === $checked) {
$atts['checked'] = 'checked';
$class = ' class="selected"';
}
// deisabled
if (isset($field['disabled']) && acf_in_array($value, $field['disabled'])) {
$atts['disabled'] = 'disabled';
}
// id (use crounter for each input)
if ($i > 1) {
$atts['id'] .= '-' . $value;
}
// append
$e .= '<li><label' . $class . '><input ' . acf_esc_attr($atts) . '/>' . $label . '</label></li>';
}
// close
$e .= '</ul>';
// return
echo $e;
}
示例7: get_post_title
function get_post_title($post, $field, $post_id = 0, $is_search = 0)
{
// get post_id
if (!$post_id) {
$post_id = acf_get_form_data('post_id');
}
// vars
$title = acf_get_post_title($post, $is_search);
// featured_image
if (acf_in_array('featured_image', $field['elements'])) {
// vars
$class = 'thumbnail';
$thumbnail = acf_get_post_thumbnail($post->ID, array(17, 17));
// icon
if ($thumbnail['type'] == 'icon') {
$class .= ' -' . $thumbnail['type'];
}
// append
$title = '<div class="' . $class . '">' . $thumbnail['html'] . '</div>' . $title;
}
// filters
$title = apply_filters('acf/fields/relationship/result', $title, $post, $field, $post_id);
$title = apply_filters('acf/fields/relationship/result/name=' . $field['_name'], $title, $post, $field, $post_id);
$title = apply_filters('acf/fields/relationship/result/key=' . $field['key'], $title, $post, $field, $post_id);
// return
return $title;
}