SimpleCalendarAdminPagesCalendars

Calendar settings.

Defined (1)

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

/includes/admin/pages/calendars.php  
  1. class Calendars extends Admin_Page { 
  2.  
  3. /** 
  4. * Calendar Types. 
  5. * @access private 
  6. * @var array 
  7. */ 
  8. private $calendar_types = array(); 
  9.  
  10. /** 
  11. * Constructor. 
  12. * @since 3.0.0 
  13. */ 
  14. public function __construct() { 
  15.  
  16. $this->id = 'calendars'; 
  17. $this->option_group = 'settings'; 
  18. $this->label = __( 'Calendars', 'google-calendar-events' ); 
  19. //$this->description = __( 'Manage calendar preferences and calendar types settings and options.', 'google-calendar-events' ); 
  20.  
  21. $calendars = simcal_get_calendar_types(); 
  22. $calendar_settings = array(); 
  23. if ( ! empty( $calendars ) && is_array( $calendars ) ) { 
  24. foreach ( $calendars as $calendar => $views ) { 
  25.  
  26. $calendar_type = simcal_get_calendar( $calendar ); 
  27.  
  28. if ( $calendar_type instanceof Calendar ) { 
  29. $settings = $calendar_type->settings_fields(); 
  30. if ( ! empty( $settings ) ) { 
  31. $calendar_settings[ $calendar ] = $settings; 
  32.  
  33. $this->calendar_types = $calendar_settings; 
  34. $this->sections = $this->add_sections(); 
  35. $this->fields = $this->add_fields(); 
  36.  
  37. /** 
  38. * Add sections. 
  39. * @since 3.0.0 
  40. * @return array 
  41. */ 
  42. public function add_sections() { 
  43.  
  44. $sections = array( 
  45. 'general' => array( 
  46. 'title' => __( 'General', 'google-calendar-events' ),  
  47. 'description' => '',  
  48. ),  
  49. ); 
  50.  
  51. $calendar_types = $this->calendar_types; 
  52.  
  53. if ( ! empty( $calendar_types ) && is_array( $calendar_types ) ) { 
  54. foreach ( $calendar_types as $calendar_type => $type ) { 
  55.  
  56. $sections[ $calendar_type ] = array( 
  57. 'title' => $type['name'],  
  58. 'description' => $type['description'],  
  59. ); 
  60.  
  61.  
  62. arsort( $calendar_types ); 
  63.  
  64. return apply_filters( 'simcal_add_' . $this->option_group . '_' . $this->id .'_sections', $sections ); 
  65.  
  66. /** 
  67. * Add fields. 
  68. * @since 3.0.0 
  69. * @return array 
  70. */ 
  71. public function add_fields() { 
  72.  
  73. $fields = array(); 
  74. $feed_types = $this->calendar_types; 
  75. $this->values = get_option( 'simple-calendar_' . $this->option_group . '_' . $this->id ); 
  76.  
  77. foreach ( $this->sections as $section => $contents ) : 
  78.  
  79. if ( 'general' == $section ) { 
  80.  
  81. $options = array(); 
  82. $post_types = get_post_types( 
  83. array( 
  84. 'public' => false,  
  85. 'publicly_queriable' => false,  
  86. 'show_ui' => false,  
  87. ),  
  88. 'objects',  
  89. 'not' 
  90. ); 
  91. unset( $post_types['attachment'] ); 
  92. unset( $post_types['calendar'] ); 
  93. unset( $post_types['gce_feed'] ); 
  94. foreach ( $post_types as $slug => $post_type ) { 
  95. $options[ $slug ] = $post_type->label; 
  96. asort( $options ); 
  97.  
  98. $fields[ $section ][] = array( 
  99. 'type' => 'select',  
  100. 'multiselect' => 'multiselect',  
  101. 'enhanced' => 'enhanced',  
  102. 'title' => __( 'Attach Calendars', 'google-calendar-events' ),  
  103. 'tooltip' => __( 'You can choose on which content types to add the ability to attach calendars.', 'google-calendar-events' ),  
  104. 'name' => 'simple-calendar_' . $this->option_group . '_' . $this->id . '[' . $section . '][attach_calendars_posts]',  
  105. 'id' => 'simple-calendar-' . $this->option_group . '-' . $this->id . '-attach-calendars-posts',  
  106. 'value' => $this->get_option_value( $section, 'attach_calendars_posts' ),  
  107. 'default' => 'post, page',  
  108. 'options' => $options,  
  109. ); 
  110.  
  111. } elseif ( isset( $feed_types[ $section ]['fields'] ) ) { 
  112.  
  113. foreach ( $feed_types[ $section ]['fields'] as $key => $args ) { 
  114.  
  115. $fields[ $section ][] = array_merge( $args, array( 
  116. 'name' => 'simple-calendar_' . $this->option_group . '_' . $this->id . '[' . $section . '][' . $key . ']',  
  117. 'id' => 'simple-calendar-' . $this->option_group . '-' . $this->id . '-' . $key,  
  118. 'value' => $this->get_option_value( $section, $key ) 
  119. ) ); 
  120.  
  121.  
  122.  
  123. endforeach; 
  124.  
  125. return apply_filters( 'simcal_add_' . $this->option_group . '_' . $this->id . '_fields', $fields ); 
  126.