HM\BackUpWordPress\Path::protect_path PHP Метод

protect_path() публичный Метод

- Adds an index.html file in an attempt to disable directory browsing - Adds a .httaccess file to deny direct access if on Apache
public protect_path ( string $reset = 'no' )
$reset string
    public function protect_path($reset = 'no')
    {
        global $is_apache;
        // Protect against directory browsing by including an index.html file
        $index = $this->path . '/index.html';
        if ('reset' === $reset && file_exists($index)) {
            @unlink($index);
        }
        if (!file_exists($index) && wp_is_writable($this->path)) {
            file_put_contents($index, '');
        }
        $htaccess = $this->path . '/.htaccess';
        if ('reset' === $reset && file_exists($htaccess)) {
            @unlink($htaccess);
        }
        // Protect the directory with a .htaccess file on Apache servers
        if ($is_apache && function_exists('insert_with_markers') && !file_exists($htaccess) && wp_is_writable($this->path)) {
            $contents = array();
            $contents[] = '# ' . sprintf(__('This %s file ensures that other people cannot download your backup files.', 'backupwordpress'), '.htaccess');
            $contents[] = '';
            $contents[] = '<IfModule mod_rewrite.c>';
            $contents[] = 'RewriteEngine On';
            $contents[] = 'RewriteCond %{QUERY_STRING} !key=' . HMBKP_SECURE_KEY;
            $contents[] = 'RewriteRule (.*) - [F]';
            $contents[] = '</IfModule>';
            $contents[] = '';
            file_put_contents($htaccess, '');
            insert_with_markers($htaccess, 'BackUpWordPress', $contents);
        }
    }