如果htaccess文件可写,则使用当前规则更新htaccess文件。

原型

save_mod_rewrite_rules()

描述

如果文件存在并且可写,则始终写入文件以确保我们删除旧规则。

返回值

(bool|null)  写入成功时为真,失败时为假。在多站点中为空。

源文件

路径:wp-admin/includes/misc.php

<?php
...
function save_mod_rewrite_rules() {
	if ( is_multisite() )
		return;
	global $wp_rewrite;
	// Ensure get_home_path() is declared.
	require_once( ABSPATH . 'wp-admin/includes/file.php' );
	$home_path     = get_home_path();
	$htaccess_file = $home_path . '.htaccess';
	/*
	 * If the file doesn't already exist check for write access to the directory
	 * and whether we have some rules. Else check for write access to the file.
	 */
	if ((!file_exists($htaccess_file) && is_writable($home_path) && $wp_rewrite->using_mod_rewrite_permalinks()) || is_writable($htaccess_file)) {
		if ( got_mod_rewrite() ) {
			$rules = explode( "n", $wp_rewrite->mod_rewrite_rules() );
			return insert_with_markers( $htaccess_file, 'WordPress', $rules );
		}
	}
	return false;
}
...
?>

其他

英文文档:https://developer.wordpress.org/reference/functions/save_mod_rewrite_rules/