class-option-tab.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <?php
  2. /**
  3. * WPSEO plugin file.
  4. *
  5. * @package WPSEO\Admin\Options\Tabs
  6. */
  7. /**
  8. * Class WPSEO_Option_Tab.
  9. */
  10. class WPSEO_Option_Tab {
  11. /**
  12. * Name of the tab.
  13. *
  14. * @var string
  15. */
  16. private $name;
  17. /**
  18. * Label of the tab.
  19. *
  20. * @var string
  21. */
  22. private $label;
  23. /**
  24. * Optional arguments.
  25. *
  26. * @var array
  27. */
  28. private $arguments;
  29. /**
  30. * WPSEO_Option_Tab constructor.
  31. *
  32. * @param string $name Name of the tab.
  33. * @param string $label Localized label of the tab.
  34. * @param array $arguments Optional arguments.
  35. */
  36. public function __construct( $name, $label, array $arguments = [] ) {
  37. $this->name = sanitize_title( $name );
  38. $this->label = $label;
  39. $this->arguments = $arguments;
  40. }
  41. /**
  42. * Gets the name.
  43. *
  44. * @return string The name.
  45. */
  46. public function get_name() {
  47. return $this->name;
  48. }
  49. /**
  50. * Gets the label.
  51. *
  52. * @return string The label.
  53. */
  54. public function get_label() {
  55. return $this->label;
  56. }
  57. /**
  58. * Retrieves whether the tab needs a save button.
  59. *
  60. * @return bool True whether the tabs needs a save button.
  61. */
  62. public function has_save_button() {
  63. return (bool) $this->get_argument( 'save_button', true );
  64. }
  65. /**
  66. * Gets the option group.
  67. *
  68. * @return string The option group.
  69. */
  70. public function get_opt_group() {
  71. return $this->get_argument( 'opt_group' );
  72. }
  73. /**
  74. * Retrieves the variable from the supplied arguments.
  75. *
  76. * @param string $variable Variable to retrieve.
  77. * @param string|mixed $default Default to use when variable not found.
  78. *
  79. * @return mixed|string The retrieved variable.
  80. */
  81. protected function get_argument( $variable, $default = '' ) {
  82. return array_key_exists( $variable, $this->arguments ) ? $this->arguments[ $variable ] : $default;
  83. }
  84. }