class-configuration-components.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. /**
  3. * WPSEO plugin file.
  4. *
  5. * @package WPSEO\Admin\ConfigurationUI
  6. */
  7. /**
  8. * Class WPSEO_Configuration_Components
  9. */
  10. class WPSEO_Configuration_Components {
  11. /** @var WPSEO_Config_Component[] List of registered components */
  12. protected $components = array();
  13. /** @var WPSEO_Configuration_Options_Adapter Adapter */
  14. protected $adapter;
  15. /**
  16. * Add default components.
  17. */
  18. public function initialize() {
  19. $this->add_component( new WPSEO_Config_Component_Connect_Google_Search_Console() );
  20. $this->add_component( new WPSEO_Config_Component_Mailchimp_Signup() );
  21. $this->add_component( new WPSEO_Config_Component_Configuration_Choices() );
  22. $this->add_component( new WPSEO_Config_Component_Suggestions() );
  23. }
  24. /**
  25. * Add a component
  26. *
  27. * @param WPSEO_Config_Component $component Component to add.
  28. */
  29. public function add_component( WPSEO_Config_Component $component ) {
  30. $this->components[] = $component;
  31. }
  32. /**
  33. * Sets the storage to use.
  34. *
  35. * @param WPSEO_Configuration_Storage $storage Storage to use.
  36. */
  37. public function set_storage( WPSEO_Configuration_Storage $storage ) {
  38. $this->set_adapter( $storage->get_adapter() );
  39. foreach ( $this->components as $component ) {
  40. $storage->add_field( $component->get_field() );
  41. }
  42. }
  43. /**
  44. * Sets the adapter to use.
  45. *
  46. * @param WPSEO_Configuration_Options_Adapter $adapter Adapter to use.
  47. */
  48. public function set_adapter( WPSEO_Configuration_Options_Adapter $adapter ) {
  49. $this->adapter = $adapter;
  50. foreach ( $this->components as $component ) {
  51. $adapter->add_custom_lookup(
  52. $component->get_field()->get_identifier(),
  53. array(
  54. $component,
  55. 'get_data',
  56. ),
  57. array(
  58. $component,
  59. 'set_data',
  60. )
  61. );
  62. }
  63. }
  64. }