当前位置: 首页>>代码示例>>PHP>>正文


PHP acf_parse_args函数代码示例

本文整理汇总了PHP中acf_parse_args函数的典型用法代码示例。如果您正苦于以下问题:PHP acf_parse_args函数的具体用法?PHP acf_parse_args怎么用?PHP acf_parse_args使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了acf_parse_args函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: get_choices

 function get_choices($options = array())
 {
     // defaults
     $options = acf_parse_args($options, array('post_id' => 0, 's' => '', 'field_key' => ''));
     // vars
     $r = array();
     $args = array('hide_empty' => false);
     // load field
     $field = acf_get_field($options['field_key']);
     if (!$field) {
         return false;
     }
     // search
     if ($options['s']) {
         $args['search'] = $options['s'];
     }
     // filters
     $args = apply_filters('acf/fields/taxonomy/query', $args, $field, $options['post_id']);
     $args = apply_filters('acf/fields/taxonomy/query/name=' . $field['name'], $args, $field, $options['post_id']);
     $args = apply_filters('acf/fields/taxonomy/query/key=' . $field['key'], $args, $field, $options['post_id']);
     // get terms
     $terms = get_terms($field['taxonomy'], $args);
     // sort into hierachial order!
     if (is_taxonomy_hierarchical($field['taxonomy'])) {
         // get parent
         $parent = acf_maybe_get($args, 'parent', 0);
         $parent = acf_maybe_get($args, 'child_of', $parent);
         // this will fail if a search has taken place because parents wont exist
         if (empty($args['search'])) {
             $terms = _get_term_children($parent, $terms, $field['taxonomy']);
         }
     }
     /// append to r
     foreach ($terms as $term) {
         // add to json
         $r[] = array('id' => $term->term_id, 'text' => $this->get_term_title($term, $field, $options['post_id']));
     }
     // return
     return $r;
 }
开发者ID:brycefrees,项目名称:nddLive,代码行数:40,代码来源:taxonomy.php

示例2: ajax_layout_title

 function ajax_layout_title()
 {
     // options
     $options = acf_parse_args($_POST, array('post_id' => 0, 'i' => 0, 'field_key' => '', 'nonce' => '', 'layout' => '', 'acf' => array()));
     // load field
     $field = acf_get_field($options['field_key']);
     if (!$field) {
         die;
     }
     // vars
     $layout = false;
     foreach ($field['layouts'] as $k => $layout) {
         if ($layout['name'] === $options['layout']) {
             break;
         }
     }
     // bail ealry if no layout
     if (!$layout) {
         die;
     }
     // value
     // this flexible content field may be a sub field so it is important to
     // loop though all $_POST data to find thi's field's row value
     $value = $options['acf'];
     while (is_array($value)) {
         // get first key
         $k = key($value);
         // update value
         $value = array_pop($value[$k]);
         // stop looking if we have found the correct field's value
         if ($k === $options['field_key']) {
             break;
         }
     }
     // title
     $title = $this->get_layout_title($field, $layout, $options['i'], $value);
     // echo
     echo $title;
     die;
 }
开发者ID:cimocimocimo,项目名称:staydrysystems.com,代码行数:40,代码来源:flexible-content.php

示例3: acf_get_valid_options_page

function acf_get_valid_options_page($page = '')
{
    // allow for string
    if (empty($page)) {
        $page = array('page_title' => __('Options', 'acf'), 'menu_title' => __('Options', 'acf'), 'menu_slug' => 'acf-options');
    } elseif (is_string($page)) {
        $page_title = $page;
        $page = array('page_title' => $page_title, 'menu_title' => $page_title);
    }
    // defaults
    $page = acf_parse_args($page, array('page_title' => '', 'menu_title' => '', 'menu_slug' => '', 'capability' => 'edit_posts', 'parent_slug' => '', 'position' => false, 'icon_url' => false, 'redirect' => true, 'post_id' => 'options', 'autoload' => false));
    // ACF4 compatibility
    $migrate = array('title' => 'page_title', 'menu' => 'menu_title', 'slug' => 'menu_slug', 'parent' => 'parent_slug');
    foreach ($migrate as $old => $new) {
        if (!empty($page[$old])) {
            $page[$new] = acf_extract_var($page, $old);
        }
    }
    // page_title (allows user to define page with just page_title or title)
    if (empty($page['menu_title'])) {
        $page['menu_title'] = $page['page_title'];
    }
    // menu_slug
    if (empty($page['menu_slug'])) {
        $page['menu_slug'] = 'acf-options-' . sanitize_title($page['menu_title']);
    }
    // return
    return $page;
}
开发者ID:de190909,项目名称:WPTest,代码行数:29,代码来源:api-options-page.php

