1,
'per_page' => 12,
'accent' => '#00a06e',
'default_image_id' => 0,
'donate_url' => '',
'donate_qr_id' => 0,
'seo_noindex_tax' => 1,
);
return wp_parse_args( (array) get_option( 'fegp_options', array() ), $defaults );
}
/**
* Topic groups of a sermon (direct, or derived from its topics).
*
* @param int $post_id Post ID.
* @return WP_Term[]
*/
function fegp_get_groups( $post_id ) {
$groups = get_the_terms( $post_id, 'feg_topic_group' );
if ( $groups && ! is_wp_error( $groups ) ) {
return $groups;
}
$out = array();
$topics = get_the_terms( $post_id, 'sermon_topics' );
if ( $topics && ! is_wp_error( $topics ) ) {
foreach ( $topics as $t ) {
$gid = (int) get_term_meta( $t->term_id, 'fegp_group_id', true );
if ( $gid ) {
$g = get_term( $gid, 'feg_topic_group' );
if ( $g && ! is_wp_error( $g ) ) {
$out[ $gid ] = $g;
}
}
}
}
return array_values( $out );
}
/**
* Image ID for a sermon: featured image, else group image, else default image.
*
* @param int $post_id Post ID.
* @return int
*/
function fegp_image_id( $post_id ) {
$id = (int) get_post_thumbnail_id( $post_id );
if ( $id ) {
return $id;
}
foreach ( fegp_get_groups( $post_id ) as $g ) {
$id = (int) get_term_meta( $g->term_id, 'fegp_image_id', true );
if ( $id ) {
return $id;
}
}
$series = get_the_terms( $post_id, 'sermon_series' );
if ( $series && ! is_wp_error( $series ) ) {
foreach ( $series as $t ) {
$id = (int) get_term_meta( $t->term_id, 'series-taxonomy-image-id', true );
if ( $id ) {
return $id;
}
}
}
$o = fegp_options();
return (int) $o['default_image_id'];
}
/**
* Render a term list as links.
*
* @param int $post_id Post ID.
* @param string $tax Taxonomy.
* @return string Escaped HTML.
*/
function fegp_terms( $post_id, $tax ) {
$terms = 'feg_topic_group' === $tax ? fegp_get_groups( $post_id ) : get_the_terms( $post_id, $tax );
if ( ! $terms || is_wp_error( $terms ) ) {
return '';
}
$links = array();
foreach ( $terms as $t ) {
$links[] = esc_html( $t->name );
}
return implode( ', ', $links );
}
/**
* Audio player HTML.
*
* @param int $post_id Post ID.
* @return string
*/
function fegp_player( $post_id ) {
$url = get_post_meta( $post_id, 'asp_sermon_mp4', true );
if ( ! $url ) {
return '';
}
return '';
}
/**
* Alt text for a sermon image: the attachment's own alt, else the sermon title.
*
* @param int $attachment_id Attachment ID.
* @param int $post_id Sermon ID.
* @return string
*/
function fegp_image_alt( $attachment_id, $post_id ) {
$alt = trim( (string) get_post_meta( $attachment_id, '_wp_attachment_image_alt', true ) );
return '' !== $alt ? $alt : wp_strip_all_tags( get_the_title( $post_id ) );
}
/**
* Tile markup for grids and slider.
*
* @param int $post_id Post ID.
* @return string
*/
function fegp_tile( $post_id ) {
$img = fegp_image_id( $post_id );
$link = get_permalink( $post_id );
$html = '';
$html .= '';
$html .= $img ? wp_get_attachment_image( $img, 'medium_large', false, array( 'loading' => 'lazy', 'alt' => fegp_image_alt( $img, $post_id ) ) ) : '';
$html .= '';
$html .= '
';
$html .= '
';
$sp = fegp_terms( $post_id, 'sermon_speaker' );
if ( $sp ) {
$html .= '
' . $sp . '
';
}
$tp = fegp_terms( $post_id, 'sermon_topics' );
$pass = get_post_meta( $post_id, 'asp_sermon_bible_passage', true );
$pass = $pass ? esc_html( $pass ) : fegp_terms( $post_id, 'sermon_book' );
if ( $tp || $pass ) {
$html .= '
' . ( $tp ? '' . $tp . '' : '' ) . ( $pass ? '' . $pass . '' : '' ) . '
';
}
$fegp_post = get_post( $post_id );
$ex = has_excerpt( $post_id ) ? $fegp_post->post_excerpt : wp_strip_all_tags( strip_shortcodes( $fegp_post->post_content ) );
$ex = wp_trim_words( $ex, 18, '…' );
if ( $ex ) {
$html .= '
' . esc_html( $ex ) . '
';
}
$html .= '
' . fegp_player( $post_id ) . '
';
$html .= '
';
return $html;
}
/**
* Donation URL (setting, else constant).
*
* @return string
*/
function fegp_donate_url() {
$o = fegp_options();
return $o['donate_url'] ? $o['donate_url'] : FEGP_DONATE_URL;
}
/**
* Donation box: link and QR code (local media only).
*
* @return string
*/
function fegp_donate_box() {
$o = fegp_options();
$html = '
';
if ( $o['donate_qr_id'] ) {
$html .= wp_get_attachment_image( (int) $o['donate_qr_id'], 'thumbnail', false, array( 'style' => 'width:110px;height:110px', 'alt' => esc_attr__( 'Donation QR code', 'kanzelbuch' ) ) );
} elseif ( fegp_donate_url() === FEGP_DONATE_URL ) {
$html .= '
 . ')
';
}
$html .= '
';
return $html;
}
/**
* Allowed HTML for escaping the plugin's own markup late with wp_kses().
* Post HTML plus the form, media and SVG elements the plugin renders.
*
* @return array
*/
function fegp_kses_allowed() {
static $allowed = null;
if ( null !== $allowed ) {
return $allowed;
}
$global = array_fill_keys( array( 'class', 'id', 'style', 'title', 'role', 'hidden', 'tabindex', 'data-*', 'aria-label', 'aria-hidden', 'aria-expanded', 'aria-controls', 'aria-current', 'aria-describedby', 'aria-labelledby', 'aria-live' ), true );
$extra = array(
'form' => array( 'action', 'method', 'enctype', 'name', 'novalidate', 'autocomplete', 'target' ),
'input' => array( 'type', 'name', 'value', 'checked', 'placeholder', 'required', 'min', 'max', 'step', 'size', 'maxlength', 'multiple', 'accept', 'form', 'disabled', 'readonly', 'autocomplete', 'inputmode', 'pattern' ),
'select' => array( 'name', 'multiple', 'form', 'required', 'disabled', 'size', 'autocomplete' ),
'option' => array( 'value', 'selected', 'disabled', 'label' ),
'optgroup' => array( 'label', 'disabled' ),
'button' => array( 'type', 'name', 'value', 'form', 'formnovalidate', 'disabled' ),
'textarea' => array( 'name', 'rows', 'cols', 'placeholder', 'form', 'required', 'maxlength', 'readonly', 'disabled' ),
'label' => array( 'for' ),
'fieldset' => array(),
'legend' => array(),
'details' => array( 'open' ),
'summary' => array(),
'audio' => array( 'src', 'controls', 'preload', 'loop', 'muted' ),
'source' => array( 'src', 'type' ),
'svg' => array( 'xmlns', 'viewbox', 'width', 'height', 'fill', 'stroke', 'stroke-width', 'stroke-linecap', 'stroke-linejoin', 'focusable' ),
'path' => array( 'd', 'fill', 'stroke', 'stroke-width', 'stroke-linecap', 'stroke-linejoin', 'fill-rule', 'clip-rule', 'opacity' ),
'circle' => array( 'cx', 'cy', 'r', 'fill', 'stroke', 'stroke-width', 'opacity' ),
'rect' => array( 'x', 'y', 'width', 'height', 'rx', 'ry', 'fill', 'stroke', 'stroke-width', 'opacity' ),
'ellipse' => array( 'cx', 'cy', 'rx', 'ry', 'fill', 'stroke', 'opacity' ),
'g' => array( 'fill', 'stroke', 'opacity' ),
'time' => array( 'datetime' ),
'nav' => array(),
'section' => array(),
'main' => array(),
'article' => array(),
'noscript' => array(),
);
$allowed = wp_kses_allowed_html( 'post' );
foreach ( $extra as $tag => $attrs ) {
$allowed[ $tag ] = array_merge( isset( $allowed[ $tag ] ) ? $allowed[ $tag ] : array(), array_fill_keys( $attrs, true ), $global );
}
return $allowed;
}