Custom Post Type Permalinks - Version 2.1.3

Version Description

  • Set no_taxonomy_structure default true.
Download this release

Release Info

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

Code changes from version 2.1.2 to 2.1.3

CPTP/Module/Admin.php CHANGED
@@ -70,11 +70,11 @@ class CPTP_Module_Admin extends CPTP_Module {
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
 
@@ -116,9 +116,9 @@ class CPTP_Module_Admin extends CPTP_Module {
116
 
117
 
118
  public function setting_no_tax_structure_callback_function() {
119
- echo '<input name="no_taxonomy_structure" id="no_taxonomy_structure" type="checkbox" value="1" class="code" ' . checked( false, get_option( 'no_taxonomy_structure' ), false ) . ' /> ';
120
  $txt = __( "If you check this, the custom taxonomy's permalinks will be <code>%s/post_type/taxonomy/term</code>.", 'custom-post-type-permalinks' );
121
- echo sprintf( $txt, esc_html( home_url() ) );
122
  }
123
 
124
 
70
 
71
  public function setting_section_callback_function() {
72
  ?>
73
+ <p><?php echo wp_kses( __( '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' ), array( 'code' => array() ) ); ?>
74
+ <?php echo wp_kses( __( '<code>%"custom_taxonomy_slug"%</code> is replaced by the term of taxonomy.', 'custom-post-type-permalinks' ), array( 'code' => array() ) ); ?></p>
75
 
76
+ <p><?php esc_html_e( "Presence of the trailing '/' is unified into a standard permalink structure setting.", 'custom-post-type-permalinks' ); ?>
77
+ <p><?php echo wp_kses( __( 'If <code>has_archive</code> is true, add permalinks for custom post type archive.', 'custom-post-type-permalinks' ), array( 'code' => array() ) ); ?></p>
78
  <?php
79
  }
80
 
116
 
117
 
118
  public function setting_no_tax_structure_callback_function() {
119
+ echo '<input name="no_taxonomy_structure" id="no_taxonomy_structure" type="checkbox" value="1" class="code" ' . checked( false, get_option( 'no_taxonomy_structure', true ), false ) . ' /> ';
120
  $txt = __( "If you check this, the custom taxonomy's permalinks will be <code>%s/post_type/taxonomy/term</code>.", 'custom-post-type-permalinks' );
121
+ echo sprintf( wp_kses( $txt, array( 'code' => array() ) ), esc_html( home_url() ) );
122
  }
123
 
124
 
CPTP/Module/FlushRules.php CHANGED
@@ -30,7 +30,7 @@ class CPTP_Module_FlushRules extends CPTP_Module {
30
 
31
  $post_types = CPTP_Util::get_post_types();
32
  foreach ( $post_types as $post_type ) {
33
- add_action( 'update_option_'.$post_type.'_structure', array( __CLASS__, 'queue_flush_rules' ), 10, 2 );
34
  }
35
  add_action( 'update_option_no_taxonomy_structure', array( __CLASS__, 'queue_flush_rules' ), 10, 2 );
36
  }
30
 
31
  $post_types = CPTP_Util::get_post_types();
32
  foreach ( $post_types as $post_type ) {
33
+ add_action( 'update_option_' . $post_type . '_structure', array( __CLASS__, 'queue_flush_rules' ), 10, 2 );
34
  }
35
  add_action( 'update_option_no_taxonomy_structure', array( __CLASS__, 'queue_flush_rules' ), 10, 2 );
36
  }
CPTP/Module/GetArchives.php CHANGED
@@ -39,7 +39,7 @@ class CPTP_Module_GetArchives extends CPTP_Module {
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
  }
44
 
45
  return $where;
@@ -57,7 +57,7 @@ class CPTP_Module_GetArchives extends CPTP_Module {
57
  * @version 1.0
58
  *
59
  * @param string $join
60
- * @param array $r
61
  *
62
  * @return string
63
  */
@@ -106,7 +106,7 @@ class CPTP_Module_GetArchives extends CPTP_Module {
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]
@@ -117,7 +117,7 @@ class CPTP_Module_GetArchives extends CPTP_Module {
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
  }
122
 
123
  if ( ! strstr( $link, '/date/' ) ) {
@@ -125,7 +125,7 @@ class CPTP_Module_GetArchives extends CPTP_Module {
125
  }
126
 
127
  if ( $post_type->rewrite['with_front'] ) {
128
- $link_dir = $front.$link_dir;
129
  }
130
 
131
  $ret_link = str_replace( '%link_dir%', $link_dir, $ret_link );
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
  }
44
 
45
  return $where;
57
  * @version 1.0
58
  *
59
  * @param string $join
60
+ * @param array $r
61
  *
62
  * @return string
63
  */
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]
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
  }
