Created
October 26, 2016 15:07
-
-
Save andyphillips82/9bd0cdab46dd01638181693343e08c72 to your computer and use it in GitHub Desktop.
WP Core Scalability issue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Retrieves the rewrite rules. | |
* | |
* The difference between this method and WP_Rewrite::rewrite_rules() is that | |
* this method stores the rewrite rules in the 'rewrite_rules' option and retrieves | |
* it. This prevents having to process all of the permalinks to get the rewrite rules | |
* in the form of caching. | |
* | |
* @since 1.5.0 | |
* @access public | |
* | |
* @return array Rewrite rules. | |
*/ | |
public function wp_rewrite_rules( $flushed = false ) { | |
$this->rules = get_option('rewrite_rules'); | |
if ( $flushed === true ) { | |
$this->matches = 'matches'; | |
$this->rewrite_rules(); | |
update_option('rewrite_rules', $this->rules); | |
} | |
return $this->rules; | |
} | |
/** | |
* Removes rewrite rules and then recreate rewrite rules. | |
* | |
* Calls WP_Rewrite::wp_rewrite_rules() after removing the 'rewrite_rules' option. | |
* If the function named 'save_mod_rewrite_rules' exists, it will be called. | |
* | |
* @since 2.0.1 | |
* @access public | |
* | |
* @staticvar bool $do_hard_later | |
* | |
* @param bool $hard Whether to update .htaccess (hard flush) or just update rewrite_rules option (soft flush). Default is true (hard). | |
*/ | |
public function flush_rules( $hard = true ) { | |
static $do_hard_later = null; | |
// Prevent this action from running before everyone has registered their rewrites. | |
if ( ! did_action( 'wp_loaded' ) ) { | |
add_action( 'wp_loaded', array( $this, 'flush_rules' ) ); | |
$do_hard_later = ( isset( $do_hard_later ) ) ? $do_hard_later || $hard : $hard; | |
return; | |
} | |
if ( isset( $do_hard_later ) ) { | |
$hard = $do_hard_later; | |
unset( $do_hard_later ); | |
} | |
//update_option( 'rewrite_rules', '' ); | |
$this->wp_rewrite_rules( true ); | |
/** | |
* Filters whether a "hard" rewrite rule flush should be performed when requested. | |
* | |
* A "hard" flush updates .htaccess (Apache) or web.config (IIS). | |
* | |
* @since 3.7.0 | |
* | |
* @param bool $hard Whether to flush rewrite rules "hard". Default true. | |
*/ | |
if ( ! $hard || ! apply_filters( 'flush_rewrite_rules_hard', true ) ) { | |
return; | |
} | |
if ( function_exists( 'save_mod_rewrite_rules' ) ) | |
save_mod_rewrite_rules(); | |
if ( function_exists( 'iis7_save_url_rewrite_rules' ) ) | |
iis7_save_url_rewrite_rules(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment