Sometimes you may want to add an additional custom column to the stats table. This cannot be achieved through native plugin features, but some light custom coding is enough.
This tutorial will provide developers a sketch code of how this can be done. It should be easily be adapted to your needs with some (PHP) coding skills. Be sure to review the code, because there are several optional checks just to showcase them (for example, permission checks).
In the example, we add a custom column to show the user email address.
add_filter( 'ppc_general_stats_format_stats_after_cols_default', 'ppc_add_email_col_html', 10 ); add_filter( 'ppc_general_stats_each_field_empty_value', 'ppc_email_td_html', 10, 4 ); /** * Adds custom field column to stats page. * * Hooks to PPC_HTML_functions::get_html_stats() - ppc_general_stats_html_cols_after_default. * * @param $cols array Stats columns */ function ppc_add_email_col_html( $cols ) { global $ppc_global_settings; //Only add column to general stats page if( $ppc_global_settings['current_page'] != 'stats_general' ) return $cols; $perm = new PPC_permissions(); if( $perm->can_mark_as_paid() ) $cols['author_email'] = __( 'Email', 'ppc' ); return $cols; } /** * Populates custom field in stats page. * * Hooks to PPC_HTML_functions::get_html_stats() - ppc_general_stats_html_after_each_default. * * @param $author int author id * @param $formatted_data array formatted stats * @param $raw_data array sorted stats */ function ppc_email_td_html( $field_value, $column_name, $author_stats, $author_id ) { global $ppc_global_settings; //Only add column to general stats page if( $ppc_global_settings['current_page'] != 'stats_general' ) return $field_value; if( $column_name != 'author_email' ) return $field_value; $perm = new PPC_permissions(); if( $perm->can_mark_as_paid() OR $perm->can_see_paypal_functions() ) { $user_data = get_userdata( $author_id ); $author_email = $user_data->user_email; return $author_email; } return $field_value; }
David says
Thanks Stefano, this is great. Which file do we edit?
Stefano says
You should wrap that into a new custom plugin, or put it into your theme functions.php file. This will ensure that it will keep working even with future updates of Post Pay Counter.