SimpleCalendarAbstractsAdmin_Page

The Admin Page.

Defined (1)

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

/includes/abstracts/admin-page.php  
  1. abstract class Admin_Page { 
  2.  
  3. /** 
  4. * Admin page ID. 
  5. * @access public 
  6. * @var string 
  7. */ 
  8. public $id = ''; 
  9.  
  10. /** 
  11. * Option group. 
  12. * @access public 
  13. * @var string 
  14. */ 
  15. public $option_group = ''; 
  16.  
  17. /** 
  18. * Admin Page label. 
  19. * @access public 
  20. * @var string 
  21. */ 
  22. public $label = ''; 
  23.  
  24. /** 
  25. * Admin Page description. 
  26. * @access public 
  27. * @var string 
  28. */ 
  29. public $description = ''; 
  30.  
  31. /** 
  32. * Amdin Page settings sections. 
  33. * @access public 
  34. * @var array Associative array with section id (key) and section name (value) 
  35. */ 
  36. public $sections; 
  37.  
  38. /** 
  39. * Admin Page settings fields. 
  40. * @access public 
  41. * @var array 
  42. */ 
  43. public $fields; 
  44.  
  45. /** 
  46. * Saved values. 
  47. * @access protected 
  48. * @var array 
  49. */ 
  50. protected $values = array(); 
  51.  
  52. /** 
  53. * Get admin page settings. 
  54. * @since 3.0.0 
  55. * @return array 
  56. */ 
  57. public function get_settings() { 
  58.  
  59. $settings = array(); 
  60.  
  61. $settings[ $this->id ] = array( 
  62. 'label' => $this->label,  
  63. 'description' => $this->description,  
  64. ); 
  65.  
  66. if ( ! empty( $this->sections ) && is_array( $this->sections ) ) { 
  67.  
  68. foreach ( $this->sections as $section => $content ) { 
  69.  
  70. $settings[ $this->id ]['sections'][ $section ] = array( 
  71. 'title' => isset( $content['title'] ) ? $content['title'] : '',  
  72. 'description' => isset( $content['description'] ) ? $content['description'] : '',  
  73. 'callback' => array( $this, 'add_settings_section_callback' ),  
  74. 'fields' => isset( $this->fields[ $section ] ) ? $this->fields[ $section ] : '',  
  75. ); 
  76.  
  77.  
  78.  
  79. return apply_filters( 'simcal_get_' . $this->option_group . '_' . $this->id , $settings ); 
  80.  
  81. /** 
  82. * Get option value. 
  83. * @since 3.0.0 
  84. * @access protected 
  85. * @param string $section 
  86. * @param string $setting 
  87. * @return string 
  88. */ 
  89. protected function get_option_value( $section, $setting ) { 
  90.  
  91. $option = $this->values; 
  92.  
  93. if ( ! empty( $option ) && is_array( $option ) ) { 
  94. return isset( $option[ $section ][ $setting ] ) ? $option[ $section ][ $setting ] : ''; 
  95.  
  96. return ''; 
  97.  
  98. /** 
  99. * Add sections for this page. 
  100. * @since 3.0.0 
  101. * @return array 
  102. */ 
  103. abstract public function add_sections(); 
  104.  
  105. /** 
  106. * Get settings fields. 
  107. * @since 3.0.0 
  108. * @return array 
  109. */ 
  110. abstract public function add_fields(); 
  111.  
  112. /** 
  113. * Default basic callback for page sections. 
  114. * @since 3.0.0 
  115. * @param array $section 
  116. * @return string 
  117. */ 
  118. public function add_settings_section_callback( $section ) { 
  119.  
  120. $callback = isset( $section['callback'][0] ) ? $section['callback'][0] : ''; 
  121. $sections = isset( $callback->sections ) ? $callback->sections : ''; 
  122. $description = isset( $sections[ $section['id'] ]['description'] ) ? $sections[ $section['id'] ]['description'] : ''; 
  123. $default = $description ? '<p>' . $description . '</p>' : ''; 
  124.  
  125. echo apply_filters( 'simcal_' . $this->option_group . '_' . $this->id . '_sections_callback', $default ); 
  126.  
  127. /** 
  128. * Register setting callback. 
  129. * Callback function for sanitizing and validating options before they are updated. 
  130. * @since 3.0.0 
  131. * @param array $settings Settings inputs. 
  132. * @return array Sanitized settings. 
  133. */ 
  134. public function validate( $settings ) { 
  135.  
  136. $sanitized = ''; 
  137.  
  138. if ( is_array( $settings ) ) { 
  139. foreach ( $settings as $k => $v ) { 
  140. $sanitized[ $k ] = simcal_sanitize_input( $v ); 
  141. } else { 
  142. $sanitized = simcal_sanitize_input( $settings ); 
  143.  
  144. return $sanitized; 
  145.