Making WordPress.org

Changeset 7816


Ignore:
Timestamp:
11/01/2018 10:31:04 PM (6 years ago)
Author:
coffee2code
Message:

Developer: Add a column in the admin listing of posts for an indicator if the parsed post has an explanation.

Fixes #3900.

Location:
sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/inc/explanations.php

    r7815 r7816  
    4949        add_action( 'init',                    array( $this, 'register_post_type'     ), 0     );
    5050        add_action( 'init',                    array( $this, 'remove_editor_support'  ), 100   );
     51
     52        // Admin.
    5153        add_action( 'edit_form_after_title',   array( $this, 'post_to_expl_controls'  )        );
    5254        add_action( 'edit_form_top',           array( $this, 'expl_to_post_controls'  )        );
     
    5456        add_action( 'admin_menu',              array( $this, 'admin_menu'             )        );
    5557        add_action( 'load-post-new.php',       array( $this, 'prevent_direct_creation')        );
     58        // Add admin post listing column for explanations indicator.
     59        add_filter( 'manage_posts_columns',       array( $this, 'add_post_column'     )        );
     60        // Output checkmark in explanations column if post has an explanation.
     61        add_action( 'manage_posts_custom_column', array( $this, 'handle_column_data'  ), 10, 2 );
    5662
    5763        // Permissions.
     
    543549    }
    544550
     551    /**
     552     * Adds a column in the admin listing of posts for parsed post types to
     553     * indicate if they have an explanation.
     554     *
     555     * Inserted as first column after title column.
     556     *
     557     * @access public
     558     *
     559     * @param array $columns Associative array of post column ids and labels.
     560     * @return array
     561     */
     562    public function add_post_column( $columns ) {
     563        if ( ! empty( $_GET['post_type'] ) && DevHub\is_parsed_post_type( $_GET['post_type'] ) ) {
     564            $index = array_search( 'title', array_keys( $columns ) );
     565            $pos   = false === $index ? count( $columns ) : $index + 1;
     566
     567            $col_data = [ 'has_explanation' => sprintf(
     568                '<span class="dashicons dashicons-info" title="%s"></span><span class="screen-reader-text">%s</span>',
     569                esc_attr__( 'Has explanation?', 'wporg' ),
     570                esc_html__( 'Explanation?', 'wporg' )
     571            ) ];
     572            $columns  = array_merge( array_slice( $columns, 0, $pos ), $col_data, array_slice( $columns, $pos ) );
     573        }
     574
     575        return $columns;
     576    }
     577
     578    /**
     579     * Outputs an indicator for the explanations column if post has an explanation.
     580     *
     581     * @access public
     582     *
     583     * @param string $column_name The name of the column.
     584     * @param int    $post_id     The ID of the post.
     585     */
     586    public function handle_column_data( $column_name, $post_id ) {
     587        if ( 'has_explanation' === $column_name ) {
     588            if ( $explanation = DevHub\get_explanation( $post_id ) ) {
     589                printf(
     590                    '<a href="%s">%s%s</a>',
     591                    get_edit_post_link( $explanation ),
     592                    '<span class="dashicons dashicons-info" aria-hidden="true"></span>',
     593                    '<span class="screen-reader-text">' . __( 'Post has an explanation.', 'wporg' ) . '</span>'
     594                );
     595            }
     596        }
     597    }
     598
    545599}
    546600
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/scss/admin.scss

    r3608 r7816  
    2525
    2626/* Explanations */
     27
     28.fixed {
     29    .column-has_explanation {
     30        width: 2em;
     31
     32        .dashicons {
     33            width: 30px;
     34        }
     35    }
     36
     37    tbody .column-has_explanation a {
     38        color: #72777c;
     39        display: inline-block;
     40        margin-top: 4px;
     41
     42        &:focus, &:hover {
     43            color: #0073aa;
     44        }
     45
     46        .dashicons {
     47            font-size: 26px;
     48        }
     49
     50        .screen-reader-text {
     51            @media screen and (max-width: 782px) {
     52                position: static;
     53                -webkit-clip-path: none;
     54                clip-path: none;
     55                width: auto;
     56                height: auto;
     57                margin: 0;
     58            }
     59        }
     60
     61        & [aria-hidden="true"] {
     62            @media screen and (max-width: 782px) {
     63                display: none;
     64            }
     65        }
     66    }
     67}
    2768
    2869.post-type-wporg_explanations .page-title-action {
     
    81122    width: 100%;
    82123}
     124
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/stylesheets/admin.css

    r3720 r7816  
    2323
    2424/* Explanations */
     25.fixed .column-has_explanation {
     26  width: 2em;
     27}
     28
     29.fixed .column-has_explanation .dashicons {
     30  width: 30px;
     31}
     32
     33.fixed tbody .column-has_explanation a {
     34  color: #72777c;
     35  display: inline-block;
     36  margin-top: 4px;
     37}
     38
     39.fixed tbody .column-has_explanation a:focus, .fixed tbody .column-has_explanation a:hover {
     40  color: #0073aa;
     41}
     42
     43.fixed tbody .column-has_explanation a .dashicons {
     44  font-size: 26px;
     45}
     46
     47@media screen and (max-width: 782px) {
     48  .fixed tbody .column-has_explanation a .screen-reader-text {
     49    position: static;
     50    -webkit-clip-path: none;
     51    clip-path: none;
     52    width: auto;
     53    height: auto;
     54    margin: 0;
     55  }
     56}
     57
     58@media screen and (max-width: 782px) {
     59  .fixed tbody .column-has_explanation a [aria-hidden="true"] {
     60    display: none;
     61  }
     62}
     63
    2564.post-type-wporg_explanations .page-title-action {
    2665  display: none;
Note: See TracChangeset for help on using the changeset viewer.