Custom Post Type Permalinks - Version 1.0.3

Version Description

  • add category rule, if only attached category to post type.
Download this release

Release Info

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

Code changes from version 1.0.2 to 1.0.3

CPTP/Module/Rewrite.php CHANGED
@@ -6,7 +6,7 @@
6
  * Add Rewrite Rules
7
  *
8
  * @package Custom_Post_Type_Permalinks
9
- * @version 1.0.2
10
  * @since 0.9.4
11
  *
12
  * */
@@ -120,10 +120,6 @@ class CPTP_Module_Rewrite extends CPTP_Module {
120
 
121
  $date_front = CPTP_Util::get_date_front( $post_type );
122
 
123
- $category_base = get_option( 'category_base' );
124
- if( !$category_base ) {
125
- $category_base = 'category';
126
- }
127
  add_rewrite_rule( $slug . $date_front . '/([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' );
128
  add_rewrite_rule( $slug . $date_front . '/([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' );
129
  add_rewrite_rule( $slug . $date_front . '/([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' );
@@ -138,8 +134,18 @@ class CPTP_Module_Rewrite extends CPTP_Module {
138
  add_rewrite_rule( $slug . $date_front . '/([0-9]{4})/?$', 'index.php?year=$matches[1]&post_type=' . $post_type, 'top' );
139
  add_rewrite_rule( $slug . '/author/([^/]+)/page/?([0-9]{1,})/?$', 'index.php?author_name=$matches[1]&paged=$matches[2]&post_type=' . $post_type, 'top' );
140
  add_rewrite_rule( $slug . '/author/([^/]+)/?$', 'index.php?author_name=$matches[1]&post_type=' . $post_type, 'top' );
141
- add_rewrite_rule( $slug . '/'. $category_base . '/([^/]+)/page/?([0-9]{1,})/?$', 'index.php?category_name=$matches[1]&paged=$matches[2]&post_type=' . $post_type, 'top' );
142
- add_rewrite_rule( $slug . '/'. $category_base . '/([^/]+)/?$', 'index.php?category_name=$matches[1]&post_type=' . $post_type, 'top' );
 
 
 
 
 
 
 
 
 
 
143
 
144
  do_action( 'CPTP_registered_' . $post_type . '_rules', $args, $slug );
145
  }
6
  * Add Rewrite Rules
7
  *
8
  * @package Custom_Post_Type_Permalinks
9
+ * @version 1.0.3
10
  * @since 0.9.4
11
  *
12
  * */
120
 
121
  $date_front = CPTP_Util::get_date_front( $post_type );
122
 
 
 
 
 
123
  add_rewrite_rule( $slug . $date_front . '/([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' );
124
  add_rewrite_rule( $slug . $date_front . '/([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' );
125
  add_rewrite_rule( $slug . $date_front . '/([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' );
134
  add_rewrite_rule( $slug . $date_front . '/([0-9]{4})/?$', 'index.php?year=$matches[1]&post_type=' . $post_type, 'top' );
135
  add_rewrite_rule( $slug . '/author/([^/]+)/page/?([0-9]{1,})/?$', 'index.php?author_name=$matches[1]&paged=$matches[2]&post_type=' . $post_type, 'top' );
136
  add_rewrite_rule( $slug . '/author/([^/]+)/?$', 'index.php?author_name=$matches[1]&post_type=' . $post_type, 'top' );
137
+
138
+ if( in_array( 'category', $args->taxonomies ) ) {
139
+
140
+ $category_base = get_option( 'category_base' );
141
+ if( !$category_base ) {
142
+ $category_base = 'category';
143
+ }
144
+
145
+ add_rewrite_rule( $slug . '/'. $category_base . '/([^/]+)/page/?([0-9]{1,})/?$', 'index.php?category_name=$matches[1]&paged=$matches[2]&post_type=' . $post_type, 'top' );
146
+ add_rewrite_rule( $slug . '/'. $category_base . '/([^/]+)/?$', 'index.php?category_name=$matches[1]&post_type=' . $post_type, 'top' );
147
+
148
+ }
149
 
150
  do_action( 'CPTP_registered_' . $post_type . '_rules', $args, $slug );
151
  }
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: 1.0.2
9
  Text Domain: cptp
10
  License: GPL2 or later
11
  Domain Path: /language/
@@ -22,7 +22,8 @@ Domain Path: /language/
22
  */
23
 
24
  define( 'CPTP_PLUGIN_FILE', __FILE__ );
25
- define( 'CPTP_VERSION', '1.0.2' );
 
26
  define( 'CPTP_DEFAULT_PERMALINK', '/%postname%/' );
27
 
28
 
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: 1.0.3
9
  Text Domain: cptp
10
  License: GPL2 or later
11
  Domain Path: /language/
22
  */
23
 
24
  define( 'CPTP_PLUGIN_FILE', __FILE__ );
25
+ $data = get_file_data( __FILE__, array( 'ver' => 'Version', 'lang_dir' => 'Domain Path' ) );
26
+ define( 'CPTP_VERSION', $data['ver'] );
27
  define( 'CPTP_DEFAULT_PERMALINK', '/%postname%/' );
28
 
29
 
readme.txt CHANGED
@@ -4,7 +4,7 @@ Donate link: http://www.amazon.co.jp/registry/wishlist/COKSXS25MVQV
4
  Tags: permalink,permalinks,custom post type,custom taxonomy,cms
5
  Requires at least: 4.1
6
  Tested up to: 4.2
7
- Stable tag: 1.0.2
8
  License: GPLv2 or Later
9
 
10
  Lets you edit the permalink of custom post type.
@@ -61,6 +61,9 @@ That's it. You can access the permalinks setting by going to *Settings -> Permal
61
 
62
  == Changelog ==
63
 
 
 
 
64
  = 1.0.2 =
65
  * category slug bug fix.
66
 
4
  Tags: permalink,permalinks,custom post type,custom taxonomy,cms
5
  Requires at least: 4.1
6
  Tested up to: 4.2
7
+ Stable tag: 1.0.3
8
  License: GPLv2 or Later
9
 
10
  Lets you edit the permalink of custom post type.
61
 
62
  == Changelog ==
63
 
64
+ = 1.0.3 =
65
+ * add category rule, if only attached category to post type.
66
+
67
  = 1.0.2 =
68
  * category slug bug fix.
69