示例4: ajax_query

 function ajax_query()
 {
     // options
     $options = acf_parse_args($_POST, array('post_id' => 0, 's' => '', 'field_key' => '', 'nonce' => ''));
     // load field
     $field = acf_get_field($options['field_key']);
     if (!$field) {
         die;
     }
     // vars
     $r = array();
     $s = false;
     // search
     if ($options['s'] !== '') {
         // search may be integer
         $s = strval($options['s']);
         // strip slashes
         $s = wp_unslash($s);
     }
     // loop through choices
     if (!empty($field['choices'])) {
         foreach ($field['choices'] as $k => $v) {
             // if searching, but doesn't exist
             if ($s !== false && stripos($v, $s) === false) {
                 continue;
             }
             // append
             $r[] = array('id' => $k, 'text' => strval($v));
         }
     }
     // return JSON
     echo json_encode($r);
     die;
 }
开发者ID:SayenkoDesign,项目名称:bushcooking.com,代码行数:34,代码来源:select.php

示例5: ajax_upgrade

 function ajax_upgrade()
 {
     // options
     $options = acf_parse_args($_POST, array('version' => '', 'nonce' => ''));
     // validate
     if (!wp_verify_nonce($options['nonce'], 'acf_nonce')) {
         wp_send_json_error();
     }
     // vars
     $path = acf_get_path("admin/updates/{$options['version']}.php");
     // load version
     if (!file_exists($path)) {
         wp_send_json_error();
     }
     // load any errors / feedback from update
     ob_start();
     // include
     include $path;
     // get feedback
     $feedback = ob_get_clean();
     // update successful
     update_option('acf_version', $options['version']);
     // check for relevant updates. If none are found, update this to the plugin version
     $updates = acf_get_updates();
     if (empty($updates)) {
         update_option('acf_version', acf_get_setting('version'));
     }
     // return
     wp_send_json_success(array('feedback' => $feedback));
 }
开发者ID:dleatherman,项目名称:timbangular-js,代码行数:30,代码来源:update.php

示例6: acf_get_valid_field

function acf_get_valid_field($field = false)
{
    // $field must be an array
    if (!is_array($field)) {
        $field = array();
    }
    // bail ealry if field_name exists (only run this function once)
    if (!empty($field['_valid'])) {
        return $field;
    }
    // defaults
    $field = acf_parse_args($field, array('ID' => 0, 'key' => '', 'label' => '', 'name' => '', 'prefix' => '', 'type' => 'text', 'value' => null, 'menu_order' => 0, 'instructions' => '', 'required' => 0, 'id' => '', 'class' => '', 'conditional_logic' => 0, 'parent' => 0, '_name' => '', '_input' => '', '_valid' => 0));
    // _name
    $field['_name'] = $field['name'];
    // translate
    foreach (array('label', 'instructions') as $s) {
        $field[$s] = __($field[$s]);
    }
    // field specific defaults
    $field = apply_filters("acf/get_valid_field", $field);
    $field = apply_filters("acf/get_valid_field/type={$field['type']}", $field);
    // field is now valid
    $field['_valid'] = 1;
    // return
    return $field;
}
开发者ID:spiff888,项目名称:rockharbor,代码行数:26,代码来源:api-field.php

示例7: ajax_query

 function ajax_query()
 {
     // options
     $options = acf_parse_args($_GET, array('post_id' => 0, 's' => '', 'field_key' => '', 'nonce' => ''));
     // load field
     $field = acf_get_field($options['field_key']);
     if (!$field) {
         die;
     }
     // vars
     $r = array();
     // strip slashes
     $options['s'] = wp_unslash($options['s']);
     if (!empty($field['choices'])) {
         foreach ($field['choices'] as $k => $v) {
             // search
             if ($options['s'] && stripos($v, $options['s']) === false) {
                 continue;
             }
             // append
             $r[] = array('id' => $k, 'text' => strval($v));
         }
     }
     // return JSON
     echo json_encode($r);
     die;
 }
