/** * Save admin fields. * * Loops though the wpclubmanager options array and outputs each field. * * @access public * @param array $options Opens array to output * @return bool */ public static function save_fields($options) { if (empty($_POST)) { return false; } // Options to update will be stored here $update_options = array(); // Loop options and get values to save foreach ($options as $value) { if (!isset($value['id'])) { continue; } $type = isset($value['type']) ? sanitize_title($value['type']) : ''; // Get the option name $option_value = null; switch ($type) { // Standard types case "checkbox": if (isset($_POST[$value['id']])) { $option_value = 'yes'; } else { $option_value = 'no'; } break; case "textarea": if (isset($_POST[$value['id']])) { $option_value = wp_kses_post(trim(stripslashes($_POST[$value['id']]))); } else { $option_value = ''; } break; case "text": case 'email': case 'number': case "select": case "color": case 'password': case 'default_club': case "single_select_page": case "single_select_country": case 'radio': case 'license_key': if (isset($_POST[$value['id']])) { $option_value = wpcm_clean(stripslashes($_POST[$value['id']])); } else { $option_value = ''; } break; // Special types // Special types case "multiselect": case "image_width": if (isset($_POST[$value['id']]['width'])) { $update_options[$value['id']]['width'] = wpcm_clean(stripslashes($_POST[$value['id']]['width'])); $update_options[$value['id']]['height'] = wpcm_clean(stripslashes($_POST[$value['id']]['height'])); if (isset($_POST[$value['id']]['crop'])) { $update_options[$value['id']]['crop'] = 1; } else { $update_options[$value['id']]['crop'] = 0; } } else { $update_options[$value['id']]['width'] = $value['default']['width']; $update_options[$value['id']]['height'] = $value['default']['height']; $update_options[$value['id']]['crop'] = $value['default']['crop']; } break; // Custom handling // Custom handling default: do_action('wpclubmanager_update_option_' . $type, $value); break; } if (!is_null($option_value)) { // Check if option is an array if (strstr($value['id'], '[')) { parse_str($value['id'], $option_array); // Option name is first key $option_name = current(array_keys($option_array)); // Get old option value if (!isset($update_options[$option_name])) { $update_options[$option_name] = get_option($option_name, array()); } if (!is_array($update_options[$option_name])) { $update_options[$option_name] = array(); } // Set keys and value $key = key($option_array[$option_name]); $update_options[$option_name][$key] = $option_value; // Single value } else { $update_options[$value['id']] = $option_value; } } // Custom handling do_action('wpclubmanager_update_option', $value); } // Now save the options foreach ($update_options as $name => $value) { update_option($name, $value); } return true; }
/** * Bulk edit * @param integer $post_id * @param $match */ public function bulk_edit_save($post_id, $match) { if (!empty($_REQUEST['wpcm_team'])) { $teams = '_no_team' == $_REQUEST['wpcm_team'] ? '' : wpcm_clean($_REQUEST['wpcm_team']); wp_set_object_terms($post_id, $teams, 'wpcm_team'); } do_action('wpclubmanager_match_bulk_edit_save', $match); }