save_mod_rewrite_rules

The timeline below displays how wordpress function save_mod_rewrite_rules has changed across different WordPress versions. If a version is not listed, refer to the next available version below.

WordPress Version: 6.1

/**
 * Updates the htaccess file with the current rules if it is writable.
 *
 * Always writes to the file if it exists and is writable to ensure that we
 * blank out old rules.
 *
 * @since 1.5.0
 *
 * @global WP_Rewrite $wp_rewrite WordPress rewrite component.
 *
 * @return bool|null True on write success, false on failure. Null in multisite.
 */
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;
}

WordPress Version: 5.3

/**
 * Updates the htaccess file with the current rules if it is writable.
 *
 * Always writes to the file if it exists and is writable to ensure that we
 * blank out old rules.
 *
 * @since 1.5.0
 *
 * @global WP_Rewrite $wp_rewrite WordPress rewrite component.
 *
 * @return bool|null True on write success, false on failure. Null in multisite.
 */
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;
}

WordPress Version: 9.7

/**
 * Updates the htaccess file with the current rules if it is writable.
 *
 * Always writes to the file if it exists and is writable to ensure that we
 * blank out old rules.
 *
 * @since 1.5.0
 *
 * @global WP_Rewrite $wp_rewrite
 *
 * @return bool|null True on write success, false on failure. Null in multisite.
 */
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;
}

WordPress Version: 9.3

/**
 * Updates the htaccess file with the current rules if it is writable.
 *
 * Always writes to the file if it exists and is writable to ensure that we
 * blank out old rules.
 *
 * @since 1.5.0
 *
 * @global WP_Rewrite $wp_rewrite
 */
function save_mod_rewrite_rules()
{
    if (is_multisite()) {
        return;
    }
    global $wp_rewrite;
    $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;
}

WordPress Version: .20

/**
 * Updates the htaccess file with the current rules if it is writable.
 *
 * Always writes to the file if it exists and is writable to ensure that we
 * blank out old rules.
 *
 * @since 1.5.0
 *
 * @global WP_Rewrite $wp_rewrite
 *
 * @return bool|null True on write success, false on failure. Null in multisite.
 */
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;
}

WordPress Version: 9.2

/**
 * Updates the htaccess file with the current rules if it is writable.
 *
 * Always writes to the file if it exists and is writable to ensure that we
 * blank out old rules.
 *
 * @since 1.5.0
 *
 * @global WP_Rewrite $wp_rewrite
 */
function save_mod_rewrite_rules()
{
    if (is_multisite()) {
        return;
    }
    global $wp_rewrite;
    $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;
}

WordPress Version: .10

/**
 * Updates the htaccess file with the current rules if it is writable.
 *
 * Always writes to the file if it exists and is writable to ensure that we
 * blank out old rules.
 *
 * @since 1.5.0
 *
 * @global WP_Rewrite $wp_rewrite
 *
 * @return bool|null True on write success, false on failure. Null in multisite.
 */
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;
}

WordPress Version: 4.3

/**
 * Updates the htaccess file with the current rules if it is writable.
 *
 * Always writes to the file if it exists and is writable to ensure that we
 * blank out old rules.
 *
 * @since 1.5.0
 *
 * @global WP_Rewrite $wp_rewrite
 */
function save_mod_rewrite_rules()
{
    if (is_multisite()) {
        return;
    }
    global $wp_rewrite;
    $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;
}

WordPress Version: 4.0

/**
 * Updates the htaccess file with the current rules if it is writable.
 *
 * Always writes to the file if it exists and is writable to ensure that we
 * blank out old rules.
 *
 * @since 1.5.0
 */
function save_mod_rewrite_rules()
{
    if (is_multisite()) {
        return;
    }
    global $wp_rewrite;
    $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;
}

WordPress Version: 3.7

/**
 * Updates the htaccess file with the current rules if it is writable.
 *
 * Always writes to the file if it exists and is writable to ensure that we
 * blank out old rules.
 *
 * @since 1.5.0
 */
function save_mod_rewrite_rules()
{
    if (is_multisite()) {
        return;
    }
    global $wp_rewrite;
    $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;
}