WPSEO_Config_Field_Multiple_Authors

Class WPSEO_Config_Field_Multiple_Authors.

Defined (1)

The class is defined in the following location(s).

/admin/config-ui/fields/class-field-multiple-authors.php  
  1. class WPSEO_Config_Field_Multiple_Authors extends WPSEO_Config_Field_Choice { 
  2. /** 
  3. * WPSEO_Config_Field_Multiple_Authors constructor. 
  4. */ 
  5. public function __construct() { 
  6. parent::__construct( 'multipleAuthors' ); 
  7.  
  8. $this->set_property( 'label', __( 'Does, or will, your site have multiple authors?', 'wordpress-seo' ) ); 
  9.  
  10. $this->add_choice( 'yes', __( 'Yes', 'wordpress-seo' ) ); 
  11. $this->add_choice( 'no', __( 'No', 'wordpress-seo' ) ); 
  12.  
  13. /** 
  14. * Set adapter. 
  15. * @param WPSEO_Configuration_Options_Adapter $adapter Adapter to register lookup on. 
  16. */ 
  17. public function set_adapter( WPSEO_Configuration_Options_Adapter $adapter ) { 
  18. $adapter->add_custom_lookup( 
  19. $this->get_identifier(),  
  20. array( $this, 'get_data' ),  
  21. array( $this, 'set_data' ) 
  22. ); 
  23.  
  24. /** 
  25. * Get the data from the stored options. 
  26. * @return null|string 
  27. */ 
  28. public function get_data() { 
  29.  
  30. $option = WPSEO_Options::get_option( 'wpseo' ); 
  31. if ( isset( $option['has_multiple_authors'] ) ) { 
  32. $value = $option['has_multiple_authors']; 
  33.  
  34. if ( ! isset( $value ) || is_null( $value ) ) { 
  35. // If there are more than one users with level > 1 default to multiple authors. 
  36. $users = get_users( array( 
  37. 'fields' => 'IDs',  
  38. 'who' => 'authors',  
  39. ) ); 
  40.  
  41. $value = count( $users ) > 1; 
  42.  
  43. return ( $value ) ? 'yes' : 'no'; 
  44.  
  45. /** 
  46. * Set the data in the options. 
  47. * @param {string} $data The data to set for the field. 
  48. * @return bool Returns true or false for successful storing the data. 
  49. */ 
  50. public function set_data( $data ) { 
  51. $value = ( $data === 'yes' ); 
  52.  
  53. // Set multiple authors option. 
  54. $result_multiple_authors = WPSEO_Options::save_option( 'wpseo', 'has_multiple_authors', $value ); 
  55.  
  56. /** 
  57. * Set disable author archives option. When multiple authors is set to true,  
  58. * the disable author option has to be false. Because of this the $value is inversed. 
  59. */ 
  60. $result_author_archives = WPSEO_Options::save_option( 'wpseo_titles', 'disable-author', ! $value ); 
  61.  
  62. return ( $result_multiple_authors === true && $result_author_archives === true );