Version Description
-
add_rewrite_rules
onwp_loaded
priority is changed 10 from 100. fix issue #53 - Replace wp_get_post_terms by get_the_terms. fix issue #55
- Fix bug register_uninstall_hook called twice on each page. fix issue #56
Download this release
Release Info
Developer | Toro_Unit |
Plugin | Custom Post Type Permalinks |
Version | 2.0.0 |
Comparing to | |
See all releases |
Code changes from version 1.5.4 to 2.0.0
- CPTP.php +42 -7
- CPTP/Module.php +15 -2
- CPTP/Module/Admin.php +18 -16
- CPTP/Module/FlushRules.php +15 -10
- CPTP/Module/GetArchives.php +19 -16
- CPTP/Module/Option.php +13 -25
- CPTP/Module/Permalink.php +22 -24
- CPTP/Module/Rewrite.php +38 -41
- CPTP/Module/Setting.php +4 -7
- CPTP/Util.php +7 -14
- codesniffer.ruleset.xml +20 -0
- custom-post-type-permalinks.php +13 -15
- readme.md +14 -1
- readme.txt +15 -3
CPTP.php
CHANGED
@@ -7,7 +7,6 @@
|
|
7 |
*
|
8 |
* @package Custom_Post_Type_Permalinks
|
9 |
* @since 0.9.4
|
10 |
-
*
|
11 |
* */
|
12 |
class CPTP {
|
13 |
|
@@ -18,15 +17,13 @@ class CPTP {
|
|
18 |
|
19 |
private function __construct() {
|
20 |
$this->load_modules();
|
21 |
-
$this->init();
|
22 |
}
|
23 |
|
24 |
/**
|
25 |
-
* load_modules
|
26 |
*
|
27 |
* Load CPTP_Modules.
|
28 |
-
* @since 0.9.5
|
29 |
*
|
|
|
30 |
*/
|
31 |
private function load_modules() {
|
32 |
$this->set_module( 'setting', new CPTP_Module_Setting() );
|
@@ -39,12 +36,19 @@ class CPTP {
|
|
39 |
|
40 |
do_action( 'CPTP_load_modules', $this );
|
41 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
42 |
foreach ( $this->modules as $module ) {
|
43 |
$module->init();
|
44 |
}
|
45 |
|
46 |
do_action( 'CPTP_registered_modules', $this );
|
47 |
-
|
48 |
}
|
49 |
|
50 |
/**
|
@@ -66,14 +70,15 @@ class CPTP {
|
|
66 |
* Fire Module::add_hook
|
67 |
*
|
68 |
* @since 0.9.5
|
69 |
-
*
|
70 |
*/
|
71 |
-
|
|
|
72 |
do_action( 'CPTP_init' );
|
73 |
}
|
74 |
|
75 |
/**
|
76 |
* Singleton
|
|
|
77 |
* @static
|
78 |
*/
|
79 |
public static function get_instance() {
|
@@ -86,4 +91,34 @@ class CPTP {
|
|
86 |
}
|
87 |
|
88 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
89 |
}
|
7 |
*
|
8 |
* @package Custom_Post_Type_Permalinks
|
9 |
* @since 0.9.4
|
|
|
10 |
* */
|
11 |
class CPTP {
|
12 |
|
17 |
|
18 |
private function __construct() {
|
19 |
$this->load_modules();
|
|
|
20 |
}
|
21 |
|
22 |
/**
|
|
|
23 |
*
|
24 |
* Load CPTP_Modules.
|
|
|
25 |
*
|
26 |
+
* @since 0.9.5
|
27 |
*/
|
28 |
private function load_modules() {
|
29 |
$this->set_module( 'setting', new CPTP_Module_Setting() );
|
36 |
|
37 |
do_action( 'CPTP_load_modules', $this );
|
38 |
|
39 |
+
}
|
40 |
+
|
41 |
+
/**
|
42 |
+
* initialize modules.
|
43 |
+
*
|
44 |
+
* @since 2.0.0
|
45 |
+
*/
|
46 |
+
private function init_modules() {
|
47 |
foreach ( $this->modules as $module ) {
|
48 |
$module->init();
|
49 |
}
|
50 |
|
51 |
do_action( 'CPTP_registered_modules', $this );
|
|
|
52 |
}
|
53 |
|
54 |
/**
|
70 |
* Fire Module::add_hook
|
71 |
*
|
72 |
* @since 0.9.5
|
|
|
73 |
*/
|
74 |
+
public function init() {
|
75 |
+
$this->init_modules();
|
76 |
do_action( 'CPTP_init' );
|
77 |
}
|
78 |
|
79 |
/**
|
80 |
* Singleton
|
81 |
+
*
|
82 |
* @static
|
83 |
*/
|
84 |
public static function get_instance() {
|
91 |
}
|
92 |
|
93 |
|
94 |
+
/**
|
95 |
+
*
|
96 |
+
* Activation Hooks
|
97 |
+
* This function will browse initialized modules and execute their activation_hook methods.
|
98 |
+
* It will also set the uninstall_hook to the cptp_uninstall function which behaves the same way as this one.
|
99 |
+
*
|
100 |
+
* @since 2.0.0
|
101 |
+
*/
|
102 |
+
public function activate() {
|
103 |
+
foreach ( $this->modules as $module ) {
|
104 |
+
$module->activation_hook();
|
105 |
+
}
|
106 |
+
|
107 |
+
register_uninstall_hook( CPTP_PLUGIN_FILE, array( __CLASS__, 'uninstall' ) );
|
108 |
+
}
|
109 |
+
|
110 |
+
/**
|
111 |
+
*
|
112 |
+
* Uninstall Hooks
|
113 |
+
* This function will browse initialized modules and execute their uninstall_hook methods.
|
114 |
+
*
|
115 |
+
* @since 2.0.0
|
116 |
+
*/
|
117 |
+
public static function uninstall() {
|
118 |
+
$cptp = CPTP::get_instance();
|
119 |
+
|
120 |
+
foreach ( $cptp->modules as $module ) {
|
121 |
+
$module->uninstall_hook();
|
122 |
+
}
|
123 |
+
}
|
124 |
}
|
CPTP/Module.php
CHANGED
@@ -1,6 +1,6 @@
|
|
1 |
<?php
|
2 |
|
3 |
-
|
4 |
|
5 |
final public function init() {
|
6 |
$this->register();
|
@@ -9,7 +9,20 @@ Abstract Class CPTP_Module {
|
|
9 |
public function register() {
|
10 |
add_action( 'CPTP_init', array( $this, 'add_hook' ) );
|
11 |
}
|
12 |
-
|
13 |
abstract function add_hook();
|
14 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
}
|
1 |
<?php
|
2 |
|
3 |
+
abstract class CPTP_Module {
|
4 |
|
5 |
final public function init() {
|
6 |
$this->register();
|
9 |
public function register() {
|
10 |
add_action( 'CPTP_init', array( $this, 'add_hook' ) );
|
11 |
}
|
12 |
+
|
13 |
abstract function add_hook();
|
14 |
|
15 |
+
/**
|
16 |
+
* uninstall hooks
|
17 |
+
*
|
18 |
+
* @static
|
19 |
+
*/
|
20 |
+
public static function uninstall_hook() {
|
21 |
+
}
|
22 |
+
|
23 |
+
/**
|
24 |
+
* fire on activate
|
25 |
+
*/
|
26 |
+
public function activation_hook() {
|
27 |
+
}
|
28 |
}
|
CPTP/Module/Admin.php
CHANGED
@@ -7,7 +7,6 @@
|
|
7 |
*
|
8 |
* @package Custom_Post_Type_Permalinks
|
9 |
* @since 0.9.4
|
10 |
-
*
|
11 |
* */
|
12 |
class CPTP_Module_Admin extends CPTP_Module {
|
13 |
|
@@ -21,8 +20,8 @@ class CPTP_Module_Admin extends CPTP_Module {
|
|
21 |
/**
|
22 |
*
|
23 |
* Setting Init
|
24 |
-
* @since 0.7
|
25 |
*
|
|
|
26 |
*/
|
27 |
public function settings_api_init() {
|
28 |
add_settings_section( 'cptp_setting_section',
|
@@ -73,15 +72,16 @@ class CPTP_Module_Admin extends CPTP_Module {
|
|
73 |
public function setting_section_callback_function() {
|
74 |
?>
|
75 |
<p><?php _e( 'Set the permalinks of your Custom Post Types.', 'custom-post-type-permalinks' ); ?><br/>
|
76 |
-
<?php _e(
|
77 |
<br/>
|
78 |
-
<?php _e( "<code>%\"custom_taxonomy_slug\"%</code> will replace the taxonomy's term.", 'custom-post-type-permalinks' );
|
|
|
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 |
-
|
85 |
}
|
86 |
|
87 |
public function setting_structure_callback_function( $option ) {
|
@@ -92,7 +92,6 @@ class CPTP_Module_Admin extends CPTP_Module {
|
|
92 |
$slug = $pt_object->rewrite['slug'];
|
93 |
$with_front = $pt_object->rewrite['with_front'];
|
94 |
|
95 |
-
|
96 |
$value = CPTP_Util::get_permalink_structure( $post_type );
|
97 |
|
98 |
$disabled = false;
|
@@ -111,10 +110,13 @@ class CPTP_Module_Admin extends CPTP_Module {
|
|
111 |
}
|
112 |
?>
|
113 |
<p>
|
114 |
-
<code><?php echo home_url() . ( $slug ? '/' : '' ) .
|
115 |
-
<input name="<?php echo esc_attr( $name )
|
|
|
|
|
116 |
</p>
|
117 |
-
<p>has_archive: <code><?php echo $pt_object->has_archive ? 'true' : 'false'
|
|
|
118 |
<?php
|
119 |
}
|
120 |
|
@@ -122,22 +124,22 @@ class CPTP_Module_Admin extends CPTP_Module {
|
|
122 |
public function setting_no_tax_structure_callback_function() {
|
123 |
echo '<input name="no_taxonomy_structure" id="no_taxonomy_structure" type="checkbox" value="1" class="code" ' . checked( false, get_option( 'no_taxonomy_structure' ), false ) . ' /> ';
|
124 |
$txt = __( "If you check this, the custom taxonomy's permalinks will be <code>%s/post_type/taxonomy/term</code>.", 'custom-post-type-permalinks' );
|
125 |
-
|
126 |
}
|
127 |
|
128 |
|
129 |
public function add_post_type_for_tax_callback_function() {
|
130 |
echo '<input name="add_post_type_for_tax" id="add_post_type_for_tax" type="checkbox" value="1" class="code" ' . checked( true, get_option( 'add_post_type_for_tax' ), false ) . ' /> ';
|
131 |
-
|
132 |
-
|
133 |
}
|
134 |
|
135 |
|
136 |
/**
|
137 |
*
|
138 |
* enqueue CSS and JS
|
139 |
-
* @since 0.8.5
|
140 |
*
|
|
|
141 |
*/
|
142 |
public function enqueue_css_js() {
|
143 |
wp_enqueue_style( 'wp-pointer' );
|
@@ -148,19 +150,19 @@ class CPTP_Module_Admin extends CPTP_Module {
|
|
148 |
/**
|
149 |
*
|
150 |
* add js for pointer
|
|
|
151 |
* @since 0.8.5
|
152 |
*/
|
153 |
public function pointer_js() {
|
154 |
if ( ! is_network_admin() ) {
|
155 |
$dismissed = explode( ',', get_user_meta( get_current_user_id(), 'dismissed_wp_pointers', true ) );
|
156 |
if ( false === array_search( 'cptp_pointer0871', $dismissed ) ) {
|
157 |
-
$content = __( "<h3>Custom Post Type Permalinks</h3><p>From <a href='options-permalink.php'>Permalinks</a>, set a custom permalink for each post type.</p>", 'custom-post-type-permalinks' );
|
158 |
?>
|
159 |
<script type="text/javascript">
|
160 |
jQuery(function ($) {
|
161 |
|
162 |
$("#menu-settings .wp-has-submenu").pointer({
|
163 |
-
content: "<?php
|
164 |
position: {"edge": "left", "align": "center"},
|
165 |
close: function () {
|
166 |
$.post('admin-ajax.php', {
|
@@ -172,7 +174,7 @@ class CPTP_Module_Admin extends CPTP_Module {
|
|
172 |
}).pointer("open");
|
173 |
});
|
174 |
</script>
|
175 |
-
|
176 |
}
|
177 |
}
|
178 |
}
|
7 |
*
|
8 |
* @package Custom_Post_Type_Permalinks
|
9 |
* @since 0.9.4
|
|
|
10 |
* */
|
11 |
class CPTP_Module_Admin extends CPTP_Module {
|
12 |
|
20 |
/**
|
21 |
*
|
22 |
* Setting Init
|
|
|
23 |
*
|
24 |
+
* @since 0.7
|
25 |
*/
|
26 |
public function settings_api_init() {
|
27 |
add_settings_section( 'cptp_setting_section',
|
72 |
public function setting_section_callback_function() {
|
73 |
?>
|
74 |
<p><?php _e( 'Set the permalinks of your Custom Post Types.', 'custom-post-type-permalinks' ); ?><br/>
|
75 |
+
<?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' ); ?>
|
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 |
|
87 |
public function setting_structure_callback_function( $option ) {
|
92 |
$slug = $pt_object->rewrite['slug'];
|
93 |
$with_front = $pt_object->rewrite['with_front'];
|
94 |
|
|
|
95 |
$value = CPTP_Util::get_permalink_structure( $post_type );
|
96 |
|
97 |
$disabled = false;
|
110 |
}
|
111 |
?>
|
112 |
<p>
|
113 |
+
<code><?php echo esc_html( home_url() . ( $slug ? '/' : '' ) . $slug ); ?></code>
|
114 |
+
<input name="<?php echo esc_attr( $name ); ?>" id="<?php echo esc_attr( $name ); ?>" type="text"
|
115 |
+
class="regular-text code "
|
116 |
+
value="<?php echo esc_attr( $value ); ?>" <?php disabled( $disabled, true, true ); ?> />
|
117 |
</p>
|
118 |
+
<p>has_archive: <code><?php echo esc_html( $pt_object->has_archive ? 'true' : 'false' ); ?></code> / with_front:
|
119 |
+
<code><?php echo esc_html( $pt_object->rewrite['with_front'] ? 'true' : 'false' ); ?></code></p>
|
120 |
<?php
|
121 |
}
|
122 |
|
124 |
public function setting_no_tax_structure_callback_function() {
|
125 |
echo '<input name="no_taxonomy_structure" id="no_taxonomy_structure" type="checkbox" value="1" class="code" ' . checked( false, get_option( 'no_taxonomy_structure' ), false ) . ' /> ';
|
126 |
$txt = __( "If you check this, the custom taxonomy's permalinks will be <code>%s/post_type/taxonomy/term</code>.", 'custom-post-type-permalinks' );
|
127 |
+
echo sprintf( $txt, esc_html( home_url() ) );
|
128 |
}
|
129 |
|
130 |
|
131 |
public function add_post_type_for_tax_callback_function() {
|
132 |
echo '<input name="add_post_type_for_tax" id="add_post_type_for_tax" type="checkbox" value="1" class="code" ' . checked( true, get_option( 'add_post_type_for_tax' ), false ) . ' /> ';
|
133 |
+
esc_html_e( 'Custom taxonomy archive also works as post type archive. ', 'custom-post-type-permalinks' );
|
134 |
+
esc_html_e( 'There are cases when the template to be loaded is changed.', 'custom-post-type-permalinks' );
|
135 |
}
|
136 |
|
137 |
|
138 |
/**
|
139 |
*
|
140 |
* enqueue CSS and JS
|
|
|
141 |
*
|
142 |
+
* @since 0.8.5
|
143 |
*/
|
144 |
public function enqueue_css_js() {
|
145 |
wp_enqueue_style( 'wp-pointer' );
|
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( 'cptp_pointer0871', $dismissed ) ) {
|
|
|
160 |
?>
|
161 |
<script type="text/javascript">
|
162 |
jQuery(function ($) {
|
163 |
|
164 |
$("#menu-settings .wp-has-submenu").pointer({
|
165 |
+
content: "<?php esc_html_e( "<h3>Custom Post Type Permalinks</h3><p>From <a href='options-permalink.php'>Permalinks</a>, set a custom permalink for each post type.</p>", 'custom-post-type-permalinks' );?>",
|
166 |
position: {"edge": "left", "align": "center"},
|
167 |
close: function () {
|
168 |
$.post('admin-ajax.php', {
|
174 |
}).pointer("open");
|
175 |
});
|
176 |
</script>
|
177 |
+
<?php
|
178 |
}
|
179 |
}
|
180 |
}
|
CPTP/Module/FlushRules.php
CHANGED
@@ -6,7 +6,6 @@
|
|
6 |
*
|
7 |
* @package Custom_Post_Type_Permalinks
|
8 |
* @since 0.9.4
|
9 |
-
*
|
10 |
* */
|
11 |
|
12 |
class CPTP_Module_FlushRules extends CPTP_Module {
|
@@ -17,9 +16,6 @@ class CPTP_Module_FlushRules extends CPTP_Module {
|
|
17 |
add_action( 'add_option_cptp_version', array( $this, 'update_rules' ) );
|
18 |
add_action( 'update_option_cptp_version', array( $this, 'update_rules' ), 20 );
|
19 |
add_action( 'wp_loaded', array( __CLASS__, 'dequeue_flush_rules' ), 200 );
|
20 |
-
|
21 |
-
register_activation_hook( CPTP_PLUGIN_FILE, array( __CLASS__, 'queue_flush_rules' ) );
|
22 |
-
register_uninstall_hook( CPTP_PLUGIN_FILE, array( __CLASS__, 'uninstall_hook' ) );
|
23 |
}
|
24 |
|
25 |
|
@@ -27,8 +23,8 @@ class CPTP_Module_FlushRules extends CPTP_Module {
|
|
27 |
/**
|
28 |
*
|
29 |
* Add hook flush_rules
|
30 |
-
* @since 0.7.9
|
31 |
*
|
|
|
32 |
*/
|
33 |
public function update_rules() {
|
34 |
|
@@ -43,11 +39,11 @@ class CPTP_Module_FlushRules extends CPTP_Module {
|
|
43 |
/**
|
44 |
*
|
45 |
* dequeue flush rules
|
46 |
-
* @since 0.9
|
47 |
*
|
|
|
48 |
*/
|
49 |
|
50 |
-
public static function dequeue_flush_rules
|
51 |
if ( get_option( 'queue_flush_rules' ) ) {
|
52 |
flush_rewrite_rules();
|
53 |
update_option( 'queue_flush_rules', 0 );
|
@@ -56,20 +52,29 @@ class CPTP_Module_FlushRules extends CPTP_Module {
|
|
56 |
}
|
57 |
|
58 |
|
59 |
-
|
60 |
/**
|
61 |
* Flush rules
|
62 |
*
|
63 |
* @since 0.7.9
|
64 |
-
*
|
65 |
*/
|
66 |
|
67 |
-
public static function queue_flush_rules(){
|
68 |
update_option( 'queue_flush_rules', 1 );
|
69 |
}
|
70 |
|
|
|
|
|
|
|
|
|
|
|
71 |
public static function uninstall_hook() {
|
72 |
delete_option( 'queue_flush_rules' );
|
73 |
}
|
74 |
|
|
|
|
|
|
|
|
|
|
|
|
|
75 |
}
|
6 |
*
|
7 |
* @package Custom_Post_Type_Permalinks
|
8 |
* @since 0.9.4
|
|
|
9 |
* */
|
10 |
|
11 |
class CPTP_Module_FlushRules extends CPTP_Module {
|
16 |
add_action( 'add_option_cptp_version', array( $this, 'update_rules' ) );
|
17 |
add_action( 'update_option_cptp_version', array( $this, 'update_rules' ), 20 );
|
18 |
add_action( 'wp_loaded', array( __CLASS__, 'dequeue_flush_rules' ), 200 );
|
|
|
|
|
|
|
19 |
}
|
20 |
|
21 |
|
23 |
/**
|
24 |
*
|
25 |
* Add hook flush_rules
|
|
|
26 |
*
|
27 |
+
* @since 0.7.9
|
28 |
*/
|
29 |
public function update_rules() {
|
30 |
|
39 |
/**
|
40 |
*
|
41 |
* dequeue flush rules
|
|
|
42 |
*
|
43 |
+
* @since 0.9
|
44 |
*/
|
45 |
|
46 |
+
public static function dequeue_flush_rules() {
|
47 |
if ( get_option( 'queue_flush_rules' ) ) {
|
48 |
flush_rewrite_rules();
|
49 |
update_option( 'queue_flush_rules', 0 );
|
52 |
}
|
53 |
|
54 |
|
|
|
55 |
/**
|
56 |
* Flush rules
|
57 |
*
|
58 |
* @since 0.7.9
|
|
|
59 |
*/
|
60 |
|
61 |
+
public static function queue_flush_rules() {
|
62 |
update_option( 'queue_flush_rules', 1 );
|
63 |
}
|
64 |
|
65 |
+
/**
|
66 |
+
* uninstall hooks
|
67 |
+
*
|
68 |
+
* @staitc
|
69 |
+
*/
|
70 |
public static function uninstall_hook() {
|
71 |
delete_option( 'queue_flush_rules' );
|
72 |
}
|
73 |
|
74 |
+
/**
|
75 |
+
* fire on activate
|
76 |
+
*/
|
77 |
+
public function activation_hook() {
|
78 |
+
CPTP_Module_FlushRules::queue_flush_rules();
|
79 |
+
}
|
80 |
}
|
CPTP/Module/GetArchives.php
CHANGED
@@ -7,7 +7,6 @@
|
|
7 |
*
|
8 |
* @package Custom_Post_Type_Permalinks
|
9 |
* @since 0.9.4
|
10 |
-
*
|
11 |
* */
|
12 |
|
13 |
class CPTP_Module_GetArchives extends CPTP_Module {
|
@@ -25,8 +24,8 @@ class CPTP_Module_GetArchives extends CPTP_Module {
|
|
25 |
*
|
26 |
* wp_get_archives fix for custom post
|
27 |
* Ex:wp_get_archives('&post_type='.get_query_var( 'post_type' ));
|
28 |
-
* @version 2.0
|
29 |
*
|
|
|
30 |
*/
|
31 |
|
32 |
public $get_archives_where_r;
|
@@ -38,7 +37,7 @@ class CPTP_Module_GetArchives extends CPTP_Module {
|
|
38 |
$where = str_replace( '\'post\'', '\'' . $r['post_type'] . '\'', $where );
|
39 |
}
|
40 |
|
41 |
-
if ( isset( $r['taxonomy'] ) && is_array( $r['taxonomy'] ) ){
|
42 |
global $wpdb;
|
43 |
$where = $where . " AND $wpdb->term_taxonomy.taxonomy = '".$r['taxonomy']['name']."' AND $wpdb->term_taxonomy.term_id = '".$r['taxonomy']['termid']."'";
|
44 |
}
|
@@ -48,15 +47,19 @@ class CPTP_Module_GetArchives extends CPTP_Module {
|
|
48 |
|
49 |
|
50 |
|
51 |
-
//function added by [steve]
|
52 |
/**
|
53 |
*
|
54 |
* get_archive_join
|
|
|
55 |
* @author Steve
|
56 |
* @since 0.8
|
57 |
* @version 1.0
|
58 |
*
|
|
|
|
|
59 |
*
|
|
|
60 |
*/
|
61 |
public function getarchives_join( $join, $r ) {
|
62 |
global $wpdb;
|
@@ -69,12 +72,15 @@ class CPTP_Module_GetArchives extends CPTP_Module {
|
|
69 |
}
|
70 |
|
71 |
|
72 |
-
|
73 |
/**
|
74 |
*
|
75 |
* get_arcihves_link
|
|
|
76 |
* @version 2.2 03/27/14
|
77 |
*
|
|
|
|
|
|
|
78 |
*/
|
79 |
public function get_archives_link( $link ) {
|
80 |
global $wp_rewrite;
|
@@ -83,35 +89,33 @@ class CPTP_Module_GetArchives extends CPTP_Module {
|
|
83 |
return $link;
|
84 |
}
|
85 |
|
86 |
-
if ( $this->get_archives_where_r['post_type']
|
87 |
return $link;
|
88 |
}
|
89 |
|
90 |
-
$c = isset( $this->get_archives_where_r['taxonomy'] ) && is_array( $this->get_archives_where_r['taxonomy'] ) ? $this->get_archives_where_r['taxonomy'] : ''; //[steve]
|
91 |
$t = $this->get_archives_where_r['post_type'];
|
92 |
|
93 |
-
$this->get_archives_where_r['post_type'] = isset($this->get_archives_where_r['post_type_slug']) ? $this->get_archives_where_r['post_type_slug'] : $t; // [steve] [*** bug fixing]
|
94 |
|
95 |
if ( isset( $this->get_archives_where_r['post_type'] ) and 'postbypost' != $this->get_archives_where_r['type'] ) {
|
96 |
$blog_url = rtrim( home_url() ,'/' );
|
97 |
|
98 |
-
//remove front
|
99 |
$front = substr( $wp_rewrite->front, 1 );
|
100 |
$link = str_replace( $front, '', $link );
|
101 |
|
102 |
$blog_url = preg_replace( '/https?:\/\//', '', $blog_url );
|
103 |
-
$ret_link = str_replace( $blog_url, $blog_url.'
|
104 |
|
105 |
$post_type = get_post_type_object( $this->get_archives_where_r['post_type'] );
|
106 |
if ( empty( $c ) ) { // [steve]
|
107 |
if ( isset( $post_type->rewrite['slug'] ) ) {
|
108 |
$link_dir = $post_type->rewrite['slug'];
|
109 |
-
}
|
110 |
-
else {
|
111 |
$link_dir = $this->get_archives_where_r['post_type'];
|
112 |
}
|
113 |
-
}
|
114 |
-
else { // [steve]
|
115 |
$c['name'] = ( 'category' == $c['name'] && get_option( 'category_base' ) ) ? get_option( 'category_base' ) : $c['name'];
|
116 |
$link_dir = $post_type->rewrite['slug'].'/'.$c['name'].'/'.$c['termslug'];
|
117 |
}
|
@@ -125,12 +129,11 @@ class CPTP_Module_GetArchives extends CPTP_Module {
|
|
125 |
}
|
126 |
|
127 |
$ret_link = str_replace( '%link_dir%', $link_dir, $ret_link );
|
128 |
-
}else {
|
129 |
$ret_link = $link;
|
130 |
}
|
131 |
$this->get_archives_where_r['post_type'] = $t; // [steve] reverting post_type to previous value
|
132 |
|
133 |
return $ret_link;
|
134 |
}
|
135 |
-
|
136 |
}
|
7 |
*
|
8 |
* @package Custom_Post_Type_Permalinks
|
9 |
* @since 0.9.4
|
|
|
10 |
* */
|
11 |
|
12 |
class CPTP_Module_GetArchives extends CPTP_Module {
|
24 |
*
|
25 |
* wp_get_archives fix for custom post
|
26 |
* Ex:wp_get_archives('&post_type='.get_query_var( 'post_type' ));
|
|
|
27 |
*
|
28 |
+
* @version 2.0
|
29 |
*/
|
30 |
|
31 |
public $get_archives_where_r;
|
37 |
$where = str_replace( '\'post\'', '\'' . $r['post_type'] . '\'', $where );
|
38 |
}
|
39 |
|
40 |
+
if ( isset( $r['taxonomy'] ) && is_array( $r['taxonomy'] ) ) {
|
41 |
global $wpdb;
|
42 |
$where = $where . " AND $wpdb->term_taxonomy.taxonomy = '".$r['taxonomy']['name']."' AND $wpdb->term_taxonomy.term_id = '".$r['taxonomy']['termid']."'";
|
43 |
}
|
47 |
|
48 |
|
49 |
|
50 |
+
// function added by [steve]
|
51 |
/**
|
52 |
*
|
53 |
* get_archive_join
|
54 |
+
*
|
55 |
* @author Steve
|
56 |
* @since 0.8
|
57 |
* @version 1.0
|
58 |
*
|
59 |
+
* @param string $join
|
60 |
+
* @param array $r
|
61 |
*
|
62 |
+
* @return string
|
63 |
*/
|
64 |
public function getarchives_join( $join, $r ) {
|
65 |
global $wpdb;
|
72 |
}
|
73 |
|
74 |
|
|
|
75 |
/**
|
76 |
*
|
77 |
* get_arcihves_link
|
78 |
+
*
|
79 |
* @version 2.2 03/27/14
|
80 |
*
|
81 |
+
* @param string $link
|
82 |
+
*
|
83 |
+
* @return string
|
84 |
*/
|
85 |
public function get_archives_link( $link ) {
|
86 |
global $wp_rewrite;
|
89 |
return $link;
|
90 |
}
|
91 |
|
92 |
+
if ( 'post' == $this->get_archives_where_r['post_type'] ) {
|
93 |
return $link;
|
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]
|
97 |
$t = $this->get_archives_where_r['post_type'];
|
98 |
|
99 |
+
$this->get_archives_where_r['post_type'] = isset( $this->get_archives_where_r['post_type_slug'] ) ? $this->get_archives_where_r['post_type_slug'] : $t; // [steve] [*** bug fixing]
|
100 |
|
101 |
if ( isset( $this->get_archives_where_r['post_type'] ) and 'postbypost' != $this->get_archives_where_r['type'] ) {
|
102 |
$blog_url = rtrim( home_url() ,'/' );
|
103 |
|
104 |
+
// remove front
|
105 |
$front = substr( $wp_rewrite->front, 1 );
|
106 |
$link = str_replace( $front, '', $link );
|
107 |
|
108 |
$blog_url = preg_replace( '/https?:\/\//', '', $blog_url );
|
109 |
+
$ret_link = str_replace( $blog_url, $blog_url.'/%link_dir%', $link );
|
110 |
|
111 |
$post_type = get_post_type_object( $this->get_archives_where_r['post_type'] );
|
112 |
if ( empty( $c ) ) { // [steve]
|
113 |
if ( isset( $post_type->rewrite['slug'] ) ) {
|
114 |
$link_dir = $post_type->rewrite['slug'];
|
115 |
+
} else {
|
|
|
116 |
$link_dir = $this->get_archives_where_r['post_type'];
|
117 |
}
|
118 |
+
} else { // [steve]
|
|
|
119 |
$c['name'] = ( 'category' == $c['name'] && get_option( 'category_base' ) ) ? get_option( 'category_base' ) : $c['name'];
|
120 |
$link_dir = $post_type->rewrite['slug'].'/'.$c['name'].'/'.$c['termslug'];
|
121 |
}
|
129 |
}
|
130 |
|
131 |
$ret_link = str_replace( '%link_dir%', $link_dir, $ret_link );
|
132 |
+
} else {
|
133 |
$ret_link = $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 |
}
|
CPTP/Module/Option.php
CHANGED
@@ -9,13 +9,11 @@
|
|
9 |
*
|
10 |
* @package Custom_Post_Type_Permalinks
|
11 |
* @since 0.9.6
|
12 |
-
*
|
13 |
* */
|
14 |
class CPTP_Module_Option extends CPTP_Module {
|
15 |
|
16 |
public function add_hook() {
|
17 |
add_action( 'admin_init', array( $this, 'save_options' ), 30 );
|
18 |
-
register_uninstall_hook( CPTP_PLUGIN_FILE, array( __CLASS__, 'uninstall_hook' ) );
|
19 |
}
|
20 |
|
21 |
public function save_options() {
|
@@ -24,40 +22,27 @@ class CPTP_Module_Option extends CPTP_Module {
|
|
24 |
return false;
|
25 |
}
|
26 |
|
27 |
-
if (
|
28 |
-
return false;
|
29 |
-
}
|
30 |
-
|
31 |
-
if ( false === strpos( $_POST['_wp_http_referer'], 'options-permalink.php' ) ) {
|
32 |
-
return false;
|
33 |
-
}
|
34 |
-
|
35 |
-
if ( empty ( $_POST['_wpnonce'] ) ) {
|
36 |
-
return false;
|
37 |
-
}
|
38 |
-
$nonce = $_POST['_wpnonce'];
|
39 |
-
|
40 |
-
if ( ! wp_verify_nonce( $nonce, 'update-permalink' ) ) {
|
41 |
return false;
|
42 |
}
|
43 |
|
44 |
$post_types = CPTP_Util::get_post_types();
|
45 |
|
46 |
-
foreach ( $post_types as $post_type ):
|
47 |
|
48 |
-
$structure = trim( esc_attr( $_POST[ $post_type . '_structure' ] ) )
|
49 |
|
50 |
-
|
51 |
if ( ! $structure ) {
|
52 |
$structure = CPTP_DEFAULT_PERMALINK;
|
53 |
}
|
54 |
|
55 |
-
$structure = str_replace( '//', '/', '/' . $structure )
|
56 |
-
|
57 |
$lastString = substr( trim( esc_attr( $_POST['permalink_structure'] ) ), - 1 );
|
58 |
$structure = rtrim( $structure, '/' );
|
59 |
|
60 |
-
if (
|
61 |
$structure = $structure . '/';
|
62 |
}
|
63 |
|
@@ -69,6 +54,11 @@ class CPTP_Module_Option extends CPTP_Module {
|
|
69 |
|
70 |
}
|
71 |
|
|
|
|
|
|
|
|
|
|
|
72 |
public static function uninstall_hook() {
|
73 |
foreach ( CPTP_Util::get_post_types() as $post_type ) {
|
74 |
delete_option( $post_type . '_structure' );
|
@@ -76,6 +66,4 @@ class CPTP_Module_Option extends CPTP_Module {
|
|
76 |
|
77 |
delete_option( 'no_taxonomy_structure' );
|
78 |
}
|
79 |
-
|
80 |
-
|
81 |
-
}
|
9 |
*
|
10 |
* @package Custom_Post_Type_Permalinks
|
11 |
* @since 0.9.6
|
|
|
12 |
* */
|
13 |
class CPTP_Module_Option extends CPTP_Module {
|
14 |
|
15 |
public function add_hook() {
|
16 |
add_action( 'admin_init', array( $this, 'save_options' ), 30 );
|
|
|
17 |
}
|
18 |
|
19 |
public function save_options() {
|
22 |
return false;
|
23 |
}
|
24 |
|
25 |
+
if ( ! check_admin_referer( 'update-permalink' ) ) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
26 |
return false;
|
27 |
}
|
28 |
|
29 |
$post_types = CPTP_Util::get_post_types();
|
30 |
|
31 |
+
foreach ( $post_types as $post_type ) :
|
32 |
|
33 |
+
$structure = trim( esc_attr( $_POST[ $post_type . '_structure' ] ) );// get setting
|
34 |
|
35 |
+
// default permalink structure
|
36 |
if ( ! $structure ) {
|
37 |
$structure = CPTP_DEFAULT_PERMALINK;
|
38 |
}
|
39 |
|
40 |
+
$structure = str_replace( '//', '/', '/' . $structure );// first "/"
|
41 |
+
// last "/"
|
42 |
$lastString = substr( trim( esc_attr( $_POST['permalink_structure'] ) ), - 1 );
|
43 |
$structure = rtrim( $structure, '/' );
|
44 |
|
45 |
+
if ( '/' == $lastString ) {
|
46 |
$structure = $structure . '/';
|
47 |
}
|
48 |
|
54 |
|
55 |
}
|
56 |
|
57 |
+
/**
|
58 |
+
* fire on uninstall. delete options.
|
59 |
+
*
|
60 |
+
* @static
|
61 |
+
*/
|
62 |
public static function uninstall_hook() {
|
63 |
foreach ( CPTP_Util::get_post_types() as $post_type ) {
|
64 |
delete_option( $post_type . '_structure' );
|
66 |
|
67 |
delete_option( 'no_taxonomy_structure' );
|
68 |
}
|
69 |
+
}
|
|
|
|
CPTP/Module/Permalink.php
CHANGED
@@ -6,9 +6,9 @@
|
|
6 |
* CPTP_Permalink
|
7 |
*
|
8 |
* Override Permalinks
|
|
|
9 |
* @package Custom_Post_Type_Permalinks
|
10 |
* @since 0.9.4
|
11 |
-
*
|
12 |
* */
|
13 |
class CPTP_Module_Permalink extends CPTP_Module {
|
14 |
|
@@ -46,8 +46,8 @@ class CPTP_Module_Permalink extends CPTP_Module {
|
|
46 |
* Fix permalinks output.
|
47 |
*
|
48 |
* @param String $post_link
|
49 |
-
* @param
|
50 |
-
* @param String $leavename
|
51 |
*
|
52 |
* @version 2.0
|
53 |
*
|
@@ -65,7 +65,7 @@ class CPTP_Module_Permalink extends CPTP_Module {
|
|
65 |
'draft',
|
66 |
'pending',
|
67 |
'auto-draft',
|
68 |
-
|
69 |
if ( $draft_or_pending and ! $leavename ) {
|
70 |
return $post_link;
|
71 |
}
|
@@ -77,7 +77,7 @@ class CPTP_Module_Permalink extends CPTP_Module {
|
|
77 |
$permalink = str_replace( '%post_id%', $post->ID, $permalink );
|
78 |
$permalink = str_replace( '%' . $post_type . '_slug%', $pt_object->rewrite['slug'], $permalink );
|
79 |
|
80 |
-
|
81 |
$parentsDirs = '';
|
82 |
if ( $pt_object->hierarchical ) {
|
83 |
if ( ! $leavename ) {
|
@@ -95,8 +95,7 @@ class CPTP_Module_Permalink extends CPTP_Module {
|
|
95 |
$permalink = str_replace( '%' . $post_type . '%', $post->post_name, $permalink );
|
96 |
}
|
97 |
|
98 |
-
|
99 |
-
//画像の編集ページでのリンク
|
100 |
if ( isset( $_GET['post'] ) && $_GET['post'] != $post->ID ) {
|
101 |
$parent_structure = trim( CPTP_Util::get_permalink_structure( $post->post_type ), '/' );
|
102 |
$parent_dirs = explode( '/', $parent_structure );
|
@@ -118,7 +117,7 @@ class CPTP_Module_Permalink extends CPTP_Module {
|
|
118 |
$search = $search + $replace_tag['search'];
|
119 |
$replace = $replace + $replace_tag['replace'];
|
120 |
|
121 |
-
//from get_permalink.
|
122 |
$category = '';
|
123 |
if ( false !== strpos( $permalink, '%category%' ) ) {
|
124 |
$categories = get_the_category( $post->ID );
|
@@ -179,7 +178,7 @@ class CPTP_Module_Permalink extends CPTP_Module {
|
|
179 |
*
|
180 |
* create %tax% -> term
|
181 |
*
|
182 |
-
* @param int
|
183 |
* @param string $permalink
|
184 |
*
|
185 |
* @return array
|
@@ -190,16 +189,15 @@ class CPTP_Module_Permalink extends CPTP_Module {
|
|
190 |
|
191 |
$taxonomies = CPTP_Util::get_taxonomies( true );
|
192 |
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
foreach ( $taxonomies as $taxonomy => $objects ) {
|
197 |
|
198 |
if ( false !== strpos( $permalink, '%' . $taxonomy . '%' ) ) {
|
199 |
-
$terms =
|
200 |
|
201 |
if ( $terms and ! is_wp_error( $terms ) ) {
|
202 |
-
$parents = array_map( array( __CLASS__, 'get_term_parent' ), $terms );
|
203 |
$newTerms = array();
|
204 |
foreach ( $terms as $key => $term ) {
|
205 |
if ( ! in_array( $term->term_id, $parents ) ) {
|
@@ -207,8 +205,8 @@ class CPTP_Module_Permalink extends CPTP_Module {
|
|
207 |
}
|
208 |
}
|
209 |
|
210 |
-
|
211 |
-
$term_obj = reset( $newTerms );
|
212 |
$term_slug = $term_obj->slug;
|
213 |
|
214 |
if ( isset( $term_obj->parent ) and 0 != $term_obj->parent ) {
|
@@ -249,12 +247,12 @@ class CPTP_Module_Permalink extends CPTP_Module {
|
|
249 |
* @since 0.8.2
|
250 |
*
|
251 |
* @param string $link
|
252 |
-
* @param int
|
253 |
*
|
254 |
* @return string
|
255 |
*/
|
256 |
|
257 |
-
public function attachment_link( $link, $
|
258 |
/** @var WP_Rewrite $wp_rewrite */
|
259 |
global $wp_rewrite;
|
260 |
|
@@ -262,13 +260,13 @@ class CPTP_Module_Permalink extends CPTP_Module {
|
|
262 |
return $link;
|
263 |
}
|
264 |
|
265 |
-
$post = get_post( $
|
266 |
if ( ! $post->post_parent ) {
|
267 |
return $link;
|
268 |
}
|
269 |
|
270 |
$post_parent = get_post( $post->post_parent );
|
271 |
-
if ( ! $post_parent) {
|
272 |
return $link;
|
273 |
}
|
274 |
$permalink = CPTP_Util::get_permalink_structure( $post_parent->post_type );
|
@@ -286,6 +284,7 @@ class CPTP_Module_Permalink extends CPTP_Module {
|
|
286 |
/**
|
287 |
*
|
288 |
* Fix taxonomy link outputs.
|
|
|
289 |
* @since 0.6
|
290 |
* @version 1.0
|
291 |
*
|
@@ -325,11 +324,11 @@ class CPTP_Module_Permalink extends CPTP_Module {
|
|
325 |
}
|
326 |
|
327 |
$front = substr( $wp_rewrite->front, 1 );
|
328 |
-
$termlink = str_replace( $front, '', $termlink );//remove front.
|
329 |
|
330 |
$post_type_obj = get_post_type_object( $post_type );
|
331 |
|
332 |
-
if( empty( $post_type_obj ) ) {
|
333 |
return $termlink;
|
334 |
}
|
335 |
|
@@ -340,7 +339,7 @@ class CPTP_Module_Permalink extends CPTP_Module {
|
|
340 |
$slug = $front . $slug;
|
341 |
}
|
342 |
|
343 |
-
if( !empty( $slug )) {
|
344 |
$termlink = str_replace( $wp_home, $wp_home . '/' . $slug, $termlink );
|
345 |
}
|
346 |
|
@@ -350,5 +349,4 @@ class CPTP_Module_Permalink extends CPTP_Module {
|
|
350 |
|
351 |
return $termlink;
|
352 |
}
|
353 |
-
|
354 |
}
|
6 |
* CPTP_Permalink
|
7 |
*
|
8 |
* Override Permalinks
|
9 |
+
*
|
10 |
* @package Custom_Post_Type_Permalinks
|
11 |
* @since 0.9.4
|
|
|
12 |
* */
|
13 |
class CPTP_Module_Permalink extends CPTP_Module {
|
14 |
|
46 |
* Fix permalinks output.
|
47 |
*
|
48 |
* @param String $post_link
|
49 |
+
* @param WP_Post $post
|
50 |
+
* @param String $leavename for edit.php
|
51 |
*
|
52 |
* @version 2.0
|
53 |
*
|
65 |
'draft',
|
66 |
'pending',
|
67 |
'auto-draft',
|
68 |
+
) );
|
69 |
if ( $draft_or_pending and ! $leavename ) {
|
70 |
return $post_link;
|
71 |
}
|
77 |
$permalink = str_replace( '%post_id%', $post->ID, $permalink );
|
78 |
$permalink = str_replace( '%' . $post_type . '_slug%', $pt_object->rewrite['slug'], $permalink );
|
79 |
|
80 |
+
// has parent.
|
81 |
$parentsDirs = '';
|
82 |
if ( $pt_object->hierarchical ) {
|
83 |
if ( ! $leavename ) {
|
95 |
$permalink = str_replace( '%' . $post_type . '%', $post->post_name, $permalink );
|
96 |
}
|
97 |
|
98 |
+
// %post_id%/attachment/%attachement_name%;
|
|
|
99 |
if ( isset( $_GET['post'] ) && $_GET['post'] != $post->ID ) {
|
100 |
$parent_structure = trim( CPTP_Util::get_permalink_structure( $post->post_type ), '/' );
|
101 |
$parent_dirs = explode( '/', $parent_structure );
|
117 |
$search = $search + $replace_tag['search'];
|
118 |
$replace = $replace + $replace_tag['replace'];
|
119 |
|
120 |
+
// from get_permalink.
|
121 |
$category = '';
|
122 |
if ( false !== strpos( $permalink, '%category%' ) ) {
|
123 |
$categories = get_the_category( $post->ID );
|
178 |
*
|
179 |
* create %tax% -> term
|
180 |
*
|
181 |
+
* @param int $post_id
|
182 |
* @param string $permalink
|
183 |
*
|
184 |
* @return array
|
189 |
|
190 |
$taxonomies = CPTP_Util::get_taxonomies( true );
|
191 |
|
192 |
+
// %taxnomomy% -> parent/child
|
193 |
+
// 運用でケアすべきかも。
|
|
|
194 |
foreach ( $taxonomies as $taxonomy => $objects ) {
|
195 |
|
196 |
if ( false !== strpos( $permalink, '%' . $taxonomy . '%' ) ) {
|
197 |
+
$terms = get_the_terms( $post_id, $taxonomy );
|
198 |
|
199 |
if ( $terms and ! is_wp_error( $terms ) ) {
|
200 |
+
$parents = array_map( array( __CLASS__, 'get_term_parent' ), $terms ); // 親の一覧
|
201 |
$newTerms = array();
|
202 |
foreach ( $terms as $key => $term ) {
|
203 |
if ( ! in_array( $term->term_id, $parents ) ) {
|
205 |
}
|
206 |
}
|
207 |
|
208 |
+
// このブロックだけで良いはず。
|
209 |
+
$term_obj = reset( $newTerms ); // 最初のOBjectのみを対象。
|
210 |
$term_slug = $term_obj->slug;
|
211 |
|
212 |
if ( isset( $term_obj->parent ) and 0 != $term_obj->parent ) {
|
247 |
* @since 0.8.2
|
248 |
*
|
249 |
* @param string $link
|
250 |
+
* @param int $post_id
|
251 |
*
|
252 |
* @return string
|
253 |
*/
|
254 |
|
255 |
+
public function attachment_link( $link, $post_id ) {
|
256 |
/** @var WP_Rewrite $wp_rewrite */
|
257 |
global $wp_rewrite;
|
258 |
|
260 |
return $link;
|
261 |
}
|
262 |
|
263 |
+
$post = get_post( $post_id );
|
264 |
if ( ! $post->post_parent ) {
|
265 |
return $link;
|
266 |
}
|
267 |
|
268 |
$post_parent = get_post( $post->post_parent );
|
269 |
+
if ( ! $post_parent ) {
|
270 |
return $link;
|
271 |
}
|
272 |
$permalink = CPTP_Util::get_permalink_structure( $post_parent->post_type );
|
284 |
/**
|
285 |
*
|
286 |
* Fix taxonomy link outputs.
|
287 |
+
*
|
288 |
* @since 0.6
|
289 |
* @version 1.0
|
290 |
*
|
324 |
}
|
325 |
|
326 |
$front = substr( $wp_rewrite->front, 1 );
|
327 |
+
$termlink = str_replace( $front, '', $termlink );// remove front.
|
328 |
|
329 |
$post_type_obj = get_post_type_object( $post_type );
|
330 |
|
331 |
+
if ( empty( $post_type_obj ) ) {
|
332 |
return $termlink;
|
333 |
}
|
334 |
|
339 |
$slug = $front . $slug;
|
340 |
}
|
341 |
|
342 |
+
if ( ! empty( $slug ) ) {
|
343 |
$termlink = str_replace( $wp_home, $wp_home . '/' . $slug, $termlink );
|
344 |
}
|
345 |
|
349 |
|
350 |
return $termlink;
|
351 |
}
|
|
|
352 |
}
|
CPTP/Module/Rewrite.php
CHANGED
@@ -8,7 +8,6 @@
|
|
8 |
* @package Custom_Post_Type_Permalinks
|
9 |
* @version 1.0.3
|
10 |
* @since 0.9.4
|
11 |
-
*
|
12 |
* */
|
13 |
class CPTP_Module_Rewrite extends CPTP_Module {
|
14 |
|
@@ -23,7 +22,7 @@ class CPTP_Module_Rewrite extends CPTP_Module {
|
|
23 |
add_action( 'registered_post_type', array( $this, 'registered_post_type' ), 10, 2 );
|
24 |
add_action( 'registered_taxonomy', array( $this, 'registered_taxonomy' ), 10, 3 );
|
25 |
|
26 |
-
add_action( 'wp_loaded', array( $this, 'add_rewrite_rules' ),
|
27 |
}
|
28 |
|
29 |
|
@@ -58,9 +57,9 @@ class CPTP_Module_Rewrite extends CPTP_Module {
|
|
58 |
*
|
59 |
* queue taxonomy rewrite.
|
60 |
*
|
61 |
-
* @param string
|
62 |
* @param array|string $object_type Object type or array of object types.
|
63 |
-
* @param array
|
64 |
*/
|
65 |
public function registered_taxonomy( $taxonomy, $object_type, $args ) {
|
66 |
$this->taxonomy_args[] = func_get_args();
|
@@ -71,12 +70,12 @@ class CPTP_Module_Rewrite extends CPTP_Module {
|
|
71 |
*
|
72 |
* register_post_type_rules
|
73 |
* ** add rewrite tag for Custom Post Type.
|
|
|
74 |
* @version 1.1
|
75 |
* @since 0.9
|
76 |
*
|
77 |
* @param string $post_type
|
78 |
* @param object $args
|
79 |
-
*
|
80 |
*/
|
81 |
|
82 |
public function register_post_type_rules( $post_type, $args ) {
|
@@ -99,7 +98,7 @@ class CPTP_Module_Rewrite extends CPTP_Module {
|
|
99 |
add_rewrite_tag( '%' . $post_type . '_slug%', '(' . $args->rewrite['slug'] . ')', 'post_type=' . $post_type . '&slug=' );
|
100 |
|
101 |
$taxonomies = CPTP_Util::get_taxonomies( true );
|
102 |
-
foreach ( $taxonomies as $taxonomy => $objects ):
|
103 |
$wp_rewrite->add_rewrite_tag( "%$taxonomy%", '(.+?)', "$taxonomy=" );
|
104 |
endforeach;
|
105 |
|
@@ -135,10 +134,10 @@ class CPTP_Module_Rewrite extends CPTP_Module {
|
|
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(
|
142 |
$category_base = 'category';
|
143 |
}
|
144 |
|
@@ -160,9 +159,9 @@ class CPTP_Module_Rewrite extends CPTP_Module {
|
|
160 |
*
|
161 |
* register_taxonomy_rules
|
162 |
*
|
163 |
-
* @param string
|
164 |
* @param array|string $object_type
|
165 |
-
* @param array
|
166 |
*
|
167 |
* @return void
|
168 |
*/
|
@@ -178,7 +177,7 @@ class CPTP_Module_Rewrite extends CPTP_Module {
|
|
178 |
global $wp_rewrite;
|
179 |
|
180 |
$post_types = $args['object_type'];
|
181 |
-
foreach ( $post_types as $post_type ):
|
182 |
$post_type_obj = get_post_type_object( $post_type );
|
183 |
if ( ! empty( $post_type_obj->rewrite['slug'] ) ) {
|
184 |
$slug = $post_type_obj->rewrite['slug'];
|
@@ -190,7 +189,6 @@ class CPTP_Module_Rewrite extends CPTP_Module {
|
|
190 |
$slug = $post_type_obj->has_archive;
|
191 |
};
|
192 |
|
193 |
-
|
194 |
if ( ! empty( $post_type_obj->rewrite['with_front'] ) ) {
|
195 |
$slug = substr( $wp_rewrite->front, 1 ) . $slug;
|
196 |
}
|
@@ -206,60 +204,59 @@ class CPTP_Module_Rewrite extends CPTP_Module {
|
|
206 |
$taxonomy_slug = $taxonomy;
|
207 |
}
|
208 |
// [Xiphe] stop
|
209 |
-
|
210 |
$taxonomy_key = $taxonomy;
|
211 |
}
|
212 |
|
213 |
$rules = array(
|
214 |
-
//feed.
|
215 |
array(
|
216 |
-
|
217 |
-
|
218 |
),
|
219 |
array(
|
220 |
-
|
221 |
-
|
222 |
),
|
223 |
-
//year
|
224 |
array(
|
225 |
-
|
226 |
-
|
227 |
),
|
228 |
array(
|
229 |
-
|
230 |
-
|
231 |
),
|
232 |
-
//monthnum
|
233 |
array(
|
234 |
-
|
235 |
-
|
236 |
),
|
237 |
array(
|
238 |
-
|
239 |
-
|
240 |
),
|
241 |
-
//day
|
242 |
array(
|
243 |
-
|
244 |
-
|
245 |
),
|
246 |
array(
|
247 |
-
|
248 |
-
|
249 |
),
|
250 |
-
//paging
|
251 |
array(
|
252 |
-
|
253 |
-
|
254 |
),
|
255 |
-
//tax archive.
|
256 |
array(
|
257 |
-
|
258 |
-
|
259 |
),
|
260 |
);
|
261 |
|
262 |
-
//no post_type slug.
|
263 |
foreach ( $rules as $rule ) {
|
264 |
$regex = sprintf( $rule['regex'], "{$taxonomy_slug}" );
|
265 |
$redirect = $rule['redirect'];
|
@@ -272,7 +269,6 @@ class CPTP_Module_Rewrite extends CPTP_Module {
|
|
272 |
$redirect = $rule['redirect'] . "&post_type={$post_type}";
|
273 |
add_rewrite_rule( $regex, $redirect, 'top' );
|
274 |
}
|
275 |
-
|
276 |
} else {
|
277 |
foreach ( $rules as $rule ) {
|
278 |
$regex = sprintf( $rule['regex'], "{$slug}/{$taxonomy_slug}" );
|
@@ -290,6 +286,7 @@ class CPTP_Module_Rewrite extends CPTP_Module {
|
|
290 |
/**
|
291 |
*
|
292 |
* Fix taxonomy = parent/child => taxonomy => child
|
|
|
293 |
* @since 0.9.3
|
294 |
*
|
295 |
* @param WP $obj
|
8 |
* @package Custom_Post_Type_Permalinks
|
9 |
* @version 1.0.3
|
10 |
* @since 0.9.4
|
|
|
11 |
* */
|
12 |
class CPTP_Module_Rewrite extends CPTP_Module {
|
13 |
|
22 |
add_action( 'registered_post_type', array( $this, 'registered_post_type' ), 10, 2 );
|
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 |
|
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();
|
70 |
*
|
71 |
* register_post_type_rules
|
72 |
* ** add rewrite tag for Custom Post Type.
|
73 |
+
*
|
74 |
* @version 1.1
|
75 |
* @since 0.9
|
76 |
*
|
77 |
* @param string $post_type
|
78 |
* @param object $args
|
|
|
79 |
*/
|
80 |
|
81 |
public function register_post_type_rules( $post_type, $args ) {
|
98 |
add_rewrite_tag( '%' . $post_type . '_slug%', '(' . $args->rewrite['slug'] . ')', 'post_type=' . $post_type . '&slug=' );
|
99 |
|
100 |
$taxonomies = CPTP_Util::get_taxonomies( true );
|
101 |
+
foreach ( $taxonomies as $taxonomy => $objects ) :
|
102 |
$wp_rewrite->add_rewrite_tag( "%$taxonomy%", '(.+?)', "$taxonomy=" );
|
103 |
endforeach;
|
104 |
|
134 |
add_rewrite_rule( $slug . '/author/([^/]+)/page/?([0-9]{1,})/?$', 'index.php?author_name=$matches[1]&paged=$matches[2]&post_type=' . $post_type, 'top' );
|
135 |
add_rewrite_rule( $slug . '/author/([^/]+)/?$', 'index.php?author_name=$matches[1]&post_type=' . $post_type, 'top' );
|
136 |
|
137 |
+
if ( in_array( 'category', $args->taxonomies ) ) {
|
138 |
|
139 |
$category_base = get_option( 'category_base' );
|
140 |
+
if ( ! $category_base ) {
|
141 |
$category_base = 'category';
|
142 |
}
|
143 |
|
159 |
*
|
160 |
* register_taxonomy_rules
|
161 |
*
|
162 |
+
* @param string $taxonomy
|
163 |
* @param array|string $object_type
|
164 |
+
* @param array $args
|
165 |
*
|
166 |
* @return void
|
167 |
*/
|
177 |
global $wp_rewrite;
|
178 |
|
179 |
$post_types = $args['object_type'];
|
180 |
+
foreach ( $post_types as $post_type ) :
|
181 |
$post_type_obj = get_post_type_object( $post_type );
|
182 |
if ( ! empty( $post_type_obj->rewrite['slug'] ) ) {
|
183 |
$slug = $post_type_obj->rewrite['slug'];
|
189 |
$slug = $post_type_obj->has_archive;
|
190 |
};
|
191 |
|
|
|
192 |
if ( ! empty( $post_type_obj->rewrite['with_front'] ) ) {
|
193 |
$slug = substr( $wp_rewrite->front, 1 ) . $slug;
|
194 |
}
|
204 |
$taxonomy_slug = $taxonomy;
|
205 |
}
|
206 |
// [Xiphe] stop
|
|
|
207 |
$taxonomy_key = $taxonomy;
|
208 |
}
|
209 |
|
210 |
$rules = array(
|
211 |
+
// feed.
|
212 |
array(
|
213 |
+
'regex' => '%s/(.+?)/feed/(feed|rdf|rss|rss2|atom)/?$',
|
214 |
+
'redirect' => "index.php?{$taxonomy_key}=\$matches[1]&feed=\$matches[2]",
|
215 |
),
|
216 |
array(
|
217 |
+
'regex' => '%s/(.+?)/(feed|rdf|rss|rss2|atom)/?$',
|
218 |
+
'redirect' => "index.php?{$taxonomy_key}=\$matches[1]&feed=\$matches[2]",
|
219 |
),
|
220 |
+
// year
|
221 |
array(
|
222 |
+
'regex' => '%s/(.+?)/date/([0-9]{4})/?$',
|
223 |
+
'redirect' => "index.php?{$taxonomy_key}=\$matches[1]&year=\$matches[2]",
|
224 |
),
|
225 |
array(
|
226 |
+
'regex' => '%s/(.+?)/date/([0-9]{4})/page/?([0-9]{1,})/?$',
|
227 |
+
'redirect' => "index.php?{$taxonomy_key}=\$matches[1]&year=\$matches[2]&paged=\$matches[3]",
|
228 |
),
|
229 |
+
// monthnum
|
230 |
array(
|
231 |
+
'regex' => '%s/(.+?)/date/([0-9]{4})/([0-9]{1,2})/?$',
|
232 |
+
'redirect' => "index.php?{$taxonomy_key}=\$matches[1]&year=\$matches[2]&monthnum=\$matches[3]",
|
233 |
),
|
234 |
array(
|
235 |
+
'regex' => '%s/(.+?)/date/([0-9]{4})/([0-9]{1,2})/page/?([0-9]{1,})/?$',
|
236 |
+
'redirect' => "index.php?{$taxonomy_key}=\$matches[1]&year=\$matches[2]&monthnum=\$matches[3]&paged=\$matches[4]",
|
237 |
),
|
238 |
+
// day
|
239 |
array(
|
240 |
+
'regex' => '%s/(.+?)/date/([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/?$',
|
241 |
+
'redirect' => "index.php?{$taxonomy_key}=\$matches[1]&year=\$matches[2]&monthnum=\$matches[3]&day=\$matches[4]",
|
242 |
),
|
243 |
array(
|
244 |
+
'regex' => '%s/(.+?)/date/([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/page/?([0-9]{1,})/?$',
|
245 |
+
'redirect' => "index.php?{$taxonomy_key}=\$matches[1]&year=\$matches[2]&monthnum=\$matches[3]&day=\$matches[4]&paged=\$matches[5]",
|
246 |
),
|
247 |
+
// paging
|
248 |
array(
|
249 |
+
'regex' => '%s/(.+?)/page/?([0-9]{1,})/?$',
|
250 |
+
'redirect' => "index.php?{$taxonomy_key}=\$matches[1]&paged=\$matches[2]",
|
251 |
),
|
252 |
+
// tax archive.
|
253 |
array(
|
254 |
+
'regex' => '%s/(.+?)/?$',
|
255 |
+
'redirect' => "index.php?{$taxonomy_key}=\$matches[1]",
|
256 |
),
|
257 |
);
|
258 |
|
259 |
+
// no post_type slug.
|
260 |
foreach ( $rules as $rule ) {
|
261 |
$regex = sprintf( $rule['regex'], "{$taxonomy_slug}" );
|
262 |
$redirect = $rule['redirect'];
|
269 |
$redirect = $rule['redirect'] . "&post_type={$post_type}";
|
270 |
add_rewrite_rule( $regex, $redirect, 'top' );
|
271 |
}
|
|
|
272 |
} else {
|
273 |
foreach ( $rules as $rule ) {
|
274 |
$regex = sprintf( $rule['regex'], "{$slug}/{$taxonomy_slug}" );
|
286 |
/**
|
287 |
*
|
288 |
* Fix taxonomy = parent/child => taxonomy => child
|
289 |
+
*
|
290 |
* @since 0.9.3
|
291 |
*
|
292 |
* @param WP $obj
|
CPTP/Module/Setting.php
CHANGED
@@ -7,7 +7,6 @@
|
|
7 |
*
|
8 |
* @package Custom_Post_Type_Permalinks
|
9 |
* @since 0.9.4
|
10 |
-
*
|
11 |
* */
|
12 |
|
13 |
|
@@ -21,16 +20,15 @@ class CPTP_Module_Setting extends CPTP_Module {
|
|
21 |
/**
|
22 |
*
|
23 |
* check_version
|
24 |
-
* @since 0.8.6
|
25 |
*
|
|
|
26 |
*/
|
27 |
|
28 |
public function check_version() {
|
29 |
$version = get_option( 'cptp_version', 0 );
|
30 |
-
if ( false === $version ){
|
31 |
add_option( 'cptp_version', CPTP_VERSION );
|
32 |
-
}
|
33 |
-
else if ( CPTP_VERSION != $version ) {
|
34 |
update_option( 'cptp_version', CPTP_VERSION );
|
35 |
}
|
36 |
}
|
@@ -39,11 +37,10 @@ class CPTP_Module_Setting extends CPTP_Module {
|
|
39 |
/**
|
40 |
*
|
41 |
* load textdomain
|
42 |
-
* @since 0.6.2
|
43 |
*
|
|
|
44 |
*/
|
45 |
public function load_textdomain() {
|
46 |
load_plugin_textdomain( 'custom-post-type-permalinks', false, 'custom-post-type-permalinks/language' );
|
47 |
}
|
48 |
-
|
49 |
}
|
7 |
*
|
8 |
* @package Custom_Post_Type_Permalinks
|
9 |
* @since 0.9.4
|
|
|
10 |
* */
|
11 |
|
12 |
|
20 |
/**
|
21 |
*
|
22 |
* check_version
|
|
|
23 |
*
|
24 |
+
* @since 0.8.6
|
25 |
*/
|
26 |
|
27 |
public function check_version() {
|
28 |
$version = get_option( 'cptp_version', 0 );
|
29 |
+
if ( false === $version ) {
|
30 |
add_option( 'cptp_version', CPTP_VERSION );
|
31 |
+
} else if ( CPTP_VERSION != $version ) {
|
|
|
32 |
update_option( 'cptp_version', CPTP_VERSION );
|
33 |
}
|
34 |
}
|
37 |
/**
|
38 |
*
|
39 |
* load textdomain
|
|
|
40 |
*
|
41 |
+
* @since 0.6.2
|
42 |
*/
|
43 |
public function load_textdomain() {
|
44 |
load_plugin_textdomain( 'custom-post-type-permalinks', false, 'custom-post-type-permalinks/language' );
|
45 |
}
|
|
|
46 |
}
|
CPTP/Util.php
CHANGED
@@ -6,7 +6,6 @@
|
|
6 |
*
|
7 |
* @package Custom_Post_Type_Permalinks
|
8 |
* @since 0.9.4
|
9 |
-
*
|
10 |
* */
|
11 |
|
12 |
class CPTP_Util {
|
@@ -21,8 +20,7 @@ class CPTP_Util {
|
|
21 |
public static function get_taxonomies( $objects = false ) {
|
22 |
if ( $objects ) {
|
23 |
$output = 'objects';
|
24 |
-
}
|
25 |
-
else {
|
26 |
$output = 'names';
|
27 |
}
|
28 |
return get_taxonomies( array( 'show_ui' => true, '_builtin' => false ), $output );
|
@@ -32,8 +30,8 @@ class CPTP_Util {
|
|
32 |
/**
|
33 |
*
|
34 |
* Get Custom Taxonomies parents.
|
35 |
-
* @version 1.0
|
36 |
*
|
|
|
37 |
*/
|
38 |
public static function get_taxonomy_parents( $id, $taxonomy = 'category', $link = false, $separator = '/', $nicename = false, $visited = array() ) {
|
39 |
$chain = '';
|
@@ -42,9 +40,9 @@ class CPTP_Util {
|
|
42 |
return $parent;
|
43 |
}
|
44 |
|
45 |
-
if ( $nicename ){
|
46 |
$name = $parent->slug;
|
47 |
-
}else {
|
48 |
$name = $parent->name;
|
49 |
}
|
50 |
|
@@ -54,7 +52,7 @@ class CPTP_Util {
|
|
54 |
}
|
55 |
if ( $link ) {
|
56 |
$chain .= '<a href="' . get_term_link( $parent->term_id, $taxonomy ) . '" title="' . esc_attr( sprintf( __( 'View all posts in %s' ), $parent->name ) ) . '">'.esc_html( $name ).'</a>' .esc_html( $separator );
|
57 |
-
}else {
|
58 |
$chain .= $name.$separator;
|
59 |
}
|
60 |
return $chain;
|
@@ -70,15 +68,13 @@ class CPTP_Util {
|
|
70 |
public static function get_permalink_structure( $post_type ) {
|
71 |
if ( is_string( $post_type ) ) {
|
72 |
$pt_object = get_post_type_object( $post_type );
|
73 |
-
}
|
74 |
-
else {
|
75 |
$pt_object = $post_type;
|
76 |
}
|
77 |
|
78 |
if ( ! empty( $pt_object->cptp_permalink_structure ) ) {
|
79 |
$structure = $pt_object->cptp_permalink_structure;
|
80 |
-
}
|
81 |
-
else {
|
82 |
|
83 |
$structure = get_option( $pt_object->name.'_structure' );
|
84 |
}
|
@@ -112,7 +108,4 @@ class CPTP_Util {
|
|
112 |
return $front;
|
113 |
|
114 |
}
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
}
|
6 |
*
|
7 |
* @package Custom_Post_Type_Permalinks
|
8 |
* @since 0.9.4
|
|
|
9 |
* */
|
10 |
|
11 |
class CPTP_Util {
|
20 |
public static function get_taxonomies( $objects = false ) {
|
21 |
if ( $objects ) {
|
22 |
$output = 'objects';
|
23 |
+
} else {
|
|
|
24 |
$output = 'names';
|
25 |
}
|
26 |
return get_taxonomies( array( 'show_ui' => true, '_builtin' => false ), $output );
|
30 |
/**
|
31 |
*
|
32 |
* Get Custom Taxonomies parents.
|
|
|
33 |
*
|
34 |
+
* @version 1.0
|
35 |
*/
|
36 |
public static function get_taxonomy_parents( $id, $taxonomy = 'category', $link = false, $separator = '/', $nicename = false, $visited = array() ) {
|
37 |
$chain = '';
|
40 |
return $parent;
|
41 |
}
|
42 |
|
43 |
+
if ( $nicename ) {
|
44 |
$name = $parent->slug;
|
45 |
+
} else {
|
46 |
$name = $parent->name;
|
47 |
}
|
48 |
|
52 |
}
|
53 |
if ( $link ) {
|
54 |
$chain .= '<a href="' . get_term_link( $parent->term_id, $taxonomy ) . '" title="' . esc_attr( sprintf( __( 'View all posts in %s' ), $parent->name ) ) . '">'.esc_html( $name ).'</a>' .esc_html( $separator );
|
55 |
+
} else {
|
56 |
$chain .= $name.$separator;
|
57 |
}
|
58 |
return $chain;
|
68 |
public static function get_permalink_structure( $post_type ) {
|
69 |
if ( is_string( $post_type ) ) {
|
70 |
$pt_object = get_post_type_object( $post_type );
|
71 |
+
} else {
|
|
|
72 |
$pt_object = $post_type;
|
73 |
}
|
74 |
|
75 |
if ( ! empty( $pt_object->cptp_permalink_structure ) ) {
|
76 |
$structure = $pt_object->cptp_permalink_structure;
|
77 |
+
} else {
|
|
|
78 |
|
79 |
$structure = get_option( $pt_object->name.'_structure' );
|
80 |
}
|
108 |
return $front;
|
109 |
|
110 |
}
|
|
|
|
|
|
|
111 |
}
|
codesniffer.ruleset.xml
ADDED
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0"?>
|
2 |
+
<ruleset>
|
3 |
+
<!-- See https://github.com/squizlabs/PHP_CodeSniffer/wiki/Annotated-ruleset.xml -->
|
4 |
+
<!-- See https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/blob/develop/WordPress-Core/ruleset.xml -->
|
5 |
+
<!-- Include the WordPress ruleset, with exclusions. -->
|
6 |
+
<rule ref="WordPress">
|
7 |
+
<exclude name="Generic.WhiteSpace.ScopeIndent.IncorrectExact" />
|
8 |
+
<exclude name="Generic.WhiteSpace.ScopeIndent.Incorrect" />
|
9 |
+
<exclude name="WordPress.VIP" />
|
10 |
+
<exclude name="Squiz.Commenting" />
|
11 |
+
<exclude name="Generic.Commenting" />
|
12 |
+
<exclude name="Generic.Files.LowercasedFilename" />
|
13 |
+
<exclude name="WordPress.NamingConventions" />
|
14 |
+
<exclude name="WordPress.XSS.EscapeOutput.UnsafePrintingFunction" />
|
15 |
+
<exclude name="WordPress.XSS.EscapeOutput.OutputNotEscaped" />
|
16 |
+
</rule>
|
17 |
+
|
18 |
+
<exclude-pattern>*/vendor/*</exclude-pattern>
|
19 |
+
<exclude-pattern>*/tests/*</exclude-pattern>
|
20 |
+
</ruleset>
|
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:
|
9 |
Text Domain: custom-post-type-permalinks
|
10 |
License: GPL2 or later
|
11 |
Domain Path: /language/
|
@@ -17,8 +17,7 @@ Domain Path: /language/
|
|
17 |
* Custom Post Type Permalinks
|
18 |
*
|
19 |
* @package Custom_Post_Type_Permalinks
|
20 |
-
* @version
|
21 |
-
*
|
22 |
*/
|
23 |
|
24 |
define( 'CPTP_PLUGIN_FILE', __FILE__ );
|
@@ -27,32 +26,31 @@ define( 'CPTP_VERSION', $data['ver'] );
|
|
27 |
define( 'CPTP_DEFAULT_PERMALINK', '/%postname%/' );
|
28 |
|
29 |
|
30 |
-
|
31 |
/**
|
32 |
*
|
33 |
* Autoloader for CPTP.
|
34 |
-
* @since 1.0.0
|
35 |
*
|
|
|
36 |
*/
|
37 |
function cptp_class_loader( $class_name ) {
|
38 |
-
$dir
|
39 |
-
$file_name = $dir . '/'. str_replace( '_', '/', $class_name ).'.php';
|
40 |
if ( is_readable( $file_name ) ) {
|
41 |
include $file_name;
|
42 |
}
|
43 |
}
|
|
|
44 |
spl_autoload_register( 'cptp_class_loader' );
|
45 |
|
46 |
|
47 |
/**
|
48 |
-
*
|
49 |
-
* Entry Point
|
50 |
-
* @since 0.9.4
|
51 |
-
*
|
52 |
*/
|
53 |
-
add_action( 'plugins_loaded', '
|
54 |
-
|
55 |
-
CPTP::get_instance();
|
56 |
-
}
|
57 |
|
|
|
|
|
|
|
|
|
58 |
|
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.0.0
|
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.0.0
|
|
|
21 |
*/
|
22 |
|
23 |
define( 'CPTP_PLUGIN_FILE', __FILE__ );
|
26 |
define( 'CPTP_DEFAULT_PERMALINK', '/%postname%/' );
|
27 |
|
28 |
|
|
|
29 |
/**
|
30 |
*
|
31 |
* Autoloader for CPTP.
|
|
|
32 |
*
|
33 |
+
* @since 1.0.0
|
34 |
*/
|
35 |
function cptp_class_loader( $class_name ) {
|
36 |
+
$dir = dirname( __FILE__ );
|
37 |
+
$file_name = $dir . '/' . str_replace( '_', '/', $class_name ) . '.php';
|
38 |
if ( is_readable( $file_name ) ) {
|
39 |
include $file_name;
|
40 |
}
|
41 |
}
|
42 |
+
|
43 |
spl_autoload_register( 'cptp_class_loader' );
|
44 |
|
45 |
|
46 |
/**
|
47 |
+
* initialize Plugin
|
|
|
|
|
|
|
48 |
*/
|
49 |
+
add_action( 'plugins_loaded', array( CPTP::get_instance(), 'init' ) );
|
50 |
+
|
|
|
|
|
51 |
|
52 |
+
/**
|
53 |
+
* Activation hooks.
|
54 |
+
*/
|
55 |
+
register_activation_hook( CPTP_PLUGIN_FILE, array( CPTP::get_instance(), 'activate' ) );
|
56 |
|
readme.md
CHANGED
@@ -9,6 +9,7 @@ Edit the permalink of custom post type.
|
|
9 |
[![](https://img.shields.io/wordpress/plugin/dt/custom-post-type-permalinks.svg)](https://wordpress.org/plugins/custom-post-type-permalinks/)
|
10 |
[![](https://img.shields.io/wordpress/v/custom-post-type-permalinks.svg)](https://wordpress.org/plugins/custom-post-type-permalinks/)
|
11 |
[![](https://img.shields.io/wordpress/plugin/r/custom-post-type-permalinks.svg)](https://wordpress.org/plugins/custom-post-type-permalinks/)
|
|
|
12 |
|
13 |
[![](http://www.torounit.com/wp-content/uploads/2011/11/banner-772x250.png)](https://wordpress.org/plugins/custom-post-type-permalinks/)
|
14 |
|
@@ -22,7 +23,8 @@ And support wp_get_archives( "post_type=foo" ).
|
|
22 |
|
23 |
[This Plugin published on GitHub.](https://github.com/torounit/custom-post-type-permalinks)
|
24 |
|
25 |
-
Donation: Please send amazon.co.jp Gift to donate[at]torounit.com.
|
|
|
26 |
|
27 |
### Translators
|
28 |
|
@@ -30,6 +32,11 @@ Donation: Please send amazon.co.jp Gift to donate[at]torounit.com.
|
|
30 |
* French(fr_FR) - [Geoffrey Crofte](http://geoffrey.crofte.fr/)
|
31 |
* Russian(ru_RU) - [Olart](http://olart.ru), [Natali_Z](https://profiles.wordpress.org/natali_z)
|
32 |
|
|
|
|
|
|
|
|
|
|
|
33 |
## Setting on Code
|
34 |
|
35 |
Example:
|
@@ -65,6 +72,12 @@ That's it. You can access the permalinks setting by going to *Settings -> Permal
|
|
65 |
|
66 |
## Changelog
|
67 |
|
|
|
|
|
|
|
|
|
|
|
|
|
68 |
### 1.5.4
|
69 |
|
70 |
* Fixed removed parent post problem.
|
9 |
[![](https://img.shields.io/wordpress/plugin/dt/custom-post-type-permalinks.svg)](https://wordpress.org/plugins/custom-post-type-permalinks/)
|
10 |
[![](https://img.shields.io/wordpress/v/custom-post-type-permalinks.svg)](https://wordpress.org/plugins/custom-post-type-permalinks/)
|
11 |
[![](https://img.shields.io/wordpress/plugin/r/custom-post-type-permalinks.svg)](https://wordpress.org/plugins/custom-post-type-permalinks/)
|
12 |
+
[![](https://img.shields.io/badge/bitcoin-donate-yellow.svg)](https://blockchain.info/ja/address/3HwkojX2pd9wc5kPFdXnDXMTNbgBmPRygX)
|
13 |
|
14 |
[![](http://www.torounit.com/wp-content/uploads/2011/11/banner-772x250.png)](https://wordpress.org/plugins/custom-post-type-permalinks/)
|
15 |
|
23 |
|
24 |
[This Plugin published on GitHub.](https://github.com/torounit/custom-post-type-permalinks)
|
25 |
|
26 |
+
Donation: Please send [bitcoin](https://blockchain.info/ja/address/3HwkojX2pd9wc5kPFdXnDXMTNbgBmPRygX) or amazon.co.jp Gift to donate[at]torounit.com.
|
27 |
+
|
28 |
|
29 |
### Translators
|
30 |
|
32 |
* French(fr_FR) - [Geoffrey Crofte](http://geoffrey.crofte.fr/)
|
33 |
* Russian(ru_RU) - [Olart](http://olart.ru), [Natali_Z](https://profiles.wordpress.org/natali_z)
|
34 |
|
35 |
+
### Also checkout
|
36 |
+
|
37 |
+
* [Simple Post Type Permalinks](https://wordpress.org/plugins/simple-post-type-permalinks/)
|
38 |
+
|
39 |
+
|
40 |
## Setting on Code
|
41 |
|
42 |
Example:
|
72 |
|
73 |
## Changelog
|
74 |
|
75 |
+
### 2.0.0
|
76 |
+
|
77 |
+
* `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)
|
78 |
+
* Replace wp_get_post_terms by get_the_terms. [fix issue #55](https://github.com/torounit/custom-post-type-permalinks/issues/55)
|
79 |
+
* Fix bug register_uninstall_hook called twice on each page. [fix issue #56](https://github.com/torounit/custom-post-type-permalinks/issues/56)
|
80 |
+
|
81 |
### 1.5.4
|
82 |
|
83 |
* Fixed removed parent post problem.
|
readme.txt
CHANGED
@@ -3,8 +3,8 @@ Contributors: Toro_Unit,inc2734,ixkaito,keita_kobayashi
|
|
3 |
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.
|
7 |
-
Stable tag:
|
8 |
License: GPLv2 or Later
|
9 |
|
10 |
Edit the permalink of custom post type.
|
@@ -19,13 +19,19 @@ And support wp_get_archives( "post_type=foo" ).
|
|
19 |
|
20 |
[This Plugin published on GitHub.](https://github.com/torounit/custom-post-type-permalinks)
|
21 |
|
22 |
-
Donation: Please send amazon.co.jp Gift to donate[at]torounit.com.
|
|
|
23 |
|
24 |
= Translators =
|
25 |
* Japanese(ja) - [Toro_Unit](http://www.torounit.com/)
|
26 |
* French(fr_FR) - [Geoffrey Crofte](http://geoffrey.crofte.fr/)
|
27 |
* Russian(ru_RU) - [Olart](http://olart.ru), [Natali_Z](https://profiles.wordpress.org/natali_z)
|
28 |
|
|
|
|
|
|
|
|
|
|
|
29 |
== Setting on Code ==
|
30 |
|
31 |
Example:
|
@@ -61,6 +67,12 @@ That's it. You can access the permalinks setting by going to *Settings -> Permal
|
|
61 |
|
62 |
== Changelog ==
|
63 |
|
|
|
|
|
|
|
|
|
|
|
|
|
64 |
= 1.5.4 =
|
65 |
|
66 |
* Fixed removed parent post problem.
|
3 |
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.0.0
|
8 |
License: GPLv2 or Later
|
9 |
|
10 |
Edit the permalink of custom post type.
|
19 |
|
20 |
[This Plugin published on GitHub.](https://github.com/torounit/custom-post-type-permalinks)
|
21 |
|
22 |
+
Donation: Please send [bitcoin](https://blockchain.info/ja/address/3HwkojX2pd9wc5kPFdXnDXMTNbgBmPRygX) or amazon.co.jp Gift to donate[at]torounit.com.
|
23 |
+
|
24 |
|
25 |
= Translators =
|
26 |
* Japanese(ja) - [Toro_Unit](http://www.torounit.com/)
|
27 |
* French(fr_FR) - [Geoffrey Crofte](http://geoffrey.crofte.fr/)
|
28 |
* Russian(ru_RU) - [Olart](http://olart.ru), [Natali_Z](https://profiles.wordpress.org/natali_z)
|
29 |
|
30 |
+
= Also checkout =
|
31 |
+
|
32 |
+
* [Simple Post Type Permalinks](https://wordpress.org/plugins/simple-post-type-permalinks/)
|
33 |
+
|
34 |
+
|
35 |
== Setting on Code ==
|
36 |
|
37 |
Example:
|
67 |
|
68 |
== Changelog ==
|
69 |
|
70 |
+
= 2.0.0 =
|
71 |
+
|
72 |
+
* `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)
|
73 |
+
* Replace wp_get_post_terms by get_the_terms. [fix issue #55](https://github.com/torounit/custom-post-type-permalinks/issues/55)
|
74 |
+
* Fix bug register_uninstall_hook called twice on each page. [fix issue #56](https://github.com/torounit/custom-post-type-permalinks/issues/56)
|
75 |
+
|
76 |
= 1.5.4 =
|
77 |
|
78 |
* Fixed removed parent post problem.
|