Forum Replies Created

Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter kidders

    (@kidders)

    Hi @rubengc

    Thank you, I have made some progress, I can make titles now and correct point number appear in admin panel earnings. However I would like to be able to provide correct data so that I can make the entry appear in the User Earnings block, looking like a normal GamiPress entry (with points thumbnail, description, date, amount, etc). Could you please give a comprehensive idea of how to do this please? specifically what fields to fill and how to create both arrays and the function call. I did check the docblock but it did not give me this data explicitly.

    Thanks again for your help.

    Thread Starter kidders

    (@kidders)

    Hi @rubengc forgive me for not understanding, I have tried your suggestion (code below), and get the same thing. The user earnings log only shows in admin panel and shows no message and that points added was 0. I am not sure why this is. Forgive my misunderstanding but may you help.

    <?php
    /**
    * Plugin Name: Amo Earnings Bare Test
    * Description: Minimal test for gamipress_insert_user_earning()
    */

    if ( ! defined('ABSPATH') ) exit;

    add_shortcode('amo_earning_test', function() {

    $user_id = get_current_user_id();
    $points_type = 'amo';
    $points = 50;
    $title = 'Test via gamipress_insert_user_earning()';

    // --- The exact structure from support ---
    $data = array(
    'title' => $title,
    'user_id' => $user_id,
    'post_id' => 0,
    'post_type' => '',
    'points' => $points,
    'points_type' => $points_type,
    'date' => date( 'Y-m-d H:i:s', current_time( 'timestamp' ) ),
    );

    $earning_id = gamipress_insert_user_earning( $data );

    if ( $earning_id ) {
    return "<p>✅ Created earning ID $earning_id<br>User: $user_id<br>Points: $points<br>Message: $title</p>";
    } else {
    return "<p>❌ Failed to create earning entry.</p>";
    }
    });
    Thread Starter kidders

    (@kidders)

    Hi @rubengc

    Okay thanks, could you link me to some documentation on the correct call to make? Or give me some example code? What exactly does the function expect?

    some example code would be really helpful.

    Thank again for your help.

    Thread Starter kidders

    (@kidders)

    Hi @rubengc

    Thanks for offering.

    I have tried the below as a test mu-plugin.

    <?php
    /**
    * Plugin Name: GamiPress User Earning Test
    * Description: Simple front-end test to add a User Earnings entry and update balance.
    */

    if ( ! defined( 'ABSPATH' ) ) exit;

    add_shortcode('gp_test_award', function() {
    // Change these for your test
    $user_id = get_current_user_id(); // logged-in user
    $points = 50;
    $points_type = 'amo'; // your points type slug
    $message = 'Test front-end award message';

    // Insert into User Earnings
    $earning_id = gamipress_insert_user_earning( array(
    'user_id' => $user_id,
    'points' => $points,
    'points_type' => $points_type,
    'description' => $message,
    'access' => 'public',
    ) );

    // Update user balance
    if ( function_exists( 'gamipress_award_points_to_user' ) ) {
    gamipress_award_points_to_user( $user_id, $points, $points_type );
    }

    if ( $earning_id ) {
    return "<p>✅ Added $points $points_type to user #$user_id with message:<br><em>$message</em></p>";
    } else {
    return "<p>❌ Failed to insert earning entry.</p>";
    }
    });

    However, I get points addition and I can see an entry in admin user earnings that points were added, but the message is blank and it also says 0 points awarded (when I do get points added). It also only shows an entry in admin user earnings, not the user earnings block where a user can see it frontend.

    Let me know what I should do or if you need more information and what specifically.

    Thanks for your help.

Viewing 4 replies - 1 through 4 (of 4 total)