'string', 'single' => true, 'show_in_rest' => true, 'sanitize_callback' => 'wp_kses_post', 'auth_callback' => 'skrift_ratgeber_meta_auth', ) ); register_post_meta( 'post', 'faq_ueberschrift', array( 'type' => 'string', 'single' => true, 'show_in_rest' => true, 'sanitize_callback' => 'sanitize_text_field', 'auth_callback' => 'skrift_ratgeber_meta_auth', ) ); 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', ) ); register_post_meta( 'post', 'stand_datum', array( 'type' => 'string', 'single' => true, 'show_in_rest' => true, 'sanitize_callback' => 'skrift_ratgeber_datum', 'auth_callback' => 'skrift_ratgeber_meta_auth', ) ); 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', ) ); } ); function skrift_ratgeber_datum( $wert ) { return preg_match( '/^\d{4}-\d{2}-\d{2}$/', (string) $wert ) ? $wert : ''; } /* ------------------------------------------------------------------------ * 2. Eingabebox im Beitragseditor (Gutenberg und klassisch) * --------------------------------------------------------------------- */ add_action( 'add_meta_boxes_post', function () { add_meta_box( 'skrift_ratgeber', 'Ratgeber: Kurzantwort, CTA und FAQ', 'skrift_ratgeber_metabox', 'post', 'normal', 'high' ); } ); function skrift_ratgeber_metabox( $post ) { wp_nonce_field( 'skrift_ratgeber_speichern', 'skrift_ratgeber_nonce' ); $kurz = (string) get_post_meta( $post->ID, 'kurzantwort', true ); $cta = (string) get_post_meta( $post->ID, 'cta_ziel', true ); $stand = (string) get_post_meta( $post->ID, 'stand_datum', true ); $faq_u = (string) get_post_meta( $post->ID, 'faq_ueberschrift', true ); $faq = get_post_meta( $post->ID, 'faq', true ); if ( ! is_array( $faq ) ) { $faq = array(); } ?>
Zwei bis drei Saetze, Preise nur per [skrift_preis key="..."].
faq des jeweiligen Beitrags.',
) );
$this->add_control( 'erste_offen', array(
'label' => 'Erste Frage geoeffnet',
'type' => $C::SWITCHER,
'default' => '',
) );
$this->add_control( 'schema', array(
'label' => 'FAQ-Schema ausgeben',
'type' => $C::SWITCHER,
'default' => 'yes',
) );
$this->end_controls_section();
$this->start_controls_section( 'stil_frage', array( 'label' => 'Frage', 'tab' => $C::TAB_STYLE ) );
$this->add_group_control( \Elementor\Group_Control_Typography::get_type(), array(
'name' => 'frage_typo',
'selector' => '{{WRAPPER}} .skrift-faq__frage',
) );
$this->add_control( 'frage_farbe', array(
'label' => 'Farbe',
'type' => $C::COLOR,
'selectors' => array( '{{WRAPPER}} .skrift-faq__frage' => 'color: {{VALUE}};' ),
) );
$this->add_control( 'frage_farbe_offen', array(
'label' => 'Farbe geoeffnet',
'type' => $C::COLOR,
'selectors' => array( '{{WRAPPER}} .skrift-faq__eintrag[open] .skrift-faq__frage' => 'color: {{VALUE}};' ),
) );
$this->add_control( 'frage_hintergrund', array(
'label' => 'Hintergrund',
'type' => $C::COLOR,
'selectors' => array( '{{WRAPPER}} .skrift-faq__frage' => 'background-color: {{VALUE}};' ),
) );
$this->add_responsive_control( 'frage_innenabstand', array(
'label' => 'Innenabstand',
'type' => $C::DIMENSIONS,
'size_units' => array( 'px', 'em' ),
'selectors' => array( '{{WRAPPER}} .skrift-faq__frage' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};' ),
) );
$this->end_controls_section();
$this->start_controls_section( 'stil_antwort', array( 'label' => 'Antwort', 'tab' => $C::TAB_STYLE ) );
$this->add_group_control( \Elementor\Group_Control_Typography::get_type(), array(
'name' => 'antwort_typo',
'selector' => '{{WRAPPER}} .skrift-faq__antwort',
) );
$this->add_control( 'antwort_farbe', array(
'label' => 'Farbe',
'type' => $C::COLOR,
'selectors' => array( '{{WRAPPER}} .skrift-faq__antwort' => 'color: {{VALUE}};' ),
) );
$this->add_responsive_control( 'antwort_innenabstand', array(
'label' => 'Innenabstand',
'type' => $C::DIMENSIONS,
'size_units' => array( 'px', 'em' ),
'selectors' => array( '{{WRAPPER}} .skrift-faq__antwort' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};' ),
) );
$this->end_controls_section();
$this->start_controls_section( 'stil_eintrag', array( 'label' => 'Eintrag', 'tab' => $C::TAB_STYLE ) );
$this->add_group_control( \Elementor\Group_Control_Border::get_type(), array(
'name' => 'eintrag_rahmen',
'selector' => '{{WRAPPER}} .skrift-faq__eintrag',
) );
$this->add_control( 'eintrag_radius', array(
'label' => 'Eckenradius',
'type' => $C::DIMENSIONS,
'size_units' => array( 'px' ),
'selectors' => array( '{{WRAPPER}} .skrift-faq__eintrag' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}}; overflow: hidden;' ),
) );
$this->add_control( 'eintrag_hintergrund', array(
'label' => 'Hintergrund',
'type' => $C::COLOR,
'selectors' => array( '{{WRAPPER}} .skrift-faq__eintrag' => 'background-color: {{VALUE}};' ),
) );
$this->add_responsive_control( 'eintrag_abstand', array(
'label' => 'Abstand zwischen Eintraegen',
'type' => $C::SLIDER,
'size_units' => array( 'px', 'em' ),
'selectors' => array( '{{WRAPPER}} .skrift-faq__eintrag + .skrift-faq__eintrag' => 'margin-top: {{SIZE}}{{UNIT}};' ),
) );
$this->end_controls_section();
}
protected function render() {
$s = $this->get_settings_for_display();
$faq = skrift_faq_eintraege();
$bearbeiten = skrift_elementor_bearbeitungsmodus();
// Im Theme-Builder-Template gibt es keinen Beitrag mit FAQ,
// deshalb dort Platzhalter zum Gestalten.
if ( empty( $faq ) && $bearbeiten ) {
$faq = array(
array( 'frage' => 'Beispielfrage aus dem Feld faq', 'antwort' => 'Im Beitrag erscheinen hier die Antworten aus dem Meta-Feld faq.' ),
array( 'frage' => 'Zweite Beispielfrage', 'antwort' => 'Die Gestaltung legen Sie hier im Widget fest, sie gilt fuer alle Beitraege.' ),
array( 'frage' => 'Dritte Beispielfrage', 'antwort' => 'Beitraege ohne FAQ zeigen an dieser Stelle nichts an.' ),
);
}
echo skrift_faq_html( $faq, array( // phpcs:ignore WordPress.Security.EscapeOutput
'erste_offen' => 'yes' === ( $s['erste_offen'] ?? '' ),
'schema' => 'yes' === ( $s['schema'] ?? '' ) && ! $bearbeiten,
) );
}
}
}
if ( ! class_exists( 'Skrift_Kurzantwort_Widget' ) ) {
class Skrift_Kurzantwort_Widget extends \Elementor\Widget_Base {
public function get_name() {
return 'skrift_kurzantwort';
}
public function get_title() {
return 'Skrift Kurzantwort';
}
public function get_icon() {
return 'eicon-text';
}
public function get_categories() {
return array( 'general' );
}
public function get_keywords() {
return array( 'kurzantwort', 'skrift', 'zusammenfassung', 'box' );
}
protected function register_controls() {
$C = '\Elementor\Controls_Manager';
$this->start_controls_section( 'inhalt', array( 'label' => 'Inhalt' ) );
$this->add_control( 'hinweis', array(
'type' => $C::RAW_HTML,
'raw' => 'Der Text kommt aus dem Meta-Feld kurzantwort. Preis-Shortcodes darin werden aufgeloest.',
) );
$this->end_controls_section();
$this->start_controls_section( 'stil_box', array( 'label' => 'Box', 'tab' => $C::TAB_STYLE ) );
$this->add_group_control( \Elementor\Group_Control_Typography::get_type(), array(
'name' => 'box_typo',
'selector' => '{{WRAPPER}} .skrift-kurzantwort',
) );
$this->add_control( 'box_farbe', array(
'label' => 'Textfarbe',
'type' => $C::COLOR,
'selectors' => array( '{{WRAPPER}} .skrift-kurzantwort' => 'color: {{VALUE}};' ),
) );
$this->add_control( 'box_hintergrund', array(
'label' => 'Hintergrund',
'type' => $C::COLOR,
'selectors' => array( '{{WRAPPER}} .skrift-kurzantwort' => 'background-color: {{VALUE}};' ),
) );
$this->add_group_control( \Elementor\Group_Control_Border::get_type(), array(
'name' => 'box_rahmen',
'selector' => '{{WRAPPER}} .skrift-kurzantwort',
) );
$this->add_control( 'box_radius', array(
'label' => 'Eckenradius',
'type' => $C::DIMENSIONS,
'size_units' => array( 'px' ),
'selectors' => array( '{{WRAPPER}} .skrift-kurzantwort' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};' ),
) );
$this->add_responsive_control( 'box_innenabstand', array(
'label' => 'Innenabstand',
'type' => $C::DIMENSIONS,
'size_units' => array( 'px', 'em' ),
'selectors' => array( '{{WRAPPER}} .skrift-kurzantwort' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};' ),
) );
$this->end_controls_section();
}
protected function render() {
$html = skrift_kurzantwort_html();
if ( '' === $html && skrift_elementor_bearbeitungsmodus() ) {
$html = 'Platzhalter: Hier erscheint die Kurzantwort des jeweiligen Beitrags.