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


PHP acf_get_valid_post_id函数代码示例

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


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

示例1: __construct

 public function __construct($args = array())
 {
     //Some of these args will be changed in the future, not all are required at this point.
     $this->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, 'return' => add_query_arg('updated', 'true', acf_get_current_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'));
     // filter post_id
     $this->args['post_id'] = acf_get_valid_post_id($this->args['post_id']);
     // load values from this post
     $this->post_id = $this->args['post_id'];
     if ($this->post_id == 'new_post') {
         throw new Exception(__('Post ID must be set when using the acf_view function', 'acf-views'));
     }
     //This will eventually be moved from an action into a better object oriented rendering method.
     add_action("acf/views_render_field", array($this, 'on_render_field'), 0, 1);
 }
开发者ID:NikolaGrdanjski,项目名称:acf-views,代码行数:14,代码来源:acf-views-view.php

示例2: acf_maybe_get_field

function acf_maybe_get_field($selector, $post_id = false, $strict = true)
{
    // complete init
    // this function may be used in a theme file before the init action has been run
    acf()->init();
    // vars
    $field_name = false;
    // get valid post_id
    $post_id = acf_get_valid_post_id($post_id);
    // load field reference if not a field_key
    if (!acf_is_field_key($selector)) {
        // save selector as field_name (could be sub field name)
        $field_name = $selector;
        // get reference
        $field_key = acf_get_field_reference($selector, $post_id);
        if ($field_key) {
            $selector = $field_key;
        } elseif ($strict) {
            return false;
        }
    }
    // get field key
    $field = acf_get_field($selector);
    // bail early if no field
    if (!$field) {
        return false;
    }
    // Override name - allows the $selector to be a sub field (images_0_image)
    if ($field_name) {
        $field['name'] = $field_name;
    }
    // return
    return $field;
}
开发者ID:coreymargulis,项目名称:karenmargulis,代码行数:34,代码来源:api-field.php

示例3: get_acf_field_group_filters

 /**
  * Get field group filters based on active screen.
  */
 public function get_acf_field_group_filters()
 {
     global $post, $pagenow, $typenow, $plugin_page;
     $filter = array();
     if ($pagenow === 'post.php' || $pagenow === 'post-new.php') {
         if ($typenow !== 'acf') {
             $filter['post_id'] = $post->ID;
             $filter['post_type'] = $typenow;
         }
     } elseif ($pagenow === 'admin.php' && isset($plugin_page)) {
         if (acf_get_options_page($plugin_page)) {
             $filter['post_id'] = acf_get_valid_post_id('options');
         }
     } elseif ($pagenow === 'edit-tags.php' && isset($_GET['taxonomy'])) {
         $filter['taxonomy'] = filter_var($_GET['taxonomy'], FILTER_SANITIZE_STRING);
     } elseif ($pagenow === 'profile.php') {
         $filter['user_id'] = get_current_user_id();
         $filter['user_form'] = 'edit';
     } elseif ($pagenow === 'user-edit.php' && isset($_GET['user_id'])) {
         $filter['user_id'] = filter_var($_GET['user_id'], FILTER_SANITIZE_NUMBER_INT);
         $filter['user_form'] = 'edit';
     } elseif ($pagenow === 'user-new.php') {
         $filter['user_id'] = 'new';
         $filter['user_form'] = 'edit';
     } elseif ($pagenow === 'media.php' || $pagenow === 'upload.php') {
         $filter['attachment'] = 'All';
     } elseif (acf_is_screen('widgets') || acf_is_screen('customize')) {
         $filter['widget'] = 'all';
     }
     return $filter;
 }
开发者ID:AndreyLanko,项目名称:perevorot-prozorro-wp,代码行数:34,代码来源:acf.php

示例4: acf_filter_post_id

function acf_filter_post_id($post_id)
{
    return acf_get_valid_post_id($post_id);
}
开发者ID:de190909,项目名称:WPTest,代码行数:4,代码来源:api-template.php

示例5: render_meta_box

    function render_meta_box($post, $args)
    {
        // extract args
        extract($args);
        // all variables from the add_meta_box function
        extract($args);
        // all variables from the args argument
        // vars
        $o = array('id' => $id, 'key' => $field_group['key'], 'style' => $field_group['style'], 'edit_url' => '', 'edit_title' => __('Edit field group', 'acf'), 'visibility' => true);
        // vars
        $post_id = acf_get_valid_post_id('options');
        // load fields
        $fields = acf_get_fields($field_group);
        // render
        if ($field_group['label_placement'] == 'left') {
            ?>
			<table class="acf-table">
				<tbody>
					<?php 
            acf_render_fields($post_id, $fields, 'tr', $field_group['instruction_placement']);
            ?>
				</tbody>
			</table>
			<?php 
        } else {
            acf_render_fields($post_id, $fields, 'div', $field_group['instruction_placement']);
        }
        // edit_url
        if ($field_group['ID'] && acf_current_user_can_admin()) {
            $o['edit_url'] = admin_url('post.php?post=' . $field_group['ID'] . '&action=edit');
        }
        ?>
<script type="text/javascript">
if( typeof acf !== 'undefined' ) {
		
	acf.postbox.render(<?php 
        echo json_encode($o);
        ?>
);	

}
</script>
<?php 
    }
开发者ID:bmavus,项目名称:wp-theme-blank,代码行数:44,代码来源:options-page.php

示例6: get_field_choice_label

 function get_field_choice_label($selector, $value, $post_id = false)
 {
     $post_id = acf_get_valid_post_id($post_id);
     $field = acf_maybe_get_field($selector, $post_id);
     if (!$field || !isset($field['choices']) || !isset($field['choices'][$value])) {
         return NULL;
     }
     return $field['choices'][$value];
 }
开发者ID:Hube2,项目名称:acf-filters-and-functions,代码行数:9,代码来源:acf-field-label-functions.php

示例7: render_form

        function render_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', 'honeypot' => true));
            $args['form_attributes'] = wp_parse_args($args['form_attributes'], array('id' => $args['id'], 'class' => 'acf-form', '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'] = wp_parse_args($args['new_post'], array('post_type' => 'post', 'post_status' => 'draft'));
            }
            // register local fields
            foreach ($this->fields as $k => $field) {
                acf_add_local_field($field);
            }
            // vars
            $field_groups = array();
            $fields = array();
            // post_title
            if ($args['post_title']) {
                // load local field
                $_post_title = acf_get_field('_post_title');
                $_post_title['value'] = $post_id ? get_post_field('post_title', $post_id) : '';
                // append
                $fields[] = $_post_title;
            }
            // post_content
            if ($args['post_content']) {
                // load local field
                $_post_content = acf_get_field('_post_content');
                $_post_content['value'] = $post_id ? get_post_field('post_content', $post_id) : '';
                // append
                $fields[] = $_post_content;
            }
            // 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($args['new_post']);
            } 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);
                        }
                    }
                }
            }
            // honeypot
            if ($args['honeypot']) {
                $fields[] = acf_get_field('_validate_email');
            }
            // 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'];
