acf

The Advanced Custom Fields acf class.

Defined (1)

The class is defined in the following location(s).

/acf.php  
  1. class acf 
  2. // vars 
  3. var $settings; 
  4.  
  5.  
  6. /** 
  7. * Constructor 
  8. * This function will construct all the neccessary actions, filters and functions for the ACF plugin to work 
  9. * @type function 
  10. * @date 23/06/12 
  11. * @since 1.0.0 
  12. * @param N/A 
  13. * @return N/A 
  14. */ 
  15.  
  16. function __construct() 
  17. // helpers 
  18. add_filter('acf/helpers/get_path', array($this, 'helpers_get_path'), 1, 1); 
  19. add_filter('acf/helpers/get_dir', array($this, 'helpers_get_dir'), 1, 1); 
  20.  
  21.  
  22. // vars 
  23. $this->settings = array( 
  24. 'path' => apply_filters('acf/helpers/get_path', __FILE__),  
  25. 'dir' => apply_filters('acf/helpers/get_dir', __FILE__),  
  26. 'hook' => basename( dirname( __FILE__ ) ) . '/' . basename( __FILE__ ),  
  27. 'version' => '4.4.9',  
  28. 'upgrade_version' => '3.4.1',  
  29. 'include_3rd_party' => false 
  30. ); 
  31.  
  32.  
  33. // set text domain 
  34. load_textdomain('acf', $this->settings['path'] . 'lang/acf-' . get_locale() . '.mo'); 
  35.  
  36.  
  37. // actions 
  38. add_action('init', array($this, 'init'), 1); 
  39. add_action('acf/pre_save_post', array($this, 'save_post_lock'), 0); 
  40. add_action('acf/pre_save_post', array($this, 'save_post_unlock'), 999); 
  41. add_action('acf/save_post', array($this, 'save_post_lock'), 0); 
  42. add_action('acf/save_post', array($this, 'save_post'), 10); 
  43. add_action('acf/save_post', array($this, 'save_post_unlock'), 999); 
  44. add_action('acf/create_fields', array($this, 'create_fields'), 1, 2); 
  45.  
  46.  
  47. // filters 
  48. add_filter('acf/get_info', array($this, 'get_info'), 1, 1); 
  49. add_filter('acf/parse_types', array($this, 'parse_types'), 1, 1); 
  50. add_filter('acf/get_post_types', array($this, 'get_post_types'), 1, 3); 
  51. add_filter('acf/get_taxonomies_for_select', array($this, 'get_taxonomies_for_select'), 1, 2); 
  52. add_filter('acf/get_image_sizes', array($this, 'get_image_sizes'), 1, 1); 
  53. add_filter('acf/get_post_id', array($this, 'get_post_id'), 1, 1); 
  54.  
  55.  
  56. // includes 
  57. $this->include_before_theme(); 
  58. add_action('after_setup_theme', array($this, 'include_after_theme'), 1); 
  59. add_action('after_setup_theme', array($this, 'include_3rd_party'), 1); 
  60.  
  61.  
  62.  
  63. /** 
  64. * helpers_get_path 
  65. * This function will calculate the path to a file 
  66. * @type function 
  67. * @date 30/01/13 
  68. * @since 3.6.0 
  69. * @param $file (file) a reference to the file 
  70. * @return (string) 
  71. */ 
  72.  
  73. function helpers_get_path( $file ) 
  74. return trailingslashit(dirname($file)); 
  75.  
  76.  
  77. /** 
  78. * helpers_get_dir 
  79. * This function will calculate the directory (URL) to a file 
  80. * @type function 
  81. * @date 30/01/13 
  82. * @since 3.6.0 
  83. * @param $file (file) a reference to the file 
  84. * @return (string) 
  85. */ 
  86.  
  87. function helpers_get_dir( $file ) 
  88. $dir = trailingslashit(dirname($file)); 
  89. $count = 0; 
  90.  
  91.  
  92. // sanitize for Win32 installs 
  93. $dir = str_replace('\\' , '/', $dir);  
  94.  
  95.  
  96. // if file is in plugins folder 
  97. $wp_plugin_dir = str_replace('\\' , '/', WP_PLUGIN_DIR);  
  98. $dir = str_replace($wp_plugin_dir, plugins_url(), $dir, $count); 
  99.  
  100.  
  101. if( $count < 1 ) 
  102. // if file is in wp-content folder 
  103. $wp_content_dir = str_replace('\\' , '/', WP_CONTENT_DIR);  
  104. $dir = str_replace($wp_content_dir, content_url(), $dir, $count); 
  105.  
  106.  
  107. if( $count < 1 ) 
  108. // if file is in ??? folder 
  109. $wp_dir = str_replace('\\' , '/', ABSPATH);  
  110. $dir = str_replace($wp_dir, site_url('/'), $dir); 
  111.  
  112.  
  113. return $dir; 
  114.  
  115.  
  116. /** 
  117. * acf/get_post_id 
  118. * A helper function to filter the post_id variable. 
  119. * @type filter 
  120. * @date 27/05/13 
  121. * @param {mixed} $post_id 
  122. * @return {mixed} $post_id 
  123. */ 
  124.  
  125. function get_post_id( $post_id ) { 
  126.  
  127. // if not $post_id, load queried object 
  128. if( !$post_id ) { 
  129.  
  130. // try for global post (needed for setup_postdata) 
  131. $post_id = (int) get_the_ID(); 
  132.  
  133.  
  134. // try for current screen 
  135. if( !$post_id ) { 
  136.  
  137. $post_id = get_queried_object(); 
  138.  
  139.  
  140.  
  141.  
  142. // $post_id may be an object 
  143. if( is_object($post_id) ) { 
  144.  
  145. // user 
  146. if( isset($post_id->roles, $post_id->ID) ) { 
  147.  
  148. $post_id = 'user_' . $post_id->ID; 
  149.  
  150. // term 
  151. } elseif( isset($post_id->taxonomy, $post_id->term_id) ) { 
  152.  
  153. $post_id = $post_id->taxonomy . '_' . $post_id->term_id; 
  154.  
  155. // comment 
  156. } elseif( isset($post_id->comment_ID) ) { 
  157.  
  158. $post_id = 'comment_' . $post_id->comment_ID; 
  159.  
  160. // post 
  161. } elseif( isset($post_id->ID) ) { 
  162.  
  163. $post_id = $post_id->ID; 
  164.  
  165. // default 
  166. } else { 
  167.  
  168. $post_id = 0; 
  169.  
  170.  
  171.  
  172.  
  173. // allow for option == options 
  174. if( $post_id === 'option' ) { 
  175.  
  176. $post_id = 'options'; 
  177.  
  178.  
  179.  
  180. /** 
  181. * Override for preview 
  182. *  
  183. * If the $_GET['preview_id'] is set, then the user wants to see the preview data. 
  184. * There is also the case of previewing a page with post_id = 1, but using get_field 
  185. * to load data from another post_id. 
  186. * In this case, we need to make sure that the autosave revision is actually related 
  187. * to the $post_id variable. If they match, then the autosave data will be used, otherwise,  
  188. * the user wants to load data from a completely different post_id 
  189. */ 
  190.  
  191. if( isset($_GET['preview_id']) ) { 
  192.  
  193. $autosave = wp_get_post_autosave( $_GET['preview_id'] ); 
  194.  
  195. if( $autosave && $autosave->post_parent == $post_id ) { 
  196.  
  197. $post_id = (int) $autosave->ID; 
  198.  
  199.  
  200.  
  201.  
  202. // return 
  203. return $post_id; 
  204.  
  205.  
  206. /** 
  207. * get_info 
  208. * This function will return a setting from the settings array 
  209. * @type function 
  210. * @date 24/01/13 
  211. * @since 3.6.0 
  212. * @param $i (string) the setting to get 
  213. * @return (mixed) 
  214. */ 
  215.  
  216. function get_info( $i ) 
  217. // vars 
  218. $return = false; 
  219.  
  220.  
  221. // specific 
  222. if( isset($this->settings[ $i ]) ) 
  223. $return = $this->settings[ $i ]; 
  224.  
  225.  
  226. // all 
  227. if( $i == 'all' ) 
  228. $return = $this->settings; 
  229.  
  230.  
  231. // return 
  232. return $return; 
  233.  
  234.  
  235. /** 
  236. * parse_types 
  237. * @description: helper function to set the 'types' of variables 
  238. * @since: 2.0.4 
  239. * @created: 9/12/12 
  240. */ 
  241.  
  242. function parse_types( $value ) 
  243. // vars 
  244. $restricted = array( 
  245. 'label',  
  246. 'name',  
  247. '_name',  
  248. 'value',  
  249. 'instructions' 
  250. ); 
  251.  
  252.  
  253. // is value another array? 
  254. if( is_array($value) ) 
  255. foreach( $value as $k => $v ) 
  256. // bail early for restricted pieces 
  257. if( in_array($k, $restricted, true) ) 
  258. continue; 
  259.  
  260.  
  261. // filter piece 
  262. $value[ $k ] = apply_filters( 'acf/parse_types', $v ); 
  263. }  
  264. else 
  265. // string 
  266. if( is_string($value) ) 
  267. $value = trim( $value ); 
  268.  
  269.  
  270. // numbers 
  271. if( is_numeric($value) ) 
  272. // check for non numeric characters 
  273. if( preg_match('/[^0-9]/', $value) ) 
  274. // leave value if it contains such characters: . + - e 
  275. //$value = floatval( $value ); 
  276. else 
  277. $value = intval( $value ); 
  278.  
  279.  
  280. // return 
  281. return $value; 
  282.  
  283.  
  284. /** 
  285. * include_before_theme 
  286. * This function will include core files before the theme's functions.php file has been excecuted. 
  287. *  
  288. * @type action (plugins_loaded) 
  289. * @date 3/09/13 
  290. * @since 4.3.0 
  291. * @param N/A 
  292. * @return N/A 
  293. */ 
  294.  
  295. function include_before_theme() 
  296. // incudes 
  297. include_once('core/api.php'); 
  298.  
  299. include_once('core/controllers/input.php'); 
  300. include_once('core/controllers/location.php'); 
  301. include_once('core/controllers/field_group.php'); 
  302.  
  303.  
  304. // admin only includes 
  305. if( is_admin() ) 
  306. include_once('core/controllers/post.php'); 
  307. include_once('core/controllers/revisions.php'); 
  308. include_once('core/controllers/everything_fields.php');  
  309. include_once('core/controllers/field_groups.php'); 
  310.  
  311.  
  312. // register fields 
  313. include_once('core/fields/_functions.php'); 
  314. include_once('core/fields/_base.php'); 
  315.  
  316. include_once('core/fields/text.php'); 
  317. include_once('core/fields/textarea.php'); 
  318. include_once('core/fields/number.php'); 
  319. include_once('core/fields/email.php'); 
  320. include_once('core/fields/password.php'); 
  321.  
  322. include_once('core/fields/wysiwyg.php'); 
  323. include_once('core/fields/image.php'); 
  324. include_once('core/fields/file.php'); 
  325.  
  326. include_once('core/fields/select.php'); 
  327. include_once('core/fields/checkbox.php'); 
  328. include_once('core/fields/radio.php'); 
  329. include_once('core/fields/true_false.php'); 
  330.  
  331. include_once('core/fields/page_link.php'); 
  332. include_once('core/fields/post_object.php'); 
  333. include_once('core/fields/relationship.php'); 
  334. include_once('core/fields/taxonomy.php'); 
  335. include_once('core/fields/user.php'); 
  336.  
  337. include_once('core/fields/google-map.php'); 
  338. include_once('core/fields/date_picker/date_picker.php'); 
  339. include_once('core/fields/color_picker.php'); 
  340.  
  341. include_once('core/fields/message.php'); 
  342. include_once('core/fields/tab.php'); 
  343.  
  344.  
  345.  
  346. /** 
  347. * include_3rd_party 
  348. * This function will include 3rd party add-ons 
  349. * @type function 
  350. * @date 29/01/2014 
  351. * @since 5.0.0 
  352. * @param N/A 
  353. * @return N/A 
  354. */ 
  355.  
  356. function include_3rd_party() { 
  357.  
  358. // run only once 
  359. if( $this->settings['include_3rd_party'] ) 
  360. return false; 
  361.  
  362.  
  363. // update setting 
  364. $this->settings['include_3rd_party'] = true; 
  365.  
  366.  
  367. // include 3rd party fields 
  368. do_action('acf/register_fields'); 
  369.  
  370.  
  371.  
  372. /** 
  373. * include_after_theme 
  374. * This function will include core files after the theme's functions.php file has been excecuted. 
  375. *  
  376. * @type action (after_setup_theme) 
  377. * @date 3/09/13 
  378. * @since 4.3.0 
  379. * @param N/A 
  380. * @return N/A 
  381. */ 
  382.  
  383. function include_after_theme() { 
  384.  
  385. // bail early if user has defined LITE_MODE as true 
  386. if( defined('ACF_LITE') && ACF_LITE ) 
  387. return; 
  388.  
  389.  
  390. // admin only includes 
  391. if( is_admin() ) 
  392. include_once('core/controllers/export.php'); 
  393. include_once('core/controllers/addons.php'); 
  394. include_once('core/controllers/third_party.php'); 
  395. include_once('core/controllers/upgrade.php'); 
  396.  
  397.  
  398.  
  399. /** 
  400. * init 
  401. * This function is called during the 'init' action and will do things such as: 
  402. * create post_type, register scripts, add actions / filters 
  403. * @type action (init) 
  404. * @date 23/06/12 
  405. * @since 1.0.0 
  406. * @param N/A 
  407. * @return N/A 
  408. */ 
  409.  
  410. function init() 
  411.  
  412. // Create ACF post type 
  413. $labels = array( 
  414. 'name' => __( 'Field Groups', 'acf' ),  
  415. 'singular_name' => __( 'Advanced Custom Fields', 'acf' ),  
  416. 'add_new' => __( 'Add New' , 'acf' ),  
  417. 'add_new_item' => __( 'Add New Field Group' , 'acf' ),  
  418. 'edit_item' => __( 'Edit Field Group' , 'acf' ),  
  419. 'new_item' => __( 'New Field Group' , 'acf' ),  
  420. 'view_item' => __('View Field Group', 'acf'),  
  421. 'search_items' => __('Search Field Groups', 'acf'),  
  422. 'not_found' => __('No Field Groups found', 'acf'),  
  423. 'not_found_in_trash' => __('No Field Groups found in Trash', 'acf'),  
  424. ); 
  425.  
  426. register_post_type('acf', array( 
  427. 'labels' => $labels,  
  428. 'public' => false,  
  429. 'show_ui' => true,  
  430. '_builtin' => false,  
  431. 'capability_type' => 'page',  
  432. 'hierarchical' => true,  
  433. 'rewrite' => false,  
  434. 'query_var' => "acf",  
  435. 'supports' => array( 
  436. 'title',  
  437. ),  
  438. 'show_in_menu' => false,  
  439. )); 
  440.  
  441.  
  442. // min 
  443. $min = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; 
  444.  
  445.  
  446. // register acf scripts 
  447. $scripts = array(); 
  448. $scripts[] = array( 
  449. 'handle' => 'acf-field-group',  
  450. 'src' => $this->settings['dir'] . "js/field-group{$min}.js",  
  451. 'deps' => array('jquery') 
  452. ); 
  453. $scripts[] = array( 
  454. 'handle' => 'acf-input',  
  455. 'src' => $this->settings['dir'] . "js/input{$min}.js",  
  456. 'deps' => array('jquery', 'jquery-ui-core', 'jquery-ui-datepicker') 
  457. ); 
  458.  
  459.  
  460. foreach( $scripts as $script ) 
  461. wp_register_script( $script['handle'], $script['src'], $script['deps'], $this->settings['version'] ); 
  462.  
  463.  
  464. // register acf styles 
  465. $styles = array( 
  466. 'acf' => $this->settings['dir'] . 'css/acf.css',  
  467. 'acf-field-group' => $this->settings['dir'] . 'css/field-group.css',  
  468. 'acf-global' => $this->settings['dir'] . 'css/global.css',  
  469. 'acf-input' => $this->settings['dir'] . 'css/input.css',  
  470. 'acf-datepicker' => $this->settings['dir'] . 'core/fields/date_picker/style.date_picker.css',  
  471. ); 
  472.  
  473. foreach( $styles as $k => $v ) 
  474. wp_register_style( $k, $v, false, $this->settings['version'] );  
  475.  
  476.  
  477. // bail early if user has defined LITE_MODE as true 
  478. if( defined('ACF_LITE') && ACF_LITE ) 
  479. return; 
  480.  
  481.  
  482. // admin only 
  483. if( is_admin() ) 
  484. add_action('admin_menu', array($this, 'admin_menu')); 
  485. add_action('admin_head', array($this, 'admin_head')); 
  486. add_filter('post_updated_messages', array($this, 'post_updated_messages')); 
  487.  
  488.  
  489. /** 
  490. * admin_menu 
  491. * @description:  
  492. * @since 1.0.0 
  493. * @created: 23/06/12 
  494. */ 
  495.  
  496. function admin_menu() 
  497. add_menu_page(__("Custom Fields", 'acf'), __("Custom Fields", 'acf'), 'manage_options', 'edit.php?post_type=acf', false, false, '80.025'); 
  498.  
  499.  
  500. /** 
  501. * post_updated_messages 
  502. * @description: messages for saving a field group 
  503. * @since 1.0.0 
  504. * @created: 23/06/12 
  505. */ 
  506.  
  507. function post_updated_messages( $messages ) 
  508. global $post, $post_ID; 
  509.  
  510. $messages['acf'] = array( 
  511. 0 => '', // Unused. Messages start at index 1. 
  512. 1 => __('Field group updated.', 'acf'),  
  513. 2 => __('Custom field updated.', 'acf'),  
  514. 3 => __('Custom field deleted.', 'acf'),  
  515. 4 => __('Field group updated.', 'acf'),  
  516. /** translators: %s: date and time of the revision */ 
  517. 5 => isset($_GET['revision']) ? sprintf( __('Field group restored to revision from %s', 'acf'), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false,  
  518. 6 => __('Field group published.', 'acf'),  
  519. 7 => __('Field group saved.', 'acf'),  
  520. 8 => __('Field group submitted.', 'acf'),  
  521. 9 => __('Field group scheduled for.', 'acf'),  
  522. 10 => __('Field group draft updated.', 'acf'),  
  523. ); 
  524.  
  525. return $messages; 
  526. }  
  527.  
  528.  
  529. /**-------------------------------------------------------------------------------------- 
  530. * admin_head 
  531. * @author Elliot Condon 
  532. * @since 1.0.0 
  533. *  
  534. *-------------------------------------------------------------------------------------*/ 
  535.  
  536. function admin_head() 
  537. ?> 
  538. <style type="text/css">  
  539. #adminmenu #toplevel_page_edit-post_type-acf a[href="edit.php?post_type=acf&page=acf-upgrade"]{ display: none; } 
  540. #adminmenu #toplevel_page_edit-post_type-acf .wp-menu-image { background-position: 1px -33px; } 
  541. #adminmenu #toplevel_page_edit-post_type-acf:hover .wp-menu-image,  
  542. #adminmenu #toplevel_page_edit-post_type-acf.wp-menu-open .wp-menu-image { background-position: 1px -1px; } 
  543. </style> 
  544. <?php 
  545.  
  546.  
  547. /** 
  548. * get_taxonomies_for_select 
  549. * @description:  
  550. * @since: 3.6 
  551. * @created: 27/01/13 
  552. */ 
  553.  
  554. function get_taxonomies_for_select( $choices, $simple_value = false ) 
  555. {  
  556. // vars 
  557. $post_types = get_post_types(); 
  558.  
  559.  
  560. if($post_types) 
  561. foreach($post_types as $post_type) 
  562. $post_type_object = get_post_type_object($post_type); 
  563. $taxonomies = get_object_taxonomies($post_type); 
  564. if($taxonomies) 
  565. foreach($taxonomies as $taxonomy) 
  566. if(!is_taxonomy_hierarchical($taxonomy)) continue; 
  567. $terms = get_terms($taxonomy, array('hide_empty' => false)); 
  568. if($terms) 
  569. foreach($terms as $term) 
  570. $value = $taxonomy . ':' . $term->term_id; 
  571.  
  572. if( $simple_value ) 
  573. $value = $term->term_id; 
  574.  
  575. $choices[$post_type_object->label . ': ' . $taxonomy][$value] = $term->name;  
  576.  
  577. return $choices; 
  578.  
  579.  
  580. /** 
  581. * get_post_types 
  582. * @description:  
  583. * @since: 3.5.5 
  584. * @created: 16/12/12 
  585. */ 
  586.  
  587. function get_post_types( $post_types, $exclude = array(), $include = array() ) 
  588. // get all custom post types 
  589. $post_types = array_merge($post_types, get_post_types()); 
  590.  
  591.  
  592. // core include / exclude 
  593. $acf_includes = array_merge( array(), $include ); 
  594. $acf_excludes = array_merge( array( 'acf', 'revision', 'nav_menu_item' ), $exclude ); 
  595.  
  596.  
  597. // include 
  598. foreach( $acf_includes as $p ) 
  599. {  
  600. if( post_type_exists($p) ) 
  601. {  
  602. $post_types[ $p ] = $p; 
  603.  
  604.  
  605. // exclude 
  606. foreach( $acf_excludes as $p ) 
  607. unset( $post_types[ $p ] ); 
  608.  
  609.  
  610. return $post_types; 
  611.  
  612.  
  613.  
  614. /** 
  615. * get_image_sizes 
  616. * @description: returns an array holding all the image sizes 
  617. * @since 3.2.8 
  618. * @created: 6/07/12 
  619. */ 
  620.  
  621. function get_image_sizes( $sizes ) 
  622. // find all sizes 
  623. $all_sizes = get_intermediate_image_sizes(); 
  624.  
  625.  
  626. // define default sizes 
  627. $sizes = array_merge($sizes, array( 
  628. 'thumbnail' => __("Thumbnail", 'acf'),  
  629. 'medium' => __("Medium", 'acf'),  
  630. 'large' => __("Large", 'acf'),  
  631. 'full' => __("Full", 'acf') 
  632. )); 
  633.  
  634.  
  635. // add extra registered sizes 
  636. foreach( $all_sizes as $size ) 
  637. if( !isset($sizes[ $size ]) ) 
  638. $sizes[ $size ] = ucwords( str_replace('-', ' ', $size) ); 
  639.  
  640.  
  641. // return array 
  642. return $sizes; 
  643.  
  644.  
  645. /** 
  646. * render_fields_for_input 
  647. * @description:  
  648. * @since 3.1.6 
  649. * @created: 23/06/12 
  650. */ 
  651.  
  652. function create_fields( $fields, $post_id ) 
  653. if( is_array($fields) ) { foreach( $fields as $field ) { 
  654.  
  655. // if they didn't select a type, skip this field 
  656. if( !$field || !$field['type'] || $field['type'] == 'null' ) 
  657. continue; 
  658.  
  659.  
  660. // set value 
  661. if( !isset($field['value']) ) 
  662. $field['value'] = apply_filters('acf/load_value', false, $post_id, $field); 
  663. $field['value'] = apply_filters('acf/format_value', $field['value'], $post_id, $field); 
  664.  
  665.  
  666. // required 
  667. $required_class = ""; 
  668. $required_label = ""; 
  669.  
  670. if( $field['required'] ) 
  671. $required_class = ' required'; 
  672. $required_label = ' <span class="required">*</span>'; 
  673.  
  674.  
  675. 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'] . '">'; 
  676.  
  677. echo '<p class="label">'; 
  678. echo '<label for="' . $field['id'] . '">' . $field['label'] . $required_label . '</label>'; 
  679. echo $field['instructions']; 
  680. echo '</p>'; 
  681.  
  682. $field['name'] = 'fields[' . $field['key'] . ']'; 
  683. do_action('acf/create_field', $field, $post_id); 
  684.  
  685. echo '</div>'; 
  686.  
  687. }} 
  688.  
  689.  
  690.  
  691. /** 
  692. * save_post_lock 
  693. * This action sets a global variable which locks the ACF save functions to this ID. 
  694. * This prevents an inifinite loop if a user was to hook into the save and create a new post 
  695. * @type function 
  696. * @date 16/07/13 
  697. * @param {int} $post_id 
  698. * @return {int} $post_id 
  699. */ 
  700.  
  701. function save_post_lock( $post_id ) 
  702. $GLOBALS['acf_save_lock'] = $post_id; 
  703.  
  704. return $post_id; 
  705.  
  706.  
  707. /** 
  708. * save_post_unlock 
  709. * This action sets a global variable which unlocks the ACF save functions to this ID. 
  710. * This prevents an inifinite loop if a user was to hook into the save and create a new post 
  711. * @type function 
  712. * @date 16/07/13 
  713. * @param {int} $post_id 
  714. * @return {int} $post_id 
  715. */ 
  716.  
  717. function save_post_unlock( $post_id ) 
  718. $GLOBALS['acf_save_lock'] = false; 
  719.  
  720. return $post_id; 
  721.  
  722.  
  723. /** 
  724. * save_post 
  725. * @description:  
  726. * @since: 3.6 
  727. * @created: 28/01/13 
  728. */ 
  729.  
  730. function save_post( $post_id ) 
  731.  
  732. // load from post 
  733. if( !isset($_POST['fields']) ) 
  734. return $post_id; 
  735.  
  736.  
  737. // loop through and save 
  738. if( !empty($_POST['fields']) ) 
  739. // loop through and save $_POST data 
  740. foreach( $_POST['fields'] as $k => $v ) 
  741. // get field 
  742. $f = apply_filters('acf/load_field', false, $k ); 
  743.  
  744. // update field 
  745. do_action('acf/update_value', $v, $post_id, $f ); 
  746.  
  747. // foreach($fields as $key => $value) 
  748. // if($fields) 
  749.  
  750.  
  751. return $post_id; 
  752.  
  753.