init_hooks(); } return self::$instance; } /** * Register global hooks and instantiate subsystems. */ private function init_hooks() { add_action( 'init', array( 'PulpitKit_Post_Types', 'register_post_types' ) ); add_action( 'init', array( 'PulpitKit_Post_Types', 'register_taxonomies' ) ); add_action( 'init', array( 'PulpitKit_Podcast', 'register_feed' ) ); add_action( 'init', array( $this, 'register_blocks' ) ); add_action( 'admin_enqueue_scripts', array( $this, 'admin_assets' ) ); add_action( 'enqueue_block_editor_assets', array( $this, 'block_editor_assets' ) ); new PulpitKit_Post_Types(); new PulpitKit_Shortcodes(); new PulpitKit_Settings(); new PulpitKit_Importer(); } /** * Enqueue admin assets (media-picker helper) on relevant screens only. * * @param string $hook Current admin page hook. */ public function admin_assets( $hook ) { $screen = function_exists( 'get_current_screen' ) ? get_current_screen() : null; $ours = array( 'settings_page_pulpitkit', 'tools_page_pulpitkit-import' ); if ( in_array( $hook, $ours, true ) || ( $screen && in_array( $screen->post_type, array( 'pulpitkit_sermon', 'pulpitkit_event' ), true ) ) ) { wp_enqueue_media(); wp_enqueue_script( 'pulpitkit-admin', PULPITKIT_URL . 'assets/js/pulpitkit-admin.js', array( 'jquery' ), PULPITKIT_VERSION, true ); } } /** * Enqueue block editor script. */ public function block_editor_assets() { wp_enqueue_script( 'pulpitkit-blocks', PULPITKIT_URL . 'assets/js/pulpitkit-blocks.js', array( 'wp-blocks', 'wp-element', 'wp-components', 'wp-server-side-render', 'wp-block-editor' ), PULPITKIT_VERSION, false ); } /** * Register server-rendered blocks that mirror the shortcodes. */ public function register_blocks() { if ( ! function_exists( 'register_block_type' ) ) { return; } $shortcodes = new PulpitKit_Shortcodes(); register_block_type( 'pulpitkit/sermons', array( 'editor_script' => 'pulpitkit-blocks', 'render_callback' => array( $shortcodes, 'render_sermons' ), 'attributes' => array( 'limit' => array( 'type' => 'number', 'default' => 10 ), 'series' => array( 'type' => 'string', 'default' => '' ), 'speaker' => array( 'type' => 'string', 'default' => '' ), ), ) ); register_block_type( 'pulpitkit/events', array( 'editor_script' => 'pulpitkit-blocks', 'render_callback' => array( $shortcodes, 'render_events' ), 'attributes' => array( 'limit' => array( 'type' => 'number', 'default' => 5 ), ), ) ); register_block_type( 'pulpitkit/live', array( 'editor_script' => 'pulpitkit-blocks', 'render_callback' => array( $shortcodes, 'render_live' ), 'attributes' => array(), ) ); } /** * Default plugin settings. * * @return array */ public static function default_settings() { return array( 'church_name' => get_bloginfo( 'name' ), 'podcast_author' => get_bloginfo( 'name' ), 'podcast_email' => get_bloginfo( 'admin_email' ), 'podcast_artwork' => '', 'podcast_description' => get_bloginfo( 'description' ), 'live_youtube_channel_id' => '', 'live_youtube_url' => '', 'live_facebook_url' => '', 'service_day' => 0, // Sunday. 'service_time' => '10:30', 'service_duration' => 90, // Minutes. 'live_window_before' => 15, // Minutes before start to show "live soon/live". ); } /** * Fetch a single setting with fallback to defaults. * * @param string $key Setting key. * @param mixed $default Fallback when unset. * @return mixed */ public static function get_setting( $key, $default = '' ) { $settings = get_option( 'pulpitkit_settings', array() ); $defaults = self::default_settings(); if ( isset( $settings[ $key ] ) && '' !== $settings[ $key ] ) { return $settings[ $key ]; } if ( array_key_exists( $key, $defaults ) ) { return $defaults[ $key ]; } return $default; } /** * Enqueue the plugin's self-contained front-end styles. * Safe to call from shortcode callbacks (WP prints late styles in footer). */ public static function enqueue_styles() { wp_enqueue_style( 'pulpitkit', PULPITKIT_URL . 'assets/css/pulpitkit.css', array(), PULPITKIT_VERSION ); } }