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