Hooks.php
1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<?php
namespace WPML\PB\Config;
use function WPML\FP\tap as tap;
class Hooks implements \IWPML_Action {
const PRIORITY_AFTER_DEFAULT = 20;
/** @var Parser $parser */
private $parser;
/** @var Storage $storage */
private $storage;
/** @var string $translatableWidgetsHook */
private $translatableWidgetsHook;
public function __construct(
Parser $parser,
Storage $storage,
$translatableWidgetsHook
) {
$this->parser = $parser;
$this->storage = $storage;
$this->translatableWidgetsHook = $translatableWidgetsHook;
}
public function add_hooks() {
add_filter( 'wpml_config_array', tap( [ $this, 'extractConfig' ] ) );
add_filter( $this->translatableWidgetsHook , [ $this, 'extendTranslatableWidgets' ], self::PRIORITY_AFTER_DEFAULT );
}
public function extractConfig( array $allConfig ) {
$this->storage->update( $this->parser->extract( $allConfig ) );
}
/**
* @param array $widgets
*
* @return array
*/
public function extendTranslatableWidgets( array $widgets ) {
return array_merge( $widgets, $this->storage->get() );
}
}