Now tag pretty permalinks should work, and support custom tag bases.

git-svn-id: http://svn.automattic.com/wordpress/trunk@5150 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
matt 2007-03-31 09:19:32 +00:00
parent 14f1c622ff
commit c86599b85c
6 changed files with 61 additions and 8 deletions

View File

@ -73,10 +73,18 @@ if ( isset($_POST['permalink_structure']) || isset($_POST['category_base']) ) {
$category_base = preg_replace('#/+#', '/', '/' . $_POST['category_base']);
$wp_rewrite->set_category_base($category_base);
}
if ( isset($_POST['tag_base']) ) {
$tag_base = $_POST['tag_base'];
if (! empty($tag_base) )
$tag_base = preg_replace('#/+#', '/', '/' . $_POST['tag_base']);
$wp_rewrite->set_tag_base($tag_base);
}
}
$permalink_structure = get_option('permalink_structure');
$category_base = get_option('category_base');
$tag_base = get_option( 'tag_base' );
if ( (!file_exists($home_path.'.htaccess') && is_writable($home_path)) || is_writable($home_path.'.htaccess') )
$writable = true;
@ -159,6 +167,9 @@ checked="checked"
<?php endif; ?>
<p>
<?php _e('Category base'); ?>: <input name="category_base" type="text" class="code" value="<?php echo attribute_escape($category_base); ?>" size="30" />
</p>
<p>
<?php _e('Tag base'); ?>: <input name="tag_base" type="text" class="code" value="<?php echo attribute_escape($tag_base); ?>" size="30" />
</p>
<p class="submit">
<input type="submit" name="submit" value="<?php _e('Update Permalink Structure &raquo;') ?>" />

View File

