Skip to content

Commit

Permalink
Push 1.5.0 structured data and timestamp filtering
Browse files Browse the repository at this point in the history
  • Loading branch information
duplaja committed Feb 27, 2018
1 parent f5bb052 commit 93df5af
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 5 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ Stores expert and review information from the API in transients to lower number
* filter_reviews, comma seperated list of review IDs to exclude from display
* only_clients, comma serpated list of client IDs to exclusively display (other filters still apply)
* only_reviews, comma serpated list of review IDs to exclusively display (other filters still apply)
* schema=yes Enable structured data using json-ld (aggregate review, review markup) (yes to enable, only use this once per page for now)
* schema_desc="Your description here" (default is: Custom WordPress work through Codeable.io)
* start_time (unix timestamp, will only show reviews published after this time)
* end_time (unix timestamp, will only show reviews published before this time)

### Optional atts: expert_image
* circle=yes , default is yes shows image as a circle
Expand All @@ -61,6 +65,10 @@ Stores expert and review information from the API in transients to lower number

== Changelog ==

= 1.5.0 =
* First version of schema / structured data (aggregate review, reviews): schema, schema_desc atts
* Added ability to filter displayed reviews by start_time and end_time (must be in Unix timestamp format)

= 1.4.1 =
* Added sanitizing of external data (esc_html / esc_url where appropriate)

Expand Down
92 changes: 87 additions & 5 deletions codeable-reviews-and-expert-profile.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
Plugin URI: https://dandulaney.com
GitHub Plugin URI: https://github.com/duplaja/codeable-reviews-and-expert-profile
Description: Gathers Codeable Reviews and Profile Information for a Codeable Expert
Version: 1.4.1
Version: 1.5.0
Author: Dan Dulaney
Author URI: https://dandulaney.com
License: GPLv2
Expand Down Expand Up @@ -282,8 +282,12 @@ function codeable_display_reviews($atts){
'show_rating'=> 'yes', //Show rating on each review
'filter_clients' => '', //Comma seperated list of client IDs to filter out
'filter_reviews' => '', //Comma seperated list of review IDs to filter out
'only_clients' => '', //Comma seperated list of client IDs to include (filters all others)
'only_reviews' => '', //Comma seperated list of review IDs to include (filters all others)
'only_clients' => '', //Comma seperated list of client IDs to include (filters all others)
'only_reviews' => '', //Comma seperated list of review IDs to include (filters all others)
'schema' => '', //Send yes to include review schema (once per page only)
'schema_desc' => 'Custom WordPress work through Codeable.io', //Product description for schema
'start_time' => '', //Unix timestamp, shows reviews after this time
'end_time' => '', //Unix timestamp, shows reviews before this time
), $atts, 'expert_completed' );

if (empty($atts['codeable_id'])) {
Expand All @@ -305,6 +309,28 @@ function codeable_display_reviews($atts){
//Retrieves (from api or transient) all stored reviews
$codeable_review_data = codeable_handle_review_transient($atts['codeable_id'],$to_pull);

$schema = $atts['schema'];
if ($schema=='yes') {

$codeable_expert_data = codeable_handle_expert_transient($atts['codeable_id']);

$schema_data = '
<script type="application/ld+json">
{
"@context": "http://schema.org",
"@type": "Product",
"aggregateRating": {
"@type": "AggregateRating",
"ratingValue": "'.$codeable_expert_data->average_rating.'",
"reviewCount": "'.$codeable_expert_data->completed_tasks_count.'"
},
"description": "'.$atts['schema_desc'].'",
"name": "'.$codeable_expert_data->full_name.'",
"image": "'.$codeable_expert_data->avatar->large_url.'",
"review": [
';

}

//Filters out / removes all with default images, if that att is set
if ($atts['has_picture'] == 'yes') {
Expand Down Expand Up @@ -341,7 +367,7 @@ function codeable_display_reviews($atts){

}

//Filters out / removes all above the max score
//Filters out / removes all below the min score
if (!empty($atts['min_score'])) {

$min_score = $atts['min_score'];
Expand All @@ -351,6 +377,26 @@ function codeable_display_reviews($atts){

}

//Shows only reviews published after the unix timestamp for start time
if (!empty($atts['start_time'])) {

$start_time = $atts['start_time'];
$codeable_review_data = array_filter($codeable_review_data,function($review) use($start_time){
return $review->timestamp >= $start_time;
});

}

//Shows only reviews published before the unix timestamp for end time
if (!empty($atts['end_time'])) {

$end_time = $atts['end_time'];
$codeable_review_data = array_filter($codeable_review_data,function($review) use($end_time){
return $review->timestamp <= $end_time;
});

}

//Filters out matching client ID #'s
if (!empty($atts['filter_clients'])) {

Expand Down Expand Up @@ -413,7 +459,8 @@ function codeable_display_reviews($atts){
if ($review_num < $atts['start_at']) {
$review_num++;
continue;
}
}


$task_title = $review->task_title;
$score = $review->score;
Expand All @@ -424,6 +471,30 @@ function codeable_display_reviews($atts){
$reviewer_id = $review->reviewer->id;
$review_id = $review->id;


if($schema=='yes') {

if ($showed_this_run != 0) {

$schema_data.=',';
}
$schema_data.='
{
"@type": "Review",
"author": "'.$name.'",
"datePublished": "'.date('Y-m-d',$time).'",
"description": "'.$comment.'",
"name": "",
"reviewRating": {
"@type": "Rating",
"bestRating": "5",
"ratingValue": "'.$score.'",
"worstRating": "1"
}
}';
}


$score_disp = '';

if ($atts['show_rating'] != 'no') {
Expand Down Expand Up @@ -467,6 +538,17 @@ function codeable_display_reviews($atts){
}
$to_return.= '</ul>';

if($schema == 'yes') {

$schema_data.='
]
}
</script>';

$to_return.=$schema_data;
}

return $to_return;

}
Expand Down

0 comments on commit 93df5af

Please sign in to comment.