Skip to content

Commit ceca1b8

Browse files
committed
Add plugin updater
1 parent c58d538 commit ceca1b8

File tree

135 files changed

+12653
-8
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

135 files changed

+12653
-8
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
name: Manually Build release zip
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
tag:
7+
description: 'Tag to deploy'
8+
required: true
9+
type: string
10+
default: ''
11+
12+
jobs:
13+
build:
14+
name: Build release zip
15+
runs-on: ubuntu-latest
16+
permissions:
17+
contents: write
18+
steps:
19+
- name: Checkout
20+
uses: actions/checkout@v4
21+
22+
- name: Build plugin # Remove or modify this step as needed
23+
run: |
24+
composer install --no-dev
25+
26+
- name: Archive Release
27+
uses: thedoctor0/zip-release@b57d897cb5d60cb78b51a507f63fa184cfe35554 #0.7.6
28+
with:
29+
type: 'zip'
30+
filename: 'additional-javascript.zip'
31+
exclusions: '*.git* .editorconfig composer* *.md package.json package-lock.json'
32+
33+
- name: Release
34+
uses: softprops/action-gh-release@c95fe1489396fe8a9eb87c0abf8aa5b2ef267fda #v2
35+
env:
36+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
37+
with:
38+
files: additional-javascript.zip
39+
tag_name: ${{ github.event.inputs.tag }}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: On Release, Build release zip
2+
3+
on:
4+
release:
5+
types: [published]
6+
7+
jobs:
8+
build:
9+
name: Build release zip
10+
runs-on: ubuntu-latest
11+
permissions:
12+
contents: write
13+
steps:
14+
- name: Checkout
15+
uses: actions/checkout@v4
16+
17+
- name: Build plugin # Remove or modify this step as needed
18+
run: |
19+
composer install --no-dev
20+
21+
- name: Archive Release
22+
uses: thedoctor0/zip-release@b57d897cb5d60cb78b51a507f63fa184cfe35554 #0.7.6
23+
with:
24+
type: 'zip'
25+
filename: 'additional-javascript.zip'
26+
exclusions: '*.git* .editorconfig composer* *.md package.json package-lock.json'
27+
28+
- name: Release
29+
uses: softprops/action-gh-release@c95fe1489396fe8a9eb87c0abf8aa5b2ef267fda #v2
30+
env:
31+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
32+
with:
33+
files: additional-javascript.zip
34+
tag_name: ${{ github.event.release.tag_name }}

additional-javascript.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,18 @@
2525
die();
2626
}
2727

28+
define( 'ADDITIONAL_JAVASCRIPT_VERSION', '1.1.0' );
29+
define( 'ADDITIONAL_JAVASCRIPT_FILE', __FILE__ );
30+
define( 'ADDITIONAL_JAVASCRIPT_PATH', plugin_dir_path( __FILE__ ) );
31+
32+
require_once ADDITIONAL_JAVASCRIPT_PATH . 'vendor/autoload.php';
33+
/**
34+
* Load the plugin updater class.
35+
*/
36+
require_once dirname( __FILE__ ) . '/class-additional-javascript-updater.php';
37+
// Initialize the updater.
38+
$additional_javascript_updater = new Additional_JavaScript_Updater();
39+
2840
add_action( 'init', __NAMESPACE__ . '\register_post_type_javascript', 0 );
2941
add_action( 'wp_head', __NAMESPACE__ . '\soderlind_custom_javascript_cb', 110 );
3042
add_action( 'customize_register', __NAMESPACE__ . '\register_additional_javascript' );
@@ -34,7 +46,8 @@
3446
/**
3547
* Plugin version - used for cache-busting assets
3648
*/
37-
define( 'ADDITIONAL_JAVASCRIPT_VERSION', '1.1.0' );
49+
50+
3851

3952
/**
4053
* Add a default JavaScript code.
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<?php
2+
namespace Soderlind\Customizer;
3+
4+
use YahnisElsts\PluginUpdateChecker\v5\PucFactory;
5+
6+
/**
7+
* Plugin updater class for WP Loupe
8+
*
9+
* Handles plugin updates directly from GitHub using the plugin-update-checker library
10+
*
11+
* @package Soderlind\Plugin\WPLoupe
12+
* @since 0.1.2
13+
*/
14+
class Additional_JavaScript_Updater {
15+
/**
16+
* @var string GitHub repository URL
17+
*/
18+
private $github_url = 'https://github.com/soderlind/additional-javascript';
19+
20+
/**
21+
* @var string Branch to check for updates
22+
*/
23+
private $branch = 'main';
24+
25+
/**
26+
* @var string Regex pattern to match the plugin zip file name
27+
*/
28+
private $name_regex = '/additional-javascript\.zip/';
29+
30+
/**
31+
* @var string The plugin slug
32+
*/
33+
private $plugin_slug = 'additional-javascript';
34+
35+
/**
36+
* Constructor
37+
*/
38+
public function __construct() {
39+
add_action( 'init', array( $this, 'setup_updater' ) );
40+
}
41+
42+
/**
43+
* Set up the update checker using GitHub integration
44+
*/
45+
public function setup_updater() {
46+
$update_checker = PucFactory::buildUpdateChecker(
47+
$this->github_url,
48+
ADDITIONAL_JAVASCRIPT_FILE,
49+
$this->plugin_slug
50+
);
51+
52+
$update_checker->setBranch( $this->branch );
53+
$update_checker->getVcsApi()->enableReleaseAssets( $this->name_regex );
54+
}
55+
}

composer.json

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,6 @@
2121
"issues": "https://github.com/soderlind/additional-javascript/issues"
2222
},
2323
"require": {
24-
"php": ">=5.6",
25-
"composer/installers": "~1.0"
26-
},
27-
"require-dev": {
28-
"squizlabs/php_codesniffer": "^3.3",
29-
"dealerdirect/phpcodesniffer-composer-installer": "*",
30-
"wp-coding-standards/wpcs": "*"
24+
"yahnis-elsts/plugin-update-checker": "^5.6"
3125
}
3226
}

composer.lock

Lines changed: 69 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/autoload.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
// autoload.php @generated by Composer
4+
5+
if (PHP_VERSION_ID < 50600) {
6+
if (!headers_sent()) {
7+
header('HTTP/1.1 500 Internal Server Error');
8+
}
9+
$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;
10+
if (!ini_get('display_errors')) {
11+
if (PHP_SAPI === 'cli' || PHP_SAPI === 'phpdbg') {
12+
fwrite(STDERR, $err);
13+
} elseif (!headers_sent()) {
14+
echo $err;
15+
}
16+
}
17+
throw new RuntimeException($err);
18+
}
19+
20+
require_once __DIR__ . '/composer/autoload_real.php';
21+
22+
return ComposerAutoloaderInit0278dedba831eb3c0b5c13d4f10f3e1d::getLoader();

0 commit comments

Comments
 (0)