Skip to content

Commit 185c1ab

Browse files
committed
fix: xWP compatibilty standardization
1 parent 16e3b4e commit 185c1ab

File tree

7 files changed

+82
-108
lines changed

7 files changed

+82
-108
lines changed

.github/workflows/release.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ on:
33
push:
44
branches:
55
- master
6-
- develop
7-
- alpha
6+
- 1.x
87
- beta
98

109
jobs:

.releaserc

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,7 @@
11
{
22
"branches": [
33
"master",
4-
{
5-
"name": "develop",
6-
"prerelease": true
7-
},
8-
{
9-
"name": "alpha",
10-
"prerelease": true
11-
},
4+
"1.x",
125
{
136
"name": "beta",
147
"prerelease": true

composer.json

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@
1212
"require": {
1313
"php": ">= 8.0",
1414
"automattic/jetpack-constants": "^2.0.1",
15-
"oblak/wp-polyfills": "^1.4.2"
15+
"x-wp/helper-functions": "^1.9"
1616
},
1717
"require-dev": {
18-
"oblak/wordpress-coding-standard": "^1.1.1"
18+
"oblak/wordpress-coding-standard": "^1"
1919
},
2020
"suggest": {
2121
"automattic/jetpack-autoloader": "Allow for better interoperability with other plugins that use this package.",
@@ -36,8 +36,10 @@
3636
"sort-packages": true,
3737
"allow-plugins": {
3838
"automattic/jetpack-autoloader": true,
39-
"dealerdirect/phpcodesniffer-composer-installer": true,
40-
"ergebnis/composer-normalize": true
39+
"dealerdirect/phpcodesniffer-composer-installer": true
40+
},
41+
"platform": {
42+
"php": "8.0"
4143
}
4244
}
4345
}

composer.lock

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

src/Traits/Hook_Processor_Trait.php

Lines changed: 8 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?php
1+
<?php //phpcs:disable SlevomatCodingStandard.Classes.SuperfluousTraitNaming.SuperfluousSuffix
22
/**
33
* Base_Plugin class file.
44
*
@@ -9,7 +9,6 @@
99
namespace Oblak\WP\Traits;
1010

1111
use Oblak\WP\Decorators\Hookable;
12-
use Oblak\WP\Traits\Singleton_Trait;
1312

1413
use function Oblak\WP\Utils\get_decorators;
1514
use function Oblak\WP\Utils\invoke_class_hooks;
@@ -18,7 +17,6 @@
1817
* Enables basic DI and hooking functionality for plugins / themes
1918
*/
2019
trait Hook_Processor_Trait {
21-
2220
/**
2321
* Plugin textdomain
2422
*
@@ -33,8 +31,8 @@ trait Hook_Processor_Trait {
3331
* @param int $priority Hook priority.
3432
*/
3533
public function init( string $hook = 'plugins_loaded', int $priority = 10 ) {
36-
add_action( $hook, array( $this, 'run_hooks' ), $priority );
37-
add_action( $hook, array( $this, 'init_dependencies' ), $priority );
34+
\add_action( $hook, array( $this, 'run_hooks' ), $priority );
35+
\add_action( $hook, array( $this, 'init_dependencies' ), $priority );
3836
}
3937

4038
/**
@@ -55,24 +53,14 @@ public function run_hooks() {
5553
* Initializes the dependency dlasses
5654
*/
5755
public function init_dependencies() {
58-
$di_data = array();
59-
6056
foreach ( $this->get_dependencies() as $dep_class ) {
61-
$dep_data = $this->get_dependency_data( $dep_class );
57+
$dep = $this->get_dependency_data( $dep_class );
6258

63-
if ( ! $dep_data ) {
59+
if ( ! $dep || ! $dep['conditional']() ) {
6460
continue;
6561
}
6662

67-
$di_data[ $dep_data['hook'] ][ $dep_data['priority'] ][] = wp_array_slice_assoc( $dep_data, array( 'classname', 'conditional' ) );
68-
}
69-
70-
foreach ( $di_data as $hook => $priorities ) {
71-
ksort( $priorities );
72-
73-
foreach ( $priorities as $priority => $deps ) {
74-
add_action( $hook, fn() => $this->load_dependencies( $deps ), $priority );
75-
}
63+
\add_action( $dep['hook'], static fn() => new $dep_class(), $dep['priority'] );
7664
}
7765
}
7866

@@ -84,31 +72,12 @@ public function init_dependencies() {
8472
*/
8573
protected function get_dependency_data( string $dep_class ): ?array {
8674
$metadata = get_decorators( $dep_class, Hookable::class );
87-
$metadata = array_shift( $metadata );
75+
$metadata = \array_shift( $metadata );
8876

8977
return $metadata ? array(
78+
'conditional' => $metadata->conditional ?? '__return_true',
9079
'hook' => $metadata->hook,
9180
'priority' => $metadata->priority,
92-
'classname' => $dep_class,
93-
'conditional' => $metadata->conditional,
9481
) : null;
9582
}
96-
97-
98-
/**
99-
* Loads the dependencies
100-
*
101-
* @param array<string, callable|class-string> $deps Array of dependencies.
102-
*/
103-
protected function load_dependencies( array $deps ) {
104-
$deps = wp_list_pluck(
105-
array_filter(
106-
$deps,
107-
fn( $dep ) => $dep['conditional'](),
108-
),
109-
'classname'
110-
);
111-
112-
array_walk( $deps, fn( $d ) => new $d() );
113-
}
11483
}

src/Utils/oblak-wp-hook-utils.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,13 @@ function xwp_get_hooked_methods( object|string $obj, bool $all = false ): array
3939

4040
return array_filter(
4141
wp_array_flatmap(
42-
$methods,
4342
static fn( $m ) => array(
4443
$m->getName() => array(
4544
'args' => $m->getNumberOfParameters(),
4645
'hooks' => xwp_get_hook_decorators( $m ),
4746
),
4847
),
48+
$methods,
4949
),
5050
static fn( $m ) => $m['hooks']
5151
);

0 commit comments

Comments
 (0)