Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //==================DISABLE GEORGIAN + Russian SLUGS for POSTS================
- public function disable_geo_rus_slugs()
- {
- add_action( 'wp_ajax_sample-permalink', function ($data) {
- // check that we're dealing with a product, and editing the slug
- $post_id = isset($_POST['post_id']) ? (int) ($_POST['post_id']) : 0;
- $new_title = isset($_POST['new_title'])? sanitize_text_field($_POST['new_title']) : null;
- $post_name = isset($_POST['new_slug'])? sanitize_text_field($_POST['new_slug']) : $new_title;
- //on first fire, there is not set the "new_slug"
- $_POST['new_slug'] = ISSET($_POST['new_slug']) ? sanitize_text_field($_POST['new_slug']) : $this->slug_modify($post_name);
- } ,1);
- //disable slug beforehand Post Update action (also, in navigation menus and etc...)
- add_filter('name_save_pre', function ($post_name) {
- if (!empty($_POST['post_ID']) || !empty($_POST['post_name']) || !empty($_POST['post_title']) ){
- // check that we're dealing with a product, and editing the slug
- $post_id = !empty($_POST['post_ID']) ? (int) ($_POST['post_ID']) : 0;
- $new_slug = !empty($_POST['post_name']) ? sanitize_text_field($_POST['post_name']) : sanitize_text_field($_POST['post_title']);
- //if got from new post
- 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;} }
- }
- return $post_name;
- });
- //disable slug on any update
- add_filter('wp_insert_post_data', function($dataaaaaa) {
- if (!empty($_POST['_wp_http_referer'])) {
- if (stripos($_POST['_wp_http_referer'],'wp-admin/post-new.php')!==false) {
- $dataaaaaa['post_name']=$this->slug_modify( (!empty($_POST['post_name']) ? sanitize_text_field($_POST['post_name']) : $dataaaaaa['post_title']) );
- }
- }
- return $dataaaaaa;
- }, 3);
- }
- public function slug_modify($slg) {return $this->myUTF8truncate(sanitize_title($this->GEO_to_ENG__LowerCased($this->Rus_To_Eng__LowerCased(urldecode($slg)))), 5);}
- //=============================================================================
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement