HM\BackUpWordPress\Zip_File_Backup_Engine::get_exclude_string PHP Method

get_exclude_string() public method

Convert the exclude rules to a format zip accepts
public get_exclude_string ( ) : string
return string The exclude string ready to pass to `zip -x`
    public function get_exclude_string()
    {
        if (empty($this->excludes)) {
            return '';
        }
        $excludes = $this->excludes->get_excludes();
        foreach ($excludes as $key => &$rule) {
            $file = $absolute = $fragment = false;
            // Files don't end with /
            if (!in_array(substr($rule, -1), array('\\', '/'))) {
                $file = true;
            } elseif (in_array(substr($rule, 0, 1), array('\\', '/'))) {
                $absolute = true;
            } else {
                $fragment = true;
            }
            $rule = str_ireplace(Path::get_root(), '', untrailingslashit(wp_normalize_path($rule)));
            // Strip the preceeding slash
            if (in_array(substr($rule, 0, 1), array('\\', '/'))) {
                $rule = substr($rule, 1);
            }
            // Wrap directory fragments and files in wildcards for zip
            if ($fragment || $file) {
                $rule = '*' . $rule . '*';
            }
            // Add a wildcard to the end of absolute url for zips
            if ($absolute) {
                $rule .= '*';
            }
        }
        // Escape shell args for zip command
        $excludes = array_map('escapeshellarg', array_unique($excludes));
        return implode(' -x ', $excludes);
    }