/** * Clean input fields */ function go_portfolio_clean_input($input_data = array(), $html_allowed_keys = array(), $trash_keys = array()) { foreach ($input_data as $data_key => $data_value) { if (is_array($data_value)) { go_portfolio_clean_input($data_value, $html_allowed_keys, $trash_keys); } elseif (in_array($data_key, $trash_keys)) { unset($input_data[$data_key]); continue; } else { $input_data[$data_key] = stripslashes(trim($input_data[$data_key])); if (empty($html_allowed_keys) || !in_array($data_key, $html_allowed_keys)) { $input_data[$data_key] = sanitize_text_field($input_data[$data_key]); } } } return $input_data; }
/* Get general settings db data */ $general_settings = get_option(self::$plugin_prefix . '_general_settings'); /* Get cpts db data */ $custom_post_types = get_option(self::$plugin_prefix . '_cpts'); $portfolio_cpts = array(); if (isset($custom_post_types) && !empty($custom_post_types)) { foreach ($custom_post_types as $cpt_key => $custom_post_type) { $portfolio_cpts[$cpt_key] = $custom_post_type['slug']; } } /* Handle post */ if (!empty($_POST) && check_admin_referer($this->plugin_slug . basename(__FILE__), $this->plugin_slug . '-nonce')) { $reponse = array(); $referrer = $_POST['_wp_http_referer']; /* Clean post fields */ $_POST = go_portfolio_clean_input($_POST, array(), array('go-portfolio-nonce', '_wp_http_referer')); $new_general_settings = $_POST; /* Save data to db */ if (!isset($response['result']) || $response['result'] != 'error') { if ($general_settings != $new_general_settings) { update_option(self::$plugin_prefix . '_general_settings', $new_general_settings); } self::generate_styles(); /* Set the reponse message */ $response['result'] = 'success'; $response['message'][] = __('General settings has been successfully updated.', 'go_portfolio_textdomain'); set_transient(md5($screen->id . '-response'), $response, 30); } /* Redirect */ wp_redirect(admin_url('admin.php?page=' . $_GET['page'] . '&updated=true')); exit;
$general_settings = get_option(self::$plugin_prefix . '_general_settings'); /* Get cpts db data */ $custom_post_types = get_option(self::$plugin_prefix . '_cpts'); if (isset($custom_post_types) && !empty($custom_post_types)) { foreach ($custom_post_types as $cpt_key => $custom_post_type) { $portfolio_cpts[$cpt_key] = $custom_post_type['slug']; } } /* Get portfolios db data */ $portfolios = get_option(self::$plugin_prefix . '_portfolios'); /* Handle post */ if (!empty($_POST) && check_admin_referer($this->plugin_slug . basename(__FILE__), $this->plugin_slug . '-nonce')) { $reponse = array(); $referrer = $_POST['_wp_http_referer']; /* Clean post fields */ $_POST = go_portfolio_clean_input($_POST, array('template-data', 'style-data', 'excerpt-allowed-tags'), array('go-portfolio-nonce', '_wp_http_referer')); /* Default Page POST */ if (isset($_POST['action-type']) && isset($_POST['cpt-item'])) { $uniqid = !empty($_POST['cpt-item']) ? sanitize_key($_POST['cpt-item']) : ''; /* Edit action */ if ($_POST['action-type'] == 'edit') { if (empty($_POST['cpt-item'])) { wp_redirect(admin_url('admin.php?page=' . $_GET['page'] . '&edit=new')); } else { wp_redirect(admin_url('admin.php?page=' . $_GET['page'] . '&edit=' . $uniqid)); } /* Clone action */ } elseif ($_POST['action-type'] == 'clone' && !empty($uniqid)) { /* Do stuff */ $new_uniqid = uniqid(); $new_portfolios = $portfolios;