Support Forum

Advanced Search
Forum Scope


Match



Forum Options



Minimum search word length is 3 characters - maximum search word length is 84 characters
plugins-topic
Post Rating Confirmation?
Avatar
Jean Moroney
Member
Free Members
sp_UserOfflineSmall Offline
Sep 10, 2014 - 8:33 pm

We are using the Post Rating plugin (with stars).

We would like to introduce an intermediate step into the rating process where people will have to confirm their rating before it is applied to the post.

I've looked at the actions and hooks, and don't see anything that would seem to help us insert this extra step. 

Do you know whether this has been done before, or can you offer any bright ideas as to how we can accomplish this?

I don't mind digging into the plugin's code, but would prefer not to...

Thanks,
David

Avatar
Mr Papa
Simi Valley, CA
SP Master
Free Members
sp_UserOfflineSmall Offline
Sep 11, 2014 - 1:12 am

afraid there is no option for enabling something like this...  however, I think you can use one of our hooks to do it... namely this one:

sph_PostIndexRatePost

its actually a filter and contains the entire post rating html before being displayed... so you could filter it and add a javascript confirmation...  over simplifying, but look for the html output by this code:

                $link = 'style="cursor: pointer;" onclick="javascript:spRatingRatePost(\''.$postid.'\', \''.$site.'\', 2);" onmouseover="spRatingStarHover(\''.$postid.'\', \''.$x.'\', \''.$overimg.'\')" onmouseout="spRatingStarUnhover(\''.$postid.'\', \''.$intrating.'\', \''.$onimg.'\', \''.$offimg.'\')" ';

and add a javascript confirm statement prior to the javascript:spRatingRatePost portion of the onclick attribute...

Avatar
Jean Moroney
Member
Free Members
sp_UserOfflineSmall Offline
Sep 16, 2014 - 6:31 pm

Thanks for the suggestion.

I'm having a bit of trouble with using the filter.

$out = apply_filters(‘sph_PostIndexRatePost’, $out, $a); 

Is the $a variable required? Could you explain the usage here, or (even better) show me a simple example?

I got the confirmation to work by editing the plugin file, but obviously would prefer not to have to modify that page each time we upgrade...

Thanks,
David

Avatar
Mr Papa
Simi Valley, CA
SP Master
Free Members
sp_UserOfflineSmall Offline
Sep 16, 2014 - 10:19 pm

its a wp function... see:  http://codex.wordpress.org/Fun.....ly_filters

basically, you are passed $out and a bunch of options context data...  you must return the $out value modified or not... the trailing arguments are provided for your use if needed...

so something like:

add_filter('sph_PostIndexRatePost', 'my_post_rating');
function my_post_rating($out) {
    $out = str_replcae('javascript:spRatingRatePost(', 'javascript:if(confirm("Do you want to rate?")) spRatingRatePost(', $out);
}

Now, that is untested, but hopefully you get the idea... search the html in the $out variable being filtered and replace it with the javascript confirm added...

Forum Timezone: Europe/Stockholm
Most Users Ever Online: 1170
Currently Online:
Guest(s) 1
Currently Browsing this Page:
1 Guest(s)
Top Posters:
Mr Papa: 19448
Ike: 2086
Brandon: 864
kvr28: 804
jim: 643
FidoSysop: 577
Conrad_Farlow: 531
fiddlerman: 358
Stefano Prete: 325
Member Stats:
Guest Posters: 616
Members: 17343
Moderators: 0
Admins: 4
Forum Stats:
Groups: 7
Forums: 17
Topics: 10117
Posts: 79590