本文整理汇总了PHP中acf_form_data函数的典型用法代码示例。如果您正苦于以下问题:PHP acf_form_data函数的具体用法?PHP acf_form_data怎么用?PHP acf_form_data使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了acf_form_data函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: edit_widget
function edit_widget($widget, $return, $instance)
{
// vars
$post_id = 0;
if ($widget->number !== '__i__') {
$post_id = "widget_{$widget->id}";
}
// get field groups
$field_groups = acf_get_field_groups(array('widget' => $widget->id_base));
// render
if (!empty($field_groups)) {
// render post data
acf_form_data(array('post_id' => $post_id, 'nonce' => 'widget'));
foreach ($field_groups as $field_group) {
$fields = acf_get_fields($field_group);
acf_render_fields($post_id, $fields, 'div', 'field');
}
if ($widget->updated) {
?>
<script type="text/javascript">
(function($) {
acf.do_action('append', $('[id^="widget"][id$="<?php
echo $widget->id;
?>
"]') );
})(jQuery);
</script>
<?php
}
}
}
示例2: 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'];
?>
//.........这里部分代码省略.........
示例3: extract
// extract
extract($args);
?>
<div class="wrap acf-settings-wrap">
<h2><?php
echo $page['page_title'];
?>
</h2>
<form id="post" method="post" name="post">
<?php
// render post data
acf_form_data(array('post_id' => 'options', 'nonce' => 'options'));
wp_nonce_field('meta-box-order', 'meta-box-order-nonce', false);
wp_nonce_field('closedpostboxes', 'closedpostboxesnonce', false);
?>
<div id="poststuff">
<div id="post-body" class="metabox-holder columns-<?php
echo 1 == get_current_screen()->get_columns() ? '1' : '2';
?>
">
<div id="postbox-container-1" class="postbox-container">
<?php
do_meta_boxes('acf_options_page', 'side', null);
示例4: edit_term
function edit_term($term, $taxonomy)
{
// vars
$post_id = "{$taxonomy}_{$term->term_id}";
$args = array('taxonomy' => $taxonomy);
// update vars
$this->form = '#edittag';
// get field groups
$field_groups = acf_get_field_groups($args);
// render
if (!empty($field_groups)) {
acf_form_data(array('post_id' => $post_id, 'nonce' => 'taxonomy'));
foreach ($field_groups as $field_group) {
$fields = acf_get_fields($field_group);
?>
<?php
if ($field_group['style'] == 'default') {
?>
<h3><?php
echo $field_group['title'];
?>
</h3>
<?php
}
?>
<table class="form-table">
<tbody>
<?php
acf_render_fields($post_id, $fields, 'tr', 'field');
?>
</tbody>
</table>
<?php
}
}
}
示例5: edit_attachment
function edit_attachment($form_fields, $post)
{
// vars
$el = 'tr';
$post_id = $post->ID;
$args = array('attachment' => 'All');
// $el
if ($this->validate_page()) {
//$el = 'div';
}
// get field groups
$field_groups = acf_get_field_groups($args);
// render
if (!empty($field_groups)) {
// get acf_form_data
ob_start();
acf_form_data(array('post_id' => $post_id, 'nonce' => 'attachment'));
if ($this->validate_page()) {
echo '<style type="text/css">
.compat-attachment-fields,
.compat-attachment-fields > tbody,
.compat-attachment-fields > tbody > tr,
.compat-attachment-fields > tbody > tr > th,
.compat-attachment-fields > tbody > tr > td {
display: block;
}
tr.acf-field {
display: block;
margin: 0 0 13px;
}
tr.acf-field td.acf-label {
display: block;
margin: 0;
}
tr.acf-field td.acf-input {
display: block;
margin: 0;
}
</style>';
}
// $el
//if( $el == 'tr' ) {
echo '</td></tr>';
//}
foreach ($field_groups as $field_group) {
$fields = acf_get_fields($field_group);
acf_render_fields($post_id, $fields, $el, 'field');
}
// $el
//if( $el == 'tr' ) {
echo '<tr class="compat-field-acf-blank"><td>';
//}
$html = ob_get_contents();
ob_end_clean();
$form_fields['acf-form-data'] = array('label' => '', 'input' => 'html', 'html' => $html);
}
// return
return $form_fields;
}
示例6: add_comment
function add_comment()
{
// vars
$post_id = "comment_0";
// get field groups
$field_groups = acf_get_field_groups(array('comment' => 'new'));
if (!empty($field_groups)) {
// render post data
acf_form_data(array('post_id' => $post_id, 'nonce' => 'comment'));
foreach ($field_groups as $field_group) {
$fields = acf_get_fields($field_group);
?>
<table class="form-table">
<tbody>
<?php
acf_render_fields($post_id, $fields, 'tr', 'field');
?>
</tbody>
</table>
<?php
}
}
}
示例7: edit_form_after_title
function edit_form_after_title()
{
// globals
global $post, $wp_meta_boxes;
// render post data
acf_form_data(array('post_id' => $this->post_id, 'nonce' => 'post', 'ajax' => 1));
// render
do_meta_boxes(get_current_screen(), 'acf_after_title', $post);
// clean up
unset($wp_meta_boxes['post']['acf_after_title']);
}
示例8: edit_form_after_editor
function edit_form_after_editor()
{
// render post data
acf_form_data(array('post_id' => $this->post_id, 'nonce' => 'post', 'ajax' => 1));
}
示例9: render
function render($user_id, $user_form, $el = 'tr')
{
// vars
$post_id = "user_{$user_id}";
$show_title = true;
// show title
if ($user_form === 'register') {
$show_title = false;
}
// args
$args = array('user_id' => 'new', 'user_form' => $user_form);
if ($user_id) {
$args['user_id'] = $user_id;
}
// get field groups
$field_groups = acf_get_field_groups($args);
// bail early if no field groups
if (empty($field_groups)) {
return;
}
// form data
acf_form_data(array('post_id' => $post_id, 'nonce' => 'user'));
// loop
foreach ($field_groups as $field_group) {
// vars
$fields = acf_get_fields($field_group);
// title
if ($show_title && $field_group['style'] === 'default') {
echo '<h2>' . $field_group['title'] . '</h2>';
}
// table start
if ($el == 'tr') {
echo '<table class="form-table"><tbody>';
}
// render fields
acf_render_fields($post_id, $fields, $el, $field_group['instruction_placement']);
// table end
if ($el == 'tr') {
echo '</tbody></table>';
}
}
}
示例10: render
function render($user_id, $user_form, $el = 'tr')
{
// vars
$post_id = "user_{$user_id}";
$show_title = true;
// show title
if ($user_form == 'register') {
$show_title = false;
}
// args
$args = array('user_id' => 'new', 'user_form' => $user_form);
if ($user_id) {
$args['user_id'] = $user_id;
}
// get field groups
$field_groups = acf_get_field_groups($args);
// render
if (!empty($field_groups)) {
acf_form_data(array('post_id' => $post_id, 'nonce' => 'user'));
foreach ($field_groups as $field_group) {
$fields = acf_get_fields($field_group);
?>
<?php
if ($show_title && $field_group['style'] == 'default') {
?>
<h3><?php
echo $field_group['title'];
?>
</h3>
<?php
}
?>
<?php
if ($el == 'tr') {
?>
<table class="form-table">
<tbody>
<?php
}
?>
<?php
acf_render_fields($post_id, $fields, $el, 'field');
?>
<?php
if ($el == 'tr') {
?>
</tbody>
</table>
<?php
}
?>
<?php
}
}
}
示例11: 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'));
$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 (!empty($args['fields'])) {
foreach ($args['fields'] as $selector) {
$fields[] = get_field_object($selector, $post_id, false, false);
}
} elseif (!empty($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>';
}
// 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
// html before fields
echo $args['html_before_fields'];
// start table
if ($args['label_placement'] == 'left') {
$args['field_el'] = 'tr';
?>
<table class="acf-table"><tbody><?php
}
acf_render_fields($post_id, $fields, $args['field_el'], $args['instruction_placement']);
// end table
if ($args['label_placement'] == 'left') {
?>
</tbody></table><?php
}
// html after fields
echo $args['html_after_fields'];
?>
//.........这里部分代码省略.........
示例12: edit_form_after_title
function edit_form_after_title()
{
// globals
global $post;
// render post data
acf_form_data(array('post_id' => $post->post_id, 'nonce' => 'field_group', 'ajax' => 0));
}
示例13: comment_form_field_comment
function comment_form_field_comment($html)
{
// global
global $post;
// vars
$post_id = false;
// get field groups
$field_groups = acf_get_field_groups(array('comment' => $post->post_type));
// bail early if no field groups
if (!$field_groups) {
return $html;
}
// ob
ob_start();
// render post data
acf_form_data(array('post_id' => $post_id, 'nonce' => 'comment'));
foreach ($field_groups as $field_group) {
$fields = acf_get_fields($field_group);
acf_render_fields($post_id, $fields, 'p', $field_group['instruction_placement']);
}
// append
$html .= ob_get_contents();
ob_end_clean();
// return
return $html;
}
示例14: add_comment
function add_comment()
{
// vars
$post_id = "comment_0";
// get field groups
$field_groups = acf_get_field_groups(array('comment' => 'new'));
if (!empty($field_groups)) {
// render post data
acf_form_data(array('post_id' => $post_id, 'nonce' => 'comment'));
foreach ($field_groups as $field_group) {
$fields = acf_get_fields($field_group);
?>
<div class="acf-fields -<?php
echo $field_group['label_placement'];
?>
">
<?php
acf_render_fields($post_id, $fields, 'div', $field_group['instruction_placement']);
?>
</div>
<?php
}
}
}
示例15: acf_form
function acf_form($args = array())
{
// vars
$url = home_url($_SERVER['REQUEST_URI']);
// 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'));
$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 (!empty($args['fields'])) {
foreach ($args['fields'] as $selector) {
$fields[] = acf_get_field($selector);
}
} elseif (!empty($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) {
$fields = array_merge($fields, acf_get_fields($field_group));
}
}
// updated message
if (!empty($_GET['updated']) && $args['updated_message']) {
echo '<div id="message" class="updated"><p>' . $args['updated_message'] . '</p></div>';
}
// 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-form-fields">
<?php
// html before fields
echo $args['html_before_fields'];
// start table
if ($args['label_placement'] == 'left') {
$args['field_el'] = 'tr';
?>
<table class="acf-table"><tbody><?php
}
acf_render_fields($post_id, $fields, $args['field_el'], $args['instruction_placement']);
// end table
if ($args['label_placement'] == 'left') {
?>
</tbody></table><?php
}
// html after fields
echo $args['html_after_fields'];
?>
</div><!-- acf-form-fields -->
//.........这里部分代码省略.........