Skip to content

Add plugin updater #7

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 11, 2025
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
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: 'additional-javascript.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: additional-javascript.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: 'additional-javascript.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: additional-javascript.zip
tag_name: ${{ github.event.release.tag_name }}
15 changes: 14 additions & 1 deletion additional-javascript.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,18 @@
die();
}

define( 'ADDITIONAL_JAVASCRIPT_VERSION', '1.1.0' );
define( 'ADDITIONAL_JAVASCRIPT_FILE', __FILE__ );
define( 'ADDITIONAL_JAVASCRIPT_PATH', plugin_dir_path( __FILE__ ) );

require_once ADDITIONAL_JAVASCRIPT_PATH . 'vendor/autoload.php';
/**
* Load the plugin updater class.
*/
require_once dirname( __FILE__ ) . '/class-additional-javascript-updater.php';
// Initialize the updater.
$additional_javascript_updater = new Additional_JavaScript_Updater();

add_action( 'init', __NAMESPACE__ . '\register_post_type_javascript', 0 );
add_action( 'wp_head', __NAMESPACE__ . '\soderlind_custom_javascript_cb', 110 );
add_action( 'customize_register', __NAMESPACE__ . '\register_additional_javascript' );
Expand All @@ -34,7 +46,8 @@
/**
* Plugin version - used for cache-busting assets
*/
define( 'ADDITIONAL_JAVASCRIPT_VERSION', '1.1.0' );



/**
* Add a default JavaScript code.
Expand Down
55 changes: 55 additions & 0 deletions class-additional-javascript-updater.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php
namespace Soderlind\Customizer;

use YahnisElsts\PluginUpdateChecker\v5\PucFactory;

/**
* Plugin updater class for WP Loupe
*
* Handles plugin updates directly from GitHub using the plugin-update-checker library
*
* @package Soderlind\Plugin\WPLoupe
* @since 0.1.2
*/
class Additional_JavaScript_Updater {
/**
* @var string GitHub repository URL
*/
private $github_url = 'https://github.com/soderlind/additional-javascript';

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

/**
* @var string Regex pattern to match the plugin zip file name
*/
private $name_regex = '/additional-javascript\.zip/';

/**
* @var string The plugin slug
*/
private $plugin_slug = 'additional-javascript';

/**
* Constructor
*/
public function __construct() {
add_action( 'init', array( $this, 'setup_updater' ) );
}

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

$update_checker->setBranch( $this->branch );
$update_checker->getVcsApi()->enableReleaseAssets( $this->name_regex );
}
}
8 changes: 1 addition & 7 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,6 @@
"issues": "https://github.com/soderlind/additional-javascript/issues"
},
"require": {
"php": ">=5.6",
"composer/installers": "~1.0"
},
"require-dev": {
"squizlabs/php_codesniffer": "^3.3",
"dealerdirect/phpcodesniffer-composer-installer": "*",
"wp-coding-standards/wpcs": "*"
"yahnis-elsts/plugin-update-checker": "^5.6"
}
}
69 changes: 69 additions & 0 deletions composer.lock

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

22 changes: 22 additions & 0 deletions vendor/autoload.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

// autoload.php @generated by Composer

if (PHP_VERSION_ID < 50600) {
if (!headers_sent()) {
header('HTTP/1.1 500 Internal Server Error');
}
$err = 'Composer 2.3.0 dropped support for autoloading on PHP <5.6 and you are running '.PHP_VERSION.', please upgrade PHP or use Composer 2.2 LTS via "composer self-update --2.2". Aborting.'.PHP_EOL;
if (!ini_get('display_errors')) {
if (PHP_SAPI === 'cli' || PHP_SAPI === 'phpdbg') {
fwrite(STDERR, $err);
} elseif (!headers_sent()) {
echo $err;
}
}
throw new RuntimeException($err);
}

require_once __DIR__ . '/composer/autoload_real.php';

return ComposerAutoloaderInit0278dedba831eb3c0b5c13d4f10f3e1d::getLoader();
Loading