diff --git a/wp-includes/classes.php b/wp-includes/classes.php index 347e0fe9b..e7073c11a 100644 --- a/wp-includes/classes.php +++ b/wp-includes/classes.php @@ -723,8 +723,16 @@ class WP_Rewrite { var $permalink_structure; var $category_base; var $category_structure; + var $author_base = 'author'; var $author_structure; var $date_structure; + var $page_structure; + var $search_base = 'search'; + var $search_structure; + var $comments_base = 'comments'; + var $feed_base = 'feed'; + var $comments_feed_structure; + var $feed_structure; var $front; var $root = ''; var $index = 'index.php'; @@ -791,7 +799,7 @@ class WP_Rewrite { } // If the index is not in the permalink, we're using mod_rewrite. - if (preg_match('#^/*index.php#', $this->permalink_structure)) { + if (preg_match('#^/*' . $this->index . '#', $this->permalink_structure)) { return true; } @@ -821,7 +829,7 @@ class WP_Rewrite { $uris = get_settings('page_uris'); $rewrite_rules = array(); - $page_structure = '/%pagename%'; + $page_structure = $this->get_page_permastruct(); if( is_array( $uris ) ) { foreach ($uris as $uri => $pagename) { @@ -925,11 +933,71 @@ class WP_Rewrite { return false; } - $this->author_structure = $this->front . 'author/%author%'; + $this->author_structure = $this->front . $this->author_base . '/%author%'; return $this->author_structure; } + function get_search_permastruct() { + if (isset($this->search_structure)) { + return $this->search_structure; + } + + if (empty($this->permalink_structure)) { + $this->search_structure = ''; + return false; + } + + $this->search_structure = $this->root . $this->search_base . '/%search%'; + + return $this->search_structure; + } + + function get_page_permastruct() { + if (isset($this->page_structure)) { + return $this->page_structure; + } + + if (empty($this->permalink_structure)) { + $this->page_structure = ''; + return false; + } + + $this->page_structure = $this->root . '%pagename%'; + + return $this->page_structure; + } + + function get_feed_permastruct() { + if (isset($this->feed_structure)) { + return $this->feed_structure; + } + + if (empty($this->permalink_structure)) { + $this->feed_structure = ''; + return false; + } + + $this->feed_structure = $this->root . $this->feed_base . '/%feed%'; + + return $this->feed_structure; + } + + function get_comment_feed_permastruct() { + if (isset($this->comment_feed_structure)) { + return $this->comment_feed_structure; + } + + if (empty($this->permalink_structure)) { + $this->comment_feed_structure = ''; + return false; + } + + $this->comment_feed_structure = $this->root . $this->comments_base . '/' . $this->feed_base . '/%feed%'; + + return $this->comment_feed_structure; + } + function add_rewrite_tag($tag, $pattern, $query) { // If the tag already exists, replace the existing pattern and query for // that tag, otherwise add the new tag, pattern, and query to the end of @@ -1068,11 +1136,11 @@ class WP_Rewrite { $root_rewrite = apply_filters('root_rewrite_rules', $root_rewrite); // Comments - $comments_rewrite = $this->generate_rewrite_rules($this->root . 'comments',true, true, true); + $comments_rewrite = $this->generate_rewrite_rules($this->root . $this->comments_base, true, true, true); $comments_rewrite = apply_filters('comments_rewrite_rules', $comments_rewrite); // Search - $search_structure = $this->root . "search/%search%"; + $search_structure = $this->get_search_permastruct(); $search_rewrite = $this->generate_rewrite_rules($search_structure); $search_rewrite = apply_filters('search_rewrite_rules', $search_rewrite); @@ -1134,7 +1202,7 @@ class WP_Rewrite { //nada. } - if (strstr($query, 'index.php')) { + if (strstr($query, $this->index)) { $rules .= 'RewriteRule ^' . $match . ' ' . $home_root . $query . " [QSA,L]\n"; } else { $rules .= 'RewriteRule ^' . $match . ' ' . $site_root . $query . " [QSA,L]\n"; @@ -1158,7 +1226,11 @@ class WP_Rewrite { $this->category_base = get_settings('category_base'); unset($this->category_structure); unset($this->author_structure); - unset($this->date_structure); + unset($this->date_structure); + unset($this->page_structure); + unset($this->search_structure); + unset($this->feed_structure); + unset($this->comment_feed_structure); } function set_permalink_structure($permalink_structure) { diff --git a/wp-includes/template-functions-links.php b/wp-includes/template-functions-links.php index c3a9c4602..5d86745b3 100644 --- a/wp-includes/template-functions-links.php +++ b/wp-includes/template-functions-links.php @@ -74,10 +74,10 @@ function get_permalink($id = false) { $author, $idpost->post_name, ); - return get_settings('home') . str_replace($rewritecode, $rewritereplace, $permalink); + return apply_filters('post_link', get_settings('home') . str_replace($rewritecode, $rewritereplace, $permalink)); } else { // if they're not using the fancy permalink option $permalink = get_settings('home') . '/?p=' . $idpost->ID; - return $permalink; + return apply_filters('post_link', $permalink); } } @@ -88,19 +88,17 @@ function get_page_link($id = false) { $id = $post->ID; } - $permalink = get_settings('permalink_structure'); + $pagestruct = $wp_rewrite->get_page_permastruct(); - if ('' != $permalink) { + if ('' != $pagestruct) { $link = get_page_uri($id); - if ($wp_rewrite->using_index_permalinks()) { - $link = 'index.php/' . $link; - } + $link = str_replace('%pagename%', $link, $pagestruct); $link = get_settings('home') . "/$link/"; } else { - $link = get_settings('home') . "/index.php?page_id=$id"; + $link = get_settings('home') . "/?page_id=$id"; } - return $link; + return apply_filters('page_link', $link); } function get_year_link($year) { @@ -109,9 +107,9 @@ function get_year_link($year) { $yearlink = $wp_rewrite->get_year_permastruct(); if (!empty($yearlink)) { $yearlink = str_replace('%year%', $year, $yearlink); - return get_settings('home') . trailingslashit($yearlink); + return apply_filters('year_link', get_settings('home') . trailingslashit($yearlink)); } else { - return get_settings('home') .'/'. $querystring_start.'m'.$querystring_equal.$year; + return apply_filters('year_link', get_settings('home') .'/'. $querystring_start.'m'.$querystring_equal.$year); } } @@ -123,9 +121,9 @@ function get_month_link($year, $month) { if (!empty($monthlink)) { $monthlink = str_replace('%year%', $year, $monthlink); $monthlink = str_replace('%monthnum%', zeroise(intval($month), 2), $monthlink); - return get_settings('home') . trailingslashit($monthlink); + return apply_filters('month_link', get_settings('home') . trailingslashit($monthlink)); } else { - return get_settings('home') .'/'. $querystring_start.'m'.$querystring_equal.$year.zeroise($month, 2); + return apply_filters('month_link', get_settings('home') .'/'. $querystring_start.'m'.$querystring_equal.$year.zeroise($month, 2)); } } @@ -140,68 +138,39 @@ function get_day_link($year, $month, $day) { $daylink = str_replace('%year%', $year, $daylink); $daylink = str_replace('%monthnum%', zeroise(intval($month), 2), $daylink); $daylink = str_replace('%day%', zeroise(intval($day), 2), $daylink); - return get_settings('home') . trailingslashit($daylink); + return apply_filters('day_link', get_settings('home') . trailingslashit($daylink)); } else { - return get_settings('home') .'/'. $querystring_start.'m'.$querystring_equal.$year.zeroise($month, 2).zeroise($day, 2); + return apply_filters('day_link', get_settings('home') .'/'. $querystring_start.'m'.$querystring_equal.$year.zeroise($month, 2).zeroise($day, 2)); } } function get_feed_link($feed='rss2') { global $wp_rewrite; - $do_perma = 0; - $feed_url = get_settings('siteurl'); - $comment_feed_url = $feed_url; + $do_perma = 0; + $feed_url = get_settings('siteurl'); + $comment_feed_url = $feed_url; - $permalink = get_settings('permalink_structure'); - if ('' != $permalink) { - $do_perma = 1; - $feed_url = get_settings('home'); - $index = 'index.php'; - $prefix = ''; - if ($wp_rewrite->using_index_permalinks()) { - $feed_url .= '/' . $index; - } + $permalink = $wp_rewrite->get_feed_permastruct(); + if ('' != $permalink) { + if ( false !== strpos($feed, 'comments_') ) { + $feed = str_replace('comments_', '', $feed); + $permalink = $wp_rewrite->get_comment_feed_permastruct(); + } - $comment_feed_url = $feed_url; - $feed_url .= '/feed'; - $comment_feed_url .= '/comments/feed'; - } + if ( 'rss2' == $feed ) + $feed = ''; - switch($feed) { - case 'rdf': - $output = $feed_url .'/wp-rdf.php'; - if ($do_perma) { - $output = $feed_url . '/rdf/'; - } - break; - case 'rss': - $output = $feed_url . '/wp-rss.php'; - if ($do_perma) { - $output = $feed_url . '/rss/'; - } - break; - case 'atom': - $output = $feed_url .'/wp-atom.php'; - if ($do_perma) { - $output = $feed_url . '/atom/'; - } - break; - case 'comments_rss2': - $output = $feed_url .'/wp-commentsrss2.php'; - if ($do_perma) { - $output = $comment_feed_url . '/'; - } - break; - case 'rss2': - default: - $output = $feed_url .'/wp-rss2.php'; - if ($do_perma) { - $output = $feed_url . '/'; - } - break; - } + $permalink = str_replace('%feed%', $feed, $permalink); + $output = get_settings('home') . "/$permalink/"; + $output = preg_replace('#/+#', '/', $output); + } else { + if ( false !== strpos($feed, 'comments_') ) + $feed = str_replace('comments_', 'comments', $feed); - return $output; + $output = get_settings('siteurl') . "/wp-{$feed}.php"; + } + + return apply_filters('feed_link', $output); } function edit_post_link($link = 'Edit This', $before = '', $after = '') { diff --git a/wp-settings.php b/wp-settings.php index b528465d8..7b50f1ba0 100644 --- a/wp-settings.php +++ b/wp-settings.php @@ -114,4 +114,6 @@ function shutdown_action_hook() { } register_shutdown_function('shutdown_action_hook'); +// Everything is loaded. +do_action('init', ''); ?> \ No newline at end of file