/** * GET THE REVIEWS * Our main function for getting the reviews * and splittting them up into individual reviews * and their parts * * @since 1.0 * @var $instance **/ public function wprrw_split_reviews($instance) { // Create DOM from reviews output string $wprepo = new WP_Ratings_Widget(); $xpath = $wprepo->wprrw_get_xpath($instance); // Target the class of the reviews element $reviewclass = './/div[contains(concat(" ", normalize-space(@class), " "), " review ")]'; // Loop through all review elements // and output the markup accordingly foreach ($xpath->evaluate($reviewclass) as $div) { $i = 0; // Save each review as an XML instance $raw_review = $div->ownerDocument->saveXML($div); // Grab all "a" elements from each review $linkhrefs = array(); $linkTags = $div->getElementsByTagName('a'); // Grab the links from each "a" element // and define the Author according to the // text inside the "a" element foreach ($linkTags as $tag) { $linkhrefs[] = $tag->getAttribute('href'); $author = trim(strip_tags($tag->ownerDocument->saveXML($tag))); } // If a reviewer added any links into their // review, it will return as their author link // So we'll grab their author url instead and // trim that to be their name if (strpos($author, 'http') !== false) { $profile = str_replace("//profiles.wordpress.org/", "", $linkhrefs[0]); $author = $profile; } else { $author = $author; } // Grab and define each element of the review $gettitle = $this->wprrw_getElementsByClass($div, 'div', 'review-title-section'); $title = substr($gettitle[0]->textContent, 0, -13); $getstars = $this->wprrw_getElementsByClass($div, 'div', 'star-rating'); $stars = $getstars[0]->textContent; $getrevdate = $this->wprrw_getElementsByClass($div, 'span', 'review-date'); $revdate = $getrevdate[0]->textContent; $getcontent = $this->wprrw_getElementsByClass($div, 'div', 'review-body'); $content = $getcontent[0]->textContent; $trimmedcontent = wp_trim_words($content, 50); $starnum = substr($stars, 0, -9); $i = 0; if ($starnum >= 4) { include WPRRW_PATH . 'views/default-reviews.php'; } // For testing you can always echo $raw_review // to see the original output that the plugins_api returns //echo $raw_review; } }