save_mod_rewrite_rules

函式
save_mod_rewrite_rules ( No parameters )
返回值
  • (bool|null) True on write success, false on failure. Null in multisite.
定義位置
相關方法
add_rewrite_ruleiis7_save_url_rewrite_rulesiis7_add_rewrite_ruleflush_rewrite_rulesiis7_delete_rewrite_rule
引入
1.5.0
棄用
-

save_mod_rewrite_rules函式用來儲存mod_rewrite規則到你的WordPress安裝根目錄下的.htaccess檔案。mod_rewrite規則是用來使WordPress為你的文章和頁面建立搜尋引擎友好的URL的。

如果htaccess檔案是可寫的,則用當前規則更新該檔案。

如果該檔案存在並可寫入,則始終寫入該檔案,以確保我們清空舊規則。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
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;
}
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; }
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;
}

常見問題

FAQs
檢視更多 >