-
Notifications
You must be signed in to change notification settings - Fork 9
Sample Eight Day Week filters for the Observer
Jeffrey Paul edited this page Sep 16, 2020
·
1 revision
Examples from Observer's eight-day-week-filters.php:
<?php
add_filter( 'Eight_Day_Week\Plugins\Article_Export\xml_outer_elements', function( $elements, $article ) {
$elements['subHeadline'] = get_post_meta( $article->ID, 'nyo_dek', true );
return $elements;
}, 10, 2 );
add_filter( 'Eight_Day_Week\Plugins\Article_Export\xml_outer_elements', function( $elements, $article ) {
if( function_exists( '\Eight_Day_Week\Plugins\Article_Byline\get_article_byline' ) ) {
$elements['byline'] = \Eight_Day_Week\Plugins\Article_Byline\get_article_byline( $article );
}
return $elements;
}, 10, 2 );
add_filter( 'Eight_Day_Week\Plugins\Article_Export\xpath_extract', function( $extract ) {
$extract[] = [
'tag_name' => 'pullQuote',
'container' => 'pullQuotes',
'query' => '//p[contains(@class, "pullquote")]'
];
return $extract;
} );
add_filter( 'Eight_Day_Week\Plugins\Article_Export\dom', function ( $dom ) {
$swap_tag_name = 'emphasized';
$extract_map = [
'strong' => [
'solo' => 'bold',
'inner' => 'em'
],
'em' => [
'solo' => 'italics',
'inner' => 'strong'
],
];
foreach ( $extract_map as $tag_name => $map ) {
$nodes = $dom->getElementsByTagName( $tag_name );
$length = $nodes->length;
for ( $i = $length; -- $i >= 0; ) {
$el = $nodes->item( $i );
$emphasized = $el->getElementsByTagName( $map['inner'] );
if ( $emphasized->length ) {
$em = $dom->createElement( $swap_tag_name );
$em->nodeValue = $el->nodeValue;
try {
$el->parentNode->replaceChild( $em, $el );
} catch ( \Exception $e ) {
}
continue;
}
$new = $dom->createElement( $map['solo'] );
$new->nodeValue = $el->nodeValue;
try {
$el->parentNode->replaceChild( $new, $el );
} catch ( \Exception $e ) {
}
}
}
return $dom;
} );