class-field-choice.php 937 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. <?php
  2. /**
  3. * WPSEO plugin file.
  4. *
  5. * @package WPSEO\Admin\ConfigurationUI
  6. */
  7. /**
  8. * Class WPSEO_Config_Field_Choice
  9. */
  10. class WPSEO_Config_Field_Choice extends WPSEO_Config_Field {
  11. /**
  12. * WPSEO_Config_Field_Choice constructor.
  13. *
  14. * @param string $field Field name to use.
  15. */
  16. public function __construct( $field ) {
  17. parent::__construct( $field, 'Choice' );
  18. $this->properties['choices'] = array();
  19. }
  20. /**
  21. * Add a choice to the properties
  22. *
  23. * @param string $value Value op the option.
  24. * @param string $label Label to display for the value.
  25. * @param string $screen_reader_text Optional. Screenreader text to use.
  26. */
  27. public function add_choice( $value, $label, $screen_reader_text = '' ) {
  28. $choice = array(
  29. 'label' => $label,
  30. );
  31. if ( $screen_reader_text ) {
  32. $choice['screenReaderText'] = $screen_reader_text;
  33. }
  34. $this->properties['choices'][ $value ] = $choice;
  35. }
  36. }