Custom Post Type Permalinks - Version 0.7.6

Version Description

  • Add parent's slug to hierarchical post type.
Download this release

Release Info

Developer Toro_Unit
Plugin Icon 128x128 Custom Post Type Permalinks
Version 0.7.6
Comparing to
See all releases

Code changes from version 0.7.5.6 to 0.7.6

Files changed (2) hide show
  1. custom-post-type-permalinks.php +22 -8
  2. readme.txt +6 -1
custom-post-type-permalinks.php CHANGED
@@ -5,7 +5,7 @@ Plugin URI: http://www.torounit.com
5
  Description: Add post archives of custom post type and customizable permalinks.
6
  Author: Toro-Unit
7
  Author URI: http://www.torounit.com/plugins/custom-post-type-permalinks/
8
- Version: 0.7.5.6
9
  Text Domain: cptp
10
  Domain Path: /
11
  */
@@ -168,8 +168,21 @@ class Custom_Post_Type_Permalinks {
168
  $permalink = str_replace( '%'.$post_type.'_id%', $post->ID, $permalink );
169
  $permalink = str_replace( '%'.$post_type.'_page%', "", $permalink );
170
 
171
- if( !$leavename )
 
 
 
 
 
 
 
 
 
 
 
172
  $permalink = str_replace( '%'.$post_type.'%', $post->post_name, $permalink );
 
 
173
 
174
  $taxonomies = get_taxonomies( array('show_ui' => true),'objects' );
175
 
@@ -186,7 +199,9 @@ class Custom_Post_Type_Permalinks {
186
  $term = $this->get_taxonomy_parents( $parent,$taxonomy, false, '/', true ) . $term;
187
  }
188
 
189
- $permalink = str_replace( "%$taxonomy%", $term, $permalink );
 
 
190
  }
191
  }
192
 
@@ -203,10 +218,9 @@ class Custom_Post_Type_Permalinks {
203
 
204
  $permalink = str_replace('//', "/", $permalink );
205
 
206
-
207
- return $permalink = home_url( user_trailingslashit( $permalink ) );
208
- //$str = rtrim( preg_replace("/%[a-z,_]*%/","",get_option("permalink_structure")) ,'/');
209
- //$permalink = str_replace($str, "", $permalink );
210
 
211
  }
212
 
@@ -295,7 +309,7 @@ class Custom_Post_Type_Permalinks {
295
 
296
  //$termlink = str_replace( $term->slug.'/', $this->get_taxonomy_parents( $term->term_id,$taxonomy->name, false, '/', true ), $termlink );
297
  $termlink = str_replace( $wp_home, $wp_home.'/'.$slug, $termlink );
298
- $str = rtrim( preg_replace("/%[a-z]*%/","",get_option("permalink_structure")) ,'/');
299
  return str_replace($str, "", $termlink );
300
 
301
  }
5
  Description: Add post archives of custom post type and customizable permalinks.
6
  Author: Toro-Unit
7
  Author URI: http://www.torounit.com/plugins/custom-post-type-permalinks/
8
+ Version: 0.7.6
9
  Text Domain: cptp
10
  Domain Path: /
11
  */
168
  $permalink = str_replace( '%'.$post_type.'_id%', $post->ID, $permalink );
169
  $permalink = str_replace( '%'.$post_type.'_page%', "", $permalink );
170
 
171
+ $parentsDirs = "";
172
+ $postId = $post->ID;
173
+ while ($parent = get_post($postId)->post_parent) {
174
+ $parentsDirs = get_post($parent)->post_name."/".$parentsDirs;
175
+ $postId = $parent;
176
+ }
177
+
178
+ $permalink = str_replace( '%'.$post_type.'%', $parentsDirs.'%'.$post_type.'%', $permalink );
179
+
180
+
181
+ if( !$leavename ){
182
+
183
  $permalink = str_replace( '%'.$post_type.'%', $post->post_name, $permalink );
184
+ }
185
+
186
 
187
  $taxonomies = get_taxonomies( array('show_ui' => true),'objects' );
188
 
199
  $term = $this->get_taxonomy_parents( $parent,$taxonomy, false, '/', true ) . $term;
200
  }
201
 
202
+ if(isset($term)) {
203
+ $permalink = str_replace( "%$taxonomy%", $term, $permalink );
204
+ }
205
  }
206
  }
207
 
218
 
219
  $permalink = str_replace('//', "/", $permalink );
220
 
221
+ $permalink = home_url( user_trailingslashit( $permalink ) );
222
+ $str = rtrim( preg_replace("/%[a-z,_]*%/","",get_option("permalink_structure")) ,'/');
223
+ return $permalink = str_replace($str, "", $permalink );
 
224
 
225
  }
226
 
309
 
310
  //$termlink = str_replace( $term->slug.'/', $this->get_taxonomy_parents( $term->term_id,$taxonomy->name, false, '/', true ), $termlink );
311
  $termlink = str_replace( $wp_home, $wp_home.'/'.$slug, $termlink );
312
+ $str = rtrim( preg_replace("/%[a-z_]*%/","",get_option("permalink_structure")) ,'/');
313
  return str_replace($str, "", $termlink );
314
 
315
  }
readme.txt CHANGED
@@ -3,7 +3,7 @@ Contributors: Toro_Unit
3
  Tags: custom post type,permalink
4
  Requires at least: 3.2
5
  Tested up to: 3.3
6
- Stable tag: 0.7.5.6
7
 
8
  Lets you edit the permalink of custom post type.
9
 
@@ -32,6 +32,11 @@ That's it. You can access the permalinks setting by going to *Settings -> Permal
32
 
33
  == Changelog ==
34
 
 
 
 
 
 
35
  = 0.7.5 =
36
  * Add ability to disable to change custom taxonomy archive's permalink.
37
 
3
  Tags: custom post type,permalink
4
  Requires at least: 3.2
5
  Tested up to: 3.3
6
+ Stable tag: 0.7.7
7
 
8
  Lets you edit the permalink of custom post type.
9
 
32
 
33
  == Changelog ==
34
 
35
+
36
+ = 0.7.6 =
37
+ * Add parent's slug to hierarchical post type.
38
+
39
+
40
  = 0.7.5 =
41
  * Add ability to disable to change custom taxonomy archive's permalink.
42