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

Prevent the usage of event titles that can conflict with event URLs #113

Merged
merged 2 commits into from
Feb 21, 2024

Conversation

amieiro
Copy link
Collaborator

@amieiro amieiro commented Feb 19, 2024

Currently, we can create events with some problematic URLs, used in the routes:

  • new
  • edit
  • attend
  • my-events

This PR adds a check to avoid the creation of events with these titles:

image

Fixes #89.

Copy link
Member

@psrpinto psrpinto left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested and it works

wporg-gp-translation-events.php Outdated Show resolved Hide resolved
@amieiro amieiro requested a review from psrpinto February 20, 2024 12:00
$title = isset( $_POST['event_title'] ) ? sanitize_text_field( wp_unslash( $_POST['event_title'] ) ) : '';
$description = isset( $_POST['event_description'] ) ? sanitize_text_field( wp_unslash( $_POST['event_description'] ) ) : '';
$event_start = isset( $_POST['event_start'] ) ? sanitize_text_field( wp_unslash( $_POST['event_start'] ) ) : '';
$event_end = isset( $_POST['event_end'] ) ? sanitize_text_field( wp_unslash( $_POST['event_end'] ) ) : '';
$event_timezone = isset( $_POST['event_timezone'] ) ? sanitize_text_field( wp_unslash( $_POST['event_timezone'] ) ) : '';
if ( isset( $title ) && in_array( sanitize_title( $title ), $invalid_slugs, true ) ) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It has been sanitized above, there's no need to sanitize, right? Though maybe above it should be changed to sanitize_title() instead of sanitize_text_field()?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What I want in this line is the slug, to look for it in the array, so I think is the correct function, because the title has been sanitized before.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I understand now, thanks 👍

@amieiro amieiro merged commit 16e52d3 into trunk Feb 21, 2024
2 checks passed
@amieiro amieiro deleted the prevent-problematic-slugs branch February 21, 2024 08:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Prevent creating events with slugs we use
2 participants