Advertisement
fahimmurshed

Increasing Unicode Permalinks Limit

Apr 7th, 2024
743
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.27 KB | None | 0 0
  1. // first of all lets remove standard hook
  2. remove_filter( 'sanitize_title', 'sanitize_title_with_dashes' );
  3.  
  4. // More info here https://wordpress.stackexchange.com/questions/89767/how-to-increase-the-character-limit-for-post-name-of-200
  5. // add our custom hook
  6. add_filter( 'sanitize_title', 'wpse8170_sanitize_title_with_dashes', 10, 3 );
  7. function wpse8170_sanitize_title_with_dashes( $title, $raw_title = '', $context = 'display' ) {
  8.     $title = strip_tags($title);
  9.     // Preserve escaped octets.
  10.     $title = preg_replace('|%([a-fA-F0-9][a-fA-F0-9])|', '---$1---', $title);
  11.     // Remove percent signs that are not part of an octet.
  12.     $title = str_replace('%', '', $title);
  13.     // Restore octets.
  14.     $title = preg_replace('|---([a-fA-F0-9][a-fA-F0-9])---|', '%$1', $title);
  15.  
  16.     if (seems_utf8($title)) {
  17.         if (function_exists('mb_strtolower')) {
  18.             $title = mb_strtolower($title, 'UTF-8');
  19.         }
  20.         $title = utf8_uri_encode($title, 1000); // <--- here is the trick!
  21.     }
  22.  
  23.     $title = strtolower($title);
  24.     $title = preg_replace('/&.+?;/', '', $title); // kill entities
  25.     $title = str_replace('.', '-', $title);
  26.  
  27.     if ( 'save' == $context ) {
  28.         // Convert nbsp, ndash and mdash to hyphens
  29.         $title = str_replace( array( '%c2%a0', '%e2%80%93', '%e2%80%94' ), '-', $title );
  30.  
  31.             // Strip these characters entirely
  32.             $title = str_replace( array(
  33.             // iexcl and iquest
  34.             '%c2%a1', '%c2%bf',
  35.             // angle quotes
  36.             '%c2%ab', '%c2%bb', '%e2%80%b9', '%e2%80%ba',
  37.             // curly quotes
  38.             '%e2%80%98', '%e2%80%99', '%e2%80%9c', '%e2%80%9d',
  39.             '%e2%80%9a', '%e2%80%9b', '%e2%80%9e', '%e2%80%9f',
  40.             // copy, reg, deg, hellip and trade
  41.             '%c2%a9', '%c2%ae', '%c2%b0', '%e2%80%a6', '%e2%84%a2',
  42.             // grave accent, acute accent, macron, caron
  43.             '%cc%80', '%cc%81', '%cc%84', '%cc%8c',
  44.         ), '', $title );
  45.  
  46.         // Convert times to x
  47.         $title = str_replace( '%c3%97', 'x', $title );
  48.     }
  49.  
  50.     $title = preg_replace('/[^%a-z0-9 _-]/', '', $title);
  51.     $title = preg_replace('/\s+/', '-', $title);
  52.     $title = preg_replace('|-+|', '-', $title);
  53.     $title = trim($title, '-');
  54.  
  55.     return $title;
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement