Version Description
- Archives Rewrite Fix.
Download this release
Release Info
Developer | Toro_Unit |
Plugin | Custom Post Type Permalinks |
Version | 0.9.5.2 |
Comparing to | |
See all releases |
Code changes from version 0.9.5.1 to 0.9.5.2
- CPTP/Module/Rewrite.php +77 -106
- custom-post-type-permalinks.php +1 -1
- readme.txt +4 -1
CPTP/Module/Rewrite.php
CHANGED
@@ -15,61 +15,10 @@ class CPTP_Module_Rewrite extends CPTP_Module {
|
|
15 |
|
16 |
public function add_hook() {
|
17 |
add_action( 'parse_request', array( $this, "parse_request") );
|
18 |
-
add_action( 'wp_loaded', array( $this,'add_archive_rewrite_rules'), 99 );
|
19 |
-
add_action( 'wp_loaded', array( $this,'add_tax_rewrite_rules') );
|
20 |
add_action( 'registered_post_type', array( $this,'registered_post_type'), 10, 2 );
|
|
|
21 |
}
|
22 |
|
23 |
-
/**
|
24 |
-
*
|
25 |
-
* Add rewrite rules for archives.
|
26 |
-
* @version 1.1
|
27 |
-
*
|
28 |
-
*/
|
29 |
-
public function add_archive_rewrite_rules() {
|
30 |
-
$post_types = CPTP_Util::get_post_types();
|
31 |
-
|
32 |
-
foreach ( $post_types as $post_type ):
|
33 |
-
if( !$post_type ) {
|
34 |
-
continue;
|
35 |
-
}
|
36 |
-
|
37 |
-
$permalink = get_option( $post_type.'_structure' );
|
38 |
-
$post_type_obj = get_post_type_object($post_type);
|
39 |
-
$slug = $post_type_obj->rewrite['slug'];
|
40 |
-
if( !$slug )
|
41 |
-
$slug = $post_type;
|
42 |
-
|
43 |
-
if( $post_type_obj->has_archive ){
|
44 |
-
if( is_string( $post_type_obj->has_archive ) ){
|
45 |
-
$slug = $post_type_obj->has_archive;
|
46 |
-
};
|
47 |
-
|
48 |
-
if($post_type_obj->rewrite['with_front']) {
|
49 |
-
global $wp_rewrite;
|
50 |
-
$slug = substr( $wp_rewrite->front, 1 ).$slug;
|
51 |
-
}
|
52 |
-
|
53 |
-
|
54 |
-
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' );
|
55 |
-
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' );
|
56 |
-
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' );
|
57 |
-
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' );
|
58 |
-
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' );
|
59 |
-
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' );
|
60 |
-
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' );
|
61 |
-
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' );
|
62 |
-
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' );
|
63 |
-
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' );
|
64 |
-
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' );
|
65 |
-
add_rewrite_rule( $slug.'/date/([0-9]{4})/?$', 'index.php?year=$matches[1]&post_type='.$post_type, 'top' );
|
66 |
-
add_rewrite_rule( $slug.'/author/([^/]+)/?$', 'index.php?author_name=$matches[1]&post_type='.$post_type, 'top' );
|
67 |
-
}
|
68 |
-
|
69 |
-
endforeach;
|
70 |
-
}
|
71 |
-
|
72 |
-
|
73 |
|
74 |
/**
|
75 |
*
|
@@ -82,7 +31,7 @@ class CPTP_Module_Rewrite extends CPTP_Module {
|
|
82 |
|
83 |
public function registered_post_type( $post_type, $args ) {
|
84 |
|
85 |
-
global $wp_post_types, $wp_rewrite
|
86 |
|
87 |
if( $args->_builtin or !$args->publicly_queryable or !$args->show_ui ){
|
88 |
return false;
|
@@ -105,83 +54,105 @@ class CPTP_Module_Rewrite extends CPTP_Module {
|
|
105 |
|
106 |
$permalink = trim($permalink, "/" );
|
107 |
$rewrite_args = $args->rewrite;
|
|
|
|
|
|
|
|
|
108 |
$rewrite_args["walk_dirs"] = false;
|
109 |
add_permastruct( $post_type, $permalink, $rewrite_args);
|
110 |
|
111 |
-
}
|
112 |
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
123 |
}
|
124 |
|
125 |
|
126 |
-
global $wp_rewrite;
|
127 |
-
$taxonomies = CPTP_Util::get_taxonomies();
|
128 |
-
$taxonomies['category'] = 'category';
|
129 |
|
130 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
131 |
return false;
|
132 |
}
|
133 |
|
134 |
-
|
135 |
-
$taxonomyObject = get_taxonomy($taxonomy);
|
136 |
-
$post_types = $taxonomyObject->object_type;
|
137 |
|
138 |
-
|
139 |
-
|
140 |
-
|
|
|
|
|
141 |
|
142 |
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
|
155 |
-
|
156 |
-
|
157 |
-
|
|
|
|
|
|
|
|
|
158 |
} else {
|
159 |
-
|
160 |
-
if (isset($taxonomyObject->rewrite['slug'])) {
|
161 |
-
$taxonomypat = $taxonomyObject->rewrite['slug'];
|
162 |
-
} else {
|
163 |
-
$taxonomypat = $taxonomy;
|
164 |
-
}
|
165 |
-
// [Xiphe] stop
|
166 |
-
|
167 |
-
$tax = $taxonomy;
|
168 |
}
|
|
|
|
|
|
|
|
|
169 |
|
170 |
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
|
183 |
-
endforeach;
|
184 |
endforeach;
|
|
|
185 |
}
|
186 |
|
187 |
|
15 |
|
16 |
public function add_hook() {
|
17 |
add_action( 'parse_request', array( $this, "parse_request") );
|
|
|
|
|
18 |
add_action( 'registered_post_type', array( $this,'registered_post_type'), 10, 2 );
|
19 |
+
add_action( 'registered_taxonomy', array( $this,'registered_taxonomy'), 10, 3 );
|
20 |
}
|
21 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
22 |
|
23 |
/**
|
24 |
*
|
31 |
|
32 |
public function registered_post_type( $post_type, $args ) {
|
33 |
|
34 |
+
global $wp_post_types, $wp_rewrite;
|
35 |
|
36 |
if( $args->_builtin or !$args->publicly_queryable or !$args->show_ui ){
|
37 |
return false;
|
54 |
|
55 |
$permalink = trim($permalink, "/" );
|
56 |
$rewrite_args = $args->rewrite;
|
57 |
+
if( !is_array($rewrite_args) ) {
|
58 |
+
$rewrite_args = array( 'with_front' => $args->rewrite );
|
59 |
+
}
|
60 |
+
|
61 |
$rewrite_args["walk_dirs"] = false;
|
62 |
add_permastruct( $post_type, $permalink, $rewrite_args);
|
63 |
|
|
|
64 |
|
65 |
+
|
66 |
+
$slug = $args->rewrite['slug'];
|
67 |
+
if( $args->has_archive ){
|
68 |
+
if( is_string( $args->has_archive ) ){
|
69 |
+
$slug = $args->has_archive;
|
70 |
+
};
|
71 |
+
|
72 |
+
if($args->rewrite['with_front']) {
|
73 |
+
$slug = substr( $wp_rewrite->front, 1 ).$slug;
|
74 |
+
}
|
75 |
+
|
76 |
+
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' );
|
77 |
+
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' );
|
78 |
+
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' );
|
79 |
+
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' );
|
80 |
+
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' );
|
81 |
+
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' );
|
82 |
+
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' );
|
83 |
+
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' );
|
84 |
+
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' );
|
85 |
+
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' );
|
86 |
+
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' );
|
87 |
+
add_rewrite_rule( $slug.'/date/([0-9]{4})/?$', 'index.php?year=$matches[1]&post_type='.$post_type, 'top' );
|
88 |
+
add_rewrite_rule( $slug.'/author/([^/]+)/?$', 'index.php?author_name=$matches[1]&post_type='.$post_type, 'top' );
|
89 |
}
|
90 |
|
91 |
|
|
|
|
|
|
|
92 |
|
93 |
+
}
|
94 |
+
|
95 |
+
|
96 |
+
public function registered_taxonomy( $taxonomy, $object_type, $args ) {
|
97 |
+
|
98 |
+
if(get_option('no_taxonomy_structure')) {
|
99 |
+
return false;
|
100 |
+
}
|
101 |
+
if($args["_builtin"]) {
|
102 |
return false;
|
103 |
}
|
104 |
|
105 |
+
global $wp_rewrite;
|
|
|
|
|
106 |
|
107 |
+
$taxonomyObject = $args;
|
108 |
+
$post_types = $args["object_type"];
|
109 |
+
foreach ($post_types as $post_type):
|
110 |
+
$post_type_obj = get_post_type_object($post_type);
|
111 |
+
$slug = $post_type_obj->rewrite['slug'];
|
112 |
|
113 |
|
114 |
+
if(!$slug) {
|
115 |
+
$slug = $post_type;
|
116 |
+
}
|
117 |
|
118 |
+
if(is_string($post_type_obj->has_archive)) {
|
119 |
+
$slug = $post_type_obj->has_archive;
|
120 |
+
};
|
121 |
|
122 |
+
if($post_type_obj->rewrite['with_front']) {
|
123 |
+
$slug = substr( $wp_rewrite->front, 1 ).$slug;
|
124 |
+
}
|
125 |
|
126 |
+
if ( $taxonomy == 'category' ){
|
127 |
+
$taxonomypat = ($cb = get_option('category_base')) ? $cb : $taxonomy;
|
128 |
+
$tax = 'category_name';
|
129 |
+
} else {
|
130 |
+
// Edit by [Xiphe]
|
131 |
+
if (isset($args["rewrite"]['slug'])) {
|
132 |
+
$taxonomypat = $args["rewrite"]['slug'];
|
133 |
} else {
|
134 |
+
$taxonomypat = $taxonomy;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
135 |
}
|
136 |
+
// [Xiphe] stop
|
137 |
+
|
138 |
+
$tax = $taxonomy;
|
139 |
+
}
|
140 |
|
141 |
|
142 |
+
//add taxonomy slug
|
143 |
+
add_rewrite_rule( $slug.'/'.$taxonomypat.'/(.+?)/page/?([0-9]{1,})/?$', 'index.php?'.$tax.'=$matches[1]&paged=$matches[2]&post_type='.$post_type, 'top' );
|
144 |
+
add_rewrite_rule( $slug.'/'.$taxonomypat.'/(.+?)/feed/(feed|rdf|rss|rss2|atom)/?$', 'index.php?'.$tax.'=$matches[1]&feed=$matches[2]&post_type='.$post_type, 'top' );
|
145 |
+
add_rewrite_rule( $slug.'/'.$taxonomypat.'/(.+?)/(feed|rdf|rss|rss2|atom)/?$', 'index.php?'.$tax.'=$matches[1]&feed=$matches[2]&post_type='.$post_type, 'top' );
|
146 |
+
add_rewrite_rule( $slug.'/'.$taxonomypat.'/(.+?)/?$', 'index.php?'.$tax.'=$matches[1]&post_type='.$post_type, 'top' ); // modified by [steve] [*** bug fixing]
|
147 |
|
148 |
+
// below rules were added by [steve]
|
149 |
+
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' );
|
150 |
+
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' );
|
151 |
+
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' );
|
152 |
+
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' );
|
153 |
|
|
|
154 |
endforeach;
|
155 |
+
|
156 |
}
|
157 |
|
158 |
|
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.9.5.
|
9 |
Text Domain: cptp
|
10 |
License: GPL2 or later
|
11 |
Domain Path: /language/
|
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.9.5.2
|
9 |
Text Domain: cptp
|
10 |
License: GPL2 or later
|
11 |
Domain Path: /language/
|
readme.txt
CHANGED
@@ -3,7 +3,7 @@ Contributors: Toro_Unit
|
|
3 |
Tags: permalink,permalinks,custom post type,custom taxonomy,cms
|
4 |
Requires at least: 3.7
|
5 |
Tested up to: 3.8
|
6 |
-
Stable tag: 0.9.5.
|
7 |
|
8 |
Lets you edit the permalink of custom post type.
|
9 |
|
@@ -41,6 +41,9 @@ That's it. You can access the permalinks setting by going to *Settings -> Permal
|
|
41 |
|
42 |
== Changelog ==
|
43 |
|
|
|
|
|
|
|
44 |
= 0.9.5.1 =
|
45 |
* Admin Bug Fix.
|
46 |
|
3 |
Tags: permalink,permalinks,custom post type,custom taxonomy,cms
|
4 |
Requires at least: 3.7
|
5 |
Tested up to: 3.8
|
6 |
+
Stable tag: 0.9.5.2
|
7 |
|
8 |
Lets you edit the permalink of custom post type.
|
9 |
|
41 |
|
42 |
== Changelog ==
|
43 |
|
44 |
+
= 0.9.5.2 =
|
45 |
+
* Archives Rewrite Fix.
|
46 |
+
|
47 |
= 0.9.5.1 =
|
48 |
* Admin Bug Fix.
|
49 |
|