add_rewrite_rules(); } flush_rewrite_rules(); } /** * Enqueue admin assets. */ public function enqueue_assets( string $hook ) : void { $allowed_hooks = [ 'toplevel_page_webcalendar', 'webcalendar_page_webcalendar-categories', 'webcalendar_page_webcalendar-remote', 'webcalendar_page_webcalendar-holidays', 'webcalendar_page_webcalendar-shared', 'webcalendar_page_webcalendar-layers', 'webcalendar_page_webcalendar-submissions', 'webcalendar_page_webcalendar-places', 'webcalendar_page_webcalendar-extra-fields' ]; if ( !in_array( $hook, $allowed_hooks, true ) ) { return; } wp_enqueue_media(); $asset_file = WEBCALENDAR_WP_PATH . 'build/index.asset.php'; if ( !file_exists( $asset_file ) ) { return; } $assets = (require $asset_file); wp_enqueue_script( 'webcalendar-admin', WEBCALENDAR_WP_URL . 'build/index.js', $assets['dependencies'], $assets['version'], true ); // The admin bundle carries the bulk of the plugin's translatable JS. // Without this, WordPress never loads the JSON catalogue for it and // every __() in the React admin stays in English. wp_set_script_translations( 'webcalendar-admin', 'agenticdaisy-calendar', WEBCALENDAR_WP_PATH . 'languages' ); // Build layer data for admin color matching (mirrors Plugin.php frontend logic) $layers_data = []; if ( is_user_logged_in() ) { $layer_service = \WebCalendar\WP\Container::get_instance()->get_layer_service(); $layers = $layer_service->getLayersForUser( wp_get_current_user()->user_login ); foreach ( $layers as $layer ) { $layer_name = $layer->layerUser(); $wp_layer_user = get_user_by( 'login', $layer->layerUser() ); if ( $wp_layer_user ) { $layer_name = $wp_layer_user->display_name; } else { $resource_repo = \WebCalendar\WP\Container::get_instance()->get_resource_repository(); $resource = $resource_repo->findByLogin( $layer->layerUser() ); if ( $resource !== null ) { $layer_name = $resource->name(); } } $layers_data[] = [ 'layerUser' => $layer->layerUser(), 'color' => $layer->color(), 'showDuplicates' => $layer->showDuplicates(), 'name' => $layer_name, ]; } } wp_localize_script( 'webcalendar-admin', 'webcalApiSettings', [ 'root' => esc_url_raw( rest_url() ), 'nonce' => wp_create_nonce( 'wp_rest' ), 'timeFormat' => webcal_time_format(), 'dateFormat' => webcal_date_format(), 'startOfWeek' => $this->start_of_week(), 'mapProvider' => get_option( 'webcal_map_provider', 'osm' ), 'googleMapsApiKey' => get_option( 'webcal_google_maps_api_key', '' ), 'currentUser' => wp_get_current_user()->user_login, 'canEditOthers' => current_user_can( 'webcal_can_edit_others' ), 'licenseTier' => \WebCalendar\WP\Container::get_instance()->get_license()->get_tier(), 'upgradeUrl' => esc_url_raw( $this->get_upgrade_url() ), 'layers' => $layers_data, 'features' => webcal_feature_flags(), ] ); // wp-components is declared as a dependency rather than merely enqueued, // so WordPress loads it before our overrides. // // The React admin is built from @wordpress/components, and listing // wp-components among the *script* dependencies does not load its // stylesheet. WordPress 7.x enqueues that stylesheet by itself, which // is why this was invisible: on 6.6 -- the version this plugin declares // as its minimum -- it is registered and never enqueued, so every // component renders unstyled. The event editor is the visible casualty: // .components-modal__screen-overlay falls back to position: static and // lays out in document flow instead of covering the viewport, leaving // the admin menu (z-index: 9990) painted over the modal. wp_enqueue_style( 'webcalendar-admin', WEBCALENDAR_WP_URL . 'build/index.css', ['wp-components'], $assets['version'] ); // Premium admin bundles. Each built file is stripped from the free build // via @fs_premium_only, so enqueue_premium_bundle() no-ops there. $premium_admin = [ 'webcalendar_page_webcalendar-remote' => 'premium-remote-calendars', 'webcalendar_page_webcalendar-submissions' => 'premium-submissions', ]; if ( isset( $premium_admin[$hook] ) ) { $this->enqueue_premium_bundle( $premium_admin[$hook] ); } } /** * Enqueue a premium UI bundle if it exists in this build. * * Premium bundles (build/premium-*.js) are stripped from the auto-generated * free build via the @fs_premium_only header, so file_exists() is false * there and nothing is enqueued. The bundle depends on webcalendar-admin so * React, webcalApiSettings, and apiFetch middleware are already available. * * @param string $name Bundle base name, e.g. "premium-remote-calendars". */ private function enqueue_premium_bundle( string $name ) : void { $asset_path = WEBCALENDAR_WP_PATH . 'build/' . $name . '.asset.php'; $js_path = WEBCALENDAR_WP_PATH . 'build/' . $name . '.js'; if ( !file_exists( $asset_path ) || !file_exists( $js_path ) ) { return; } $asset = (require $asset_path); wp_enqueue_script( 'webcal-' . $name, WEBCALENDAR_WP_URL . 'build/' . $name . '.js', array_merge( $asset['dependencies'], ['webcalendar-admin'] ), $asset['version'], true ); } /** * Add the menu page. */ public function add_menu_page() : void { add_menu_page( __( 'WebCalendar', 'agenticdaisy-calendar' ), __( 'WebCalendar', 'agenticdaisy-calendar' ), 'webcal_can_view_calendar', 'webcalendar', [$this, 'render_calendar_page'], 'dashicons-calendar-alt' ); // Rename the auto-created first submenu item to "Calendar". add_submenu_page( 'webcalendar', __( 'Calendar', 'agenticdaisy-calendar' ), __( 'Calendar', 'agenticdaisy-calendar' ), 'webcal_can_view_calendar', 'webcalendar', [$this, 'render_calendar_page'] ); add_submenu_page( 'webcalendar', __( 'Categories', 'agenticdaisy-calendar' ), __( 'Categories', 'agenticdaisy-calendar' ), 'webcal_can_manage_categories', 'webcalendar-categories', [$this, 'render_categories_page'] ); add_submenu_page( 'webcalendar', __( 'Custom Fields', 'agenticdaisy-calendar' ), __( 'Custom Fields', 'agenticdaisy-calendar' ), 'webcal_can_manage_categories', 'webcalendar-extra-fields', [$this, 'render_extra_fields_page'] ); add_submenu_page( 'webcalendar', __( 'Venues & Organizers', 'agenticdaisy-calendar' ), __( 'Venues & Organizers', 'agenticdaisy-calendar' ), 'webcal_can_manage_categories', 'webcalendar-places', [$this, 'render_places_page'] ); // Submissions submenu with pending count badge if ( webcal_feature_available( 'frontend_submission' ) && function_exists( 'webcal_fs' ) ) { } } /** * Add the Settings submenu at a later priority so it appears last. */ public function add_settings_submenu() : void { add_submenu_page( 'webcalendar', __( 'Settings', 'agenticdaisy-calendar' ), __( 'Settings', 'agenticdaisy-calendar' ), 'webcal_can_manage_settings', 'webcalendar-settings', [$this, 'render_settings_page'] ); } /** * Render the full calendar page. */ public function render_calendar_page() : void { ?>
' . esc_html__( 'Configure basic calendar behavior.', 'agenticdaisy-calendar' ) . '
'; // The timezone itself lives in WordPress General Settings, but its effect // on stored event times is a calendar concern, so surface it here too. ( new TimezoneCheck() )->render_notice(); } /** * Render maps section description. */ public function render_maps_section() : void { echo '' . esc_html__( 'Configure how event location maps are displayed on single event pages and calendar popups.', 'agenticdaisy-calendar' ) . '
'; } /** * Render the map provider dropdown. */ public function render_map_provider_field() : void { $value = get_option( 'webcal_map_provider', 'osm' ); $value = ( is_scalar( $value ) ? (string) $value : 'osm' ); ?>__( 'Please enter a Google Maps API key, or switch to OpenStreetMap.', 'agenticdaisy-calendar' ), ] ); } /** * Render Google Maps API key field. */ public function render_google_maps_key_field() : void { $raw_val = get_option( 'webcal_google_maps_api_key', '' ); $value = ( is_scalar( $raw_val ) ? (string) $raw_val : '' ); ?>
Google Cloud Console' ); ?>
> > >
' . esc_html__( 'Allow visitors to submit events from the frontend. Requires Business plan or higher.', 'agenticdaisy-calendar' ) . ''; return; } echo '
' . esc_html__( 'Allow logged-in users to submit events from the frontend using the [webcalendar-submit] shortcode or Submit Event block.', 'agenticdaisy-calendar' ) . '
'; } /** * Render the frontend submission enable checkbox. */ public function render_frontend_submission_field() : void { $available = webcal_feature_available( 'frontend_submission' ); $raw_val = get_option( 'webcal_frontend_submission', 'no' ); $checked = is_scalar( $raw_val ) && (string) $raw_val === 'yes'; ?> >> ' . esc_html__( 'Manage your WebCalendar license and features.', 'agenticdaisy-calendar' ) . ''; } /** * Render the license status field. */ public function render_license_status_field() : void { $license = \WebCalendar\WP\Container::get_instance()->get_license(); $tier = $license->get_tier(); $tier_labels = [ 'free' => __( 'Free', 'agenticdaisy-calendar' ), 'starter' => __( 'Starter', 'agenticdaisy-calendar' ), 'business' => __( 'Business', 'agenticdaisy-calendar' ), 'agency' => __( 'Agency', 'agenticdaisy-calendar' ), ]; $label = $tier_labels[$tier] ?? ucfirst( $tier ); echo '' . esc_html( $label ) . ''; if ( $license->is_freemius_active() ) { $fs = $license->get_freemius(); if ( $fs !== null ) { $account_url = $fs->get_account_url(); echo ' — ' . esc_html__( 'Manage Account', 'agenticdaisy-calendar' ) . ''; } } if ( $tier === 'free' ) { $upgrade_url = $this->get_upgrade_url(); echo '
' . esc_html__( 'Upgrade to unlock more features.', 'agenticdaisy-calendar' ) . '
'; } } /** * Sanitize the single event pages setting to an allowed value. * * @param mixed $value Raw input. * @return string 'off', 'public', or 'all'. */ public function sanitize_single_event_pages( $value ) : string { $value = ( is_scalar( $value ) ? (string) $value : 'off' ); return ( in_array( $value, ['off', 'public', 'all'], true ) ? $value : 'off' ); } /** * Render the dev override checkbox (WP_DEBUG only). */ public function render_dev_override_field() : void { $value = get_option( 'webcal_license_dev_override', 'no' ); $checked = is_scalar( $value ) && (string) $value === 'yes'; ?> > get_license(); if ( $license->is_freemius_active() ) { $fs = $license->get_freemius(); if ( $fs !== null ) { return $fs->get_upgrade_url(); } } return \WebCalendar\WP\License\License::PRICING_URL; } /** * Whether the dev tier override can apply on this site, so its fields are * not offered where they would do nothing. */ private function dev_override_allowed() : bool { return \WebCalendar\WP\Container::get_instance()->get_license()->dev_override_allowed(); } /** * Render time format field. */ public function render_time_format_field() : void { $value = webcal_time_format(); ?>| ' . esc_html( $field['label'] ) . ' | '; echo '' . esc_html( $field['value'] ) . ' | ';
echo '