• Resolved roly151

    (@roly151)


    Hi, I used the import points tool and it reported that it imported fine. However, it did not update the users points balance, and did not add an entry to register the user earnings. I can see the import in the log files, but there is no trace of it on the user profile. How do I import points that can be seen on the user profile? (And why did it not update the user points balance?)

Viewing 4 replies - 1 through 4 (of 4 total)
  • Hi @roly151!!

    I just did a test and it works perfectly.

    https://imgur.com/l5bGegF
    https://imgur.com/1H1e1oi
    https://imgur.com/IlQBtn5

    I recommend you download the CSV template from GamiPress->Tools->Import/Export->User Point->Import->”Download CSV Template”.

    Once you have it downloaded, edit it with Google Sheet, since if you edit it with Excel it is possible that the columns will be misconfigured.

    You simply have to fill in the columns as shown in the CSV template. https://gamipress.com/docs/tools/import-export-tools/

    Hope it helps!

    Thread Starter roly151

    (@roly151)

    Hi @pacogon

    Thankyou for your reply. I have used the template, and the points are imported – but they are not registered on user earnings. In your first picture, in the User Earnings metabox, there is no indication that the user has been awarded points?

    I can use the bulk award tool, which has the option to “Register on User Earnings”. But this option is not available in the import tool. I would also need to type in each user to use this tool, so it’s not ideal for large numbers of users

    It seems strange that I can add points manually and register on the users earnings, I can bulk award and register on user earnings, but the import tool does not provide this option.

    Thread Starter roly151

    (@roly151)

    If anyone comes across this issue and needs a solution, here is some code you need to add to your site functions.php or your site plugin. This will register the user earnings when using the import tool to import user points.

    //Gamipress - Register user points when importing points from CSV
    function ofc_insert_user_earning_on_import_points_tool( $user_id, $points, $points_type, $args ) {
    
        if( ! defined( 'DOING_AJAX' ) ) return;
        if( ! DOING_AJAX ) return;
        if( ! isset( $_REQUEST['action'] ) ) return;
        if( $_REQUEST['action'] !== 'gamipress_import_export_points_tool_import' ) return;
    
        $points_type_obj = gamipress_get_points_type( $points_type );
        $award = ( current_filter() === 'gamipress_award_points_to_user' );
    
        //if we are deducting points, then make the points negative
        if( ! $award ) {
            $points *= -1;
        }
    
        $current_total_points = gamipress_get_user_points( $user_id, $points_type);
    
        gamipress_insert_user_earning( $user_id, array(
            'title'         => ( isset( $args['reason'] ) ? $args['reason'] : '' ),
            'post_id'       => $points_type_obj['ID'],
            'post_type'     => 'points-type',
            'points'        => $points - $current_total_points,
            'points_type'   => $points_type,
            'date'          => date( 'Y-m-d H:i:s', current_time( 'timestamp' ) ),
        ) );
    
    }
    add_action( 'gamipress_award_points_to_user', 'ofc_insert_user_earning_on_import_points_tool', 10, 4 );
    add_action( 'gamipress_deduct_points_to_user', 'ofc_insert_user_earning_on_import_points_tool', 10, 4 );

    Hi @roly151!

    Indeed, our import tool does not add an entry to the user earnings, but it is possible with that snippet that you have used.
    ??

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Import User Points & Register User Earnings’ is closed to new replies.