Skip to content

Commit

Permalink
fix/#301_url_requirement_is_broken_by_ellipsis_colon_and_other_charac…
Browse files Browse the repository at this point in the history
…ters (#733)
  • Loading branch information
richaferry authored Aug 7, 2024
1 parent 8da595a commit bc49d9e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
16 changes: 14 additions & 2 deletions modules/permalinks/assets/js/meta-box.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,18 @@
slugHasValidChars = true;

if (PP_Checklists.is_gutenberg_active()) {
var slugField = jQuery('.editor-post-permalink-editor__edit');
let slugField = $('.editor-post-permalink-editor__edit');
if(slugField.length) {
// Gutenberg 8.4+ or wordpress 5.5+
slugField = $('.editor-post-title');
}

if (slugField.length > 0) {
slug = slugField.val();
if (!slug) {
// Gutenberg 8.4+ or wordpress 5.5+
slug = slugField.text();
}
} else {
var editor = PP_Checklists.getEditor(),
edits = editor.getPostEdits();
Expand All @@ -65,9 +73,13 @@
slug = edits.slug;
} else {
slug = editor.getCurrentPost().slug;
const generatedSlug = editor.getCurrentPost().generated_slug;

if (slug === '') {
if (typeof edits.title !== 'undefined') {
// Gutenberg 8.4+ or wordpress 5.5+
if (typeof generatedSlug !== 'undefined') {
slug = generatedSlug;
} else if (typeof edits.title !== 'undefined') {
slug = edits.title.replace(/[\s!\?]/g, '').toLocaleLowerCase();
}
}
Expand Down
5 changes: 3 additions & 2 deletions modules/permalinks/lib/Requirement/ValidChars.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,9 @@ public function get_option($option_name)
*/
public function get_current_status($post, $option_value)
{
$slug = $post->post_name;
// Fallback to title if slug is empty
$slug = $post->post_name ?: $post->post_title;

return preg_match('/^[a-z0-9\-_]+$/', $slug) === 1;
return preg_match('/^[a-z0-9_\-]+$/', sanitize_title($slug)) === 1;
}
}

0 comments on commit bc49d9e

Please sign in to comment.