1. Customize
  2. Customizations
  3. Custom user earnings column

Custom user earnings column

Note: This snippet will affect the output of [gamipress_earnings] shortcode and GamiPress: User Earnings widget.

You are able to add, remove and rename columns show on the user earnings table.

The default earnings columns are:

  • user: User
  • thumbnail: Thumbnail
  • description: Description
  • date: Date
  • points: Points

Renaming and removing columns

function my_prefix_gamipress_earnings_columns( $earnings_columns, $template_args ) {

    // Rename thumbnail column
    $earnings_columns['thumbnail'] = __( 'Image', 'gamipress' );

    // Remove the points column
    unset( $earnings_columns['points'] );

    return $earnings_columns;

}
add_filter( 'gamipress_earnings_columns', 'my_prefix_gamipress_earnings_columns', 10, 2 );

Adding a custom column

function my_prefix_gamipress_earnings_new_column( $earnings_columns, $template_args ) {

    // Add the user column
    $earnings_columns['user'] = __( 'User', 'gamipress' );

    return $earnings_columns;

}
add_filter( 'gamipress_earnings_columns', 'my_prefix_gamipress_earnings_new_column', 10, 2 );

function my_prefix_gamipress_earnings_render_new_column( $column_output, $column_name, $user_earning, $template_args ) {

    // Check that column is our newly added one
    if( $column_name !== 'user' ) {
        return $column_output;
    }

    $user = get_userdata( $user_earning->user_id );

    if( $user ) {
        // Add the user display name as column output
        $column_output = $user->display_name;
    }

    return $column_output;

}
add_filter( 'gamipress_earnings_render_column', 'my_prefix_gamipress_earnings_render_new_column', 10, 2 );
Was this article helpful to you? Yes 2 No 1

How can we help?