Can I set a maximum of 200 reputation per day?

4.27K viewsGeneral
1

Do you think its a good idea to set a maximum number of reputation points per day, and can I do so?

1

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 are viewing 1 out of 2 answers, click here to view all answers.