class-configuration-components.php
1.53 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<?php
/**
* @package WPSEO\Admin\ConfigurationUI
*/
/**
* Class WPSEO_Configuration_Components
*/
class WPSEO_Configuration_Components {
/** @var WPSEO_Config_Component[] List of registered components */
protected $components = array();
/** @var WPSEO_Configuration_Options_Adapter Adapter */
protected $adapter;
/**
* Add default components.
*/
public function initialize() {
$this->add_component( new WPSEO_Config_Component_Connect_Google_Search_Console() );
$this->add_component( new WPSEO_Config_Component_Mailchimp_Signup() );
}
/**
* Add a component
*
* @param WPSEO_Config_Component $component Component to add.
*/
public function add_component( WPSEO_Config_Component $component ) {
$this->components[] = $component;
}
/**
* Sets the storage to use.
*
* @param WPSEO_Configuration_Storage $storage Storage to use.
*/
public function set_storage( WPSEO_Configuration_Storage $storage ) {
$this->set_adapter( $storage->get_adapter() );
foreach ( $this->components as $component ) {
$storage->add_field( $component->get_field() );
}
}
/**
* Sets the adapter to use.
*
* @param WPSEO_Configuration_Options_Adapter $adapter Adapter to use.
*/
public function set_adapter( WPSEO_Configuration_Options_Adapter $adapter ) {
$this->adapter = $adapter;
foreach ( $this->components as $component ) {
$adapter->add_custom_lookup(
$component->get_field()->get_identifier(),
array(
$component,
'get_data',
),
array(
$component,
'set_data',
)
);
}
}
}