Ejemplo n.º 1
0
 function save_comment($comment_id)
 {
     // bail early if not valid nonce
     if (!acf_verify_nonce('comment')) {
         return $comment_id;
     }
     // validate and save
     if (acf_validate_save_post(true)) {
         acf_save_post("comment_{$comment_id}");
     }
 }
Ejemplo n.º 2
0
 function admin_load()
 {
     // globals
     global $plugin_page;
     // set currrent
     $this->view['slug'] = $plugin_page;
     // verify and remove nonce
     if (acf_verify_nonce('options')) {
         // save data
         if (acf_validate_save_post(true)) {
             // get post_id (allow lang modification)
             $post_id = acf_get_valid_post_id('options');
             // save
             acf_save_post($post_id);
             // redirect
             wp_redirect(admin_url("admin.php?page={$plugin_page}&message=1"));
             exit;
         }
     }
     add_action('admin_enqueue_scripts', array($this, 'admin_enqueue_scripts'));
 }
Ejemplo n.º 3
0
 function ajax_validate_save_post()
 {
     // validate
     if (!acf_verify_ajax()) {
         die;
     }
     // vars
     $json = array('valid' => 1, 'errors' => 0);
     // success
     if (acf_validate_save_post()) {
         wp_send_json_success($json);
     }
     // update vars
     $json['valid'] = 0;
     $json['errors'] = acf_get_validation_errors();
     // return
     wp_send_json_success($json);
 }
Ejemplo n.º 4
0
 function save_widget()
 {
     // bail early if no nonce
     if (!acf_verify_nonce('widget')) {
         return;
     }
     // vars
     $id = acf_maybe_get($_POST, 'widget-id');
     // save data
     if ($id && acf_validate_save_post()) {
         acf_save_post("widget_{$id}");
     }
 }
Ejemplo n.º 5
0
 function ajax_validate_save_post()
 {
     // bail early if _acfnonce is missing
     if (!isset($_POST['_acfnonce'])) {
         wp_send_json_error();
     }
     // vars
     $json = array('valid' => 1, 'errors' => 0);
     // success
     if (acf_validate_save_post()) {
         wp_send_json_success($json);
     }
     // update vars
     $json['valid'] = 0;
     $json['errors'] = acf_get_validation_errors();
     // return
     wp_send_json_success($json);
 }
Ejemplo n.º 6
0
 function save_widget($instance, $new_instance, $old_instance, $widget)
 {
     // verify and remove nonce
     if (!acf_verify_nonce('widget')) {
         return $instance;
     }
     // save data
     if (acf_validate_save_post()) {
         acf_save_post("widget_{$widget->id}");
     }
     // return
     return $instance;
 }
Ejemplo n.º 7
0
 function admin_load()
 {
     // globals
     global $plugin_page;
     // vars
     $this->page = acf_get_options_page($plugin_page);
     // verify and remove nonce
     if (acf_verify_nonce('options')) {
         // save data
         if (acf_validate_save_post(true)) {
             // get post_id (allow lang modification)
             $post_id = acf_get_valid_post_id($this->page['post_id']);
             // set autoload
             acf_update_setting('autoload', $this->page['autoload']);
             // save
             acf_save_post($post_id);
             // redirect
             wp_redirect(admin_url("admin.php?page={$plugin_page}&message=1"));
             exit;
         }
     }
     // actions
     add_action('admin_enqueue_scripts', array($this, 'admin_enqueue_scripts'));
 }
Ejemplo n.º 8
0
 function save_attachment($post, $attachment)
 {
     // bail early if not valid nonce
     if (!acf_verify_nonce('attachment')) {
         return $post;
     }
     // validate and save
     if (acf_validate_save_post(true)) {
         acf_save_post($post['ID']);
     }
     // return
     return $post;
 }
Ejemplo n.º 9
0
 function ajax_validate_save_post()
 {
     // validate
     if (!isset($_POST['_acfnonce'])) {
         // ignore validation, this form $_POST was not correctly configured
         die;
     }
     // success
     if (acf_validate_save_post()) {
         $json = array('result' => 1, 'message' => __('Validation successful', 'acf'), 'errors' => 0);
         die(json_encode($json));
     }
     // fail
     $json = array('result' => 0, 'message' => __('Validation failed', 'acf'), 'errors' => acf_get_validation_errors());
     // update message
     $i = count($json['errors']);
     $json['message'] .= '. ' . sprintf(_n('1 field below is invalid.', '%s fields below are invalid.', $i, 'acf_vf'), $i) . ' ' . __('Please check your values and submit again.', 'acf_vf');
     die(json_encode($json));
 }
