Skip to content

Instantly share code, notes, and snippets.

View danielpowney's full-sized avatar

Daniel Powney danielpowney

View GitHub Profile
@danielpowney
danielpowney / mrp_rating_form_shortcode_sample.txt
Last active August 29, 2015 14:14
Sample shortcode to display the rating form
[mrp_rating_form title="My Rating Form" user_can_update_delete="false"
show_comment_textarea="true" submit_button_text="Submit Rating"
before_title="<h3>" after_title="</h3>"]
function my_custom_comment_form_validation( $validation_results ) {
array_push( $validation_results, array(
'severity' => 'error',
'name' => 'my_custom_error2',
'field' => null,
'message' => __( 'My custom error 1', 'my-text-domain' )
) );
return $validation_results;
}
<?php
/**
* Adds WP loop sort by highest rating then count entries
*
* @param unknown $order_by
* @param unknown $query
* @return string
*/
function mrp_posts_orderby( $order_by ) {
.review-details .comment {
font-weight: bold;
color: #AAA;
}
.review-meta .name {
font-weight: bold;
}
.user-rating-results .rank, .rating-results-list .rank {
font-weight: bold;
}
.top-rating-results .rank {
background-color: #DDDDDD;
-webkit-border-radius: 50%;
-moz-border-radius: 50%;
border-radius: 50%;
padding-left: 8px;
padding-right: 8px;
}
.rating-result .percentage-result, .rating-result .score-result {
font-weight: bold;
if ( class_exists( 'MRP_Multi_Rating_API' ) ) {
$post_id = get_the_ID(); // must be in the WP loop
// if a rating form is not specified in post meta, use default settings
$rating_form_id = get_post_meta( $post_id, MRP_Multi_Rating::RATING_FORM_ID_POST_META, true );
if ( $rating_form_id == '' ) {
$general_settings = (array) get_option( MRP_Multi_Rating::GENERAL_SETTINGS );
$rating_form_id = $general_settings[ MRP_Multi_Rating::DEFAULT_RATING_FORM_OPTION ];
}
@danielpowney
danielpowney / rating-form.php
Last active August 29, 2015 14:21
rating-form.php template with custom order for rating items and custom fields
<div class="rating-form <?php echo $class; ?>">
<?php
if ( ! empty( $title ) ) {
$before_title = apply_filters( 'mrp_rating_form_before_title', $before_title, $post_id, $rating_form_id );
$after_title = apply_filters( 'mrp_rating_form_after_title', $after_title, $post_id, $rating_form_id );
echo "$before_title" . esc_html( $title ) . "$after_title";
@danielpowney
danielpowney / rating-result-reviews.php
Created June 2, 2015 11:37
Custom template for rating result reviews with custom order for rating items and custom fields
<?php
/**
* Rating result reviews template
*/
?>
<div class="rating-result-reviews <?php if ( isset( $class ) ) { echo esc_attr( $class ); } ?>">
<?php
if ( $show_filter == true && $taxonomy ) {
@danielpowney
danielpowney / before_after_count_filters.php
Last active November 2, 2015 10:52
Modify count of entries e.g. "(5 ratings)" instead of "(5)"
<?php
/**
* after count e.g. " ratings)"
* @param string $after_count
*/
function mrp_rating_result_after_count( $after_count ) {
return __( ' ratings)' );
}
add_filter( 'mrp_rating_result_after_count', 'mrp_rating_result_after_count' );
@danielpowney
danielpowney / default_rating_form_by_post_type.php
Last active August 29, 2015 14:23
Changes the default rating form so that it's set based on post type. This overrides the general settings but keeps rating form chosen from post meta if set.
<?php
/**
* Sets default rating form for a post based on post type
*
* @param int $rating_form_id
* @param int $post_id
* @param array $params
* @return $rating_form_id
*/
function mrp_default_rating_form_by_post_type( $rating_form_id, $post_id, $params ) {