The following snippet shows how to force to set as current user the current displayed post author.
To make it work you need to set the attribute current_user
to author
.
Example:
[gamipress_points current_user="author"]
function my_prefix_replace_logged_in_user_by_post_author( $out, $pairs, $atts ) {
// Just override current_user is set to "author"
if( isset( $atts['current_user'] ) && $atts['current_user'] === 'author' ) {
// Set as user ID the current post author
$out['user_id'] = get_post_field( 'post_author', get_the_ID() );
// Force current user to "no" to prevent being overwritten after
$out['current_user'] = 'no';
}
return $out;
}
// Hook for [gamipress_achievements] shortcode
add_filter( 'shortcode_atts_gamipress_achievements', 'my_prefix_replace_logged_in_user_by_post_author', 10, 3 );
// Hook for [gamipress_points] shortcode
add_filter( 'shortcode_atts_gamipress_points', 'my_prefix_replace_logged_in_user_by_post_author', 10, 3 );
// Hook for [gamipress_rank] shortcode
add_filter( 'shortcode_atts_gamipress_ranks', 'my_prefix_replace_logged_in_user_by_post_author', 10, 3 );
// Hook for [gamipress_user_rank] shortcode
add_filter( 'shortcode_atts_gamipress_user_rank', 'my_prefix_replace_logged_in_user_by_post_author', 10, 3 );
// Hook for [gamipress_logs] shortcode
add_filter( 'shortcode_atts_gamipress_logs', 'my_prefix_replace_logged_in_user_by_post_author', 10, 3 );
// Hook for [gamipress_earnings] shortcode
add_filter( 'shortcode_atts_gamipress_earnings', 'my_prefix_replace_logged_in_user_by_post_author', 10, 3 );