public function admin_save($init_run = false) { $error = false; if (isset($_POST['save'])) { $nonce_verified = wp_verify_nonce($_REQUEST['_catablog_save_nonce'], 'catablog_save'); if ($nonce_verified) { $post_vars = $_POST; $post_vars = array_map('stripslashes_deep', $post_vars); // trim whitespace from specific fields $trim_fields = array('title', 'description', 'link', 'price', 'product_code'); foreach ($trim_fields as $field) { $post_vars[$field] = trim($post_vars[$field]); } // build a categories array $post_vars['categories'] = isset($post_vars['categories']) ? $post_vars['categories'] : array(); foreach ($post_vars['categories'] as $key => $value) { $post_vars['categories'][$key] = (int) $value; } // build a sub images array if (!isset($post_vars['sub_images'])) { $post_vars['sub_images'] = array(); } // create new object with modified $post_vars variable $result = new CataBlogItem($post_vars); $validate = $result->validate(); if ($validate === true) { $write = $result->save(); if ($write === true) { header('Location: admin.php?page=catablog&id=' . $result->getId() . '&message=1'); die; } else { $error = $write; } } else { $error = $validate; } } else { $error = __("WordPress Nonce Error, please reload the form and try again.", 'catablog'); } } else { $error = __("full form was not submitted, please try again.", 'catablog'); } if (!$init_run && $error) { $this->wp_error($error); include_once $this->directories['template'] . '/admin-edit.php'; return true; } }