Skip to main content

PDF for GravityView Hooks – gfpdf_gv_ratings_star_{$kind}

Description​

Change the star images for the Ratings & Reviews extension's Stars field, and the stars beside its Reviews Link field. The PDF draws five images for an entry's average rating: filled stars for each whole star, a half star for any fraction, then empty stars. The default stars are the extension's blue (#0074a2) star icons.

There's one filter for each kind of star:

  • gfpdf_gv_ratings_star_filled
  • gfpdf_gv_ratings_star_half
  • gfpdf_gv_ratings_star_empty

The images are used in the Single Entry PDF and the Multiple Entries PDF. Change all three to keep the stars matching.

Each star is output as <img class="gv-pdf-star gv-pdf-star-filled" src="..."> (or -half/-empty) and is 1.25em wide. To change the size, target .gv-pdf-star with gfpdf_gv_template_styles or the View's Additional CSS setting.

For Survey rating fields, use gfpdf_gv_field_star_filled and gfpdf_gv_field_star_empty instead.

Version​

This hook was introduced in PDF for GravityView 2.0.1.

Arguments​

The following arguments are passed to functions that use this hook:

$star | string​

  • The image used for this kind of star, placed in the src attribute of an <img> tag.
  • It can be a data URI, an image URL or a path to an image on the server. SVG, PNG and JPG all work.
  • The default value is a base64-encoded SVG data URI.
  • Returning an empty string or a non-string uses the default image.

$entry | \GV\Entry​

  • The entry being rendered.

$field_settings | array​

  • The View field's settings, from \GV\Field::as_configuration().

$gravityview | \GV\Template_Context​

  • GravityView's template context for the field.

Usage​

Use gold stars instead of blue:

$gold_star = function( $star ) {
$svg = base64_decode( substr( $star, strlen( 'data:image/svg+xml;base64,' ) ) );

return 'data:image/svg+xml;base64,' . base64_encode( str_replace( '#0074a2', '#f0ad4e', $svg ) );
};

add_filter( 'gfpdf_gv_ratings_star_filled', $gold_star );
add_filter( 'gfpdf_gv_ratings_star_half', $gold_star );
add_filter( 'gfpdf_gv_ratings_star_empty', $gold_star );

Use images from your theme. A server path saves the PDF engine from fetching the image over HTTP:

foreach ( [ 'filled', 'half', 'empty' ] as $kind ) {
add_filter( 'gfpdf_gv_ratings_star_' . $kind, function() use ( $kind ) {
return get_stylesheet_directory() . '/images/star-' . $kind . '.png';
} );
}

Source Code​

This filter is located in src/Pdf/ThirdParty/RatingsReviews.php of the PDF for GravityView extension.