Cache rewrite rules. Add WP_Rewrite::flush_rules(). fixes #2155

git-svn-id: http://svn.automattic.com/wordpress/trunk@3373 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
ryan 2005-12-28 07:05:05 +00:00
parent 81f0c504cd
commit 305a286ce1
6 changed files with 26 additions and 17 deletions

View File

@ -171,7 +171,7 @@ $wpdb->query("INSERT INTO $wpdb->comments (comment_post_ID, comment_author, comm
// First Page // First Page
$wpdb->query("INSERT INTO $wpdb->posts (post_author, post_date, post_date_gmt, post_content, post_excerpt, post_title, post_category, post_name, post_modified, post_modified_gmt, post_status, to_ping, pinged, post_content_filtered) VALUES ('1', '$now', '$now_gmt', '".$wpdb->escape(__('This is an example of a WordPress page, you could edit this to put information about yourself or your site so readers know where you are coming from. You can create as many pages like this one or sub-pages as you like and manage all of your content inside of WordPress.'))."', '', '".$wpdb->escape(__('About'))."', '0', '".$wpdb->escape(__('about'))."', '$now', '$now_gmt', 'static', '', '', '')"); $wpdb->query("INSERT INTO $wpdb->posts (post_author, post_date, post_date_gmt, post_content, post_excerpt, post_title, post_category, post_name, post_modified, post_modified_gmt, post_status, to_ping, pinged, post_content_filtered) VALUES ('1', '$now', '$now_gmt', '".$wpdb->escape(__('This is an example of a WordPress page, you could edit this to put information about yourself or your site so readers know where you are coming from. You can create as many pages like this one or sub-pages as you like and manage all of your content inside of WordPress.'))."', '', '".$wpdb->escape(__('About'))."', '0', '".$wpdb->escape(__('about'))."', '$now', '$now_gmt', 'static', '', '', '')");
generate_page_rewrite_rules(); $wp_rewrite->flush_rules();
// Set up admin user // Set up admin user
$random_password = substr(md5(uniqid(microtime())), 0, 6); $random_password = substr(md5(uniqid(microtime())), 0, 6);

View File

@ -76,8 +76,6 @@ if ( isset($_POST) ) {
$permalink_structure = get_settings('permalink_structure'); $permalink_structure = get_settings('permalink_structure');
$category_base = get_settings('category_base'); $category_base = get_settings('category_base');
generate_page_rewrite_rules();
if ( (!file_exists($home_path.'.htaccess') && is_writable($home_path)) || is_writable($home_path.'.htaccess') ) if ( (!file_exists($home_path.'.htaccess') && is_writable($home_path)) || is_writable($home_path.'.htaccess') )
$writable = true; $writable = true;
else else
@ -88,7 +86,7 @@ if ($wp_rewrite->using_index_permalinks())
else else
$usingpi = false; $usingpi = false;
save_mod_rewrite_rules(); $wp_rewrite->flush_rules();
?> ?>
<?php if (isset($_POST['submit'])) : ?> <?php if (isset($_POST['submit'])) : ?>

View File

@ -66,7 +66,7 @@ case 'update':
// If siteurl or home changed, reset cookies. // If siteurl or home changed, reset cookies.
if ( get_settings('siteurl') != $old_siteurl || get_settings('home') != $old_home ) { if ( get_settings('siteurl') != $old_siteurl || get_settings('home') != $old_home ) {
// If home changed, write rewrite rules to new location. // If home changed, write rewrite rules to new location.
save_mod_rewrite_rules(); $wp_rewrite->flush_rules();
// Get currently logged in user and password. // Get currently logged in user and password.
get_currentuserinfo(); get_currentuserinfo();
// Clear cookies for old paths. // Clear cookies for old paths.

View File

@ -4,7 +4,7 @@ require_once(ABSPATH . '/wp-admin/admin-functions.php');
require_once(ABSPATH . '/wp-admin/upgrade-schema.php'); require_once(ABSPATH . '/wp-admin/upgrade-schema.php');
// Functions to be called in install and upgrade scripts // Functions to be called in install and upgrade scripts
function upgrade_all() { function upgrade_all() {
global $wp_current_db_version, $wp_db_version; global $wp_current_db_version, $wp_db_version, $wp_rewrite;
$wp_current_db_version = __get_option('db_version'); $wp_current_db_version = __get_option('db_version');
// We are up-to-date. Nothing to do. // We are up-to-date. Nothing to do.
@ -33,8 +33,7 @@ function upgrade_all() {
if ( $wp_current_db_version < 3308 ) if ( $wp_current_db_version < 3308 )
upgrade_160(); upgrade_160();
generate_page_rewrite_rules(); $wp_rewrite->flush_rules();
save_mod_rewrite_rules();
update_option('db_version', $wp_db_version); update_option('db_version', $wp_db_version);
} }

View File

@ -1339,8 +1339,14 @@ class WP_Rewrite {
} }
function wp_rewrite_rules() { function wp_rewrite_rules() {
$this->matches = 'matches'; $this->rules = get_option('rewrite_rules');
return $this->rewrite_rules(); if ( empty($this->rules) ) {
$this->matches = 'matches';
$this->rewrite_rules();
update_option('rewrite_rules', $this->rules);
}
return $this->rules;
} }
function mod_rewrite_rules() { function mod_rewrite_rules() {
@ -1396,6 +1402,14 @@ class WP_Rewrite {
return $rules; return $rules;
} }
function flush_rules() {
generate_page_rewrite_rules();
delete_option('rewrite_rules');
$this->wp_rewrite_rules();
if ( function_exists('save_mod_rewrite_rules') )
save_mod_rewrite_rules();
}
function init() { function init() {
$this->permalink_structure = get_settings('permalink_structure'); $this->permalink_structure = get_settings('permalink_structure');
$this->front = substr($this->permalink_structure, 0, strpos($this->permalink_structure, '%')); $this->front = substr($this->permalink_structure, 0, strpos($this->permalink_structure, '%'));

View File

@ -6,7 +6,7 @@
* generic function for inserting data into the posts table. * generic function for inserting data into the posts table.
*/ */
function wp_insert_post($postarr = array()) { function wp_insert_post($postarr = array()) {
global $wpdb, $allowedtags, $user_ID; global $wpdb, $wp_rewrite, $allowedtags, $user_ID;
if ( is_object($postarr) ) if ( is_object($postarr) )
$postarr = get_object_vars($postarr); $postarr = get_object_vars($postarr);
@ -196,7 +196,7 @@ function wp_insert_post($postarr = array()) {
spawn_pinger(); spawn_pinger();
} }
} else if ($post_status == 'static') { } else if ($post_status == 'static') {
generate_page_rewrite_rules(); $wp_rewrite->flush_rules();
if ( !empty($page_template) ) if ( !empty($page_template) )
if ( ! update_post_meta($post_ID, '_wp_page_template', $page_template)) if ( ! update_post_meta($post_ID, '_wp_page_template', $page_template))
@ -526,7 +526,7 @@ function wp_set_post_cats($blogid = '1', $post_ID = 0, $post_categories = array(
} // wp_set_post_cats() } // wp_set_post_cats()
function wp_delete_post($postid = 0) { function wp_delete_post($postid = 0) {
global $wpdb; global $wpdb, $wp_rewrite;
$postid = (int) $postid; $postid = (int) $postid;
if ( !$post = $wpdb->get_row("SELECT * FROM $wpdb->posts WHERE ID = $postid") ) if ( !$post = $wpdb->get_row("SELECT * FROM $wpdb->posts WHERE ID = $postid") )
@ -559,8 +559,8 @@ function wp_delete_post($postid = 0) {
$wpdb->query("DELETE FROM $wpdb->postmeta WHERE post_id = $postid"); $wpdb->query("DELETE FROM $wpdb->postmeta WHERE post_id = $postid");
if ( 'static' == $post->post_status ) if ( 'static' == $post->post_status )
generate_page_rewrite_rules(); $wp_rewrite->flush_rules();
return $post; return $post;
} }
@ -818,8 +818,6 @@ function generate_page_rewrite_rules() {
if ( $page_attachment_rewrite_rules ) if ( $page_attachment_rewrite_rules )
update_option('page_attachment_uris', $page_attachment_rewrite_rules); update_option('page_attachment_uris', $page_attachment_rewrite_rules);
save_mod_rewrite_rules();
} }
} }