Post Pay Counter

The best way to pay authors on WordPress

  • Features
    • PRO version
  • Cart
    • Addons
  • Documentation
  • Support

Add a custom column to the stats table

December 3, 2018 by Stefano 2 Comments

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;
}
  • Was this Helpful ?
  • Yes   No
Post Views: 657

Filed Under: Developer documentation, Tutorials

Comments

  1. David says

    December 3, 2018 at 7:33 pm

    Thanks Stefano, this is great. Which file do we edit?

    Reply
    • Stefano says

      December 3, 2018 at 7:37 pm

      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.

      Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Your cart

Number of items in cart: 0

  • Your cart is empty.
  • Total: €0.00
  • Checkout

What are you looking for?

Copyright © 2025 · Centric Theme on Genesis Framework · WordPress · Log in