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: 'passwp-posts.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: passwp-posts.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: 'passwp-posts.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: passwp-posts.zip
tag_name: ${{ github.event.release.tag_name }}
13 changes: 12 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [1.0.4] - 2024-12-15

### Added

- GitHub Plugin Updater class for automatic updates from GitHub releases
- Plugin Update Checker library (yahnis-elsts/plugin-update-checker) as dependency
- GitHub Actions workflow for building release zips on publish
- GitHub Actions workflow for manually building release zips
- GitHub FUNDING.yml for sponsor information

## [1.0.3] - 2024-12-12

### Changed
Expand Down Expand Up @@ -66,7 +76,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Admin capabilities checked with `manage_options`
- All forms protected with WordPress nonces

[Unreleased]: https://github.com/soderlind/passwp-posts/compare/v1.0.3...HEAD
[Unreleased]: https://github.com/soderlind/passwp-posts/compare/v1.0.4...HEAD
[1.0.4]: https://github.com/soderlind/passwp-posts/compare/v1.0.3...v1.0.4
[1.0.3]: https://github.com/soderlind/passwp-posts/compare/v1.0.2...v1.0.3
[1.0.2]: https://github.com/soderlind/passwp-posts/compare/v1.0.1...v1.0.2
[1.0.1]: https://github.com/soderlind/passwp-posts/compare/v1.0.0...v1.0.1
Expand Down
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+",
"require": {
"php": ">=8.3"
"php": ">=8.3",
"yahnis-elsts/plugin-update-checker": "^5.6"
},
"require-dev": {
"phpunit/phpunit": "^10.0",
Expand All @@ -30,4 +31,4 @@
"dealerdirect/phpcodesniffer-composer-installer": true
}
}
}
}
146 changes: 146 additions & 0 deletions includes/class-github-plugin-updater.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
<?php
namespace PassWP\Posts;

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,
) );
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "passwp-posts",
"version": "1.0.0",
"version": "1.0.4",
"description": "Password protects all pages and posts except the front page",
"type": "module",
"scripts": {
Expand Down
13 changes: 11 additions & 2 deletions passwp-posts.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Plugin Name: PassWP Posts
* Plugin URI: https://developer.suspended.no/passwp-posts
* Description: Password protects all pages and posts except the front page. Logged-in users bypass the password.
* Version: 1.0.3
* Version: 1.0.4
* Author: Per Soderlind
* Author URI: https://soderlind.no
* License: GPL-2.0+
Expand All @@ -22,7 +22,7 @@
defined( 'ABSPATH' ) || exit;

// Plugin constants.
define( 'PASSWP_POSTS_VERSION', '1.0.3' );
define( 'PASSWP_POSTS_VERSION', '1.0.4' );
define( 'PASSWP_POSTS_PATH', plugin_dir_path( __FILE__ ) );
define( 'PASSWP_POSTS_URL', plugin_dir_url( __FILE__ ) );
define( 'PASSWP_POSTS_BASENAME', plugin_basename( __FILE__ ) );
Expand Down Expand Up @@ -51,6 +51,7 @@
use PassWP\Posts\Admin_Settings;
use PassWP\Posts\Cookie_Handler;
use PassWP\Posts\Protection;
use PassWP\Posts\GitHub_Plugin_Updater;

/**
* Initialize the plugin.
Expand All @@ -59,6 +60,14 @@ function passwp_posts_init(): void {
// Load text domain.
load_plugin_textdomain( 'passwp-posts', false, dirname( PASSWP_POSTS_BASENAME ) . '/languages' );

// Set up GitHub plugin updater.
GitHub_Plugin_Updater::create_with_assets(
'https://github.com/soderlind/passwp-posts',
__FILE__,
'passwp-posts',
'/passwp-posts\.zip/',
'main'
);
// Initialize components.
new Admin_Settings();
new Protection();
Expand Down
10 changes: 9 additions & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Tags: password, protection, privacy, security, access control
Requires at least: 6.8
Tested up to: 6.9
Requires PHP: 8.3
Stable tag: 1.0.3
Stable tag: 1.0.4
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

Expand Down Expand Up @@ -82,6 +82,11 @@ You may need to exclude protected pages from caching or configure your caching p

== Changelog ==

= 1.0.4 =
* Added GitHub Plugin Updater for automatic updates from GitHub releases
* Added Plugin Update Checker library as dependency
* Added GitHub Actions workflows for building release zips

= 1.0.3 =
* Housekeeping

Expand All @@ -106,6 +111,9 @@ You may need to exclude protected pages from caching or configure your caching p

== Upgrade Notice ==

= 1.0.4 =
Added automatic plugin updates from GitHub releases.

= 1.0.3 =
Housekeeping.

Expand Down