This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Plugin Name: Listenability: Wikipedia | |
* Plugin URI: https://wordpress.org/plugins/listenability/ | |
* Author: Weston Ruter | |
* Description: Format the text for listening (the say command). | |
*/ | |
/** | |
* Strip out elements from Wikipedia articles. | |
* | |
* @param array $args { | |
* @type DOMDocument $document | |
* @type DOMXPath $xpath | |
* @type string $url | |
* @type array|null $readability_parser_response | |
* } | |
*/ | |
add_action( 'listenability_document', function ( $args ) { | |
$is_wikipedia = ( false !== strpos( parse_url( $args['url'], PHP_URL_HOST ), 'wikipedia' ) ); | |
if ( ! $is_wikipedia ) { | |
return; | |
} | |
$removed_elements = array( | |
'//span[@class = "mw-editsection"]', | |
'//sup[@class = "reference"]', | |
'//sup[@class = "Template-Fact"]', | |
'//div[@class = "reflist"]', | |
'//figure', | |
'//div[@class = "printfooter"]', | |
'//div[@class = "catlinks"]', | |
'//div[@class = "toc"]', | |
'//table', | |
); | |
foreach ( $args['xpath']->query( join( ' | ', $removed_elements ) ) as $element ) { | |
$element->parentNode->removeChild( $element ); | |
} | |
} ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment