W3cubDocs

/WordPress

WP_Rewrite::refresh_rewrite_rules()

Refreshes the rewrite rules, saving the fresh value to the database.

Description

If the ‘wp_loaded’ action has not occurred yet, will postpone saving to the database.

Source

private function refresh_rewrite_rules() {
	$this->rules   = '';
	$this->matches = 'matches';

	$this->rewrite_rules();

	if ( ! did_action( 'wp_loaded' ) ) {
		/*
		 * It is not safe to save the results right now, as the rules may be partial.
		 * Need to give all rules the chance to register.
		 */
		add_action( 'wp_loaded', array( $this, 'flush_rules' ) );
	} else {
		update_option( 'rewrite_rules', $this->rules );
	}
}

Changelog

Version Description
6.4.0 Introduced.

© 2003–2024 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/classes/wp_rewrite/refresh_rewrite_rules