Custom Post Type Permalinks - Version 0.7.5.2

Version Description

Download this release

Release Info

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

Code changes from version 0.7.5.1 to 0.7.5.2

Files changed (2) hide show
  1. custom-post-type-permalinks.php +75 -56
  2. readme.txt +1 -1
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.5.1
9
  Text Domain: cptp
10
  Domain Path: /
11
  */
@@ -14,19 +14,19 @@ Domain Path: /
14
 
15
  /* Copyright 2011 Toro_Unit (email : mail@torounit.com)
16
 
17
- This program is free software; you can redistribute it and/or modify
18
- it under the terms of the GNU General Public License as published by
19
- the Free Software Foundation; either version 2 of the License, or
20
- (at your option) any later version.
21
 
22
- This program is distributed in the hope that it will be useful,
23
- but WITHOUT ANY WARRANTY; without even the implied warranty of
24
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25
- GNU General Public License for more details.
26
 
27
- You should have received a copy of the GNU General Public License
28
- along with this program; if not, write to the Free Software
29
- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
30
  */
31
 
32
  /* This plugin don't support Multisite yet.*/
@@ -37,14 +37,14 @@ class Custom_Post_Type_Permalinks {
37
  static public $default_structure = '/%year%/%monthnum%/%day%/%post_id%/';
38
 
39
  function __construct () {
40
- add_action('wp_loaded',array(&$this,'set_archive_rewrite'),99);
41
- add_action('wp_loaded', array(&$this,'set_rewrite'),100);
42
  add_filter('post_type_link', array(&$this,'set_permalink'),10,3);
43
 
44
  add_filter('getarchives_where', array(&$this,'get_archives_where'), 10, 2);
45
  add_filter('get_archives_link', array(&$this,'get_archives_link'));
46
 
47
- add_action('wp_loaded', array(&$this,'add_tax_rewrite'));
48
  add_filter('term_link', array(&$this,'set_term_link'),10,3);
49
  }
50
 
@@ -79,37 +79,37 @@ class Custom_Post_Type_Permalinks {
79
  $permalink = get_option( $post_type.'_structure' );
80
  $slug = get_post_type_object($post_type)->rewrite['slug'];
81
 
82
- if( $slug ){
83
- 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' );
84
- 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' );
85
- 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' );
86
- 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' );
87
- 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' );
88
- 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' );
89
- 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' );
90
- 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' );
91
- 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' );
92
- 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' );
93
- 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' );
94
- add_rewrite_rule( $slug.'/date/([0-9]{4})/?$', 'index.php?year=$matches[1]&post_type='.$post_type, 'top' );
95
- add_rewrite_rule( $slug.'/author/([^/]+)/?$', 'index.php?author=$matches[1]&post_type='.$post_type, 'top' );
96
- add_rewrite_rule( $slug.'/?$', 'index.php?post_type='.$post_type, 'top' );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
97
  }
98
-
99
- add_rewrite_rule( $post_type.'/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' );
100
- add_rewrite_rule( $post_type.'/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' );
101
- add_rewrite_rule( $post_type.'/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' );
102
- add_rewrite_rule( $post_type.'/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' );
103
- add_rewrite_rule( $post_type.'/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' );
104
- add_rewrite_rule( $post_type.'/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' );
105
- add_rewrite_rule( $post_type.'/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' );
106
- add_rewrite_rule( $post_type.'/date/([0-9]{4})/([0-9]{1,2})/?$', 'index.php?year=$matches[1]&monthnum=$matches[2]&post_type='.$post_type, 'top' );
107
- add_rewrite_rule( $post_type.'/date/([0-9]{4})/feed/(feed|rdf|rss|rss2|atom)/?$', 'index.php?year=$matches[1]&feed=$matches[2]&post_type='.$post_type, 'top' );
108
- add_rewrite_rule( $post_type.'/date/([0-9]{4})/(feed|rdf|rss|rss2|atom)/?$', 'index.php?year=$matches[1]&feed=$matches[2]&post_type='.$post_type, 'top' );
109
- add_rewrite_rule( $post_type.'/date/([0-9]{4})/page/?([0-9]{1,})/?$', 'index.php?year=$matches[1]&paged=$matches[2]&post_type='.$post_type, 'top' );
110
- add_rewrite_rule( $post_type.'/date/([0-9]{4})/?$', 'index.php?year=$matches[1]&post_type='.$post_type, 'top' );
111
- add_rewrite_rule( $post_type.'/date/([0-9]{4})/?$', 'index.php?author=$matches[1]&post_type='.$post_type, 'top' );
112
- add_rewrite_rule( $post_type.'/?$', 'index.php?post_type='.$post_type, 'top' );
113
  endforeach;
114
  }
115
 
@@ -148,6 +148,10 @@ class Custom_Post_Type_Permalinks {
148
  endforeach;
149
 
150
  $wp_rewrite->use_verbose_page_rules = true;
 
 
 
 
151
  }
152
 
153
  function set_permalink( $post_link, $post,$leavename ) {
@@ -200,7 +204,7 @@ class Custom_Post_Type_Permalinks {
200
 
201
 
202
  $permalink = home_url( user_trailingslashit( $permalink ) );
203
- $str = rtrim( preg_replace("/%[a-z]*%/","",get_option("permalink_structure")) ,'/');
204
  $permalink = str_replace($str, "", $permalink );
205
 
206
  return $permalink;
@@ -224,10 +228,16 @@ class Custom_Post_Type_Permalinks {
224
 
225
  function get_archives_link( $link_html ) {
226
 
 
 
227
  if (isset($this->get_archives_where_r['post_type']) and $this->get_archives_where_r['type'] != 'postbypost'){
228
  $blog_url = get_bloginfo("url");
229
- $blog_url = rtrim($blog_url,"/");
230
- $link_html = str_replace($blog_url,$blog_url.'/'.$this->get_archives_where_r['post_type'].'/date',$link_html);
 
 
 
 
231
  }
232
 
233
  return $link_html;
@@ -297,15 +307,16 @@ class Custom_Post_Type_Permalinks_Admin {
297
 
298
  function __construct () {
299
  add_action('init', array(&$this,'load_textdomain'));
300
- add_action('admin_init', array(&$this,'settings_api_init'),10);
 
301
  }
302
 
303
- function load_textdomain() {
304
  load_plugin_textdomain('cptp',false,'custom-post-type-permalinks');
305
  }
306
 
307
  function settings_api_init() {
308
- add_settings_section('cptp_setting_section',
309
  __("Permalink Setting for custom post type",'cptp'),
310
  array(&$this,'setting_section_callback_function'),
311
  'permalink'
@@ -328,7 +339,7 @@ class Custom_Post_Type_Permalinks_Admin {
328
  $lastString = substr(trim(esc_attr($_POST['permalink_structure'])),-1);
329
  $structure = rtrim($structure,'/');
330
 
331
- if ( $lastString == '/')
332
  $structure = $structure.'/';
333
 
334
  update_option($post_type.'_structure', $structure );
@@ -336,7 +347,7 @@ class Custom_Post_Type_Permalinks_Admin {
336
 
337
  }
338
 
339
- add_settings_field($post_type.'_structure',
340
  $post_type,
341
  array(&$this,'setting_structure_callback_function'),
342
  'permalink',
@@ -344,7 +355,7 @@ class Custom_Post_Type_Permalinks_Admin {
344
  $post_type.'_structure'
345
  );
346
 
347
- register_setting('permalink',$post_type.'_structure');
348
  endforeach;
349
 
350
  add_settings_field(
@@ -366,13 +377,16 @@ class Custom_Post_Type_Permalinks_Admin {
366
  }
367
  update_option('no_taxonomy_structure', $set);
368
 
369
- $this->set_rules();
370
  }
 
371
  }
372
 
373
  function set_rules() {
 
374
  global $wp_rewrite;
375
- $wp_rewrite->flush_rules();
 
 
376
  }
377
 
378
  function setting_section_callback_function() {
@@ -386,9 +400,12 @@ class Custom_Post_Type_Permalinks_Admin {
386
  <?php _e("If you don't entered permalink structure, permalink is configured /%year%/%monthnum%/%day%/%post_id%/.",'cptp');?>
387
  </p>
388
  <?php
 
 
389
  }
390
 
391
  function setting_structure_callback_function( $option ) {
 
392
  $post_type = str_replace('_structure',"" ,$option);
393
  $slug = get_post_type_object($post_type)->rewrite['slug'];
394
  if( !$slug )
@@ -398,12 +415,14 @@ class Custom_Post_Type_Permalinks_Admin {
398
  }
399
 
400
  function setting_no_tax_structure_callback_function(){
 
401
  echo '<input name="no_taxonomy_structure" id="no_taxonomy_structure" type="checkbox" value="1" class="code" ' . checked( false, get_option('no_taxonomy_structure'),false) . ' /> ';
402
  _e("If you check,The custom taxonomy's permalinks is example.com/post_type/taxonomy/term.","cptp");
403
  }
404
  }
405
 
406
 
 
407
  if(get_option("permalink_structure") != "")
408
  new Custom_Post_Type_Permalinks;
409
 
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.5.2
9
  Text Domain: cptp
10
  Domain Path: /
11
  */
14
 
15
  /* Copyright 2011 Toro_Unit (email : mail@torounit.com)
16
 
17
+ This program is free software; you can redistribute it and/or modify
18
+ it under the terms of the GNU General Public License as published by
19
+ the Free Software Foundation; either version 2 of the License, or
20
+ (at your option) any later version.
21
 
22
+ This program is distributed in the hope that it will be useful,
23
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
24
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25
+ GNU General Public License for more details.
26
 
27
+ You should have received a copy of the GNU General Public License
28
+ along with this program; if not, write to the Free Software
29
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
30
  */
31
 
32
  /* This plugin don't support Multisite yet.*/
37
  static public $default_structure = '/%year%/%monthnum%/%day%/%post_id%/';
38
 
39
  function __construct () {
40
+ add_action('admin_init',array(&$this,'set_archive_rewrite'),99);
41
+ add_action('admin_init', array(&$this,'set_rewrite'),100);
42
  add_filter('post_type_link', array(&$this,'set_permalink'),10,3);
43
 
44
  add_filter('getarchives_where', array(&$this,'get_archives_where'), 10, 2);
45
  add_filter('get_archives_link', array(&$this,'get_archives_link'));
46
 
47
+ add_action('admin_init', array(&$this,'add_tax_rewrite'));
48
  add_filter('term_link', array(&$this,'set_term_link'),10,3);
49
  }
50
 
79
  $permalink = get_option( $post_type.'_structure' );
80
  $slug = get_post_type_object($post_type)->rewrite['slug'];
81
 
82
+ 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' );
83
+ 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' );
84
+ 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' );
85
+ 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' );
86
+ 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' );
87
+ 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' );
88
+ 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' );
89
+ 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' );
90
+ 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' );
91
+ 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' );
92
+ 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' );
93
+ add_rewrite_rule( $slug.'/date/([0-9]{4})/?$', 'index.php?year=$matches[1]&post_type='.$post_type, 'top' );
94
+ add_rewrite_rule( $slug.'/author/([^/]+)/?$', 'index.php?author=$matches[1]&post_type='.$post_type, 'top' );
95
+ add_rewrite_rule( $slug.'/?$', 'index.php?post_type='.$post_type, 'top' );
96
+
97
+ if( $slug != $post_type ){
98
+ add_rewrite_rule( $post_type.'/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' );
99
+ add_rewrite_rule( $post_type.'/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' );
100
+ add_rewrite_rule( $post_type.'/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' );
101
+ add_rewrite_rule( $post_type.'/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' );
102
+ add_rewrite_rule( $post_type.'/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' );
103
+ add_rewrite_rule( $post_type.'/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' );
104
+ add_rewrite_rule( $post_type.'/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' );
105
+ add_rewrite_rule( $post_type.'/date/([0-9]{4})/([0-9]{1,2})/?$', 'index.php?year=$matches[1]&monthnum=$matches[2]&post_type='.$post_type, 'top' );
106
+ add_rewrite_rule( $post_type.'/date/([0-9]{4})/feed/(feed|rdf|rss|rss2|atom)/?$', 'index.php?year=$matches[1]&feed=$matches[2]&post_type='.$post_type, 'top' );
107
+ add_rewrite_rule( $post_type.'/date/([0-9]{4})/(feed|rdf|rss|rss2|atom)/?$', 'index.php?year=$matches[1]&feed=$matches[2]&post_type='.$post_type, 'top' );
108
+ add_rewrite_rule( $post_type.'/date/([0-9]{4})/page/?([0-9]{1,})/?$', 'index.php?year=$matches[1]&paged=$matches[2]&post_type='.$post_type, 'top' );
109
+ add_rewrite_rule( $post_type.'/date/([0-9]{4})/?$', 'index.php?year=$matches[1]&post_type='.$post_type, 'top' );
110
+ add_rewrite_rule( $post_type.'/date/([0-9]{4})/?$', 'index.php?author=$matches[1]&post_type='.$post_type, 'top' );
111
+ add_rewrite_rule( $post_type.'/?$', 'index.php?post_type='.$post_type, 'top' );
112
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
113
  endforeach;
114
  }
115
 
148
  endforeach;
149
 
150
  $wp_rewrite->use_verbose_page_rules = true;
151
+ if(isset($_POST['submit']) && strpos($_POST['_wp_http_referer'],'options-permalink.php') !== FALSE ) {
152
+ global $wp_rewrite;
153
+ $wp_rewrite->flush_rules();
154
+ }
155
  }
156
 
157
  function set_permalink( $post_link, $post,$leavename ) {
204
 
205
 
206
  $permalink = home_url( user_trailingslashit( $permalink ) );
207
+ $str = rtrim( preg_replace("/%[a-z,_]*%/","",get_option("permalink_structure")) ,'/');
208
  $permalink = str_replace($str, "", $permalink );
209
 
210
  return $permalink;
228
 
229
  function get_archives_link( $link_html ) {
230
 
231
+ //$slug = get_post_type_object($this->get_archives_where_r['post_type'])->rewrite['slug'];
232
+
233
  if (isset($this->get_archives_where_r['post_type']) and $this->get_archives_where_r['type'] != 'postbypost'){
234
  $blog_url = get_bloginfo("url");
235
+ if($str = rtrim( preg_replace("/%[a-z,_]*%/","",get_option("permalink_structure")) ,'/')) {
236
+ $link_html = str_replace($str, '/'.$this->get_archives_where_r['post_type'], $link_html);
237
+ }else{
238
+ $blog_url = rtrim($blog_url,"/");
239
+ $link_html = str_replace($blog_url,$blog_url.'/'.$this->get_archives_where_r['post_type'].'/date',$link_html);
240
+ }
241
  }
242
 
243
  return $link_html;
307
 
308
  function __construct () {
309
  add_action('init', array(&$this,'load_textdomain'));
310
+ add_action('admin_init', array(&$this,'settings_api_init'),30);
311
+ //add_action('admin_init', array(&$this,'set_rules'),50);
312
  }
313
 
314
+ function load_textdomain() {
315
  load_plugin_textdomain('cptp',false,'custom-post-type-permalinks');
316
  }
317
 
318
  function settings_api_init() {
319
+ add_settings_section('cptp_setting_section',
320
  __("Permalink Setting for custom post type",'cptp'),
321
  array(&$this,'setting_section_callback_function'),
322
  'permalink'
339
  $lastString = substr(trim(esc_attr($_POST['permalink_structure'])),-1);
340
  $structure = rtrim($structure,'/');
341
 
342
+ if ( $lastString == '/')
343
  $structure = $structure.'/';
344
 
345
  update_option($post_type.'_structure', $structure );
347
 
348
  }
349
 
350
+ add_settings_field($post_type.'_structure',
351
  $post_type,
352
  array(&$this,'setting_structure_callback_function'),
353
  'permalink',
355
  $post_type.'_structure'
356
  );
357
 
358
+ register_setting('permalink',$post_type.'_structure');
359
  endforeach;
360
 
361
  add_settings_field(
377
  }
378
  update_option('no_taxonomy_structure', $set);
379
 
 
380
  }
381
+
382
  }
383
 
384
  function set_rules() {
385
+
386
  global $wp_rewrite;
387
+ if( strpos($_SERVER["REQUEST_URI"],'options-permalink.php') !== FALSE ) {
388
+ $wp_rewrite->flush_rules();
389
+ }
390
  }
391
 
392
  function setting_section_callback_function() {
400
  <?php _e("If you don't entered permalink structure, permalink is configured /%year%/%monthnum%/%day%/%post_id%/.",'cptp');?>
401
  </p>
402
  <?php
403
+
404
+
405
  }
406
 
407
  function setting_structure_callback_function( $option ) {
408
+
409
  $post_type = str_replace('_structure',"" ,$option);
410
  $slug = get_post_type_object($post_type)->rewrite['slug'];
411
  if( !$slug )
415
  }
416
 
417
  function setting_no_tax_structure_callback_function(){
418
+
419
  echo '<input name="no_taxonomy_structure" id="no_taxonomy_structure" type="checkbox" value="1" class="code" ' . checked( false, get_option('no_taxonomy_structure'),false) . ' /> ';
420
  _e("If you check,The custom taxonomy's permalinks is example.com/post_type/taxonomy/term.","cptp");
421
  }
422
  }
423
 
424
 
425
+
426
  if(get_option("permalink_structure") != "")
427
  new Custom_Post_Type_Permalinks;
428
 
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.5.1
7
 
8
  Lets you edit the permalink of custom post type.
9
 
3
  Tags: custom post type,permalink
4
  Requires at least: 3.2
5
  Tested up to: 3.3
6
+ Stable tag: 0.7.5.2
7
 
8
  Lets you edit the permalink of custom post type.
9