Custom Post Type Permalinks - Version 0.7.10

Version Description

  • Bug Fix.
Download this release

Release Info

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

Code changes from version 0.7.9.2 to 0.7.10

Files changed (2) hide show
  1. custom-post-type-permalinks.php +99 -12
  2. readme.txt +4 -1
custom-post-type-permalinks.php CHANGED
@@ -5,13 +5,13 @@ 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.9.2
9
  Text Domain: cptp
10
  Domain Path: /
11
  */
12
 
13
 
14
- /* Copyright 2011 Toro_Unit (email : mail@torounit.com)
15
 
16
  This program is free software; you can redistribute it and/or modify
17
  it under the terms of the GNU General Public License as published by
@@ -30,11 +30,23 @@ Domain Path: /
30
 
31
  /* This plugin don't support Multisite yet.*/
32
 
33
-
 
 
 
 
 
34
  class Custom_Post_Type_Permalinks {
35
 
36
  static public $default_structure = '/%postname%/';
37
 
 
 
 
 
 
 
 
38
  public function __construct () {
39
  add_action('wp_loaded',array(&$this,'set_archive_rewrite'),99);
40
  add_action('wp_loaded', array(&$this,'set_rewrite'),100);
@@ -42,6 +54,7 @@ class Custom_Post_Type_Permalinks {
42
 
43
  if(get_option("permalink_structure") != "") {
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'),20,1);
47
  add_filter('term_link', array(&$this,'set_term_link'),10,3);
@@ -51,6 +64,7 @@ class Custom_Post_Type_Permalinks {
51
  /**
52
  *
53
  * Get Custom Taxonomies parents.
 
54
  *
55
  */
56
  private function get_taxonomy_parents( $id, $taxonomy = 'category', $link = false, $separator = '/', $nicename = false, $visited = array() ) {
@@ -82,6 +96,7 @@ class Custom_Post_Type_Permalinks {
82
  /**
83
  *
84
  * Add rewrite rules for archives.
 
85
  *
86
  */
87
  public function set_archive_rewrite() {
@@ -124,6 +139,7 @@ class Custom_Post_Type_Permalinks {
124
  /**
125
  *
126
  * Add Rewrite rule for single posts.
 
127
  *
128
  */
129
  public function set_rewrite() {
@@ -167,6 +183,7 @@ class Custom_Post_Type_Permalinks {
167
  /**
168
  *
169
  * Fix permalinks output.
 
170
  *
171
  */
172
  public function set_permalink( $post_link, $post,$leavename ) {
@@ -239,40 +256,86 @@ class Custom_Post_Type_Permalinks {
239
  *
240
  * wp_get_archives fix for custom post
241
  * Ex:wp_get_archives('&post_type='.get_query_var( 'post_type' ));
 
242
  *
243
  */
244
 
245
  public $get_archives_where_r;
246
 
 
247
  public function get_archives_where( $where, $r ) {
248
  $this->get_archives_where_r = $r;
249
  if ( isset($r['post_type']) )
250
  $where = str_replace( '\'post\'', '\'' . $r['post_type'] . '\'', $where );
251
 
 
 
 
 
 
252
  return $where;
253
  }
254
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
255
  public function get_archives_link( $link ) {
 
 
 
 
256
  if (isset($this->get_archives_where_r['post_type']) and $this->get_archives_where_r['type'] != 'postbypost'){
257
  $blog_url = get_bloginfo("url");
258
 
259
  // /archive/%post_id%
260
- if($str = rtrim( preg_replace("/%[a-z,_]*%/","",get_option("permalink_structure")) ,'/')) {
 
261
  $ret_link = str_replace($str, '/'.'%link_dir%', $link);
262
  }else{
263
  $blog_url = rtrim($blog_url,"/");
264
  $ret_link = str_replace($blog_url,$blog_url.'/'.'%link_dir%',$link);
265
  }
266
- $link_dir = $this->get_archives_where_r['post_type'];
 
 
 
 
 
 
 
267
 
268
  if(!strstr($link,'/date/')){
269
  $link_dir = $link_dir .'/date';
270
  }
271
 
272
  $ret_link = str_replace('%link_dir%',$link_dir,$ret_link);
273
-
274
  return $ret_link;
275
  }
 
 
276
  return $link;
277
  }
278
 
@@ -280,6 +343,7 @@ class Custom_Post_Type_Permalinks {
280
  *
281
  * Add rewrite rules for custom taxonomies.
282
  * @since 0.6
 
283
  *
284
  */
285
  public function add_tax_rewrite() {
@@ -288,6 +352,7 @@ class Custom_Post_Type_Permalinks {
288
 
289
  global $wp_rewrite;
290
  $taxonomies = get_taxonomies(array( '_builtin' => false));
 
291
  if(empty($taxonomies))
292
  return false;
293
 
@@ -305,11 +370,26 @@ class Custom_Post_Type_Permalinks {
305
  $slug = $post_type_obj->has_archive;
306
  };
307
 
 
 
 
 
 
 
 
 
 
308
  //add taxonomy slug
309
- add_rewrite_rule( $slug.'/'.$taxonomy.'/(.+?)/page/?([0-9]{1,})/?$', 'index.php?'.$taxonomy.'=$matches[1]&paged=$matches[2]', 'top' );
310
- add_rewrite_rule( $slug.'/'.$taxonomy.'/(.+?)/feed/(feed|rdf|rss|rss2|atom)/?$', 'index.php?'.$taxonomy.'=$matches[1]&feed=$matches[2]', 'top' );
311
- add_rewrite_rule( $slug.'/'.$taxonomy.'/(.+?)/(feed|rdf|rss|rss2|atom)/?$', 'index.php?'.$taxonomy.'=$matches[1]&feed=$matches[2]', 'top' );
312
- add_rewrite_rule( $slug.'/'.$taxonomy.'/(.+?)/?$', 'index.php?'.$taxonomy.'=$matches[1]', 'top' );
 
 
 
 
 
 
313
 
314
  endforeach;
315
  endforeach;
@@ -320,6 +400,7 @@ class Custom_Post_Type_Permalinks {
320
  *
321
  * Fix taxonomy link outputs.
322
  * @since 0.6
 
323
  *
324
  */
325
  public function set_term_link( $termlink, $term, $taxonomy ) {
@@ -347,6 +428,12 @@ class Custom_Post_Type_Permalinks {
347
  }
348
  }
349
 
 
 
 
 
 
 
350
  class Custom_Post_Type_Permalinks_Admin {
351
 
352
  public function __construct () {
@@ -484,5 +571,5 @@ class Custom_Post_Type_Permalinks_Admin {
484
  }
485
  }
486
 
487
- new Custom_Post_Type_Permalinks;
488
- new Custom_Post_Type_Permalinks_Admin;
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.10
9
  Text Domain: cptp
10
  Domain Path: /
11
  */
12
 
13
 
14
+ /* Copyright 2012 Toro_Unit (email : mail@torounit.com)
15
 
16
  This program is free software; you can redistribute it and/or modify
17
  it under the terms of the GNU General Public License as published by
30
 
31
  /* This plugin don't support Multisite yet.*/
32
 
33
+ /**
34
+ *
35
+ * Custom Permalink Class
36
+ *
37
+ *
38
+ */
39
  class Custom_Post_Type_Permalinks {
40
 
41
  static public $default_structure = '/%postname%/';
42
 
43
+ /**
44
+ *
45
+ * Constructor
46
+ * Add Action & filter hooks.
47
+ * @version 2.0
48
+ */
49
+
50
  public function __construct () {
51
  add_action('wp_loaded',array(&$this,'set_archive_rewrite'),99);
52
  add_action('wp_loaded', array(&$this,'set_rewrite'),100);
54
 
55
  if(get_option("permalink_structure") != "") {
56
  add_filter('post_type_link', array(&$this,'set_permalink'),10,3);
57
+ add_filter('getarchives_join', array(&$this,'get_archives_join'),10,2); // [steve]
58
  add_filter('getarchives_where', array(&$this,'get_archives_where'), 10, 2);
59
  add_filter('get_archives_link', array(&$this,'get_archives_link'),20,1);
60
  add_filter('term_link', array(&$this,'set_term_link'),10,3);
64
  /**
65
  *
66
  * Get Custom Taxonomies parents.
67
+ * @version 1.0
68
  *
69
  */
70
  private function get_taxonomy_parents( $id, $taxonomy = 'category', $link = false, $separator = '/', $nicename = false, $visited = array() ) {
96
  /**
97
  *
98
  * Add rewrite rules for archives.
99
+ * @version 1.0
100
  *
101
  */
102
  public function set_archive_rewrite() {
139
  /**
140
  *
141
  * Add Rewrite rule for single posts.
142
+ * @version 1.5
143
  *
144
  */
145
  public function set_rewrite() {
183
  /**
184
  *
185
  * Fix permalinks output.
186
+ * @version 1.0
187
  *
188
  */
189
  public function set_permalink( $post_link, $post,$leavename ) {
256
  *
257
  * wp_get_archives fix for custom post
258
  * Ex:wp_get_archives('&post_type='.get_query_var( 'post_type' ));
259
+ * @version 2.0
260
  *
261
  */
262
 
263
  public $get_archives_where_r;
264
 
265
+ // function modified by [steve]
266
  public function get_archives_where( $where, $r ) {
267
  $this->get_archives_where_r = $r;
268
  if ( isset($r['post_type']) )
269
  $where = str_replace( '\'post\'', '\'' . $r['post_type'] . '\'', $where );
270
 
271
+ if(isset($r['taxonomy']) && is_array($r['taxonomy']) ){
272
+ global $wpdb;
273
+ $where = $where . " AND $wpdb->term_taxonomy.taxonomy = '".$r['taxonomy']['name']."' AND $wpdb->term_taxonomy.term_id = '".$r['taxonomy']['termid']."'";
274
+ }
275
+
276
  return $where;
277
  }
278
 
279
+ //function added by [steve]
280
+ /**
281
+ *
282
+ * get_archive_join
283
+ * @author Steve
284
+ * @since 0.7.10
285
+ * @version 1.0
286
+ *
287
+ *
288
+ */
289
+ public function get_archives_join( $join, $r ) {
290
+ global $wpdb;
291
+ $this->get_archives_where_r = $r;
292
+ if(isset($r['taxonomy']) && is_array($r['taxonomy']) )
293
+ $join = $join . " INNER JOIN $wpdb->term_relationships ON ($wpdb->posts.ID = $wpdb->term_relationships.object_id) INNER JOIN $wpdb->term_taxonomy ON ($wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id)";
294
+
295
+ return $join;
296
+ }
297
+
298
+ /**
299
+ *
300
+ * get_arcihves_link
301
+ * @version 2.0
302
+ *
303
+ */
304
  public function get_archives_link( $link ) {
305
+ $c = isset($this->get_archives_where_r['taxonomy']) && is_array($this->get_archives_where_r['taxonomy']) ? $this->get_archives_where_r['taxonomy'] : ""; //[steve]
306
+ $t = $this->get_archives_where_r['post_type']; // [steve] [*** bug fixing]
307
+ $this->get_archives_where_r['post_type'] = isset($this->get_archives_where_r['post_type_slug']) ? $this->get_archives_where_r['post_type_slug'] : $t; // [steve] [*** bug fixing]
308
+
309
  if (isset($this->get_archives_where_r['post_type']) and $this->get_archives_where_r['type'] != 'postbypost'){
310
  $blog_url = get_bloginfo("url");
311
 
312
  // /archive/%post_id%
313
+ $str = rtrim( preg_replace("/\.[a-z,_]*/","",get_option("permalink_structure")) ,'');
314
+ if($str = rtrim( preg_replace("/%[a-z,_]*%/","",$str) ,'/')) {
315
  $ret_link = str_replace($str, '/'.'%link_dir%', $link);
316
  }else{
317
  $blog_url = rtrim($blog_url,"/");
318
  $ret_link = str_replace($blog_url,$blog_url.'/'.'%link_dir%',$link);
319
  }
320
+
321
+ if(empty($c) ){ // [steve]
322
+ $link_dir = $this->get_archives_where_r['post_type'];
323
+ }
324
+ else{ // [steve]
325
+ $c['name'] = ($c['name'] == 'category' && get_option('category_base')) ? get_option('category_base') : $c['name'];
326
+ $link_dir = $this->get_archives_where_r['post_type']."/".$c['name']."/".$c['termslug'];
327
+ }
328
 
329
  if(!strstr($link,'/date/')){
330
  $link_dir = $link_dir .'/date';
331
  }
332
 
333
  $ret_link = str_replace('%link_dir%',$link_dir,$ret_link);
334
+ $this->get_archives_where_r['post_type'] = $t; // [steve] reverting post_type to previous value
335
  return $ret_link;
336
  }
337
+ $this->get_archives_where_r['post_type'] = $t; // [steve] reverting post_type to previous value
338
+
339
  return $link;
340
  }
341
 
343
  *
344
  * Add rewrite rules for custom taxonomies.
345
  * @since 0.6
346
+ * @version 2.0
347
  *
348
  */
349
  public function add_tax_rewrite() {
352
 
353
  global $wp_rewrite;
354
  $taxonomies = get_taxonomies(array( '_builtin' => false));
355
+ $taxonomies['category'] = 'category';
356
  if(empty($taxonomies))
357
  return false;
358
 
370
  $slug = $post_type_obj->has_archive;
371
  };
372
 
373
+ if($taxonomy == 'category'){
374
+ $taxonomypat = ($cb = get_option('category_base')) ? $cb : $taxonomy;
375
+ $tax = 'category_name';
376
+ }else{
377
+ $taxonomypat = $taxonomy;
378
+ $tax = $taxonomy;
379
+ }
380
+
381
+
382
  //add taxonomy slug
383
+ add_rewrite_rule( $slug.'/'.$taxonomypat.'/(.+?)/page/?([0-9]{1,})/?$', 'index.php?'.$tax.'=$matches[1]&paged=$matches[2]', 'top' );
384
+ add_rewrite_rule( $slug.'/'.$taxonomypat.'/(.+?)/feed/(feed|rdf|rss|rss2|atom)/?$', 'index.php?'.$tax.'=$matches[1]&feed=$matches[2]', 'top' );
385
+ add_rewrite_rule( $slug.'/'.$taxonomypat.'/(.+?)/(feed|rdf|rss|rss2|atom)/?$', 'index.php?'.$tax.'=$matches[1]&feed=$matches[2]', 'top' );
386
+ add_rewrite_rule( $slug.'/'.$taxonomypat.'/([^/]+)/?$', 'index.php?'.$tax.'=$matches[1]', 'top' ); // modified by [steve] [*** bug fixing]
387
+
388
+ // below rules were added by [steve]
389
+ add_rewrite_rule( $taxonomypat.'/([^/]+)/date/([0-9]{4})/([0-9]{1,2})/?$', 'index.php?'.$tax.'=$matches[1]&year=$matches[2]&monthnum=$matches[3]&post_type='.$post_type, 'top' );
390
+ add_rewrite_rule( $taxonomypat.'/([^/]+)/date/([0-9]{4})/([0-9]{1,2})/page/?([0-9]{1,})/?$', 'index.php?'.$tax.'=$matches[1]&year=$matches[2]&monthnum=$matches[3]&paged=$matches[4]&post_type='.$post_type, 'top' );
391
+ add_rewrite_rule( $slug.'/'.$taxonomypat.'/([^/]+)/date/([0-9]{4})/([0-9]{1,2})/?$', 'index.php?'.$tax.'=$matches[1]&year=$matches[2]&monthnum=$matches[3]&post_type='.$post_type, 'top' );
392
+ add_rewrite_rule( $slug.'/'.$taxonomypat.'/([^/]+)/date/([0-9]{4})/([0-9]{1,2})/page/?([0-9]{1,})/?$', 'index.php?'.$tax.'=$matches[1]&year=$matches[2]&monthnum=$matches[3]&paged=$matches[4]&post_type='.$post_type, 'top' );
393
 
394
  endforeach;
395
  endforeach;
400
  *
401
  * Fix taxonomy link outputs.
402
  * @since 0.6
403
+ * @version 1.0
404
  *
405
  */
406
  public function set_term_link( $termlink, $term, $taxonomy ) {
428
  }
429
  }
430
 
431
+ /**
432
+ *
433
+ * Admin Page Class
434
+ *
435
+ */
436
+
437
  class Custom_Post_Type_Permalinks_Admin {
438
 
439
  public function __construct () {
571
  }
572
  }
573
 
574
+ $custom_post_type_permalinks = new Custom_Post_Type_Permalinks;
575
+ $custom_post_type_permalinks_admin = new Custom_Post_Type_Permalinks_Admin;
readme.txt CHANGED
@@ -3,7 +3,7 @@ Contributors: Toro_Unit
3
  Tags: custom post type,permalink
4
  Requires at least: 3.4
5
  Tested up to: 3.4
6
- Stable tag: 0.7.9.2
7
 
8
  Lets you edit the permalink of custom post type.
9
 
@@ -32,6 +32,9 @@ That's it. You can access the permalinks setting by going to *Settings -> Permal
32
 
33
  == Changelog ==
34
 
 
 
 
35
  = 0.7.9.1 =
36
  * Support Comment permalink.
37
  * Small change in setting page.
3
  Tags: custom post type,permalink
4
  Requires at least: 3.4
5
  Tested up to: 3.4
6
+ Stable tag: 0.7.10
7
 
8
  Lets you edit the permalink of custom post type.
9
 
32
 
33
  == Changelog ==
34
 
35
+ = 0.7.10 =
36
+ * Bug Fix.
37
+
38
  = 0.7.9.1 =
39
  * Support Comment permalink.
40
  * Small change in setting page.