@ -242,6 +242,9 @@ function populate_options() {
add_option('default_link_category', 2);
add_option('show_on_front', 'posts');
// 2.2
add_option('tag_base');
// Delete unused options
$unusedoptions = array ('blodotgsping_url', 'bodyterminator', 'emailtestonly', 'phoneemail_separator', 'smilies_directory', 'subjectprefix', 'use_bbcode', 'use_blodotgsping', 'use_phoneemail', 'use_quicktags', 'use_weblogsping', 'weblogs_cache_file', 'use_preview', 'use_htmltrans', 'smilies_directory', 'fileupload_allowedusers', 'use_phoneemail', 'default_post_status', 'default_post_category', 'archive_mode', 'time_difference', 'links_minadminlevel', 'links_use_adminlevels', 'links_rating_type', 'links_rating_char', 'links_rating_ignore_zero', 'links_rating_single_image', 'links_rating_image0', 'links_rating_image1', 'links_rating_image2', 'links_rating_image3', 'links_rating_image4', 'links_rating_image5', 'links_rating_image6', 'links_rating_image7', 'links_rating_image8', 'links_rating_image9', 'weblogs_cacheminutes', 'comment_allowed_tags', 'search_engine_friendly_urls', 'default_geourl_lat', 'default_geourl_lon', 'use_default_geourl', 'weblogs_xml_url', 'new_users_can_blog', '_wpnonce', '_wp_http_referer', 'Update', 'action', 'rich_editing');
foreach ($unusedoptions as $option) :

View File

@ -42,7 +42,7 @@ function get_category_link($category_id) {
function get_tag_link( $tag_id ) {
global $wp_rewrite;
$catlink = $wp_rewrite->get_category_permastruct();
$catlink = $wp_rewrite->get_tag_permastruct();
$category = &get_category($tag_id);
$category_nicename = $category->category_nicename;

View File

@ -670,7 +670,7 @@ function update_post_category_cache($post_ids) {
}
function update_post_caches(&$posts) {
global $post_cache, $category_cache, $post_meta_cache;
global $post_cache, $category_cache, $post_meta_cache, $tag_cache;
global $wpdb, $blog_id;
// No point in doing all this work if we didn't match any posts.

View File

@ -59,6 +59,7 @@ function get_permalink($id = 0) {
'%postname%',
'%post_id%',
'%category%',
'%tag%',
'%author%',
'%pagename%'
);

View File

@ -46,11 +46,12 @@ define('EP_ROOT', 64 );
define('EP_COMMENTS', 128 );
define('EP_SEARCH', 256 );
define('EP_CATEGORIES', 512 );
define('EP_AUTHORS', 1024);
define('EP_PAGES', 2048);
define('EP_TAGS', 1024 );
define('EP_AUTHORS', 2048);
define('EP_PAGES', 4096);
//pseudo-places
define('EP_NONE', 0 );
define('EP_ALL', 4095);
define('EP_ALL', 8191);
//and an endpoint, like /trackback/
function add_rewrite_endpoint($name, $places) {
@ -150,7 +151,9 @@ class WP_Rewrite {
var $permalink_structure;
var $use_trailing_slashes;
var $category_base;
var $tag_base;
var $category_structure;
var $tag_structure;
var $author_base = 'author';
var $author_structure;
var $date_structure;
@ -181,6 +184,7 @@ class WP_Rewrite {
'%postname%',
'%post_id%',
'%category%',
'%tag%',
'%author%',
'%pagename%',
'%search%'
@ -197,6 +201,7 @@ class WP_Rewrite {
'([^/]+)',
'([0-9]+)',
'(.+?)',
'(.+?)',
'([^/]+)',
'([^/]+)',
'(.+)'
@ -213,6 +218,7 @@ class WP_Rewrite {
'name=',
'p=',
'category_name=',
'tag=',
'author_name=',
'pagename=',
's='
@ -378,6 +384,26 @@ class WP_Rewrite {
return $this->category_structure;
}
function get_tag_permastruct() {
if (isset($this->tag_structure)) {
return $this->tag_structure;
}
if (empty($this->permalink_structure)) {
$this->tag_structure = '';
return false;
}
if (empty($this->tag_base))
$this->tag_structure = $this->front . 'tag/';
else
$this->tag_structure = $this->tag_base . '/';
$this->tag_structure .= '%tag%';
return $this->tag_structure;
}
function get_author_permastruct() {
if (isset($this->author_structure)) {
return $this->author_structure;
@ -734,6 +760,10 @@ class WP_Rewrite {
$category_rewrite = $this->generate_rewrite_rules($this->get_category_permastruct(), EP_CATEGORIES);
$category_rewrite = apply_filters('category_rewrite_rules', $category_rewrite);
// Tags
$tag_rewrite = $this->generate_rewrite_rules($this->get_tag_permastruct(), EP_TAGS);
$tag_rewrite = apply_filters('tag_rewrite_rules', $tag_rewrite);
// Authors
$author_rewrite = $this->generate_rewrite_rules($this->get_author_permastruct(), EP_AUTHORS);
$author_rewrite = apply_filters('author_rewrite_rules', $author_rewrite);
@ -743,7 +773,7 @@ class WP_Rewrite {
$page_rewrite = apply_filters('page_rewrite_rules', $page_rewrite);
// Put them together.
$this->rules = array_merge($robots_rewrite, $default_feeds, $page_rewrite, $root_rewrite, $comments_rewrite, $search_rewrite, $category_rewrite, $author_rewrite, $date_rewrite, $post_rewrite, $this->extra_rules);
$this->rules = array_merge($robots_rewrite, $default_feeds, $page_rewrite, $root_rewrite, $comments_rewrite, $search_rewrite, $category_rewrite, $tag_rewrite, $author_rewrite, $date_rewrite, $post_rewrite, $this->extra_rules);
do_action_ref_array('generate_rewrite_rules', array(&$this));
$this->rules = apply_filters('rewrite_rules_array', $this->rules);
@ -869,7 +899,8 @@ class WP_Rewrite {
if ($this->using_index_permalinks()) {
$this->root = $this->index . '/';
}
$this->category_base = get_option('category_base');
$this->category_base = get_option( 'category_base' );
$this->tag_base = get_option( 'tag_base' );
unset($this->category_structure);
unset($this->author_structure);
unset($this->date_structure);
@ -894,6 +925,13 @@ class WP_Rewrite {
}
}
function set_tag_base( $tag_base ) {
if ( $tag_base != $this->tag_base ) {
update_option( 'tag_base', $tag_base );
$this->init();
}
}
function WP_Rewrite() {
$this->init();
}