开发者ID:pellio11,项目名称:ns-select-project,代码行数:27,代码来源:select.php

示例8: acf_get_valid_field_group

function acf_get_valid_field_group($field_group = false)
{
    // parse in defaults
    $field_group = acf_parse_args($field_group, array('ID' => 0, 'key' => '', 'title' => '', 'fields' => array(), 'location' => array(), 'menu_order' => 0, 'position' => 'normal', 'style' => 'default', 'label_placement' => 'top', 'instruction_placement' => 'label', 'hide_on_screen' => array()));
    // filter
    $field_group = apply_filters('acf/get_valid_field_group', $field_group);
    // return
    return $field_group;
}
开发者ID:kochira,项目名称:competstrat,代码行数:9,代码来源:api-field-group.php

示例9: update_user_setting

 function update_user_setting()
 {
     // options
     $options = acf_parse_args($_POST, array('name' => '', 'value' => '', 'nonce' => ''));
     // validate
     if (!wp_verify_nonce($options['nonce'], 'acf_nonce') || empty($options['name'])) {
         die('0');
     }
     // upadte setting
     acf_update_user_setting($options['name'], $options['value']);
     // return
     die('1');
 }
开发者ID:slavic18,项目名称:cats,代码行数:13,代码来源:ajax.php

示例10: set_data

 function set_data($data)
 {
     // defaults
     $data = acf_parse_args($data, array('post_id' => 0, 'nonce' => 'post', 'validation' => 1, 'ajax' => 0));
     // update
     $this->data = $data;
     // enqueue uploader if page allows AJAX fields to appear
     if ($data['ajax']) {
         add_action($this->admin_footer, 'acf_enqueue_uploader', 1);
     }
     // return
     return $data;
 }
开发者ID:ashenkar,项目名称:sanga,代码行数:13,代码来源:input.php

示例11: ajax_query

 function ajax_query()
 {
     // options
     $options = acf_parse_args($_GET, array('post_id' => 0, 's' => '', 'field_key' => '', 'nonce' => ''));
     // validate
     if (!wp_verify_nonce($options['nonce'], 'acf_nonce')) {
         die;
     }
     // vars
     $r = array();
     $args = array('hide_empty' => false);
     // load field
     $field = acf_get_field($options['field_key']);
     if (!$field) {
         die;
     }
     // search
     if ($options['s']) {
         $args['search'] = $options['s'];
     }
     // filters
     $args = apply_filters('acf/fields/taxonomy/query', $args, $field, $options['post_id']);
     $args = apply_filters('acf/fields/taxonomy/query/name=' . $field['name'], $args, $field, $options['post_id']);
     $args = apply_filters('acf/fields/taxonomy/query/key=' . $field['key'], $args, $field, $options['post_id']);
     // get terms
     $terms = get_terms($field['taxonomy'], $args);
     // sort into hierachial order!
     if (is_taxonomy_hierarchical($field['taxonomy'])) {
         // this will fail if a search has taken place because parents wont exist
         if (empty($args['search'])) {
             $terms = _get_term_children(0, $terms, $field['taxonomy']);
         }
     }
     /// append to r
     foreach ($terms as $term) {
         // add to json
         $r[] = array('id' => $term->term_id, 'text' => $this->get_term_title($term, $field, $options['post_id']));
     }
     // return JSON
     echo json_encode($r);
     die;
 }
开发者ID:pellio11,项目名称:ns-select-project,代码行数:42,代码来源:taxonomy.php

示例12: ajax_search

 function ajax_search()
 {
     // options
     $args = acf_parse_args($_POST, array('s' => '', 'nonce' => '', 'width' => 0, 'height' => 0));
     // width and height
     if (!$args['width']) {
         $args['width'] = $this->default_values['width'];
     }
     if (!$args['height']) {
         $args['height'] = $this->default_values['height'];
     }
     // validate
     if (!wp_verify_nonce($args['nonce'], 'acf_nonce')) {
         die;
     }
     // get oembed
     echo $this->wp_oembed_get($args['s'], $args['width'], $args['height']);
     // die
     die;
 }
