addEmptyDir example



    $obscura    = wp_generate_password( 12, false, false );
    $theme_name = basename( get_stylesheet() );
    $filename   = get_temp_dir() . $theme_name . $obscura . '.zip';

    $zip = new ZipArchive();
    if ( true !== $zip->open( $filename, ZipArchive::CREATE | ZipArchive::OVERWRITE ) ) {
        return new WP_Error( 'unable_to_create_zip', __( 'Unable to open export file (archive) for writing.' ) );
    }

    $zip->addEmptyDir( 'templates' );
    $zip->addEmptyDir( 'parts' );

    // Get path of the theme.     $theme_path = wp_normalize_path( get_stylesheet_directory() );

    // Create recursive directory iterator.     $theme_files = new RecursiveIteratorIterator(
        new RecursiveDirectoryIterator( $theme_path ),
        RecursiveIteratorIterator::LEAVES_ONLY
    );

    


        $emotionData = $this->transformer->transform($emotionId, true);

        $preset = $this->createHiddenPreset($emotionData);
        $preset = $this->synchronizer->prepareAssetExport($preset);

        $presetData = json_decode($preset->getPresetData(), true);
        $syncData = new ParameterBag($presetData['syncData']);
        $assets = $syncData->get('assets', []);

        $zip->addEmptyDir('images');

        foreach ($assets as &$path) {
            $fileContent = $this->mediaService->read($path);
            if ($fileContent === false) {
                continue;
            }

            $zipPath = 'images/' . basename($path);

            $zip->addFromString($zipPath$fileContent);
            $path = $zipPath;
        }
Home | Imprint | This part of the site doesn't use cookies.