| 1 |
<?php |
| 2 |
/* |
| 3 |
Plugin Name: Advanced Custom Fields |
| 4 |
Plugin URI: http://www.advancedcustomfields.com/ |
| 5 |
Description: Fully customise WordPress edit screens with powerful fields. Boasting a professional interface and a powerfull API, it’s a must have for any web developer working with WordPress. Field types include: Wysiwyg, text, textarea, image, file, select, checkbox, page link, post object, date picker, color picker, repeater, flexible content, gallery and more! |
| 6 |
Version: 4.1.1 |
| 7 |
Author: Elliot Condon |
| 8 |
Author URI: http://www.elliotcondon.com/ |
| 9 |
License: GPL |
| 10 |
Copyright: Elliot Condon |
| 11 |
*/ |
| 12 |
|
| 13 |
|
| 14 |
// lite mode |
| 15 |
if( !defined('ACF_LITE') ) |
| 16 |
{ |
| 17 |
define( 'ACF_LITE', false ); |
| 18 |
} |
| 19 |
|
| 20 |
|
| 21 |
// API |
| 22 |
include_once('core/api.php'); |
| 23 |
|
| 24 |
|
| 25 |
// controllers |
| 26 |
include_once('core/controllers/field_groups.php'); |
| 27 |
include_once('core/controllers/field_group.php'); |
| 28 |
include_once('core/controllers/input.php'); |
| 29 |
include_once('core/controllers/location.php'); |
| 30 |
|
| 31 |
if( is_admin() ) |
| 32 |
{ |
| 33 |
if( !ACF_LITE ) |
| 34 |
{ |
| 35 |
include_once('core/controllers/export.php'); |
| 36 |
include_once('core/controllers/addons.php'); |
| 37 |
include_once('core/controllers/third_party.php'); |
| 38 |
include_once('core/controllers/upgrade.php'); |
| 39 |
} |
| 40 |
|
| 41 |
include_once('core/controllers/everything_fields.php'); |
| 42 |
} |
| 43 |
|
| 44 |
|
| 45 |
class Acf |
| 46 |
{ |
| 47 |
var $settings; |
| 48 |
|
| 49 |
|
| 50 |
/* |
| 51 |
* Constructor |
| 52 |
* |
| 53 |
* @description: |
| 54 |
* @since 1.0.0 |
| 55 |
* @created: 23/06/12 |
| 56 |
*/ |
| 57 |
|
| 58 |
function __construct() |
| 59 |
{ |
| 60 |
// helpers |
| 61 |
add_filter('acf/helpers/get_path', array($this, 'helpers_get_path'), 1, 1); |
| 62 |
add_filter('acf/helpers/get_dir', array($this, 'helpers_get_dir'), 1, 1); |
| 63 |
|
| 64 |
|
| 65 |
// vars |
| 66 |
$this->settings = array( |
| 67 |
'path' => apply_filters('acf/helpers/get_path', __FILE__), |
| 68 |
'dir' => apply_filters('acf/helpers/get_dir', __FILE__), |
| 69 |
'version' => '4.1.1', |
| 70 |
'upgrade_version' => '3.4.1', |
| 71 |
); |
| 72 |
|
| 73 |
|
| 74 |
// set text domain |
| 75 |
load_plugin_textdomain('acf', false, basename(dirname(__FILE__)).'/lang' ); |
| 76 |
|
| 77 |
|
| 78 |
// actions |
| 79 |
add_action('init', array($this, 'init'), 1); |
| 80 |
add_action('acf/save_post', array($this, 'save_post'), 10); |
| 81 |
|
| 82 |
|
| 83 |
// filters |
| 84 |
add_filter('acf/get_info', array($this, 'get_info'), 1, 1); |
| 85 |
add_filter('acf/parse_types', array($this, 'parse_types'), 1, 1); |
| 86 |
add_filter('acf/get_post_types', array($this, 'get_post_types'), 1, 3); |
| 87 |
add_filter('acf/get_taxonomies_for_select', array($this, 'get_taxonomies_for_select'), 1, 2); |
| 88 |
add_filter('acf/get_image_sizes', array($this, 'get_image_sizes'), 1, 1); |
| 89 |
add_action('acf/create_fields', array($this, 'create_fields'), 1, 2); |
| 90 |
|
| 91 |
|
| 92 |
// admin only |
| 93 |
if( is_admin() && !ACF_LITE ) |
| 94 |
{ |
| 95 |
add_action('admin_menu', array($this,'admin_menu')); |
| 96 |
add_action('admin_head', array($this,'admin_head')); |
| 97 |
add_filter('post_updated_messages', array($this, 'post_updated_messages')); |
| 98 |
} |
| 99 |
|
| 100 |
|
| 101 |
return true; |
| 102 |
} |
| 103 |
|
| 104 |
|
| 105 |
/* |
| 106 |
* helpers_get_path |
| 107 |
* |
| 108 |
* @description: calculates the path (works for plugin / theme folders) |
| 109 |
* @since: 3.6 |
| 110 |
* @created: 30/01/13 |
| 111 |
*/ |
| 112 |
|
| 113 |
function helpers_get_path( $file ) |
| 114 |
{ |
| 115 |
return trailingslashit(dirname($file)); |
| 116 |
} |
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
/* |
| 121 |
* helpers_get_dir |
| 122 |
* |
| 123 |
* @description: calculates the directory (works for plugin / theme folders) |
| 124 |
* @since: 3.6 |
| 125 |
* @created: 30/01/13 |
| 126 |
*/ |
| 127 |
|
| 128 |
function helpers_get_dir( $file ) |
| 129 |
{ |
| 130 |
$dir = trailingslashit(dirname($file)); |
| 131 |
$count = 0; |
| 132 |
|
| 133 |
|
| 134 |
// sanitize for Win32 installs |
| 135 |
$dir = str_replace('\\' ,'/', $dir); |
| 136 |
|
| 137 |
|
| 138 |
// if file is in plugins folder |
| 139 |
$wp_plugin_dir = str_replace('\\' ,'/', WP_PLUGIN_DIR); |
| 140 |
$dir = str_replace($wp_plugin_dir, plugins_url(), $dir, $count); |
| 141 |
|
| 142 |
|
| 143 |
if( $count < 1 ) |
| 144 |
{ |
| 145 |
// if file is in wp-content folder |
| 146 |
$wp_content_dir = str_replace('\\' ,'/', WP_CONTENT_DIR); |
| 147 |
$dir = str_replace($wp_content_dir, content_url(), $dir, $count); |
| 148 |
} |
| 149 |
|
| 150 |
|
| 151 |
if( $count < 1 ) |
| 152 |
{ |
| 153 |
// if file is in ??? folder |
| 154 |
$wp_dir = str_replace('\\' ,'/', ABSPATH); |
| 155 |
$dir = str_replace($wp_dir, site_url('/'), $dir); |
| 156 |
} |
| 157 |
|
| 158 |
|
| 159 |
return $dir; |
| 160 |
} |
| 161 |
|
| 162 |
|
| 163 |
/* |
| 164 |
* get_info |
| 165 |
* |
| 166 |
* @description: helper to get variable from settings array |
| 167 |
* @since: 3.6 |
| 168 |
* @created: 24/01/13 |
| 169 |
*/ |
| 170 |
|
| 171 |
function get_info( $info ) |
| 172 |
{ |
| 173 |
// vars |
| 174 |
$return = false; |
| 175 |
|
| 176 |
|
| 177 |
// specific |
| 178 |
if( isset($this->settings[ $info ]) ) |
| 179 |
{ |
| 180 |
$return = $this->settings[ $info ]; |
| 181 |
} |
| 182 |
|
| 183 |
|
| 184 |
// all |
| 185 |
if( $info == 'all' ) |
| 186 |
{ |
| 187 |
$return = $this->settings; |
| 188 |
} |
| 189 |
|
| 190 |
|
| 191 |
// return |
| 192 |
return $return; |
| 193 |
} |
| 194 |
|
| 195 |
|
| 196 |
/* |
| 197 |
* parse_types |
| 198 |
* |
| 199 |
* @description: helper function to set the 'types' of variables |
| 200 |
* @since: 2.0.4 |
| 201 |
* @created: 9/12/12 |
| 202 |
*/ |
| 203 |
|
| 204 |
function parse_types( $value ) |
| 205 |
{ |
| 206 |
|
| 207 |
// is value another array? |
| 208 |
if( is_array($value) ) |
| 209 |
{ |
| 210 |
foreach( $value as $k => $v ) |
| 211 |
{ |
| 212 |
// if $field was passed, never modify the value! NEVER! |
| 213 |
if( $k === 'value' ) |
| 214 |
{ |
| 215 |
continue; |
| 216 |
} |
| 217 |
|
| 218 |
$value[ $k ] = apply_filters( 'acf/parse_types', $v ); |
| 219 |
} |
| 220 |
} |
| 221 |
else |
| 222 |
{ |
| 223 |
// string |
| 224 |
if( is_string($value) ) |
| 225 |
{ |
| 226 |
$value = trim( $value ); |
| 227 |
} |
| 228 |
|
| 229 |
|
| 230 |
// numbers |
| 231 |
if( is_numeric($value) ) |
| 232 |
{ |
| 233 |
// float / int |
| 234 |
if( strpos($value,'.') !== false ) |
| 235 |
{ |
| 236 |
$value = floatval( $value ); |
| 237 |
} |
| 238 |
else |
| 239 |
{ |
| 240 |
$value = intval( $value ); |
| 241 |
} |
| 242 |
} |
| 243 |
} |
| 244 |
|
| 245 |
|
| 246 |
// return |
| 247 |
return $value; |
| 248 |
} |
| 249 |
|
| 250 |
|
| 251 |
/* |
| 252 |
* Init |
| 253 |
* |
| 254 |
* @description: |
| 255 |
* @since 1.0.0 |
| 256 |
* @created: 23/06/12 |
| 257 |
*/ |
| 258 |
|
| 259 |
function init() |
| 260 |
{ |
| 261 |
|
| 262 |
// Create ACF post type |
| 263 |
$labels = array( |
| 264 |
'name' => __( 'Field Groups', 'acf' ), |
| 265 |
'singular_name' => __( 'Advanced Custom Fields', 'acf' ), |
| 266 |
'add_new' => __( 'Add New' , 'acf' ), |
| 267 |
'add_new_item' => __( 'Add New Field Group' , 'acf' ), |
| 268 |
'edit_item' => __( 'Edit Field Group' , 'acf' ), |
| 269 |
'new_item' => __( 'New Field Group' , 'acf' ), |
| 270 |
'view_item' => __('View Field Group', 'acf'), |
| 271 |
'search_items' => __('Search Field Groups', 'acf'), |
| 272 |
'not_found' => __('No Field Groups found', 'acf'), |
| 273 |
'not_found_in_trash' => __('No Field Groups found in Trash', 'acf'), |
| 274 |
); |
| 275 |
|
| 276 |
register_post_type('acf', array( |
| 277 |
'labels' => $labels, |
| 278 |
'public' => false, |
| 279 |
'show_ui' => true, |
| 280 |
'_builtin' => false, |
| 281 |
'capability_type' => 'page', |
| 282 |
'hierarchical' => true, |
| 283 |
'rewrite' => false, |
| 284 |
'query_var' => "acf", |
| 285 |
'supports' => array( |
| 286 |
'title', |
| 287 |
), |
| 288 |
'show_in_menu' => false, |
| 289 |
)); |
| 290 |
|
| 291 |
|
| 292 |
// register acf scripts |
| 293 |
$scripts = array(); |
| 294 |
$scripts[] = array( |
| 295 |
'handle' => 'acf-field-group', |
| 296 |
'src' => $this->settings['dir'] . 'js/field-group.js', |
| 297 |
'deps' => array('jquery') |
| 298 |
); |
| 299 |
$scripts[] = array( |
| 300 |
'handle' => 'acf-input', |
| 301 |
'src' => $this->settings['dir'] . 'js/input.php', |
| 302 |
'deps' => array('jquery') |
| 303 |
); |
| 304 |
$scripts[] = array( |
| 305 |
'handle' => 'acf-input-ajax', |
| 306 |
'src' => $this->settings['dir'] . 'js/input/ajax.js', |
| 307 |
'deps' => array('jquery', 'acf-input') |
| 308 |
); |
| 309 |
$scripts[] = array( |
| 310 |
'handle' => 'acf-datepicker', |
| 311 |
'src' => $this->settings['dir'] . 'core/fields/date_picker/jquery.ui.datepicker.js', |
| 312 |
'deps' => array('jquery', 'acf-input') |
| 313 |
); |
| 314 |
|
| 315 |
|
| 316 |
foreach( $scripts as $script ) |
| 317 |
{ |
| 318 |
wp_register_script( $script['handle'], $script['src'], $script['deps'], $this->settings['version'] ); |
| 319 |
} |
| 320 |
|
| 321 |
|
| 322 |
// register acf styles |
| 323 |
$styles = array( |
| 324 |
'acf' => $this->settings['dir'] . 'css/acf.css', |
| 325 |
'acf-field-group' => $this->settings['dir'] . 'css/field-group.css', |
| 326 |
'acf-global' => $this->settings['dir'] . 'css/global.css', |
| 327 |
'acf-input' => $this->settings['dir'] . 'css/input.css', |
| 328 |
'acf-datepicker' => $this->settings['dir'] . 'core/fields/date_picker/style.date_picker.css', |
| 329 |
); |
| 330 |
|
| 331 |
foreach( $styles as $k => $v ) |
| 332 |
{ |
| 333 |
wp_register_style( $k, $v, false, $this->settings['version'] ); |
| 334 |
} |
| 335 |
|
| 336 |
|
| 337 |
// register fields |
| 338 |
include_once('core/fields/_functions.php'); |
| 339 |
include_once('core/fields/_base.php'); |
| 340 |
|
| 341 |
include_once('core/fields/text.php'); |
| 342 |
include_once('core/fields/textarea.php'); |
| 343 |
include_once('core/fields/number.php'); |
| 344 |
include_once('core/fields/email.php'); |
| 345 |
include_once('core/fields/password.php'); |
| 346 |
|
| 347 |
include_once('core/fields/wysiwyg.php'); |
| 348 |
include_once('core/fields/image.php'); |
| 349 |
include_once('core/fields/file.php'); |
| 350 |
|
| 351 |
include_once('core/fields/select.php'); |
| 352 |
include_once('core/fields/checkbox.php'); |
| 353 |
include_once('core/fields/radio.php'); |
| 354 |
include_once('core/fields/true_false.php'); |
| 355 |
|
| 356 |
include_once('core/fields/page_link.php'); |
| 357 |
include_once('core/fields/post_object.php'); |
| 358 |
include_once('core/fields/relationship.php'); |
| 359 |
include_once('core/fields/taxonomy.php'); |
| 360 |
include_once('core/fields/user.php'); |
| 361 |
|
| 362 |
include_once('core/fields/date_picker/date_picker.php'); |
| 363 |
include_once('core/fields/color_picker.php'); |
| 364 |
|
| 365 |
include_once('core/fields/message.php'); |
| 366 |
include_once('core/fields/tab.php'); |
| 367 |
|
| 368 |
|
| 369 |
// register 3rd party fields |
| 370 |
do_action('acf/register_fields'); |
| 371 |
|
| 372 |
|
| 373 |
} |
| 374 |
|
| 375 |
|
| 376 |
/* |
| 377 |
* admin_menu |
| 378 |
* |
| 379 |
* @description: |
| 380 |
* @since 1.0.0 |
| 381 |
* @created: 23/06/12 |
| 382 |
*/ |
| 383 |
|
| 384 |
function admin_menu() |
| 385 |
{ |
| 386 |
add_utility_page(__("Custom Fields",'acf'), __("Custom Fields",'acf'), 'manage_options', 'edit.php?post_type=acf'); |
| 387 |
} |
| 388 |
|
| 389 |
|
| 390 |
/* |
| 391 |
* post_updated_messages |
| 392 |
* |
| 393 |
* @description: messages for saving a field group |
| 394 |
* @since 1.0.0 |
| 395 |
* @created: 23/06/12 |
| 396 |
*/ |
| 397 |
|
| 398 |
function post_updated_messages( $messages ) |
| 399 |
{ |
| 400 |
global $post, $post_ID; |
| 401 |
|
| 402 |
$messages['acf'] = array( |
| 403 |
0 => '', // Unused. Messages start at index 1. |
| 404 |
1 => __('Field group updated.', 'acf'), |
| 405 |
2 => __('Custom field updated.', 'acf'), |
| 406 |
3 => __('Custom field deleted.', 'acf'), |
| 407 |
4 => __('Field group updated.', 'acf'), |
| 408 |
/* translators: %s: date and time of the revision */ |
| 409 |
5 => isset($_GET['revision']) ? sprintf( __('Field group restored to revision from %s', 'acf'), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false, |
| 410 |
6 => __('Field group published.', 'acf'), |
| 411 |
7 => __('Field group saved.', 'acf'), |
| 412 |
8 => __('Field group submitted.', 'acf'), |
| 413 |
9 => __('Field group scheduled for.', 'acf'), |
| 414 |
10 => __('Field group draft updated.', 'acf'), |
| 415 |
); |
| 416 |
|
| 417 |
return $messages; |
| 418 |
} |
| 419 |
|
| 420 |
|
| 421 |
/*-------------------------------------------------------------------------------------- |
| 422 |
* |
| 423 |
* admin_head |
| 424 |
* |
| 425 |
* @author Elliot Condon |
| 426 |
* @since 1.0.0 |
| 427 |
* |
| 428 |
*-------------------------------------------------------------------------------------*/ |
| 429 |
|
| 430 |
function admin_head() |
| 431 |
{ |
| 432 |
?> |
| 433 |
<style type="text/css"> |
| 434 |
#adminmenu #toplevel_page_edit-post_type-acf a[href="edit.php?post_type=acf&page=acf-upgrade"]{ display:none; } |
| 435 |
#adminmenu #toplevel_page_edit-post_type-acf .wp-menu-image { background-position: 1px -33px; } |
| 436 |
#adminmenu #toplevel_page_edit-post_type-acf:hover .wp-menu-image, |
| 437 |
#adminmenu #toplevel_page_edit-post_type-acf.wp-menu-open .wp-menu-image { background-position: 1px -1px; } |
| 438 |
</style> |
| 439 |
<?php |
| 440 |
} |
| 441 |
|
| 442 |
|
| 443 |
/* |
| 444 |
* get_taxonomies_for_select |
| 445 |
* |
| 446 |
* @description: |
| 447 |
* @since: 3.6 |
| 448 |
* @created: 27/01/13 |
| 449 |
*/ |
| 450 |
|
| 451 |
function get_taxonomies_for_select( $choices, $simple_value = false ) |
| 452 |
{ |
| 453 |
// vars |
| 454 |
$post_types = get_post_types(); |
| 455 |
|
| 456 |
|
| 457 |
if($post_types) |
| 458 |
{ |
| 459 |
foreach($post_types as $post_type) |
| 460 |
{ |
| 461 |
$post_type_object = get_post_type_object($post_type); |
| 462 |
$taxonomies = get_object_taxonomies($post_type); |
| 463 |
if($taxonomies) |
| 464 |
{ |
| 465 |
foreach($taxonomies as $taxonomy) |
| 466 |
{ |
| 467 |
if(!is_taxonomy_hierarchical($taxonomy)) continue; |
| 468 |
$terms = get_terms($taxonomy, array('hide_empty' => false)); |
| 469 |
if($terms) |
| 470 |
{ |
| 471 |
foreach($terms as $term) |
| 472 |
{ |
| 473 |
$value = $taxonomy . ':' . $term->term_id; |
| 474 |
|
| 475 |
if( $simple_value ) |
| 476 |
{ |
| 477 |
$value = $term->term_id; |
| 478 |
} |
| 479 |
|
| 480 |
$choices[$post_type_object->label . ': ' . $taxonomy][$value] = $term->name; |
| 481 |
} |
| 482 |
} |
| 483 |
} |
| 484 |
} |
| 485 |
} |
| 486 |
} |
| 487 |
|
| 488 |
return $choices; |
| 489 |
} |
| 490 |
|
| 491 |
|
| 492 |
/* |
| 493 |
* get_post_types |
| 494 |
* |
| 495 |
* @description: |
| 496 |
* @since: 3.5.5 |
| 497 |
* @created: 16/12/12 |
| 498 |
*/ |
| 499 |
|
| 500 |
function get_post_types( $post_types, $exclude = array(), $include = array() ) |
| 501 |
{ |
| 502 |
// get all custom post types |
| 503 |
$post_types = array_merge($post_types, get_post_types()); |
| 504 |
|
| 505 |
|
| 506 |
// core include / exclude |
| 507 |
$acf_includes = array_merge( array(), $include ); |
| 508 |
$acf_excludes = array_merge( array( 'acf', 'revision', 'nav_menu_item' ), $exclude ); |
| 509 |
|
| 510 |
|
| 511 |
// include |
| 512 |
foreach( $acf_includes as $p ) |
| 513 |
{ |
| 514 |
if( post_type_exists($p) ) |
| 515 |
{ |
| 516 |
$post_types[ $p ] = $p; |
| 517 |
} |
| 518 |
} |
| 519 |
|
| 520 |
|
| 521 |
// exclude |
| 522 |
foreach( $acf_excludes as $p ) |
| 523 |
{ |
| 524 |
unset( $post_types[ $p ] ); |
| 525 |
} |
| 526 |
|
| 527 |
|
| 528 |
return $post_types; |
| 529 |
|
| 530 |
} |
| 531 |
|
| 532 |
|
| 533 |
/* |
| 534 |
* get_image_sizes |
| 535 |
* |
| 536 |
* @description: returns an array holding all the image sizes |
| 537 |
* @since 3.2.8 |
| 538 |
* @created: 6/07/12 |
| 539 |
*/ |
| 540 |
|
| 541 |
function get_image_sizes( $sizes ) |
| 542 |
{ |
| 543 |
// find all sizes |
| 544 |
$all_sizes = get_intermediate_image_sizes(); |
| 545 |
|
| 546 |
|
| 547 |
// define default sizes |
| 548 |
$sizes = array_merge($sizes, array( |
| 549 |
'thumbnail' => __("Thumbnail",'acf'), |
| 550 |
'medium' => __("Medium",'acf'), |
| 551 |
'large' => __("Large",'acf'), |
| 552 |
'full' => __("Full",'acf') |
| 553 |
)); |
| 554 |
|
| 555 |
|
| 556 |
// add extra registered sizes |
| 557 |
foreach( $all_sizes as $size ) |
| 558 |
{ |
| 559 |
if( !isset($sizes[ $size ]) ) |
| 560 |
{ |
| 561 |
$sizes[ $size ] = ucwords( str_replace('-', ' ', $size) ); |
| 562 |
} |
| 563 |
} |
| 564 |
|
| 565 |
|
| 566 |
// return array |
| 567 |
return $sizes; |
| 568 |
} |
| 569 |
|
| 570 |
|
| 571 |
/* |
| 572 |
* render_fields_for_input |
| 573 |
* |
| 574 |
* @description: |
| 575 |
* @since 3.1.6 |
| 576 |
* @created: 23/06/12 |
| 577 |
*/ |
| 578 |
|
| 579 |
function create_fields( $fields, $post_id ) |
| 580 |
{ |
| 581 |
if( is_array($fields) ){ foreach( $fields as $field ){ |
| 582 |
|
| 583 |
// if they didn't select a type, skip this field |
| 584 |
if( !$field['type'] || $field['type'] == 'null' ) continue; |
| 585 |
|
| 586 |
|
| 587 |
// set value |
| 588 |
if( !isset($field['value']) ) |
| 589 |
{ |
| 590 |
|
| 591 |
$field['value'] = apply_filters('acf/load_value', false, $post_id, $field); |
| 592 |
$field['value'] = apply_filters('acf/format_value', $field['value'], $post_id, $field); |
| 593 |
} |
| 594 |
|
| 595 |
|
| 596 |
// required |
| 597 |
$required_class = ""; |
| 598 |
$required_label = ""; |
| 599 |
|
| 600 |
if( $field['required'] ) |
| 601 |
{ |
| 602 |
$required_class = ' required'; |
| 603 |
$required_label = ' <span class="required">*</span>'; |
| 604 |
} |
| 605 |
|
| 606 |
|
| 607 |
echo '<div id="acf-' . $field['name'] . '" class="field field_type-' . $field['type'] . ' field_key-' . $field['key'] . $required_class . '" data-field_name="' . $field['name'] . '" data-field_key="' . $field['key'] . '" data-field_type="' . $field['type'] . '">'; |
| 608 |
|
| 609 |
echo '<p class="label">'; |
| 610 |
echo '<label for="' . $field['id'] . '">' . $field['label'] . $required_label . '</label>'; |
| 611 |
echo $field['instructions']; |
| 612 |
echo '</p>'; |
| 613 |
|
| 614 |
$field['name'] = 'fields[' . $field['key'] . ']'; |
| 615 |
do_action('acf/create_field', $field); |
| 616 |
|
| 617 |
echo '</div>'; |
| 618 |
|
| 619 |
}} |
| 620 |
|
| 621 |
} |
| 622 |
|
| 623 |
|
| 624 |
/* |
| 625 |
* save_post |
| 626 |
* |
| 627 |
* @description: |
| 628 |
* @since: 3.6 |
| 629 |
* @created: 28/01/13 |
| 630 |
*/ |
| 631 |
|
| 632 |
function save_post( $post_id ) |
| 633 |
{ |
| 634 |
|
| 635 |
// load from post |
| 636 |
if( !isset($_POST['fields']) ) |
| 637 |
{ |
| 638 |
return false; |
| 639 |
} |
| 640 |
|
| 641 |
|
| 642 |
// loop through and save |
| 643 |
if( $_POST['fields'] ) |
| 644 |
{ |
| 645 |
foreach( $_POST['fields'] as $key => $value ) |
| 646 |
{ |
| 647 |
// parse types |
| 648 |
// - caused issues with saving numbers (0 were removed) |
| 649 |
//$value = apply_filters('acf/parse_types', $value); |
| 650 |
|
| 651 |
// get field |
| 652 |
$field = apply_filters('acf/load_field', false, $key ); |
| 653 |
|
| 654 |
// update field |
| 655 |
do_action('acf/update_value', $value, $post_id, $field ); |
| 656 |
|
| 657 |
} |
| 658 |
// foreach($fields as $key => $value) |
| 659 |
} |
| 660 |
// if($fields) |
| 661 |
|
| 662 |
|
| 663 |
return true; |
| 664 |
} |
| 665 |
|
| 666 |
|
| 667 |
} |
| 668 |
|
| 669 |
$acf = new Acf(); |
| 670 |
|
| 671 |
?> |
| 672 |
|