Advertisement
iEmanuele

Aggiungo in admin post list WP

Feb 10th, 2017
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.75 KB | None | 0 0
  1. <?php
  2.  
  3. /**
  4.  * Aggiungo bottone vista elenco WP ( admin )
  5.  *
  6.  * @uses : remove_query_arg, wp_get_referer
  7.  * @see: http://wordpress.stackexchange.com/questions/149143/hide-the-post-count-behind-post-views-remove-all-published-and-trashed-in-cus
  8.  * @see: https://developer.wordpress.org/reference/functions/remove_query_arg/
  9.  * @see: https://developer.wordpress.org/reference/functions/wp_get_referer/
  10.  *
  11.  * Il filtro è "views_edit-{post_type}"
  12.  *
  13.  * carico il mio pulsante nell'array $views
  14.  */
  15. add_filter('views_edit-annuncio', 'add_custom_clear_button', 10);
  16. function add_custom_clear_button($views){
  17.     $button  = '<a ';
  18.     $button .= 'style="margin-right:5px" ';
  19.     $button .= 'id="clear" ';
  20.     $button .= 'href="'.remove_query_arg( array('fonte', 'localita', 'customer', 'performer', 'performance', 'telefono', 'email'),wp_get_referer()).'" ';
  21.     $button .= 'class="button button-primary" ';
  22.     $button .= '>' . __('Pulisci','safra');
  23.     $button .= '</a>';
  24.  
  25.     $views['clear'] = $button;
  26.  
  27.     return $views;
  28. }
  29.  
  30. /**
  31.  * Sposto il bottone dove credo sia più indicato, non ci sono metodi più puliti per farlo
  32.  *
  33.  * @see : https://codex.wordpress.org/Plugin_API/Action_Reference/admin_head-(page_hook)
  34.  *
  35.  * L'azione è "views_edit-{post_type}"
  36.  * Stampo javascript arbitrario per modificare il DOM a piacere
  37.  */
  38. add_action('admin_head-edit.php', 'move_clear_button', 10);
  39. function move_clear_button(){
  40.     $current_screen = get_current_screen();
  41.     //Se mi trovo in "annunci"
  42.     if( 'annuncio'  == $current_screen->post_type ) : ?>
  43.         <script type="text/javascript">
  44.             jQuery(document).ready(function($){
  45.                 $('#clear').appendTo('.tablenav.top div.alignleft.actions:not(.bulkactions)');    
  46.             });    
  47.         </script>
  48.     <?php endif;
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement