Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /* referente ao tutorial: http://rozanchetta.wordpress.com/2011/10/12/area-de-clientes-colunas-administracao-cpt */
- // ARQUIVO PARA OS CUSTOM POST TYPES DO TEMA
- /* CPT DOCUMENTOS */
- add_action( 'init', 'register_cpt_documentos' );
- function register_cpt_documentos() {
- $labels = array(
- 'name' => _x( 'Documentos', 'documentos' ),
- 'singular_name' => _x( 'Documento', 'documentos' ),
- 'add_new' => _x( 'Adicionar Documento', 'documentos' ),
- 'add_new_item' => _x( 'Adicionar Novo Documento', 'documentos' ),
- 'edit_item' => _x( 'Editar Documento', 'documentos' ),
- 'new_item' => _x( 'Novo Documento', 'documentos' ),
- 'view_item' => _x( 'Ver Documento', 'documentos' ),
- 'search_items' => _x( 'Localizar documentos', 'documentos' ),
- 'not_found' => _x( 'Nenhum Documento encontrado', 'documentos' ),
- 'not_found_in_trash' => _x( 'Não há documentos na Lixeira', 'documentos' ),
- 'parent_item_colon' => _x( 'Pai Documento:', 'documentos' ),
- 'menu_name' => _x( 'Documentos de Clientes', 'documentos' ), /* "Documentos de Clientes" será o texto que vai aparecer no menu do painel */
- );
- $args = array(
- 'labels' => $labels,
- 'hierarchical' => true,
- 'supports' => array( 'title', 'author', 'editor', 'comments' ),
- 'taxonomies' => array( 'cliente' ), /* "Cliente" será a taxonomia para o CPT documentos */
- 'public' => true,
- 'show_ui' => true,
- 'show_in_menu' => true,
- 'menu_position' => 5,
- 'menu_icon' => 'http://acharme.com.br/testesrozanchetta/wp-content/themes/tema-base/images/documentos-icone.gif', /* Crie uma imagem de 16x16 px e salve em seu tema */
- 'show_in_nav_menus' => true,
- 'publicly_queryable' => true,
- 'exclude_from_search' => true,
- 'has_archive' => true,
- 'query_var' => true,
- 'can_export' => true,
- 'rewrite' => true,
- 'capability_type' => 'post'
- );
- register_post_type( 'documentos', $args );
- }
- // T A X O N O M I A S
- /* TAX:CLIENTE - PARA O CPT DOCUMENTOS */
- add_action( 'init', 'register_taxonomy_cliente' );
- function register_taxonomy_cliente() {
- $labels = array(
- 'name' => _x( 'Clientes', 'cliente' ),
- 'singular_name' => _x( 'Cliente', 'cliente' ),
- 'search_items' => _x( 'Localizar Cliente', 'cliente' ),
- 'popular_items' => _x( 'Clientes Populares', 'cliente' ),
- 'all_items' => _x( 'Todos os Clientes', 'cliente' ),
- 'parent_item' => _x( 'Cliente Pai', 'cliente' ),
- 'parent_item_colon' => _x( 'Cliente Pai:', 'cliente' ),
- 'edit_item' => _x( 'Editar Cliente', 'cliente' ),
- 'update_item' => _x( 'Atualizar Cliente', 'cliente' ),
- 'add_new_item' => _x( 'Adicionar Novo Cliente', 'cliente' ),
- 'new_item_name' => _x( 'Novo Nome de Cliente', 'cliente' ),
- 'separate_items_with_commas' => _x( 'Separe por vírgulas', 'cliente' ),
- 'add_or_remove_items' => _x( 'Adicionar ou remover Cliente', 'cliente' ),
- 'choose_from_most_used' => _x( 'Escolha entre os mais usados', 'cliente' ),
- 'menu_name' => _x( 'Clientes', 'cliente' ),
- );
- $args = array(
- 'labels' => $labels,
- 'public' => true,
- 'show_in_nav_menus' => true,
- 'show_ui' => true,
- 'show_tagcloud' => true,
- 'hierarchical' => true,
- 'rewrite' => true,
- 'query_var' => true
- );
- register_taxonomy( 'cliente', array('documentos'), $args );
- }
- // ADICIONAR COLUNAS AO PAINEL DO CPT DOCUMENTOS
- add_filter( 'manage_edit-documentos_columns', 'meutema_edit_documentos_columns' ) ;
- function meutema_edit_documentos_columns( $columns ) {
- $columns = array(
- 'cb' => '<input type="checkbox" />',
- 'title' => __( 'Documento' ),
- 'author' => __( 'Autor' ),
- 'cliente' => __( 'Cliente' ),
- 'restrito' => __( 'Restrito para' ),
- 'comments' => __( 'Com' ),
- 'date' => __( 'Data' )
- );
- return $columns;
- }
- add_action( 'manage_documentos_posts_custom_column', 'meutema_manage_documentos_columns', 10, 2 );
- function meutema_manage_documentos_columns( $column, $post_id ) {
- switch( $column ) {
- /* Adiciona coluna para a meta box */
- case 'restrito' :
- global $restrito_mb;
- $restrito_mb->the_meta();
- $restrito_mb->the_value('teste_restrito');
- break;
- /* Adiciona coluna para a taxonomia */
- case 'cliente' :
- global $post;
- $terms = get_the_terms( $post_id, 'cliente' );
- if ( !empty( $terms ) ) {
- $out = array();
- foreach ( $terms as $term ) {
- $out[] = sprintf( '<a href="%s">%s</a>',
- esc_url( add_query_arg( array( 'post_type' => $post->post_type, 'cliente' => $term->slug ), 'edit.php' ) ),
- esc_html( sanitize_term_field( 'name', $term->name, $term->term_id, 'cliente', 'display' ) )
- );
- }
- echo join( ', ', $out );
- }
- else {
- _e( 'Nenhum Cliente' );
- }
- break;
- default :
- break;
- }
- }
- /* Habilita a coluna restrito para ser ordenada */
- function restrito_column_register_sortable( $columns ) {
- $columns['restrito'] = 'restrito';
- return $columns;
- }
- add_filter( 'manage_edit-documentos_sortable_columns', 'restrito_column_register_sortable' );
- /* Classifica a coluna restrito */
- function restrito_column_orderby( $vars ) {
- global $restrito_mb;
- if ( isset( $vars['orderby'] ) && 'restrito' == $vars['orderby'] ) {
- $vars = array_merge( $vars, array(
- 'meta_key' => $restrito_mb->get_the_name('teste_restrito'),
- 'orderby' => 'meta_value'
- ) );
- }
- return $vars;
- }
- add_filter( 'request', 'restrito_column_orderby' );
- /* Habilita a coluna cliente para ser ordenada */
- function cliente_column_register_sortable( $columns ) {
- $columns['cliente'] = 'cliente';
- return $columns;
- }
- add_filter( 'manage_edit-documentos_sortable_columns', 'cliente_column_register_sortable' );
- /* Classifica a coluna cliente */
- function cliente_clauses_meutema( $clauses, $wp_query ) {
- global $wpdb;
- if ( isset( $wp_query->query['orderby'] ) && 'cliente' == $wp_query->query['orderby'] ) {
- $clauses['join'] .= <<<SQL
- LEFT OUTER JOIN {$wpdb->term_relationships} ON {$wpdb->posts}.ID={$wpdb->term_relationships}.object_id
- LEFT OUTER JOIN {$wpdb->term_taxonomy} USING (term_taxonomy_id)
- LEFT OUTER JOIN {$wpdb->terms} USING (term_id)
- SQL;
- $clauses['where'] .= " AND (taxonomy = 'cliente' OR taxonomy IS NULL)";
- $clauses['groupby'] = "object_id";
- $clauses['orderby'] = "GROUP_CONCAT({$wpdb->terms}.name ORDER BY name ASC) ";
- $clauses['orderby'] .= ( 'ASC' == strtoupper( $wp_query->get('order') ) ) ? 'ASC' : 'DESC';
- }
- return $clauses;
- }
- add_filter( 'posts_clauses', 'cliente_clauses_meutema', 10, 2 );
- /* Adiciona os CPTs ao Box "Agora" no Painel de Administração */
- function wph_right_now_content_table_end() {
- $args = array(
- 'public' => true ,
- '_builtin' => false
- );
- $output = 'object';
- $operator = 'and';
- $post_types = get_post_types( $args , $output , $operator );
- foreach( $post_types as $post_type ) {
- $num_posts = wp_count_posts( $post_type->name );
- $num = number_format_i18n( $num_posts->publish );
- $text = _n( $post_type->labels->singular_name, $post_type->labels->name , intval( $num_posts->publish ) );
- if ( current_user_can( 'edit_posts' ) ) {
- $num = "<a href='edit.php?post_type=$post_type->name'>$num</a>";
- $text = "<a href='edit.php?post_type=$post_type->name'>$text</a>";
- }
- echo '<tr><td class="first b b-' . $post_type->name . '">' . $num . '</td>';
- echo '<td class="t ' . $post_type->name . '">' . $text . '</td></tr>';
- }
- $taxonomies = get_taxonomies( $args , $output , $operator );
- foreach( $taxonomies as $taxonomy ) {
- $num_terms = wp_count_terms( $taxonomy->name );
- $num = number_format_i18n( $num_terms );
- $text = _n( $taxonomy->labels->singular_name, $taxonomy->labels->name , intval( $num_terms ));
- if ( current_user_can( 'manage_categories' ) ) {
- $num = "<a href='edit-tags.php?taxonomy=$taxonomy->name'>$num</a>";
- $text = "<a href='edit-tags.php?taxonomy=$taxonomy->name'>$text</a>";
- }
- echo '<tr><td class="first b b-' . $taxonomy->name . '">' . $num . '</td>';
- echo '<td class="t ' . $taxonomy->name . '">' . $text . '</td></tr>';
- }
- }
- add_action( 'right_now_content_table_end' , 'wph_right_now_content_table_end' );
Advertisement
Add Comment
Please, Sign In to add comment