Can I set a maximum of 200 reputation per day?
1. //$ap->add_action( ‘ap_added_reputation’, $this, ‘ap_added_reputation’, 10, 4 );
It is currently not active, implementing this action would not work without changing AnsPress core.
2.
$row = ap_add_meta( $uid, 'reputation', $action_id, $reputation, $type ); if ( $row !== false ) { do_action( 'ap_added_reputation', $uid, $action_id, $reputation, $type, $current_user_id ); }
It is called after reputation already added, only thing you could do is subtract just given reputation post-factum. That would pollute history log. (can’t just remove last row with reputation, it’s not thread-safe, unless there’s some big transaction going above it that I don’t know of)
3. In case first two points are fixed, you’d probably use code like this:
add_action('ap_added_reputation', 'my_reputation_limit', 10, 5); function my_reputation_limit( $user_id, $action_id, $reputation, $type, $current_user_id ){ limit = 200; $deny_reputation = false; global $wpdb; $query = $wpdb->prepare("SELECT sum(v.apmeta_value) as points FROM ".$wpdb->prefix."ap_meta v WHERE v.apmeta_type='reputation' AND v.apmeta_userid = %d AND v.apmeta_date BETWEEN now() - INTERVAL 1 DAY AND now()", $user_id); $result = $wpdb->get_results($query); if ($result) { $deny_reputation = $result->points > $limit; } return $deny_reputation; }
I don’t know php and sql, there must be syntax errors here.
You can use reputation filter to check:
function my_reputation_limit( $user_id, $action_id, $reputation, $type, $current_user_id ){ // Your logic } add_action('ap_added_reputation', 'my_reputation_limit', 10, 5);
Then its gonna be harder for you. I will show an example in my free time.
Thanks Rahul. I know you’re busy so I am not expecting an early answer.
Thanks, but sorry, I’m just a poor marketing guy with no coding chops.
Any possibility you could give me some “// Your Logic” examples or tell me where I could find some reference?