diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml new file mode 100644 index 0000000..6f59ccc --- /dev/null +++ b/.github/FUNDING.yml @@ -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'] diff --git a/.github/workflows/manually-build-zip.yml b/.github/workflows/manually-build-zip.yml new file mode 100644 index 0000000..f9a2ec3 --- /dev/null +++ b/.github/workflows/manually-build-zip.yml @@ -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 }} diff --git a/.github/workflows/on-release-add.zip.yml b/.github/workflows/on-release-add.zip.yml new file mode 100644 index 0000000..c7bb2c8 --- /dev/null +++ b/.github/workflows/on-release-add.zip.yml @@ -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 }} \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index 91def1d..8218283 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 @@ -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 diff --git a/composer.json b/composer.json index 0c0a8a9..79fce37 100644 --- a/composer.json +++ b/composer.json @@ -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", @@ -30,4 +31,4 @@ "dealerdirect/phpcodesniffer-composer-installer": true } } -} \ No newline at end of file +} diff --git a/includes/class-github-plugin-updater.php b/includes/class-github-plugin-updater.php new file mode 100644 index 0000000..a7906bc --- /dev/null +++ b/includes/class-github-plugin-updater.php @@ -0,0 +1,146 @@ +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, + ) ); + } +} diff --git a/package.json b/package.json index 0d464a2..5be3dff 100644 --- a/package.json +++ b/package.json @@ -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": { diff --git a/passwp-posts.php b/passwp-posts.php index 106608b..55e38c1 100644 --- a/passwp-posts.php +++ b/passwp-posts.php @@ -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+ @@ -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__ ) ); @@ -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. @@ -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(); diff --git a/readme.txt b/readme.txt index 584b19b..92e18e3 100644 --- a/readme.txt +++ b/readme.txt @@ -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 @@ -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 @@ -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.