hhdev / codeberg-wp-plugin-updater
Updater class for WordPress plugins from Codeberg
Package info
codeberg.org/hhdev/hhdev-plugin-updater.git
pkg:composer/hhdev/codeberg-wp-plugin-updater
Requires
None
Requires (Dev)
- phpunit/phpunit: ^11.5
Suggests
None
Provides
None
Conflicts
None
Replaces
None
This package is not auto-updated.
Last update: 2026-11-27 15:05:17 UTC
README
A WordPress plugin updater class that enables automatic updates from private Codeberg (Forgejo) repositories.
Description
This PHP class provides a seamless way to enable automatic updates for your WordPress plugins hosted on Codeberg (or any Forgejo-compatible platform). It integrates with WordPress's native update system, allowing your plugin to receive updates directly from your Codeberg repository.
Key Features
- Automatic Updates: Support for automatic updates of the plugin when new releases are published
- Private Repository Support: Works with both public and private Codeberg repositories
- Version Management: Uses Git tags for version control
- Release Assets: Supports both release assets and source code archives
- Secure Authentication: Supports token-based authentication for private repositories
- WordPress Native Integration: Uses WordPress's built-in update system
- Changelog Display: Shows release notes in the WordPress plugin details modal
- Auto-activation: Automatically reactivates the plugin after update
Installation
The updater can be included in your WordPress plugin in two ways:
- Composer (recommended): install the package and load Composer's autoloader.
- Manual: include the updater PHP file directly without Composer.
Option 1: Install with Composer (recommended)
From your plugin project directory, run:
composer require hhdev/codeberg-wp-plugin-updater
This installs the package and updates your composer.json and composer.lock.
In your main plugin file, load Composer's autoloader and initialize the updater:
// Load Composer autoloader.
require_once plugin_dir_path(__FILE__) . 'vendor/autoload.php';
// Initialize Codeberg Plugin Updater.
// Change v120 to the namespace version included in the package you installed.
$updater = new \hhdev\CodebergPluginUpdater\v120\PluginUpdater(
__FILE__,
'your-plugin-slug',
'https://codeberg.org/api/v1/repos/username/plugin/releases',
'your_token',
'Your Plugin Name'
);
The namespace is versioned so that plugins bundling different updater versions can load them side by side. Use the namespace version that is actually provided by the installed release.
When preparing your plugin for distribution, include the Composer vendor/ directory. WordPress does not run composer install automatically for plugin users.
Option 2: Manual installation (without Composer)
If you do not want to use Composer, copy the updater PHP file into your plugin, for example:
your-plugin/
├── your-plugin.php
└── includes/
└── PluginUpdater.php
Then include the file directly in your main plugin file:
// Load the updater class.
require_once plugin_dir_path(__FILE__) . 'includes/PluginUpdater.php';
// Initialize Codeberg Plugin Updater.
$updater = new \hhdev\CodebergPluginUpdater\v120\PluginUpdater(
__FILE__,
'your-plugin-slug',
'https://codeberg.org/api/v1/repos/username/plugin/releases',
'your_token',
'Your Plugin Name'
);
Make sure the copied file contains the namespace matching the class name used above. Update the namespace when you replace the file with a release that uses a different namespace version.
Optional: Enable automatic updates
WordPress lets administrators enable automatic updates per plugin. To force automatic updates for this plugin, you can add:
add_filter('auto_update_plugin', function ($update, $item) {
if (isset($item->slug) && $item->slug === 'your-plugin-slug') {
return true;
}
return $update;
}, 10, 2);
This explicitly enables automatic updates for the matching plugin, regardless of the administrator's per-plugin auto-update setting. Omit this filter if you want administrators to control that setting themselves.
Create a Release on Codeberg
For the updater to work, you need to:
- Create a release on Codeberg.
- Tag it with a version number (e.g.,
v1.0.0,v1.2.3). - Either:
- Attach a ZIP file of your plugin as a release asset, OR
- Let the updater use the source code archive.
Usage
The examples below use the Composer/manual class namespace shown above. If your installed updater release uses a different namespace version, change v120 accordingly.
Basic Usage with Public Repository
$updater = new \hhdev\CodebergPluginUpdater\v120\PluginUpdater(
__FILE__,
'your-plugin-slug',
'https://codeberg.org/api/v1/repos/my-username/my-awesome-plugin/releases'
);
Usage with Private Repository
$updater = new \hhdev\CodebergPluginUpdater\v120\PluginUpdater(
__FILE__,
'your-plugin-slug',
'https://codeberg.org/api/v1/repos/my-username/my-awesome-plugin/releases',
'your_codeberg_personal_access_token'
);
Using Plugin Header Name
$plugin_data = get_plugin_data(__FILE__);
$updater = new \hhdev\CodebergPluginUpdater\v120\PluginUpdater(
__FILE__,
'your-plugin-slug',
'https://codeberg.org/api/v1/repos/my-username/my-awesome-plugin/releases',
'your_codeberg_token',
$plugin_data['Name']
);
Configuration
Constructor Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
$plugin_file | string | Yes | Path to the main plugin file (use __FILE__) |
$plugin_slug | string | Yes | Plugin slug used by the updater |
$repo_api_url | string | Yes | Codeberg API URL for releases |
$token | string | No | Codeberg personal access token (required for private repos) |
$plugin_name | string | No | Display name for the plugin (defaults to 'Plugin') |
Getting a Codeberg Token
For private repositories, you need a personal access token:
- Go to Codeberg → Settings → Applications.
- Generate a new token with
reposcope. - Add the token to your plugin configuration.
Release Management
Creating a Release
- Push your changes to Codeberg
- Go to your repository → Releases → Create Release
- Choose a tag name (e.g.,
v1.0.0) - Add a title and description (this becomes the changelog)
- Optionally attach a ZIP file containing your plugin
- Publish the release
Version Format
The class expects versions in the format:
v1.0.0✓v1.2.3✓v2.0.0-beta✓1.0.0(works but without 'v' prefix)
Changelog Display
The release description (body) is automatically displayed in:
- The WordPress plugin details modal
- The updates section
You can format the release description using markdown for better readability.
How It Works
- Version Check: WordPress checks for updates using the
check_for_update()method - API Request: The class fetches release data from Codeberg
- Version Comparison: Compares your plugin version with the latest release
- Download: Downloads the update (ZIP file or source archive)
- Installation: Extracts and installs the update
- Activation: Automatically reactivates the plugin
Requirements
- WordPress 4.6+
- PHP 5.6+
- Codeberg account (for private repositories)
- cURL or allow_url_fopen enabled
Troubleshooting
Update Not Showing
- Verify the release exists on Codeberg
- Check that the tag name starts with 'v' (e.g.,
v1.0.0) - Ensure the version in your plugin header is lower than the release version
- Clear WordPress transients:
delete_site_transient('update_plugins')
Private Repository Authentication Failed
- Verify your token has the correct permissions
- Ensure the token is correctly entered in the configuration
- Check that the repository URL is correct
Security Notes
- Never hardcode tokens in your plugin files. Consider using WordPress options or environment variables.
- For public repositories, you don't need a token.
- The token is only used for API requests and is transmitted via HTTPS.
Example Plugin Header
Make sure your main plugin file has a proper header:
<?php
/**
* Plugin Name: My Awesome Plugin
* Description: A great plugin that does awesome things
* Version: 1.0.0
* Author: Your Name
* License: GPL v2 or later
*/
Contributing
Contributions are welcome! Feel free to:
- Report bugs
- Suggest enhancements
- Submit pull requests
License
This code is released under the GPL v2 (or later) license.
Support
For issues with the updater class, please open an issue on the repository.
Made with ❤️ for the WordPress community