Custom Post Type Permalinks - Version 0.7.3.1

Version Description

Download this release

Release Info

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

Code changes from version 0.7.3 to 0.7.3.1

Files changed (4) hide show
  1. cptp-ja.mo +0 -0
  2. cptp-ja.po +2 -2
  3. custom-post-type-permalinks.php +35 -35
  4. readme.txt +2 -2
cptp-ja.mo CHANGED
Binary file
cptp-ja.po CHANGED
@@ -5,10 +5,10 @@
5
  #
6
  msgid ""
7
  msgstr ""
8
- "Project-Id-Version: Custom Post Type Permalinks 0.7.0 Ja\n"
9
  "Report-Msgid-Bugs-To: \n"
10
  "POT-Creation-Date: 2011-09-21 11:00+0900\n"
11
- "PO-Revision-Date: 2011-12-30 10:57+0900\n"
12
  "Last-Translator: Toro_Unit <mail@torounit.com>\n"
13
  "Language-Team: Toro_Unit <mail@torounit.com>\n"
14
  "MIME-Version: 1.0\n"
5
  #
6
  msgid ""
7
  msgstr ""
8
+ "Project-Id-Version: Custom Post Type Permalinks 0.7.3 Ja\n"
9
  "Report-Msgid-Bugs-To: \n"
10
  "POT-Creation-Date: 2011-09-21 11:00+0900\n"
11
+ "PO-Revision-Date: 2012-01-06 23:08+0900\n"
12
  "Last-Translator: Toro_Unit <mail@torounit.com>\n"
13
  "Language-Team: Toro_Unit <mail@torounit.com>\n"
14
  "MIME-Version: 1.0\n"
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.7.3
9
  Text Domain: cptp
10
  Domain Path: /
11
  */
@@ -47,29 +47,29 @@ class Custom_Post_Type_Permalinks {
47
  add_action('generate_rewrite_rules', array(&$this,'add_tax_rewrite'));
48
  add_filter('term_link', array(&$this,'set_term_link'),10,3);
49
  }
50
-
51
  static function uninstall_hook() {
52
  if ( function_exists('register_uninstall_hook') ) {
53
  register_uninstall_hook(__FILE__, array(&$this,'uninstall_hook_custom_permalink'));
54
  }
55
  }
