#adminmenu li:has(> a[href="admin.php?page=' . esc_attr( self::SLUG ) . '"]){display:none;}' . '#adminmenu a[href="admin.php?page=' . esc_attr( self::SLUG ) . '"]{display:none;}'; } public function assets( $hook ) { if ( false === strpos( (string) $hook, self::SLUG ) ) { return; } wp_enqueue_media(); wp_enqueue_style( 'advk-admin-door', ADVK_URL . 'assets/css/admin-door.css', array(), ADVK_VERSION ); wp_enqueue_script( 'advk-admin-door', ADVK_URL . 'assets/js/admin-door.js', array( 'jquery' ), ADVK_VERSION, true ); } /** Edit URL for a door id (0 = new). */ public static function edit_url( $id = 0 ) { $args = array( 'page' => self::SLUG ); if ( $id ) { $args['door'] = (int) $id; } return admin_url( 'admin.php?' . http_build_query( $args ) ); } /* ---------------- save ---------------- */ public function handle_save() { if ( ! current_user_can( 'manage_options' ) ) { wp_die( esc_html__( 'Keine Berechtigung.', 'adventura-interactive-advent-calendar' ) ); } check_admin_referer( 'advk_door_editor' ); $id = isset( $_POST['door_id'] ) ? (int) $_POST['door_id'] : 0; $name = sanitize_text_field( wp_unslash( $_POST['advk_sponsor_name'] ?? '' ) ); if ( '' === $name ) { $name = __( 'Türchen', 'adventura-interactive-advent-calendar' ); } $args = array( 'post_type' => ADVK_Doors_CPT::POST_TYPE, 'post_status' => 'publish', 'post_title' => $name, ); if ( $id ) { $args['ID'] = $id; wp_update_post( $args ); // triggers save_post_advk_door → saves all meta from $_POST. } else { $id = (int) wp_insert_post( $args ); // same hook fires → meta saved. } $url = add_query_arg( array( 'page' => self::SLUG, 'door' => $id, 'saved' => 1 ), admin_url( 'admin.php' ) ); wp_safe_redirect( $url ); exit; } /* ---------------- render ---------------- */ public function render_page() { if ( ! current_user_can( 'manage_options' ) ) { return; } // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- read-only id from a link; capability-guarded above. $id = isset( $_GET['door'] ) ? (int) $_GET['door'] : 0; $post = $id ? get_post( $id ) : null; if ( $id && ( ! $post || ADVK_Doors_CPT::POST_TYPE !== $post->post_type ) ) { $id = 0; $post = null; } $is_new = ! $id; // A lightweight post-like object for the extension hooks (Pro). $hook_post = $post ? $post : (object) array( 'ID' => 0 ); $gopts = ADVK_Settings::get_options(); $show_sponsor = ! empty( $gopts['show_sponsor'] ); $show_prizes = ! empty( $gopts['show_prizes'] ); $social_enabled = ! empty( $gopts['social_enabled'] ); // Load current values. $name = $post ? get_the_title( $post ) : ''; $day = $post ? (int) get_post_meta( $id, '_advk_day', true ) : 0; $sponsor_text = $post ? (string) get_post_meta( $id, '_advk_sponsor_text', true ) : ''; $sponsor_url = $post ? (string) get_post_meta( $id, '_advk_sponsor_url', true ) : ''; $logo_id = $post ? (int) get_post_meta( $id, '_advk_logo_id', true ) : 0; $door_img_id = $post ? (int) get_post_meta( $id, '_advk_door_image_id', true ) : 0; $donate_url = $post ? (string) get_post_meta( $id, '_advk_donate_url', true ) : ''; $donate_text = $post ? (string) get_post_meta( $id, '_advk_donate_text', true ) : ''; $social = $post ? (array) get_post_meta( $id, '_advk_social', true ) : array(); $social = array_filter( $social ); $social_urls = $post ? (array) get_post_meta( $id, '_advk_social_urls', true ) : array(); $social_urls = is_array( $social_urls ) ? $social_urls : array(); $prizes_raw = $post ? get_post_meta( $id, '_advk_prizes', true ) : array(); if ( ! is_array( $prizes_raw ) || empty( $prizes_raw ) ) { $prizes_raw = array( array( 'title' => '', 'text' => '', 'value' => '', 'image_id' => 0, 'qty' => 1 ) ); } $prizes_raw = array_values( $prizes_raw ); $prize_total = 0; foreach ( $prizes_raw as $r ) { $prize_total += ( is_array( $r ) && isset( $r['qty'] ) ) ? max( 1, (int) $r['qty'] ) : 1; } $winner_count = $post ? (int) get_post_meta( $id, '_advk_winner_count', true ) : 0; if ( $winner_count < 1 ) { $winner_count = max( 1, $prize_total ); } $quiz = $post ? get_post_meta( $id, '_advk_quiz', true ) : array(); $quiz = is_array( $quiz ) ? $quiz : array(); for ( $i = 0; $i < 2; $i++ ) { if ( ! isset( $quiz[ $i ] ) || ! is_array( $quiz[ $i ] ) ) { $quiz[ $i ] = array( 'q' => '', 'options' => array( '', '', '', '' ), 'correct' => 0 ); } $quiz[ $i ]['options'] = array_pad( (array) $quiz[ $i ]['options'], 4, '' ); } $social_labels = array( 'instagram' => 'Instagram', 'facebook' => 'Facebook', 'tiktok' => 'TikTok', 'youtube' => 'YouTube', 'linkedin' => 'LinkedIn', 'newsletter' => 'Newsletter', ); $social_ph = array( 'instagram' => 'https://instagram.com/dein-profil', 'facebook' => 'https://facebook.com/deine-seite', 'tiktok' => 'https://tiktok.com/@dein-profil', 'youtube' => 'https://youtube.com/@dein-kanal', 'linkedin' => 'https://linkedin.com/company/dein-unternehmen', 'newsletter' => 'https://… (Anmeldeseite)', ); // Publication status. $today = ADVK_Data::today_day(); $status = ( $day && $today && $day < $today ) ? 'open' : ( ( $day && $today && $day === $today ) ? 'today' : 'plan' ); $status_labels = array( 'open' => array( __( 'Geöffnet', 'adventura-interactive-advent-calendar' ), 'is-ok' ), 'today' => array( __( 'Heute', 'adventura-interactive-advent-calendar' ), 'is-today' ), 'plan' => array( __( 'Geplant', 'adventura-interactive-advent-calendar' ), 'is-plan' ), ); $mode = isset( $gopts['reveal_mode'] ) ? (string) $gopts['reveal_mode'] : 'advent'; $year = isset( $gopts['year'] ) ? (int) $gopts['year'] : (int) wp_date( 'Y' ); $opens_at = $day ? ( 'advent' === $mode /* translators: 1: day, 2: year. */ ? sprintf( __( '%1$d. Dez. %2$d, 00:00', 'adventura-interactive-advent-calendar' ), $day, $year ) /* translators: %d: day number. */ : sprintf( __( 'Tag %d', 'adventura-interactive-advent-calendar' ), $day ) ) : '—'; $modified = $post ? mysql2date( 'd.m.Y, H:i', $post->post_modified ) : __( 'noch nicht gespeichert', 'adventura-interactive-advent-calendar' ); $n_prizes = 0; foreach ( $prizes_raw as $r ) { if ( is_array( $r ) && ( '' !== trim( (string) ( $r['title'] ?? '' ) ) || ! empty( $r['image_id'] ) ) ) { $n_prizes++; } } $n_quiz = 0; foreach ( $quiz as $q ) { if ( '' !== trim( (string) $q['q'] ) ) { $n_quiz++; } } $n_social = count( $social ); $saved = isset( $_GET['saved'] ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- display-only flag after our own redirect. $preview_url = ADVK_Data::calendar_page_url(); $list_url = admin_url( 'admin.php?page=advk-doors' ); ?>