save_mod_rewrite_rules

函数


save_mod_rewrite_rules ( No parameters )
返回值
  • (bool|null) True on write success, false on failure. Null in multisite.
定义位置
  • wp-admin/includes/misc.php
    , line 261
引入
1.5.0
弃用

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

如果该文件存在并可写入,则始终写入该文件,以确保我们清空旧规则。

function save_mod_rewrite_rules() {
	global $wp_rewrite;

	if ( is_multisite() ) {
		return;
	}

	// 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;
}