Skip to content

Commit

Permalink
Transliterate only when sample permalink has been generated
Browse files Browse the repository at this point in the history
  • Loading branch information
aginev committed Nov 29, 2018
1 parent 8bc4376 commit 97dc70d
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/WpSanitize.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ class WpSanitize
*/
public static function title()
{
remove_filter('sanitize_title', 'sanitize_title_with_dashes', 11);
add_filter('get_sample_permalink', function ($permalink, $post_id, $title, $name, $post) {
$slug = $permalink[1] ?? '';

add_filter('sanitize_title', function ($title, $rawTitle, $context) {
if ($context == 'save') {
return Stringy::create($rawTitle)->slugify()->__toString();
} else {
return $title;
if ($slug) {
$permalink[1] = Stringy::create($permalink[1])->slugify()->__toString();
}
}, 10, 3);

return $permalink;
}, 10, 5);
}

/**
Expand All @@ -44,4 +44,4 @@ public static function filenames()
return Stringy::create($name)->slugify()->__toString() . '.' . $extension;
}, 10, 1);
}
}
}

0 comments on commit 97dc70d

Please sign in to comment.