Custom Post Type Permalinks - Version 3.3.5

Version Description

  • Tested 5.4
  • fix CPTP_Module_Permalink::post_type_link.
Download this release

Release Info

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

Code changes from version 3.3.4 to 3.3.5

CPTP/Module/Permalink.php CHANGED
@@ -48,9 +48,8 @@ class CPTP_Module_Permalink extends CPTP_Module {
48
  * @param WP_Post $post post object.
49
  * @param String $leavename for edit.php.
50
  *
51
- * @version 2.0
52
- *
53
  * @return string
 
54
  */
55
  public function post_type_link( $post_link, $post, $leavename ) {
56
  /**
@@ -113,17 +112,19 @@ class CPTP_Module_Permalink extends CPTP_Module {
113
 
114
  // %post_id%/attachment/%attachement_name%;
115
  $id = filter_input( INPUT_GET, 'post' );
116
- if ( null !== $id && intval( $id ) !== $post->ID ) {
117
- $parent_structure = trim( CPTP_Util::get_permalink_structure( $post->post_type ), '/' );
118
- $parent_dirs = explode( '/', $parent_structure );
119
- if ( is_array( $parent_dirs ) ) {
120
- $last_dir = array_pop( $parent_dirs );
121
- } else {
122
- $last_dir = $parent_dirs;
123
- }
 
124
 
125
- if ( '%post_id%' === $parent_structure || '%post_id%' === $last_dir ) {
126
- $permalink = $permalink . '/attachment/';
 
127
  }
128
  }
129
 
@@ -145,7 +146,7 @@ class CPTP_Module_Permalink extends CPTP_Module {
145
  $category_object = get_term( $category_object, 'category' );
146
  $category = $category_object->slug;
147
  if ( $category_object->parent ) {
148
- $parent = $category_object->parent;
149
  $category = get_category_parents( $parent, false, '/', true ) . $category;
150
  }
151
  }
@@ -176,12 +177,12 @@ class CPTP_Module_Permalink extends CPTP_Module {
176
  '%author%',
177
  ),
178
  array(
179
- date( 'Y', $post_date ),
180
- date( 'm', $post_date ),
181
- date( 'd', $post_date ),
182
- date( 'H', $post_date ),
183
- date( 'i', $post_date ),
184
- date( 's', $post_date ),
185
  $category,
186
  $author,
187
  ),
@@ -189,6 +190,7 @@ class CPTP_Module_Permalink extends CPTP_Module {
189
  );
190
  $permalink = str_replace( $search, $replace, $permalink );
191
  $permalink = home_url( $permalink );
 
192
  return $permalink;
193
  }
194
 
@@ -196,7 +198,7 @@ class CPTP_Module_Permalink extends CPTP_Module {
196
  /**
197
  * Create %tax% -> term
198
  *
199
- * @param int $post_id post id.
200
  * @param string $permalink permalink uri.
201
  *
202
  * @return array
@@ -237,7 +239,7 @@ class CPTP_Module_Permalink extends CPTP_Module {
237
  }
238
 
239
  return array(
240
- 'search' => $search,
241
  'replace' => $replace,
242
  );
243
  }
@@ -259,13 +261,13 @@ class CPTP_Module_Permalink extends CPTP_Module {
259
  /**
260
  * Fix attachment output
261
  *
262
- * @version 1.0
263
- * @since 0.8.2
264
- *
265
  * @param string $link permalink URI.
266
  * @param int $post_id Post ID.
267
  *
268
  * @return string
 
 
 
269
  */
270
  public function attachment_link( $link, $post_id ) {
271
  /**
@@ -299,8 +301,8 @@ class CPTP_Module_Permalink extends CPTP_Module {
299
  return $link;
300
  }
301
 
302
- $permalink = CPTP_Util::get_permalink_structure( $post_parent->post_type );
303
- $post_type = get_post_type_object( $post_parent->post_type );
304
 
305
  if ( empty( $post_type->_builtin ) ) {
306
  if ( strpos( $permalink, '%postname%' ) < strrpos( $permalink, '%post_id%' ) && false === strrpos( $link, 'attachment/' ) ) {
@@ -314,14 +316,13 @@ class CPTP_Module_Permalink extends CPTP_Module {
314
  /**
315
  * Fix taxonomy link outputs.
316
  *
317
- * @since 0.6
318
- * @version 1.0
319
- *
320
  * @param string $termlink link URI.
321
  * @param Object $term Term Object.
322
  * @param Object $taxonomy Taxonomy Object.
323
  *
324
  * @return string
 
 
325
  */
326
  public function term_link( $termlink, $term, $taxonomy ) {
327
  /**
@@ -361,8 +362,8 @@ class CPTP_Module_Permalink extends CPTP_Module {
361
  $post_type = $taxonomy->object_type[0];
362
  }
363
 
364
- $front = substr( $wp_rewrite->front, 1 );
365
- $termlink = str_replace( $front, '', $termlink );// remove front.
366
 
367
  $post_type_obj = get_post_type_object( $post_type );
368
 
@@ -370,8 +371,8 @@ class CPTP_Module_Permalink extends CPTP_Module {
370
  return $termlink;
371
  }
372
 
373
- $slug = $post_type_obj->rewrite['slug'];
374
- $with_front = $post_type_obj->rewrite['with_front'];
375
 
376
  if ( $with_front ) {
377
  $slug = $front . $slug;
48
  * @param WP_Post $post post object.
49
  * @param String $leavename for edit.php.
50
  *
 
 
51
  * @return string
52
+ * @version 2.0
53
  */
54
  public function post_type_link( $post_link, $post, $leavename ) {
55
  /**
112
 
113
  // %post_id%/attachment/%attachement_name%;
114
  $id = filter_input( INPUT_GET, 'post' );
115
+ if ( 'attachment' === $post->post_type ) {
116
+ if ( null !== $id && intval( $id ) !== $post->ID ) {
117
+ $parent_structure = trim( CPTP_Util::get_permalink_structure( $post->post_type ), '/' );
118
+ $parent_dirs = explode( '/', $parent_structure );
119
+ if ( is_array( $parent_dirs ) ) {
120
+ $last_dir = array_pop( $parent_dirs );
121
+ } else {
122
+ $last_dir = $parent_dirs;
123
+ }
124
 
125
+ if ( '%post_id%' === $parent_structure || '%post_id%' === $last_dir ) {
126
+ $permalink = untrailingslashit( $permalink ) . '/attachment/';
127
+ }
128
  }
129
  }
130
 
146
  $category_object = get_term( $category_object, 'category' );
147
  $category = $category_object->slug;
148
  if ( $category_object->parent ) {
149
+ $parent = $category_object->parent;
150
  $category = get_category_parents( $parent, false, '/', true ) . $category;
151
  }
152
  }
177
  '%author%',
178
  ),
179
  array(
180
+ gmdate( 'Y', $post_date ),
181
+ gmdate( 'm', $post_date ),
182
+ gmdate( 'd', $post_date ),
183
+ gmdate( 'H', $post_date ),
184
+ gmdate( 'i', $post_date ),
185
+ gmdate( 's', $post_date ),
186
  $category,
187
  $author,
188
  ),
190
  );
191
  $permalink = str_replace( $search, $replace, $permalink );
192
  $permalink = home_url( $permalink );
193
+
194
  return $permalink;
195
  }
196
 
198
  /**
199
  * Create %tax% -> term
200
  *
201
+ * @param int $post_id post id.
202
  * @param string $permalink permalink uri.
203
  *
204
  * @return array
239
  }
240
 
241
  return array(
242
+ 'search' => $search,
243
  'replace' => $replace,
244
  );
245
  }
261
  /**
262
  * Fix attachment output
263
  *
 
 
 
264
  * @param string $link permalink URI.
265
  * @param int $post_id Post ID.
266
  *
267
  * @return string
268
+ * @since 0.8.2
269
+ *
270
+ * @version 1.0
271
  */
272
  public function attachment_link( $link, $post_id ) {
273
  /**
301
  return $link;
302
  }
303
 
304
+ $permalink = CPTP_Util::get_permalink_structure( $post_parent->post_type );
305
+ $post_type = get_post_type_object( $post_parent->post_type );
306
 
307
  if ( empty( $post_type->_builtin ) ) {
308
  if ( strpos( $permalink, '%postname%' ) < strrpos( $permalink, '%post_id%' ) && false === strrpos( $link, 'attachment/' ) ) {
316
  /**
317
  * Fix taxonomy link outputs.
318
  *
 
 
 
319
  * @param string $termlink link URI.
320
  * @param Object $term Term Object.
321
  * @param Object $taxonomy Taxonomy Object.
322
  *
323
  * @return string
324
+ * @since 0.6
325
+ * @version 1.0
326
  */
327
  public function term_link( $termlink, $term, $taxonomy ) {
328
  /**
362
  $post_type = $taxonomy->object_type[0];
363
  }
364
 
365
+ $front = substr( $wp_rewrite->front, 1 );
366
+ $termlink = str_replace( $front, '', $termlink );// remove front.
367
 
368
  $post_type_obj = get_post_type_object( $post_type );
369
 
371
  return $termlink;
372
  }
373
 
374
+ $slug = $post_type_obj->rewrite['slug'];
375
+ $with_front = $post_type_obj->rewrite['with_front'];
376
 
377
  if ( $with_front ) {
378
  $slug = $front . $slug;
custom-post-type-permalinks.php CHANGED
@@ -5,13 +5,13 @@
5
  * Description: Add post archives of custom post type and customizable permalinks.
6
  * Author: Toro_Unit
7
  * Author URI: https://torounit.com/
8
- * Version: 3.3.4
9
  * Text Domain: custom-post-type-permalinks
10
  * License: GPL2 or later
11
  * Domain Path: /language/
12
  *
13
  * @package Custom_Post_Type_Permalinks
14
- * @version 3.3.4
15
  */
16
 
17
  define( 'CPTP_PLUGIN_FILE', __FILE__ );
5
  * Description: Add post archives of custom post type and customizable permalinks.
6
  * Author: Toro_Unit
7
  * Author URI: https://torounit.com/
8
+ * Version: 3.3.5
9
  * Text Domain: custom-post-type-permalinks
10
  * License: GPL2 or later
11
  * Domain Path: /language/
12
  *
13
  * @package Custom_Post_Type_Permalinks
14
+ * @version 3.3.5
15
  */
16
 
17
  define( 'CPTP_PLUGIN_FILE', __FILE__ );
readme.md CHANGED
@@ -1,4 +1,6 @@
1
  # Custom Post Type Permalinks
 
 
2
 
3
  Edit the permalink of custom post type.
4
 
@@ -9,8 +11,7 @@ Edit the permalink of custom post type.
9
  [![Tested up](https://img.shields.io/wordpress/v/custom-post-type-permalinks.svg)](https://wordpress.org/plugins/custom-post-type-permalinks/)
10
  [![wp.org rating](https://img.shields.io/wordpress/plugin/r/custom-post-type-permalinks.svg)](https://wordpress.org/plugins/custom-post-type-permalinks/)
11
  [![Build Status](https://travis-ci.org/torounit/custom-post-type-permalinks.svg)](https://travis-ci.org/torounit/custom-post-type-permalinks)
12
- [![Donate](https://img.shields.io/badge/donate-paypal-yellow.svg)](https://www.paypal.me/torounit)
13
-
14
  [![](https://ps.w.org/custom-post-type-permalinks/assets/banner-1544x500.png?rev=1044335)](https://wordpress.org/plugins/custom-post-type-permalinks/)
15
 
16
  ## Description
@@ -19,7 +20,7 @@ Custom Post Type Permalinks allow you edit the permalink structure of custom pos
19
 
20
  Change custom taxonomy archive's permalink to "example.org/post_type/taxonomy_name/term_slug". Can disable this fix.
21
 
22
- And support `wp_get_archives( 'post_type=foo' )`.
23
 
24
  [This Plugin published on GitHub.](https://github.com/torounit/custom-post-type-permalinks)
25
 
@@ -41,7 +42,7 @@ Donation: Please send [My Wishlist](http://www.amazon.co.jp/registry/wishlist/CO
41
 
42
  Example:
43
 
44
- ```php
45
  register_post_type( 'foo',
46
  array(
47
  'public' => true,
@@ -52,7 +53,7 @@ register_post_type( 'foo',
52
  'cptp_permalink_structure' => '%post_id%'
53
  )
54
  );
55
- ```
56
 
57
 
58
  ## Installation
@@ -72,19 +73,28 @@ That's it. You can access the permalinks setting by going to *Settings -> Permal
72
 
73
  ## Changelog
74
 
 
 
 
 
 
75
  ### 3.3.1
 
76
  * Add disable option for date / author and post type archive.
77
  * Bug fix for `parse_request`.
78
 
79
  ### 3.2.2
 
80
  * Fix readme.txt
81
 
82
  ### 3.2.0
 
83
  * Support only public post type.
84
  * Add `CPTP_is_rewrite_supported_by_${post_type}` and `CPTP_is_rewrite_supported` filter.
85
  * Remove post_type query wp_get_archives.
86
 
87
  ### 3.1.4
 
88
  * Test for WordPress 4.9.
89
  * PHPCS fix.
90
 
@@ -135,6 +145,7 @@ That's it. You can access the permalinks setting by going to *Settings -> Permal
135
  * `add_rewrite_rules` on `wp_loaded` priority is changed 10 from 100. [fix issue #53](https://github.com/torounit/custom-post-type-permalinks/issues/53)
136
  * Replace `wp_get_post_terms` by `get_the_terms`. [fix issue #55](https://github.com/torounit/custom-post-type-permalinks/issues/55)
137
  * Fix bug `register_uninstall_hook` called twice on each page. [fix issue #56](https://github.com/torounit/custom-post-type-permalinks/issues/56)
 
138
  ### 1.5.4
139
 
140
  * Fixed removed parent post problem.
@@ -207,6 +218,7 @@ That's it. You can access the permalinks setting by going to *Settings -> Permal
207
  * Adding date slug only conflicting `%post_id%`.
208
  * Change taxonomy link rewrite rule. Use `post_type`.
209
  * Can change template include custom taxonomy.
 
210
  ### 0.9.6
211
 
212
  * Category and author.
@@ -268,7 +280,6 @@ That's it. You can access the permalinks setting by going to *Settings -> Permal
268
 
269
  ### 0.9
270
 
271
-
272
  * Add custom post type archive only `has_archive` is `true`.
273
  * Change method name.
274
  * Change hook custom post link.
1
  # Custom Post Type Permalinks
2
+ Donate link: https://www.paypal.me/torounit
3
+ Requires PHP: 5.3
4
 
5
  Edit the permalink of custom post type.
6
 
11
  [![Tested up](https://img.shields.io/wordpress/v/custom-post-type-permalinks.svg)](https://wordpress.org/plugins/custom-post-type-permalinks/)
12
  [![wp.org rating](https://img.shields.io/wordpress/plugin/r/custom-post-type-permalinks.svg)](https://wordpress.org/plugins/custom-post-type-permalinks/)
13
  [![Build Status](https://travis-ci.org/torounit/custom-post-type-permalinks.svg)](https://travis-ci.org/torounit/custom-post-type-permalinks)
14
+ [![Donation](https://img.shields.io/badge/bitcoin-donate-yellow.svg)](https://blockchain.info/ja/address/3HwkojX2pd9wc5kPFdXnDXMTNbgBmPRygX)
 
15
  [![](https://ps.w.org/custom-post-type-permalinks/assets/banner-1544x500.png?rev=1044335)](https://wordpress.org/plugins/custom-post-type-permalinks/)
16
 
17
  ## Description
20
 
21
  Change custom taxonomy archive's permalink to "example.org/post_type/taxonomy_name/term_slug". Can disable this fix.
22
 
23
+ And support `wp_get_archives( 'post_type=foo' )` and post type date archive (ex. `example.com/post_type_slug/date/2010/01/01` ).
24
 
25
  [This Plugin published on GitHub.](https://github.com/torounit/custom-post-type-permalinks)
26
 
42
 
43
  Example:
44
 
45
+ `
46
  register_post_type( 'foo',
47
  array(
48
  'public' => true,
53
  'cptp_permalink_structure' => '%post_id%'
54
  )
55
  );
56
+ `
57
 
58
 
59
  ## Installation
73
 
74
  ## Changelog
75
 
76
+ ### 3.3.5
77
+
78
+ * Tested 5.4
79
+ * fix CPTP_Module_Permalink::post_type_link.
80
+
81
  ### 3.3.1
82
+
83
  * Add disable option for date / author and post type archive.
84
  * Bug fix for `parse_request`.
85
 
86
  ### 3.2.2
87
+
88
  * Fix readme.txt
89
 
90
  ### 3.2.0
91
+
92
  * Support only public post type.
93
  * Add `CPTP_is_rewrite_supported_by_${post_type}` and `CPTP_is_rewrite_supported` filter.
94
  * Remove post_type query wp_get_archives.
95
 
96
  ### 3.1.4
97
+
98
  * Test for WordPress 4.9.
99
  * PHPCS fix.
100
 
145
  * `add_rewrite_rules` on `wp_loaded` priority is changed 10 from 100. [fix issue #53](https://github.com/torounit/custom-post-type-permalinks/issues/53)
146
  * Replace `wp_get_post_terms` by `get_the_terms`. [fix issue #55](https://github.com/torounit/custom-post-type-permalinks/issues/55)
147
  * Fix bug `register_uninstall_hook` called twice on each page. [fix issue #56](https://github.com/torounit/custom-post-type-permalinks/issues/56)
148
+
149
  ### 1.5.4
150
 
151
  * Fixed removed parent post problem.
218
  * Adding date slug only conflicting `%post_id%`.
219
  * Change taxonomy link rewrite rule. Use `post_type`.
220
  * Can change template include custom taxonomy.
221
+
222
  ### 0.9.6
223
 
224
  * Category and author.
280
 
281
  ### 0.9
282
 
 
283
  * Add custom post type archive only `has_archive` is `true`.
284
  * Change method name.
285
  * Change hook custom post link.
readme.txt CHANGED
@@ -3,9 +3,9 @@ Contributors: Toro_Unit,inc2734,ixkaito,keita_kobayashi
3
  Donate link: https://www.paypal.me/torounit
4
  Tags: permalink,permalinks,custom post type,custom taxonomy,cms
5
  Requires at least: 4.3
6
- Tested up to: 5.3
7
  Requires PHP: 5.3
8
- Stable tag: 3.3.4
9
  License: GPLv2 or Later
10
 
11
  Edit the permalink of custom post type.
@@ -68,6 +68,10 @@ That's it. You can access the permalinks setting by going to *Settings -> Permal
68
 
69
  == Changelog ==
70
 
 
 
 
 
71
  = 3.3.1 =
72
  * Add disable option for date / author and post type archive.
73
  * Bug fix for `parse_request`.
3
  Donate link: https://www.paypal.me/torounit
4
  Tags: permalink,permalinks,custom post type,custom taxonomy,cms
5
  Requires at least: 4.3
6
+ Tested up to: 5.4
7
  Requires PHP: 5.3
8
+ Stable tag: 3.3.5
9
  License: GPLv2 or Later
10
 
11
  Edit the permalink of custom post type.
68
 
69
  == Changelog ==
70
 
71
+ = 3.3.5 =
72
+ * Tested 5.4
73
+ * fix CPTP_Module_Permalink::post_type_link.
74
+
75
  = 3.3.1 =
76
  * Add disable option for date / author and post type archive.
77
  * Bug fix for `parse_request`.