Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function pm_get_matching_group() {
- return '(?:4-4s|5-5s-se|5c|6-6s|6-plus-6s-plus|7-et-7-plus|7-7-plus|8-et-8-plus|8-8-plus|x-xs|xs-max|xr?)';
- }
- function pm_filter_product_permalinks($permalink, $slug, $post, $native_slug, $native) {
- if(!empty($post->post_type) && $post->post_type == 'product') {
- $matching_group = pm_get_matching_group();
- // $permalink = preg_replace("/([^\/]+)-coque-iphone-{$matching_group}(\/[^\/]+)$/", '$1$3', $permalink);
- // $permalink = preg_replace("/coque-iphone-{$matching_group}-([^\/]+)$/", '$2', $permalink);
- $permalink = preg_replace("/([^\/]+)?(coque-iphone-{$matching_group})([^\/]+)?(\/[^\/]+)$/", '$1$3$4', $permalink);
- $permalink = preg_replace('/([-]+)/', '-', $permalink);
- $permalink = preg_replace('/(\/([-]+)|([-]+)\/)/', '/', $permalink);
- }
- return $permalink;
- }
- add_filter('permalink_manager_filter_default_post_uri', 'pm_filter_product_permalinks', 9, 5);
- function pm_filter_product_slugs($slug, $post) {
- if(!empty($post->post_type) && $post->post_type == 'product') {
- $matching_group = pm_get_matching_group();
- $slug = preg_replace("/(coque-iphone-{$matching_group})/", '', $slug);
- }
- return $slug;
- }
- add_filter('permalink_manager_filter_default_post_slug', 'pm_filter_product_slugs', 9, 2);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement