58 lines
1.3 KiB
PHP
58 lines
1.3 KiB
PHP
<?php
|
|
/**
|
|
* Plugin Name: the_content
|
|
* Description: test to see if the_content works
|
|
* Version: 1.0
|
|
* Author: Kian
|
|
*/
|
|
|
|
|
|
|
|
add_filter('the_content', 'test_replace_tabs_on_book_wrapper', 30);
|
|
|
|
function test_replace_tabs_on_book_wrapper($content) {
|
|
|
|
if (strpos($content, 'book-wrapper') === false) {
|
|
return $content;
|
|
}
|
|
|
|
libxml_use_internal_errors(true);
|
|
$dom = new DOMDocument('1.0', 'UTF-8');
|
|
$dom->loadHTML('<?xml encoding="utf-8" ?>' . $content);
|
|
$xpath = new DOMXPath($dom);
|
|
|
|
$panels = $xpath->query(
|
|
"//*[contains(@class,'wp-block-ub-tabbed-content-tab-content-wrap')]"
|
|
);
|
|
|
|
if ($panels->length === 0) {
|
|
return $content;
|
|
}
|
|
|
|
if ($panels->item(0)) {
|
|
replace_panel_html($dom, $panels->item(0), '<p>TEST AUTHOR CONTENT</p>');
|
|
}
|
|
|
|
if ($panels->item(1)) {
|
|
replace_panel_html($dom, $panels->item(1), '<p>TEST SUMMARY CONTENT</p>');
|
|
}
|
|
|
|
if ($panels->item(2)) {
|
|
replace_panel_html($dom, $panels->item(2), '<p>TEST REVIEWS CONTENT</p>');
|
|
}
|
|
|
|
return $dom->saveHTML();
|
|
}
|
|
|
|
|
|
|
|
function replace_panel_html($dom, $panel, $html) {
|
|
while ($panel->firstChild) {
|
|
$panel->removeChild($panel->firstChild);
|
|
}
|
|
|
|
$fragment = $dom->createDocumentFragment();
|
|
$fragment->appendXML($html);
|
|
$panel->appendChild($fragment);
|
|
}
|