word_count(); //echo $cpwcpost->word_count(); endif;//column label is cpwordcount } //define submenu function cp_wc_csv_dl_page() { echo '

Download Word Count CSV


'; if(isset($_GET['category'])): echo '

Filtered by category


'; endif; if(isset($_GET['date'])): echo '

Filtered by date range


'; endif; //unlink('cpwc.csv'); $cpwcdlurl = plugin_dir_url('/admin-word-count-column/wc-column.php'); $cpwcdir = WP_PLUGIN_DIR . plugin_dir_path('/admin-word-count-column/wc-column.php'); $cpcsv = fopen($cpwcdir . 'cpwc.csv', 'w+'); $cpwcargs = array('posts_per_page'=>-1,'orderby'=>'post_date','order'=>'DESC'); $cpwccsvheader = array('Date','Author','Title','Words','Target','Completion'); fputcsv($cpcsv, $cpwccsvheader); query_posts( $cpwcargs ); while ( have_posts() ) : the_post();//running through query_posts $awcpost = new CPWordCount(get_the_id()); fputcsv($cpcsv, $awcpost->csv_row()); endwhile; fclose($cpcsv); echo '

SPREADSHEET UPDATED.

'; echo 'Download aforementioned CSV file'; } class CPWordCount {//this object represents the word count of a single post. public static $id = false; public static $csvheader = ''; function __construct($postid) { $id = $postid; } function csv_row() {//formatted for putcsv() $row = array(get_the_date('M j Y'),get_the_author(),get_the_title(),$this->word_count(),$this->target_count(),$this->target_completion()); return $row; } function word_count() { return str_word_count(get_the_content($this::$id)); } function target_count() { } function target_completion() { } } ?>