Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Entity(s) causing path suffix conflicts are not indicated #6339

Closed
westonruter opened this issue May 31, 2021 · 1 comment · Fixed by #6374
Closed

Entity(s) causing path suffix conflicts are not indicated #6339

westonruter opened this issue May 31, 2021 · 1 comment · Fixed by #6374
Assignees
Labels
Enhancement New feature or improvement of an existing one Routing Handling URLs
Projects
Milestone

Comments

@westonruter
Copy link
Member

westonruter commented May 31, 2021

Feature description

In a couple cases recently users have reported the inability to select the Legacy Reader or Path Suffix paired URL structures and getting this notice:

There is a post, term, user, or some other entity that is already using the “amp” URL slug. For this reason, you cannot currently use the path suffix or legacy reader paired URL structures.

We don't expose the conflict in the UI at present.

For example, if I add this plugin code:

add_action('init', function () {
	register_taxonomy( 'amp', 'post' );
});

The settings screen shows:

image

The conflict is not shown, but the conflicts are returned in the API response.

In the console doing:

(await wp.apiFetch({path:'/amp/v1/options'})).endpoint_path_slug_conflicts

Results in:

image

So we just need to amend the notice with a list of what the conflicts are. This can be done in an unordered list.

The REST API endpoint should return the taxonomy slug, taxonomy translated name, and term edit link for each entity if available. When an option says “unavailable due to slug conflict” there should be a clear reference to the above notice.

public function get_endpoint_path_slug_conflicts() {
$conflicts = [];
$amp_slug = amp_get_slug();
$post_query = new WP_Query(
[
'post_type' => 'any',
'name' => $amp_slug,
'fields' => 'ids',
'posts_per_page' => 100,
]
);
if ( $post_query->post_count > 0 ) {
$conflicts['posts'] = $post_query->posts;
}
$term_query = new WP_Term_Query(
[
'slug' => $amp_slug,
'fields' => 'ids',
'hide_empty' => false,
]
);
if ( $term_query->terms ) {
$conflicts['terms'] = $term_query->terms;
}
$user = get_user_by( 'slug', $amp_slug );
if ( $user ) {
$conflicts['users'] = [ $user->ID ];
}
foreach ( get_post_types( [], 'objects' ) as $post_type ) {
if (
$amp_slug === $post_type->query_var
||
isset( $post_type->rewrite['slug'] ) && $post_type->rewrite['slug'] === $amp_slug
) {
$conflicts['post_types'][] = $post_type->name;
}
}
foreach ( get_taxonomies( [], 'objects' ) as $taxonomy ) {
if (
$amp_slug === $taxonomy->query_var
||
isset( $taxonomy->rewrite['slug'] ) && $taxonomy->rewrite['slug'] === $amp_slug
) {
$conflicts['taxonomies'][] = $taxonomy->name;
}
}
return $conflicts;
}

Also, I just realized that we should also check if the amp_get_slug() exists among WP_Rewrite::$endpoints and indicate that as another conflict.


Do not alter or remove anything below. The following sections will be managed by moderators only.

Acceptance criteria

Implementation brief

QA testing instructions

Demo

Changelog entry

@westonruter westonruter added Enhancement New feature or improvement of an existing one Routing Handling URLs labels May 31, 2021
@westonruter westonruter added this to the v2.1.3 milestone May 31, 2021
@westonruter westonruter added this to Backlog in Ongoing via automation May 31, 2021
@westonruter westonruter moved this from Backlog to To Do in Ongoing May 31, 2021
@westonruter westonruter self-assigned this Jun 11, 2021
@westonruter westonruter moved this from To Do to In Progress in Ongoing Jun 11, 2021
@westonruter westonruter changed the title Indicate what entity(s) are blocking the use of the paired endpoint suffix Entity(s) causing path suffix conflicts are not indicated Jun 11, 2021
@westonruter westonruter moved this from In Progress to Ready for Review in Ongoing Jun 11, 2021
@westonruter westonruter moved this from Ready for Review to Ready for QA in Ongoing Jun 12, 2021
@westonruter westonruter removed their assignment Jun 12, 2021
@westonruter westonruter self-assigned this Jun 30, 2021
@westonruter
Copy link
Member Author

QA Passed

I created a post, page, category, tag, and user all with the amp slug. I also registered a taxonomy and a post type with the amp slug. And I also registered an amp rewrite endpoint. I then got the message as expected, without the ability to select path suffix or legacy Reader structures:

image

@westonruter westonruter moved this from Ready for QA to QA Passed in Ongoing Jul 1, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement New feature or improvement of an existing one Routing Handling URLs
Projects
Ongoing
  
QA Passed
Development

Successfully merging a pull request may close this issue.

1 participant