56
-
57
  function get_taxonomy_parents( $id, $taxonomy = 'category', $link = false, $separator = '/', $nicename = false, $visited = array() ) {
58
  $chain = '';
59
  $parent = &get_term( $id, $taxonomy, OBJECT, 'raw');
60
  if ( is_wp_error( $parent ) )
61
  return $parent;
62
-
63
  if ( $nicename )
64
  $name = $parent->slug;
65
  else
66
  $name = $parent->name;
67
-
68
  if ( $parent->parent && ( $parent->parent != $parent->term_id ) && !in_array( $parent->parent, $visited ) ) {
69
  $visited[] = $parent->parent;
70
  $chain .= $this->get_taxonomy_parents( $parent->parent, $taxonomy, $link, $separator, $nicename, $visited );
71
  }
72
-
73
  if ( $link )
74
  $chain .= '<a href="' . get_term_link( $parent->term_id, $taxonomy ) . '" title="' . esc_attr( sprintf( __( "View all posts in %s" ), $parent->name ) ) . '">'.$name.'</a>' . $separator;
75
  else
@@ -78,7 +78,7 @@ class Custom_Post_Type_Permalinks {
78
  }
79
 
80
 
81
-
82
  function set_archive_rewrite() {
83
  $post_types = get_post_types( array('_builtin'=>false, 'publicly_queryable'=>true,'show_ui' => true) );
84
 
@@ -127,11 +127,11 @@ class Custom_Post_Type_Permalinks {
127
  $post_types = get_post_types( array('_builtin'=>false, 'publicly_queryable'=>true,'show_ui' => true) );
128
 
129
  foreach ( $post_types as $post_type ):
130
-
131
  $permalink = get_option($post_type.'_structure');
132
 
133
  if( !$permalink ){
134
- $permalink = '/%year%/%monthnum%/%day%/%post_id%/';
135
  }
136
 
137
  $permalink = str_replace('%postname%','%'.$post_type.'%',$permalink);
@@ -141,11 +141,11 @@ class Custom_Post_Type_Permalinks {
141
  if( !$slug ) {
142
  $slug = $post_type;
143
  }
144
-
145
  $permalink = '/'.$slug.'/'.$permalink;
146
- $permalink = $permalink.'/%'.$post_type.'_page%';
147
  $permalink = str_replace('//','/',$permalink);
148
-
149
  $wp_rewrite->add_rewrite_tag('%post_type%', '([^/]+)','post_type=');
150
  $wp_rewrite->add_rewrite_tag('%'.$post_type.'_id%', '([0-9]{1,})','post_type='.$post_type.'&p=');
151
  $wp_rewrite->add_rewrite_tag('%'.$post_type.'_page%', '/?([0-9]{1,}?)/?',"page=");
@@ -153,20 +153,20 @@ class Custom_Post_Type_Permalinks {
153
 
154
  endforeach;
155
 
156
- $taxonomies = get_taxonomies(array("show_ui" => true),'objects');
157
  foreach ( $taxonomies as $taxonomy => $objects ):
158
  $wp_rewrite->add_rewrite_tag("%$taxonomy%", '(.+?)',"$taxonomy=");
159
  endforeach;
160
-
161
  $wp_rewrite->use_verbose_page_rules = true;
162
  }
163
-
164
  function set_permalink( $post_link, $post,$leavename ) {
165
  global $wp_rewrite;
166
  $draft_or_pending = isset( $post->post_status ) && in_array( $post->post_status, array( 'draft', 'pending', 'auto-draft' ) );
167
  if( $draft_or_pending and !$leavename )
168
  return $post_link;
169
-
170
  $post_type = $post->post_type;
171
  $permalink = $wp_rewrite->get_extra_permastruct($post_type);
172
 
@@ -182,11 +182,11 @@ class Custom_Post_Type_Permalinks {
182
  foreach ( $taxonomies as $taxonomy => $objects ) {
183
  if ( strpos($permalink, "%$taxonomy%") !== false ) {
184
  $terms = get_the_terms($post->ID,$taxonomy);
185
-
186
  if ( $terms ) {
187
  usort($terms, '_usort_terms_by_ID'); // order by ID
188
  $term = $terms[0]->slug;
189
-
190
  if ( $parent = $terms[0]->parent ) {
191
  $term = $this->get_taxonomy_parents($parent,$taxonomy, false, '/', true) . $term;
192
  }
@@ -194,7 +194,7 @@ class Custom_Post_Type_Permalinks {
194
  $permalink = str_replace("%$taxonomy%", $term, $permalink);
195
  }
196
  }
197
-
198
  $user = get_userdata($post->post_author);
199
  $permalink = str_replace("%author%", $user->user_nicename, $permalink);
200
 
@@ -206,7 +206,7 @@ class Custom_Post_Type_Permalinks {
206
  $permalink = str_replace("%minute%",date("i",$post_date), $permalink);
207
  $permalink = str_replace("%second%",date("s",$post_date), $permalink);
208
 
209
- $permalink = str_replace('//',"/",$permalink);
210
  $permalink = home_url(user_trailingslashit($permalink));
211
  return $permalink;
212
  }
@@ -221,7 +221,7 @@ class Custom_Post_Type_Permalinks {
221
  * if(is_post_type_archive()) {
222
  * $arg .= '&post_type='.get_query_var( 'post_type' );
223
  * }
224
- * wp_get_archives($arg);
225
  *
226
  *
227
  *
@@ -278,7 +278,7 @@ class Custom_Post_Type_Permalinks {
278
  if( $taxonomy->_builtin ) {
279
  return $termlink;
280
  }
281
-
282
  if(empty($taxonomy)){
283
  return $termlink;
284
  }
@@ -306,30 +306,30 @@ class Custom_Post_Type_Permalinks_Admin {
306
  add_action('admin_init', array(&$this,'settings_api_init'),10);
307
  add_action('admin_init', array(&$this,'set_rules'),50);
308
  }
309
-
310
  function load_textdomain() {
311
- load_plugin_textdomain('cptp',false,'custom-post-type-permalinks');
312
  }
313
-
314
  function settings_api_init() {
315
  add_settings_section('setting_section',
316
  __("Permalink Setting for custom post type",'cptp'),
317
  array(&$this,'setting_section_callback_function'),
318
  'permalink');
319
-
320
  $post_types = get_post_types( array('_builtin'=>false, 'publicly_queryable'=>true, 'show_ui' => true) );
321
  foreach ($post_types as $post_type):
322
  if(isset($_POST['submit'])){
323
  if( strpos($_POST['_wp_http_referer'],'options-permalink.php') !== FALSE ) {
324
 
325
  $structure = trim(esc_attr($_POST[$post_type.'_structure']));#get setting
326
-
327
  #default permalink structure
328
  if( !$structure ) {
329
  $structure = '/%year%/%monthnum%/%day%/%post_id%/';
330
  }
331
  $structure = str_replace('//','/','/'.$structure);# first "/"
332
-
333
  #last "/"
334
  $lastString = substr(trim(esc_attr($_POST['permalink_structure'])),-1);
335
  $structure = rtrim($structure,'/');
@@ -337,7 +337,7 @@ class Custom_Post_Type_Permalinks_Admin {
337
  $structure = $structure.'/';
338
  }
339
 
340
- update_option($post_type.'_structure', $structure );
341
  }
342
 
343
  }
@@ -348,14 +348,14 @@ class Custom_Post_Type_Permalinks_Admin {
348
  'permalink',
349
  'setting_section',
350
  $post_type.'_structure');
351
-
352
  register_setting('permalink',$post_type.'_structure');
353
- endforeach;
354
  }
355
-
356
  function set_rules() {
357
  global $wp_rewrite;
358
- $wp_rewrite->flush_rules();
359
  }
360
 
361
  function setting_section_callback_function() {
@@ -363,14 +363,14 @@ class Custom_Post_Type_Permalinks_Admin {
363
  <p><?php _e("Setting permalinks of custom post type.",'cptp');?><br />
364
  <?php _e("The tags you can use is WordPress Structure Tags and '%{custom_taxonomy_slug}%'.",'cptp');?><br />
365
  <?php _e("%{custom_taxonomy_slug}% is replaced the taxonomy's term.'.",'cptp');?></p>
366
-
367
  <p><?php _e("Presence of the trailing '/' is unified into a standard permalink structure setting.",'cptp');?><br />
368
  <?php _e("If you don't entered permalink structure, permalink is configured /%year%/%monthnum%/%day%/%post_id%/.",'cptp');?>
369
  </p>
370
  <?php
371
  }
372
 
373
- function setting_callback_function( $option ) {
374
  $post_type = str_replace('_structure',"" ,$option);
375
  $slug = get_post_type_object($post_type)->rewrite['slug'];
376
  if( !$slug ) {
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.7.3.1
9
  Text Domain: cptp
10
  Domain Path: /
11
  */
47
  add_action('generate_rewrite_rules', array(&$this,'add_tax_rewrite'));
48
  add_filter('term_link', array(&$this,'set_term_link'),10,3);
49
  }
50
+
51
  static function uninstall_hook() {
52
  if ( function_exists('register_uninstall_hook') ) {
53
  register_uninstall_hook(__FILE__, array(&$this,'uninstall_hook_custom_permalink'));
54
  }
55
  }
56
+
57
  function get_taxonomy_parents( $id, $taxonomy = 'category', $link = false, $separator = '/', $nicename = false, $visited = array() ) {
58
  $chain = '';
59
  $parent = &get_term( $id, $taxonomy, OBJECT, 'raw');
60
  if ( is_wp_error( $parent ) )
61
  return $parent;
62
+
63
  if ( $nicename )
64
  $name = $parent->slug;
65
  else
66
  $name = $parent->name;
67
+
68
  if ( $parent->parent && ( $parent->parent != $parent->term_id ) && !in_array( $parent->parent, $visited ) ) {
69
  $visited[] = $parent->parent;
70
  $chain .= $this->get_taxonomy_parents( $parent->parent, $taxonomy, $link, $separator, $nicename, $visited );
71
  }
72
+
73
  if ( $link )
74
  $chain .= '<a href="' . get_term_link( $parent->term_id, $taxonomy ) . '" title="' . esc_attr( sprintf( __( "View all posts in %s" ), $parent->name ) ) . '">'.$name.'</a>' . $separator;
75
  else
78
  }
79
 
80
 
81
+
82
  function set_archive_rewrite() {
83
  $post_types = get_post_types( array('_builtin'=>false, 'publicly_queryable'=>true,'show_ui' => true) );
84
 
127
  $post_types = get_post_types( array('_builtin'=>false, 'publicly_queryable'=>true,'show_ui' => true) );
128
 
129
  foreach ( $post_types as $post_type ):
130
+
131
  $permalink = get_option($post_type.'_structure');
132
 
133
  if( !$permalink ){
134
+ $permalink = '/%year%/%monthnum%/%day%/%post_id%/';
135
  }
136
 
137
  $permalink = str_replace('%postname%','%'.$post_type.'%',$permalink);
141
  if( !$slug ) {
142
  $slug = $post_type;
143
  }
144
+
145
  $permalink = '/'.$slug.'/'.$permalink;
146
+ $permalink = $permalink.'/%'.$post_type.'_page%';
147
  $permalink = str_replace('//','/',$permalink);
148
+
149
  $wp_rewrite->add_rewrite_tag('%post_type%', '([^/]+)','post_type=');
150
  $wp_rewrite->add_rewrite_tag('%'.$post_type.'_id%', '([0-9]{1,})','post_type='.$post_type.'&p=');
151
  $wp_rewrite->add_rewrite_tag('%'.$post_type.'_page%', '/?([0-9]{1,}?)/?',"page=");
153
 
154
  endforeach;
155
 
156
+ $taxonomies = get_taxonomies(array("show_ui" => true, "_builtin" => false),'objects');
157
  foreach ( $taxonomies as $taxonomy => $objects ):
158
  $wp_rewrite->add_rewrite_tag("%$taxonomy%", '(.+?)',"$taxonomy=");
159
  endforeach;
160
+
161
  $wp_rewrite->use_verbose_page_rules = true;
162
  }
163
+
164
  function set_permalink( $post_link, $post,$leavename ) {
165
  global $wp_rewrite;
166
  $draft_or_pending = isset( $post->post_status ) && in_array( $post->post_status, array( 'draft', 'pending', 'auto-draft' ) );
167
  if( $draft_or_pending and !$leavename )
168
  return $post_link;
169
+
170
  $post_type = $post->post_type;
171
  $permalink = $wp_rewrite->get_extra_permastruct($post_type);
172
 
182
  foreach ( $taxonomies as $taxonomy => $objects ) {
183
  if ( strpos($permalink, "%$taxonomy%") !== false ) {
184
  $terms = get_the_terms($post->ID,$taxonomy);
185
+
186
  if ( $terms ) {
187
  usort($terms, '_usort_terms_by_ID'); // order by ID
188
  $term = $terms[0]->slug;
189
+
190
  if ( $parent = $terms[0]->parent ) {
191
  $term = $this->get_taxonomy_parents($parent,$taxonomy, false, '/', true) . $term;
192
  }
194
  $permalink = str_replace("%$taxonomy%", $term, $permalink);
195
  }
196
  }
197
+
198
  $user = get_userdata($post->post_author);
199
  $permalink = str_replace("%author%", $user->user_nicename, $permalink);
200
 
206
  $permalink = str_replace("%minute%",date("i",$post_date), $permalink);
207
  $permalink = str_replace("%second%",date("s",$post_date), $permalink);
208
 
209
+ $permalink = str_replace('//',"/",$permalink);
210
  $permalink = home_url(user_trailingslashit($permalink));
211
  return $permalink;
212
  }
221
  * if(is_post_type_archive()) {
222
  * $arg .= '&post_type='.get_query_var( 'post_type' );
223
  * }
224
+ * wp_get_archives($arg);
225
  *
226
  *
227
  *
278
  if( $taxonomy->_builtin ) {
279
  return $termlink;
280
  }
281
+
282
  if(empty($taxonomy)){
283
  return $termlink;
284
  }
306
  add_action('admin_init', array(&$this,'settings_api_init'),10);
307
  add_action('admin_init', array(&$this,'set_rules'),50);
308
  }
309
+
310
  function load_textdomain() {
311
+ load_plugin_textdomain('cptp',false,'custom-post-type-permalinks');
312
  }
313
+
314
  function settings_api_init() {
315
  add_settings_section('setting_section',
316
  __("Permalink Setting for custom post type",'cptp'),
317
  array(&$this,'setting_section_callback_function'),
318
  'permalink');
319
+
320
  $post_types = get_post_types( array('_builtin'=>false, 'publicly_queryable'=>true, 'show_ui' => true) );
321
  foreach ($post_types as $post_type):
322
  if(isset($_POST['submit'])){
323
  if( strpos($_POST['_wp_http_referer'],'options-permalink.php') !== FALSE ) {
324
 
325
  $structure = trim(esc_attr($_POST[$post_type.'_structure']));#get setting
326
+
327
  #default permalink structure
328
  if( !$structure ) {
329
  $structure = '/%year%/%monthnum%/%day%/%post_id%/';
330
  }
331
  $structure = str_replace('//','/','/'.$structure);# first "/"
332
+
333
  #last "/"
334
  $lastString = substr(trim(esc_attr($_POST['permalink_structure'])),-1);
335
  $structure = rtrim($structure,'/');
337
  $structure = $structure.'/';
338
  }
339
 
340
+ update_option($post_type.'_structure', $structure );
341
  }
342
 
343
  }
348
  'permalink',
349
  'setting_section',
350
  $post_type.'_structure');
351
+
352
  register_setting('permalink',$post_type.'_structure');
353
+ endforeach;
354
  }
355
+
356
  function set_rules() {
357
  global $wp_rewrite;
358
+ $wp_rewrite->flush_rules();
359
  }
360
 
361
  function setting_section_callback_function() {
363
  <p><?php _e("Setting permalinks of custom post type.",'cptp');?><br />
364
  <?php _e("The tags you can use is WordPress Structure Tags and '%{custom_taxonomy_slug}%'.",'cptp');?><br />
365
  <?php _e("%{custom_taxonomy_slug}% is replaced the taxonomy's term.'.",'cptp');?></p>
366
+
367
  <p><?php _e("Presence of the trailing '/' is unified into a standard permalink structure setting.",'cptp');?><br />
368
  <?php _e("If you don't entered permalink structure, permalink is configured /%year%/%monthnum%/%day%/%post_id%/.",'cptp');?>
369
  </p>
370
  <?php
371
  }
372
 
373
+ function setting_callback_function( $option ) {
374
  $post_type = str_replace('_structure',"" ,$option);
375
  $slug = get_post_type_object($post_type)->rewrite['slug'];
376
  if( !$slug ) {
readme.txt CHANGED
@@ -3,7 +3,7 @@ Contributors: Toro_Unit
3
  Tags: custom post type,permalink
4
  Requires at least: 3.2
5
  Tested up to: 3.3
6
- Stable tag: 0.7.3
7
 
8
  Lets you edit the permalink of custom post type.
9
 
@@ -25,7 +25,7 @@ That's it. You can access the permalinks setting by going to *Settings -> Permal
25
 
26
  == Screenshots ==
27
 
28
- 1. screenshot-1.png
29
 
30
 
31
  == Changelog ==
3
  Tags: custom post type,permalink
4
  Requires at least: 3.2
5
  Tested up to: 3.3
6
+ Stable tag: 0.7.3.1
7
 
8
  Lets you edit the permalink of custom post type.
9
 
25
 
26
  == Screenshots ==
27
 
28
+ 1. screenshot-1.png
29
 
30
 
31
  == Changelog ==