0 && class_exists('AKSRT\\User\\Badges') && method_exists('AKSRT\\User\\Badges', 'auto_evaluate')) { Badges::auto_evaluate($user_id); } } public function on_post_liked(int $post_id, int $actor_id, bool $active): void { $post = get_post($post_id); if (!$post instanceof \WP_Post || $post->post_type !== 'post') { return; } $author = (int) $post->post_author; if ($author <= 0 || $author === $actor_id) { return; } self::bump_user_meta($author, self::META_POST_LIKE_SUM, $active ? 1.0 : -1.0); if ($active) { self::reevaluate_medals($author); } } public function on_comment_liked(int $comment_id, int $actor_id, bool $active): void { $comment = get_comment($comment_id); if (!$comment) { return; } $author = (int) $comment->user_id; if ($author <= 0 || $author === $actor_id) { return; } self::bump_user_meta($author, self::META_COMMENT_LIKE_SUM, $active ? 1.0 : -1.0); if ($active) { self::reevaluate_medals($author); } } public function on_post_favorited(int $post_id, int $actor_id, bool $active): void { unset($post_id, $actor_id, $active); // Favorite is free-points / level only; no dedicated medal get_type. } public function on_user_followed(int $follower_id, int $following_id): void { unset($follower_id); if ($following_id > 0) { self::reevaluate_medals($following_id); } } public function on_post_viewed(int $post_id, int $viewer_id = 0): void { unset($viewer_id); $post = get_post($post_id); if (!$post instanceof \WP_Post || $post->post_type !== 'post') { return; } $author = (int) $post->post_author; if ($author <= 0) { return; } self::bump_user_meta($author, self::META_POSTS_VIEWS_SUM, 1.0); // Cheap throttle: reevaluate every 50 views on author sum. $sum = (float) get_user_meta($author, self::META_POSTS_VIEWS_SUM, true); if (((int) $sum % 50) === 0) { self::reevaluate_medals($author); } } /** * @param int $topic_id * @param int $author_id */ public function on_user_signed_in(int $user_id): void { if ($user_id <= 0) { return; } self::bump_user_meta($user_id, self::META_CHECKIN_ALL_DAY, 1.0); self::reevaluate_medals($user_id); } /** * @param int $user_id * @param float $amount * @param array $context */ public function on_creator_income_added($user_id, $amount, $context = []): void { unset($context); $user_id = (int) $user_id; $amount = (float) $amount; if ($user_id <= 0 || $amount <= 0) { return; } self::bump_user_meta($user_id, self::META_PAY_INCOME, $amount); self::reevaluate_medals($user_id); } /** * @param int $user_id * @param float $amount * @param array $context */ public function on_pay_rebate_added($user_id, $amount, $context = []): void { unset($context); $user_id = (int) $user_id; $amount = (float) $amount; if ($user_id <= 0 || $amount <= 0) { return; } self::bump_user_meta($user_id, self::META_PAY_REBATE, $amount); self::reevaluate_medals($user_id); } }