Skip to content

Term mutations adding extra slashes to names, descriptions, slugs #2378

@jasonbahl

Description

@jasonbahl

When using a WPGraphQL mutation to update/create a taxonomy term that contains an apostrophe, WPGraphQL is saving the slashes to the database. This is not consistent with other core behaviors for creating/inserting terms (Admin Dashboard, WP REST API)

Steps to reproduce:

As an authenticated user, execute the following mutation:

mutation {
  createTag( input: { name: "What's up!" } ) {
    tag {
      name
    }
  }
}

This will give us the tag name What\\'s up! in the response.

CleanShot 2022-05-16 at 09 28 05

And if we look at the database we see the raw value What\'s up! was stored.

CleanShot 2022-05-16 at 09 29 48

Expectation

I expect the value in the database to not be stored with the slash, as seen when doing Tag mutations with the WP REST API.

If we create a term using the WP REST API

This gives us the expected name in the response:

CleanShot 2022-05-16 at 09 30 18

And stores as expected in the database:

CleanShot 2022-05-16 at 09 31 36

Quick Solution

Until this is fixed in WPGraphQL, users should be able to use the following filter:

add_action('graphql_term_object_insert_term_args', 'clean_tag_name');

function clean_tag_name($args) {
	$args['name']        = stripslashes($args['name']);
	$args['description'] = stripslashes($args['description']);
	$args['slug']        = stripslashes($args['slug']);
	return $args;
}

Metadata

Metadata

Assignees

Labels

component: mutationsRelating to GraphQL Mutationsobject type: termRelating to the Term Typesstatus: in progressCurrently being worked ontype: bugIssue that causes incorrect or unexpected behavior

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions