Custom Post Type Permalinks - Version 0.7.4

Version Description

Download this release

Release Info

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

Code changes from version 0.7.3.1 to 0.7.4

Files changed (2) hide show
  1. custom-post-type-permalinks.php +40 -35
  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.3.1
9
  Text Domain: cptp
10
  Domain Path: /
11
  */
@@ -44,7 +44,7 @@ class Custom_Post_Type_Permalinks {
44
  add_filter('post_type_link', array(&$this,'set_permalink'),10,3);
45
  add_filter('getarchives_where', array(&$this,'get_archives_where'), 10, 2);
46
  add_filter('get_archives_link', array(&$this,'get_archives_link'));
47
- add_action('generate_rewrite_rules', array(&$this,'add_tax_rewrite'));
48
  add_filter('term_link', array(&$this,'set_term_link'),10,3);
49
  }
50
 
@@ -88,36 +88,36 @@ class Custom_Post_Type_Permalinks {
88
  $slug = get_post_type_object($post_type)->rewrite['slug'];
89
 
90
  if( $slug ){
91
- add_rewrite_rule($slug.'/date/([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/feed/(feed|rdf|rss|rss2|atom)/?$','index.php?year=$matches[1]&monthnum=$matches[2]&day=$matches[3]&feed=$matches[4]&post_type='.$post_type,'bottom');
92
- add_rewrite_rule($slug.'/date/([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/(feed|rdf|rss|rss2|atom)/?$','index.php?year=$matches[1]&monthnum=$matches[2]&day=$matches[3]&feed=$matches[4]&post_type='.$post_type,'bottom');
93
- add_rewrite_rule($slug.'/date/([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/page/?([0-9]{1,})/?$','index.php?year=$matches[1]&monthnum=$matches[2]&day=$matches[3]&paged=$matches[4]&post_type='.$post_type,'bottom');
94
- add_rewrite_rule($slug.'/date/([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/?$','index.php?year=$matches[1]&monthnum=$matches[2]&day=$matches[3]&post_type='.$post_type,'bottom');
95
- add_rewrite_rule($slug.'/date/([0-9]{4})/([0-9]{1,2})/feed/(feed|rdf|rss|rss2|atom)/?$','index.php?year=$matches[1]&monthnum=$matches[2]&feed=$matches[3]&post_type='.$post_type,'bottom');
96
- add_rewrite_rule($slug.'/date/([0-9]{4})/([0-9]{1,2})/(feed|rdf|rss|rss2|atom)/?$','index.php?year=$matches[1]&monthnum=$matches[2]&feed=$matches[3]&post_type='.$post_type,'bottom');
97
- add_rewrite_rule($slug.'/date/([0-9]{4})/([0-9]{1,2})/page/?([0-9]{1,})/?$','index.php?year=$matches[1]&monthnum=$matches[2]&paged=$matches[3]&post_type='.$post_type,'bottom');
98
- add_rewrite_rule($slug.'/date/([0-9]{4})/([0-9]{1,2})/?$','index.php?year=$matches[1]&monthnum=$matches[2]&post_type='.$post_type,'bottom');
99
- add_rewrite_rule($slug.'/date/([0-9]{4})/feed/(feed|rdf|rss|rss2|atom)/?$','index.php?year=$matches[1]&feed=$matches[2]&post_type='.$post_type,'bottom');
100
- add_rewrite_rule($slug.'/date/([0-9]{4})/(feed|rdf|rss|rss2|atom)/?$','index.php?year=$matches[1]&feed=$matches[2]&post_type='.$post_type,'bottom');
101
- add_rewrite_rule($slug.'/date/([0-9]{4})/page/?([0-9]{1,})/?$','index.php?year=$matches[1]&paged=$matches[2]&post_type='.$post_type,'bottom');
102
- add_rewrite_rule($slug.'/date/([0-9]{4})/?$','index.php?year=$matches[1]&post_type='.$post_type,'bottom');
103
- add_rewrite_rule($slug.'/author/([^/]+)/?$','index.php?author=$matches[1]&post_type='.$post_type,'bottom');
104
- add_rewrite_rule($slug.'/?$','index.php?post_type='.$post_type,'bottom');
105
  }
106
 
107
- add_rewrite_rule($post_type.'/date/([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/feed/(feed|rdf|rss|rss2|atom)/?$','index.php?year=$matches[1]&monthnum=$matches[2]&day=$matches[3]&feed=$matches[4]&post_type='.$post_type,'bottom');
108
- add_rewrite_rule($post_type.'/date/([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/(feed|rdf|rss|rss2|atom)/?$','index.php?year=$matches[1]&monthnum=$matches[2]&day=$matches[3]&feed=$matches[4]&post_type='.$post_type,'bottom');
109
- add_rewrite_rule($post_type.'/date/([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/page/?([0-9]{1,})/?$','index.php?year=$matches[1]&monthnum=$matches[2]&day=$matches[3]&paged=$matches[4]&post_type='.$post_type,'bottom');
110
- add_rewrite_rule($post_type.'/date/([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/?$','index.php?year=$matches[1]&monthnum=$matches[2]&day=$matches[3]&post_type='.$post_type,'bottom');
111
- add_rewrite_rule($post_type.'/date/([0-9]{4})/([0-9]{1,2})/feed/(feed|rdf|rss|rss2|atom)/?$','index.php?year=$matches[1]&monthnum=$matches[2]&feed=$matches[3]&post_type='.$post_type,'bottom');
112
- add_rewrite_rule($post_type.'/date/([0-9]{4})/([0-9]{1,2})/(feed|rdf|rss|rss2|atom)/?$','index.php?year=$matches[1]&monthnum=$matches[2]&feed=$matches[3]&post_type='.$post_type,'bottom');
113
- add_rewrite_rule($post_type.'/date/([0-9]{4})/([0-9]{1,2})/page/?([0-9]{1,})/?$','index.php?year=$matches[1]&monthnum=$matches[2]&paged=$matches[3]&post_type='.$post_type,'bottom');
114
- add_rewrite_rule($post_type.'/date/([0-9]{4})/([0-9]{1,2})/?$','index.php?year=$matches[1]&monthnum=$matches[2]&post_type='.$post_type,'bottom');
115
- add_rewrite_rule($post_type.'/date/([0-9]{4})/feed/(feed|rdf|rss|rss2|atom)/?$','index.php?year=$matches[1]&feed=$matches[2]&post_type='.$post_type,'bottom');
116
- add_rewrite_rule($post_type.'/date/([0-9]{4})/(feed|rdf|rss|rss2|atom)/?$','index.php?year=$matches[1]&feed=$matches[2]&post_type='.$post_type,'bottom');
117
- add_rewrite_rule($post_type.'/date/([0-9]{4})/page/?([0-9]{1,})/?$','index.php?year=$matches[1]&paged=$matches[2]&post_type='.$post_type,'bottom');
118
- add_rewrite_rule($post_type.'/date/([0-9]{4})/?$','index.php?year=$matches[1]&post_type='.$post_type,'bottom');
119
- add_rewrite_rule($post_type.'/date/([0-9]{4})/?$','index.php?author=$matches[1]&post_type='.$post_type,'bottom');
120
- add_rewrite_rule($post_type.'/?$','index.php?post_type='.$post_type,'bottom');
121
  endforeach;
122
  }
