/admin/config-ui/fields/class-field-site-name.php

  1. <?php 
  2. /** 
  3. * @package WPSEO\Admin\ConfigurationUI 
  4. */ 
  5.  
  6. /** 
  7. * Class WPSEO_Config_Field_Site_Name 
  8. */ 
  9. class WPSEO_Config_Field_Site_Name extends WPSEO_Config_Field { 
  10.  
  11. /** 
  12. * WPSEO_Config_Field_Site_Name constructor. 
  13. */ 
  14. public function __construct() { 
  15. parent::__construct( 'siteName', 'Input' ); 
  16.  
  17. $this->set_property( 'label', __( 'Website name', 'wordpress-seo' ) ); 
  18. $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' ) ); 
  19.  
  20. /** 
  21. * Set adapter 
  22. * 
  23. * @param WPSEO_Configuration_Options_Adapter $adapter Adapter to register lookup on. 
  24. */ 
  25. public function set_adapter( WPSEO_Configuration_Options_Adapter $adapter ) { 
  26. $adapter->add_custom_lookup( 
  27. $this->get_identifier(),  
  28. array( $this, 'get_data' ),  
  29. array( $this, 'set_data' ) 
  30. ); } 
  31.  
  32. /** 
  33. * Get the data from the stored options. 
  34. * 
  35. * @return null|string 
  36. */ 
  37. public function get_data() { 
  38. $option = WPSEO_Options::get_option( 'wpseo' ); 
  39. if ( ! empty( $option['website_name'] ) ) { 
  40. return $option['website_name']; 
  41.  
  42. return get_bloginfo( 'name' ); 
  43.  
  44. /** 
  45. * Set the data in the options. 
  46. * 
  47. * @param {string} $data The data to set for the field. 
  48. * 
  49. * @return bool Returns true or false for successful storing the data. 
  50. */ 
  51. public function set_data( $data ) { 
  52. $value = $data; 
  53.  
  54. $option = WPSEO_Options::get_option( 'wpseo' ); 
  55. $option['website_name'] = $value; 
  56.  
  57. update_option( 'wpseo', $option ); 
  58.  
  59. // Check if everything got saved properly. 
  60. $saved_option = WPSEO_Options::get_option( 'wpseo' ); 
  61.  
  62. return ( $saved_option['website_name'] === $option['website_name'] ); 
.