//.........这里部分代码省略.........
开发者ID:rmikeska,项目名称:ushipnetwork,代码行数:101,代码来源:api-template.php

示例8: render_meta_box

    function render_meta_box($post, $args)
    {
        // extract args
        extract($args);
        // all variables from the add_meta_box function
        extract($args);
        // all variables from the args argument
        // vars
        $post_id = acf_get_valid_post_id('options');
        $class = 'acf-postbox ' . $field_group['style'];
        $toggle_class = 'acf-postbox-toggle';
        // load fields
        $fields = acf_get_fields($field_group);
        // render
        if ($field_group['label_placement'] == 'left') {
            ?>
			<table class="acf-table">
				<tbody>
					<?php 
            acf_render_fields($post_id, $fields, 'tr', $field_group['instruction_placement']);
            ?>
				</tbody>
			</table>
			<?php 
        } else {
            acf_render_fields($post_id, $fields, 'div', $field_group['instruction_placement']);
        }
        // inline script
        ?>
		<div class="acf-hidden">
			<script type="text/javascript">
			(function($) {
				
				$('#<?php 
        echo $id;
        ?>
').addClass('<?php 
        echo $class;
        ?>
').removeClass('hide-if-js');
				$('#adv-settings label[for="<?php 
        echo $id;
        ?>
-hide"]').addClass('<?php 
        echo $toggle_class;
        ?>
');
				
			})(jQuery);	
			</script>
		</div>
		<?php 
    }
开发者ID:spiff888,项目名称:rockharbor,代码行数:53,代码来源:options-page.php

示例9: postbox_acf

    function postbox_acf($post, $args)
    {
        // extract args
        extract($args);
        // all variables from the add_meta_box function
        extract($args);
        // all variables from the args argument
        // vars
        $o = array('id' => $id, 'key' => $field_group['key'], 'style' => $field_group['style'], 'label' => $field_group['label_placement'], 'edit_url' => '', 'edit_title' => __('Edit field group', 'acf'), 'visibility' => true);
        // get post_id (allow lang modification)
        $post_id = acf_get_valid_post_id($this->page['post_id']);
        // edit_url
        if ($field_group['ID'] && acf_current_user_can_admin()) {
            $o['edit_url'] = admin_url('post.php?post=' . $field_group['ID'] . '&action=edit');
        }
        // load fields
        $fields = acf_get_fields($field_group);
        // render
        acf_render_fields($post_id, $fields, 'div', $field_group['instruction_placement']);
        ?>
<script type="text/javascript">
if( typeof acf !== 'undefined' ) {
		
	acf.postbox.render(<?php 
        echo json_encode($o);
        ?>
);	

}
</script>
<?php 
    }
开发者ID:rmikeska,项目名称:ushipnetwork,代码行数:32,代码来源:options-page.php

示例10: live_edit

function live_edit($fields = false, $post_id = false)
{
    // validate fields
    if (!$fields) {
        return false;
    }
    // filter post_id
    $post_id = acf_get_valid_post_id($post_id);
    // turn array into string
    if (is_array($fields)) {
        $fields = implode(',', $fields);
    }
    // remove any white spaces from $fields
    $fields = str_replace(' ', '', $fields);
    // build atts
    acf_esc_attr_e(array('data-live-edit-id' => $post_id . '-' . str_replace(',', '-', $fields), 'data-live-edit-fields' => $fields, 'data-live-edit-post_id' => $post_id));
}
开发者ID:kmcaloon,项目名称:acf-frontend-editor,代码行数:17,代码来源:live-edit-v5.php


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