feat: add sanitize value on update mapper properties

This commit is contained in:
vnmedeiros 2021-03-22 23:19:20 -03:00
parent 5450d7670f
commit 003cb26411
1 changed files with 12 additions and 16 deletions

View File

@ -151,9 +151,10 @@ abstract class Repository {
$obj->WP_Post->post_status = 'publish'; $obj->WP_Post->post_status = 'publish';
} }
$sanitized_title = $this->sanitize_value($obj->get('name'));
$sanitized_desc = $this->sanitize_value($obj->get('description'));
if ( $obj instanceof Entities\Item ) { if ( $obj instanceof Entities\Item ) {
$sanitized_title = $this->sanitize_value($obj->get('title')); $sanitized_title = $this->sanitize_value($obj->get('title'));
$sanitized_desc = $this->sanitize_value($obj->get('description'));
// get collection to determine post type // get collection to determine post type
$collection = $obj->get_collection(); $collection = $obj->get_collection();
@ -164,18 +165,11 @@ abstract class Repository {
$post_t = $collection->get_db_identifier(); $post_t = $collection->get_db_identifier();
$obj->WP_Post->post_type = $post_t; $obj->WP_Post->post_type = $post_t;
$obj->WP_Post->post_title = $sanitized_title;
$obj->WP_Post->post_content = $sanitized_desc;
$obj_post_type = 'tainacan-item'; $obj_post_type = 'tainacan-item';
do_action( "tainacan-pre-insert-$obj_post_type", $obj ); do_action( "tainacan-pre-insert-$obj_post_type", $obj );
} }
$obj->WP_Post->post_title = $sanitized_title;
if ($obj instanceof Entities\Collection || $obj instanceof Entities\Metadatum || $obj instanceof Entities\Taxonomy) {
$sanitized = $this->sanitize_value($obj->get('name'));
$sanitized_desc = $this->sanitize_value($obj->get('description'));
$obj->WP_Post->post_title = $sanitized;
$obj->WP_Post->post_content = $sanitized_desc; $obj->WP_Post->post_content = $sanitized_desc;
}
$id = wp_insert_post( $obj->WP_Post ); $id = wp_insert_post( $obj->WP_Post );
if ($id instanceof \WP_Error || 0 === $id) { if ($id instanceof \WP_Error || 0 === $id) {
@ -258,10 +252,12 @@ abstract class Repository {
} }
function maybe_add_slashes( $value ) { function maybe_add_slashes( $value ) {
if ( is_string( $value ) && strpos( $value, '\\' ) !== false ) { if ( is_string( $value ) ) {
return wp_slash( $value ); if( strpos( $value, '\\' ) !== false ) {
return wp_slash( $this->sanitize_value($value) );
}
return $this->sanitize_value($value);
} }
return $value; return $value;
} }