Custom Post Type Permalinks - Version 1.0.0

Version Description

  • Set Permalink enable register_post_type.
  • Enable add post type query to taxonomy archives.
  • Use Class Autoloader.
  • Create Rewrite Rule on wp_loaded action.
  • WordPress Code Format Fix.
  • CPTP_Module_Permalink Bug Fix.
  • Bug Fix.
  • Use Semantic Versioning.
  • Date Structure Fix.
  • Use Category Base.
Download this release

Release Info

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

Code changes from version 0.9.6 to 1.0.0

.travis.yml DELETED
@@ -1,16 +0,0 @@
1
- language: php
2
-
3
- php:
4
- - 5.3
5
- - 5.4
6
-
7
- env:
8
- - WP_VERSION=latest WP_MULTISITE=0
9
- - WP_VERSION=latest WP_MULTISITE=1
10
- - WP_VERSION=3.8 WP_MULTISITE=0
11
- - WP_VERSION=3.8 WP_MULTISITE=1
12
-
13
- before_script:
14
- - bash bin/install-wp-tests.sh wordpress_test root '' localhost $WP_VERSION
15
-
16
- script: phpunit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
CPTP.php CHANGED
@@ -11,24 +11,10 @@
11
  * */
12
 
13
 
14
- define( "CPTP_VERSION", "0.9.6" );
15
- define( "CPTP_DEFAULT_PERMALINK", "/%postname%/" );
16
- define( "CPTP_DIR", dirname( __FILE__ ) );
17
-
18
-
19
- require_once CPTP_DIR.'/CPTP/Util.php';
20
- require_once CPTP_DIR.'/CPTP/Module.php';
21
- require_once CPTP_DIR.'/CPTP/Module/Setting.php';
22
- require_once CPTP_DIR.'/CPTP/Module/Rewrite.php';
23
- require_once CPTP_DIR.'/CPTP/Module/Admin.php';
24
- require_once CPTP_DIR.'/CPTP/Module/Permalink.php';
25
- require_once CPTP_DIR.'/CPTP/Module/GetArchives.php';
26
- require_once CPTP_DIR.'/CPTP/Module/FlushRules.php';
27
-
28
-
29
  class CPTP {
30
 
31
- private static $instance;
 
32
 
33
  private function __construct() {
34
  $this->load_modules();
@@ -36,37 +22,34 @@ class CPTP {
36
  }
37
 
38
  /**
39
- *
40
  * load_modules
41
  *
42
  * Load CPTP_Modules.
43
  * @since 0.9.5
44
  *
45
- * */
46
-
47
  private function load_modules() {
48
  new CPTP_Module_Setting();
49
  new CPTP_Module_Rewrite();
50
  new CPTP_Module_Admin();
 
51
  new CPTP_Module_Permalink();
52
  new CPTP_Module_GetArchives();
53
  new CPTP_Module_FlushRules();
54
- do_action( "CPTP_load_modules" );
55
 
56
  }
57
 
58
  /**
59
- *
60
  * init
61
  *
62
  * Fire Module::add_hook
63
  *
64
  * @since 0.9.5
65
  *
66
- * */
67
-
68
  private function init() {
69
- do_action( "CPTP_init" );
70
  }
71
 
72
  /**
@@ -75,11 +58,11 @@ class CPTP {
75
  */
76
  public static function get_instance() {
77
 
78
- if (!isset(self::$_instance)) {
79
- self::$instance = new CPTP;
80
  }
81
 
82
- return self::$instance;
83
  }
84
 
85
 
11
  * */
12
 
13
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
14
  class CPTP {
15
 
16
+
17
+ private static $_instance;
18
 
19
  private function __construct() {
20
  $this->load_modules();
22
  }
23
 
24
  /**
 
25
  * load_modules
26
  *
27
  * Load CPTP_Modules.
28
  * @since 0.9.5
29
  *
30
+ */
 
31
  private function load_modules() {
32
  new CPTP_Module_Setting();
33
  new CPTP_Module_Rewrite();
34
  new CPTP_Module_Admin();
35
+ new CPTP_Module_Option();
36
  new CPTP_Module_Permalink();
37
  new CPTP_Module_GetArchives();
38
  new CPTP_Module_FlushRules();
39
+ do_action( 'CPTP_load_modules' );
40
 
41
  }
42
 
43
  /**
 
44
  * init
45
  *
46
  * Fire Module::add_hook
47
  *
48
  * @since 0.9.5
49
  *
50
+ */
 
51
  private function init() {
52
+ do_action( 'CPTP_init' );
53
  }
54
 
55
  /**
58
  */
59
  public static function get_instance() {
60
 
61
+ if ( ! isset( self::$_instance ) ) {
62
+ self::$_instance = new CPTP;
63
  }
64
 
65
+ return self::$_instance;
66
  }
67
 
68
 
CPTP/Module.php CHANGED
@@ -4,7 +4,7 @@
4
  Abstract Class CPTP_Module {
5
 
6
  public function __construct() {
7
- add_action("CPTP_init", array( $this, "add_hook" ));
8
  }
9
 
10
  abstract function add_hook();
4
  Abstract Class CPTP_Module {
5
 
6
  public function __construct() {
7
+ add_action( 'CPTP_init', array( $this, 'add_hook' ) );
8
  }
9
 
10
  abstract function add_hook();
CPTP/Module/Admin.php CHANGED
@@ -4,7 +4,7 @@
4
 
5
  /**
6
  *
7
- * Admin Page.
8
  *
9
  * @package Custom_Post_Type_Permalinks
10
  * @since 0.9.4
@@ -14,11 +14,12 @@
14
  class CPTP_Module_Admin extends CPTP_Module {
15
 
16
  public function add_hook() {
17
- add_action( 'admin_init', array( $this,'settings_api_init'), 30 );
18
- add_action( 'admin_enqueue_scripts', array( $this,'enqueue_css_js') );
19
- add_action( 'admin_footer', array( $this,'pointer_js') );
20
  }
21
 
 
22
  /**
23
  *
24
  * Setting Init
@@ -26,111 +27,113 @@ class CPTP_Module_Admin extends CPTP_Module {
26
  *
27
  */
28
  public function settings_api_init() {
29
- add_settings_section('cptp_setting_section',
30
- __("Permalink Setting for custom post type",'cptp'),
31
- array( $this,'setting_section_callback_function'),
32
  'permalink'
33
  );
34
 
35
  $post_types = CPTP_Util::get_post_types();
36
- foreach ($post_types as $post_type):
37
- if(isset($_POST['submit']) and isset($_POST['_wp_http_referer'])){
38
- if( strpos($_POST['_wp_http_referer'],'options-permalink.php') !== FALSE ) {
39
-
40
- $structure = trim(esc_attr($_POST[$post_type.'_structure']));#get setting
41
-
42
- #default permalink structure
43
- if( !$structure )
44
- $structure = CPTP_DEFAULT_PERMALINK;
45
-
46
- $structure = str_replace('//','/','/'.$structure);# first "/"
47
 
48
- #last "/"
49
- $lastString = substr(trim(esc_attr($_POST['permalink_structure'])),-1);
50
- $structure = rtrim($structure,'/');
51
-
52
- if ( $lastString == '/')
53
- $structure = $structure.'/';
54
-
55
- update_option($post_type.'_structure', $structure );
56
- }
57
- }
58
-
59
- add_settings_field($post_type.'_structure',
60
  $post_type,
61
- array( $this,'setting_structure_callback_function'),
62
  'permalink',
63
  'cptp_setting_section',
64
  $post_type.'_structure'
65
  );
66
 
67
- register_setting('permalink',$post_type.'_structure');
68
  endforeach;
69
 
70
  add_settings_field(
71
  'no_taxonomy_structure',
72
- __("Use custom permalink of custom taxonomy archive.",'cptp'),
73
- array( $this,'setting_no_tax_structure_callback_function'),
74
  'permalink',
75
  'cptp_setting_section'
76
  );
77
 
78
- register_setting('permalink','no_taxonomy_structure');
79
 
80
- if(isset($_POST['submit']) && isset($_POST['_wp_http_referer']) && strpos($_POST['_wp_http_referer'],'options-permalink.php') !== false ) {
 
 
 
 
 
 
 
 
81
 
82
- if(!isset($_POST['no_taxonomy_structure'])){
83
- $set = true;
84
- }else {
85
- $set = false;
86
- }
87
- update_option('no_taxonomy_structure', $set);
88
- }
89
  }
90
 
91
  public function setting_section_callback_function() {
92
  ?>
93
- <p><?php _e("Setting permalinks of custom post type.",'cptp');?><br />
94
- <?php _e("The tags you can use is WordPress Structure Tags and '%\"custom_taxonomy_slug\"%'. (e.g. %actors%)",'cptp');?><br />
95
- <?php _e("%\"custom_taxonomy_slug\"% is replaced the taxonomy's term.'.",'cptp');?></p>
96
 
97
- <p><?php _e("Presence of the trailing '/' is unified into a standard permalink structure setting.",'cptp');?>
98
- <p><?php _e("If <code>has_archive</code> is true, add permalinks for custom post type archive.",'cptp');?>
99
- <?php _e("If you don't entered permalink structure, permalink is configured /%postname%/'.",'cptp');?>
100
  </p>
101
  <?php
102
  }
103
 
104
  public function setting_structure_callback_function( $option ) {
105
- $post_type = str_replace('_structure',"" ,$option);
106
- $pt_object = get_post_type_object($post_type);
 
107
  $slug = $pt_object->rewrite['slug'];
108
  $with_front = $pt_object->rewrite['with_front'];
109
 
110
- $value = get_option($option);
111
- if( !$value )
 
 
 
 
 
 
112
  $value = CPTP_DEFAULT_PERMALINK;
 
113
 
114
  global $wp_rewrite;
115
  $front = substr( $wp_rewrite->front, 1 );
116
- if( $front and $with_front ) {
117
  $slug = $front.$slug;
118
  }
119
 
120
- echo '<p><code>'.home_url().'/'.$slug.'</code> <input name="'.$option.'" id="'.$option.'" type="text" class="regular-text code" value="' . $value .'" /></p>';
121
  echo '<p>has_archive: <code>';
122
- echo $pt_object->has_archive ? "true" : "false";
123
  echo '</code> / ';
124
  echo 'with_front: <code>';
125
- echo $pt_object->rewrite['with_front'] ? "true" : "false";
126
  echo '</code></p>';
127
 
128
  }
129
 
 
 
 
 
 
 
 
130
  public function setting_no_tax_structure_callback_function(){
131
- echo '<input name="no_taxonomy_structure" id="no_taxonomy_structure" type="checkbox" value="1" class="code" ' . checked( false, get_option('no_taxonomy_structure'),false) . ' /> ';
132
- $txt = __("If you check,The custom taxonomy's permalinks is <code>%s/post_type/taxonomy/term</code>.","cptp");
133
- printf($txt , home_url());
 
 
 
 
 
 
 
134
  }
135
 
136
 
@@ -142,8 +145,8 @@ class CPTP_Module_Admin extends CPTP_Module {
142
  *
143
  */
144
  public function enqueue_css_js() {
145
- wp_enqueue_style('wp-pointer');
146
- wp_enqueue_script('wp-pointer');
147
  }
148
 
149
 
@@ -154,10 +157,10 @@ class CPTP_Module_Admin extends CPTP_Module {
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(array_search('cptp_pointer0871', $dismissed) === false){
160
- $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>", "cptp");
161
  ?>
162
  <script type="text/javascript">
163
  jQuery(function($) {
@@ -166,7 +169,7 @@ class CPTP_Module_Admin extends CPTP_Module {
166
  content: "<?php echo $content;?>",
167
  position: {"edge":"left","align":"center"},
168
  close: function() {
169
- $.post('admin-ajax.php', {
170
  action:'dismiss-wp-pointer',
171
  pointer: 'cptp_pointer0871'
172
  })
4
 
5
  /**
6
  *
7
+ * Admin Page View.
8
  *
9
  * @package Custom_Post_Type_Permalinks
10
  * @since 0.9.4
14
  class CPTP_Module_Admin extends CPTP_Module {
15
 
16
  public function add_hook() {
17
+ add_action( 'admin_init', array( $this, 'settings_api_init' ), 30 );
18
+ add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_css_js' ) );
19
+ add_action( 'admin_footer', array( $this, 'pointer_js' ) );
20
  }
21
 
22
+
23
  /**
24
  *
25
  * Setting Init
27
  *
28
  */
29
  public function settings_api_init() {
30
+ add_settings_section( 'cptp_setting_section',
31
+ __( 'Permalink Setting for custom post type', 'cptp' ),
32
+ array( $this, 'setting_section_callback_function' ),
33
  'permalink'
34
  );
35
 
36
  $post_types = CPTP_Util::get_post_types();
37
+ foreach ( $post_types as $post_type ):
 
 
 
 
 
 
 
 
 
 
38
 
39
+ add_settings_field( $post_type.'_structure',
 
 
 
 
 
 
 
 
 
 
 
40
  $post_type,
41
+ array( $this, 'setting_structure_callback_function' ),
42
  'permalink',
43
  'cptp_setting_section',
44
  $post_type.'_structure'
45
  );
46
 
47
+ register_setting( 'permalink',$post_type.'_structure' );
48
  endforeach;
49
 
50
  add_settings_field(
51
  'no_taxonomy_structure',
52
+ __( 'Use custom permalink of custom taxonomy archive.', 'cptp' ),
53
+ array( $this, 'setting_no_tax_structure_callback_function' ),
54
  'permalink',
55
  'cptp_setting_section'
56
  );
57
 
58
+ register_setting( 'permalink', 'no_taxonomy_structure' );
59
 
60
+ add_settings_field(
61
+ 'add_post_type_for_tax.',
62
+ __( 'Add post_type query for custom taxonomy archive.', 'cptp' ),
63
+ array( $this, 'add_post_type_for_tax_callback_function' ),
64
+ 'permalink',
65
+ 'cptp_setting_section'
66
+ );
67
+
68
+ register_setting( 'permalink', 'no_taxonomy_structure' );
69
 
 
 
 
 
 
 
 
70
  }
71
 
72
  public function setting_section_callback_function() {
73
  ?>
74
+ <p><?php _e( 'Setting permalinks of custom post type.', 'cptp' );?><br />
75
+ <?php _e( "The tags you can use is WordPress Structure Tags and '%\"custom_taxonomy_slug\"%'. (e.g. %actors%)", 'cptp' );?><br />
76
+ <?php _e( "%\"custom_taxonomy_slug\"% is replaced the taxonomy's term.'.", 'cptp' );?></p>
77
 
78
+ <p><?php _e( "Presence of the trailing '/' is unified into a standard permalink structure setting.", 'cptp' );?>
79
+ <p><?php _e( 'If <code>has_archive</code> is true, add permalinks for custom post type archive.', 'cptp' );?>
80
+ <?php _e( "If you don't entered permalink structure, permalink is configured /%postname%/'.", 'cptp' );?>
81
  </p>
82
  <?php
83
  }
84
 
85
  public function setting_structure_callback_function( $option ) {
86
+
87
+ $post_type = str_replace( '_structure', '' ,$option );
88
+ $pt_object = get_post_type_object( $post_type );
89
  $slug = $pt_object->rewrite['slug'];
90
  $with_front = $pt_object->rewrite['with_front'];
91
 
92
+ $value = CPTP_Util::get_permalink_structure( $post_type );
93
+
94
+ $disabled = false;
95
+ if ( isset( $pt_object->cptp_permalink_structure ) and $pt_object->cptp_permalink_structure ) {
96
+ $disabled = true;
97
+ }
98
+
99
+ if ( ! $value ) {
100
  $value = CPTP_DEFAULT_PERMALINK;
101
+ }
102
 
103
  global $wp_rewrite;
104
  $front = substr( $wp_rewrite->front, 1 );
105
+ if ( $front and $with_front ) {
106
  $slug = $front.$slug;
107
  }
108
 
109
+ echo '<p><code>'.home_url().'/'.esc_html( $slug ).'</code> <input name="'.esc_attr( $option ).'" id="'.esc_attr( $option ).'" type="text" class="regular-text code '.$this->disabled_string($disabled).'" value="' . $value .'" '.$this->disabled_string($disabled).' /></p>';
110
  echo '<p>has_archive: <code>';
111
+ echo $pt_object->has_archive ? 'true' : 'false';
112
  echo '</code> / ';
113
  echo 'with_front: <code>';
114
+ echo $pt_object->rewrite['with_front'] ? 'true' : 'false';
115
  echo '</code></p>';
116
 
117
  }
118
 
119
+ private function disabled_string( $bool ) {
120
+ if ( $bool ) {
121
+ return 'disabled';
122
+ }
123
+ return '';
124
+ }
125
+
126
  public function setting_no_tax_structure_callback_function(){
127
+ echo '<input name="no_taxonomy_structure" id="no_taxonomy_structure" type="checkbox" value="1" class="code" ' . checked( false, get_option( 'no_taxonomy_structure' ), false ) . ' /> ';
128
+ $txt = __( "If you check,The custom taxonomy's permalinks is <code>%s/post_type/taxonomy/term</code>.", 'cptp' );
129
+ printf( $txt , home_url() );
130
+ }
131
+
132
+
133
+ public function add_post_type_for_tax_callback_function() {
134
+ 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 ) . ' /> ';
135
+ _e( "custom taxonomy archive also works as post type archive.", 'cptp' );
136
+ _e( "There are cases when template to be loaded is changed.", 'cptp' );
137
  }
138
 
139
 
145
  *
146
  */
147
  public function enqueue_css_js() {
148
+ wp_enqueue_style( 'wp-pointer' );
149
+ wp_enqueue_script( 'wp-pointer' );
150
  }
151
 
152
 
157
  * @since 0.8.5
158
  */
159
  public function pointer_js() {
160
+ if ( ! is_network_admin() ) {
161
+ $dismissed = explode( ',', get_user_meta( get_current_user_id(), 'dismissed_wp_pointers', true ) );
162
+ if ( false === array_search( 'cptp_pointer0871', $dismissed ) ) {
163
+ $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>" , 'cptp' );
164
  ?>
165
  <script type="text/javascript">
166
  jQuery(function($) {
169
  content: "<?php echo $content;?>",
170
  position: {"edge":"left","align":"center"},
171
  close: function() {
172
+ $.post( 'admin-ajax.php', {
173
  action:'dismiss-wp-pointer',
174
  pointer: 'cptp_pointer0871'
175
  })
CPTP/Module/FlushRules.php CHANGED
@@ -13,42 +13,46 @@ class CPTP_Module_FlushRules extends CPTP_Module {
13
 
14
 
15
  public function add_hook() {
16
- add_action( 'init', array( $this, 'update_rules') );
17
- add_action( 'update_option_cptp_version', array( $this, 'update_rules') );
18
- add_action( 'wp_loaded', array( $this, "dequeue_flush_rules"),100);
 
 
 
 
19
  }
20
 
 
 
21
  /**
22
  *
23
- * dequeue flush rules
24
- * @since 0.9
25
  *
26
  */
 
27
 
28
- public function dequeue_flush_rules () {
29
- if(get_option("queue_flush_rules")){
30
- flush_rewrite_rules();
31
- update_option( "queue_flush_rules", 0 );
32
-
33
- }
34
  }
35
 
36
 
37
  /**
38
  *
39
- * Add hook flush_rules
40
- * @since 0.7.9
41
  *
42
  */
43
- public function update_rules() {
44
 
45
- $post_types = CPTP_Util::get_post_types();
46
- $type_count = count($post_types);
47
- $i = 0;
48
- foreach ($post_types as $post_type):
49
- add_action('update_option_'.$post_type.'_structure',array( $this,'queue_flush_rules'),10,2);
50
- endforeach;
51
- add_action('update_option_no_taxonomy_structure',array( $this,'queue_flush_rules'),10,2);
52
  }
53
 
54
 
@@ -60,8 +64,12 @@ class CPTP_Module_FlushRules extends CPTP_Module {
60
  *
61
  */
62
 
63
- public function queue_flush_rules(){
64
- update_option( "queue_flush_rules", 1 );
 
 
 
 
65
  }
66
 
67
  }
13
 
14
 
15
  public function add_hook() {
16
+ add_action( 'init', array( $this, 'update_rules' ) );
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
+
26
+
27
  /**
28
  *
29
+ * Add hook flush_rules
30
+ * @since 0.7.9
31
  *
32
  */
33
+ public function update_rules() {
34
 
35
+ $post_types = CPTP_Util::get_post_types();
36
+ foreach ( $post_types as $post_type ):
37
+ add_action( 'update_option_'.$post_type.'_structure', array( __CLASS__, 'queue_flush_rules' ), 10, 2 );
38
+ endforeach;
39
+ add_action( 'update_option_no_taxonomy_structure', array( __CLASS__, 'queue_flush_rules' ), 10, 2 );
 
40
  }
41
 
42
 
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 );
54
+
55
+ }
 
56
  }
57
 
58
 
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
  }
CPTP/Module/GetArchives.php CHANGED
@@ -13,10 +13,10 @@
13
  class CPTP_Module_GetArchives extends CPTP_Module {
14
 
15
  public function add_hook() {
16
- if(get_option( "permalink_structure") != "") {
17
- add_filter( 'getarchives_join', array( $this,'getarchives_join'), 10, 2 ); // [steve]
18
- add_filter( 'getarchives_where', array( $this,'getarchives_where'), 10 , 2 );
19
- add_filter( 'get_archives_link', array( $this,'get_archives_link'), 20, 1 );
20
  }
21
 
22
  }
@@ -34,11 +34,11 @@ class CPTP_Module_GetArchives extends CPTP_Module {
34
  // function modified by [steve]
35
  public function getarchives_where( $where, $r ) {
36
  $this->get_archives_where_r = $r;
37
- if ( isset($r['post_type']) ) {
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
  }
@@ -61,8 +61,9 @@ class CPTP_Module_GetArchives extends CPTP_Module {
61
  public function getarchives_join( $join, $r ) {
62
  global $wpdb;
63
  $this->get_archives_where_r = $r;
64
- if(isset($r['taxonomy']) && is_array($r['taxonomy']) )
65
- $join = $join . " INNER JOIN $wpdb->term_relationships ON ($wpdb->posts.ID = $wpdb->term_relationships.object_id) INNER JOIN $wpdb->term_taxonomy ON ($wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id)";
 
66
 
67
  return $join;
68
  }
@@ -78,52 +79,48 @@ class CPTP_Module_GetArchives extends CPTP_Module {
78
  public function get_archives_link( $link ) {
79
  global $wp_rewrite;
80
 
81
-
82
- if(!isset($this->get_archives_where_r['post_type'])) {
83
  return $link;
84
  }
85
 
86
- $c = isset($this->get_archives_where_r['taxonomy']) && is_array($this->get_archives_where_r['taxonomy']) ? $this->get_archives_where_r['taxonomy'] : ""; //[steve]
87
- $t = $this->get_archives_where_r['post_type'];
88
-
89
 
90
  $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]
91
 
92
- if (isset($this->get_archives_where_r['post_type']) and $this->get_archives_where_r['type'] != 'postbypost'){
93
- $blog_url = rtrim( home_url() ,'/');
94
 
95
  //remove front
96
  $front = substr( $wp_rewrite->front, 1 );
97
- $link = str_replace($front,"",$link);
98
 
99
- $blog_url = preg_replace('/https?:\/\//', '', $blog_url);
100
- $ret_link = str_replace($blog_url,$blog_url.'/'.'%link_dir%',$link);
101
 
102
  $post_type = get_post_type_object( $this->get_archives_where_r['post_type'] );
103
- if(empty($c) ){ // [steve]
104
- if(isset( $post_type->rewrite["slug"] )) {
105
- $link_dir = $post_type->rewrite["slug"];
106
  }
107
- else{
108
  $link_dir = $this->get_archives_where_r['post_type'];
109
  }
110
  }
111
- else{ // [steve]
112
- $c['name'] = ($c['name'] == 'category' && get_option('category_base')) ? get_option('category_base') : $c['name'];
113
- $link_dir = $post_type->rewrite["slug"]."/".$c['name']."/".$c['termslug'];
114
  }
115
 
116
- if(!strstr($link,'/date/')){
117
- $link_dir = $link_dir .'/date';
118
  }
119
 
120
- if($post_type->rewrite['with_front']) {
121
  $link_dir = $front.$link_dir;
122
- }else {
123
  }
124
 
125
-
126
- $ret_link = str_replace('%link_dir%',$link_dir,$ret_link);
127
  }else {
128
  $ret_link = $link;
129
  }
13
  class CPTP_Module_GetArchives extends CPTP_Module {
14
 
15
  public function add_hook() {
16
+ if ( get_option( 'permalink_structure' ) != '' ) {
17
+ add_filter( 'getarchives_join', array( $this, 'getarchives_join' ), 10, 2 ); // [steve]
18
+ add_filter( 'getarchives_where', array( $this, 'getarchives_where' ), 10 , 2 );
19
+ add_filter( 'get_archives_link', array( $this, 'get_archives_link' ), 20, 1 );
20
  }
21
 
22
  }
34
  // function modified by [steve]
35
  public function getarchives_where( $where, $r ) {
36
  $this->get_archives_where_r = $r;
37
+ if ( isset( $r['post_type'] ) ) {
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
  }
61
  public function getarchives_join( $join, $r ) {
62
  global $wpdb;
63
  $this->get_archives_where_r = $r;
64
+ if ( isset( $r['taxonomy'] ) && is_array( $r['taxonomy'] ) ) {
65
+ $join = $join . " INNER JOIN $wpdb->term_relationships ON ($wpdb->posts.ID = $wpdb->term_relationships.object_id) INNER JOIN $wpdb->term_taxonomy ON ($wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id)";
66
+ }
67
 
68
  return $join;
69
  }
79
  public function get_archives_link( $link ) {
80
  global $wp_rewrite;
81
 
82
+ if ( ! isset( $this->get_archives_where_r['post_type'] ) ) {
 
83
  return $link;
84
  }
85
 
86
+ $c = isset( $this->get_archives_where_r['taxonomy'] ) && is_array( $this->get_archives_where_r['taxonomy'] ) ? $this->get_archives_where_r['taxonomy'] : ''; //[steve]
87
+ $t = $this->get_archives_where_r['post_type'];
 
88
 
89
  $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]
90
 
91
+ if ( isset( $this->get_archives_where_r['post_type'] ) and 'postbypost' != $this->get_archives_where_r['type'] ) {
92
+ $blog_url = rtrim( home_url() ,'/' );
93
 
94
  //remove front
95
  $front = substr( $wp_rewrite->front, 1 );
96
+ $link = str_replace( $front, '', $link );
97
 
98
+ $blog_url = preg_replace( '/https?:\/\//', '', $blog_url );
99
+ $ret_link = str_replace( $blog_url, $blog_url.'/'.'%link_dir%', $link );
100
 
101
  $post_type = get_post_type_object( $this->get_archives_where_r['post_type'] );
102
+ if ( empty( $c ) ) { // [steve]
103
+ if ( isset( $post_type->rewrite['slug'] ) ) {
104
+ $link_dir = $post_type->rewrite['slug'];
105
  }
106
+ else {
107
  $link_dir = $this->get_archives_where_r['post_type'];
108
  }
109
  }
110
+ else { // [steve]
111
+ $c['name'] = ( $c['name'] == 'category' && get_option( 'category_base' ) ) ? get_option( 'category_base' ) : $c['name'];
112
+ $link_dir = $post_type->rewrite['slug'].'/'.$c['name'].'/'.$c['termslug'];
113
  }
114
 
115
+ if ( ! strstr( $link, '/date/' ) ) {
116
+ $link_dir = $link_dir . CPTP_Util::get_date_front( $post_type );
117
  }
118
 
119
+ if ( $post_type->rewrite['with_front'] ) {
120
  $link_dir = $front.$link_dir;
 
121
  }
122
 
123
+ $ret_link = str_replace( '%link_dir%', $link_dir, $ret_link );
 
124
  }else {
125
  $ret_link = $link;
126
  }
CPTP/Module/Option.php ADDED
@@ -0,0 +1,65 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+
4
+
5
+ /**
6
+ *
7
+ * Options.
8
+ *
9
+ * Save Options.
10
+ *
11
+ * @package Custom_Post_Type_Permalinks
12
+ * @since 0.9.6
13
+ *
14
+ * */
15
+
16
+ class CPTP_Module_Option extends CPTP_Module {
17
+
18
+ public function add_hook() {
19
+ add_action( 'admin_init', array( $this, 'save_options' ), 30 );
20
+ register_uninstall_hook( CPTP_PLUGIN_FILE, array( __CLASS__, 'uninstall_hook' ) );
21
+ }
22
+
23
+ public function save_options() {
24
+
25
+ if ( isset( $_POST['submit'] ) and isset( $_POST['_wp_http_referer'] ) ){
26
+ if ( false !== strpos( $_POST['_wp_http_referer'], 'options-permalink.php' ) ) {
27
+ $post_types = CPTP_Util::get_post_types();
28
+ foreach ( $post_types as $post_type ):
29
+
30
+ $structure = trim( esc_attr( $_POST[ $post_type.'_structure' ] ) );#get setting
31
+
32
+ #default permalink structure
33
+ if ( ! $structure ) {
34
+ $structure = CPTP_DEFAULT_PERMALINK;
35
+ }
36
+
37
+ $structure = str_replace( '//', '/', '/'.$structure );# first "/"
38
+ #last "/"
39
+ $lastString = substr( trim( esc_attr( $_POST['permalink_structure'] ) ), -1 );
40
+ $structure = rtrim( $structure, '/' );
41
+
42
+ if ( $lastString == '/' ) {
43
+ $structure = $structure.'/';
44
+ }
45
+
46
+ update_option( $post_type.'_structure', $structure );
47
+ endforeach;
48
+ }
49
+ update_option( 'no_taxonomy_structure', ! isset( $_POST['no_taxonomy_structure'] ) );
50
+ update_option( 'add_post_type_for_tax', isset( $_POST['add_post_type_for_tax'] ) );
51
+
52
+
53
+ }
54
+ }
55
+
56
+ public static function uninstall_hook() {
57
+ foreach ( CPTP_Util::get_post_types() as $post_type ) {
58
+ delete_option( $post_type.'_structure' );
59
+ }
60
+
61
+ delete_option( 'no_taxonomy_structure' );
62
+ }
63
+
64
+
65
+ }
CPTP/Module/Permalink.php CHANGED
@@ -16,13 +16,12 @@ class CPTP_Module_Permalink extends CPTP_Module {
16
 
17
 
18
  public function add_hook() {
19
- if(get_option( "permalink_structure") != "") {
20
- add_filter( 'post_type_link', array( $this,'post_type_link'), 10, 4 );
21
- add_filter( 'term_link', array( $this,'term_link'), 10, 3 );
22
- add_filter( 'attachment_link', array( $this, 'attachment_link'), 20 , 2);
23
- }
24
  }
25
 
 
26
  /**
27
  *
28
  * Fix permalinks output.
@@ -33,127 +32,139 @@ class CPTP_Module_Permalink extends CPTP_Module {
33
  *
34
  * @version 2.0
35
  *
 
36
  */
37
  public function post_type_link( $post_link, $post, $leavename ) {
38
- global $wp_rewrite;
39
- $draft_or_pending = isset( $post->post_status ) && in_array( $post->post_status, array( 'draft', 'pending', 'auto-draft' ) );
40
- if( $draft_or_pending and !$leavename )
 
41
  return $post_link;
 
42
 
43
 
 
 
 
 
44
 
45
  $post_type = $post->post_type;
46
  $permalink = $wp_rewrite->get_extra_permastruct( $post_type );
 
47
 
48
  $permalink = str_replace( '%post_id%', $post->ID, $permalink );
49
- $permalink = str_replace( '%'.$post_type.'_slug%', get_post_type_object( $post_type )->rewrite['slug'], $permalink );
50
-
51
-
52
 
53
  //親ページが有るとき。
54
- $parentsDirs = "";
55
- if( !$leavename ){
56
- $postId = $post->ID;
57
- while ($parent = get_post($postId)->post_parent) {
58
- $parentsDirs = get_post($parent)->post_name."/".$parentsDirs;
59
- $postId = $parent;
 
 
60
  }
61
  }
62
 
63
  $permalink = str_replace( '%'.$post_type.'%', $parentsDirs.'%'.$post_type.'%', $permalink );
64
 
65
- if( !$leavename ){
66
  $permalink = str_replace( '%'.$post_type.'%', $post->post_name, $permalink );
67
  }
68
 
69
  //%post_id%/attachment/%attachement_name%;
70
  //画像の編集ページでのリンク
71
- if( isset($_GET["post"]) && $_GET["post"] != $post->ID ) {
72
- $parent_structure = trim( CPTP_Util::get_permalink_structure( $this->post_type ), "/");
73
- $parent_dirs = explode( "/", $parent_structure );
74
- if(is_array($parent_dirs)) {
75
  $last_dir = array_pop( $parent_dirs );
76
  }
77
  else {
78
  $last_dir = $parent_dirs;
79
  }
80
 
81
- if( "%post_id%" == $parent_structure or "%post_id%" == $last_dir ) {
82
- $permalink = $permalink."/attachment/";
83
- };
84
  }
85
 
86
  $search = array();
87
  $replace = array();
88
 
89
  $replace_tag = $this->create_taxonomy_replace_tag( $post->ID , $permalink );
90
- $search = $search + $replace_tag["search"];
91
- $replace = $replace + $replace_tag["replace"];
92
-
93
 
94
  //from get_permalink.
95
  $category = '';
96
- if ( strpos($permalink, '%category%') !== false ) {
97
- $cats = get_the_category($post->ID);
98
- if ( $cats ) {
99
- usort($cats, '_usort_terms_by_ID'); // order by ID
100
- $category_object = apply_filters( 'post_link_category', $cats[0], $cats, $post );
101
  $category_object = get_term( $category_object, 'category' );
102
  $category = $category_object->slug;
103
- if ( $parent = $category_object->parent )
104
- $category = get_category_parents($parent, false, '/', true) . $category;
 
105
  }
106
  // show default category in permalinks, without
107
  // having to assign it explicitly
108
- if ( empty($category) ) {
109
  $default_category = get_term( get_option( 'default_category' ), 'category' );
110
  $category = is_wp_error( $default_category ) ? '' : $default_category->slug;
111
  }
112
  }
113
 
114
  $author = '';
115
- if ( strpos($permalink, '%author%') !== false ) {
116
- $authordata = get_userdata($post->post_author);
117
  $author = $authordata->user_nicename;
118
  }
119
 
120
-
121
  $post_date = strtotime( $post->post_date );
122
- $permalink = str_replace(array(
123
- "%year%",
124
- "%monthnum%",
125
- "%day%",
126
- "%hour%",
127
- "%minute%",
128
- "%second%",
129
- '%category%',
130
- '%author%'
131
-
132
- ), array(
133
- date("Y",$post_date),
134
- date("m",$post_date),
135
- date("d",$post_date),
136
- date("H",$post_date),
137
- date("i",$post_date),
138
- date("s",$post_date),
139
- $category,
140
- $author
141
-
142
- ), $permalink );
143
- $permalink = str_replace($search, $replace, $permalink);
144
- $permalink = rtrim( home_url(),"/")."/".ltrim( $permalink ,"/" );
 
 
145
 
146
  return $permalink;
147
  }
148
 
149
 
150
-
151
  /**
152
  *
153
  * create %tax% -> term
154
  *
155
- * */
156
- private function create_taxonomy_replace_tag( $post_id , $permalink ) {
 
 
 
 
157
  $search = array();
158
  $replace = array();
159
 
@@ -164,47 +175,44 @@ class CPTP_Module_Permalink extends CPTP_Module {
164
 
165
  foreach ( $taxonomies as $taxonomy => $objects ) {
166
 
167
- if ( strpos($permalink, "%$taxonomy%") !== false ) {
168
- $terms = wp_get_post_terms( $post_id, $taxonomy, array('orderby' => 'term_id'));
169
-
170
- if( $terms and !is_wp_error($terms) ) {
171
 
172
- $parents = array_map( array(__CLASS__, 'get_term_parent'), $terms); //親の一覧
 
173
  $newTerms = array();
174
- foreach ($terms as $key => $term) {
175
- if( !in_array($term->term_id, $parents )) {
176
  $newTerms[] = $term;
177
  }
178
  }
179
 
180
  //このブロックだけで良いはず。
181
- $term_obj = reset($newTerms); //最初のOBjectのみを対象。
182
  $term_slug = $term_obj->slug;
183
 
184
- if(isset($term_obj->parent) and $term_obj->parent != 0) {
185
  $term_slug = CPTP_Util::get_taxonomy_parents( $term_obj->parent,$taxonomy, false, '/', true ) . $term_slug;
186
  }
187
  }
188
 
189
- if( isset($term_slug) ) {
190
- $search[] = "%$taxonomy%";
191
  $replace[] = $term_slug;
192
  }
193
-
194
  }
195
  }
196
 
197
- return array("search" => $search, "replace" => $replace );
198
  }
199
 
200
- private static function get_term_parent($term) {
201
- if(isset($term->parent) and $term->parent > 0) {
202
  return $term->parent;
203
  }
204
  }
205
 
206
 
207
-
208
  /**
209
  *
210
  * fix attachment output
@@ -212,20 +220,32 @@ class CPTP_Module_Permalink extends CPTP_Module {
212
  * @version 1.0
213
  * @since 0.8.2
214
  *
 
 
 
 
215
  */
216
 
217
- public function attachment_link( $link , $postID ) {
 
 
 
 
 
 
 
 
218
  $post = get_post( $postID );
219
- if (!$post->post_parent){
220
  return $link;
221
  }
222
  $post_parent = get_post( $post->post_parent );
223
  $permalink = CPTP_Util::get_permalink_structure( $post_parent->post_type );
224
  $post_type = get_post_type_object( $post_parent->post_type );
225
 
226
- if( $post_type->_builtin == false ) {
227
- if(strpos( $permalink, "%postname%" ) < strrpos( $permalink, "%post_id%" ) && strrpos( $permalink, "attachment/" ) === FALSE ){
228
- $link = str_replace($post->post_name , "attachment/".$post->post_name, $link);
229
  }
230
  }
231
 
@@ -238,40 +258,52 @@ class CPTP_Module_Permalink extends CPTP_Module {
238
  * @since 0.6
239
  * @version 1.0
240
  *
 
 
 
 
 
241
  */
242
  public function term_link( $termlink, $term, $taxonomy ) {
 
243
  global $wp_rewrite;
244
 
245
- if( get_option('no_taxonomy_structure') ) {
 
 
 
 
246
  return $termlink;
247
  }
248
 
249
- $taxonomy = get_taxonomy($taxonomy);
250
- if( $taxonomy->_builtin )
251
  return $termlink;
 
252
 
253
- if( empty($taxonomy) )
254
  return $termlink;
 
255
 
256
  $wp_home = rtrim( home_url(), '/' );
257
 
258
- if(in_array(get_post_type(), $taxonomy->object_type)){
259
  $post_type = get_post_type();
260
  }
261
  else {
262
  $post_type = $taxonomy->object_type[0];
263
  }
264
- $post_type_obj = get_post_type_object($post_type);
265
  $slug = $post_type_obj->rewrite['slug'];
266
  $with_front = $post_type_obj->rewrite['with_front'];
267
  $front = substr( $wp_rewrite->front, 1 );
268
- $termlink = str_replace($front,"",$termlink);
269
 
270
- if( $with_front ) {
271
  $slug = $front.$slug;
272
  }
273
 
274
- $termlink = str_replace( $wp_home, $wp_home."/".$slug, $termlink );
275
 
276
  if ( ! $taxonomy->rewrite['hierarchical'] ) {
277
  $termlink = str_replace( $term->slug.'/', CPTP_Util::get_taxonomy_parents( $term->term_id,$taxonomy->name, false, '/', true ), $termlink );
16
 
17
 
18
  public function add_hook() {
19
+ add_filter( 'post_type_link', array( $this, 'post_type_link' ), 10, 4 );
20
+ add_filter( 'term_link', array( $this, 'term_link' ), 10, 3 );
21
+ add_filter( 'attachment_link', array( $this, 'attachment_link' ), 20 , 2 );
 
 
22
  }
23
 
24
+
25
  /**
26
  *
27
  * Fix permalinks output.
32
  *
33
  * @version 2.0
34
  *
35
+ * @return string
36
  */
37
  public function post_type_link( $post_link, $post, $leavename ) {
38
+ global /** @var WP_Rewrite $wp_rewrite */
39
+ $wp_rewrite;
40
+
41
+ if ( !$wp_rewrite->permalink_structure ) {
42
  return $post_link;
43
+ }
44
 
45
 
46
+ $draft_or_pending = isset( $post->post_status ) && in_array( $post->post_status, array( 'draft', 'pending', 'auto-draft' ) );
47
+ if ( $draft_or_pending and ! $leavename ) {
48
+ return $post_link;
49
+ }
50
 
51
  $post_type = $post->post_type;
52
  $permalink = $wp_rewrite->get_extra_permastruct( $post_type );
53
+ $pt_object = get_post_type_object( $post_type );
54
 
55
  $permalink = str_replace( '%post_id%', $post->ID, $permalink );
56
+ $permalink = str_replace( '%'.$post_type.'_slug%', $pt_object->rewrite['slug'], $permalink );
 
 
57
 
58
  //親ページが有るとき。
59
+ $parentsDirs = '';
60
+ if ( $pt_object->hierarchical ) {
61
+ if ( ! $leavename ){
62
+ $postId = $post->ID;
63
+ while ( $parent = get_post( $postId )->post_parent ) {
64
+ $parentsDirs = get_post( $parent )->post_name.'/'.$parentsDirs;
65
+ $postId = $parent;
66
+ }
67
  }
68
  }
69
 
70
  $permalink = str_replace( '%'.$post_type.'%', $parentsDirs.'%'.$post_type.'%', $permalink );
71
 
72
+ if ( ! $leavename ) {
73
  $permalink = str_replace( '%'.$post_type.'%', $post->post_name, $permalink );
74
  }
75
 
76
  //%post_id%/attachment/%attachement_name%;
77
  //画像の編集ページでのリンク
78
+ if ( isset( $_GET['post'] ) && $_GET['post'] != $post->ID ) {
79
+ $parent_structure = trim( CPTP_Util::get_permalink_structure( $post->post_type ), '/' );
80
+ $parent_dirs = explode( '/', $parent_structure );
81
+ if ( is_array( $parent_dirs ) ) {
82
  $last_dir = array_pop( $parent_dirs );
83
  }
84
  else {
85
  $last_dir = $parent_dirs;
86
  }
87
 
88
+ if ( '%post_id%' == $parent_structure or '%post_id%' == $last_dir ) {
89
+ $permalink = $permalink.'/attachment/';
90
+ }
91
  }
92
 
93
  $search = array();
94
  $replace = array();
95
 
96
  $replace_tag = $this->create_taxonomy_replace_tag( $post->ID , $permalink );
97
+ $search = $search + $replace_tag['search'];
98
+ $replace = $replace + $replace_tag['replace'];
 
99
 
100
  //from get_permalink.
101
  $category = '';
102
+ if ( false !== strpos( $permalink, '%category%' ) ) {
103
+ $categories = get_the_category( $post->ID );
104
+ if ( $categories ) {
105
+ usort( $categories, '_usort_terms_by_ID' ); // order by ID
106
+ $category_object = apply_filters( 'post_link_category', $categories[0], $categories, $post );
107
  $category_object = get_term( $category_object, 'category' );
108
  $category = $category_object->slug;
109
+ if ( $parent = $category_object->parent ) {
110
+ $category = get_category_parents( $parent, false, '/', true ) . $category;
111
+ }
112
  }
113
  // show default category in permalinks, without
114
  // having to assign it explicitly
115
+ if ( empty( $category ) ) {
116
  $default_category = get_term( get_option( 'default_category' ), 'category' );
117
  $category = is_wp_error( $default_category ) ? '' : $default_category->slug;
118
  }
119
  }
120
 
121
  $author = '';
122
+ if ( false !== strpos( $permalink, '%author%' ) ) {
123
+ $authordata = get_userdata( $post->post_author );
124
  $author = $authordata->user_nicename;
125
  }
126
 
 
127
  $post_date = strtotime( $post->post_date );
128
+ $permalink = str_replace(
129
+ array(
130
+ '%year%',
131
+ '%monthnum%',
132
+ '%day%',
133
+ '%hour%',
134
+ '%minute%',
135
+ '%second%',
136
+ '%category%',
137
+ '%author%',
138
+ ),
139
+ array(
140
+ date( 'Y', $post_date ),
141
+ date( 'm', $post_date ),
142
+ date( 'd', $post_date ),
143
+ date( 'H', $post_date ),
144
+ date( 'i', $post_date ),
145
+ date( 's', $post_date ),
146
+ $category,
147
+ $author,
148
+ ),
149
+ $permalink
150
+ );
151
+ $permalink = str_replace( $search, $replace, $permalink );
152
+ $permalink = rtrim( home_url(), '/' ).'/'.ltrim( $permalink, '/' );
153
 
154
  return $permalink;
155
  }
156
 
157
 
 
158
  /**
159
  *
160
  * create %tax% -> term
161
  *
162
+ * @param int $post_id
163
+ * @param string $permalink
164
+ *
165
+ * @return array
166
+ */
167
+ private function create_taxonomy_replace_tag( $post_id, $permalink ) {
168
  $search = array();
169
  $replace = array();
170
 
175
 
176
  foreach ( $taxonomies as $taxonomy => $objects ) {
177
 
178
+ if ( false !== strpos( $permalink, '%'.$taxonomy.'%' ) ) {
179
+ $terms = wp_get_post_terms( $post_id, $taxonomy, array( 'orderby' => 'term_id' ) );
 
 
180
 
181
+ if ( $terms and ! is_wp_error( $terms ) ) {
182
+ $parents = array_map( array( __CLASS__, 'get_term_parent' ), $terms ); //親の一覧
183
  $newTerms = array();
184
+ foreach ( $terms as $key => $term ) {
185
+ if ( ! in_array( $term->term_id, $parents ) ) {
186
  $newTerms[] = $term;
187
  }
188
  }
189
 
190
  //このブロックだけで良いはず。
191
+ $term_obj = reset( $newTerms ); //最初のOBjectのみを対象。
192
  $term_slug = $term_obj->slug;
193
 
194
+ if ( isset( $term_obj->parent ) and 0 != $term_obj->parent ) {
195
  $term_slug = CPTP_Util::get_taxonomy_parents( $term_obj->parent,$taxonomy, false, '/', true ) . $term_slug;
196
  }
197
  }
198
 
199
+ if ( isset( $term_slug ) ) {
200
+ $search[] = '%'.$taxonomy.'%';
201
  $replace[] = $term_slug;
202
  }
 
203
  }
204
  }
205
 
206
+ return array( 'search' => $search, 'replace' => $replace );
207
  }
208
 
209
+ private static function get_term_parent( $term ) {
210
+ if ( isset( $term->parent ) and $term->parent > 0 ) {
211
  return $term->parent;
212
  }
213
  }
214
 
215
 
 
216
  /**
217
  *
218
  * fix attachment output
220
  * @version 1.0
221
  * @since 0.8.2
222
  *
223
+ * @param string $link
224
+ * @param int $postID
225
+ *
226
+ * @return string
227
  */
228
 
229
+ public function attachment_link( $link, $postID ) {
230
+ /** @var WP_Rewrite $wp_rewrite */
231
+ global $wp_rewrite;
232
+
233
+ if ( !$wp_rewrite->permalink_structure ) {
234
+ return $link;
235
+ }
236
+
237
+
238
  $post = get_post( $postID );
239
+ if ( ! $post->post_parent ){
240
  return $link;
241
  }
242
  $post_parent = get_post( $post->post_parent );
243
  $permalink = CPTP_Util::get_permalink_structure( $post_parent->post_type );
244
  $post_type = get_post_type_object( $post_parent->post_type );
245
 
246
+ if ( false == $post_type->_builtin ) {
247
+ if ( strpos( $permalink, '%postname%' ) < strrpos( $permalink, '%post_id%' ) && false === strrpos( $permalink, 'attachment/' ) ){
248
+ $link = str_replace( $post->post_name, 'attachment/'.$post->post_name, $link );
249
  }
250
  }
251
 
258
  * @since 0.6
259
  * @version 1.0
260
  *
261
+ * @param string $termlink
262
+ * @param Object $term
263
+ * @param Object $taxonomy
264
+ *
265
+ * @return string
266
  */
267
  public function term_link( $termlink, $term, $taxonomy ) {
268
+ /** @var WP_Rewrite $wp_rewrite */
269
  global $wp_rewrite;
270
 
271
+ if ( !$wp_rewrite->permalink_structure ) {
272
+ return $termlink;
273
+ }
274
+
275
+ if ( get_option( 'no_taxonomy_structure' ) ) {
276
  return $termlink;
277
  }
278
 
279
+ $taxonomy = get_taxonomy( $taxonomy );
280
+ if ( $taxonomy->_builtin ) {
281
  return $termlink;
282
+ }
283
 
284
+ if ( empty( $taxonomy ) ) {
285
  return $termlink;
286
+ }
287
 
288
  $wp_home = rtrim( home_url(), '/' );
289
 
290
+ if ( in_array( get_post_type(), $taxonomy->object_type ) ) {
291
  $post_type = get_post_type();
292
  }
293
  else {
294
  $post_type = $taxonomy->object_type[0];
295
  }
296
+ $post_type_obj = get_post_type_object( $post_type );
297
  $slug = $post_type_obj->rewrite['slug'];
298
  $with_front = $post_type_obj->rewrite['with_front'];
299
  $front = substr( $wp_rewrite->front, 1 );
300
+ $termlink = str_replace( $front, '', $termlink );
301
 
302
+ if ( $with_front ) {
303
  $slug = $front.$slug;
304
  }
305
 
306
+ $termlink = str_replace( $wp_home, $wp_home.'/'.$slug, $termlink );
307
 
308
  if ( ! $taxonomy->rewrite['hierarchical'] ) {
309
  $termlink = str_replace( $term->slug.'/', CPTP_Util::get_taxonomy_parents( $term->term_id,$taxonomy->name, false, '/', true ), $termlink );
CPTP/Module/Rewrite.php CHANGED
@@ -1,7 +1,6 @@
1
  <?php
2
 
3
 
4
-
5
  /**
6
  *
7
  * Add Rewrite Rules
@@ -10,42 +9,93 @@
10
  * @since 0.9.4
11
  *
12
  * */
13
-
14
  class CPTP_Module_Rewrite extends CPTP_Module {
15
 
 
 
 
 
 
16
  public function add_hook() {
17
- add_action( 'parse_request', array( $this, "parse_request") );
18
- add_action( 'registered_post_type', array( $this,'registered_post_type'), 10, 2 );
19
- add_action( 'registered_taxonomy', array( $this,'registered_taxonomy'), 10, 3 );
 
 
 
20
  }
21
 
22
 
 
 
 
 
 
 
 
 
 
 
 
 
23
  /**
24
  *
25
  * registered_post_type
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
26
  * ** add rewrite tag for Custom Post Type.
27
  * @version 1.1
28
  * @since 0.9
29
  *
 
 
 
30
  */
31
 
32
- public function registered_post_type( $post_type, $args ) {
33
 
34
- global $wp_post_types, $wp_rewrite;
 
35
 
36
- if( $args->_builtin or !$args->publicly_queryable or !$args->show_ui ){
37
- return false;
38
  }
39
- $permalink = CPTP_Util::get_permalink_structure($post_type);
40
 
41
- if( !$permalink ) {
42
  $permalink = CPTP_DEFAULT_PERMALINK;
43
  }
44
 
45
- $permalink = '%'.$post_type.'_slug%'.$permalink;
46
- $permalink = str_replace( '%postname%', '%'.$post_type.'%', $permalink );
47
 
48
- add_rewrite_tag( '%'.$post_type.'_slug%', '('.$args->rewrite['slug'].')','post_type='.$post_type.'&slug=' );
49
 
50
  $taxonomies = CPTP_Util::get_taxonomies( true );
51
  foreach ( $taxonomies as $taxonomy => $objects ):
@@ -53,123 +103,194 @@ class CPTP_Module_Rewrite extends CPTP_Module {
53
  endforeach;
54
 
55
  $rewrite_args = $args->rewrite;
56
- if( !is_array($rewrite_args) ) {
57
- $rewrite_args = array( 'with_front' => $args->rewrite );
58
  }
59
 
60
- $rewrite_args["walk_dirs"] = false;
61
- add_permastruct( $post_type, $permalink, $rewrite_args);
62
-
63
 
64
 
65
  $slug = $args->rewrite['slug'];
66
- if( $args->has_archive ){
67
- if( is_string( $args->has_archive ) ){
68
  $slug = $args->has_archive;
69
  };
70
 
71
- if($args->rewrite['with_front']) {
72
- $slug = substr( $wp_rewrite->front, 1 ).$slug;
73
  }
74
 
75
- add_rewrite_rule( $slug.'/date/([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/feed/(feed|rdf|rss|rss2|atom)/?$', 'index.php?year=$matches[1]&monthnum=$matches[2]&day=$matches[3]&feed=$matches[4]&post_type='.$post_type, 'top' );
76
- add_rewrite_rule( $slug.'/date/([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/(feed|rdf|rss|rss2|atom)/?$', 'index.php?year=$matches[1]&monthnum=$matches[2]&day=$matches[3]&feed=$matches[4]&post_type='.$post_type, 'top' );
77
- add_rewrite_rule( $slug.'/date/([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/page/?([0-9]{1,})/?$', 'index.php?year=$matches[1]&monthnum=$matches[2]&day=$matches[3]&paged=$matches[4]&post_type='.$post_type, 'top' );
78
- add_rewrite_rule( $slug.'/date/([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/?$', 'index.php?year=$matches[1]&monthnum=$matches[2]&day=$matches[3]&post_type='.$post_type, 'top' );
79
- add_rewrite_rule( $slug.'/date/([0-9]{4})/([0-9]{1,2})/feed/(feed|rdf|rss|rss2|atom)/?$', 'index.php?year=$matches[1]&monthnum=$matches[2]&feed=$matches[3]&post_type='.$post_type, 'top' );
80
- add_rewrite_rule( $slug.'/date/([0-9]{4})/([0-9]{1,2})/(feed|rdf|rss|rss2|atom)/?$', 'index.php?year=$matches[1]&monthnum=$matches[2]&feed=$matches[3]&post_type='.$post_type, 'top' );
81
- add_rewrite_rule( $slug.'/date/([0-9]{4})/([0-9]{1,2})/page/?([0-9]{1,})/?$', 'index.php?year=$matches[1]&monthnum=$matches[2]&paged=$matches[3]&post_type='.$post_type, 'top' );
82
- add_rewrite_rule( $slug.'/date/([0-9]{4})/([0-9]{1,2})/?$', 'index.php?year=$matches[1]&monthnum=$matches[2]&post_type='.$post_type, 'top' );
83
- add_rewrite_rule( $slug.'/date/([0-9]{4})/feed/(feed|rdf|rss|rss2|atom)/?$', 'index.php?year=$matches[1]&feed=$matches[2]&post_type='.$post_type, 'top' );
84
- add_rewrite_rule( $slug.'/date/([0-9]{4})/(feed|rdf|rss|rss2|atom)/?$', 'index.php?year=$matches[1]&feed=$matches[2]&post_type='.$post_type, 'top' );
85
- add_rewrite_rule( $slug.'/date/([0-9]{4})/page/?([0-9]{1,})/?$', 'index.php?year=$matches[1]&paged=$matches[2]&post_type='.$post_type, 'top' );
86
- add_rewrite_rule( $slug.'/date/([0-9]{4})/?$', 'index.php?year=$matches[1]&post_type='.$post_type, 'top' );
87
- add_rewrite_rule( $slug.'/author/([^/]+)/?$', 'index.php?author_name=$matches[1]&post_type='.$post_type, 'top' );
 
 
 
 
 
 
 
88
  }
89
-
90
-
91
-
92
  }
93
 
94
 
95
- public function registered_taxonomy( $taxonomy, $object_type, $args ) {
 
 
 
 
 
 
 
 
 
 
96
 
97
- if(get_option('no_taxonomy_structure')) {
98
- return false;
99
  }
100
- if($args["_builtin"]) {
101
- return false;
102
  }
103
 
104
  global $wp_rewrite;
105
 
106
- $taxonomyObject = $args;
107
- $post_types = $args["object_type"];
108
- foreach ($post_types as $post_type):
109
- $post_type_obj = get_post_type_object($post_type);
110
- if(!empty($post_type_obj->rewrite['slug'])){
111
  $slug = $post_type_obj->rewrite['slug'];
112
- }
113
- else {
114
  $slug = $post_type;
115
  }
116
 
117
- if(!empty($post_type_obj->has_archive) && is_string($post_type_obj->has_archive)) {
118
  $slug = $post_type_obj->has_archive;
119
  };
120
 
121
- if(!empty($post_type_obj->rewrite['with_front'])) {
122
- $slug = substr( $wp_rewrite->front, 1 ).$slug;
 
123
  }
124
 
125
- if ( $taxonomy == 'category' ){
126
- $taxonomypat = ($cb = get_option('category_base')) ? $cb : $taxonomy;
127
- $tax = 'category_name';
128
  } else {
129
  // Edit by [Xiphe]
130
- if (isset($args["rewrite"]['slug'])) {
131
- $taxonomypat = $args["rewrite"]['slug'];
132
  } else {
133
- $taxonomypat = $taxonomy;
134
  }
135
  // [Xiphe] stop
136
 
137
- $tax = $taxonomy;
138
  }
139
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
140
 
141
- //add taxonomy slug
142
- add_rewrite_rule( $slug.'/'.$taxonomypat.'/(.+?)/page/?([0-9]{1,})/?$', 'index.php?'.$tax.'=$matches[1]&paged=$matches[2]', 'top' );
143
- add_rewrite_rule( $slug.'/'.$taxonomypat.'/(.+?)/feed/(feed|rdf|rss|rss2|atom)/?$', 'index.php?'.$tax.'=$matches[1]&feed=$matches[2]', 'top' );
144
- add_rewrite_rule( $slug.'/'.$taxonomypat.'/(.+?)/(feed|rdf|rss|rss2|atom)/?$', 'index.php?'.$tax.'=$matches[1]&feed=$matches[2]', 'top' );
145
- add_rewrite_rule( $slug.'/'.$taxonomypat.'/(.+?)/?$', 'index.php?'.$tax.'=$matches[1]', 'top' ); // modified by [steve] [*** bug fixing]
 
146
 
147
- // below rules were added by [steve]
148
- add_rewrite_rule( $taxonomypat.'/(.+?)/date/([0-9]{4})/([0-9]{1,2})/?$', 'index.php?'.$tax.'=$matches[1]&year=$matches[2]&monthnum=$matches[3]', 'top' );
149
- add_rewrite_rule( $taxonomypat.'/(.+?)/date/([0-9]{4})/([0-9]{1,2})/page/?([0-9]{1,})/?$', 'index.php?'.$tax.'=$matches[1]&year=$matches[2]&monthnum=$matches[3]&paged=$matches[4]', 'top' );
150
- add_rewrite_rule( $slug.'/'.$taxonomypat.'/(.+?)/date/([0-9]{4})/([0-9]{1,2})/?$', 'index.php?'.$tax.'=$matches[1]&year=$matches[2]&monthnum=$matches[3]', 'top' );
151
- add_rewrite_rule( $slug.'/'.$taxonomypat.'/(.+?)/date/([0-9]{4})/([0-9]{1,2})/page/?([0-9]{1,})/?$', 'index.php?'.$tax.'=$matches[1]&year=$matches[2]&monthnum=$matches[3]&paged=$matches[4]', 'top' );
 
 
152
 
153
- endforeach;
154
 
 
155
  }
156
 
157
 
158
-
159
  /**
160
  *
161
  * Fix taxonomy = parent/child => taxonomy => child
162
  * @since 0.9.3
163
  *
 
164
  */
165
- public function parse_request($obj) {
166
  $taxes = CPTP_Util::get_taxonomies();
167
- foreach ($taxes as $key => $tax) {
168
- if(isset($obj->query_vars[$tax])) {
169
- if(strpos( $obj->query_vars[$tax] ,"/") !== false ) {
170
- $query_vars = explode("/", $obj->query_vars[$tax]);
171
- if(is_array($query_vars)) {
172
- $obj->query_vars[$tax] = array_pop($query_vars);
173
  }
174
  }
175
  }
1
  <?php
2
 
3
 
 
4
  /**
5
  *
6
  * Add Rewrite Rules
9
  * @since 0.9.4
10
  *
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( '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' ), 100 );
26
  }
27
 
28
 
29
+ public function add_rewrite_rules() {
30
+
31
+ foreach ( $this->post_type_args as $args ) {
32
+ call_user_func_array( array( $this, 'register_post_type_rules' ), $args );
33
+ }
34
+
35
+ foreach ( $this->taxonomy_args as $args ) {
36
+ call_user_func_array( array( $this, 'register_taxonomy_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
+
69
+ /**
70
+ *
71
+ * register_post_type_rules
72
  * ** add rewrite tag for Custom Post Type.
73
  * @version 1.1
74
  * @since 0.9
75
  *
76
+ * @param string $post_type
77
+ * @param object $args
78
+ *
79
  */
80
 
81
+ public function register_post_type_rules( $post_type, $args ) {
82
 
83
+ /** @var WP_Rewrite $wp_rewrite */
84
+ global $wp_rewrite;
85
 
86
+ if ( $args->_builtin or ! $args->publicly_queryable or ! $args->show_ui ) {
87
+ return;
88
  }
89
+ $permalink = CPTP_Util::get_permalink_structure( $post_type );
90
 
91
+ if ( ! $permalink ) {
92
  $permalink = CPTP_DEFAULT_PERMALINK;
93
  }
94
 
95
+ $permalink = '%' . $post_type . '_slug%' . $permalink;
96
+ $permalink = str_replace( '%postname%', '%' . $post_type . '%', $permalink );
97
 
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 ):
103
  endforeach;
104
 
105
  $rewrite_args = $args->rewrite;
106
+ if ( ! is_array( $rewrite_args ) ) {
107
+ $rewrite_args = array( 'with_front' => $args->rewrite );
108
  }
109
 
110
+ $rewrite_args['walk_dirs'] = false;
111
+ add_permastruct( $post_type, $permalink, $rewrite_args );
 
112
 
113
 
114
  $slug = $args->rewrite['slug'];
115
+ if ( $args->has_archive ) {
116
+ if ( is_string( $args->has_archive ) ) {
117
  $slug = $args->has_archive;
118
  };
119
 
120
+ if ( $args->rewrite['with_front'] ) {
121
+ $slug = substr( $wp_rewrite->front, 1 ) . $slug;
122
  }
123
 
124
+ $date_front = CPTP_Util::get_date_front( $post_type );
125
+
126
+ add_rewrite_rule( $slug . $date_front . '/([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/feed/(feed|rdf|rss|rss2|atom)/?$', 'index.php?year=$matches[1]&monthnum=$matches[2]&day=$matches[3]&feed=$matches[4]&post_type=' . $post_type, 'top' );
127
+ add_rewrite_rule( $slug . $date_front . '/([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/(feed|rdf|rss|rss2|atom)/?$', 'index.php?year=$matches[1]&monthnum=$matches[2]&day=$matches[3]&feed=$matches[4]&post_type=' . $post_type, 'top' );
128
+ add_rewrite_rule( $slug . $date_front . '/([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/page/?([0-9]{1,})/?$', 'index.php?year=$matches[1]&monthnum=$matches[2]&day=$matches[3]&paged=$matches[4]&post_type=' . $post_type, 'top' );
129
+ add_rewrite_rule( $slug . $date_front . '/([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/?$', 'index.php?year=$matches[1]&monthnum=$matches[2]&day=$matches[3]&post_type=' . $post_type, 'top' );
130
+ add_rewrite_rule( $slug . $date_front . '/([0-9]{4})/([0-9]{1,2})/feed/(feed|rdf|rss|rss2|atom)/?$', 'index.php?year=$matches[1]&monthnum=$matches[2]&feed=$matches[3]&post_type=' . $post_type, 'top' );
131
+ add_rewrite_rule( $slug . $date_front . '/([0-9]{4})/([0-9]{1,2})/(feed|rdf|rss|rss2|atom)/?$', 'index.php?year=$matches[1]&monthnum=$matches[2]&feed=$matches[3]&post_type=' . $post_type, 'top' );
132
+ add_rewrite_rule( $slug . $date_front . '/([0-9]{4})/([0-9]{1,2})/page/?([0-9]{1,})/?$', 'index.php?year=$matches[1]&monthnum=$matches[2]&paged=$matches[3]&post_type=' . $post_type, 'top' );
133
+ add_rewrite_rule( $slug . $date_front . '/([0-9]{4})/([0-9]{1,2})/?$', 'index.php?year=$matches[1]&monthnum=$matches[2]&post_type=' . $post_type, 'top' );
134
+ add_rewrite_rule( $slug . $date_front . '/([0-9]{4})/feed/(feed|rdf|rss|rss2|atom)/?$', 'index.php?year=$matches[1]&feed=$matches[2]&post_type=' . $post_type, 'top' );
135
+ add_rewrite_rule( $slug . $date_front . '/([0-9]{4})/(feed|rdf|rss|rss2|atom)/?$', 'index.php?year=$matches[1]&feed=$matches[2]&post_type=' . $post_type, 'top' );
136
+ add_rewrite_rule( $slug . $date_front . '/([0-9]{4})/page/?([0-9]{1,})/?$', 'index.php?year=$matches[1]&paged=$matches[2]&post_type=' . $post_type, 'top' );
137
+ add_rewrite_rule( $slug . $date_front . '/([0-9]{4})/?$', 'index.php?year=$matches[1]&post_type=' . $post_type, 'top' );
138
+ add_rewrite_rule( $slug . '/author/([^/]+)/page/?([0-9]{1,})/?$', 'index.php?author_name=$matches[1]&paged=$matches[2]&post_type=' . $post_type, 'top' );
139
+ add_rewrite_rule( $slug . '/author/([^/]+)/?$', 'index.php?author_name=$matches[1]&post_type=' . $post_type, 'top' );
140
+ add_rewrite_rule( $slug . '/' . get_option( 'category_base' ) . '/([^/]+)/page/?([0-9]{1,})/?$', 'index.php?category_name=$matches[1]&paged=$matches[2]&post_type=' . $post_type, 'top' );
141
+ add_rewrite_rule( $slug . '/' . get_option( 'category_base' ) . '/([^/]+)/?$', 'index.php?category_name=$matches[1]&post_type=' . $post_type, 'top' );
142
+
143
+ do_action( 'CPTP_registered_' . $post_type . '_rules', $args, $slug );
144
  }
 
 
 
145
  }
146
 
147
 
148
+ /**
149
+ *
150
+ * register_taxonomy_rules
151
+ *
152
+ * @param string $taxonomy
153
+ * @param array|string $object_type
154
+ * @param array $args
155
+ *
156
+ * @return void
157
+ */
158
+ public function register_taxonomy_rules( $taxonomy, $object_type, $args ) {
159
 
160
+ if ( get_option( 'no_taxonomy_structure' ) ) {
161
+ return;
162
  }
163
+ if ( $args['_builtin'] ) {
164
+ return;
165
  }
166
 
167
  global $wp_rewrite;
168
 
169
+ $post_types = $args['object_type'];
170
+ foreach ( $post_types as $post_type ):
171
+ $post_type_obj = get_post_type_object( $post_type );
172
+ if ( ! empty( $post_type_obj->rewrite['slug'] ) ) {
 
173
  $slug = $post_type_obj->rewrite['slug'];
174
+ } else {
 
175
  $slug = $post_type;
176
  }
177
 
178
+ if ( ! empty( $post_type_obj->has_archive ) && is_string( $post_type_obj->has_archive ) ) {
179
  $slug = $post_type_obj->has_archive;
180
  };
181
 
182
+
183
+ if ( ! empty( $post_type_obj->rewrite['with_front'] ) ) {
184
+ $slug = substr( $wp_rewrite->front, 1 ) . $slug;
185
  }
186
 
187
+ if ( 'category' == $taxonomy ) {
188
+ $taxonomy_slug = ( $cb = get_option( 'category_base' ) ) ? $cb : $taxonomy;
189
+ $taxonomy_key = 'category_name';
190
  } else {
191
  // Edit by [Xiphe]
192
+ if ( isset( $args['rewrite']['slug'] ) ) {
193
+ $taxonomy_slug = $args['rewrite']['slug'];
194
  } else {
195
+ $taxonomy_slug = $taxonomy;
196
  }
197
  // [Xiphe] stop
198
 
199
+ $taxonomy_key = $taxonomy;
200
  }
201
 
202
+ $rules = array(
203
+ //feed.
204
+ array(
205
+ "regex" => "%s/(.+?)/feed/(feed|rdf|rss|rss2|atom)/?$",
206
+ "redirect" => "index.php?{$taxonomy_key}=\$matches[1]&feed=\$matches[2]"
207
+ ),
208
+ array(
209
+ "regex" => "%s/(.+?)/(feed|rdf|rss|rss2|atom)/?$",
210
+ "redirect" => "index.php?{$taxonomy_key}=\$matches[1]&feed=\$matches[2]"
211
+ ),
212
+ //year
213
+ array(
214
+ "regex" => "%s/(.+?)/date/([0-9]{4})/?$",
215
+ "redirect" => "index.php?{$taxonomy_key}=\$matches[1]&year=\$matches[2]"
216
+ ),
217
+ array(
218
+ "regex" => "%s/(.+?)/date/([0-9]{4})/page/?([0-9]{1,})/?$",
219
+ "redirect" => "index.php?{$taxonomy_key}=\$matches[1]&year=\$matches[2]&paged=\$matches[3]"
220
+ ),
221
+ //monthnum
222
+ array(
223
+ "regex" => "%s/(.+?)/date/([0-9]{4})/([0-9]{1,2})/?$",
224
+ "redirect" => "index.php?{$taxonomy_key}=\$matches[1]&year=\$matches[2]&monthnum=\$matches[3]"
225
+ ),
226
+ array(
227
+ "regex" => "%s/(.+?)/date/([0-9]{4})/([0-9]{1,2})/page/?([0-9]{1,})/?$",
228
+ "redirect" => "index.php?{$taxonomy_key}=\$matches[1]&year=\$matches[2]&monthnum=\$matches[3]&paged=\$matches[4]"
229
+ ),
230
+ //day
231
+ array(
232
+ "regex" => "%s/(.+?)/date/([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/?$",
233
+ "redirect" => "index.php?{$taxonomy_key}=\$matches[1]&year=\$matches[2]&monthnum=\$matches[3]&day=\$matches[4]"
234
+ ),
235
+ array(
236
+ "regex" => "%s/(.+?)/date/([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/page/?([0-9]{1,})/?$",
237
+ "redirect" => "index.php?{$taxonomy_key}=\$matches[1]&year=\$matches[2]&monthnum=\$matches[3]&day=\$matches[4]&paged=\$matches[5]"
238
+ ),
239
+ //paging
240
+ array(
241
+ "regex" => "%s/(.+?)/page/?([0-9]{1,})/?$",
242
+ "redirect" => "index.php?{$taxonomy_key}=\$matches[1]&paged=\$matches[2]"
243
+ ),
244
+ //tax archive.
245
+ array(
246
+ "regex" => "%s/(.+?)/?$",
247
+ "redirect" => "index.php?{$taxonomy_key}=\$matches[1]"
248
+ ),
249
+ );
250
+
251
+ //no post_type slug.
252
+ foreach ( $rules as $rule ) {
253
+ $regex = sprintf( $rule['regex'], "{$taxonomy_slug}" );
254
+ $redirect = $rule['redirect'];
255
+ add_rewrite_rule( $regex, $redirect, 'top' );
256
+ }
257
 
258
+ if ( get_option( 'add_post_type_for_tax' ) ) {
259
+ foreach ( $rules as $rule ) {
260
+ $regex = sprintf( $rule['regex'], "{$slug}/{$taxonomy_slug}" );
261
+ $redirect = $rule['redirect'] . "&post_type={$post_type}";
262
+ add_rewrite_rule( $regex, $redirect, 'top' );
263
+ }
264
 
265
+ } else {
266
+ foreach ( $rules as $rule ) {
267
+ $regex = sprintf( $rule['regex'], "{$slug}/{$taxonomy_slug}" );
268
+ $redirect = $rule['redirect'];
269
+ add_rewrite_rule( $regex, $redirect, 'top' );
270
+ }
271
+ }
272
 
273
+ do_action( 'CPTP_registered_' . $taxonomy . '_rules', $object_type, $args, $taxonomy_slug );
274
 
275
+ endforeach;
276
  }
277
 
278
 
 
279
  /**
280
  *
281
  * Fix taxonomy = parent/child => taxonomy => child
282
  * @since 0.9.3
283
  *
284
+ * @param WP $obj
285
  */
286
+ public function parse_request( $obj ) {
287
  $taxes = CPTP_Util::get_taxonomies();
288
+ foreach ( $taxes as $key => $tax ) {
289
+ if ( isset( $obj->query_vars[ $tax ] ) ) {
290
+ if ( false !== strpos( $obj->query_vars[ $tax ], '/' ) ) {
291
+ $query_vars = explode( '/', $obj->query_vars[ $tax ] );
292
+ if ( is_array( $query_vars ) ) {
293
+ $obj->query_vars[ $tax ] = array_pop( $query_vars );
294
  }
295
  }
296
  }
CPTP/Module/Setting.php CHANGED
@@ -14,8 +14,8 @@
14
  class CPTP_Module_Setting extends CPTP_Module {
15
 
16
  public function add_hook() {
17
- add_action( 'init', array( $this,'load_textdomain') );
18
- add_action( 'plugins_loaded', array( $this,'check_version') );
19
  }
20
 
21
  /**
@@ -26,9 +26,12 @@ class CPTP_Module_Setting extends CPTP_Module {
26
  */
27
 
28
  public function check_version() {
29
- $version = get_option('cptp_version', 0);
30
- if($version != CPTP_VERSION) {
31
- update_option('cptp_version', CPTP_VERSION);
 
 
 
32
  }
33
  }
34
 
@@ -40,7 +43,7 @@ class CPTP_Module_Setting extends CPTP_Module {
40
  *
41
  */
42
  public function load_textdomain() {
43
- load_plugin_textdomain('cptp',false,'custom-post-type-permalinks/language');
44
  }
45
 
46
  }
14
  class CPTP_Module_Setting extends CPTP_Module {
15
 
16
  public function add_hook() {
17
+ add_action( 'init', array( $this, 'load_textdomain' ) );
18
+ add_action( 'plugins_loaded', array( $this, 'check_version' ) );
19
  }
20
 
21
  /**
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 ( $version != CPTP_VERSION ) {
34
+ update_option( 'cptp_version', CPTP_VERSION );
35
  }
36
  }
37
 
43
  *
44
  */
45
  public function load_textdomain() {
46
+ load_plugin_textdomain( 'cptp', false, 'custom-post-type-permalinks/language' );
47
  }
48
 
49
  }
CPTP/Util.php CHANGED
@@ -15,17 +15,17 @@ class CPTP_Util {
15
  }
16
 
17
  public static function get_post_types() {
18
- return get_post_types( array('_builtin'=>false, 'publicly_queryable'=>true, 'show_ui' => true) );
19
  }
20
 
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 );
29
  }
30
 
31
 
@@ -48,23 +48,73 @@ class CPTP_Util {
48
  $name = $parent->name;
49
  }
50
 
51
- if ( $parent->parent && ( $parent->parent != $parent->term_id ) && !in_array( $parent->parent, $visited ) ) {
52
  $visited[] = $parent->parent;
53
  $chain .= CPTP_Util::get_taxonomy_parents( $parent->parent, $taxonomy, $link, $separator, $nicename, $visited );
54
  }
55
 
56
  if ( $link ) {
57
- $chain .= '<a href="' . get_term_link( $parent->term_id, $taxonomy ) . '" title="' . esc_attr( sprintf( __( "View all posts in %s" ), $parent->name ) ) . '">'.$name.'</a>' . $separator;
58
  }else {
59
  $chain .= $name.$separator;
60
  }
61
  return $chain;
62
  }
63
 
64
- public static function get_permalink_structure($post_type) {
65
- return apply_filters( "CPTP_".$post_type."_structure", get_option($post_type."_structure") );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
66
  }
67
 
68
 
69
 
70
- }
15
  }
16
 
17
  public static function get_post_types() {
18
+ return get_post_types( array( '_builtin' => false, 'publicly_queryable' => true, 'show_ui' => true ) );
19
  }
20
 
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 );
29
  }
30
 
31
 
48
  $name = $parent->name;
49
  }
50
 
51
+ if ( $parent->parent && ( $parent->parent != $parent->term_id ) && ! in_array( $parent->parent, $visited ) ) {
52
  $visited[] = $parent->parent;
53
  $chain .= CPTP_Util::get_taxonomy_parents( $parent->parent, $taxonomy, $link, $separator, $nicename, $visited );
54
  }
55
 
56
  if ( $link ) {
57
+ $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 );
58
  }else {
59
  $chain .= $name.$separator;
60
  }
61
  return $chain;
62
  }
63
 
64
+ /**
65
+ * Get permalink structure.
66
+ *
67
+ * @since 0.9.6
68
+ * @param string|object $post_type post type name. / object post type object.
69
+ * @return string post type structure.
70
+ */
71
+ public static function get_permalink_structure( $post_type ) {
72
+ if ( is_string( $post_type ) ) {
73
+ $pt_object = get_post_type_object( $post_type );
74
+ }
75
+ else {
76
+ $pt_object = $post_type;
77
+ }
78
+
79
+
80
+ if ( !empty( $pt_object->cptp_permalink_structure ) ) {
81
+ $structure = $pt_object->cptp_permalink_structure;
82
+ }
83
+ else {
84
+
85
+ $structure = get_option( $pt_object->name.'_structure' );
86
+ }
87
+
88
+ return apply_filters( 'CPTP_'.$pt_object->name.'_structure', $structure );
89
+ }
90
+
91
+
92
+ /**
93
+ * Get permalink structure front for date archive.
94
+ *
95
+ * @since 1.0.0
96
+ * @param string $post_type post type name.
97
+ * @return string
98
+ */
99
+ public static function get_date_front( $post_type ) {
100
+ $structure = CPTP_Util::get_permalink_structure( $post_type );
101
+
102
+ $front = '';
103
+
104
+ preg_match_all( '/%.+?%/', $structure, $tokens );
105
+ $tok_index = 1;
106
+ foreach ( (array) $tokens[0] as $token ) {
107
+ if ( '%post_id%' == $token && ($tok_index <= 3) ) {
108
+ $front = '/date';
109
+ break;
110
+ }
111
+ $tok_index++;
112
+ }
113
+
114
+ return $front;
115
+
116
  }
117
 
118
 
119
 
120
+ }
bin/install-wp-tests.sh DELETED
@@ -1,78 +0,0 @@
1
- #!/usr/bin/env bash
2
-
3
- if [ $# -lt 3 ]; then
4
- echo "usage: $0 <db-name> <db-user> <db-pass> [db-host] [wp-version]"
5
- exit 1
6
- fi
7
-
8
- DB_NAME=$1
9
- DB_USER=$2
10
- DB_PASS=$3
11
- DB_HOST=${4-localhost}
12
- WP_VERSION=${5-latest}
13
-
14
- WP_TESTS_DIR=${WP_TESTS_DIR-/tmp/wordpress-tests-lib}
15
- WP_CORE_DIR=/tmp/wordpress/
16
-
17
- set -ex
18
-
19
- install_wp() {
20
- mkdir -p $WP_CORE_DIR
21
-
22
- if [ $WP_VERSION == 'latest' ]; then
23
- local ARCHIVE_NAME='latest'
24
- else
25
- local ARCHIVE_NAME="wordpress-$WP_VERSION"
26
- fi
27
-
28
- wget -nv --no-check-certificate -O /tmp/wordpress.tar.gz http://wordpress.org/${ARCHIVE_NAME}.tar.gz
29
- tar --strip-components=1 -zxmf /tmp/wordpress.tar.gz -C $WP_CORE_DIR
30
-
31
- wget -nv --no-check-certificate -O $WP_CORE_DIR/wp-content/db.php https://raw.github.com/markoheijnen/wp-mysqli/master/db.php
32
- }
33
-
34
- install_test_suite() {
35
- # portable in-place argument for both GNU sed and Mac OSX sed
36
- if [[ $(uname -s) == 'Darwin' ]]; then
37
- local ioption='-i .bak'
38
- else
39
- local ioption='-i'
40
- fi
41
-
42
- # set up testing suite
43
- mkdir -p $WP_TESTS_DIR
44
- cd $WP_TESTS_DIR
45
- svn co --quiet http://develop.svn.wordpress.org/trunk/tests/phpunit/includes/
46
-
47
- wget --no-check-certificate -nv -O wp-tests-config.php http://develop.svn.wordpress.org/trunk/wp-tests-config-sample.php
48
- sed $ioption "s:dirname( __FILE__ ) . '/src/':'$WP_CORE_DIR':" wp-tests-config.php
49
- sed $ioption "s/youremptytestdbnamehere/$DB_NAME/" wp-tests-config.php
50
- sed $ioption "s/yourusernamehere/$DB_USER/" wp-tests-config.php
51
- sed $ioption "s/yourpasswordhere/$DB_PASS/" wp-tests-config.php
52
- sed $ioption "s|localhost|${DB_HOST}|" wp-tests-config.php
53
- }
54
-
55
- install_db() {
56
- # parse DB_HOST for port or socket references
57
- local PARTS=(${DB_HOST//\:/ })
58
- local DB_HOSTNAME=${PARTS[0]};
59
- local DB_SOCK_OR_PORT=${PARTS[1]};
60
- local EXTRA=""
61
-
62
- if ! [ -z $DB_HOSTNAME ] ; then
63
- if [[ "$DB_SOCK_OR_PORT" =~ ^[0-9]+$ ]] ; then
64
- EXTRA=" --host=$DB_HOSTNAME --port=$DB_SOCK_OR_PORT --protocol=tcp"
65
- elif ! [ -z $DB_SOCK_OR_PORT ] ; then
66
- EXTRA=" --socket=$DB_SOCK_OR_PORT"
67
- elif ! [ -z $DB_HOSTNAME ] ; then
68
- EXTRA=" --host=$DB_HOSTNAME --protocol=tcp"
69
- fi
70
- fi
71
-
72
- # create database
73
- mysqladmin create $DB_NAME --user="$DB_USER" --password="$DB_PASS"$EXTRA
74
- }
75
-
76
- install_wp
77
- install_test_suite
78
- install_db
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
custom-post-type-permalinks.php CHANGED
@@ -5,7 +5,7 @@ Plugin URI: http://www.torounit.com
5
  Description: Add post archives of custom post type and customizable permalinks.
6
  Author: Toro_Unit
7
  Author URI: http://www.torounit.com/plugins/custom-post-type-permalinks/
8
- Version: 0.9.6
9
  Text Domain: cptp
10
  License: GPL2 or later
11
  Domain Path: /language/
@@ -17,16 +17,41 @@ Domain Path: /language/
17
  * Custom Post Type Permalinks
18
  *
19
  * @package Custom_Post_Type_Permalinks
20
- * @version 0.9.4
21
  *
22
  */
23
 
 
 
 
24
 
25
- require_once dirname(__FILE__).'/CPTP.php';
26
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
27
  add_action( 'plugins_loaded', 'cptp_init_instance' );
28
  function cptp_init_instance() {
29
- CPTP::get_instance();
30
  }
31
 
32
 
5
  Description: Add post archives of custom post type and customizable permalinks.
6
  Author: Toro_Unit
7
  Author URI: http://www.torounit.com/plugins/custom-post-type-permalinks/
8
+ Version: 1.0.0
9
  Text Domain: cptp
10
  License: GPL2 or later
11
  Domain Path: /language/
17
  * Custom Post Type Permalinks
18
  *
19
  * @package Custom_Post_Type_Permalinks
20
+ * @version 1.0.0
21
  *
22
  */
23
 
24
+ define( 'CPTP_PLUGIN_FILE', __FILE__ );
25
+ define( 'CPTP_VERSION', '1.0.0' );
26
+ define( 'CPTP_DEFAULT_PERMALINK', '/%postname%/' );
27
 
 
28
 
29
+
30
+ /**
31
+ *
32
+ * Autoloader for CPTP.
33
+ * @since 1.0.0
34
+ *
35
+ */
36
+ function cptp_class_loader( $class_name ) {
37
+ $dir = dirname( __FILE__ );
38
+ $file_name = $dir . '/'. str_replace( '_', '/', $class_name ).'.php';
39
+ if ( is_readable( $file_name ) ) {
40
+ include $file_name;
41
+ }
42
+ }
43
+ spl_autoload_register( 'cptp_class_loader' );
44
+
45
+
46
+ /**
47
+ *
48
+ * Entry Point
49
+ * @since 0.9.4
50
+ *
51
+ */
52
  add_action( 'plugins_loaded', 'cptp_init_instance' );
53
  function cptp_init_instance() {
54
+ CPTP::get_instance();
55
  }
56
 
57
 
language/cptp-fr_FR.mo ADDED
Binary file
language/cptp-fr_FR.po ADDED
@@ -0,0 +1,94 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ msgid ""
2
+ msgstr ""
3
+ "Project-Id-Version: Custom Post Type Permalinks\n"
4
+ "Report-Msgid-Bugs-To: \n"
5
+ "POT-Creation-Date: 2014-10-01 01:22+0100\n"
6
+ "PO-Revision-Date: 2014-10-01 01:23+0100\n"
7
+ "Last-Translator: Geoffrey <rikuasakura@hotmail.fr>\n"
8
+ "Language-Team: Geoffrey Crofte <support@creativejuiz.com>\n"
9
+ "Language: fr_FR\n"
10
+ "MIME-Version: 1.0\n"
11
+ "Content-Type: text/plain; charset=UTF-8\n"
12
+ "Content-Transfer-Encoding: 8bit\n"
13
+ "X-Poedit-KeywordsList: _;gettext;gettext_noop;_e;__\n"
14
+ "X-Poedit-Basepath: .\n"
15
+ "X-Generator: Poedit 1.6.5\n"
16
+ "Plural-Forms: nplurals=2; plural=(n > 1);\n"
17
+ "X-Poedit-SearchPath-0: ..\n"
18
+
19
+ #: ../CPTP/Module/Admin.php:30
20
+ msgid "Permalink Setting for custom post type"
21
+ msgstr "Réglage des permaliens des custom-post-types"
22
+
23
+ #: ../CPTP/Module/Admin.php:72
24
+ msgid "Use custom permalink of custom taxonomy archive."
25
+ msgstr ""
26
+ "Utiliser le permalien personnalisé de l'archive de la taxonomie "
27
+ "personnalisée."
28
+
29
+ #: ../CPTP/Module/Admin.php:93
30
+ msgid "Setting permalinks of custom post type."
31
+ msgstr "Réglage des permaliens des custom-post-types"
32
+
33
+ #: ../CPTP/Module/Admin.php:94
34
+ msgid ""
35
+ "The tags you can use is WordPress Structure Tags and '%\"custom_taxonomy_slug"
36
+ "\"%'. (e.g. %actors%)"
37
+ msgstr ""
38
+ "Les tags que vous pouvez utiliser sont ceux classiques de WordPress, ainsi "
39
+ "que '%custom_taxonomy_slug%'. (ex. %acteurs%)"
40
+
41
+ #: ../CPTP/Module/Admin.php:95
42
+ msgid "%\"custom_taxonomy_slug\"% is replaced the taxonomy's term.'."
43
+ msgstr "%custom_taxonomy_slug% est remplacé par le nom de la taxonomie."
44
+
45
+ #: ../CPTP/Module/Admin.php:97
46
+ msgid ""
47
+ "Presence of the trailing '/' is unified into a standard permalink structure "
48
+ "setting."
49
+ msgstr ""
50
+ "La présence du '/' (trailing slash) est unifié dans un réglage de structure "
51
+ "standard du permalien."
52
+
53
+ #: ../CPTP/Module/Admin.php:98
54
+ msgid ""
55
+ "If <code>has_archive</code> is true, add permalinks for custom post type "
56
+ "archive."
57
+ msgstr ""
58
+ "Si <code>has_archive</code> est à <code>true</code>, ajouter les permaliens "
59
+ "pour les archives du type de post personnalisé."
60
+
61
+ #: ../CPTP/Module/Admin.php:99
62
+ msgid ""
63
+ "If you don't entered permalink structure, permalink is configured /%postname"
64
+ "%/'."
65
+ msgstr ""
66
+ "Si vous n'entrez pas de structure de permalien, celui-ci est configuré avec /"
67
+ "%postname%/."
68
+
69
+ #: ../CPTP/Module/Admin.php:132
70
+ #, php-format
71
+ msgid ""
72
+ "If you check,The custom taxonomy's permalinks is <code>%s/post_type/taxonomy/"
73
+ "term</code>."
74
+ msgstr ""
75
+ "Si vous cochez, le permalien d'une taxonomie personnalisée sera <code>%s/"
76
+ "post_type/taxonomy/term</code>."
77
+
78
+ #: ../CPTP/Module/Admin.php:160
79
+ msgid ""
80
+ "<h3>Custom Post Type Permalinks</h3><p>From <a href='options-permalink."
81
+ "php'>Permalinks</a>, set a custom permalink for each post type.</p>"
82
+ msgstr ""
83
+ "<h3>Custom Post Type Permalinks</h3><p>Depuis <a href='options-permalink."
84
+ "php'>Permaliens</a>, paramétrez un permalien personnalisé pour chaque type "
85
+ "de post.</p>"
86
+
87
+ #: ../CPTP/Util.php:57
88
+ #, php-format
89
+ msgid "View all posts in %s"
90
+ msgstr "Voir tous les posts dans %s"
91
+
92
+ #~ msgid "From Permalinks, set a custom permalink for each post type."
93
+ #~ msgstr ""
94
+ #~ "パーマリンク設定より、カスタム投稿タイプごとのパーマリンクを設定できます。"
phpunit.xml DELETED
@@ -1,14 +0,0 @@
1
- <phpunit
2
- bootstrap="tests/bootstrap.php"
3
- backupGlobals="false"
4
- colors="true"
5
- convertErrorsToExceptions="true"
6
- convertNoticesToExceptions="true"
7
- convertWarningsToExceptions="true"
8
- >
9
- <testsuites>
10
- <testsuite>
11
- <directory prefix="test-" suffix=".php">./tests/</directory>
12
- </testsuite>
13
- </testsuites>
14
- </phpunit>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
readme.md ADDED
@@ -0,0 +1,218 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Custom Post Type Permalinks
2
+ Donate link: http://www.amazon.co.jp/registry/wishlist/COKSXS25MVQV
3
+
4
+ Lets you edit the permalink of custom post type.
5
+
6
+ ## Description
7
+
8
+ Custom Post Type Permalinks lets you edit the permalink structure of custom post type.
9
+
10
+ Change custom taxonomy archive's permalink to "example.org/post_type/taxonomy_name/term_slug". Can disable this fix.
11
+
12
+ And support wp_get_archives( "post_type=foo" ).
13
+
14
+ [This Plugin published on GitHub.](https://github.com/torounit/custom-post-type-permalinks)
15
+
16
+ Donation: Please send amazon.co.jp Gift to donate[at]torounit.com.
17
+
18
+ ### Translators
19
+
20
+ * French(fr_FR) - [Geoffrey Crofte](http://geoffrey.crofte.fr/)
21
+ * Japanese(ja) - [Toro_Unit](http://www.torounit.com/)
22
+ * Russian(ru_RU) - [Olart](http://olart.ru)
23
+
24
+ ## Setting on Code
25
+
26
+ Example:
27
+
28
+ ```
29
+ register_post_type( 'foo',
30
+ array(
31
+ "public" => true,
32
+ 'has_archive' => true,
33
+ "rewrite" => [
34
+ "with_front" => true
35
+ ],
36
+ "cptp_permalink_structure" => "%post_id%"
37
+ )
38
+ );
39
+ ```
40
+
41
+
42
+ ## Installation
43
+
44
+ * Download the custom-post-type-permalinks.zip file to your computer.
45
+ * Unzip the file.
46
+ * Upload the `custom-post-type-permalinks` directory to your `/wp-content/plugins/` directory.
47
+ * Activate the plugin through the 'Plugins' menu in WordPress.
48
+
49
+ That's it. You can access the permalinks setting by going to *Settings -> Permalinks*.
50
+
51
+
52
+ ## Screenshots
53
+
54
+ * screenshot-1.png
55
+
56
+
57
+ ## Changelog
58
+
59
+ ### 1.0.0
60
+
61
+ * Set Permalink enable register_post_type.
62
+ * Enable add post type query to taxonomy archives.
63
+ * Use Class Autoloader.
64
+ * Create Rewrite Rule on `wp_loaded` action.
65
+ * WordPress Code Format Fix.
66
+ * CPTP_Module_Permalink Bug Fix.
67
+ * Bug Fix.
68
+ * Use Semantic Versioning.
69
+ * Date Structure Fix.
70
+ * Use Category Base.
71
+
72
+ ### 0.9.7
73
+
74
+ * Adding date slug only conflicting %post_id%.
75
+ * Change taxonomy link rewrite rule. Use post_type.
76
+ * Can change template include custom taxonomy.
77
+
78
+ ### 0.9.6
79
+
80
+ * Category and author.
81
+ * French Transration. Thanks Geoffrey!
82
+ * Hierarchial Term Fix.
83
+
84
+ ### 0.9.5.6
85
+
86
+ * Strict Standard Error Fix.
87
+
88
+ ### 0.9.5.4
89
+
90
+ * archive link bug fix.
91
+ * Tested Up 3.9
92
+
93
+ ### 0.9.5.3
94
+
95
+ * “/”bug fix.
96
+ * taxonomy tmplate bug fix.
97
+
98
+ ### 0.9.5.2
99
+
100
+ * Archives Rewrite Fix.
101
+
102
+ ### 0.9.5.1
103
+
104
+ * Admin Bug Fix.
105
+
106
+ ### 0.9.5
107
+
108
+ * Big change plugin architecture.
109
+ * Show has_archive, with_front.
110
+
111
+ ### 0.9.4
112
+
113
+ * Internal release.
114
+
115
+ ### 0.9.3.3
116
+
117
+ * has_archive Bug Fix.
118
+ * Fixed a bug in the link, including the extension.
119
+
120
+ ### 0.9.3.2
121
+
122
+ * wp_get_archives Bug Fix.
123
+
124
+ ### 0.9.3.1
125
+
126
+ * Tested 3.6
127
+ * Bug Fix.
128
+
129
+
130
+ ### 0.9.3
131
+
132
+ * Admin page fix.
133
+ * slngle pageing link fix.
134
+ * Add Russian translation.
135
+
136
+
137
+ ### 0.9
138
+
139
+ * Add custom post type archive only has_archive->true
140
+ * Change method name.
141
+ * Change hook custom post link.
142
+ * Use Slug in wp_get_archive().
143
+ * Fix attachment link.
144
+
145
+
146
+ ### 0.8.7
147
+
148
+ * Translate Bug Fix.
149
+
150
+ ### 0.8.6
151
+
152
+ * Paging Bug Fix.
153
+ * Commnent Paging.
154
+ * Show pointer.
155
+ *
156
+
157
+ ### 0.8.1
158
+
159
+ * Bug Fix.
160
+
161
+ ### 0.7.9.1
162
+
163
+ * Support Comment permalink.
164
+ * Small change in setting page.
165
+ * Change default value.
166
+ * Bug Fix.
167
+
168
+ ### 0.7.8
169
+
170
+ * Bug fix.
171
+
172
+
173
+ ### 0.7.7
174
+
175
+ * Bug fix.
176
+
177
+ ### 0.7.6
178
+
179
+ * Add parent's slug to hierarchical post type.
180
+
181
+
182
+ ### 0.7.5
183
+
184
+ * Add ability to disable to change custom taxonomy archive's permalink.
185
+
186
+
187
+ ### 0.7.4
188
+
189
+ * Bug fix taxonomy rewrite.
190
+
191
+
192
+ ### 0.7.3
193
+
194
+ * Changed part for saving the data.
195
+
196
+ ### 0.7.2
197
+
198
+ * Reweite bug fix.
199
+ * Prewview bug fix.
200
+
201
+ ### 0.7.1
202
+
203
+ * Bug fix.
204
+
205
+ ### 0.7
206
+
207
+ * Add %{taxonomy}% tag.
208
+ * A large number of Bug Fix.
209
+ * Change Setting Page. Use Setting API.
210
+
211
+
212
+ ### 0.6.2
213
+
214
+ * Fix %author% tag.
215
+
216
+ ### 0.6
217
+
218
+ * First release on wordpress.org
readme.txt CHANGED
@@ -1,157 +1,192 @@
1
- === Custom Post Type Permalinks ===
2
- Contributors: Toro_Unit
3
- Tags: permalink,permalinks,custom post type,custom taxonomy,cms
4
- Requires at least: 3.7
5
- Tested up to: 4.0
6
- Stable tag: 0.9.6
7
-
8
- Lets you edit the permalink of custom post type.
9
-
10
- == Description ==
11
-
12
- Custom Post Type Permalinks lets you edit the permalink structure of custom post type.
13
-
14
- Change custom taxonomy archive's permalink to "example.org/post_type/taxonomy_name/term_slug". Can disable this fix.
15
-
16
- And support wp_get_archives( "post_type=foo" ).
17
-
18
- [This Plugin published on GitHub.](https://github.com/torounit/custom-post-type-permalinks)
19
-
20
- Donation: Please send amazon.co.jp Gift to donate[at]torounit.com.
21
-
22
- = Translators =
23
- * French(fr_FR) - [Geoffrey Crofte](http://geoffrey.crofte.fr/)
24
- * Japanese(ja) - [Toro_Unit](http://www.torounit.com/)
25
- * Russian(ru_RU) - [Olart](http://olart.ru)
26
-
27
-
28
- == Installation ==
29
-
30
- * Download the custom-post-type-permalinks.zip file to your computer.
31
- * Unzip the file.
32
- * Upload the `custom-post-type-permalinks` directory to your `/wp-content/plugins/` directory.
33
- * Activate the plugin through the 'Plugins' menu in WordPress.
34
-
35
- That's it. You can access the permalinks setting by going to *Settings -> Permalinks*.
36
-
37
-
38
- == Screenshots ==
39
-
40
- * screenshot-1.png
41
-
42
-
43
- == Changelog ==
44
-
45
- = 0.9.6 =
46
- * Category and author.
47
- * French Transration. Thanks Geoffrey!
48
- * Hierarchial Term Fix.
49
-
50
- = 0.9.5.6 =
51
- * Strict Standard Error Fix.
52
-
53
- = 0.9.5.4 =
54
- * archive link bug fix.
55
- * Tested Up 3.9
56
-
57
- = 0.9.5.3 =
58
- * “/”bug fix.
59
- * taxonomy tmplate bug fix.
60
-
61
- = 0.9.5.2 =
62
- * Archives Rewrite Fix.
63
-
64
- = 0.9.5.1 =
65
- * Admin Bug Fix.
66
-
67
- = 0.9.5 =
68
- * Big change plugin architecture.
69
- * Show has_archive, with_front.
70
-
71
- = 0.9.4 =
72
- * Internal release.
73
-
74
- = 0.9.3.3 =
75
- * has_archive Bug Fix.
76
- * Fixed a bug in the link, including the extension.
77
-
78
- = 0.9.3.2 =
79
- * wp_get_archives Bug Fix.
80
-
81
- = 0.9.3.1 =
82
- * Tested 3.6
83
- * Bug Fix.
84
-
85
-
86
- = 0.9.3 =
87
- * Admin page fix.
88
- * slngle pageing link fix.
89
- * Add Russian translation.
90
-
91
-
92
- = 0.9 =
93
- * Add custom post type archive only has_archive->true
94
- * Change method name.
95
- * Change hook custom post link.
96
- * Use Slug in wp_get_archive().
97
- * Fix attachment link.
98
-
99
-
100
- = 0.8.7 =
101
- * Translate Bug Fix.
102
-
103
- = 0.8.6 =
104
- * Paging Bug Fix.
105
- * Commnent Paging.
106
- * Show pointer.
107
- *
108
-
109
- = 0.8.1 =
110
- * Bug Fix.
111
-
112
- = 0.7.9.1 =
113
- * Support Comment permalink.
114
- * Small change in setting page.
115
- * Change default value.
116
- * Bug Fix.
117
-
118
- = 0.7.8 =
119
- * Bug fix.
120
-
121
-
122
- = 0.7.7 =
123
- * Bug fix.
124
-
125
- = 0.7.6 =
126
- * Add parent's slug to hierarchical post type.
127
-
128
-
129
- = 0.7.5 =
130
- * Add ability to disable to change custom taxonomy archive's permalink.
131
-
132
-
133
- = 0.7.4 =
134
- * Bug fix taxonomy rewrite.
135
-
136
-
137
- = 0.7.3 =
138
- * Changed part for saving the data.
139
-
140
- = 0.7.2 =
141
- * Reweite bug fix.
142
- * Prewview bug fix.
143
-
144
- = 0.7.1 =
145
- * Bug fix.
146
-
147
- = 0.7 =
148
- * Add %{taxonomy}% tag.
149
- * A large number of Bug Fix.
150
- * Change Setting Page. Use Setting API.
151
-
152
-
153
- = 0.6.2 =
154
- * Fix %author% tag.
155
-
156
- = 0.6 =
157
- * First release on wordpress.org
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ === Custom Post Type Permalinks ===
2
+ Contributors: Toro_Unit
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.1
6
+ Tested up to: 4.2
7
+ Stable tag: 1.0.0
8
+
9
+ Lets you edit the permalink of custom post type.
10
+
11
+ == Description ==
12
+
13
+ Custom Post Type Permalinks lets you edit the permalink structure of custom post type.
14
+
15
+ Change custom taxonomy archive's permalink to "example.org/post_type/taxonomy_name/term_slug". Can disable this fix.
16
+
17
+ And support wp_get_archives( "post_type=foo" ).
18
+
19
+ [This Plugin published on GitHub.](https://github.com/torounit/custom-post-type-permalinks)
20
+
21
+ Donation: Please send amazon.co.jp Gift to donate[at]torounit.com.
22
+
23
+ = Translators =
24
+ * French(fr_FR) - [Geoffrey Crofte](http://geoffrey.crofte.fr/)
25
+ * Japanese(ja) - [Toro_Unit](http://www.torounit.com/)
26
+ * Russian(ru_RU) - [Olart](http://olart.ru)
27
+
28
+ == Setting on Code ==
29
+
30
+ Example:
31
+
32
+ `
33
+ register_post_type( 'foo',
34
+ array(
35
+ "public" => true,
36
+ 'has_archive' => true,
37
+ "rewrite" => [
38
+ "with_front" => true
39
+ ],
40
+ "cptp_permalink_structure" => "%post_id%"
41
+ )
42
+ );
43
+ `
44
+
45
+
46
+ == Installation ==
47
+
48
+ * Download the custom-post-type-permalinks.zip file to your computer.
49
+ * Unzip the file.
50
+ * Upload the `custom-post-type-permalinks` directory to your `/wp-content/plugins/` directory.
51
+ * Activate the plugin through the 'Plugins' menu in WordPress.
52
+
53
+ That's it. You can access the permalinks setting by going to *Settings -> Permalinks*.
54
+
55
+
56
+ == Screenshots ==
57
+
58
+ * screenshot-1.png
59
+
60
+
61
+ == Changelog ==
62
+
63
+ = 1.0.0 =
64
+ * Set Permalink enable register_post_type.
65
+ * Enable add post type query to taxonomy archives.
66
+ * Use Class Autoloader.
67
+ * Create Rewrite Rule on `wp_loaded` action.
68
+ * WordPress Code Format Fix.
69
+ * CPTP_Module_Permalink Bug Fix.
70
+ * Bug Fix.
71
+ * Use Semantic Versioning.
72
+ * Date Structure Fix.
73
+ * Use Category Base.
74
+
75
+ = 0.9.7 =
76
+ * Adding date slug only conflicting %post_id%.
77
+ * Change taxonomy link rewrite rule. Use post_type.
78
+ * Can change template include custom taxonomy.
79
+
80
+ = 0.9.6 =
81
+ * Category and author.
82
+ * French Transration. Thanks Geoffrey!
83
+ * Hierarchial Term Fix.
84
+
85
+ = 0.9.5.6 =
86
+ * Strict Standard Error Fix.
87
+
88
+ = 0.9.5.4 =
89
+ * archive link bug fix.
90
+ * Tested Up 3.9
91
+
92
+ = 0.9.5.3 =
93
+ * “/”bug fix.
94
+ * taxonomy tmplate bug fix.
95
+
96
+ = 0.9.5.2 =
97
+ * Archives Rewrite Fix.
98
+
99
+ = 0.9.5.1 =
100
+ * Admin Bug Fix.
101
+
102
+ = 0.9.5 =
103
+ * Big change plugin architecture.
104
+ * Show has_archive, with_front.
105
+
106
+ = 0.9.4 =
107
+ * Internal release.
108
+
109
+ = 0.9.3.3 =
110
+ * has_archive Bug Fix.
111
+ * Fixed a bug in the link, including the extension.
112
+
113
+ = 0.9.3.2 =
114
+ * wp_get_archives Bug Fix.
115
+
116
+ = 0.9.3.1 =
117
+ * Tested 3.6
118
+ * Bug Fix.
119
+
120
+
121
+ = 0.9.3 =
122
+ * Admin page fix.
123
+ * slngle pageing link fix.
124
+ * Add Russian translation.
125
+
126
+
127
+ = 0.9 =
128
+ * Add custom post type archive only has_archive->true
129
+ * Change method name.
130
+ * Change hook custom post link.
131
+ * Use Slug in wp_get_archive().
132
+ * Fix attachment link.
133
+
134
+
135
+ = 0.8.7 =
136
+ * Translate Bug Fix.
137
+
138
+ = 0.8.6 =
139
+ * Paging Bug Fix.
140
+ * Commnent Paging.
141
+ * Show pointer.
142
+ *
143
+
144
+ = 0.8.1 =
145
+ * Bug Fix.
146
+
147
+ = 0.7.9.1 =
148
+ * Support Comment permalink.
149
+ * Small change in setting page.
150
+ * Change default value.
151
+ * Bug Fix.
152
+
153
+ = 0.7.8 =
154
+ * Bug fix.
155
+
156
+
157
+ = 0.7.7 =
158
+ * Bug fix.
159
+
160
+ = 0.7.6 =
161
+ * Add parent's slug to hierarchical post type.
162
+
163
+
164
+ = 0.7.5 =
165
+ * Add ability to disable to change custom taxonomy archive's permalink.
166
+
167
+
168
+ = 0.7.4 =
169
+ * Bug fix taxonomy rewrite.
170
+
171
+
172
+ = 0.7.3 =
173
+ * Changed part for saving the data.
174
+
175
+ = 0.7.2 =
176
+ * Reweite bug fix.
177
+ * Prewview bug fix.
178
+
179
+ = 0.7.1 =
180
+ * Bug fix.
181
+
182
+ = 0.7 =
183
+ * Add %{taxonomy}% tag.
184
+ * A large number of Bug Fix.
185
+ * Change Setting Page. Use Setting API.
186
+
187
+
188
+ = 0.6.2 =
189
+ * Fix %author% tag.
190
+
191
+ = 0.6 =
192
+ * First release on wordpress.org
tests/bootstrap.php DELETED
@@ -1,14 +0,0 @@
1
- <?php
2
-
3
- $_tests_dir = getenv('WP_TESTS_DIR');
4
- if ( !$_tests_dir ) $_tests_dir = '/tmp/wordpress-tests-lib';
5
-
6
- require_once $_tests_dir . '/includes/functions.php';
7
-
8
- function _manually_load_plugin() {
9
- require dirname( __FILE__ ) . '/../custom-post-type-permalinks.php';
10
- }
11
- tests_add_filter( 'muplugins_loaded', '_manually_load_plugin' );
12
-
13
- require $_tests_dir . '/includes/bootstrap.php';
14
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
tests/test-cptp.php DELETED
@@ -1,143 +0,0 @@
1
- <?php
2
-
3
- class CPTPTest extends WP_UnitTestCase {
4
-
5
-
6
- public function setUp() {
7
- global $wp_rewrite;
8
- parent::setUp();
9
-
10
- $wp_rewrite->init();
11
- $wp_rewrite->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' );
12
- create_initial_taxonomies();
13
- $wp_rewrite->flush_rules();
14
- cptp_init_instance();
15
- }
16
-
17
-
18
- public function test_url_to_postid_cpt_year_monthnum_day_post_id () {
19
- delete_option( 'rewrite_rules' );
20
- $post_type = rand_str( 12 );
21
- register_post_type( $post_type, array( "public" => true ) );
22
-
23
- update_option($post_type."_structure", "/%year%/%monthnum%/%day%/%post_id%/" );
24
- $id = $this->factory->post->create( array( 'post_type' => $post_type ) );
25
- $this->assertEquals( $id, url_to_postid( get_permalink( $id ) ) );
26
-
27
- _unregister_post_type( $post_type );
28
- }
29
-
30
- public function test_url_to_postid_cpt_year_monthnum_day_postname () {
31
- delete_option( 'rewrite_rules' );
32
- $post_type = rand_str( 12 );
33
- update_option($post_type."_structure", "/%year%/%monthnum%/%day%/%postname%/" );
34
- register_post_type( $post_type, array( "public" => true ) );
35
-
36
- $id = $this->factory->post->create( array( 'post_type' => $post_type ) );
37
- $this->assertEquals( $id, url_to_postid( get_permalink( $id ) ) );
38
-
39
- _unregister_post_type( $post_type );
40
- }
41
-
42
- public function test_url_to_postid_cpt_term_post_id () {
43
- delete_option( 'rewrite_rules' );
44
- $post_type = rand_str( 12 );
45
- $taxonomy = rand_str( 12 );
46
- update_option($post_type."_structure", "/%".$taxonomy."%/%post_id%/" );
47
- register_taxonomy( $taxonomy, $post_type, array( "public" => true ) );
48
- register_post_type( $post_type, array( "public" => true ) );
49
- $id = $this->factory->post->create( array( 'post_type' => $post_type ) );
50
- wp_set_post_terms( $id, rand_str( 12 ) , $taxonomy );
51
- $this->assertEquals( $id, url_to_postid( get_permalink( $id ) ) );
52
-
53
- _unregister_post_type( $post_type );
54
- _unregister_taxonomy( $taxonomy, $post_type );
55
- }
56
-
57
-
58
- public function test_url_to_postid_cpt_hierarchial_term_post_id() {
59
- delete_option( 'rewrite_rules' );
60
- $post_type = rand_str( 12 );
61
- $taxonomy = rand_str( 12 );
62
-
63
- update_option($post_type."_structure", "/%".$taxonomy."%/%post_id%/" );
64
- register_taxonomy( $taxonomy, $post_type, array( "public" => true ,"hierarchial" => true) );
65
- register_post_type( $post_type, array( "public" => true ) );
66
-
67
- $id = $this->factory->post->create( array( 'post_type' => $post_type ) );
68
-
69
- $term_id = 0;
70
- for ($i=0; $i < 10; $i++) {
71
- $slug = rand_str( 12 );
72
- $term = wp_insert_term( $slug, $taxonomy, array("parent" => $term_id, "slug" => $slug) );
73
- $term_id = $term["term_id"];
74
- }
75
- wp_set_post_terms( $id, get_term( $term_id, $taxonomy )->slug, $taxonomy );
76
-
77
- $this->assertEquals( $id, url_to_postid( get_permalink( $id ) ) );
78
- _unregister_post_type( $post_type );
79
- _unregister_taxonomy( $taxonomy, $post_type );
80
- }
81
-
82
- public function test_url_cpt_hierarchial_url_to_that_all() {
83
- delete_option( 'rewrite_rules' );
84
- $post_type = rand_str( 12 );
85
- $taxonomy = rand_str( 12 );
86
-
87
- update_option($post_type."_structure", "/%".$taxonomy."%/%postname%/" );
88
- register_taxonomy( $taxonomy, $post_type, array( "public" => true ,"hierarchial" => true) );
89
- register_post_type( $post_type, array( "public" => true ) );
90
-
91
- $id = $this->factory->post->create( array( 'post_type' => $post_type ,"post_name" => "foo") );
92
- $id_all_term = $this->factory->post->create( array( 'post_type' => $post_type ,"post_name" => "foo_all_term") );
93
-
94
- $term_id = 0;
95
- $slug_list = array();
96
- for ($i=0; $i < 10; $i++) {
97
- $slug = rand_str( 12 );
98
- $term = wp_insert_term( $slug, $taxonomy, array("parent" => $term_id, "slug" => $slug) );
99
- $term_id = $term["term_id"];
100
- $slug_list[] = get_term( $term_id, $taxonomy )->slug;
101
-
102
- }
103
- wp_set_post_terms( $id, get_term( $term_id, $taxonomy )->slug, $taxonomy );
104
- wp_set_post_terms( $id_all_term, $slug_list, $taxonomy );
105
-
106
- $this->assertEquals( get_permalink( $id ), str_replace("foo_all_term", "foo", get_permalink( $id_all_term )) );
107
-
108
- _unregister_post_type( $post_type );
109
- _unregister_taxonomy( $taxonomy, $post_type );
110
- }
111
-
112
-
113
- public function test_url_to_postid_category_post_id () {
114
- delete_option( 'rewrite_rules' );
115
- $post_type = rand_str( 12 );
116
- $taxonomy = rand_str( 12 );
117
- update_option($post_type."_structure", "/%category%/%post_id%/" );
118
- register_post_type( $post_type, array( "public" => true , 'taxonomies' => array('category')) );
119
- $id = $this->factory->post->create( array( 'post_type' => $post_type ) );
120
- $term = wp_insert_term( rand_str( 12 ), "category" );
121
- wp_set_post_categories( $id, array($term["term_id"]) );
122
-
123
- $this->assertEquals( $id, url_to_postid( get_permalink( $id ) ) );
124
-
125
- _unregister_post_type( $post_type );
126
- _unregister_taxonomy( $taxonomy, $post_type );
127
- }
128
-
129
-
130
- public function test_url_to_postid_cpt_author_postname () {
131
- delete_option( 'rewrite_rules' );
132
- $post_type = rand_str( 12 );
133
- update_option($post_type."_structure", "/%author%/%postname%/" );
134
- register_post_type( $post_type, array( "public" => true ) );
135
- $user_id = $this->factory->user->create();
136
- $id = $this->factory->post->create( array( 'post_type' => $post_type ,"post_author" => $user_id ) );
137
- $this->assertEquals( $id, url_to_postid( get_permalink( $id ) ) );
138
- _unregister_post_type( $post_type );
139
- }
140
-
141
-
142
- }
143
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
tests/test-sample.php DELETED
@@ -1,11 +0,0 @@
1
- <?php
2
-
3
- class SampleTest extends WP_UnitTestCase {
4
-
5
- function testSample() {
6
- // replace this with some actual testing code
7
- $this->assertTrue( true );
8
- }
9
-
10
- }
11
-