SHARE
TWEET

Restore Post Format Icons

SergeyBiryukov Jul 10th, 2019 (edited) 85 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. /*
  3. Plugin Name: Restore Post Format Icons
  4. Description: Restores post format icons in list tables, removed in WordPress 5.2.
  5. Author: Sergey Biryukov
  6. Author URI: http://profiles.wordpress.org/sergeybiryukov/
  7. Version: 1.0
  8. */
  9.  
  10. class Restore_Post_Format_Icons {
  11.  
  12.     function __construct() {
  13.         add_filter( 'manage_posts_columns',       array( $this, 'add_column' ), 10, 2 );
  14.         add_action( 'manage_posts_custom_column', array( $this, 'display_column' ), 10, 2 );
  15.         add_action( 'admin_enqueue_scripts',      array( $this, 'add_inline_style' ) );
  16.     }
  17.  
  18.     function add_column( $posts_columns, $post_type ) {
  19.         $filtered_columns = array();
  20.  
  21.         foreach ( $posts_columns as $key => $column ) {
  22.             if ( 'title' === $key ) {
  23.                 $filtered_columns['format'] = '<span class="dashicons dashicons-images-alt"></span>';
  24.             }
  25.  
  26.             $filtered_columns[ $key ] = $column;
  27.         }
  28.  
  29.         return $filtered_columns;
  30.     }
  31.  
  32.     function display_column( $column_name, $post_id ) {
  33.         if ( 'format' !== $column_name ) {
  34.             return;
  35.         }
  36.  
  37.         $format = get_post_format( $post_id );
  38.         if ( $format ) {
  39.             printf( '<span class="post-format-icon post-format-%s"></span>', esc_attr( $format ) );
  40.         } else {
  41.             echo '<span aria-hidden="true">&#8212;</span>';
  42.         }
  43.     }
  44.  
  45.     function add_inline_style( $hook_suffix ) {
  46.         if ( 'edit.php' !== $hook_suffix ) {
  47.             return;
  48.         }
  49.  
  50.         wp_add_inline_style( 'wp-admin', '.fixed .column-format { width: 1em }' );
  51.     }
  52.  
  53. }
  54.  
  55. new Restore_Post_Format_Icons;
  56. ?>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top