123
  //rewrite_tagの追加
@@ -232,6 +232,7 @@ class Custom_Post_Type_Permalinks {
232
  function get_archives_where( $where, $r ) {
233
  if ( isset($r['post_type']) ) {
234
  $this->post_type_archives = $r['post_type'];
 
235
  $where = str_replace( '\'post\'', '\'' . $r['post_type'] . '\'', $where );
236
  }else {
237
  $this->post_type_archives = '';
@@ -240,9 +241,12 @@ class Custom_Post_Type_Permalinks {
240
  }
241
 
242
  function get_archives_link( $link_html ) {
243
- if ( '' != $this->post_type_archives )
244
  $blog_url = get_bloginfo("url");
245
- $link_html = str_replace($blog_url,$blog_url.$this->post_type_archives,$link_html);
 
 
 
246
  return $link_html;
247
  }
248
 
@@ -267,8 +271,8 @@ class Custom_Post_Type_Permalinks {
267
  foreach ($post_types as $post_type){
268
  $slug = get_post_type_object($post_type)->rewrite["slug"];
269
  //add taxonomy slug
270
- add_rewrite_rule($slug.'/'.$taxonomy.'/(.+?)/?$','index.php?taxonomy='.$taxonomy.'&term=$matches[1]','bottom');
271
- add_rewrite_rule($post_type.'/'.$taxonomy.'/(.+?)/?$','index.php?taxonomy='.$taxonomy.'&term=$matches[1]','bottom');
272
  }
273
  endforeach;
274
  }
@@ -285,9 +289,10 @@ class Custom_Post_Type_Permalinks {
285
  $wp_home = get_option('home');
286
  $wp_home = $wp_home.'/';
287
  $wp_home = str_replace('//','/',$wp_home);
 
288
  $post_type = $taxonomy->object_type[0];
289
  $slug = get_post_type_object($post_type)->rewrite['slug'];
290
- return str_replace($wp_home,$wp_home.$slug,$termlink);
291
  }
292
 
293
  static function uninstall_hook_custom_permalink () {
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.4
9
  Text Domain: cptp
10
  Domain Path: /
11
  */
44
  add_filter('post_type_link', array(&$this,'set_permalink'),10,3);
45
  add_filter('getarchives_where', array(&$this,'get_archives_where'), 10, 2);
46
  add_filter('get_archives_link', array(&$this,'get_archives_link'));
47
+ add_action('wp_loaded', array(&$this,'add_tax_rewrite'));
48
  add_filter('term_link', array(&$this,'set_term_link'),10,3);
49
  }
50
 
88
  $slug = get_post_type_object($post_type)->rewrite['slug'];
89
 
90
  if( $slug ){
91
+ add_rewrite_rule($slug.'/date/([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/feed/(feed|rdf|rss|rss2|atom)/?$','index.php?year=$matches[1]&monthnum=$matches[2]&day=$matches[3]&feed=$matches[4]&post_type='.$post_type,'top');
92
+ add_rewrite_rule($slug.'/date/([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/(feed|rdf|rss|rss2|atom)/?$','index.php?year=$matches[1]&monthnum=$matches[2]&day=$matches[3]&feed=$matches[4]&post_type='.$post_type,'top');
93
+ add_rewrite_rule($slug.'/date/([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/page/?([0-9]{1,})/?$','index.php?year=$matches[1]&monthnum=$matches[2]&day=$matches[3]&paged=$matches[4]&post_type='.$post_type,'top');
94
+ add_rewrite_rule($slug.'/date/([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/?$','index.php?year=$matches[1]&monthnum=$matches[2]&day=$matches[3]&post_type='.$post_type,'top');
95
+ add_rewrite_rule($slug.'/date/([0-9]{4})/([0-9]{1,2})/feed/(feed|rdf|rss|rss2|atom)/?$','index.php?year=$matches[1]&monthnum=$matches[2]&feed=$matches[3]&post_type='.$post_type,'top');
96
+ add_rewrite_rule($slug.'/date/([0-9]{4})/([0-9]{1,2})/(feed|rdf|rss|rss2|atom)/?$','index.php?year=$matches[1]&monthnum=$matches[2]&feed=$matches[3]&post_type='.$post_type,'top');
97
+ add_rewrite_rule($slug.'/date/([0-9]{4})/([0-9]{1,2})/page/?([0-9]{1,})/?$','index.php?year=$matches[1]&monthnum=$matches[2]&paged=$matches[3]&post_type='.$post_type,'top');
98
+ add_rewrite_rule($slug.'/date/([0-9]{4})/([0-9]{1,2})/?$','index.php?year=$matches[1]&monthnum=$matches[2]&post_type='.$post_type,'top');
99
+ add_rewrite_rule($slug.'/date/([0-9]{4})/feed/(feed|rdf|rss|rss2|atom)/?$','index.php?year=$matches[1]&feed=$matches[2]&post_type='.$post_type,'top');
100
+ add_rewrite_rule($slug.'/date/([0-9]{4})/(feed|rdf|rss|rss2|atom)/?$','index.php?year=$matches[1]&feed=$matches[2]&post_type='.$post_type,'top');
101
+ add_rewrite_rule($slug.'/date/([0-9]{4})/page/?([0-9]{1,})/?$','index.php?year=$matches[1]&paged=$matches[2]&post_type='.$post_type,'top');
102
+ add_rewrite_rule($slug.'/date/([0-9]{4})/?$','index.php?year=$matches[1]&post_type='.$post_type,'top');
103
+ add_rewrite_rule($slug.'/author/([^/]+)/?$','index.php?author=$matches[1]&post_type='.$post_type,'top');
104
+ add_rewrite_rule($slug.'/?$','index.php?post_type='.$post_type,'top');
105
  }
106
 
107
+ add_rewrite_rule($post_type.'/date/([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/feed/(feed|rdf|rss|rss2|atom)/?$','index.php?year=$matches[1]&monthnum=$matches[2]&day=$matches[3]&feed=$matches[4]&post_type='.$post_type,'top');
108
+ add_rewrite_rule($post_type.'/date/([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/(feed|rdf|rss|rss2|atom)/?$','index.php?year=$matches[1]&monthnum=$matches[2]&day=$matches[3]&feed=$matches[4]&post_type='.$post_type,'top');
109
+ add_rewrite_rule($post_type.'/date/([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/page/?([0-9]{1,})/?$','index.php?year=$matches[1]&monthnum=$matches[2]&day=$matches[3]&paged=$matches[4]&post_type='.$post_type,'top');
110
+ add_rewrite_rule($post_type.'/date/([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/?$','index.php?year=$matches[1]&monthnum=$matches[2]&day=$matches[3]&post_type='.$post_type,'top');
111
+ add_rewrite_rule($post_type.'/date/([0-9]{4})/([0-9]{1,2})/feed/(feed|rdf|rss|rss2|atom)/?$','index.php?year=$matches[1]&monthnum=$matches[2]&feed=$matches[3]&post_type='.$post_type,'top');
112
+ add_rewrite_rule($post_type.'/date/([0-9]{4})/([0-9]{1,2})/(feed|rdf|rss|rss2|atom)/?$','index.php?year=$matches[1]&monthnum=$matches[2]&feed=$matches[3]&post_type='.$post_type,'top');
113
+ add_rewrite_rule($post_type.'/date/([0-9]{4})/([0-9]{1,2})/page/?([0-9]{1,})/?$','index.php?year=$matches[1]&monthnum=$matches[2]&paged=$matches[3]&post_type='.$post_type,'top');
114
+ add_rewrite_rule($post_type.'/date/([0-9]{4})/([0-9]{1,2})/?$','index.php?year=$matches[1]&monthnum=$matches[2]&post_type='.$post_type,'top');
115
+ add_rewrite_rule($post_type.'/date/([0-9]{4})/feed/(feed|rdf|rss|rss2|atom)/?$','index.php?year=$matches[1]&feed=$matches[2]&post_type='.$post_type,'top');
116
+ add_rewrite_rule($post_type.'/date/([0-9]{4})/(feed|rdf|rss|rss2|atom)/?$','index.php?year=$matches[1]&feed=$matches[2]&post_type='.$post_type,'top');
117
+ add_rewrite_rule($post_type.'/date/([0-9]{4})/page/?([0-9]{1,})/?$','index.php?year=$matches[1]&paged=$matches[2]&post_type='.$post_type,'top');
118
+ add_rewrite_rule($post_type.'/date/([0-9]{4})/?$','index.php?year=$matches[1]&post_type='.$post_type,'top');
119
+ add_rewrite_rule($post_type.'/date/([0-9]{4})/?$','index.php?author=$matches[1]&post_type='.$post_type,'top');
120
+ add_rewrite_rule($post_type.'/?$','index.php?post_type='.$post_type,'top');
121
  endforeach;
122
  }
123
  //rewrite_tagの追加
232
  function get_archives_where( $where, $r ) {
233
  if ( isset($r['post_type']) ) {
234
  $this->post_type_archives = $r['post_type'];
235
+
236
  $where = str_replace( '\'post\'', '\'' . $r['post_type'] . '\'', $where );
237
  }else {
238
  $this->post_type_archives = '';
241
  }
242
 
243
  function get_archives_link( $link_html ) {
244
+ if ( '' != $this->post_type_archives ){
245
  $blog_url = get_bloginfo("url");
246
+ $blog_url = rtrim($blog_url,"/");
247
+ $link_html = str_replace($blog_url,$blog_url.'/'.$this->post_type_archives.'/date',$link_html);
248
+ }
249
+
250
  return $link_html;
251
  }
252
 
271
  foreach ($post_types as $post_type){
272
  $slug = get_post_type_object($post_type)->rewrite["slug"];
273
  //add taxonomy slug
274
+ add_rewrite_rule($slug.'/'.$taxonomy.'/(.+?)/?$','index.php?taxonomy='.$taxonomy.'&term=$matches[1]','top');
275
+ add_rewrite_rule($post_type.'/'.$taxonomy.'/(.+?)/?$','index.php?taxonomy='.$taxonomy.'&term=$matches[1]','top');
276
  }
277
  endforeach;
278
  }
289
  $wp_home = get_option('home');
290
  $wp_home = $wp_home.'/';
291
  $wp_home = str_replace('//','/',$wp_home);
292
+ $wp_home = str_replace(':/', '://', $wp_home);
293
  $post_type = $taxonomy->object_type[0];
294
  $slug = get_post_type_object($post_type)->rewrite['slug'];
295
+ return str_replace($wp_home,$wp_home.$slug.'/',$termlink);
296
  }
297
 
298
  static function uninstall_hook_custom_permalink () {
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.3.1
7
 
8
  Lets you edit the permalink of custom post type.
9
 
@@ -30,6 +30,11 @@ That's it. You can access the permalinks setting by going to *Settings -> Permal
30
 
31
  == Changelog ==
32
 
 
 
 
 
 
33
  =0.7.3=
34
  * Changed part for saving the data.
35
 
3
  Tags: custom post type,permalink
4
  Requires at least: 3.2
5
  Tested up to: 3.3
6
+ Stable tag: 0.7.4
7
 
8
  Lets you edit the permalink of custom post type.
9
 
30
 
31
  == Changelog ==
32
 
33
+
34
+ =0.7.4=
35
+ * Bug fix taxonomy rewrite.
36
+
37
+
38
  =0.7.3=
39
  * Changed part for saving the data.
40