开发者ID:rousnay,项目名称:lighthouse,代码行数:20,代码来源:oembed.php

示例13: ajax_query

 function ajax_query()
 {
     // validate
     if (!acf_verify_ajax()) {
         die;
     }
     // disable field to allow clone fields to appear selectable
     acf_disable_filter('clone');
     // options
     $options = acf_parse_args($_POST, array('post_id' => 0, 'paged' => 0, 's' => '', 'title' => '', 'fields' => array()));
     // vars
     $results = array();
     $s = false;
     $i = -1;
     $limit = 20;
     $range_start = $limit * ($options['paged'] - 1);
     //	0,	20,	40
     $range_end = $range_start + ($limit - 1);
     //	19,	39,	59
     // search
     if ($options['s'] !== '') {
         // strip slashes (search may be integer)
         $s = wp_unslash(strval($options['s']));
     }
     // load groups
     $field_groups = acf_get_field_groups();
     $field_group = false;
     // bail early if no field groups
     if (empty($field_groups)) {
         die;
     }
     // move current field group to start
     foreach (array_keys($field_groups) as $j) {
         // check ID
         if ($field_groups[$j]['ID'] !== $options['post_id']) {
             continue;
         }
         // extract field group and move to start
         $field_group = acf_extract_var($field_groups, $j);
         // field group found, stop looking
         break;
     }
     // if field group was not found, this is a new field group (not yet saved)
     if (!$field_group) {
         $field_group = array('ID' => $options['post_id'], 'title' => $options['title'], 'key' => '');
     }
     // move current field group to start of list
     array_unshift($field_groups, $field_group);
     // loop
     foreach ($field_groups as $field_group) {
         // vars
         $fields = false;
         $data = array('text' => $field_group['title'], 'children' => array());
         // get fields
         if ($field_group['ID'] == $options['post_id']) {
             $fields = $options['fields'];
         } else {
             $fields = acf_get_fields($field_group);
             $fields = acf_prepare_fields_for_import($fields);
         }
         // bail early if no fields
         if (!$fields) {
             continue;
         }
         // populate children
         $children = array();
         $children[] = $field_group['key'];
         foreach ($fields as $field) {
             $children[] = $field['key'];
         }
         // loop
         foreach ($children as $child) {
             // bail ealry if no key (fake field group or corrupt field)
             if (!$child) {
                 continue;
             }
             // vars
             $text = false;
             // bail early if is search, and $text does not contain $s
             if ($s !== false) {
                 // get early
                 $text = $this->get_clone_setting_choice($child);
                 // search
                 if (stripos($text, $s) === false) {
                     continue;
                 }
             }
             // $i
             $i++;
             // bail early if $i is out of bounds
             if ($i < $range_start || $i > $range_end) {
                 continue;
             }
             // load text
             if ($text === false) {
                 $text = $this->get_clone_setting_choice($child);
             }
             // append
             $data['children'][] = array('id' => $child, 'text' => $text);
         }
//.........这里部分代码省略.........
开发者ID:developmentDM2,项目名称:Whohaha,代码行数:101,代码来源:clone.php

示例14: _e

<div class="wrap acf-settings-wrap">
	
	<h2><?php 
_e("Add-ons", 'acf');
?>
</h2>
	
	<div class="add-ons-list acf-cf">
		
		<?php 
if (!empty($json)) {
    ?>
			
			<?php 
    foreach ($json as $addon) {
        $addon = acf_parse_args($addon, array("title" => "", "slug" => "", "description" => "", "thumbnail" => "", "url" => "", "btn" => __("Download & Install", 'acf'), "btn_color" => ""));
        ?>
				
				<div class="acf-box add-on add-on-<?php 
        echo $addon['slug'];
        ?>
">
					
					<div class="thumbnail">
						<a target="_blank" href="<?php 
        echo $addon['url'];
        ?>
">
							<img src="<?php 
        echo $addon['thumbnail'];
        ?>
开发者ID:slavic18,项目名称:cats,代码行数:31,代码来源:settings-addons.php

示例15: acf_form

function acf_form($args = array())
{
    // vars
    $url = acf_get_current_url();
    // defaults
    $args = wp_parse_args($args, array('id' => 'acf-form', 'post_id' => false, 'new_post' => false, 'field_groups' => false, 'fields' => false, 'post_title' => false, 'post_content' => false, 'form' => true, 'form_attributes' => array(), 'return' => add_query_arg('updated', 'true', $url), 'html_before_fields' => '', 'html_after_fields' => '', 'submit_value' => __("Update", 'acf'), 'updated_message' => __("Post updated", 'acf'), 'label_placement' => 'top', 'instruction_placement' => 'label', 'field_el' => 'div', 'uploader' => 'wp'));
    $args['form_attributes'] = wp_parse_args($args['form_attributes'], array('id' => 'post', 'class' => '', 'action' => '', 'method' => 'post'));
    // filter post_id
    $args['post_id'] = acf_get_valid_post_id($args['post_id']);
    // load values from this post
    $post_id = $args['post_id'];
    // new post?
    if ($post_id == 'new_post') {
        // dont load values
        $post_id = false;
        // new post defaults
        $args['new_post'] = acf_parse_args($args['new_post'], array('post_type' => 'post', 'post_status' => 'draft'));
    }
    // attributes
    $args['form_attributes']['class'] .= ' acf-form';
    // vars
    $field_groups = array();
    $fields = array();
    // post_title
    if ($args['post_title']) {
        $fields[] = acf_get_valid_field(array('name' => '_post_title', 'label' => 'Title', 'type' => 'text', 'value' => $post_id ? get_post_field('post_title', $post_id) : '', 'required' => true));
    }
    // post_content
    if ($args['post_content']) {
        $fields[] = acf_get_valid_field(array('name' => '_post_content', 'label' => 'Content', 'type' => 'wysiwyg', 'value' => $post_id ? get_post_field('post_content', $post_id) : ''));
    }
    // specific fields
    if ($args['fields']) {
        foreach ($args['fields'] as $selector) {
            // append field ($strict = false to allow for better compatibility with field names)
            $fields[] = acf_maybe_get_field($selector, $post_id, false);
        }
    } elseif ($args['field_groups']) {
        foreach ($args['field_groups'] as $selector) {
            $field_groups[] = acf_get_field_group($selector);
        }
    } elseif ($args['post_id'] == 'new_post') {
        $field_groups = acf_get_field_groups(array('post_type' => $args['new_post']['post_type']));
    } else {
        $field_groups = acf_get_field_groups(array('post_id' => $args['post_id']));
    }
    //load fields based on field groups
    if (!empty($field_groups)) {
        foreach ($field_groups as $field_group) {
            $field_group_fields = acf_get_fields($field_group);
            if (!empty($field_group_fields)) {
                foreach (array_keys($field_group_fields) as $i) {
                    $fields[] = acf_extract_var($field_group_fields, $i);
                }
            }
        }
    }
    // updated message
    if (!empty($_GET['updated']) && $args['updated_message']) {
        echo '<div id="message" class="updated"><p>' . $args['updated_message'] . '</p></div>';
    }
    // uploader (always set incase of multiple forms on the page)
    acf_update_setting('uploader', $args['uploader']);
    // display form
    if ($args['form']) {
        ?>

	
	<form <?php 
        acf_esc_attr_e($args['form_attributes']);
        ?>
>
	
	<?php 
    }
    // render post data
    acf_form_data(array('post_id' => $args['post_id'], 'nonce' => 'acf_form'));
    ?>

	<div class="acf-hidden">
		<?php 
    acf_hidden_input(array('name' => '_acf_form', 'value' => base64_encode(json_encode($args))));
    ?>

	</div>
	<div class="acf-fields acf-form-fields -<?php 
    echo $args['label_placement'];
    ?>
">
	
		<?php 
    // html before fields
    echo $args['html_before_fields'];
    // render
    acf_render_fields($post_id, $fields, $args['field_el'], $args['instruction_placement']);
    // html after fields
    echo $args['html_after_fields'];
    ?>

	
//.........这里部分代码省略.........
开发者ID:de190909,项目名称:WPTest,代码行数:101,代码来源:api-template.php


注:本文中的acf_parse_args函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。