Plugin Author
Ste_95
(@ste_95)
Hi there,
I believe something like this should work, although I haven’t tested it so it might require some tweaking 🙂
add_action( 'ppc_general_stats_format_stats_after_cols_default', function( $cols ) {
$cols['author_words_real'] = 'Real words';
return $cols;
});
add_filter( 'ppc_general_stats_each_field_empty_value', function( $field_value, $field_name, $raw_author_stats, $author ) {
if( $field_name == 'author_words_real' and isset( $raw_author_stats['total']['ppc_count']['normal_count']['words'] ) )
$field_value = $raw_author_stats['total']['ppc_count']['normal_count']['words']['real'];
return $field_value;
}, 10, 4 );
The new column will go towards the end though.
A nice day,
Stefano
Stefano,
THANK YOU so much. I think just about nailed it.
I changed _general_ to _author_ but it’s throwing an argument count error.
I’m unclear regarding how to get data from your class to feed to the function in my template function file.
Any additional tips would be welcome, but no worries. You’ve already given me some ideas.
Fatal error: Uncaught ArgumentCountError: Too few arguments to function {closure}(), 2 passed in /wp-includes/class-wp-hook.php on line 287
and exactly 4 expected in /wp-content/themes/tna/inc/post_pay_counter.php:13
Stack trace:
#0 /wp-includes/class-wp-hook.php(287): {closure}('N.A.', 'author_words_re...')
#1 /wp-includes/plugin.php(206): WP_Hook->apply_filters('N.A.', Array)
#2 /wp-content/plugins/post-pay-counter/classes/ppc_wp_list_table_posts_class.php(157): apply_filters('ppc_author_stat...', 'N.A.', 'author_words_re...')
#3 /wp-admin/includes/class-wp-list-table.php(1410): Post_Pay_Counter_Posts_List_Table->column_default(Array, 'author_words_re...')
#4 /wp-admin/includes/class-wp-list-table.php(1350): WP_List_Table->single_row_columns(Array)
#5 /wp-admin/includes/class-wp-list-table.php(1337): WP_List_Table->single_row(Array)
#6 /wp-content/themes/tna/inc/post_pay_counter.php on line 13
Plugin Author
Ste_95
(@ste_95)
If you want it in the author page the second filter is different.
This should work 🙂
add_action( 'ppc_author_stats_format_stats_after_cols_default', function( $cols ) {
$cols['post_words_real'] = 'Real words';
return $cols;
});
add_filter( 'ppc_author_stats_html_each_field_value', function( $field_value, $field_name, $post ) {
if( $field_name == 'post_words_real' and isset( $post->ppc_count['normal_count']['words'] ) )
$field_value = $post->ppc_count['normal_count']['words']['real'];
return $field_value;
}, 10, 3 );
Thank you again for trying to help me make this happen.
The column value doesn’t populate, but instead throws the “N.A.” for the empty value.
Plugin Author
Ste_95
(@ste_95)
I apologize, my mistake! This should work 🙂
add_filter( 'ppc_author_stats_format_stats_after_cols_default', function( $cols ) {
$cols['post_words_real'] = 'Real words';
return $cols;
});
add_filter( 'ppc_author_stats_format_stats_after_each_default', function( $post_formatted_stats, $author_id, $post ) {
$post_formatted_stats['post_words_real'] = $post->ppc_count['normal_count']['words']['real'];
return $post_formatted_stats;
}, 10, 3 );
Ste_95: You nailed it. Thank you so much!