Skip to content

Commit

Permalink
[FIX][G3] Fixing an issue with WordPres's handling of slashes in post…
Browse files Browse the repository at this point in the history
… meta
  • Loading branch information
RadoslavGeorgiev committed May 18, 2018
1 parent 794e59a commit e42aed9
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 28 deletions.
3 changes: 1 addition & 2 deletions core/classes/Datastore/Options.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ class Options extends Datastore {
function get_value_from_db( $key ) {
$all = wp_load_alloptions();


if( ! isset( $all[ $key ] ) ) {
return null;
}
Expand All @@ -39,7 +38,7 @@ function get_value_from_db( $key ) {
* @param mixed $value The value to be saved
*/
function save_value_in_db( $key, $value ) {
return update_option( $key, is_string( $value ) ? stripslashes( $value ) : $value );
return update_option( $key, $value );
}

/**
Expand Down
33 changes: 33 additions & 0 deletions core/classes/Datastore/Post_Meta.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,33 @@ function get_value_from_db( $key ) {
return get_post_meta( $this->post_id, $key, true );
}

/**
* Adds slashes deeply into an array.
*
* @since 3.0.3
*
* @param array $value The value to add slashes to.
* @return array
*/
public function addslashes_deep( $value ) {
if( ! is_array( $value ) ) {
return $value;
}

$added = array();
foreach( $value as $key => $item ) {
if( is_string( $item ) ) {
$item = addslashes( $item );
} elseif( is_array( $item ) ) {
$item = $this->addslashes_deep( $item );
}

$added[ $key ] = $item;
}

return $added;
}

/**
* Saves values in the dabase. Might as well update existing ones
*
Expand All @@ -36,6 +63,12 @@ function get_value_from_db( $key ) {
* @param mixed $value The value to be saved
*/
function save_value_in_db( $key, $value ) {
if( is_string( $value ) ) {
$value = addslashes( $value );
} elseif( is_array( $value ) ) {
$value = $this->addslashes_deep( $value );
}

return update_post_meta( $this->post_id, $key, $value );
}

Expand Down
13 changes: 0 additions & 13 deletions core/classes/Field/Text.php
Original file line number Diff line number Diff line change
Expand Up @@ -286,17 +286,4 @@ public function export() {

return $settings;
}

/**
* Sanititizes values before saving.
*
* @since 3.0
*
* @param string $value The value that is being saved.
* @return string
*/
protected function sanitize_value( $value ) {
// WordPress likes to strip slashes, so we are escaping them here
return addslashes( $value );
}
}
13 changes: 0 additions & 13 deletions core/classes/Field/Textarea.php
Original file line number Diff line number Diff line change
Expand Up @@ -219,17 +219,4 @@ public function process( $value ) {
return $value;
}
}

/**
* Sanititizes values before saving.
*
* @since 3.0
*
* @param string $value The value that is being saved.
* @return string
*/
protected function sanitize_value( $value ) {
// WordPress likes to strip slashes, so we are escaping them here
return addslashes( $value );
}
}

0 comments on commit e42aed9

Please sign in to comment.