<?php 
/*
Plugin Name: PostsByAuthor
Plugin URI: http://www.javivicente.com/plugins-wordpress/wp-plugin-posts-by-author/
Description: Muestra el numero de blogs por autor y mes en el panel de administracion 
Version: 1.0
Author: Javi Vicente
Author URI: http://www.javivicente.com
*/                                     
                         
//periodo puede valer 'mes', 'dia', 'anno' e indica el numero de posts por periodo
//$periodo="mes";                 
$current_time = (current_time(timestamp,"1") + get_settings('gmt_offset') * 3600); //Hora en segundos

function pa_muestra() {
    global 
$dirPlugin;
  global 
$wpdb,$fs_tabla,$version$now
    include_once (
ABSPATH.'/wp-admin/upgrade-functions.php');    
    
//echo $now;
    //pa_muestra(); //mostramos la pagina        

  
?><div class="wrap"><?php
    
    $now 
gmdate('Y-m-d H:i:59');
    
$results=$wpdb->get_results("SELECT DISTINCT YEAR(post_date) AS `year`, MONTH(post_date) AS `month`, count(ID) as posts FROM $wpdb->posts WHERE post_date < '$now' AND post_date != '0000-00-00 00:00:00' AND post_status = 'publish' GROUP BY YEAR(post_date), MONTH(post_date) ORDER BY post_date DESC" $limit);
    
?>                                                                                                                  
    <form id="pa_archiveform" name="pa_archiveform" method="post" action="">
      <select name="param" onchange="(document.forms.pa_archiveform.param[document.forms.pa_archiveform.param.selectedIndex].value);document.pa_archiveform.submit();">
      <option>Selecciona mes</option>
  <?php 
     
if ( $results ) {
        foreach ( 
$results as $result ) {                                                                            
              
$fecha=$result->year."-".$result->month."-01";
                
$fecha=strtotime($fecha);    
              echo 
"<option value='?=".$result->year.$result->month."'>".date("F Y"$fecha)."</option>";
            }
     }
    
     
?>
      </select>
    </form>

<?php    if (isset($_POST['param'])) { //si se recogen parametros
     
$year=substr($_POST['param'],2,4);
     
$mes=substr($_POST['param'],6,2);
     if (
strlen($mes)==1) {
      
$mes="0".$mes;
     }
     echo 
"<h1>".$mes." - ".$year."</h1>";

     
$sql "SELECT DISTINCT count( a.ID ) AS posts, display_name"
        
" FROM wp_posts a, wp_users b"
        
" WHERE post_date like '".$year."-".$mes."%'"
        
" AND post_date != '0000-00-00 00:00:00'"
        
" AND post_status = 'publish'"
        
" AND b.ID=a.post_author"
        
" GROUP BY display_name"
        
" LIMIT 0 , 30";
     
//echo $sql;
     
$results=$wpdb->get_results($sql);        
     if ( 
$results ) {                                 
        
$total=0;
        foreach ( 
$results as $result ) {                                                                            
              echo 
"<br /><strong>".$result->display_name."</strong> escribi&oacute; ".$result->posts." posts";
                
$total=$total+$result->posts;
            }                 
            echo 
"<br /><br />Total: ".$total." posts";
     }
     
                
     
     
    }                            
?>        
        
  </div>

    
<?php }    

/* Añadimos la página al menú administrador */
function pa_menuAdmin() {
        
add_submenu_page('users.php','PostsByAuthor''Posts By Author'6__FILE__,'pa_muestra');
}    

add_action('admin_menu','pa_menuAdmin'); /* MENU ADMINISTRADOR */

?>