/** * Save the custom post data. * * @since 2.0.0 * @param integer $post_id store post ID * @return void */ public function save_post($post_id) { global $wpsl_admin; if (empty($_POST['wpsl_meta_nonce']) || !wp_verify_nonce($_POST['wpsl_meta_nonce'], 'save_store_meta')) { return; } if (!isset($_POST['post_type']) || 'wpsl_stores' !== $_POST['post_type']) { return; } if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) { return; } if (is_int(wp_is_post_revision($post_id))) { return; } if (!current_user_can('edit_post', $post_id)) { return; } $this->store_data = $_POST['wpsl']; // Check if the hours are set through dropdowns. if (isset($this->store_data['hours']) && is_array($this->store_data['hours']) && !empty($this->store_data['hours'])) { $this->store_data['hours'] = $this->format_opening_hours(); } // Loop over the meta fields defined in the meta_box_fields and update the post meta data. foreach ($this->meta_box_fields() as $tab => $meta_fields) { foreach ($meta_fields as $field_key => $field_data) { // Either update or delete the post meta. if (isset($this->store_data[$field_key]) && $this->store_data[$field_key] != "") { if (isset($field_data['type']) && $field_data['type']) { $field_type = $field_data['type']; } else { $field_type = ''; } switch ($field_type) { case 'thumbnail': update_post_meta($post_id, 'wpsl_' . $field_key, absint($this->store_data[$field_key])); break; case 'checkbox': $checkbox_val = isset($this->store_data[$field_key]) ? 1 : 0; update_post_meta($post_id, 'wpsl_' . $field_key, $checkbox_val); break; case 'textarea': update_post_meta($post_id, 'wpsl_' . $field_key, wp_kses_post(trim(stripslashes($this->store_data[$field_key])))); break; default: if (is_array($this->store_data[$field_key])) { if (wpsl_is_multi_array($this->store_data[$field_key])) { array_walk_recursive($this->store_data[$field_key], 'wpsl_sanitize_multi_array'); update_post_meta($post_id, 'wpsl_' . $field_key, $this->store_data[$field_key]); } else { update_post_meta($post_id, 'wpsl_' . $field_key, array_map('sanitize_text_field', $this->store_data[$field_key])); } } else { update_post_meta($post_id, 'wpsl_' . $field_key, sanitize_text_field($this->store_data[$field_key])); } break; } } else { delete_post_meta($post_id, 'wpsl_' . $field_key); } } } /* * If all the required fields contain data, then check if we need to * geocode the address and if we should delete the autoload transient. * * Otherwise show a notice for 'missing data' and set the post status to pending. */ if (!$this->check_missing_meta_data($post_id)) { $wpsl_admin->geocode->check_geocode_data($post_id, $this->store_data); $wpsl_admin->maybe_delete_autoload_transient($post_id); } else { $wpsl_admin->notices->save('error', __('Failed to publish the store. Please fill in the required store details.', 'wpsl')); $this->set_post_pending($post_id); } }
/** * Save the notice. * * @since 2.0.0 * @param string $type The type of notice, either 'update' or 'error' * @param string $message The user message * @param bool $multiline True if the message contains multiple lines ( used with notices created in add-ons ). * @return void */ public function save($type, $message, $multiline = false) { $current_notices = get_option('wpsl_notices'); $new_notice = array('type' => $type, 'message' => $message); if ($multiline) { $new_notice['multiline'] = true; } if ($current_notices) { if (!wpsl_is_multi_array($current_notices)) { $current_notices = array($current_notices); } array_push($current_notices, $new_notice); update_option('wpsl_notices', $current_notices); } else { update_option('wpsl_notices', $new_notice); } }