Advertisement
retesere20

disable-georgian-russian-slugs

Feb 25th, 2020
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.16 KB | None | 0 0
  1.  
  2. //==================DISABLE GEORGIAN + Russian SLUGS for POSTS================
  3. public function disable_geo_rus_slugs()
  4. {
  5. add_action( 'wp_ajax_sample-permalink', function ($data) {
  6. // check that we're dealing with a product, and editing the slug
  7. $post_id = isset($_POST['post_id']) ? (int) ($_POST['post_id']) : 0;
  8. $new_title = isset($_POST['new_title'])? sanitize_text_field($_POST['new_title']) : null;
  9. $post_name = isset($_POST['new_slug'])? sanitize_text_field($_POST['new_slug']) : $new_title;
  10. //on first fire, there is not set the "new_slug"
  11. $_POST['new_slug'] = ISSET($_POST['new_slug']) ? sanitize_text_field($_POST['new_slug']) : $this->slug_modify($post_name);
  12. } ,1);
  13.  
  14. //disable slug beforehand Post Update action (also, in navigation menus and etc...)
  15. add_filter('name_save_pre', function ($post_name) {
  16. if (!empty($_POST['post_ID']) || !empty($_POST['post_name']) || !empty($_POST['post_title']) ){
  17. // check that we're dealing with a product, and editing the slug
  18. $post_id = !empty($_POST['post_ID']) ? (int) ($_POST['post_ID']) : 0;
  19. $new_slug = !empty($_POST['post_name']) ? sanitize_text_field($_POST['post_name']) : sanitize_text_field($_POST['post_title']);
  20. //if got from new post
  21. if ($post_id && !empty($_POST['_wp_http_referer']) ) { if (stripos($_POST['_wp_http_referer'],'wp-admin/post-new.php')!==false) { $post_name = $this->slug_modify($new_slug); $_POST['post_name']=$post_name;} }
  22. }
  23. return $post_name;
  24. });
  25.  
  26.  
  27. //disable slug on any update
  28. add_filter('wp_insert_post_data', function($dataaaaaa) {
  29. if (!empty($_POST['_wp_http_referer'])) {
  30. if (stripos($_POST['_wp_http_referer'],'wp-admin/post-new.php')!==false) {
  31. $dataaaaaa['post_name']=$this->slug_modify( (!empty($_POST['post_name']) ? sanitize_text_field($_POST['post_name']) : $dataaaaaa['post_title']) );
  32. }
  33. }
  34. return $dataaaaaa;
  35. }, 3);
  36. }
  37.  
  38. public function slug_modify($slg) {return $this->myUTF8truncate(sanitize_title($this->GEO_to_ENG__LowerCased($this->Rus_To_Eng__LowerCased(urldecode($slg)))), 5);}
  39. //=============================================================================
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement