123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171 |
- <?php
- acf_register_store( 'form' );
- function acf_set_form_data( $name = '', $data = false ) {
- return acf_get_store( 'form' )->set( $name, $data );
- }
- function acf_get_form_data( $name = '' ) {
- return acf_get_store( 'form' )->get( $name );
- }
- function acf_form_data( $data = array() ) {
-
- $data = wp_parse_args(
- $data,
- array(
-
- 'screen' => 'post',
-
- 'post_id' => 0,
-
- 'validation' => true,
- )
- );
-
- $data['nonce'] = wp_create_nonce( $data['screen'] );
-
- $data['changed'] = 0;
-
- acf_set_form_data( $data );
-
- ?>
- <div id="acf-form-data" class="acf-hidden">
- <?php
- // Create hidden inputs from $data
- foreach ( $data as $name => $value ) {
- acf_hidden_input(
- array(
- 'id' => '_acf_' . $name,
- 'name' => '_acf_' . $name,
- 'value' => $value,
- )
- );
- }
-
- do_action( 'acf/form_data', $data );
- do_action( 'acf/input/form_data', $data );
- ?>
- </div>
- <?php
- }
- function acf_save_post( $post_id = 0, $values = null ) {
-
-
- if ( $values !== null ) {
- $_POST['acf'] = $values;
- }
-
- if ( empty( $_POST['acf'] ) ) {
- return false;
- }
-
- acf_set_form_data( 'post_id', $post_id );
-
- if ( ! acf_allow_unfiltered_html() ) {
- $_POST['acf'] = wp_kses_post_deep( $_POST['acf'] );
- }
-
-
- do_action( 'acf/save_post', $post_id );
-
- return true;
- }
- function _acf_do_save_post( $post_id = 0 ) {
-
- if ( ! empty( $_POST['acf'] ) ) {
- acf_update_values( $_POST['acf'], $post_id );
- }
-
- }
- add_action( 'acf/save_post', '_acf_do_save_post' );
|