Version Description
Download this release
Release Info
Developer | Toro_Unit |
Plugin | Custom Post Type Permalinks |
Version | 0.7 |
Comparing to | |
See all releases |
Code changes from version 0.6.2 to 0.7
- cptp-ja.mo +0 -0
- cptp-ja.po +9 -10
- cptp.pot +0 -36
- custom-post-type-permalinks.php +156 -117
- readme.txt +10 -4
cptp-ja.mo
CHANGED
Binary file
|
cptp-ja.po
CHANGED
@@ -5,32 +5,31 @@
|
|
5 |
#
|
6 |
msgid ""
|
7 |
msgstr ""
|
8 |
-
"Project-Id-Version: Custom Post Type Permalinks
|
9 |
"Report-Msgid-Bugs-To: \n"
|
10 |
"POT-Creation-Date: 2011-09-21 11:00+0900\n"
|
11 |
-
"PO-Revision-Date: 2011-12-
|
12 |
"Last-Translator: Toro_Unit <mail@torounit.com>\n"
|
13 |
-
"Language-Team:
|
14 |
"MIME-Version: 1.0\n"
|
15 |
"Content-Type: text/plain; charset=UTF-8\n"
|
16 |
"Content-Transfer-Encoding: 8bit\n"
|
17 |
"X-Poedit-SourceCharset: UTF-8\n"
|
18 |
-
"X-Poedit-Language:
|
19 |
"X-Poedit-Country: JAPAN\n"
|
20 |
|
21 |
-
#: custom-post-type-permalinks.php:254
|
22 |
msgid "Permalinks of Custom post type"
|
23 |
msgstr "カスタム投稿タイプのパーマリンク"
|
24 |
|
25 |
-
|
|
|
|
|
26 |
msgid "Setting permalinks of custom post type."
|
27 |
msgstr "カスタム投稿タイプごとのパーマリンク構造を設定できます。"
|
28 |
|
29 |
-
|
30 |
-
|
31 |
-
msgstr "使用できるタグは、%year%,%monthnum%,%day%,%hour%,%minute%,%second%,%postname%,%post_id%,%author%です。"
|
32 |
|
33 |
-
#: custom-post-type-permalinks.php:272
|
34 |
msgid "If you don't entered permalink structure, permalink is configured /%year%/%monthnum%/%day%/%post_id%/."
|
35 |
msgstr "未入力のときは、/%year%/%monthnum%/%day%/%post_id%/に設定されます。"
|
36 |
|
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-14 21:19+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"
|
15 |
"Content-Type: text/plain; charset=UTF-8\n"
|
16 |
"Content-Transfer-Encoding: 8bit\n"
|
17 |
"X-Poedit-SourceCharset: UTF-8\n"
|
18 |
+
"X-Poedit-Language: Japanese\n"
|
19 |
"X-Poedit-Country: JAPAN\n"
|
20 |
|
|
|
21 |
msgid "Permalinks of Custom post type"
|
22 |
msgstr "カスタム投稿タイプのパーマリンク"
|
23 |
|
24 |
+
msgid "Permalink Setting for custom post type"
|
25 |
+
msgstr "カスタム投稿タイプのパーマリンク設定"
|
26 |
+
|
27 |
msgid "Setting permalinks of custom post type."
|
28 |
msgstr "カスタム投稿タイプごとのパーマリンク構造を設定できます。"
|
29 |
|
30 |
+
msgid "The tags you can use is '%year%','%monthnum%','%day%','%hour%','%minute%','%second%','%postname%','%post_id%','%author%','%category%','%tag%' and '%{custom_taxonomy_slug}%(Replace the taxomomy term)'."
|
31 |
+
msgstr "使用できるタグは、'%year%','%monthnum%','%day%','%hour%','%minute%','%second%','%postname%','%post_id%','%author%','%category%','%tag%'、そして、'%{カスタム分類名}%'(その分類のタームに置換されます)です。"
|
|
|
32 |
|
|
|
33 |
msgid "If you don't entered permalink structure, permalink is configured /%year%/%monthnum%/%day%/%post_id%/."
|
34 |
msgstr "未入力のときは、/%year%/%monthnum%/%day%/%post_id%/に設定されます。"
|
35 |
|
cptp.pot
DELETED
@@ -1,36 +0,0 @@
|
|
1 |
-
# LANGUAGE (LOCALE) translation for Custom Post Type Permalinks.
|
2 |
-
# Copyright (C) 2011 Toro_Unit.
|
3 |
-
# This file is distributed under the same license as the WordPress package.
|
4 |
-
# FIRST AUTHOR <mail@torounit.com>, YEAR.
|
5 |
-
#
|
6 |
-
#, fuzzy
|
7 |
-
msgid ""
|
8 |
-
msgstr ""
|
9 |
-
"Project-Id-Version: Custom Post Type Permalinks 1.0 Ja \n"
|
10 |
-
"Report-Msgid-Bugs-To: \n"
|
11 |
-
"POT-Creation-Date: 2011-09-21 11:00+0900\n"
|
12 |
-
"PO-Revision-Date: 2011-09-21 11:00+0900\n"
|
13 |
-
"Last-Translator: Toro_Unit <mail@torounit.com>\n"
|
14 |
-
"Language-Team: Toro_Unit <mail@torounit.com>\n"
|
15 |
-
"MIME-Version: 1.0\n"
|
16 |
-
"Content-Type: text/plain; charset=CHARSET\n"
|
17 |
-
"Content-Transfer-Encoding: 8bit\n"
|
18 |
-
"X-Poedit-Language: Japanese\n"
|
19 |
-
"X-Poedit-Country: JAPAN\n"
|
20 |
-
"X-Poedit-SourceCharset: UTF-8\n"
|
21 |
-
|
22 |
-
#: custom-post-type-permalinks.php:254
|
23 |
-
msgid "Permalinks of Custom post type"
|
24 |
-
msgstr ""
|
25 |
-
|
26 |
-
#: custom-post-type-permalinks.php:270
|
27 |
-
msgid "Setting permalinks of custom post type."
|
28 |
-
msgstr ""
|
29 |
-
|
30 |
-
#: custom-post-type-permalinks.php:271
|
31 |
-
msgid "The tags you can use is '%year%','%monthnum%','%day%','%hour%','%minute%','%second%','%postname%','%post_id%' and '%author%'."
|
32 |
-
msgstr ""
|
33 |
-
|
34 |
-
#: custom-post-type-permalinks.php:272
|
35 |
-
msgid "If you don't entered permalink structure, permalink is configured /%year%/%monthnum%/%day%/%post_id%/."
|
36 |
-
msgstr ""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
*/
|
10 |
|
11 |
|
@@ -33,13 +33,40 @@ Version: 0.6.2
|
|
33 |
/* This plugin don't support Multisite yet.*/
|
34 |
|
35 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
36 |
|
37 |
class Custom_Post_Type_Permalinks {
|
38 |
|
39 |
-
function
|
40 |
-
add_action('
|
41 |
-
add_action('
|
42 |
-
add_filter('post_type_link', array(&$this,'set_permalink'),10,
|
43 |
|
44 |
add_filter('getarchives_where', array(&$this,'get_archives_where'), 10, 2);
|
45 |
add_filter('get_archives_link', array(&$this,'get_archives_link'));
|
@@ -48,20 +75,21 @@ class Custom_Post_Type_Permalinks {
|
|
48 |
add_filter('term_link', array(&$this,'set_term_link'),10,3);
|
49 |
|
50 |
|
|
|
|
|
|
|
51 |
if ( function_exists('register_uninstall_hook') ) {
|
52 |
register_uninstall_hook(__FILE__, array(&$this,'uninstall_hook_custom_permalink'));
|
53 |
}
|
54 |
-
|
55 |
}
|
56 |
|
57 |
-
|
58 |
|
59 |
|
60 |
|
61 |
|
62 |
//カスタム投稿タイプのアーカイブのリライトルールの追加
|
63 |
function set_archive_rewrite() {
|
64 |
-
$post_types = get_post_types(array("_builtin"=>false));
|
65 |
|
66 |
foreach ($post_types as $post_type):
|
67 |
if(!$post_type) continue;
|
@@ -75,6 +103,7 @@ class Custom_Post_Type_Permalinks {
|
|
75 |
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");
|
76 |
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");
|
77 |
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");
|
|
|
78 |
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");
|
79 |
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");
|
80 |
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");
|
@@ -107,88 +136,92 @@ class Custom_Post_Type_Permalinks {
|
|
107 |
|
108 |
|
109 |
|
110 |
-
|
111 |
function set_rewrite() {
|
112 |
global $wp_rewrite;
|
113 |
-
$post_types = get_post_types(array("_builtin"=>false));
|
|
|
114 |
foreach ($post_types as $post_type):
|
115 |
|
116 |
$permalink = get_option($post_type."_structure");
|
117 |
$slug = get_post_type_object($post_type)->rewrite["slug"];
|
|
|
118 |
if(!$permalink){
|
119 |
$permalink = '/%year%/%monthnum%/%day%/%post_id%/';
|
120 |
}
|
121 |
-
|
122 |
-
//フラグ
|
123 |
-
$post_id_count = 0;
|
124 |
-
$postname_count = 0;
|
125 |
-
|
126 |
-
//個別記事のパーマリンク
|
127 |
-
$permalink = str_replace('%post_id%','%'.$post_type.'_id%',$permalink,$post_id_count);
|
128 |
-
$permalink = str_replace('%postname%','%'.$post_type.'name%',$permalink,$postname_count);
|
129 |
-
|
130 |
-
$wp_rewrite->add_rewrite_tag('%'.$post_type.'_id%', '([^/]+)','post_type='.$post_type.'&p=');
|
131 |
-
$wp_rewrite->add_rewrite_tag('%'.$post_type.'name%', '([^/]+)',$post_type.'=');
|
132 |
-
$wp_rewrite->add_permastruct($post_type,$slug.$permalink, false);
|
133 |
|
|
|
134 |
|
|
|
|
|
135 |
|
136 |
-
//個別投稿のページング
|
137 |
-
$permalink_paged = $permalink;
|
138 |
-
|
139 |
-
$permalink_paged = str_replace("%year%","[0-9]{4}", $permalink_paged);
|
140 |
-
$permalink_paged = str_replace("%monthnum%","[0-9]{1,2}", $permalink_paged);
|
141 |
-
$permalink_paged = str_replace("%day%","[0-9]{1,2}", $permalink_paged);
|
142 |
-
$permalink_paged = str_replace("%hour%","[0-9]{1,2}", $permalink_paged);
|
143 |
-
$permalink_paged = str_replace("%minute%","[0-9]{1,2}", $permalink_paged);
|
144 |
-
$permalink_paged = str_replace("%second%","[0-9]{1,2}", $permalink_paged);
|
145 |
|
146 |
-
$
|
147 |
-
$
|
148 |
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
$count = $post_id_count + $postname_count;
|
154 |
-
|
155 |
-
if( $count == 1 ){
|
156 |
-
if($post_id_count) {
|
157 |
-
add_rewrite_rule($slug.$permalink_paged,'index.php?p=$matches[1]&page=$matches[2]&post_type='.$post_type,"top");
|
158 |
-
}
|
159 |
-
elseif($postname_count) {
|
160 |
-
add_rewrite_rule($slug.$permalink_paged,'index.php?'.$post_type.'=$matches[1]&page=$matches[2]&post_type='.$post_type,"top");
|
161 |
-
}
|
162 |
-
|
163 |
-
}elseif( $count == 2 ) {
|
164 |
-
if(strpos($permalink,'%'.$post_type.'_id%') < strpos($permalink,'%'.$post_type.'name%')){
|
165 |
-
add_rewrite_rule($slug.$permalink_paged,'index.php?p=$matches[1]&page=$matches[3]&post_type='.$post_type,"top");
|
166 |
-
}else{
|
167 |
-
add_rewrite_rule($slug.$permalink_paged,'index.php?p=$matches[2]&page=$matches[3]&post_type='.$post_type,"top");
|
168 |
-
}
|
169 |
-
|
170 |
}
|
171 |
|
172 |
|
173 |
endforeach;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
174 |
}
|
175 |
|
176 |
|
177 |
-
|
178 |
-
function set_permalink($post_link, $
|
179 |
global $wp_rewrite;
|
180 |
|
181 |
-
$post = &get_post($id);
|
182 |
-
if (is_wp_error($post)){
|
183 |
-
return $post;
|
184 |
-
}
|
185 |
-
|
186 |
$newlink = $wp_rewrite->get_extra_permastruct($post->post_type);
|
|
|
|
|
187 |
|
188 |
-
$newlink = str_replace("%
|
189 |
-
$newlink = str_replace("%
|
190 |
-
|
|
|
|
|
191 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
192 |
|
193 |
$user = get_userdata($post->post_author);
|
194 |
$newlink = str_replace("%author%", $user->user_login, $newlink);
|
@@ -203,7 +236,8 @@ class Custom_Post_Type_Permalinks {
|
|
203 |
$newlink = str_replace("%hour%",date("H",$post_date), $newlink);
|
204 |
$newlink = str_replace("%minute%",date("i",$post_date), $newlink);
|
205 |
$newlink = str_replace("%second%",date("s",$post_date), $newlink);
|
206 |
-
|
|
|
207 |
|
208 |
$newlink = home_url(user_trailingslashit($newlink));
|
209 |
return $newlink;
|
@@ -293,8 +327,8 @@ class Custom_Post_Type_Permalinks {
|
|
293 |
|
294 |
|
295 |
//アンインストール時
|
296 |
-
function uninstall_hook_custom_permalink () {
|
297 |
-
$post_types = get_post_types(array("_builtin"=>false));
|
298 |
foreach ($post_types as $post_type):
|
299 |
delete_option($post_type."_structure");
|
300 |
endforeach;
|
@@ -304,74 +338,79 @@ class Custom_Post_Type_Permalinks {
|
|
304 |
|
305 |
}
|
306 |
|
307 |
-
if(get_option("permalink_structure") != ""){
|
308 |
-
$custom_post_type_permalinks = new Custom_Post_Type_Permalinks;
|
309 |
-
$custom_post_type_permalinks->init_function();
|
310 |
-
}
|
311 |
-
|
312 |
|
313 |
|
314 |
|
315 |
class Custom_Post_Type_Permalinks_Admin {
|
316 |
|
317 |
-
function
|
318 |
add_action('init', array(&$this,'load_textdomain'));
|
319 |
-
add_action('
|
320 |
|
321 |
}
|
322 |
function load_textdomain(){
|
323 |
load_plugin_textdomain('cptp',false,'custom-post-type-permalinks');
|
324 |
}
|
|
|
325 |
|
326 |
-
function
|
327 |
-
|
328 |
-
|
329 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
330 |
}
|
331 |
|
332 |
-
|
333 |
-
|
334 |
-
|
335 |
-
|
336 |
-
|
337 |
-
// 設定変更画面を表示する
|
338 |
-
?>
|
339 |
-
<div class="wrap">
|
340 |
-
<div class="icon32" id="icon-options-general"></div>
|
341 |
-
<h2><?php echo __("Permalinks of Custom post type","cptp"); //カスタム投稿タイプのパーマリンク?></h2>
|
342 |
-
<form method="post" action="options.php">
|
343 |
-
<?php wp_nonce_field('update-options'); ?>
|
344 |
<p><?php _e("Setting permalinks of custom post type.","cptp");//カスタム投稿タイプごとのパーマリンク構造を設定できます。?><br />
|
345 |
-
<?php _e("The tags you can use is '%year%','%monthnum%','%day%','%hour%','%minute%','%second%','%postname%','%post_id%' and '%
|
346 |
-
<?php _e("If you don't entered permalink structure, permalink is configured /%year%/%monthnum%/%day%/%post_id%/.","cptp")
|
347 |
-
</p>
|
348 |
-
<table class="form-table">
|
349 |
-
<?php
|
350 |
-
$post_types = get_post_types(array("_builtin"=>false));
|
351 |
-
$page_options = "";
|
352 |
-
foreach ($post_types as $post_type):
|
353 |
-
|
354 |
-
?>
|
355 |
-
<tr valign="top"><th scope="row"><?php echo $post_type;?></th><td>/<?php echo get_post_type_object($post_type)->rewrite["slug"];?> <input type="text" name="<?php echo $post_type."_structure";?>" value="<?php echo get_option($post_type."_structure"); ?>" class="regular-text code" />
|
356 |
-
</td></tr>
|
357 |
-
<?php
|
358 |
-
$page_options .= $post_type."_structure".",";
|
359 |
-
endforeach;?>
|
360 |
-
</table>
|
361 |
-
<input type="hidden" name="action" value="update" />
|
362 |
-
<?php $page_options = rtrim($page_options, ",");?>
|
363 |
-
|
364 |
-
<input type="hidden" name="page_options" value="<?php echo $page_options;?>" />
|
365 |
-
<p class="submit">
|
366 |
-
<input type="submit" class="button-primary" value="<?php _e('Save Changes') ?>" />
|
367 |
</p>
|
368 |
-
|
369 |
-
|
370 |
-
|
371 |
-
|
|
|
|
|
|
|
|
|
372 |
|
373 |
}
|
374 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
375 |
}
|
|
|
|
|
376 |
$custom_post_type_permalinks_admin = new Custom_Post_Type_Permalinks_Admin;
|
377 |
-
$custom_post_type_permalinks_admin->
|
|
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
|
9 |
*/
|
10 |
|
11 |
|
33 |
/* This plugin don't support Multisite yet.*/
|
34 |
|
35 |
|
36 |
+
function get_taxonomy_parents( $id, $taxonomy = 'category', $link = false, $separator = '/', $nicename = false, $visited = array() ) {
|
37 |
+
$chain = '';
|
38 |
+
$parent = &get_term( $id, $taxonomy, OBJECT, 'raw');
|
39 |
+
if ( is_wp_error( $parent ) )
|
40 |
+
return $parent;
|
41 |
+
|
42 |
+
if ( $nicename )
|
43 |
+
$name = $parent->slug;
|
44 |
+
else
|
45 |
+
$name = $parent->name;
|
46 |
+
|
47 |
+
if ( $parent->parent && ( $parent->parent != $parent->term_id ) && !in_array( $parent->parent, $visited ) ) {
|
48 |
+
$visited[] = $parent->parent;
|
49 |
+
$chain .= get_taxonomy_parents( $parent->parent, $taxonomy, $link, $separator, $nicename, $visited );
|
50 |
+
}
|
51 |
+
|
52 |
+
if ( $link )
|
53 |
+
$chain .= '<a href="' . get_term_link( $parent->term_id, $taxonomy ) . '" title="' . esc_attr( sprintf( __( "View all posts in %s" ), $parent->name ) ) . '">'.$name.'</a>' . $separator;
|
54 |
+
else
|
55 |
+
$chain .= $name.$separator;
|
56 |
+
return $chain;
|
57 |
+
}
|
58 |
+
|
59 |
+
|
60 |
+
|
61 |
+
|
62 |
+
|
63 |
|
64 |
class Custom_Post_Type_Permalinks {
|
65 |
|
66 |
+
function add_hooks(){
|
67 |
+
add_action('wp_loaded',array(&$this,'set_archive_rewrite'),99);
|
68 |
+
add_action('wp_loaded', array(&$this,'set_rewrite'),100);
|
69 |
+
add_filter('post_type_link', array(&$this,'set_permalink'),10,3);
|
70 |
|
71 |
add_filter('getarchives_where', array(&$this,'get_archives_where'), 10, 2);
|
72 |
add_filter('get_archives_link', array(&$this,'get_archives_link'));
|
75 |
add_filter('term_link', array(&$this,'set_term_link'),10,3);
|
76 |
|
77 |
|
78 |
+
}
|
79 |
+
|
80 |
+
static function uninstall_hook(){
|
81 |
if ( function_exists('register_uninstall_hook') ) {
|
82 |
register_uninstall_hook(__FILE__, array(&$this,'uninstall_hook_custom_permalink'));
|
83 |
}
|
|
|
84 |
}
|
85 |
|
|
|
86 |
|
87 |
|
88 |
|
89 |
|
90 |
//カスタム投稿タイプのアーカイブのリライトルールの追加
|
91 |
function set_archive_rewrite() {
|
92 |
+
$post_types = get_post_types(array("_builtin"=>false,"publicly_queryable"=>true));
|
93 |
|
94 |
foreach ($post_types as $post_type):
|
95 |
if(!$post_type) continue;
|
103 |
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");
|
104 |
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");
|
105 |
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");
|
106 |
+
|
107 |
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");
|
108 |
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");
|
109 |
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");
|
136 |
|
137 |
|
138 |
|
139 |
+
//rewrite_tagの追加
|
140 |
function set_rewrite() {
|
141 |
global $wp_rewrite;
|
142 |
+
$post_types = get_post_types(array("_builtin"=>false,"publicly_queryable"=>true));
|
143 |
+
|
144 |
foreach ($post_types as $post_type):
|
145 |
|
146 |
$permalink = get_option($post_type."_structure");
|
147 |
$slug = get_post_type_object($post_type)->rewrite["slug"];
|
148 |
+
|
149 |
if(!$permalink){
|
150 |
$permalink = '/%year%/%monthnum%/%day%/%post_id%/';
|
151 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
152 |
|
153 |
+
$permalink = str_replace('%postname%',"%$post_type%",$permalink);
|
154 |
|
155 |
+
$permalink = '/%post_type%/'.$permalink;
|
156 |
+
$permalink = str_replace('//','/',$permalink);
|
157 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
158 |
|
159 |
+
$wp_rewrite->add_rewrite_tag('%post_type%', '([^/]+)','post_type=');
|
160 |
+
$wp_rewrite->add_permastruct($post_type,$permalink, false);
|
161 |
|
162 |
+
if(!$slug or $slug != $post_type){
|
163 |
+
$wp_rewrite->add_rewrite_tag('%$slug%', '([^/]+)',"post_type=$post_type&slug=");
|
164 |
+
$wp_rewrite->add_permastruct($post_type,str_replace("%post_type%","%$slug%",$permalink), false);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
165 |
}
|
166 |
|
167 |
|
168 |
endforeach;
|
169 |
+
|
170 |
+
//カスタム分類の対応
|
171 |
+
$taxonomies = get_taxonomies(array("show_ui" => true),'objects');
|
172 |
+
foreach ( $taxonomies as $taxonomy => $objects ):
|
173 |
+
$wp_rewrite->add_rewrite_tag("%$taxonomy%", '(.+?)',"$taxonomy=");
|
174 |
+
endforeach;
|
175 |
+
|
176 |
+
$wp_rewrite->use_verbose_page_rules = true;
|
177 |
+
}
|
178 |
+
|
179 |
+
function term_id_asc($a, $b){
|
180 |
+
|
181 |
+
if($a->term_id < $b->term_id){
|
182 |
+
return -1;
|
183 |
+
}else if($a->term_id > $b->term_id){
|
184 |
+
return 1;
|
185 |
+
}else{
|
186 |
+
return 0;
|
187 |
+
}
|
188 |
}
|
189 |
|
190 |
|
191 |
+
//パーマリンクの出力の変更
|
192 |
+
function set_permalink($post_link, $post,$leavename) {
|
193 |
global $wp_rewrite;
|
194 |
|
|
|
|
|
|
|
|
|
|
|
195 |
$newlink = $wp_rewrite->get_extra_permastruct($post->post_type);
|
196 |
+
$slug = get_post_type_object($post->post_type)->rewrite["slug"];
|
197 |
+
$newlink = str_replace("%$slug%", $slug, $newlink);
|
198 |
|
199 |
+
$newlink = str_replace("%post_type%", $post->post_type, $newlink);
|
200 |
+
$newlink = str_replace("%post_id%", $post->ID, $newlink);
|
201 |
+
if(!$leavename){
|
202 |
+
$newlink = str_replace("%$post->post_type%", $post->post_name, $newlink);
|
203 |
+
}
|
204 |
|
205 |
+
|
206 |
+
//カスタム分類の対応
|
207 |
+
$taxonomies = get_taxonomies(array("show_ui" => true),'objects');
|
208 |
+
foreach ( $taxonomies as $taxonomy => $objects ) {
|
209 |
+
$term = '';
|
210 |
+
if ( strpos($newlink, "%$taxonomy%") !== false ) {
|
211 |
+
$terms = get_the_terms($post->ID,$taxonomy);
|
212 |
+
if ( $terms ) {
|
213 |
+
usort($terms, '_usort_terms_by_ID'); // order by ID
|
214 |
+
$term = $terms[0]->slug;
|
215 |
+
if ( $parent = $terms[0]->parent )
|
216 |
+
$term = get_taxonomy_parents($parent,$taxonomy, false, '/', true) . $term;
|
217 |
+
}
|
218 |
+
$newlink = str_replace("%$taxonomy%", $term, $newlink);
|
219 |
+
}
|
220 |
+
|
221 |
+
}
|
222 |
+
|
223 |
+
|
224 |
+
|
225 |
|
226 |
$user = get_userdata($post->post_author);
|
227 |
$newlink = str_replace("%author%", $user->user_login, $newlink);
|
236 |
$newlink = str_replace("%hour%",date("H",$post_date), $newlink);
|
237 |
$newlink = str_replace("%minute%",date("i",$post_date), $newlink);
|
238 |
$newlink = str_replace("%second%",date("s",$post_date), $newlink);
|
239 |
+
|
240 |
+
$newlink = str_replace('//',"/",$newlink);
|
241 |
|
242 |
$newlink = home_url(user_trailingslashit($newlink));
|
243 |
return $newlink;
|
327 |
|
328 |
|
329 |
//アンインストール時
|
330 |
+
static function uninstall_hook_custom_permalink () {
|
331 |
+
$post_types = get_post_types(array("_builtin"=>false,"publicly_queryable"=>true));
|
332 |
foreach ($post_types as $post_type):
|
333 |
delete_option($post_type."_structure");
|
334 |
endforeach;
|
338 |
|
339 |
}
|
340 |
|
|
|
|
|
|
|
|
|
|
|
341 |
|
342 |
|
343 |
|
344 |
class Custom_Post_Type_Permalinks_Admin {
|
345 |
|
346 |
+
function add_hooks(){
|
347 |
add_action('init', array(&$this,'load_textdomain'));
|
348 |
+
add_action('admin_init', array(&$this,'settings_api_init'));
|
349 |
|
350 |
}
|
351 |
function load_textdomain(){
|
352 |
load_plugin_textdomain('cptp',false,'custom-post-type-permalinks');
|
353 |
}
|
354 |
+
|
355 |
|
356 |
+
function settings_api_init() {
|
357 |
+
add_settings_section('setting_section',
|
358 |
+
__("Permalink Setting for custom post type","cptp"),
|
359 |
+
array(&$this,'setting_section_callback_function'),
|
360 |
+
'permalink');
|
361 |
+
|
362 |
+
|
363 |
+
|
364 |
+
$post_types = get_post_types(array("_builtin"=>false,"publicly_queryable"=>true));
|
365 |
+
foreach ($post_types as $post_type):
|
366 |
+
if(isset($_POST["submit"])){
|
367 |
+
update_option($post_type."_structure",esc_attr($_POST[$post_type."_structure"]));
|
368 |
+
}
|
369 |
+
|
370 |
+
add_settings_field($post_type."_structure",
|
371 |
+
$post_type,
|
372 |
+
array(&$this,'setting_callback_function'),
|
373 |
+
'permalink',
|
374 |
+
'setting_section',
|
375 |
+
$post_type."_structure");
|
376 |
+
|
377 |
+
register_setting('permalink',$post_type."_structure");
|
378 |
+
endforeach;
|
379 |
+
|
380 |
}
|
381 |
|
382 |
+
|
383 |
+
|
384 |
+
function setting_section_callback_function() {
|
385 |
+
//セクションの上の説明文
|
386 |
+
?>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
387 |
<p><?php _e("Setting permalinks of custom post type.","cptp");//カスタム投稿タイプごとのパーマリンク構造を設定できます。?><br />
|
388 |
+
<?php _e("The tags you can use is '%year%','%monthnum%','%day%','%hour%','%minute%','%second%','%postname%','%post_id%','%author%','%category%','%tag%' and '%{custom_taxonomy_slug}%(Replace the taxomomy term)'.","cptp");?><br />
|
389 |
+
<?php _e("If you don't entered permalink structure, permalink is configured /%year%/%monthnum%/%day%/%post_id%/.","cptp");?>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
390 |
</p>
|
391 |
+
<?php
|
392 |
+
}
|
393 |
+
|
394 |
+
|
395 |
+
function setting_callback_function( $option ) {
|
396 |
+
|
397 |
+
$post_type = str_replace("_structure","" ,$option);
|
398 |
+
echo '/'.$post_type.'<input name="'.$option.'" id="'.$option.'" type="text" class="regular-text code" value="' . get_option($option) .'" />';
|
399 |
|
400 |
}
|
401 |
|
402 |
+
|
403 |
+
|
404 |
+
}
|
405 |
+
|
406 |
+
|
407 |
+
$custom_post_type_permalinks = new Custom_Post_Type_Permalinks;
|
408 |
+
|
409 |
+
if(get_option("permalink_structure") != ""){
|
410 |
+
$custom_post_type_permalinks->add_hooks();
|
411 |
}
|
412 |
+
$custom_post_type_permalinks->uninstall_hook();
|
413 |
+
|
414 |
$custom_post_type_permalinks_admin = new Custom_Post_Type_Permalinks_Admin;
|
415 |
+
$custom_post_type_permalinks_admin->add_hooks();
|
416 |
+
|
readme.txt
CHANGED
@@ -1,9 +1,9 @@
|
|
1 |
=== Custom Post Type Permalinks ===
|
2 |
Contributors: Toro_Unit
|
3 |
Tags: custom post type,permalink
|
4 |
-
Requires at least: 3.
|
5 |
Tested up to: 3.3
|
6 |
-
Stable tag: 0.
|
7 |
|
8 |
Lets you edit the permalink of custom post type.
|
9 |
|
@@ -20,7 +20,7 @@ Custom Post Type Permalinks lets you edit the permalink structure of custom post
|
|
20 |
1. Upload the `custom-post-type-permalinks` directory to your `/wp-content/plugins/` directory.
|
21 |
1. Activate the plugin through the 'Plugins' menu in WordPress.
|
22 |
|
23 |
-
That's it. You can access the permalinks setting by going to *Settings -> Permalinks
|
24 |
|
25 |
|
26 |
== Screenshots ==
|
@@ -28,8 +28,14 @@ That's it. You can access the permalinks setting by going to *Settings -> Permal
|
|
28 |
|
29 |
== Changelog ==
|
30 |
|
|
|
|
|
|
|
|
|
|
|
|
|
31 |
= 0.6.2 =
|
32 |
-
* Fix %author% tag
|
33 |
|
34 |
= 0.6 =
|
35 |
* First release on wordpress.org
|
1 |
=== Custom Post Type Permalinks ===
|
2 |
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
|
7 |
|
8 |
Lets you edit the permalink of custom post type.
|
9 |
|
20 |
1. Upload the `custom-post-type-permalinks` directory to your `/wp-content/plugins/` directory.
|
21 |
1. Activate the plugin through the 'Plugins' menu in WordPress.
|
22 |
|
23 |
+
That's it. You can access the permalinks setting by going to *Settings -> Permalinks*.
|
24 |
|
25 |
|
26 |
== Screenshots ==
|
28 |
|
29 |
== Changelog ==
|
30 |
|
31 |
+
=0.7=
|
32 |
+
* Add %{taxonomy}% tag.
|
33 |
+
* A large number of Bug Fix.
|
34 |
+
* Change Setting Page. Use Setting API.
|
35 |
+
|
36 |
+
|
37 |
= 0.6.2 =
|
38 |
+
* Fix %author% tag.
|
39 |
|
40 |
= 0.6 =
|
41 |
* First release on wordpress.org
|