class-field-site-name.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. /**
  3. * WPSEO plugin file.
  4. *
  5. * @package WPSEO\Admin\ConfigurationUI
  6. */
  7. /**
  8. * Class WPSEO_Config_Field_Site_Name.
  9. */
  10. class WPSEO_Config_Field_Site_Name extends WPSEO_Config_Field {
  11. /**
  12. * WPSEO_Config_Field_Site_Name constructor.
  13. */
  14. public function __construct() {
  15. parent::__construct( 'siteName', 'Input' );
  16. $this->set_property( 'label', __( 'Website name', 'wordpress-seo' ) );
  17. $this->set_property( 'explanation', __( 'Google shows your website\'s name in the search results, if you want to change it, you can do that here.', 'wordpress-seo' ) );
  18. }
  19. /**
  20. * Set adapter.
  21. *
  22. * @param WPSEO_Configuration_Options_Adapter $adapter Adapter to register lookup on.
  23. */
  24. public function set_adapter( WPSEO_Configuration_Options_Adapter $adapter ) {
  25. $adapter->add_custom_lookup(
  26. $this->get_identifier(),
  27. [ $this, 'get_data' ],
  28. [ $this, 'set_data' ]
  29. );
  30. }
  31. /**
  32. * Get the data from the stored options.
  33. *
  34. * @return null|string
  35. */
  36. public function get_data() {
  37. if ( WPSEO_Options::get( 'website_name', false ) ) {
  38. return WPSEO_Options::get( 'website_name' );
  39. }
  40. return get_bloginfo( 'name' );
  41. }
  42. /**
  43. * Set the data in the options.
  44. *
  45. * @param string $data The data to set for the field.
  46. *
  47. * @return bool Returns true or false for successful storing the data.
  48. */
  49. public function set_data( $data ) {
  50. return WPSEO_Options::set( 'website_name', $data );
  51. }
  52. }