PHP code example of webshr / wp-update-server

1. Go to this page and download the library: Download webshr/wp-update-server library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

webshr / wp-update-server example snippets




declare(strict_types=1);

use Webshr\WpUpdateServer\Support\Env;

$storageDir = Env::string('WP_UPDATE_SERVER_STORAGE_DIR', 'storage');

return [
    // Canonical base URL (can be overridden by env `WP_UPDATE_SERVER_BASE_URL`)
    'baseUrl'               => Env::string('WP_UPDATE_SERVER_BASE_URL', 'http://localhost:8000/'),

    // Local paths (relative to project root)
    'storageDir'            => $storageDir,
    'cacheDir'              => Env::string('WP_UPDATE_SERVER_CACHE_DIR', $storageDir . '/cache'),
    'packageDir'            => Env::string('WP_UPDATE_SERVER_PACKAGE_DIR', $storageDir . '/packages'),
    'packageAssetDir'       => Env::string('WP_UPDATE_SERVER_PACKAGE_ASSET_DIR', 'public/package-assets'),
    'logDir'                => Env::string('WP_UPDATE_SERVER_LOG_DIR', $storageDir . '/logs'),

    // Signed download configuration (toggle with env var)
    'signDownloads'         => Env::bool('WP_UPDATE_SERVER_SIGN_DOWNLOADS', false),
    'downloadSecret'        => Env::string('WP_UPDATE_SERVER_SECRET'),

    // Defaults for caches, signatures and rate limiting
    'defaultCacheTtl'       => Env::int('WP_UPDATE_SERVER_CACHE_TTL', 3600),
    'downloadSignatureTtl'  => Env::int('WP_UPDATE_SERVER_DOWNLOAD_SIGNATURE_TTL', 900),
    'downloadLimit'         => Env::int('WP_UPDATE_SERVER_DOWNLOAD_LIMIT', 60),
    'downloadWindowSeconds' => Env::int('WP_UPDATE_SERVER_DOWNLOAD_WINDOW_SECONDS', 3600),

    // Optional reverse proxy support. Forwarded IP headers are ignored unless REMOTE_ADDR matches this list.
    'trustedProxies'        => Env::list('WP_UPDATE_SERVER_TRUSTED_PROXIES'),
    'trustedProxyHeaders'   => Env::list(
        'WP_UPDATE_SERVER_TRUSTED_PROXY_HEADERS',
        ['CF-Connecting-IP', 'X-Forwarded-For', 'X-Real-IP']
    ),

    // Rotate JSON log files by size.
    'logMaxBytes'           => Env::int('WP_UPDATE_SERVER_LOG_MAX_BYTES', 10485760),
];

'packages' => [
    'my-plugin' => [
        'type' => 'plugin',
        'versions' => [
            '1.2.0' => [
                'source' => [
                    'kind' => 'filesystem',
                    'path' => 'packages/my-plugin/1.2.0/my-plugin.zip',
                ],
                'metadata' => [
                    'ta' => [
                    '

'packages' => [
    'my-plugin' => [
        'type' => 'plugin',
        'source' => [
            'kind' => 'filesystem',
            'path' => 'packages/my-plugin',
            'versionPattern' => '/^my-plugin-(?<version>.+)\.zip$/',
        ],
    ],
],

'pro-theme' => [
    'type' => 'theme',
    'source' => [
        'kind' => 'github-release',
        'repo' => 'vendor/pro-theme',
        'asset' => 'pro-theme.zip',
        'versionFrom' => 'tag_name',
        'releaseStrategy' => 'versions',
        'cacheTtl' => 900,
    ],
],

'my-plugin' => [
    'type' => 'plugin',
    'source' => [
        'kind' => 'github-release',
        'repo' => 'vendor/my-plugin',
        'assetPattern' => 'my-plugin-*.zip',
        'versionFrom' => 'name',
        'releaseStrategy' => 'versions',
    ],
],

'private-plugin' => [
    'type' => 'plugin',
    'source' => [
        'kind' => 'github-release',
        'repo' => 'vendor/private-plugin',
        'asset' => 'private-plugin.zip',
        'versionFrom' => 'tag_name',
        'releaseStrategy' => 'versions',
    ],
],

'channels' => [
    'stable' => [
        'versionPattern' => '/^\d+(?:\.\d+){0,2}$/',
        '',
        '

'metadata' => [
    '',
    'xample.com',
    'author' => 'Webshore',
    'sections' => [
        'changelog' => '<p>Fixed update checks.</p>',
    ],
],

'server' => [
    'downloadLimit' => 60,
    'downloadWindowSeconds' => 3600,
],

'server' => [
    'trustedProxies' => ['127.0.0.1', '10.0.0.0/24'],
    'trustedProxyHeaders' => ['CF-Connecting-IP', 'X-Forwarded-For', 'X-Real-IP'],
],



use YahnisElsts\PluginUpdateChecker\v5\PucFactory;

PucFactory::buildUpdateChecker(
    'https://updates.example.com/metadata/my-plugin',
    __FILE__,
    'my-plugin'
);



use YahnisElsts\PluginUpdateChecker\v5\PucFactory;

PucFactory::buildUpdateChecker(
    'https://updates.example.com/metadata/pro-theme',
    get_stylesheet_directory() . '/style.css',
    'pro-theme'
);
bash
php wpus config validate
php wpus package list
text
stubs/.env.example          -> .env
stubs/public/index.php      -> public/index.php
stubs/config/*              -> config/
stubs/storage/*             -> storage/
stubs/update-server.php     -> update-server.php
bash
export WP_UPDATE_SERVER_SIGN_DOWNLOADS=true
export WP_UPDATE_SERVER_SECRET='long-random-secret'
export WP_UPDATE_SERVER_BASE_URL='https://updates.example.com/'