Listagem de todos os arquivos carregados em sites de rede

Posso listar todos os arquivos carregados pelos usuários nos sites da Rede? Em Multisite, cada usuário pode gerenciar seus arquivos com seu próprio blog, mas o Super admin não pode monitorar todos os arquivos carregados … como posso fazer isso?

Solutions Collecting From Web of "Listagem de todos os arquivos carregados em sites de rede"

Você precisa percorrer cada blog e buscar os anexos recentes com:

 $args = array ( 'post_type' => 'attachment', 'numberposts' => 30 ); $attachments = get_posts( $args ); 

Os widgets do painel são registrados no wp_network_dashboard_setup em multi-site e wp_dashboard_setup em um único site.

Certifique-se de adicionar a seguinte linha ao header do plugin para obter a rede de plugins habilitada.

  * Network: true 

Então você pode obter uma tabela como esta:

insira a descrição da imagem aqui

(do meu site de desenvolvimento local, sim, parece um pouco estranho)

Plugin de exemplo, muito cru!

 < ?php # -*- coding: utf-8 -*- /** * Plugin Name: List recent uploads in a network * Version: 2013.04.21 * Network: true */ if ( is_multisite() ) add_action( 'wp_network_dashboard_setup', array ( 'T5_Recent_Uploads_Dashboard_Widget', 'register' ) ); else add_action( 'wp_dashboard_setup', array ( 'T5_Recent_Uploads_Dashboard_Widget', 'register' ) ); class T5_Recent_Uploads_Dashboard_Widget { protected static $instance = NULL; protected $max_items = 30; public static function register() { self::$instance = new self; wp_add_dashboard_widget( __CLASS__, 'Recent Uploads', array ( self::$instance, 'render' ) ); } public function render() { $uploads = $this->get_recent_uploads(); if ( empty ( $uploads ) ) return print '

No new uploads

'; printf( '

%d new uploads.

', count( $uploads ) ); print $this->get_attachment_table( $uploads ); // inspect content here //print '
$uploads = ' . htmlspecialchars( var_export( $uploads, TRUE ), ENT_QUOTES, 'utf-8', FALSE ) . '

'; } protected function get_recent_uploads() { if ( ! is_multisite() ) return $this->get_attachments(); $uploads = array(); $current_blog = get_current_blog_id(); $blogs = $this->get_blog_ids(); foreach ( $blogs as $blog ) { switch_to_blog( $blog->blog_id ); $attachments = $this->get_attachments(); foreach ( $attachments as $attachment ) $uploads[] = $this->prepare_attachment( $attachment, $blog ); } // restore current blog switch_to_blog( $current_blog ); return array_slice( $uploads, 0, $this->max_items ); } protected function prepare_attachment( $attachment, $blog ) { https://wordpress.stackexchange.com//questions/96644/listing-of-all-uploaded-files-in-network-sites/$attachment->blog_id = $blog->blog_id; https://wordpress.stackexchange.com//questions/96644/listing-of-all-uploaded-files-in-network-sites/$attachment->blog_name = get_bloginfo( 'name' ); https://wordpress.stackexchange.com//questions/96644/listing-of-all-uploaded-files-in-network-sites/$attachment->edit = get_edit_post_link( https://wordpress.stackexchange.com//questions/96644/listing-of-all-uploaded-files-in-network-sites/$attachment->ID ); return $attachment; } protected function get_blog_ids() { global $wpdb; $query = $wpdb->prepare( "SELECT blog_id FROM $wpdb->blogs WHERE site_id = %d AND public = '1' AND archived = '0' AND mature = '0' AND spam = '0' AND deleted = '0' ORDER BY blog_id", $wpdb->siteid ); return $wpdb->get_results( $query ); } protected function get_attachment_table( $attachments ) { $table = '

' . $this->get_table_header() . '

'; foreach ( $attachments as $attachment ) $table .= $this->get_row( $attachment ); return "$table

"; } protected function get_attachments() { $args = array ( 'post_type' => 'attachment', 'numberposts' => $this->max_items ); return get_posts( $args ); } protected function get_table_header() { $columns = array ( 'Attachment', 'User', 'Date' ); if ( is_multisite() ) $columns[] = 'Site'; $header = '

' . join( ' ', $columns ) . '

'; return "

$header $header

"; } protected function get_row( $attachment ) { $cells = array (); $cells[] = $this->get_attachment_title( $attachment ); $cells[] = $this->get_user_link( $attachment ); $cells[] = mysql2date( 'Ymd', https://wordpress.stackexchange.com//questions/96644/listing-of-all-uploaded-files-in-network-sites/$attachment->post_date ); if ( is_multisite() ) $cells[] = https://wordpress.stackexchange.com//questions/96644/listing-of-all-uploaded-files-in-network-sites/$attachment->blog_name; return '

' . join( ' ', $cells ) . '

'; } protected function get_attachment_title( $attachment ) { $title = https://wordpress.stackexchange.com//questions/96644/listing-of-all-uploaded-files-in-network-sites/$attachment->post_title; if ( empty ( $title ) ) $title = basename( https://wordpress.stackexchange.com//questions/96644/listing-of-all-uploaded-files-in-network-sites/$attachment->guid ); return "$title"; } protected function get_user_link( $attachment ) { $name = get_the_author_meta( 'nickname', https://wordpress.stackexchange.com//questions/96644/listing-of-all-uploaded-files-in-network-sites/$attachment->post_author ); https://wordpress.stackexchange.com//questions/96644/listing-of-all-uploaded-files-in-network-sites/$url = network_admin_url( 'user-edit.php?user_id=' . https://wordpress.stackexchange.com//questions/96644/listing-of-all-uploaded-files-in-network-sites/$attachment->post_author ); return "$name"; } }

O WordPress 3.7 apresentou wp_get_sites () que retornará uma série de sites em uma rede Multisite WordPress. Isso pode replace get_blog_ids ().