prefix.'author_performance ( `id` int(11) NOT NULL AUTO_INCREMENT, `post_title` text NOT NULL, `post_id` int(11) NOT NULL, `post_author_id` int(11) NOT NULL, `word_count` int(11) NOT NULL, `date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1;'; $wpdb->query($query); } function author_performance_top_authors_by_word_count ($count,$usermeta='yes') { global $wpdb; $rec1=$wpdb->get_results("select SUM(word_count) as wc,COUNT(id) as tc,post_author_id from $wpdb->prefix"."author_performance group by post_author_id order by wc desc limit $count"); foreach ($rec1 as $rec2) { $a++; $top_authors[$a]['author_id']=$rec2->post_author_id; $top_authors[$a]['word_count']=$rec2->wc; $top_authors[$a]['post_count']=$rec2->tc; if ($usermeta=='yes') { $user_data=$wpdb->get_row("select * from $wpdb->users where ID=$rec2->post_author_id"); $top_authors[$a]['display_name']=$user_data->display_name; $top_authors[$a]['login_name']=$user_data->user_login; } } return $top_authors; } // TOP AUTHORS BY TITLE COUNT function author_performance_top_authors_by_post_count ($count,$usermeta='yes') { global $wpdb; $rec1=$wpdb->get_results("select SUM(word_count) as wc,COUNT(id) as tc,post_author_id from $wpdb->prefix"."author_performance group by post_author_id order by tc desc limit $count"); foreach ($rec1 as $rec2) { $a++; $top_authors[$a]['author_id']=$rec2->post_author_id; $top_authors[$a]['word_count']=$rec2->wc; $top_authors[$a]['post_count']=$rec2->tc; if ($usermeta=='yes') { $user_data=$wpdb->get_row("select * from $wpdb->users where ID=$rec2->post_author_id"); $top_authors[$a]['display_name']=$user_data->display_name; $top_authors[$a]['login_name']=$user_data->user_login; } } return $top_authors; } // LONGEST POSTS function author_performance_longest_posts ($count,$usermeta='yes') { global $wpdb; $rec1=$wpdb->get_results("select * from $wpdb->prefix"."author_performance order by word_count desc limit $count"); foreach ($rec1 as $rec2) { $a++; $top_authors[$a]['post_title']=$rec2->post_title; $top_authors[$a]['word_count']=$rec2->word_count; $top_authors[$a]['link']=$wpdb->get_var("select guid from $wpdb->posts where ID=$rec2->post_id"); if ($usermeta=='yes') { $user_data=$wpdb->get_row("select * from $wpdb->users where ID=$rec2->post_author_id"); $top_authors[$a]['display_name']=$user_data->display_name; $top_authors[$a]['login_name']=$user_data->user_login; } } return $top_authors; } // LONGEST POST BY AUTHOR function author_performance_longest_post_by_author ($authorid,$count) { global $wpdb; $rec1=$wpdb->get_results("select * from $wpdb->prefix"."author_performance where post_author_id=$authorid order by word_count desc limit $count"); foreach ($rec1 as $rec2) { $a++; $top_authors[$a]['post_title']=$rec2->post_title; $top_authors[$a]['word_count']=$rec2->word_count; $top_authors[$a]['link']=$wpdb->get_var("select guid from $wpdb->posts where ID=$rec2->post_id"); } return $top_authors; } function author_performance_update() { global $wpdb; $recs=$wpdb->get_results("SELECT ID, post_title,post_content,post_author FROM $wpdb->prefix"."posts WHERE post_type='post' AND post_status='publish' ORDER BY ID DESC"); foreach ($recs as $record) { $word_count=count(str_word_count($record->post_content,1,'öçÖÇŞİşiIğĞüÜ')); $yaz=$wpdb->query("INSERT INTO $wpdb->prefix"."author_performance (post_title,post_id,post_author_id,word_count) VALUES ('$record->post_title',$record->ID , $record->post_author, $word_count)"); } echo "

Table updated. Click here.

"; } function author_performance_update_table() { // DO I HAVE TO UPDATE? if (get_option("author_performance_count_on_save")=='1'){ global $wpdb; $del=$wpdb->query("TRUNCATE $wpdb->prefix"."author_performance"); //echo "update"; } } function author_performance_options() { global $wpdb; $rec_count=$wpdb->get_var("select count(id) from $wpdb->prefix"."author_performance"); ?>

No records yet. Click the update button to count posts and generate authors table. This will take a while depending on post count and lenght.

" />

/>

" />

TOP AUTHORS BY WORD COUNT
Author Name Word Count Post Count
Usage: $var=author_performance_top_authors_by_word_count(2,'yes'); This gives an array of two authors, sorted by word count in posts. If you omit the second parameter, author data will not be queried. You can use foreach loop to output data. For further usage, visit Author Performance page.
TOP AUTHORS BY POST COUNT
Author Name Word Count Post Count
Usage: $var=author_performance_top_authors_by_post_count(2,'yes'); This example gives an array of two authors, sorted by post count. If you omit the second parameter, author data will not be queried. You can use foreach loop to output data. For further usage, visit Author Performance page.
LONGEST POSTS
Author Name Word Count Post Title
Usage: $var=author_performance_longest_posts(2,'yes'); This example gives an array of two longest posts, sorted by word count. If you omit the second parameter, author data will not be queried. You can use foreach loop to output data. For further usage, visit Author Performance page.
LONGEST POSTS BY AUTHOR ID
Author Name Word Count Post Title
Usage: $var=author_performance_longest_post_by_author(1,2); This example gives an array of two longest posts, sorted by word count, written by author having ID=2 (These ID's come from Wordpress users' database). You can use foreach loop to output data. For further usage, visit Author Performance page.
get_row("select count(id) as postcount,sum(word_count) as wordcount, COUNT(DISTINCT post_author_id) as author_count from $wpdb->prefix"."author_performance"); if ($recs->wordcount>0) { $a_count=$wpdb->get_var("select distinct count(post_author_id) from $wpdb->prefix"."author_performance"); echo "

"."There are $recs->author_count author(s) who wrote $recs->wordcount words and $recs->postcount posts. "."Click for details.

"; } else { echo "

You have to initialize database first. Click here to initialize and update database.

"; } } function author_performance_dashboard_widget() { wp_add_dashboard_widget( 'author_performance_dashboard_widget', __( 'Author Performance' ), 'author_performance_dashboard_widget_function' ); } add_action('wp_dashboard_setup', 'author_performance_dashboard_widget'); add_action('admin_menu', 'add_ap_menu'); add_action ( 'save_post', 'author_performance_update_table'); function add_ap_menu() { add_options_page('Author Performance','Author Performance', 'administrator', 'options_ap', 'author_performance_options'); } register_activation_hook( __FILE__, 'author_performance_activate' ); ?>