Skip to content

Instantly share code, notes, and snippets.

View danielpowney's full-sized avatar

Daniel Powney danielpowney

View GitHub Profile
@danielpowney
danielpowney / amazon-rating-form.php
Last active August 7, 2016 04:21
Amazon rating form
<?php
/**
* Amazon rating form
*/
?>
<div class="rating-form <?php echo $class; ?> amazon-rating-form">
<?php
<?php
/**
* Overrides templates with custom templates when needed
*
* @param unknown $templates
* @param unknown $slug
* @param unknown $name
* @return unknown
*/
function my_mrp_get_template_part( $templates, $slug, $name ) {
<?php
/**
* Adds Article itemReviewed for aggreagateRatings schema.org microdata
*
* @param $microdata
* @param $post_id
* @return $microdata
*/
function mrp_microdata_aggregate_rating_item_reviewed_article( $microdata, $post_id ) {
<?php
/**
* Adds itemprop=aggregateRating
*
* @param unknown $microdata
* @param unknown $post_id
* @return string
*/
function mrp_microdata_aggregate_rating_attributes( $microdata, $post_id ) {
return 'itemprop="aggregateRating" itemscope itemtype="http://schema.org/AggregateRating"';
@danielpowney
danielpowney / auto-placement-score-default.php
Created March 1, 2016 09:26
Class 'mrp-filter' is passed to the template for auto placement of rating results. This can be used to add logic to the template e.g change default result type.
<?php
if ( $result_type == MRP_Multi_Rating::SCORE_RESULT_TYPE || strpos( $class, 'mrp-filter' ) > 0 ) {
@danielpowney
danielpowney / mrp_data_callbacks.js
Created December 9, 2015 07:29
Adds custom data to save, update, delete rating form AJAX requests
jQuery(document).ready(function() {
mrp_data_callbacks.push( function(index, data) {
data["hello"] = "world";
return data;
});
});
<?php
function mrp_rating_approved_headers( $headers ) {
$headers[] = 'From: Test <[email protected]>';
return $headers;
}
add_filter( 'mrp_rating_approved_headers', 'mrp_rating_approved_headers', 10);
@danielpowney
danielpowney / mrp-search.php
Last active April 27, 2018 14:06
Search form for Multi Rating Pro. The code snippet below allows the user to select an overall star rating as search criteria in the search form. The star ratings are rounded half up or half down e.g. an overall star rating of 4.67/5 will show up in search results for 5 stars.
<?php
/**
* Search results are rounded half up or half down e.g. an overall rating of 4.67 will show up in
* search results for 5 stars.
*
* @param unknown $where
* @param unknown $query
* @return string
*/
function mrp_search_posts_where( $where, $query ) {
<?php
global $wpdb;
$filters_hash = MRP_Multi_Rating_API::get_filters_hash( array() ); // if you want to add any Multi Rating pro specific filters e.g. rating_item_ids
$rating_form = MRP_Utils::get_rating_form( $post_id );
$query = 'SELECT SUM(adjusted_score_result) FROM ' . $wpdb->prefix
. MRP_Multi_Rating::RATING_RESULT_TBL_NAME . ' rr WHERE rr.post_id = ' . $post_id .
' AND rr.rating_form_id = ' . $rating_form_id . ' AND rr.filters_hash = "' . $filters_hash
<!-- Add the following JavaScript -->
<script>
jQuery(document).ready(function() {
jQuery(".mrp-read-more-comment").on("click", function(e) {
var btnId = e.currentTarget.id; // mrp-read-more-comment-X
var parts = btnId.split("-");
var entryId = parts[4];
jQuery("#mrp-comment-full-" + entryId).css( "display", "inline-block" );
jQuery("#mrp-comment-trim-" + entryId).css( "display", "none" );