Initial setup, untested
Validate Build / validate-build (push) Failing after 36s

This commit is contained in:
Cooper Dalrymple
2026-08-25 14:58:39 -05:00
parent 7159f7099e
commit 5f702470cc
17 changed files with 2573 additions and 163 deletions
+6
View File
@@ -20,3 +20,9 @@ install:
package: install
gulp package
postinstall:
cp node_modules/klaro/dist/klaro.js assets/klaro.js
cp node_modules/klaro/dist/klaro.min.css assets/klaro.min.css
postupdate: postinstall
+1
View File
File diff suppressed because one or more lines are too long
+1
View File
File diff suppressed because one or more lines are too long
+2 -2
View File
@@ -2,8 +2,8 @@
"$schema": "https://getcomposer.org/schema.json",
"name": "cleverogre/plugin",
"version": "0.0.0",
"title": "Example",
"description": "Example plugin",
"title": "Ogre Consent",
"description": "Ogre Consent plugin",
"author": "CleverOgre",
"license": "GPL-3.0+",
"keywords": [
Generated
+2 -2
View File
@@ -12,7 +12,7 @@
"source": {
"type": "git",
"url": "git@git.cleverogre.com:cleverogre/plugin-framework.git",
"reference": "e7c2be1862b24e9c9b861f18d67b2aacafbe9946"
"reference": "0b16ec6f70a5a3852a1da9189ebef8363c2d7436"
},
"require": {
"cleverogre/plugin-update-checker": "dev-main",
@@ -52,7 +52,7 @@
"Plugin",
"WordPress"
],
"time": "2026-07-20T19:59:33+00:00"
"time": "2026-07-21T13:43:37+00:00"
},
{
"name": "cleverogre/plugin-update-checker",
+120
View File
@@ -0,0 +1,120 @@
<?php
/**
* @package ogre-consent
* @author cleverogre
* @copyright 2026 CleverOgre
* @license GLP-3.0-or-later
* @version 0.0.0
* @since 0.0.0
*/
namespace Ogre\Consent;
use Override;
use Ogre\Singleton;
use WP_Block;
use WP_HTML_Tag_Processor;
defined('ABSPATH') || exit;
abstract class Service {
use Singleton;
protected string $name;
protected bool $contextualConsentOnly = false;
protected function __construct(string $name) {
$this->name = $name;
Services::instance()->register($this);
}
public function get_config(): array
{
$config = [
'name' => $this->name,
'purposes' => $this->get_purposes(),
];
if ($this->contextualConsentOnly) $config['contextualConsentOnly'] = true;
return $config;
}
public function get_purposes(): array
{
return [
'marketing'
];
}
}
abstract class ScriptService extends Service {
protected string $handle;
protected function __construct(string $handle, string $name = '') {
$this->handle = $handle;
parent::__construct($name ?? $handle);
add_filter('script_loader_tag', [$this, 'script_loader_tag'], 10, 3);
}
public function script_loader_tag(string $tag, string $handle, string $src): string
{
if ($handle !== $this->handle) return $tag;
$tags = new WP_HTML_Tag_Processor($tag);
if ($tags->next_tag('script')) {
$tags->set_attribute('type', 'text/plain');
$tags->set_attribute('data-name', $this->name);
if (!str_starts_with(($src = $tags->get_attribute('src')), site_url())) {
$tags->remove_attribute('src');
$tags->set_attribute('data-src', $src);
}
}
return $tag;
}
}
abstract class BlockService extends Service {
protected string $blockName;
protected function __construct(string $blockName, string $name = '') {
$this->blockName = $blockName;
parent::__construct($name ?? $blockName);
add_filter("render_block_{$blockName}", [$this, 'render_block'], 10, 3);
}
abstract public function render_block(string $block_content, array $block, WP_Block $instance): string;
}
abstract class GoogleTagManagerService extends ScriptService {
protected string $consent_id;
protected function __construct(string $handle, string $name = '', string $consent_id = '') {
$this->consent_id = $consent_id ?? ($name ?? $handle);
parent::__construct($handle, $name);
}
#[Override]
public function get_config(): array
{
return array_merge(
parent::get_config(),
[
'cookies' => [
'/^_ga(_.*)?/'
],
'onAccept' => sprintf(
"gtag('consent', 'update', {'%s': 'granted'})",
esc_js($this->consent_id)
),
'onDecline' => sprintf(
"gtag('consent', 'update', {'%s': 'denied'})",
esc_js($this->consent_id)
),
]
);
}
}
+44
View File
@@ -0,0 +1,44 @@
<?php
/**
* @package ogre-consent
* @author cleverogre
* @copyright 2026 CleverOgre
* @license GLP-3.0-or-later
* @version 0.0.0
* @since 0.0.0
*/
namespace Ogre\Consent;
use Ogre\Consent as Plugin;
use Ogre\Singleton;
defined('ABSPATH') || exit;
final class Config {
use Singleton;
protected function __construct() {
}
public function get_config(): array
{
// See https://klaro.org/docs/integration/annotated-configuration
$config = [
'elementID' => Plugin::get_id(),
'storageMethod' => 'localStorage',
'storageName' => Plugin::get_id(),
'cookieDomain' => parse_url(site_url(), PHP_URL_HOST),
'default' => true,
'mustConsent' => true,
'acceptAll' => true,
'hideLearnMore' => true,
'services' => Services::instance()->get_config(),
];
return apply_filters('ogre_consent_config', $config);
}
}
Config::instance();
+63
View File
@@ -0,0 +1,63 @@
<?php
/**
* @package ogre-consent
* @author cleverogre
* @copyright 2026 CleverOgre
* @license GLP-3.0-or-later
* @version 0.0.0
* @since 0.0.0
*/
namespace Ogre\Consent;
use Ogre\Consent as Plugin;
use Ogre\Singleton;
use WP_HTML_Tag_Processor;
defined('ABSPATH') || exit;
final class Script {
use Singleton;
private const HANDLE = 'klaro';
private const CONFIG = 'klaroConfig';
protected function __construct() {
add_action('wp_enqueue_scripts', [$this, 'wp_enqueue_scripts']);
add_filter('script_loader_tag', [$this, 'script_loader_tag'], 10, 3);
}
public function wp_enqueue_scripts(): void
{
wp_enqueue_script(
self::HANDLE,
Plugin::get_url('assets/klaro.js'),
ver: Plugin::get_version()
);
wp_localize_script(
self::HANDLE,
self::CONFIG,
Config::instance()->get_config()
);
wp_enqueue_style(
self::HANDLE,
Plugin::get_url('assets/klaro.min.css'),
ver: Plugin::get_version()
);
}
public function script_loader_tag(string $tag, string $handle, string $src): string
{
if ($tag !== self::HANDLE) return $tag;
$tags = new WP_HTML_Tag_Processor($tag);
if ($tags->next_tag('script')) {
$tags->set_attribute('data-config', self::CONFIG);
}
return $tags->get_updated_html();
}
}
Script::instance();
+40
View File
@@ -0,0 +1,40 @@
<?php
/**
* @package ogre-consent
* @author cleverogre
* @copyright 2026 CleverOgre
* @license GLP-3.0-or-later
* @version 0.0.0
* @since 0.0.0
*/
namespace Ogre\Consent;
use Ogre\Consent as Plugin;
use Ogre\Singleton;
use WP_HTML_Tag_Processor;
defined('ABSPATH') || exit;
final class Services {
use Singleton;
protected array $services = [];
protected function __construct() {
}
public function register(Service $service): void
{
$this->services[] = $service;
}
public function get_config(): array
{
return array_map(fn (Service $service): array => $service->get_config(), $this->services);
}
}
Services::instance();
+3 -3
View File
@@ -1,6 +1,6 @@
<?php
/**
* @package plugin
* @package ogre-consent
* @author cleverogre
* @copyright 2026 CleverOgre
* @license GLP-3.0-or-later
@@ -8,11 +8,11 @@
* @since 0.0.0
*/
namespace Ogre\Example;
namespace Ogre\Consent;
use Override;
use Ogre\Settings as AbstractSettings;
use Ogre\Example as Plugin;
use Ogre\Consent as Plugin;
defined('ABSPATH') || exit;
+39
View File
@@ -0,0 +1,39 @@
<?php
/**
* @package ogre-consent
* @author cleverogre
* @copyright 2026 CleverOgre
* @license GLP-3.0-or-later
* @version 0.0.0
* @since 0.0.0
*/
namespace Ogre\Consent\Services;
use Ogre\Consent\GoogleTagManagerService;
use Override;
defined('ABSPATH') || exit;
final class GoogleAnalytics extends GoogleTagManagerService {
protected function __construct() {
parent::__construct('google-analytics', consent_id: 'analytics_storage');
}
#[Override]
public function get_config(): array
{
return array_merge(
parent::get_config(),
[
'cookies' => [
'/^_ga(_.*)?/'
],
]
);
}
}
GoogleAnalytics::instance();
+39
View File
@@ -0,0 +1,39 @@
<?php
/**
* @package ogre-consent
* @author cleverogre
* @copyright 2026 CleverOgre
* @license GLP-3.0-or-later
* @version 0.0.0
* @since 0.0.0
*/
namespace Ogre\Consent\Services;
use Ogre\Consent\ScriptService;
use Override;
defined('ABSPATH') || exit;
final class GoogleTagManager extends ScriptService {
protected function __construct() {
parent::__construct('google-tag-manager');
}
#[Override]
public function get_config(): array
{
return array_merge(
parent::get_config(),
[
'required' => true,
'onAccept' => "for (let k of Object.keys(opts.consents)) { if (opts.consents[k]) { dataLayer.push({'event': 'ogre-consent-'+k+'-accepted'}) } }",
'onInit' => "window.dataLayer = window.dataLayer || []; window.gtag = function() { dataLayer.push(arguments) }; gtag('consent', 'default', {'ad_storage': 'denied', 'analytics_storage': 'denied', 'ad_user_data': 'denied', 'ad_personalization': 'denied'}); gtag('set', 'ads_data_redaction', true);",
]
);
}
}
GoogleAnalytics::instance();
+45
View File
@@ -0,0 +1,45 @@
<?php
/**
* @package ogre-consent
* @author cleverogre
* @copyright 2026 CleverOgre
* @license GLP-3.0-or-later
* @version 0.0.0
* @since 0.0.0
*/
namespace Ogre\Consent\Services;
use Ogre\Consent\BlockService;
use WP_Block;
use Override;
use WP_HTML_Tag_Processor;
defined('ABSPATH') || exit;
final class YouTube extends BlockService {
protected function __construct() {
parent::__construct('core/iframe', 'youtube');
}
#[Override]
public function render_block(string $block_content, array $block, WP_Block $instance): string
{
// TODO: Check block iframe type
$tags = new WP_HTML_Tag_Processor($block_content);
if ($tags->next_tag('iframe')) {
$tags->set_attribute('data-name', $this->name);
$src = $tags->get_attribute('src');
$tags->remove_attribute('src');
$tags->set_attribute('data-src', $src);
}
return $tags->get_updated_html();
}
}
YouTube::instance();
+2144 -139
View File
File diff suppressed because it is too large Load Diff
+9 -2
View File
@@ -2,8 +2,8 @@
"$schema": "https://www.schemastore.org/package.json",
"name": "cleverogre/plugin",
"version": "0.0.0",
"title": "Example",
"description": "Example plugin",
"title": "Ogre Consent",
"description": "Ogre Consent plugin",
"author": "CleverOgre",
"license": "GPL-3.0+",
"keywords": [
@@ -15,11 +15,18 @@
"node": ">=21.1.0",
"npm": ">=10.2.3"
},
"scripts": {
"postinstall": "make postinstall",
"postupdate": "make postupdate"
},
"devDependencies": {
"gulp": "^5.0.0",
"gulp-clean": "^0.4.0",
"gulp-cli": "^2.3.0",
"gulp-filter": "^10.0.0",
"gulp-zip": "^6.1.0"
},
"dependencies": {
"klaro": "^0.7.21"
}
}
+13 -13
View File
@@ -1,8 +1,8 @@
<?php
/**
* Example
* Ogre Consent
*
* @package plugin
* @package ogre-consent
* @author cleverogre
* @copyright 2026 CleverOgre
* @license GLP-3.0-or-later
@@ -10,9 +10,9 @@
* @since 0.0.0
*
* @wordpress-plugin
* Plugin Name: Example
* Plugin URI: https://git.cleverogre.com/cleverogre/plugin/
* Description: Example plugin
* Plugin Name: Ogre Consent
* Plugin URI: https://git.cleverogre.com/cleverogre/ogre-consent/
* Description: Ogre Consent plugin
* Version: 0.0.0
* Requires at least: 6.0
* Requires PHP: 8.2
@@ -21,24 +21,24 @@
* Text Domain: plugin
* License: GPLv3 or later
* License URI: http://www.gnu.org/licenses/gpl-3.0.html
* Update URI: https://git.cleverogre.com/cleverogre/plugin/
* Update URI: https://git.cleverogre.com/cleverogre/ogre-consent/
* Domain Path: /lang
* Icon1x: https://plugins.cleverogre.com/wp-content/uploads/plugin-icon-128x128.png
* Icon2x: https://plugins.cleverogre.com/wp-content/uploads/plugin-icon.png
* BannerLow: https://plugins.cleverogre.com/wp-content/uploads/plugin-banner-772x250.png
* BannerHigh: https://plugins.cleverogre.com/wp-content/uploads/plugin-banner.png
* Icon1x: https://plugins.cleverogre.com/wp-content/uploads/ogre-consent-icon-128x128.png
* Icon2x: https://plugins.cleverogre.com/wp-content/uploads/ogre-consent-icon.png
* BannerLow: https://plugins.cleverogre.com/wp-content/uploads/ogre-consent-banner-772x250.png
* BannerHigh: https://plugins.cleverogre.com/wp-content/uploads/ogre-consent-banner.png
* Requires License: yes
*/
namespace Ogre;
use Ogre\Example\Settings;
use Ogre\Consent\Settings;
defined('ABSPATH') || exit;
require_once 'vendor/autoload.php';
final class Example extends Plugin {
final class Consent extends Plugin {
protected function __construct() {
parent::__construct();
@@ -72,4 +72,4 @@ final class Example extends Plugin {
}
Example::instance();
Consent::instance();
+2 -2
View File
@@ -1,4 +1,4 @@
=== Example ===
=== Ogre Consent ===
Contributors: ogrecooper, cleverogre
Tested up to: 7.0
Requires at least: 6.0
@@ -10,7 +10,7 @@ Copyright: CleverOgre
Donate link: https://cleverogre.com/
Tags: wordpress, plugin
Example plugin
Ogre Consent plugin
== Installation ==