Version Description
Download this release
Release Info
Developer | Toro_Unit |
Plugin | Custom Post Type Permalinks |
Version | 0.6 |
Comparing to | |
See all releases |
Version 0.6
- cptp-ja.mo +0 -0
- cptp-ja.po +36 -0
- cptp.pot +36 -0
- custom-post-type-permalinks.php +375 -0
cptp-ja.mo
ADDED
Binary file
|
cptp-ja.po
ADDED
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
+
msgid ""
|
7 |
+
msgstr ""
|
8 |
+
"Project-Id-Version: Custom Post Type Permalinks 1.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-03 15:01+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 |
+
#: custom-post-type-permalinks.php:254
|
22 |
+
msgid "Permalinks of Custom post type"
|
23 |
+
msgstr "カスタム投稿タイプのパーマリンク"
|
24 |
+
|
25 |
+
#: custom-post-type-permalinks.php:270
|
26 |
+
msgid "Setting permalinks of custom post type."
|
27 |
+
msgstr "カスタム投稿タイプごとのパーマリンク構造を設定できます。"
|
28 |
+
|
29 |
+
#: custom-post-type-permalinks.php:271
|
30 |
+
msgid "The tags you can use is '%year%','%monthnum%','%day%','%hour%','%minute%','%second%','%postname%','%post_id%' and '%author%'."
|
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 |
+
|
cptp.pot
ADDED
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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
ADDED
@@ -0,0 +1,375 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/*
|
3 |
+
Plugin Name: Custom Post Type Permalinks
|
4 |
+
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
|
8 |
+
Version: 0.6
|
9 |
+
*/
|
10 |
+
|
11 |
+
|
12 |
+
|
13 |
+
/* Copyright 2011 Toro_Unit (email : mail@torounit.com)
|
14 |
+
|
15 |
+
This program is free software; you can redistribute it and/or modify
|
16 |
+
it under the terms of the GNU General Public License as published by
|
17 |
+
the Free Software Foundation; either version 2 of the License, or
|
18 |
+
(at your option) any later version.
|
19 |
+
|
20 |
+
This program is distributed in the hope that it will be useful,
|
21 |
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
22 |
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
23 |
+
GNU General Public License for more details.
|
24 |
+
|
25 |
+
You should have received a copy of the GNU General Public License
|
26 |
+
along with this program; if not, write to the Free Software
|
27 |
+
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
28 |
+
*/
|
29 |
+
|
30 |
+
|
31 |
+
|
32 |
+
|
33 |
+
/* This plugin don't support Multisite yet.*/
|
34 |
+
|
35 |
+
|
36 |
+
|
37 |
+
class Custom_Post_Type_Permalinks {
|
38 |
+
|
39 |
+
function init_function(){
|
40 |
+
add_action('init',array(&$this,'set_archive_rewrite'),99);
|
41 |
+
add_action('init', array(&$this,'set_rewrite'),100);
|
42 |
+
add_filter('post_type_link', array(&$this,'set_permalink'),10,2);
|
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('generate_rewrite_rules', array(&$this,'add_tax_rewrite'));
|
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;
|
68 |
+
$permalink = get_option($post_type."_structure");
|
69 |
+
$slug = get_post_type_object($post_type)->rewrite["slug"];
|
70 |
+
|
71 |
+
if($slug){
|
72 |
+
|
73 |
+
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");
|
74 |
+
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");
|
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");
|
81 |
+
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");
|
82 |
+
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");
|
83 |
+
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");
|
84 |
+
add_rewrite_rule($slug.'/date/([0-9]{4})/?$','index.php?year=$matches[1]&post_type='.$post_type,"top");
|
85 |
+
add_rewrite_rule($slug.'/([0-9]{1,})/?$','index.php?p=$matches[1]&post_type='.$post_type,"top");
|
86 |
+
add_rewrite_rule($slug.'/?$','index.php?post_type='.$post_type,"top");
|
87 |
+
}
|
88 |
+
|
89 |
+
|
90 |
+
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");
|
91 |
+
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");
|
92 |
+
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");
|
93 |
+
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");
|
94 |
+
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");
|
95 |
+
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");
|
96 |
+
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");
|
97 |
+
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");
|
98 |
+
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");
|
99 |
+
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");
|
100 |
+
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");
|
101 |
+
add_rewrite_rule($post_type.'/date/([0-9]{4})/?$','index.php?year=$matches[1]&post_type='.$post_type,"top");
|
102 |
+
add_rewrite_rule($post_type.'/([0-9]{1,})/?$','index.php?p=$matches[1]&post_type='.$post_type,"top");
|
103 |
+
add_rewrite_rule($post_type.'/?$','index.php?post_type='.$post_type,"top");
|
104 |
+
endforeach;
|
105 |
+
}
|
106 |
+
|
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 |
+
$permalink_paged = str_replace('%'.$post_type.'_id%',"([0-9]{1,})", $permalink_paged);
|
147 |
+
$permalink_paged = str_replace('%'.$post_type.'name%',"([^/]+)", $permalink_paged);
|
148 |
+
|
149 |
+
|
150 |
+
$permalink_paged = $permalink_paged."/([0-9]{1,})/?$";
|
151 |
+
$permalink_paged = str_replace("//","/", $permalink_paged);
|
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 |
+
//個別投稿の出力URLの変更
|
178 |
+
function set_permalink($post_link, $id = 0) {
|
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("%".$post->post_type."%", $post->post_type, $newlink);
|
189 |
+
$newlink = str_replace("%".$post->post_type."_id%", $post->ID, $newlink);
|
190 |
+
$newlink = str_replace("%".$post->post_type."name%", $post->post_name, $newlink);
|
191 |
+
|
192 |
+
$newlink = str_replace("%author%", $post->post_author, $newlink);
|
193 |
+
|
194 |
+
|
195 |
+
|
196 |
+
$post_date = strtotime($post->post_date);
|
197 |
+
|
198 |
+
$newlink = str_replace("%year%",date("Y",$post_date), $newlink);
|
199 |
+
$newlink = str_replace("%monthnum%",date("m",$post_date), $newlink);
|
200 |
+
$newlink = str_replace("%day%",date("d",$post_date), $newlink);
|
201 |
+
$newlink = str_replace("%hour%",date("H",$post_date), $newlink);
|
202 |
+
$newlink = str_replace("%minute%",date("i",$post_date), $newlink);
|
203 |
+
$newlink = str_replace("%second%",date("s",$post_date), $newlink);
|
204 |
+
|
205 |
+
|
206 |
+
$newlink = home_url(user_trailingslashit($newlink));
|
207 |
+
return $newlink;
|
208 |
+
}
|
209 |
+
|
210 |
+
|
211 |
+
|
212 |
+
/**
|
213 |
+
*
|
214 |
+
*wp_get_archives fix for custom post
|
215 |
+
*
|
216 |
+
*How To Use:
|
217 |
+
*
|
218 |
+
* $arg = 'type=monthly';
|
219 |
+
* if(is_post_type_archive()) {
|
220 |
+
* $arg .= '&post_type='.get_query_var( 'post_type' );
|
221 |
+
* }
|
222 |
+
* wp_get_archives($arg);
|
223 |
+
*
|
224 |
+
*
|
225 |
+
*
|
226 |
+
*/
|
227 |
+
|
228 |
+
public $post_type_archives;
|
229 |
+
|
230 |
+
function get_archives_where($where, $r) {
|
231 |
+
if ( isset($r['post_type']) ) {
|
232 |
+
$this->post_type_archives = $r['post_type'];
|
233 |
+
$where = str_replace( '\'post\'', '\'' . $r['post_type'] . '\'', $where );
|
234 |
+
}else {
|
235 |
+
$this->post_type_archives = '';
|
236 |
+
}
|
237 |
+
return $where;
|
238 |
+
}
|
239 |
+
|
240 |
+
function get_archives_link($link_html) {
|
241 |
+
if ( '' != $this->post_type_archives )
|
242 |
+
$blog_url = get_bloginfo("url");
|
243 |
+
$link_html = str_replace($blog_url,$blog_url.$this->post_type_archives,$link_html);
|
244 |
+
return $link_html;
|
245 |
+
}
|
246 |
+
|
247 |
+
|
248 |
+
|
249 |
+
/**
|
250 |
+
*
|
251 |
+
*fix permalink custom taxonomy
|
252 |
+
*
|
253 |
+
*Ex:
|
254 |
+
* example.org/posttype/taxonomy/term/
|
255 |
+
*
|
256 |
+
*/
|
257 |
+
|
258 |
+
function add_tax_rewrite(){
|
259 |
+
global $wp_rewrite;
|
260 |
+
$taxonomies = get_taxonomies(array("_builtin"=>false));
|
261 |
+
if(empty($taxonomies)){
|
262 |
+
return ;
|
263 |
+
}
|
264 |
+
|
265 |
+
foreach ($taxonomies as $taxonomy) :
|
266 |
+
|
267 |
+
$post_types = get_taxonomy($taxonomy)->object_type;
|
268 |
+
foreach ($post_types as $post_type){
|
269 |
+
$slug = get_post_type_object($post_type)->rewrite["slug"];
|
270 |
+
//add taxonomy slug
|
271 |
+
|
272 |
+
add_rewrite_rule($slug.'/'.$taxonomy.'/(.+?)/?$','index.php?taxonomy='.$taxonomy.'&term=$matches[1]');
|
273 |
+
add_rewrite_rule($post_type.'/'.$taxonomy.'/(.+?)/?$','index.php?taxonomy='.$taxonomy.'&term=$matches[1]');
|
274 |
+
}
|
275 |
+
endforeach;
|
276 |
+
}
|
277 |
+
|
278 |
+
function set_term_link($termlink,$term,$taxonomy){
|
279 |
+
$taxonomy = get_taxonomy($taxonomy);
|
280 |
+
if(empty($taxonomy)){
|
281 |
+
return $termlink;
|
282 |
+
}
|
283 |
+
$wp_home = get_option("home");
|
284 |
+
$wp_home = $wp_home."/";
|
285 |
+
$wp_home = str_replace("//","/",$wp_home);
|
286 |
+
$post_type = $taxonomy->object_type[0];
|
287 |
+
$slug = get_post_type_object($post_type)->rewrite["slug"];
|
288 |
+
return str_replace($wp_home,$wp_home.$slug,$termlink);
|
289 |
+
}
|
290 |
+
|
291 |
+
|
292 |
+
|
293 |
+
//アンインストール時
|
294 |
+
function uninstall_hook_custom_permalink () {
|
295 |
+
$post_types = get_post_types(array("_builtin"=>false));
|
296 |
+
foreach ($post_types as $post_type):
|
297 |
+
delete_option($post_type."_structure");
|
298 |
+
endforeach;
|
299 |
+
}
|
300 |
+
|
301 |
+
|
302 |
+
|
303 |
+
}
|
304 |
+
|
305 |
+
if(get_option("permalink_structure") != ""){
|
306 |
+
$custom_post_type_permalinks = new Custom_Post_Type_Permalinks;
|
307 |
+
$custom_post_type_permalinks->init_function();
|
308 |
+
}
|
309 |
+
|
310 |
+
|
311 |
+
|
312 |
+
|
313 |
+
class Custom_Post_Type_Permalinks_Admin {
|
314 |
+
|
315 |
+
function init_function(){
|
316 |
+
add_action('init', array(&$this,'load_textdomain'));
|
317 |
+
add_action('admin_menu', array(&$this,'admin_menu_custom_permalink'));
|
318 |
+
|
319 |
+
}
|
320 |
+
function load_textdomain(){
|
321 |
+
load_plugin_textdomain('cptp',false,'custom-post-type-permalinks');
|
322 |
+
}
|
323 |
+
|
324 |
+
function admin_menu_custom_permalink () {
|
325 |
+
// 設定メニュー下にサブメニューを追加:
|
326 |
+
$menuName = __("Permalinks of Custom post type","cptp");
|
327 |
+
add_options_page($menuName, $menuName, 'manage_options', __FILE__, array(&$this,'admin_menu_custom_permalink_callback'));
|
328 |
+
}
|
329 |
+
|
330 |
+
// プラグインページのコンテンツを表示
|
331 |
+
function admin_menu_custom_permalink_callback () {
|
332 |
+
global $wp_rewrite;
|
333 |
+
$wp_rewrite->flush_rules();
|
334 |
+
|
335 |
+
// 設定変更画面を表示する
|
336 |
+
?>
|
337 |
+
<div class="wrap">
|
338 |
+
<div class="icon32" id="icon-options-general"></div>
|
339 |
+
<h2><?php echo __("Permalinks of Custom post type","cptp"); //カスタム投稿タイプのパーマリンク?></h2>
|
340 |
+
<form method="post" action="options.php">
|
341 |
+
<?php wp_nonce_field('update-options'); ?>
|
342 |
+
<p><?php _e("Setting permalinks of custom post type.","cptp");//カスタム投稿タイプごとのパーマリンク構造を設定できます。?><br />
|
343 |
+
<?php _e("The tags you can use is '%year%','%monthnum%','%day%','%hour%','%minute%','%second%','%postname%','%post_id%' and '%author%'.","cptp");//使用できるタグは、%year%,%monthnum%,%day%,%hour%,%minute%,%second%,%postname%,%post_id%,%author%です。?><br />
|
344 |
+
<?php _e("If you don't entered permalink structure, permalink is configured /%year%/%monthnum%/%day%/%post_id%/.","cptp");//未入力のときは、/%year%/%monthnum%/%day%/%post_id%/に設定されます。?>
|
345 |
+
</p>
|
346 |
+
<table class="form-table">
|
347 |
+
<?php
|
348 |
+
$post_types = get_post_types(array("_builtin"=>false));
|
349 |
+
$page_options = "";
|
350 |
+
foreach ($post_types as $post_type):
|
351 |
+
|
352 |
+
?>
|
353 |
+
<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" />
|
354 |
+
</td></tr>
|
355 |
+
<?php
|
356 |
+
$page_options .= $post_type."_structure".",";
|
357 |
+
endforeach;?>
|
358 |
+
</table>
|
359 |
+
<input type="hidden" name="action" value="update" />
|
360 |
+
<?php $page_options = rtrim($page_options, ",");?>
|
361 |
+
|
362 |
+
<input type="hidden" name="page_options" value="<?php echo $page_options;?>" />
|
363 |
+
<p class="submit">
|
364 |
+
<input type="submit" class="button-primary" value="<?php _e('Save Changes') ?>" />
|
365 |
+
</p>
|
366 |
+
</form>
|
367 |
+
</div>
|
368 |
+
|
369 |
+
<?php
|
370 |
+
|
371 |
+
}
|
372 |
+
|
373 |
+
}
|
374 |
+
$custom_post_type_permalinks_admin = new Custom_Post_Type_Permalinks_Admin;
|
375 |
+
$custom_post_type_permalinks_admin->init_function();
|