Version Description
Download this release
Release Info
Developer | Toro_Unit |
Plugin | Custom Post Type Permalinks |
Version | 2.1.1 |
Comparing to | |
See all releases |
Code changes from version 2.0.2 to 2.1.1
- CPTP/Module/Admin.php +17 -40
- CPTP/Module/Permalink.php +2 -2
- CPTP/Module/Rewrite.php +8 -51
- CPTP/Util.php +57 -4
- assets/settings-pointer.js +21 -0
- custom-post-type-permalinks.php +2 -2
- readme.md +5 -0
- readme.txt +6 -1
CPTP/Module/Admin.php
CHANGED
@@ -13,7 +13,6 @@ class CPTP_Module_Admin extends CPTP_Module {
|
|
13 |
public function add_hook() {
|
14 |
add_action( 'admin_init', array( $this, 'settings_api_init' ), 30 );
|
15 |
add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_css_js' ) );
|
16 |
-
add_action( 'admin_footer', array( $this, 'pointer_js' ) );
|
17 |
}
|
18 |
|
19 |
|
@@ -71,16 +70,11 @@ class CPTP_Module_Admin extends CPTP_Module {
|
|
71 |
|
72 |
public function setting_section_callback_function() {
|
73 |
?>
|
74 |
-
<p><?php _e( '
|
75 |
-
<?php _e( '
|
76 |
-
<br/>
|
77 |
-
<?php _e( "<code>%\"custom_taxonomy_slug\"%</code> will replace the taxonomy's term.", 'custom-post-type-permalinks' ); ?>
|
78 |
-
</p>
|
79 |
|
80 |
<p><?php _e( "Presence of the trailing '/' is unified into a standard permalink structure setting.", 'custom-post-type-permalinks' ); ?>
|
81 |
-
<p><?php _e( 'If <code>has_archive</code> is true, add permalinks for custom post type archive.', 'custom-post-type-permalinks' );
|
82 |
-
<?php _e( "If you don't enter a permalink structure, permalinks will be configured as <code>/%postname%/</code>.", 'custom-post-type-permalinks' ); ?>
|
83 |
-
</p>
|
84 |
<?php
|
85 |
}
|
86 |
|
@@ -142,39 +136,22 @@ class CPTP_Module_Admin extends CPTP_Module {
|
|
142 |
* @since 0.8.5
|
143 |
*/
|
144 |
public function enqueue_css_js() {
|
145 |
-
|
146 |
-
wp_enqueue_script( 'wp-pointer' );
|
147 |
-
}
|
148 |
-
|
149 |
-
|
150 |
-
/**
|
151 |
-
*
|
152 |
-
* add js for pointer
|
153 |
-
*
|
154 |
-
* @since 0.8.5
|
155 |
-
*/
|
156 |
-
public function pointer_js() {
|
157 |
if ( ! is_network_admin() ) {
|
158 |
$dismissed = explode( ',', get_user_meta( get_current_user_id(), 'dismissed_wp_pointers', true ) );
|
159 |
-
if ( false === array_search(
|
160 |
-
|
161 |
-
<
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
}
|
174 |
-
}).pointer("open");
|
175 |
-
});
|
176 |
-
</script>
|
177 |
-
<?php
|
178 |
}
|
179 |
}
|
180 |
}
|
13 |
public function add_hook() {
|
14 |
add_action( 'admin_init', array( $this, 'settings_api_init' ), 30 );
|
15 |
add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_css_js' ) );
|
|
|
16 |
}
|
17 |
|
18 |
|
70 |
|
71 |
public function setting_section_callback_function() {
|
72 |
?>
|
73 |
+
<p><?php _e( 'The tags you can use are WordPress Structure Tags and <code>%"custom_taxonomy_slug"%</code> (e.g. <code>%actors%</code> or <code>%movie_actors%</code>).', 'custom-post-type-permalinks' ); ?>
|
74 |
+
<?php _e( '<code>%"custom_taxonomy_slug"%</code> is replaced by the term of taxonomy.', 'custom-post-type-permalinks' ); ?></p>
|
|
|
|
|
|
|
75 |
|
76 |
<p><?php _e( "Presence of the trailing '/' is unified into a standard permalink structure setting.", 'custom-post-type-permalinks' ); ?>
|
77 |
+
<p><?php _e( 'If <code>has_archive</code> is true, add permalinks for custom post type archive.', 'custom-post-type-permalinks' ); ?></p>
|
|
|
|
|
78 |
<?php
|
79 |
}
|
80 |
|
136 |
* @since 0.8.5
|
137 |
*/
|
138 |
public function enqueue_css_js() {
|
139 |
+
$pointer_name = 'custom-post-type-permalinks-settings';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
140 |
if ( ! is_network_admin() ) {
|
141 |
$dismissed = explode( ',', get_user_meta( get_current_user_id(), 'dismissed_wp_pointers', true ) );
|
142 |
+
if ( false === array_search( $pointer_name, $dismissed ) ) {
|
143 |
+
$content = '';
|
144 |
+
$content .= '<h3>' . __( 'Custom Post Type Permalinks', 'custom-post-type-permalinks' ) . '</h3>';
|
145 |
+
$content .= '<p>' . __( 'You can setting permalink for post type in <a href="options-permalink.php">Permalinks</a>.', 'custom-post-type-permalinks' ) . '</p>';
|
146 |
+
|
147 |
+
wp_enqueue_style( 'wp-pointer' );
|
148 |
+
wp_enqueue_script( 'wp-pointer' );
|
149 |
+
wp_enqueue_script( 'custom-post-type-permalinks-pointer', plugins_url( 'assets/settings-pointer.js', CPTP_PLUGIN_FILE ), array( 'wp-pointer' ), CPTP_VERSION );
|
150 |
+
|
151 |
+
wp_localize_script('custom-post-type-permalinks-pointer', 'CPTP_Settings_Pointer', array(
|
152 |
+
'content' => $content,
|
153 |
+
'name' => $pointer_name,
|
154 |
+
));
|
|
|
|
|
|
|
|
|
|
|
|
|
155 |
}
|
156 |
}
|
157 |
}
|
CPTP/Module/Permalink.php
CHANGED
@@ -210,7 +210,7 @@ class CPTP_Module_Permalink extends CPTP_Module {
|
|
210 |
$term_slug = $term_obj->slug;
|
211 |
|
212 |
if ( isset( $term_obj->parent ) and 0 != $term_obj->parent ) {
|
213 |
-
$term_slug = CPTP_Util::
|
214 |
}
|
215 |
}
|
216 |
|
@@ -344,7 +344,7 @@ class CPTP_Module_Permalink extends CPTP_Module {
|
|
344 |
}
|
345 |
|
346 |
if ( ! $taxonomy->rewrite['hierarchical'] ) {
|
347 |
-
$termlink = str_replace( $term->slug . '/', CPTP_Util::
|
348 |
}
|
349 |
|
350 |
return $termlink;
|
210 |
$term_slug = $term_obj->slug;
|
211 |
|
212 |
if ( isset( $term_obj->parent ) and 0 != $term_obj->parent ) {
|
213 |
+
$term_slug = CPTP_Util::get_taxonomy_parents_slug( $term_obj->parent, $taxonomy, '/', true ) . $term_slug;
|
214 |
}
|
215 |
}
|
216 |
|
344 |
}
|
345 |
|
346 |
if ( ! $taxonomy->rewrite['hierarchical'] ) {
|
347 |
+
$termlink = str_replace( $term->slug . '/', CPTP_Util::get_taxonomy_parents_slug( $term->term_id, $taxonomy->name, '/', true ), $termlink );
|
348 |
}
|
349 |
|
350 |
return $termlink;
|
CPTP/Module/Rewrite.php
CHANGED
@@ -11,58 +11,11 @@
|
|
11 |
* */
|
12 |
class CPTP_Module_Rewrite extends CPTP_Module {
|
13 |
|
14 |
-
/** @var array */
|
15 |
-
private $post_type_args;
|
16 |
-
/** @var array */
|
17 |
-
private $taxonomy_args;
|
18 |
|
19 |
public function add_hook() {
|
20 |
add_action( 'parse_request', array( $this, 'parse_request' ) );
|
21 |
-
|
22 |
-
add_action( '
|
23 |
-
add_action( 'registered_taxonomy', array( $this, 'registered_taxonomy' ), 10, 3 );
|
24 |
-
|
25 |
-
add_action( 'wp_loaded', array( $this, 'add_rewrite_rules' ), 10 );
|
26 |
-
}
|
27 |
-
|
28 |
-
|
29 |
-
public function add_rewrite_rules() {
|
30 |
-
|
31 |
-
foreach ( $this->taxonomy_args as $args ) {
|
32 |
-
call_user_func_array( array( $this, 'register_taxonomy_rules' ), $args );
|
33 |
-
}
|
34 |
-
|
35 |
-
foreach ( $this->post_type_args as $args ) {
|
36 |
-
call_user_func_array( array( $this, 'register_post_type_rules' ), $args );
|
37 |
-
}
|
38 |
-
|
39 |
-
}
|
40 |
-
|
41 |
-
/**
|
42 |
-
*
|
43 |
-
* registered_post_type
|
44 |
-
*
|
45 |
-
* queue post_type rewrite.
|
46 |
-
*
|
47 |
-
* @param string $post_type Post type.
|
48 |
-
* @param object $args Arguments used to register the post type.
|
49 |
-
*/
|
50 |
-
public function registered_post_type( $post_type, $args ) {
|
51 |
-
$this->post_type_args[] = func_get_args();
|
52 |
-
}
|
53 |
-
|
54 |
-
/**
|
55 |
-
*
|
56 |
-
* registered_taxonomy
|
57 |
-
*
|
58 |
-
* queue taxonomy rewrite.
|
59 |
-
*
|
60 |
-
* @param string $taxonomy Taxonomy slug.
|
61 |
-
* @param array|string $object_type Object type or array of object types.
|
62 |
-
* @param array $args Array of taxonomy registration arguments.
|
63 |
-
*/
|
64 |
-
public function registered_taxonomy( $taxonomy, $object_type, $args ) {
|
65 |
-
$this->taxonomy_args[] = func_get_args();
|
66 |
}
|
67 |
|
68 |
|
@@ -83,7 +36,7 @@ class CPTP_Module_Rewrite extends CPTP_Module {
|
|
83 |
/** @var WP_Rewrite $wp_rewrite */
|
84 |
global $wp_rewrite;
|
85 |
|
86 |
-
if ( $args->_builtin or ! $args->publicly_queryable
|
87 |
return;
|
88 |
}
|
89 |
$permalink = CPTP_Util::get_permalink_structure( $post_type );
|
@@ -166,15 +119,19 @@ class CPTP_Module_Rewrite extends CPTP_Module {
|
|
166 |
* @return void
|
167 |
*/
|
168 |
public function register_taxonomy_rules( $taxonomy, $object_type, $args ) {
|
|
|
169 |
|
170 |
if ( get_option( 'no_taxonomy_structure' ) ) {
|
171 |
return;
|
172 |
}
|
|
|
173 |
if ( $args['_builtin'] ) {
|
174 |
return;
|
175 |
}
|
176 |
|
177 |
-
|
|
|
|
|
178 |
|
179 |
$post_types = $args['object_type'];
|
180 |
foreach ( $post_types as $post_type ) :
|
11 |
* */
|
12 |
class CPTP_Module_Rewrite extends CPTP_Module {
|
13 |
|
|
|
|
|
|
|
|
|
14 |
|
15 |
public function add_hook() {
|
16 |
add_action( 'parse_request', array( $this, 'parse_request' ) );
|
17 |
+
add_action( 'registered_post_type', array( $this, 'register_post_type_rules' ), 10, 2 );
|
18 |
+
add_action( 'registered_taxonomy', array( $this, 'register_taxonomy_rules' ), 10, 3 );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
}
|
20 |
|
21 |
|
36 |
/** @var WP_Rewrite $wp_rewrite */
|
37 |
global $wp_rewrite;
|
38 |
|
39 |
+
if ( $args->_builtin or ! $args->publicly_queryable ) {
|
40 |
return;
|
41 |
}
|
42 |
$permalink = CPTP_Util::get_permalink_structure( $post_type );
|
119 |
* @return void
|
120 |
*/
|
121 |
public function register_taxonomy_rules( $taxonomy, $object_type, $args ) {
|
122 |
+
global $wp_rewrite;
|
123 |
|
124 |
if ( get_option( 'no_taxonomy_structure' ) ) {
|
125 |
return;
|
126 |
}
|
127 |
+
|
128 |
if ( $args['_builtin'] ) {
|
129 |
return;
|
130 |
}
|
131 |
|
132 |
+
if ( false === $args['rewrite'] ) {
|
133 |
+
return;
|
134 |
+
}
|
135 |
|
136 |
$post_types = $args['object_type'];
|
137 |
foreach ( $post_types as $post_type ) :
|
CPTP/Util.php
CHANGED
@@ -13,10 +13,18 @@ class CPTP_Util {
|
|
13 |
private function __construct() {
|
14 |
}
|
15 |
|
|
|
|
|
|
|
16 |
public static function get_post_types() {
|
17 |
-
return get_post_types( array( '_builtin' => false, 'publicly_queryable' => true
|
18 |
}
|
19 |
|
|
|
|
|
|
|
|
|
|
|
20 |
public static function get_taxonomies( $objects = false ) {
|
21 |
if ( $objects ) {
|
22 |
$output = 'objects';
|
@@ -29,13 +37,58 @@ class CPTP_Util {
|
|
29 |
|
30 |
/**
|
31 |
*
|
32 |
-
* Get Custom Taxonomies parents.
|
33 |
*
|
34 |
* @version 1.0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
35 |
*/
|
36 |
-
public static function get_taxonomy_parents( $
|
37 |
$chain = '';
|
38 |
-
$parent = get_term( $
|
39 |
if ( is_wp_error( $parent ) ) {
|
40 |
return $parent;
|
41 |
}
|
13 |
private function __construct() {
|
14 |
}
|
15 |
|
16 |
+
/**
|
17 |
+
* @return array
|
18 |
+
*/
|
19 |
public static function get_post_types() {
|
20 |
+
return get_post_types( array( '_builtin' => false, 'publicly_queryable' => true ) );
|
21 |
}
|
22 |
|
23 |
+
/**
|
24 |
+
* @param bool $objects
|
25 |
+
*
|
26 |
+
* @return array
|
27 |
+
*/
|
28 |
public static function get_taxonomies( $objects = false ) {
|
29 |
if ( $objects ) {
|
30 |
$output = 'objects';
|
37 |
|
38 |
/**
|
39 |
*
|
40 |
+
* Get Custom Taxonomies parents slug.
|
41 |
*
|
42 |
* @version 1.0
|
43 |
+
*
|
44 |
+
* @param int|WP_Term|object $term
|
45 |
+
* @param string $taxonomy
|
46 |
+
* @param string $separator
|
47 |
+
* @param bool $nicename
|
48 |
+
* @param array $visited
|
49 |
+
*
|
50 |
+
* @return string
|
51 |
+
*/
|
52 |
+
public static function get_taxonomy_parents_slug( $term, $taxonomy = 'category', $separator = '/', $nicename = false, $visited = array() ) {
|
53 |
+
$chain = '';
|
54 |
+
$parent = get_term( $term, $taxonomy );
|
55 |
+
if ( is_wp_error( $parent ) ) {
|
56 |
+
return $parent;
|
57 |
+
}
|
58 |
+
|
59 |
+
if ( $nicename ) {
|
60 |
+
$name = $parent->slug;
|
61 |
+
} else {
|
62 |
+
$name = $parent->name;
|
63 |
+
}
|
64 |
+
|
65 |
+
if ( $parent->parent && ( $parent->parent != $parent->term_id ) && ! in_array( $parent->parent, $visited ) ) {
|
66 |
+
$visited[] = $parent->parent;
|
67 |
+
$chain .= CPTP_Util::get_taxonomy_parents_slug( $parent->parent, $taxonomy, $separator, $nicename, $visited );
|
68 |
+
}
|
69 |
+
$chain .= $name.$separator;
|
70 |
+
|
71 |
+
return $chain;
|
72 |
+
}
|
73 |
+
|
74 |
+
/**
|
75 |
+
*
|
76 |
+
* Get Custom Taxonomies parents.
|
77 |
+
*
|
78 |
+
* @deprecated
|
79 |
+
*
|
80 |
+
* @param int|WP_Term|object $term
|
81 |
+
* @param string $taxonomy
|
82 |
+
* @param bool $link
|
83 |
+
* @param string $separator
|
84 |
+
* @param bool $nicename
|
85 |
+
* @param array $visited
|
86 |
+
*
|
87 |
+
* @return string
|
88 |
*/
|
89 |
+
public static function get_taxonomy_parents( $term, $taxonomy = 'category', $link = false, $separator = '/', $nicename = false, $visited = array() ) {
|
90 |
$chain = '';
|
91 |
+
$parent = get_term( $term, $taxonomy );
|
92 |
if ( is_wp_error( $parent ) ) {
|
93 |
return $parent;
|
94 |
}
|
assets/settings-pointer.js
ADDED
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
(function ($) {
|
2 |
+
|
3 |
+
$(function () {
|
4 |
+
|
5 |
+
if( window.CPTP_Settings_Pointer ) {
|
6 |
+
$("#menu-settings .wp-has-submenu").pointer({
|
7 |
+
content: CPTP_Settings_Pointer.content,
|
8 |
+
position: {"edge": "left", "align": "center"},
|
9 |
+
close: function () {
|
10 |
+
$.post('admin-ajax.php', {
|
11 |
+
action: 'dismiss-wp-pointer',
|
12 |
+
pointer: CPTP_Settings_Pointer.name
|
13 |
+
})
|
14 |
+
|
15 |
+
}
|
16 |
+
}).pointer("open");
|
17 |
+
}
|
18 |
+
|
19 |
+
})
|
20 |
+
|
21 |
+
})(jQuery);
|
custom-post-type-permalinks.php
CHANGED
@@ -5,7 +5,7 @@ Plugin URI: https://github.com/torounit/custom-post-type-permalinks
|
|
5 |
Description: Add post archives of custom post type and customizable permalinks.
|
6 |
Author: Toro_Unit
|
7 |
Author URI: https://torounit.com/
|
8 |
-
Version: 2.
|
9 |
Text Domain: custom-post-type-permalinks
|
10 |
License: GPL2 or later
|
11 |
Domain Path: /language/
|
@@ -17,7 +17,7 @@ Domain Path: /language/
|
|
17 |
* Custom Post Type Permalinks
|
18 |
*
|
19 |
* @package Custom_Post_Type_Permalinks
|
20 |
-
* @version 2.
|
21 |
*/
|
22 |
|
23 |
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: 2.1.1
|
9 |
Text Domain: custom-post-type-permalinks
|
10 |
License: GPL2 or later
|
11 |
Domain Path: /language/
|
17 |
* Custom Post Type Permalinks
|
18 |
*
|
19 |
* @package Custom_Post_Type_Permalinks
|
20 |
+
* @version 2.1.1
|
21 |
*/
|
22 |
|
23 |
define( 'CPTP_PLUGIN_FILE', __FILE__ );
|
readme.md
CHANGED
@@ -73,6 +73,11 @@ That's it. You can access the permalinks setting by going to *Settings -> Permal
|
|
73 |
|
74 |
## Changelog
|
75 |
|
|
|
|
|
|
|
|
|
|
|
76 |
### 2.0.2
|
77 |
|
78 |
* pointer html bug fix.
|
73 |
|
74 |
## Changelog
|
75 |
|
76 |
+
### 2.1.0
|
77 |
+
|
78 |
+
* Create rewrite rule on `registered_post_type` and `registered_taxonomy` action.
|
79 |
+
* Not create taxonomy rewrite rule when `rewrite` is `false`.
|
80 |
+
|
81 |
### 2.0.2
|
82 |
|
83 |
* pointer html bug fix.
|
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.3
|
6 |
Tested up to: 4.6
|
7 |
-
Stable tag: 2.
|
8 |
License: GPLv2 or Later
|
9 |
|
10 |
Edit the permalink of custom post type.
|
@@ -67,6 +67,11 @@ That's it. You can access the permalinks setting by going to *Settings -> Permal
|
|
67 |
|
68 |
== Changelog ==
|
69 |
|
|
|
|
|
|
|
|
|
|
|
70 |
= 2.0.2 =
|
71 |
|
72 |
* pointer html bug fix.
|
4 |
Tags: permalink,permalinks,custom post type,custom taxonomy,cms
|
5 |
Requires at least: 4.3
|
6 |
Tested up to: 4.6
|
7 |
+
Stable tag: 2.1.1
|
8 |
License: GPLv2 or Later
|
9 |
|
10 |
Edit the permalink of custom post type.
|
67 |
|
68 |
== Changelog ==
|
69 |
|
70 |
+
= 2.1.0 =
|
71 |
+
|
72 |
+
* Create rewrite rule on `registered_post_type` and `registered_taxonomy` action.
|
73 |
+
* Not create taxonomy rewrite rule when `rewrite` is `false`.
|
74 |
+
|
75 |
= 2.0.2 =
|
76 |
|
77 |
* pointer html bug fix.
|