• Resolved teeboy4real

    (@teeboy4real)


    Hello,

    Please can you help correct this code to work with the gamipress plugin at https://www.ads-software.com/plugins/gamipress/

    /* assign different ngx points by gamipress to users who receive 4 or 5 star rating in their post (rate my post plugin) */
    function my_assign_ngx_points_on_rating($submitted_rating, $post_id) {
      // Get the post type of the post
      $post_type = get_post_type($post_id);
      
      // Check if the post type is "post" or "advert"
      if ($post_type == 'post' || $post_type == 'advert') {
        // Check if the rating is 5 stars
        if ($submitted_rating == 5) {
          // Get the user ID of the post author
          $user_id = get_post_field('post_author', $post_id);
          // Assign 5 ngx points to the user
          gamipress_update_user_points($user_id, 5, 'ngx', 'You earned 5 ngx points for receiving a 5 star rating');
        }
        // Check if the rating is 4 stars
        if ($submitted_rating == 4) {
          // Get the user ID of the post author
          $user_id = get_post_field('post_author', $post_id);
          // Assign 4 ngx points to the user
          gamipress_update_user_points($user_id, 4, 'ngx', 'You earned 4 ngx points for receiving a 4 star rating');
        }
      }
    }
    add_action('rmp_after_vote', 'my_assign_ngx_points_on_rating', 10, 2);
Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter teeboy4real

    (@teeboy4real)

    Hi

    I finally got this working with the code below

    function assign_ngx_points_on_rating( $post_id, $new_avg_rating, $new_vote_count, $submitted_rating ) {
      // Get the post type of the post
      $post_type = get_post_type($post_id);
      
      // Check if the post type is "post" or "advert"
      if ($post_type == 'post' || $post_type == 'advert') {
        // Get the user ID of the post author
        $user_id = get_post_field('post_author', $post_id);
        $user = get_user_by( 'id', $user_id );
        
        // Check if the rating is 5 stars
        if ($submitted_rating == 5) {
          // Assign 5 ngx points to the user
          gamipress_award_points_to_user( $user->ID, 5, 'ngx-tokens', 'You earned 5 ngx points for receiving a 5 star rating' );
        }
        // Check if the rating is 4 stars
        if ($submitted_rating == 4) {
          // Assign 4 ngx points to the user
          gamipress_award_points_to_user( $user->ID, 4, 'ngx-tokens', 'You earned 4 ngx points for receiving a 4 star rating' );
        }
      }
    }
    add_action('rmp_after_vote', 'assign_ngx_points_on_rating', 10, 4);
    Plugin Support Blaz K.

    (@blazk)

    Hi,

    I’m glad to hear you got it working! Thanks for sharing the code! ??

    Regards,
    Blaz

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Rate my post support for gamipress plugin’ is closed to new replies.