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
12 changes: 12 additions & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# These are supported funding model platforms

github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
patreon: # Replace with a single Patreon username
open_collective: # Replace with a single Open Collective username
ko_fi: # Replace with a single Ko-fi username
tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
liberapay: # Replace with a single Liberapay username
issuehunt: # Replace with a single IssueHunt username
otechie: # Replace with a single Otechie username
custom: https://paypal.me/PerSoderlind # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']
39 changes: 39 additions & 0 deletions .github/workflows/manually-build-zip.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: Manually Build release zip

on:
workflow_dispatch:
inputs:
tag:
description: 'Tag to deploy'
required: true
type: string
default: ''

jobs:
build:
name: Build release zip
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Build plugin # Remove or modify this step as needed
run: |
composer install --no-dev

- name: Archive Release
uses: thedoctor0/zip-release@b57d897cb5d60cb78b51a507f63fa184cfe35554 #0.7.6
with:
type: 'zip'
filename: 'custom-document-folder.zip'
exclusions: '*.git* .editorconfig composer* *.md package.json package-lock.json'

- name: Release
uses: softprops/action-gh-release@c95fe1489396fe8a9eb87c0abf8aa5b2ef267fda #v2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
files: custom-document-folder.zip
tag_name: ${{ github.event.inputs.tag }}
34 changes: 34 additions & 0 deletions .github/workflows/on-release-add.zip.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: On Release, Build release zip

on:
release:
types: [published]

jobs:
build:
name: Build release zip
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Build plugin # Remove or modify this step as needed
run: |
composer install --no-dev

- name: Archive Release
uses: thedoctor0/zip-release@b57d897cb5d60cb78b51a507f63fa184cfe35554 #0.7.6
with:
type: 'zip'
filename: 'custom-document-folder.zip'
exclusions: '*.git* .editorconfig composer* *.md package.json package-lock.json'

- name: Release
uses: softprops/action-gh-release@c95fe1489396fe8a9eb87c0abf8aa5b2ef267fda #v2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
files: custom-document-folder.zip
tag_name: ${{ github.event.release.tag_name }}
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,17 @@ 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.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [1.1.0] - 2025-11-25