122
 
123
  if ( ! strstr( $link, '/date/' ) ) {
125
  }
126
 
127
  if ( $post_type->rewrite['with_front'] ) {
128
+ $link_dir = $front . $link_dir;
129
  }
130
 
131
  $ret_link = str_replace( '%link_dir%', $link_dir, $ret_link );
CPTP/Module/Permalink.php CHANGED
@@ -45,9 +45,9 @@ class CPTP_Module_Permalink extends CPTP_Module {
45
  *
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
  *
@@ -314,7 +314,7 @@ class CPTP_Module_Permalink extends CPTP_Module {
314
  return $termlink;
315
  }
316
 
317
- if ( get_option( 'no_taxonomy_structure' ) ) {
318
  return $termlink;
319
  }
320
 
45
  *
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
  *
314
  return $termlink;
315
  }
316
 
317
+ if ( get_option( 'no_taxonomy_structure', true ) ) {
318
  return $termlink;
319
  }
320
 
CPTP/Module/Rewrite.php CHANGED
@@ -99,8 +99,8 @@ class CPTP_Module_Rewrite extends CPTP_Module {
99
  $category_base = 'category';
100
  }
101
 
102
- add_rewrite_rule( $slug . '/'. $category_base . '/([^/]+)/page/?([0-9]{1,})/?$', 'index.php?category_name=$matches[1]&paged=$matches[2]&post_type=' . $post_type, 'top' );
103
- add_rewrite_rule( $slug . '/'. $category_base . '/([^/]+)/?$', 'index.php?category_name=$matches[1]&post_type=' . $post_type, 'top' );
104
 
105
  }
106
 
@@ -117,20 +117,20 @@ class CPTP_Module_Rewrite extends CPTP_Module {
117
  *
118
  * register_taxonomy_rules
119
  *
120
- * @param string $taxonomy
121
  * @param array|string $object_type
122
- * @param array $args
123
  *
124
  * @return void
125
  */
126
  public function register_taxonomy_rules( $taxonomy, $object_type, $args ) {
127
  global $wp_rewrite;
128
 
129
- if ( get_option( 'no_taxonomy_structure' ) ) {
130
  return;
131
  }
132
 
133
- if ( $args['_builtin'] ) {
134
  return;
135
  }
136
 
@@ -213,7 +213,7 @@ class CPTP_Module_Rewrite extends CPTP_Module {
213
  ),
214
  // tax archive.
215
  array(
216
- 'regex' => '%s/(.+?)/?$',
217
  'redirect' => "index.php?{$taxonomy_key}=\$matches[1]",
218
  ),
219
  );
99
  $category_base = 'category';
100
  }
101
 
102
+ add_rewrite_rule( $slug . '/' . $category_base . '/([^/]+)/page/?([0-9]{1,})/?$', 'index.php?category_name=$matches[1]&paged=$matches[2]&post_type=' . $post_type, 'top' );
103
+ add_rewrite_rule( $slug . '/' . $category_base . '/([^/]+)/?$', 'index.php?category_name=$matches[1]&post_type=' . $post_type, 'top' );
104
 
105
  }
106
 
117
  *
118
  * register_taxonomy_rules
119
  *
120
+ * @param string $taxonomy
121
  * @param array|string $object_type
122
+ * @param array $args
123
  *
124
  * @return void
125
  */
126
  public function register_taxonomy_rules( $taxonomy, $object_type, $args ) {
127
  global $wp_rewrite;
128
 
129
+ if ( get_option( 'no_taxonomy_structure', true ) ) {
130
  return;
131
  }
132
 
133
+ if ( ! empty( $args['_builtin'] ) ) {
134
  return;
135
  }
136
 
213
  ),
214
  // tax archive.
215
  array(
216
+ 'regex' => '%s/(.+?)/?$',
217
  'redirect' => "index.php?{$taxonomy_key}=\$matches[1]",
218
  ),
219
  );
CPTP/Util.php CHANGED
@@ -57,10 +57,10 @@ class CPTP_Util {
57
  * @version 1.0
58
  *
59
  * @param int|WP_Term|object $term
60
- * @param string $taxonomy
61
- * @param string $separator
62
- * @param bool $nicename
63
- * @param array $visited
64
  *
65
  * @return string
66
  */
@@ -81,7 +81,7 @@ class CPTP_Util {
81
  $visited[] = $parent->parent;
82
  $chain .= CPTP_Util::get_taxonomy_parents_slug( $parent->parent, $taxonomy, $separator, $nicename, $visited );
83
  }
84
- $chain .= $name.$separator;
85
 
86
  return $chain;
87
  }
@@ -93,11 +93,11 @@ class CPTP_Util {
93
  * @deprecated
94
  *
95
  * @param int|WP_Term|object $term
96
- * @param string $taxonomy
97
- * @param bool $link
98
- * @param string $separator
99
- * @param bool $nicename
100
- * @param array $visited
101
  *
102
  * @return string
103
  */
@@ -119,9 +119,9 @@ class CPTP_Util {
119
  $chain .= CPTP_Util::get_taxonomy_parents( $parent->parent, $taxonomy, $link, $separator, $nicename, $visited );
120
  }
121
  if ( $link ) {
122
- $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 );
123
  } else {
124
- $chain .= $name.$separator;
125
  }
126
  return $chain;
127
  }
@@ -144,10 +144,10 @@ class CPTP_Util {
144
  $structure = $pt_object->cptp_permalink_structure;
145
  } else {
146
 
147
- $structure = get_option( $pt_object->name.'_structure' );
148
  }
149
 
150
- return apply_filters( 'CPTP_'.$pt_object->name.'_structure', $structure );
151
  }
152
 
153
 
57
  * @version 1.0
58
  *
59
  * @param int|WP_Term|object $term
60
+ * @param string $taxonomy
61
+ * @param string $separator
62
+ * @param bool $nicename
63
+ * @param array $visited
64
  *
65
  * @return string
66
  */
81
  $visited[] = $parent->parent;
82
  $chain .= CPTP_Util::get_taxonomy_parents_slug( $parent->parent, $taxonomy, $separator, $nicename, $visited );
83
  }
84
+ $chain .= $name . $separator;
85
 
86
  return $chain;
87
  }
93
  * @deprecated
94
  *
95
  * @param int|WP_Term|object $term
96
+ * @param string $taxonomy
97
+ * @param bool $link
98
+ * @param string $separator
99
+ * @param bool $nicename
100
+ * @param array $visited
101
  *
102
  * @return string
103
  */
119
  $chain .= CPTP_Util::get_taxonomy_parents( $parent->parent, $taxonomy, $link, $separator, $nicename, $visited );
120
  }
121
  if ( $link ) {
122
+ $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 );
123
  } else {
124
+ $chain .= $name . $separator;
125
  }
126
  return $chain;
127
  }
144
  $structure = $pt_object->cptp_permalink_structure;
145
  } else {
146
 
147
+ $structure = get_option( $pt_object->name . '_structure' );
148
  }
149
 
150
+ return apply_filters( 'CPTP_' . $pt_object->name . '_structure', $structure );
151
  }
152
 
153
 
circle.yml ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ## Customize the test machine
2
+ machine:
3
+
4
+ # Override /etc/hosts
5
+
6
+ # Add some environment variables
7
+ environment:
8
+ CIRCLE_ENV: test
9
+ WP_VERSION: trunk
10
+
11
+ ## Customize dependencies
12
+ dependencies:
13
+ pre:
14
+ - sudo apt-get update; sudo apt-get install subversion
15
+ - bash bin/install-wp-tests.sh wordpress_test ubuntu '' 127.0.0.1 $WP_VERSION
16
+ - composer install
17
+
18
+ ## Customize test commands
19
+ test:
20
+ override:
21
+ - phpunit
22
+ - composer phpcs
23
+
24
+
codesniffer.ruleset.xml CHANGED
@@ -11,8 +11,6 @@
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>
11
  <exclude name="Generic.Commenting" />
12
  <exclude name="Generic.Files.LowercasedFilename" />
13
  <exclude name="WordPress.NamingConventions" />
 
 
14
  </rule>
15
 
16
  <exclude-pattern>*/vendor/*</exclude-pattern>
composer.json CHANGED
@@ -11,8 +11,8 @@
11
  ],
12
  "require": {},
13
  "require-dev": {
14
- "squizlabs/php_codesniffer": "2.*",
15
- "wp-coding-standards/wpcs": "0.9.0"
16
  },
17
  "scripts": {
18
  "post-install-cmd": [
11
  ],
12
  "require": {},
13
  "require-dev": {
14
+ "squizlabs/php_codesniffer": "*",
15
+ "wp-coding-standards/wpcs": "*"
16
  },
17
  "scripts": {
18
  "post-install-cmd": [
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.1.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.1.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.3
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.3
21
  */
22
 
23
  define( 'CPTP_PLUGIN_FILE', __FILE__ );
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.1.2
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
  = 2.1.2 =
71
 
72
  * `rewirte => false` post type support.
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.3
8
  License: GPLv2 or Later
9
 
10
  Edit the permalink of custom post type.
67
 
68
  == Changelog ==
69
 
70
+ = 2.1.3 =
71
+
72
+ * Set `no_taxonomy_structure` default true.
73
+
74
  = 2.1.2 =
75
 
76
  * `rewirte => false` post type support.