class-taxonomy-fields.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. /**
  3. * WPSEO plugin file.
  4. *
  5. * @package WPSEO\Admin
  6. */
  7. /**
  8. * Class WPSEO_Taxonomy_Tab.
  9. *
  10. * Contains the basics for each class extending this one.
  11. */
  12. abstract class WPSEO_Taxonomy_Fields {
  13. /**
  14. * The current term data.
  15. *
  16. * @var stdClass
  17. */
  18. protected $term;
  19. /**
  20. * Setting the class properties.
  21. *
  22. * @param stdClass $term The current term.
  23. */
  24. public function __construct( $term ) {
  25. $this->term = $term;
  26. }
  27. /**
  28. * This method should return the fields.
  29. *
  30. * @return array
  31. */
  32. abstract public function get();
  33. /**
  34. * Returns array with the field data.
  35. *
  36. * @param string $label The label displayed before the field.
  37. * @param string $description Description which will explain the field.
  38. * @param string $type The field type, for example: input, select.
  39. * @param string|array $options Optional. Array with additional options.
  40. * @param bool $hide Should the field be hidden.
  41. *
  42. * @return array
  43. */
  44. protected function get_field_config( $label, $description, $type = 'text', $options = '', $hide = false ) {
  45. return [
  46. 'label' => $label,
  47. 'description' => $description,
  48. 'type' => $type,
  49. 'options' => $options,
  50. 'hide' => $hide,
  51. ];
  52. }
  53. /**
  54. * Filter the hidden fields.
  55. *
  56. * @param array $fields Array with the form fields that has will be filtered.
  57. *
  58. * @return array
  59. */
  60. protected function filter_hidden_fields( array $fields ) {
  61. foreach ( $fields as $field_name => $field_options ) {
  62. if ( ! empty( $field_options['hide'] ) ) {
  63. unset( $fields[ $field_name ] );
  64. }
  65. }
  66. return $fields;
  67. }
  68. }