### Added
- Automatic updates via GitHub releases using [Plugin Update Checker](https://github.com/YahnisElsts/plugin-update-checker) library (v5.6)
- Plugin now checks for updates from the GitHub repository
- Users receive update notifications directly in WordPress admin
- Seamless one-click updates from the Plugins page

### Dependencies
- Added `yahnis-elsts/plugin-update-checker` ^5.6 via Composer

## [1.0.1] - 2025-11-24

### Changed
Expand Down Expand Up @@ -77,5 +88,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Settings sanitization: XSS protection tested
- Upload path modification: Verified for multiple file types

[1.1.0]: https://github.com/soderlind/custom-document-folder/releases/tag/1.1.0
[1.0.1]: https://github.com/soderlind/custom-document-folder/releases/tag/1.0.1
[1.0.0]: https://github.com/soderlind/custom-document-folder/releases/tag/1.0.0
25 changes: 10 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,25 +24,20 @@ Custom Document Folder automatically organizes your WordPress media uploads by d

## Installation

### Via WordPress Admin
- **Quick Install**

1. Download the plugin zip file
2. Go to **Plugins > Add New** in WordPress admin
3. Click **Upload Plugin** and choose the zip file
4. Click **Install Now** and then **Activate**
5. Go to **Settings > Document Folder** to configure
- Download [`custom-document-folder.zip`](https://github.com/soderlind/custom-document-folder/releases/latest/download/custom-document-folder.zip)
- Upload via Plugins > Add New > Upload Plugin
- Activate the plugin.

### Manual Installation
- **Composer Install**

1. Upload the `custom-document-folder` folder to `/wp-content/plugins/`
2. Activate the plugin through the **Plugins** menu in WordPress
3. Go to **Settings > Document Folder** to configure file extensions
```bash
composer require soderlind/custom-document-folder
```

### Via Composer

```bash
composer require soderlind/custom-document-folder
```
- **Updates**
* Plugin [updates are handled automatically](https://github.com/soderlind/wordpress-plugin-github-updater#readme) via GitHub. No need to manually download and install updates.

## Usage

Expand Down
146 changes: 146 additions & 0 deletions class-github-plugin-updater.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
<?php
namespace Soderlind\DocumentFolder;

use YahnisElsts\PluginUpdateChecker\v5\PucFactory;

/**
* Generic WordPress Plugin GitHub Updater
*
* A reusable class for handling WordPress plugin updates from GitHub repositories
* using the plugin-update-checker library.
*
* @package Soderlind\WordPress
* @version 1.0.0
* @author Per Soderlind
* @license GPL-2.0+
*/
class GitHub_Plugin_Updater {
/**
* @var string GitHub repository URL
*/
private $github_url;

/**
* @var string Branch to check for updates
*/
private $branch;

/**
* @var string Regex pattern to match the plugin zip file name
*/
private $name_regex;

/**
* @var string The plugin slug
*/
private $plugin_slug;

/**
* @var string The main plugin file path
*/
private $plugin_file;

/**
* @var bool Whether to enable release assets
*/
private $enable_release_assets;

/**
* Constructor
*
* @param array $config Configuration array with the following keys:
* - github_url: GitHub repository URL (required)
* - plugin_file: Main plugin file path (required)
* - plugin_slug: Plugin slug for updates (required)
* - branch: Branch to check for updates (default: 'main')
* - name_regex: Regex pattern for zip file name (optional)
* - enable_release_assets: Whether to enable release assets (default: true if name_regex provided)
*/
public function __construct( $config = array() ) {
// Validate required parameters
$required = array( 'github_url', 'plugin_file', 'plugin_slug' );
foreach ( $required as $key ) {
if ( empty( $config[ $key ] ) ) {
throw new \InvalidArgumentException( "Required parameter '{$key}' is missing or empty." );
}
}

$this->github_url = $config[ 'github_url' ];
$this->plugin_file = $config[ 'plugin_file' ];
$this->plugin_slug = $config[ 'plugin_slug' ];
$this->branch = isset( $config[ 'branch' ] ) ? $config[ 'branch' ] : 'main';
$this->name_regex = isset( $config[ 'name_regex' ] ) ? $config[ 'name_regex' ] : '';
$this->enable_release_assets = isset( $config[ 'enable_release_assets' ] )
? $config[ 'enable_release_assets' ]
: ! empty( $this->name_regex );

// Initialize the updater
add_action( 'init', array( $this, 'setup_updater' ) );
}

/**
* Set up the update checker using GitHub integration
*/
public function setup_updater() {
try {
$update_checker = PucFactory::buildUpdateChecker(
$this->github_url,
$this->plugin_file,
$this->plugin_slug
);

$update_checker->setBranch( $this->branch );

// Enable release assets if configured
if ( $this->enable_release_assets && ! empty( $this->name_regex ) ) {
$update_checker->getVcsApi()->enableReleaseAssets( $this->name_regex );
}

} catch (\Exception $e) {
// Log error if WordPress debug is enabled
if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
error_log( 'GitHub Plugin Updater Error: ' . $e->getMessage() );
}
}
}

/**
* Create updater instance with minimal configuration
*
* @param string $github_url GitHub repository URL
* @param string $plugin_file Main plugin file path
* @param string $plugin_slug Plugin slug
* @param string $branch Branch name (default: 'main')
*
* @return GitHub_Plugin_Updater
*/
public static function create( $github_url, $plugin_file, $plugin_slug, $branch = 'main' ) {
return new self( array(
'github_url' => $github_url,
'plugin_file' => $plugin_file,
'plugin_slug' => $plugin_slug,
'branch' => $branch,
) );
}

/**
* Create updater instance for plugins with release assets
*
* @param string $github_url GitHub repository URL
* @param string $plugin_file Main plugin file path
* @param string $plugin_slug Plugin slug
* @param string $name_regex Regex pattern for release assets
* @param string $branch Branch name (default: 'main')
*
* @return GitHub_Plugin_Updater
*/
public static function create_with_assets( $github_url, $plugin_file, $plugin_slug, $name_regex, $branch = 'main' ) {
return new self( array(
'github_url' => $github_url,
'plugin_file' => $plugin_file,
'plugin_slug' => $plugin_slug,
'branch' => $branch,
'name_regex' => $name_regex,
) );
}
}
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"type": "wordpress-plugin",
"license": "GPL-2.0-or-later",
"require": {
"php": ">=8.3"
"php": ">=8.3",
"yahnis-elsts/plugin-update-checker": "^5.6"
},
"require-dev": {
"phpunit/phpunit": "^9.0",
Expand All @@ -20,4 +21,4 @@
"test": "phpunit",
"test:coverage": "phpunit --coverage-html coverage"
}
}
}
55 changes: 53 additions & 2 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading