Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [1.4.0] - 2026-02-09

### Changed

- Replaced inline plugin updater with shared `class-github-updater.php`

## [1.3.1] - 2025-06-25

### Fixed
Expand Down
60 changes: 60 additions & 0 deletions class-github-updater.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?php
/**
* GitHub Plugin Updater
*
* Minimal wrapper around yahnis-elsts/plugin-update-checker for GitHub-hosted
* WordPress plugins. Defers the actual update-checker setup to the `init` action
* so it works regardless of when the calling plugin loads the file.
*
* @package Soderlind\WordPress
* @version 1.0.0
* @author Per Soderlind
* @license GPL-2.0-or-later
* @link https://github.com/soderlind/wordpress-plugin-github-updater
*/

namespace Soderlind\WordPress;

use YahnisElsts\PluginUpdateChecker\v5\PucFactory;

// Prevent direct access.
defined( 'ABSPATH' ) || exit;

/**
* Sets up automatic plugin updates from a GitHub repository.
*/
final class GitHubUpdater {

/**
* Initialize the GitHub update checker.
*
* @param string $github_url Full GitHub repository URL (e.g. 'https://github.com/owner/repo').
* @param string $plugin_file Absolute path to the main plugin file (__FILE__).
* @param string $plugin_slug Plugin slug used by WordPress (e.g. 'my-plugin').
* @param string $name_regex Optional regex to filter release assets (e.g. '/my-plugin\.zip/').
* @param string $branch Branch to track (default 'main').
*/
public static function init(
string $github_url,
string $plugin_file,
string $plugin_slug,
string $name_regex = '',
string $branch = 'main',
): void {
add_action( 'init', static function () use ( $github_url, $plugin_file, $plugin_slug, $name_regex, $branch ): void {
try {
$checker = PucFactory::buildUpdateChecker( $github_url, $plugin_file, $plugin_slug );
$checker->setBranch( $branch );

if ( '' !== $name_regex ) {
$checker->getVcsApi()->enableReleaseAssets( $name_regex );
}
} catch ( \Exception $e ) {
if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
// phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log
error_log( 'GitHubUpdater (' . $plugin_slug . '): ' . $e->getMessage() );
}
}
} );
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "vmfa-rules-engine",
"version": "1.3.1",
"version": "1.4.0",
"description": "Rule-based automatic folder assignment for media uploads",
"author": "Per Soderlind",
"license": "GPL-2.0-or-later",
Expand Down
5 changes: 4 additions & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Tags: media library, virtual folders, automation, rules engine, media organizati
Requires at least: 6.8
Tested up to: 6.9
Requires PHP: 8.3
Stable tag: 1.3.1
Stable tag: 1.4.0
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

Expand Down Expand Up @@ -108,6 +108,9 @@ Each imported file will be evaluated against your rules and assigned to the matc

== Changelog ==

= 1.4.0 =
* Changed: Replaced inline plugin updater with shared `class-github-updater.php`

= 1.3.1 =
* Fixed: Added ABSPATH guards to all PHP source files
* Added: uninstall.php for clean plugin removal
Expand Down
150 changes: 0 additions & 150 deletions src/php/Update/GitHubPluginUpdater.php

This file was deleted.

27 changes: 15 additions & 12 deletions vmfa-rules-engine.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Plugin Name: Virtual Media Folders - Rules Engine
* Plugin URI: https://github.com/soderlind/vmfa-rules-engine
* Description: Rule-based automatic folder assignment for media uploads. Add-on for Virtual Media Folders.
* Version: 1.3.1
* Version: 1.4.0
* Author: Per Soderlind
* Author URI: https://soderlind.no
* License: GPL-2.0-or-later
Expand All @@ -20,7 +20,7 @@
defined( 'ABSPATH' ) || exit;

// Plugin constants.
define( 'VMFA_RULES_ENGINE_VERSION', '1.3.1' );
define( 'VMFA_RULES_ENGINE_VERSION', '1.4.0' );
define( 'VMFA_RULES_ENGINE_FILE', __FILE__ );
define( 'VMFA_RULES_ENGINE_PATH', plugin_dir_path( __FILE__ ) );
define( 'VMFA_RULES_ENGINE_URL', plugin_dir_url( __FILE__ ) );
Expand All @@ -31,28 +31,31 @@
require_once VMFA_RULES_ENGINE_PATH . 'vendor/autoload.php';
}

// Update checker via GitHub releases.
if ( ! class_exists( \Soderlind\WordPress\GitHubUpdater::class ) ) {
require_once __DIR__ . '/class-github-updater.php';
}
\Soderlind\WordPress\GitHubUpdater::init(
github_url: 'https://github.com/soderlind/vmfa-rules-engine',
plugin_file: VMFA_RULES_ENGINE_FILE,
plugin_slug: 'vmfa-rules-engine',
name_regex: '/vmfa-rules-engine\.zip/',
branch: 'main',
);

/**
* Initialize the plugin.
*
* @return void
*/
function vmfa_rules_engine_init() {
// Update checker via GitHub releases.
VmfaRulesEngine\Update\GitHubPluginUpdater::create_with_assets(
'https://github.com/soderlind/vmfa-rules-engine',
__FILE__,
'vmfa-rules-engine',
'/vmfa-rules-engine\.zip/',
'main'
);

// Load text domain.
load_plugin_textdomain( 'vmfa-rules-engine', false, dirname( VMFA_RULES_ENGINE_BASENAME ) . '/languages' );

// Initialize plugin components.
VmfaRulesEngine\Plugin::get_instance();
}
add_action( 'init', 'vmfa_rules_engine_init', 20 );
add_action( 'plugins_loaded', 'vmfa_rules_engine_init', 20 );

/**
* Activation hook.
Expand Down