/**
  * ACF needs $_POST['fields'] to be an array. GV supports both serialized array and array, so we just process earlier.
  *
  * @since 1.16.5
  *
  * @return void
  */
 private function fix_posted_fields()
 {
     if (is_admin() && isset($_POST['action']) && isset($_POST['post_type'])) {
         if ('editpost' === $_POST['action'] && 'gravityview' === $_POST['post_type']) {
             $_POST['fields'] = _gravityview_process_posted_fields();
         }
     }
 }
Пример #2
0
 /**
  * Save View configuration
  *
  * @access public
  * @param int $post_id Currently saved Post ID
  * @return void
  */
 function save_postdata($post_id)
 {
     if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
         return;
     }
     // validate post_type
     if (!isset($_POST['post_type']) || 'gravityview' != $_POST['post_type']) {
         return;
     }
     // validate user can edit and save View
     if (!GVCommon::has_cap('edit_gravityview', $post_id)) {
         do_action('gravityview_log_error', __METHOD__ . ' - Current user does not have the capability to edit View #' . $post_id, wp_get_current_user());
         return;
     }
     do_action('gravityview_log_debug', '[save_postdata] Saving View post type.', $_POST);
     $statii = array();
     // check if this is a start fresh View
     if (isset($_POST['gravityview_select_form_nonce']) && wp_verify_nonce($_POST['gravityview_select_form_nonce'], 'gravityview_select_form')) {
         $form_id = !empty($_POST['gravityview_form_id']) ? $_POST['gravityview_form_id'] : '';
         // save form id
         $statii['form_id'] = update_post_meta($post_id, '_gravityview_form_id', $form_id);
     }
     if (false === GVCommon::has_cap('gravityforms_create_form') && empty($statii['form_id'])) {
         do_action('gravityview_log_error', __METHOD__ . ' - Current user does not have the capability to create a new Form.', wp_get_current_user());
         return;
     }
     // Was this a start fresh?
     if (!empty($_POST['gravityview_form_id_start_fresh'])) {
         $statii['start_fresh'] = add_post_meta($post_id, '_gravityview_start_fresh', 1);
     } else {
         $statii['start_fresh'] = delete_post_meta($post_id, '_gravityview_start_fresh');
     }
     // Check if we have a template id
     if (isset($_POST['gravityview_select_template_nonce']) && wp_verify_nonce($_POST['gravityview_select_template_nonce'], 'gravityview_select_template')) {
         $template_id = !empty($_POST['gravityview_directory_template']) ? $_POST['gravityview_directory_template'] : '';
         // now save template id
         $statii['directory_template'] = update_post_meta($post_id, '_gravityview_directory_template', $template_id);
     }
     // save View Configuration metabox
     if (isset($_POST['gravityview_view_configuration_nonce']) && wp_verify_nonce($_POST['gravityview_view_configuration_nonce'], 'gravityview_view_configuration')) {
         // template settings
         if (empty($_POST['template_settings'])) {
             $_POST['template_settings'] = array();
         }
         $statii['template_settings'] = update_post_meta($post_id, '_gravityview_template_settings', $_POST['template_settings']);
         $fields = array();
         // Directory&single Visible Fields
         if (!empty($preset_fields)) {
             $fields = $preset_fields;
         } elseif (!empty($_POST['fields'])) {
             $fields = _gravityview_process_posted_fields();
         }
         $statii['directory_fields'] = update_post_meta($post_id, '_gravityview_directory_fields', $fields);
         // Directory Visible Widgets
         if (empty($_POST['widgets'])) {
             $_POST['widgets'] = array();
         }
         $statii['directory_widgets'] = update_post_meta($post_id, '_gravityview_directory_widgets', $_POST['widgets']);
     }
     // end save view configuration
     /**
      * @action `gravityview_view_saved` After a View has been saved in the admin
      * @param int $post_id ID of the View that has been saved
      * @param array $statii Array of statuses of the post meta saving processes. If saving worked, each key should be mapped to a value of the post ID (`directory_widgets` => `124`). If failed (or didn't change), the value will be false.
      * @since 1.17.2
      */
     do_action('gravityview_view_saved', $post_id, $statii);
     do_action('gravityview_log_debug', '[save_postdata] Update Post Meta Statuses (also returns false if nothing changed)', array_map('intval', $statii));
 }