cleanup [4382] a bit

git-svn-id: http://svn.automattic.com/wordpress/trunk@4383 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
markjaquith 2006-10-13 00:23:25 +00:00
parent 854cf56a7d
commit 21d1fc231c
5 changed files with 12 additions and 12 deletions

View File

@ -983,7 +983,7 @@ function list_meta($meta) {
$style .= ' hidden'; $style .= ' hidden';
if ( is_serialized($entry['meta_value']) ) { if ( is_serialized($entry['meta_value']) ) {
if ( 's' == $entry['meta_value']{0} ) { if ( is_serialized_string($entry['meta_value']) ) {
// this is a serialized string, so we should display it // this is a serialized string, so we should display it
$entry['meta_value'] = maybe_unserialize($entry['meta_value']); $entry['meta_value'] = maybe_unserialize($entry['meta_value']);
} else { } else {
@ -1068,7 +1068,7 @@ function add_meta($post_ID) {
$metakeyselect = $wpdb->escape(stripslashes(trim($_POST['metakeyselect']))); $metakeyselect = $wpdb->escape(stripslashes(trim($_POST['metakeyselect'])));
$metakeyinput = $wpdb->escape(stripslashes(trim($_POST['metakeyinput']))); $metakeyinput = $wpdb->escape(stripslashes(trim($_POST['metakeyinput'])));
$metavalue = prepare_data(stripslashes((trim($_POST['metavalue'])))); $metavalue = maybe_serialize(stripslashes((trim($_POST['metavalue']))));
$metavalue = $wpdb->escape($metavalue); $metavalue = $wpdb->escape($metavalue);
if ( ('0' === $metavalue || !empty ($metavalue)) && ((('#NONE#' != $metakeyselect) && !empty ($metakeyselect)) || !empty ($metakeyinput)) ) { if ( ('0' === $metavalue || !empty ($metavalue)) && ((('#NONE#' != $metakeyselect) && !empty ($metakeyselect)) || !empty ($metakeyinput)) ) {
@ -1100,8 +1100,8 @@ function delete_meta($mid) {
function update_meta($mid, $mkey, $mvalue) { function update_meta($mid, $mkey, $mvalue) {
global $wpdb; global $wpdb;
if ( is_serialized(stripslashes($mvalue)) ) // $mvalue looks to be already serialized, so we should serialize it again to prevent the data from coming out in a different form than it came in $mvalue = maybe_serialize(stripslashes($mvalue));
$mvalue = serialize($mvalue); $mvalue = $wpdb->escape($mvalue);
$mid = (int) $mid; $mid = (int) $mid;
return $wpdb->query("UPDATE $wpdb->postmeta SET meta_key = '$mkey', meta_value = '$mvalue' WHERE meta_id = '$mid'"); return $wpdb->query("UPDATE $wpdb->postmeta SET meta_key = '$mkey', meta_value = '$mvalue' WHERE meta_id = '$mid'");
} }

View File

@ -128,7 +128,7 @@ $options = $wpdb->get_results("SELECT * FROM $wpdb->options ORDER BY option_name
foreach ( (array) $options as $option) : foreach ( (array) $options as $option) :
$disabled = ''; $disabled = '';
if ( is_serialized($option->option_value) ) { if ( is_serialized($option->option_value) ) {
if ( 's' == $option->option_value{0} ) { if ( is_serialized_string($option->option_value) ) {
// this is a serialized string, so we should display it // this is a serialized string, so we should display it
$value = wp_specialchars(maybe_unserialize($option->option_value), 'single'); $value = wp_specialchars(maybe_unserialize($option->option_value), 'single');
$options_to_update[] = $option->option_name; $options_to_update[] = $option->option_name;

View File

@ -257,7 +257,7 @@ function update_option($option_name, $newvalue) {
} }
$_newvalue = $newvalue; $_newvalue = $newvalue;
$newvalue = prepare_data($newvalue); $newvalue = maybe_serialize($newvalue);
wp_cache_set($option_name, $newvalue, 'options'); wp_cache_set($option_name, $newvalue, 'options');
@ -279,7 +279,7 @@ function add_option($name, $value = '', $description = '', $autoload = 'yes') {
if ( false !== get_option($name) ) if ( false !== get_option($name) )
return; return;
$value = prepare_data($value); $value = maybe_serialize($value);
wp_cache_set($name, $value, 'options'); wp_cache_set($name, $value, 'options');
@ -301,7 +301,7 @@ function delete_option($name) {
return true; return true;
} }
function prepare_data($data) { function maybe_serialize($data) {
if ( is_string($data) ) if ( is_string($data) )
$data = trim($data); $data = trim($data);
elseif ( is_array($data) || is_object($data) ) elseif ( is_array($data) || is_object($data) )

View File

@ -231,7 +231,7 @@ function add_post_meta($post_id, $key, $value, $unique = false) {
$post_meta_cache[$post_id][$key][] = $value; $post_meta_cache[$post_id][$key][] = $value;
$value = prepare_data($value); $value = maybe_serialize($value);
$value = $wpdb->escape($value); $value = $wpdb->escape($value);
$wpdb->query("INSERT INTO $wpdb->postmeta (post_id,meta_key,meta_value) VALUES ('$post_id','$key','$value')"); $wpdb->query("INSERT INTO $wpdb->postmeta (post_id,meta_key,meta_value) VALUES ('$post_id','$key','$value')");
@ -310,11 +310,11 @@ function update_post_meta($post_id, $key, $value, $prev_value = '') {
$post_id = (int) $post_id; $post_id = (int) $post_id;
$original_value = $value; $original_value = $value;
$value = prepare_data($value); $value = maybe_serialize($value);
$value = $wpdb->escape($value); $value = $wpdb->escape($value);
$original_prev = $prev_value; $original_prev = $prev_value;
$prev_value = prepare_data($prev_value); $prev_value = maybe_serialize($prev_value);
$prev_value = $wpdb->escape($prev_value); $prev_value = $wpdb->escape($prev_value);
if (! $wpdb->get_var("SELECT meta_key FROM $wpdb->postmeta WHERE meta_key = '$key' AND post_id = '$post_id'") ) { if (! $wpdb->get_var("SELECT meta_key FROM $wpdb->postmeta WHERE meta_key = '$key' AND post_id = '$post_id'") ) {

View File

@ -116,7 +116,7 @@ function update_usermeta( $user_id, $meta_key, $meta_value ) {
// FIXME: usermeta data is assumed to be already escaped // FIXME: usermeta data is assumed to be already escaped
$meta_value = stripslashes($meta_value); $meta_value = stripslashes($meta_value);
$meta_value = prepare_data($meta_value); $meta_value = maybe_serialize($meta_value);
$meta_value = $wpdb->escape($meta_value); $meta_value = $wpdb->escape($meta_value);
if (empty($meta_value)) { if (empty($meta_value)) {