Ejemplo n.º 10
0
 function customizer_widget_update_callback($instance, $new_instance, $old_instance, $widget)
 {
     // bail early if not valid
     if (!acf_validate_save_post()) {
         // vars
         $errors = acf_get_validation_errors();
         $total = count($errors);
         // message
         $message = __('Validation failed', 'acf') . '. ';
         $message .= sprintf(_n('1 field requires attention.', '%d fields require attention.', $total, 'acf'), $total);
         // add missing WP JS to remove spinning
         // also set state to 'saved' which disables the save button
         $message .= '<script type="text/javascript">';
         $message .= '(function($) {';
         $message .= '$(".customize-control.previewer-loading").removeClass("previewer-loading"); ';
         $message .= 'wp.customize.state("saved").set( true ); ';
         $message .= '})(jQuery);';
         $message .= '</script>';
         // return JSON error
         wp_send_json_error(array('message' => $message));
     } else {
         $instance['acf'] = array('ID' => 'widget_' . $widget->id, 'values' => false, 'reference' => array());
         // append acf $_POST data to instance
         // this allows preview JS data to contain acf values
         $instance['acf']['values'] = $_POST['acf'];
         // backup name => key reference
         // this will allow the customizer preview to correctly load the field when attempting to run acf_load_value and acf_format_value functions on newly added widgets
         foreach ($_POST['acf'] as $k => $v) {
             // get field
             $field = acf_get_field($k);
             // continue if no field
             if (!$field) {
                 continue;
             }
             // update
             $instance['acf']['reference'][$field['name']] = $field['key'];
         }
     }
     // return
     return $instance;
 }
Ejemplo n.º 11
0
 function customizer_widget_update_callback($instance, $new_instance, $old_instance, $widget)
 {
     // add preview_values reference for later use in load_value filter
     // WP will re-generate the widget form HTML, and we need to load the $_POST data, not the DB data
     $this->preview_values["widget_{$widget->id}"] = $_POST['acf'];
     // add filter
     add_filter('acf/load_value', array($this, 'load_value'), 10, 3);
     // bail early if not valid
     if (!acf_validate_save_post()) {
         // vars
         $errors = acf_get_validation_errors();
         $total = count($errors);
         // message
         $message = __('Validation failed', 'acf') . '. ';
         $message .= sprintf(_n('1 field requires attention.', '%d fields require attention.', $total, 'acf'), $total);
         // add missing WP JS to remove spinning
         // also set state to 'saved' which disables the save button
         $message .= '<script type="text/javascript">';
         $message .= '(function($) {';
         $message .= '$(".customize-control.previewer-loading").removeClass("previewer-loading"); ';
         $message .= 'wp.customize.state("saved").set( true ); ';
         $message .= '})(jQuery);';
         $message .= '</script>';
         // return JSON error
         wp_send_json_error(array('message' => $message));
     } else {
         // append acf $_POST data to instance
         // this allows preview JS data to contain acf values
         $instance['acf'] = $_POST['acf'];
     }
     // return
     return $instance;
 }
Ejemplo n.º 12
0
 function save_post($post_id, $post)
 {
     // bail ealry if no allowed to save this post type
     if (!$this->allow_save_post($post)) {
         return $post_id;
     }
     // ensure saving to the correct post
     if (!acf_verify_nonce('post', $post_id)) {
         return $post_id;
     }
     // validate for published post (allow draft to save without validation)
     if (get_post_status($post_id) == 'publish') {
         // show errors
         acf_validate_save_post(true);
     }
     // save
     acf_save_post($post_id);
     // return
     return $post_id;
 }
Ejemplo n.º 13
0
 function admin_load()
 {
     // globals
     global $plugin_page;
     // vars
     $this->page = acf_get_options_page($plugin_page);
     // verify and remove nonce
     if (acf_verify_nonce('options')) {
         // save data
         if (acf_validate_save_post(true)) {
             // get post_id (allow lang modification)
             $post_id = acf_get_valid_post_id($this->page['post_id']);
             // set autoload
             acf_update_setting('autoload', $this->page['autoload']);
             // save
             acf_save_post($post_id);
             // redirect
             wp_redirect(add_query_arg(array('message' => '1')));
             exit;
         }
     }
     // load acf scripts
     acf_enqueue_scripts();
     // actions
     add_action('acf/input/admin_enqueue_scripts', array($this, 'admin_enqueue_scripts'));
     add_action('acf/input/admin_head', array($this, 'admin_head'));
     // add columns support
     add_screen_option('layout_columns', array('max' => 2, 'default' => 2));
 }
Ejemplo n.º 14
0
 function save_post($post_id)
 {
     // do not save if this is an auto save routine
     if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
         return $post_id;
     }
     // verify and remove nonce
     if (!acf_verify_nonce('post', $post_id)) {
         return $post_id;
     }
     // validate and save
     if (get_post_status($post_id) == 'publish') {
         if (acf_validate_save_post(true)) {
             acf_save_post($post_id);
         }
     } else {
         acf_save_post($post_id);
     }
     // return
     return $post_id;
 }
