Version Description
- Add filter 'CPTP_date_front'.
- Fix sort term by
wp_list_sort
.
Download this release
Release Info
Developer | Toro_Unit |
Plugin | Custom Post Type Permalinks |
Version | 3.1.0 |
Comparing to | |
See all releases |
Code changes from version 3.0.1 to 3.1.0
- CPTP/Module/GetArchives.php +8 -9
- CPTP/Module/Permalink.php +2 -1
- CPTP/Util.php +53 -16
- custom-post-type-permalinks.php +2 -2
- readme.txt +5 -1
CPTP/Module/GetArchives.php
CHANGED
@@ -78,19 +78,19 @@ class CPTP_Module_GetArchives extends CPTP_Module {
|
|
78 |
*
|
79 |
* @version 2.2 03/27/14
|
80 |
*
|
81 |
-
* @param string $
|
82 |
*
|
83 |
* @return string
|
84 |
*/
|
85 |
-
public function get_archives_link( $
|
86 |
global $wp_rewrite;
|
87 |
|
88 |
if ( ! isset( $this->get_archives_where_r['post_type'] ) ) {
|
89 |
-
return $
|
90 |
}
|
91 |
|
92 |
if ( 'post' == $this->get_archives_where_r['post_type'] ) {
|
93 |
-
return $
|
94 |
}
|
95 |
|
96 |
$c = isset( $this->get_archives_where_r['taxonomy'] ) && is_array( $this->get_archives_where_r['taxonomy'] ) ? $this->get_archives_where_r['taxonomy'] : ''; // [steve]
|
@@ -103,10 +103,10 @@ class CPTP_Module_GetArchives extends CPTP_Module {
|
|
103 |
|
104 |
// remove front
|
105 |
$front = substr( $wp_rewrite->front, 1 );
|
106 |
-
$
|
107 |
|
108 |
$blog_url = preg_replace( '/https?:\/\//', '', $blog_url );
|
109 |
-
$ret_link = str_replace( $blog_url, $blog_url . '/%link_dir%', $
|
110 |
|
111 |
$post_type = get_post_type_object( $this->get_archives_where_r['post_type'] );
|
112 |
if ( empty( $c ) ) { // [steve]
|
@@ -120,7 +120,7 @@ class CPTP_Module_GetArchives extends CPTP_Module {
|
|
120 |
$link_dir = $post_type->rewrite['slug'] . '/' . $c['name'] . '/' . $c['termslug'];
|
121 |
}
|
122 |
|
123 |
-
if ( ! strstr( $
|
124 |
$link_dir = $link_dir . CPTP_Util::get_date_front( $post_type );
|
125 |
}
|
126 |
|
@@ -130,10 +130,9 @@ class CPTP_Module_GetArchives extends CPTP_Module {
|
|
130 |
|
131 |
$ret_link = str_replace( '%link_dir%', $link_dir, $ret_link );
|
132 |
} else {
|
133 |
-
$ret_link = $
|
134 |
}
|
135 |
$this->get_archives_where_r['post_type'] = $t; // [steve] reverting post_type to previous value
|
136 |
-
|
137 |
return $ret_link;
|
138 |
}
|
139 |
}
|
78 |
*
|
79 |
* @version 2.2 03/27/14
|
80 |
*
|
81 |
+
* @param string $html archive <li> html.
|
82 |
*
|
83 |
* @return string
|
84 |
*/
|
85 |
+
public function get_archives_link( $html ) {
|
86 |
global $wp_rewrite;
|
87 |
|
88 |
if ( ! isset( $this->get_archives_where_r['post_type'] ) ) {
|
89 |
+
return $html;
|
90 |
}
|
91 |
|
92 |
if ( 'post' == $this->get_archives_where_r['post_type'] ) {
|
93 |
+
return $html;
|
94 |
}
|
95 |
|
96 |
$c = isset( $this->get_archives_where_r['taxonomy'] ) && is_array( $this->get_archives_where_r['taxonomy'] ) ? $this->get_archives_where_r['taxonomy'] : ''; // [steve]
|
103 |
|
104 |
// remove front
|
105 |
$front = substr( $wp_rewrite->front, 1 );
|
106 |
+
$html = str_replace( $front, '', $html );
|
107 |
|
108 |
$blog_url = preg_replace( '/https?:\/\//', '', $blog_url );
|
109 |
+
$ret_link = str_replace( $blog_url, $blog_url . '/%link_dir%', $html );
|
110 |
|
111 |
$post_type = get_post_type_object( $this->get_archives_where_r['post_type'] );
|
112 |
if ( empty( $c ) ) { // [steve]
|
120 |
$link_dir = $post_type->rewrite['slug'] . '/' . $c['name'] . '/' . $c['termslug'];
|
121 |
}
|
122 |
|
123 |
+
if ( ! strstr( $html, '/date/' ) ) {
|
124 |
$link_dir = $link_dir . CPTP_Util::get_date_front( $post_type );
|
125 |
}
|
126 |
|
130 |
|
131 |
$ret_link = str_replace( '%link_dir%', $link_dir, $ret_link );
|
132 |
} else {
|
133 |
+
$ret_link = $html;
|
134 |
}
|
135 |
$this->get_archives_where_r['post_type'] = $t; // [steve] reverting post_type to previous value
|
|
|
136 |
return $ret_link;
|
137 |
}
|
138 |
}
|
CPTP/Module/Permalink.php
CHANGED
@@ -127,7 +127,8 @@ class CPTP_Module_Permalink extends CPTP_Module {
|
|
127 |
if ( false !== strpos( $permalink, '%category%' ) ) {
|
128 |
$categories = get_the_category( $post->ID );
|
129 |
if ( $categories ) {
|
130 |
-
|
|
|
131 |
$category_object = apply_filters( 'post_link_category', $categories[0], $categories, $post );
|
132 |
$category_object = get_term( $category_object, 'category' );
|
133 |
$category = $category_object->slug;
|
127 |
if ( false !== strpos( $permalink, '%category%' ) ) {
|
128 |
$categories = get_the_category( $post->ID );
|
129 |
if ( $categories ) {
|
130 |
+
$categories = CPTP_Util::sort_terms( $categories );
|
131 |
+
|
132 |
$category_object = apply_filters( 'post_link_category', $categories[0], $categories, $post );
|
133 |
$category_object = get_term( $category_object, 'category' );
|
134 |
$category = $category_object->slug;
|
CPTP/Util.php
CHANGED
@@ -7,7 +7,6 @@
|
|
7 |
* @package Custom_Post_Type_Permalinks
|
8 |
* @since 0.9.4
|
9 |
* */
|
10 |
-
|
11 |
class CPTP_Util {
|
12 |
|
13 |
private function __construct() {
|
@@ -18,6 +17,7 @@ class CPTP_Util {
|
|
18 |
*/
|
19 |
public static function get_post_types() {
|
20 |
$post_type = get_post_types( array( '_builtin' => false, 'publicly_queryable' => true, 'show_ui' => true ) );
|
|
|
21 |
return array_filter( $post_type, array( __CLASS__, 'is_post_type_support_rewrite' ) );
|
22 |
|
23 |
}
|
@@ -32,6 +32,7 @@ class CPTP_Util {
|
|
32 |
if ( false === $post_type_object->rewrite ) {
|
33 |
return false;
|
34 |
}
|
|
|
35 |
return true;
|
36 |
}
|
37 |
|
@@ -46,6 +47,7 @@ class CPTP_Util {
|
|
46 |
} else {
|
47 |
$output = 'names';
|
48 |
}
|
|
|
49 |
return get_taxonomies( array( 'show_ui' => true, '_builtin' => false ), $output );
|
50 |
}
|
51 |
|
@@ -57,15 +59,15 @@ class CPTP_Util {
|
|
57 |
* @version 1.0
|
58 |
*
|
59 |
* @param int|WP_Term|object $term
|
60 |
-
* @param string
|
61 |
-
* @param string
|
62 |
-
* @param bool
|
63 |
-
* @param array
|
64 |
*
|
65 |
* @return string
|
66 |
*/
|
67 |
public static function get_taxonomy_parents_slug( $term, $taxonomy = 'category', $separator = '/', $nicename = false, $visited = array() ) {
|
68 |
-
$chain
|
69 |
$parent = get_term( $term, $taxonomy );
|
70 |
if ( is_wp_error( $parent ) ) {
|
71 |
return $parent;
|
@@ -93,16 +95,16 @@ class CPTP_Util {
|
|
93 |
* @deprecated
|
94 |
*
|
95 |
* @param int|WP_Term|object $term
|
96 |
-
* @param string
|
97 |
-
* @param bool
|
98 |
-
* @param string
|
99 |
-
* @param bool
|
100 |
-
* @param array
|
101 |
*
|
102 |
* @return string
|
103 |
*/
|
104 |
public static function get_taxonomy_parents( $term, $taxonomy = 'category', $link = false, $separator = '/', $nicename = false, $visited = array() ) {
|
105 |
-
$chain
|
106 |
$parent = get_term( $term, $taxonomy );
|
107 |
if ( is_wp_error( $parent ) ) {
|
108 |
return $parent;
|
@@ -123,6 +125,7 @@ class CPTP_Util {
|
|
123 |
} else {
|
124 |
$chain .= $name . $separator;
|
125 |
}
|
|
|
126 |
return $chain;
|
127 |
}
|
128 |
|
@@ -130,7 +133,9 @@ class CPTP_Util {
|
|
130 |
* Get permalink structure.
|
131 |
*
|
132 |
* @since 0.9.6
|
|
|
133 |
* @param string|object $post_type post type name. / object post type object.
|
|
|
134 |
* @return string post type structure.
|
135 |
*/
|
136 |
public static function get_permalink_structure( $post_type ) {
|
@@ -155,7 +160,9 @@ class CPTP_Util {
|
|
155 |
* Get permalink structure front for date archive.
|
156 |
*
|
157 |
* @since 1.0.0
|
|
|
158 |
* @param string $post_type post type name.
|
|
|
159 |
* @return string
|
160 |
*/
|
161 |
public static function get_date_front( $post_type ) {
|
@@ -166,15 +173,14 @@ class CPTP_Util {
|
|
166 |
preg_match_all( '/%.+?%/', $structure, $tokens );
|
167 |
$tok_index = 1;
|
168 |
foreach ( (array) $tokens[0] as $token ) {
|
169 |
-
if ( '%post_id%' == $token && ($tok_index <= 3) ) {
|
170 |
$front = '/date';
|
171 |
break;
|
172 |
}
|
173 |
-
$tok_index++;
|
174 |
}
|
175 |
|
176 |
-
return $front;
|
177 |
-
|
178 |
}
|
179 |
|
180 |
/**
|
@@ -186,4 +192,35 @@ class CPTP_Util {
|
|
186 |
public static function get_no_taxonomy_structure() {
|
187 |
return ! ! intval( get_option( 'no_taxonomy_structure', true ) );
|
188 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
189 |
}
|
7 |
* @package Custom_Post_Type_Permalinks
|
8 |
* @since 0.9.4
|
9 |
* */
|
|
|
10 |
class CPTP_Util {
|
11 |
|
12 |
private function __construct() {
|
17 |
*/
|
18 |
public static function get_post_types() {
|
19 |
$post_type = get_post_types( array( '_builtin' => false, 'publicly_queryable' => true, 'show_ui' => true ) );
|
20 |
+
|
21 |
return array_filter( $post_type, array( __CLASS__, 'is_post_type_support_rewrite' ) );
|
22 |
|
23 |
}
|
32 |
if ( false === $post_type_object->rewrite ) {
|
33 |
return false;
|
34 |
}
|
35 |
+
|
36 |
return true;
|
37 |
}
|
38 |
|
47 |
} else {
|
48 |
$output = 'names';
|
49 |
}
|
50 |
+
|
51 |
return get_taxonomies( array( 'show_ui' => true, '_builtin' => false ), $output );
|
52 |
}
|
53 |
|
59 |
* @version 1.0
|
60 |
*
|
61 |
* @param int|WP_Term|object $term
|
62 |
+
* @param string $taxonomy
|
63 |
+
* @param string $separator
|
64 |
+
* @param bool $nicename
|
65 |
+
* @param array $visited
|
66 |
*
|
67 |
* @return string
|
68 |
*/
|
69 |
public static function get_taxonomy_parents_slug( $term, $taxonomy = 'category', $separator = '/', $nicename = false, $visited = array() ) {
|
70 |
+
$chain = '';
|
71 |
$parent = get_term( $term, $taxonomy );
|
72 |
if ( is_wp_error( $parent ) ) {
|
73 |
return $parent;
|
95 |
* @deprecated
|
96 |
*
|
97 |
* @param int|WP_Term|object $term
|
98 |
+
* @param string $taxonomy
|
99 |
+
* @param bool $link
|
100 |
+
* @param string $separator
|
101 |
+
* @param bool $nicename
|
102 |
+
* @param array $visited
|
103 |
*
|
104 |
* @return string
|
105 |
*/
|
106 |
public static function get_taxonomy_parents( $term, $taxonomy = 'category', $link = false, $separator = '/', $nicename = false, $visited = array() ) {
|
107 |
+
$chain = '';
|
108 |
$parent = get_term( $term, $taxonomy );
|
109 |
if ( is_wp_error( $parent ) ) {
|
110 |
return $parent;
|
125 |
} else {
|
126 |
$chain .= $name . $separator;
|
127 |
}
|
128 |
+
|
129 |
return $chain;
|
130 |
}
|
131 |
|
133 |
* Get permalink structure.
|
134 |
*
|
135 |
* @since 0.9.6
|
136 |
+
*
|
137 |
* @param string|object $post_type post type name. / object post type object.
|
138 |
+
*
|
139 |
* @return string post type structure.
|
140 |
*/
|
141 |
public static function get_permalink_structure( $post_type ) {
|
160 |
* Get permalink structure front for date archive.
|
161 |
*
|
162 |
* @since 1.0.0
|
163 |
+
*
|
164 |
* @param string $post_type post type name.
|
165 |
+
*
|
166 |
* @return string
|
167 |
*/
|
168 |
public static function get_date_front( $post_type ) {
|
173 |
preg_match_all( '/%.+?%/', $structure, $tokens );
|
174 |
$tok_index = 1;
|
175 |
foreach ( (array) $tokens[0] as $token ) {
|
176 |
+
if ( '%post_id%' == $token && ( $tok_index <= 3 ) ) {
|
177 |
$front = '/date';
|
178 |
break;
|
179 |
}
|
180 |
+
$tok_index ++;
|
181 |
}
|
182 |
|
183 |
+
return apply_filters( 'CPTP_date_front', $front, $post_type, $structure );
|
|
|
184 |
}
|
185 |
|
186 |
/**
|
192 |
public static function get_no_taxonomy_structure() {
|
193 |
return ! ! intval( get_option( 'no_taxonomy_structure', true ) );
|
194 |
}
|
195 |
+
|
196 |
+
/**
|
197 |
+
* Sort Terms.
|
198 |
+
*
|
199 |
+
* @since 3.1.0
|
200 |
+
*
|
201 |
+
* @param WP_Term[] $terms
|
202 |
+
* @param string|array $orderby
|
203 |
+
* @param string $order
|
204 |
+
*
|
205 |
+
* @return WP_Term[]
|
206 |
+
*/
|
207 |
+
public static function sort_terms( $terms, $orderby = 'term_id', $order = 'ASC' ) {
|
208 |
+
|
209 |
+
if ( function_exists( 'wp_list_sort' ) ) {
|
210 |
+
$terms = wp_list_sort( $terms, 'term_id', 'ASC' );
|
211 |
+
} else {
|
212 |
+
|
213 |
+
if ( 'name' == $orderby ) {
|
214 |
+
usort( $terms, '_usort_terms_by_name' );
|
215 |
+
} else {
|
216 |
+
usort( $terms, '_usort_terms_by_ID' );
|
217 |
+
}
|
218 |
+
|
219 |
+
if ( 'DESC' == $order ) {
|
220 |
+
$terms = array_reverse( $terms );
|
221 |
+
}
|
222 |
+
}
|
223 |
+
|
224 |
+
return $terms;
|
225 |
+
}
|
226 |
}
|
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.
|
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.
|
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.1.0
|
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.1.0
|
15 |
*/
|
16 |
|
17 |
define( 'CPTP_PLUGIN_FILE', __FILE__ );
|
readme.txt
CHANGED
@@ -4,7 +4,7 @@ Donate link: https://blockchain.info/ja/address/3HwkojX2pd9wc5kPFdXnDXMTNb
|
|
4 |
Tags: permalink,permalinks,custom post type,custom taxonomy,cms
|
5 |
Requires at least: 4.3
|
6 |
Tested up to: 4.7
|
7 |
-
Stable tag: 3.
|
8 |
License: GPLv2 or Later
|
9 |
|
10 |
Edit the permalink of custom post type.
|
@@ -67,6 +67,10 @@ That's it. You can access the permalinks setting by going to *Settings -> Permal
|
|
67 |
|
68 |
== Changelog ==
|
69 |
|
|
|
|
|
|
|
|
|
70 |
= 3.0.0 =
|
71 |
* Admin notice on update plugin.
|
72 |
* Large bug fix.
|
4 |
Tags: permalink,permalinks,custom post type,custom taxonomy,cms
|
5 |
Requires at least: 4.3
|
6 |
Tested up to: 4.7
|
7 |
+
Stable tag: 3.1.0
|
8 |
License: GPLv2 or Later
|
9 |
|
10 |
Edit the permalink of custom post type.
|
67 |
|
68 |
== Changelog ==
|
69 |
|
70 |
+
= 3.1.0 =
|
71 |
+
* Add filter 'CPTP_date_front'.
|
72 |
+
* Fix sort term by `wp_list_sort` .
|
73 |
+
|
74 |
= 3.0.0 =
|
75 |
* Admin notice on update plugin.
|
76 |
* Large bug fix.
|