From db1b8545751355814179f1efa69649575efb190f Mon Sep 17 00:00:00 2001 From: Lucas Orth Date: Sun, 20 Sep 2026 12:09:27 +0200 Subject: [PATCH] Workflows, Mu-Plugin, Feldnachweis und Doku --- wordpress/skrift-ratgeber-felder.php | 123 +++++++++++++++++++++++++++ 1 file changed, 123 insertions(+) create mode 100644 wordpress/skrift-ratgeber-felder.php diff --git a/wordpress/skrift-ratgeber-felder.php b/wordpress/skrift-ratgeber-felder.php new file mode 100644 index 0000000..bb9a516 --- /dev/null +++ b/wordpress/skrift-ratgeber-felder.php @@ -0,0 +1,123 @@ + 'string', + 'single' => true, + 'show_in_rest' => true, + 'sanitize_callback' => 'wp_kses_post', + 'auth_callback' => 'skrift_ratgeber_meta_auth', + 'description' => 'Kurzantwort auf die Hauptfrage des Artikels', + ) ); + + // Ziel des Call-to-Action, als URL. + register_post_meta( 'post', 'cta_ziel', array( + 'type' => 'string', + 'single' => true, + 'show_in_rest' => true, + 'sanitize_callback' => 'esc_url_raw', + 'auth_callback' => 'skrift_ratgeber_meta_auth', + 'description' => 'Zieladresse des Call-to-Action', + ) ); + + // Stand des Artikels als ISO-Datum (YYYY-MM-DD). + register_post_meta( 'post', 'stand_datum', array( + 'type' => 'string', + 'single' => true, + 'show_in_rest' => true, + 'sanitize_callback' => function ( $wert ) { + return preg_match( '/^\d{4}-\d{2}-\d{2}$/', (string) $wert ) ? $wert : ''; + }, + 'auth_callback' => 'skrift_ratgeber_meta_auth', + 'description' => 'Stand des Artikels, Format YYYY-MM-DD', + ) ); + + /** + * FAQ als wiederholbare Gruppe. + * WordPress braucht fuer verschachtelte Werte ein explizites Schema, + * sonst lehnt die REST-API das Schreiben ab. + */ + register_post_meta( 'post', 'faq', array( + 'type' => 'array', + 'single' => true, + 'default' => array(), + 'show_in_rest' => array( + 'schema' => array( + 'type' => 'array', + 'items' => array( + 'type' => 'object', + 'properties' => array( + 'frage' => array( 'type' => 'string' ), + 'antwort' => array( 'type' => 'string' ), + ), + 'additionalProperties' => false, + ), + ), + ), + 'auth_callback' => 'skrift_ratgeber_meta_auth', + 'description' => 'Liste aus Frage-Antwort-Paaren', + ) ); +} ); + +/** + * Ausgabe der FAQ im Beitrag. + * Verwendung im Elementor-Shortcode-Widget: [skrift_faq] + * Optional mit Ueberschrift: [skrift_faq titel="Haeufige Fragen"] + */ +add_shortcode( 'skrift_faq', function ( $atts ) { + $atts = shortcode_atts( array( + 'titel' => '', + 'post_id' => 0, + ), $atts, 'skrift_faq' ); + + $post_id = $atts['post_id'] ? (int) $atts['post_id'] : get_the_ID(); + $faq = get_post_meta( $post_id, 'faq', true ); + + if ( empty( $faq ) || ! is_array( $faq ) ) { + return ''; + } + + $html = '
'; + + if ( $atts['titel'] ) { + $html .= '

' . esc_html( $atts['titel'] ) . '

'; + } + + foreach ( $faq as $eintrag ) { + if ( empty( $eintrag['frage'] ) ) { + continue; + } + $html .= '
'; + $html .= '' . esc_html( $eintrag['frage'] ) . ''; + $html .= '
' . wp_kses_post( wpautop( $eintrag['antwort'] ?? '' ) ) . '
'; + $html .= '
'; + } + + $html .= '
'; + + return $html; +} );