Ejemplo n.º 15
0
function acf_form_head()
{
    // verify nonce
    if (acf_verify_nonce('acf_form')) {
        // validate data
        if (acf_validate_save_post(true)) {
            // form
            $form = acf_extract_var($_POST, '_acf_form');
            $form = @json_decode(base64_decode($form), true);
            // validate
            if (empty($form)) {
                return;
            }
            // allow for custom save
            $form['post_id'] = apply_filters('acf/pre_save_post', $form['post_id'], $form);
            // save
            acf_save_post($form['post_id']);
            // redirect
            if (!empty($form['return'])) {
                // update %placeholders%
                $form['return'] = str_replace('%post_url%', get_permalink($form['post_id']), $form['return']);
                // redirect
                wp_redirect($form['return']);
                exit;
            }
        }
        // if
    }
    // if
    // load acf scripts
    acf_enqueue_scripts();
}
Ejemplo n.º 16
0
 function save_term($term_id, $tt_id, $taxonomy)
 {
     // verify and remove nonce
     if (!acf_verify_nonce('taxonomy')) {
         return $term_id;
     }
     // save data
     if (acf_validate_save_post(true)) {
         acf_save_post("{$taxonomy}_{$term_id}");
     }
 }
Ejemplo n.º 17
0
 function save_term($term_id, $tt_id, $taxonomy)
 {
     // verify and remove nonce
     if (!acf_verify_nonce('taxonomy')) {
         return $term_id;
     }
     // valied and show errors
     acf_validate_save_post(true);
     // save
     acf_save_post('term_' . $term_id);
 }
Ejemplo n.º 18
0
function acf_form_head()
{
    // verify nonce
    if (acf_verify_nonce('acf_form')) {
        // validate data
        if (acf_validate_save_post(true)) {
            // form
            $GLOBALS['acf_form'] = acf_extract_var($_POST, '_acf_form');
            $GLOBALS['acf_form'] = @json_decode(base64_decode($GLOBALS['acf_form']), true);
            // validate
            if (empty($GLOBALS['acf_form'])) {
                return;
            }
            // vars
            $post_id = acf_maybe_get($GLOBALS['acf_form'], 'post_id', 0);
            // allow for custom save
            $post_id = apply_filters('acf/pre_save_post', $post_id, $GLOBALS['acf_form']);
            // save
            acf_save_post($post_id);
            // vars
            $return = acf_maybe_get($GLOBALS['acf_form'], 'return', '');
            // redirect
            if ($return) {
                // update %placeholders%
                $return = str_replace('%post_url%', get_permalink($post_id), $return);
                // redirect
                wp_redirect($return);
                exit;
            }
        }
        // if
    }
    // if
    // load acf scripts
    acf_enqueue_scripts();
}
Ejemplo n.º 19
0
 function save_post($post_id, $post)
 {
     // do not save if this is an auto save routine
     if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
         return $post_id;
     }
     // bail early if is acf-field-group or acf-field
     if (in_array($post->post_type, array('acf-field', 'acf-field-group'))) {
         return $post_id;
     }
     // verify and remove nonce
     if (!acf_verify_nonce('post', $post_id)) {
         return $post_id;
     }
     // validate and save
     if (get_post_status($post_id) == 'publish') {
         if (acf_validate_save_post(true)) {
             acf_save_post($post_id);
         }
     } else {
         acf_save_post($post_id);
     }
     // return
     return $post_id;
 }
Ejemplo n.º 20
0
 function widget_update_callback($instance, $new_instance, $old_instance, $widget)
 {
     // bail early if no nonce
     if (!acf_verify_nonce('widget')) {
         return $instance;
     }
     // save
     if (acf_validate_save_post()) {
         acf_save_post("widget_{$widget->id}");
     }
     // return
     return $instance;
 }
Ejemplo n.º 21
0
 function save_user($user_id)
 {
     // verify and remove nonce
     if (!acf_verify_nonce('user')) {
         return $user_id;
     }
     // save data
     if (acf_validate_save_post(true)) {
         acf_save_post("user_{$user_id}");
     }
 }
Ejemplo n.º 22
0
 function ajax_validate_save_post()
 {
     // validate
     if (!isset($_POST['_acfnonce'])) {
         // ignore validation, this form $_POST was not correctly configured
         die;
     }
     // success
     if (acf_validate_save_post()) {
         $json = array('result' => 1, 'message' => __('Validation successful', 'acf'), 'errors' => 0);
         die(json_encode($json));
     }
     // fail
     $json = array('result' => 0, 'message' => __('Validation failed', 'acf'), 'errors' => acf_get_validation_errors());
     // update message
     $i = count($json['errors']);
     $json['message'] .= '. ' . sprintf(_n('1 required field below is empty', '%s required fields below are empty', $i, 'acf'), $i);
     // return
     die(json_encode($json));
 }
Ejemplo n.º 23
0
 function ajax_validate_save_post()
 {
     // bail early if _acfnonce is missing
     if (!isset($_POST['_acfnonce'])) {
         wp_send_json_error();
     }
     // vars
     $json = array('message' => __('Validation successful', 'acf'), 'valid' => 1, 'errors' => 0);
     // success
     if (acf_validate_save_post()) {
         wp_send_json_success($json);
     }
     // update vars
     $json['message'] = __('Validation failed', 'acf');
     $json['valid'] = 0;
     $json['errors'] = acf_get_validation_errors();
     // update message
     if (count($json['errors']) == 1) {
         $json['message'] .= '. ' . __('1 required field below is empty', 'acf');
     } else {
         $json['message'] .= '. ' . sprintf(__('%s required fields below are empty', 'acf'), count($json['errors']));
     }
     // return
     wp_send_json_success($json);
 }