addFromString example

$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;
        }
        unset($path);

        $syncData->set('assets', $assets);
        $presetData['syncData'] = $syncData->all();

        $exportData = [
            'requiredPlugins' => json_decode($preset->getRequiredPlugins(), true),
            'emotionTranslations' => $preset->getEmotionTranslations(),
            'presetData' => json_encode($presetData),
        ];
<?php
$file = __DIR__.'/ProjectWithXsdExtensionInPhar.phar';
if (is_file($file)) {
    @unlink($file);
}

$phar = new Phar($file, 0, 'ProjectWithXsdExtensionInPhar.phar');
$phar->addFromString('ProjectWithXsdExtensionInPhar.php', <<<'EOT' <?php class ProjectWithXsdExtensionInPhar extends ProjectExtension { public function getXsdValidationBasePath(): string { return __DIR__.'/schema'; } public function getNamespace(): string { return 'http://www.example.com/schema/projectwithxsdinphar'; } public function getAlias(): string { return 'projectwithxsdinphar'; } }
if ( ! wp_is_theme_directory_ignored( $relative_path ) ) {
                $zip->addFile( $file_path$relative_path );
            }
        }
    }

    // Load templates into the zip file.     $templates = get_block_templates();
    foreach ( $templates as $template ) {
        $template->content = _remove_theme_attribute_in_block_template_content( $template->content );

        $zip->addFromString(
            'templates/' . $template->slug . '.html',
            $template->content
        );
    }

    // Load template parts into the zip file.     $template_parts = get_block_templates( array(), 'wp_template_part' );
    foreach ( $template_parts as $template_part ) {
        $zip->addFromString(
            'parts/' . $template_part->slug . '.html',
            $template_part->content
        );
Home | Imprint | This part of the site doesn't use cookies.