'array', 'sanitize_callback' => array( $this, 'sanitize' ), 'default' => PulpitKit::default_settings(), ) ); add_settings_section( 'pulpitkit_church', __( 'Church', 'pulpitkit' ), '__return_null', 'pulpitkit' ); add_settings_field( 'church_name', __( 'Church Name', 'pulpitkit' ), array( $this, 'text_field' ), 'pulpitkit', 'pulpitkit_church', array( 'key' => 'church_name' ) ); add_settings_section( 'pulpitkit_podcast', __( 'Podcast', 'pulpitkit' ), array( $this, 'podcast_section_text' ), 'pulpitkit' ); add_settings_field( 'podcast_author', __( 'Podcast Author', 'pulpitkit' ), array( $this, 'text_field' ), 'pulpitkit', 'pulpitkit_podcast', array( 'key' => 'podcast_author' ) ); add_settings_field( 'podcast_email', __( 'Podcast Owner Email', 'pulpitkit' ), array( $this, 'text_field' ), 'pulpitkit', 'pulpitkit_podcast', array( 'key' => 'podcast_email', 'type' => 'email' ) ); add_settings_field( 'podcast_artwork', __( 'Podcast Artwork URL', 'pulpitkit' ), array( $this, 'artwork_field' ), 'pulpitkit', 'pulpitkit_podcast', array( 'key' => 'podcast_artwork' ) ); add_settings_field( 'podcast_description', __( 'Podcast Description', 'pulpitkit' ), array( $this, 'textarea_field' ), 'pulpitkit', 'pulpitkit_podcast', array( 'key' => 'podcast_description' ) ); add_settings_section( 'pulpitkit_live', __( 'Livestream & Services', 'pulpitkit' ), '__return_null', 'pulpitkit' ); add_settings_field( 'live_youtube_channel_id', __( 'YouTube Channel ID', 'pulpitkit' ), array( $this, 'text_field' ), 'pulpitkit', 'pulpitkit_live', array( 'key' => 'live_youtube_channel_id', 'help' => __( 'Enables the automatic "live stream" embed when your channel goes live.', 'pulpitkit' ) ) ); add_settings_field( 'live_youtube_url', __( 'YouTube Video / Live URL', 'pulpitkit' ), array( $this, 'text_field' ), 'pulpitkit', 'pulpitkit_live', array( 'key' => 'live_youtube_url', 'type' => 'url', 'help' => __( 'Optional: embed one specific video instead of the channel live embed.', 'pulpitkit' ) ) ); add_settings_field( 'live_facebook_url', __( 'Facebook Page / Live URL', 'pulpitkit' ), array( $this, 'text_field' ), 'pulpitkit', 'pulpitkit_live', array( 'key' => 'live_facebook_url', 'type' => 'url' ) ); add_settings_field( 'service_day', __( 'Main Service Day', 'pulpitkit' ), array( $this, 'service_day_field' ), 'pulpitkit', 'pulpitkit_live', array( 'key' => 'service_day' ) ); add_settings_field( 'service_time', __( 'Main Service Time', 'pulpitkit' ), array( $this, 'service_time_field' ), 'pulpitkit', 'pulpitkit_live', array( 'key' => 'service_time' ) ); add_settings_field( 'service_duration', __( 'Service Length (minutes)', 'pulpitkit' ), array( $this, 'number_field' ), 'pulpitkit', 'pulpitkit_live', array( 'key' => 'service_duration' ) ); add_settings_field( 'live_window_before', __( 'Show "Live" Starting (minutes before)', 'pulpitkit' ), array( $this, 'number_field' ), 'pulpitkit', 'pulpitkit_live', array( 'key' => 'live_window_before' ) ); } /** * Podcast section intro — includes the feed URL churches paste into podcast apps. */ public function podcast_section_text() { printf( '

%s

%s %s

', esc_html__( 'Sermons with audio automatically appear in your podcast feed. Apple Podcasts and Spotify require a square artwork image of at least 1400×1400 px.', 'pulpitkit' ), esc_html__( 'Your podcast feed URL:', 'pulpitkit' ), esc_html( PulpitKit_Podcast::feed_url() ) ); } /** * Current value helper. * * @param string $key Setting key. * @return mixed */ private function value( $key ) { return PulpitKit::get_setting( $key, '' ); } /** * Generic text input field. * * @param array $args Field args (key, optional type, optional help). */ public function text_field( $args ) { $key = $args['key']; $type = isset( $args['type'] ) ? $args['type'] : 'text'; printf( '', esc_attr( $type ), esc_attr( self::OPTION ), esc_attr( $key ), esc_attr( (string) $this->value( $key ) ) ); if ( ! empty( $args['help'] ) ) { printf( '

%s

', esc_html( $args['help'] ) ); } } /** * Number input field. * * @param array $args Field args. */ public function number_field( $args ) { $key = $args['key']; printf( '', esc_attr( self::OPTION ), esc_attr( $key ), esc_attr( (string) (int) $this->value( $key ) ) ); } /** * Textarea field. * * @param array $args Field args. */ public function textarea_field( $args ) { $key = $args['key']; printf( '', esc_attr( self::OPTION ), esc_attr( $key ), esc_textarea( (string) $this->value( $key ) ) ); } /** * Artwork URL field with media-picker button. * * @param array $args Field args. */ public function artwork_field( $args ) { $key = $args['key']; printf( ' ', esc_attr( self::OPTION ), esc_attr( $key ), esc_url( (string) $this->value( $key ) ) ); printf( '', esc_attr( $key ), esc_html__( 'Select from Media Library', 'pulpitkit' ) ); } /** * Weekday select field. * * @param array $args Field args. */ public function service_day_field( $args ) { $key = $args['key']; $current = (int) $this->value( $key ); $weekdays = array( 0 => __( 'Sunday', 'pulpitkit' ), 1 => __( 'Monday', 'pulpitkit' ), 2 => __( 'Tuesday', 'pulpitkit' ), 3 => __( 'Wednesday', 'pulpitkit' ), 4 => __( 'Thursday', 'pulpitkit' ), 5 => __( 'Friday', 'pulpitkit' ), 6 => __( 'Saturday', 'pulpitkit' ), ); printf( ''; } /** * Time input field. * * @param array $args Field args. */ public function service_time_field( $args ) { $key = $args['key']; printf( '', esc_attr( self::OPTION ), esc_attr( $key ), esc_attr( (string) $this->value( $key ) ) ); } /** * Sanitize all settings on save. * * @param mixed $input Raw submitted settings. * @return array Sanitized settings. */ public function sanitize( $input ) { $input = is_array( $input ) ? $input : array(); $clean = PulpitKit::default_settings(); $clean['church_name'] = isset( $input['church_name'] ) ? sanitize_text_field( wp_unslash( $input['church_name'] ) ) : ''; $clean['podcast_author'] = isset( $input['podcast_author'] ) ? sanitize_text_field( wp_unslash( $input['podcast_author'] ) ) : ''; $clean['podcast_email'] = isset( $input['podcast_email'] ) ? sanitize_email( wp_unslash( $input['podcast_email'] ) ) : ''; $clean['podcast_artwork'] = isset( $input['podcast_artwork'] ) ? esc_url_raw( wp_unslash( $input['podcast_artwork'] ) ) : ''; $clean['podcast_description'] = isset( $input['podcast_description'] ) ? sanitize_textarea_field( wp_unslash( $input['podcast_description'] ) ) : ''; $clean['live_youtube_channel_id'] = isset( $input['live_youtube_channel_id'] ) ? sanitize_text_field( wp_unslash( $input['live_youtube_channel_id'] ) ) : ''; $clean['live_youtube_url'] = isset( $input['live_youtube_url'] ) ? esc_url_raw( wp_unslash( $input['live_youtube_url'] ) ) : ''; $clean['live_facebook_url'] = isset( $input['live_facebook_url'] ) ? esc_url_raw( wp_unslash( $input['live_facebook_url'] ) ) : ''; $day = isset( $input['service_day'] ) ? absint( $input['service_day'] ) : 0; $clean['service_day'] = $day <= 6 ? $day : 0; $time = isset( $input['service_time'] ) ? sanitize_text_field( wp_unslash( $input['service_time'] ) ) : '10:30'; $clean['service_time'] = preg_match( '/^([01]\d|2[0-3]):[0-5]\d$/', $time ) ? $time : '10:30'; $clean['service_duration'] = isset( $input['service_duration'] ) ? max( 1, absint( $input['service_duration'] ) ) : 90; $clean['live_window_before'] = isset( $input['live_window_before'] ) ? absint( $input['live_window_before'] ) : 15; return $clean; } /** * Render the settings page. */ public function render_page() { if ( ! current_user_can( 'manage_options' ) ) { wp_die( esc_html__( 'You do not have permission to access this page.', 'pulpitkit' ) ); } ?>