Making WordPress.org

Changeset 7815


Ignore:
Timestamp:
11/01/2018 08:40:23 PM (8 years ago)
Author:
coffee2code
Message:

Developer: Centralize enqueuing of admin stylesheet.

Adds helper get_parsed_post_types_screen_ids().

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

Legend:

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

    r7797 r7815  
    2222         */
    2323        public static function do_init() {
     24                add_action( 'admin_enqueue_scripts', [ __CLASS__, 'admin_enqueue_scripts' ] );
     25       
    2426                add_action( 'comment_author', [ __CLASS__, 'append_user_nicename' ], 10, 2 );
    2527
     
    3032                        // Reset votes after editing a comment in the wp-admin.
    3133                        add_filter( 'comment_edit_redirect',  [ __CLASS__, 'comment_edit_redirect'], 10, 2 );
     34                }
     35        }
     36
     37        /**
     38         * Returns array of screen IDs for parsed post types.
     39         *
     40         * @access public
     41         *
     42         * @return array
     43         */
     44        public static function get_parsed_post_types_screen_ids() {
     45                $screen_ids = [];
     46                foreach ( DevHub\get_parsed_post_types() as $parsed_post_type ) {
     47                        $screen_ids[] = $parsed_post_type;
     48                        $screen_ids[] = "edit-{$parsed_post_type}";
     49                }
     50
     51                return $screen_ids;
     52        }
     53
     54        /**
     55         * Enqueue JS and CSS on the edit screens for all parsed post types.
     56         *
     57         * @access public
     58         */
     59        public static function admin_enqueue_scripts() {
     60                // By default, only enqueue on parsed post type screens.
     61                $screen_ids = self::get_parsed_post_types_screen_ids();
     62
     63                /**
     64                 * Filters whether or not admin.css should be enqueued.
     65                 *
     66                 * @param bool True if admin.css should be enqueued, false otherwise.
     67                 */
     68                if ( (bool) apply_filters( 'devhub-admin_enqueue_scripts', in_array( get_current_screen()->id, $screen_ids ) ) ) {
     69                        wp_enqueue_style( 'wporg-admin', get_template_directory_uri() . '/stylesheets/admin.css', [], '20160630' );
    3270                }
    3371        }
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/inc/explanations.php

    r7814 r7815  
    6161
    6262                // Script and styles.
     63                add_filter( 'devhub-admin_enqueue_scripts', array( $this, 'admin_enqueue_base_scripts' ) );
    6364                add_action( 'admin_enqueue_scripts',   array( $this, 'admin_enqueue_scripts'  )        );
    6465
     
    441442
    442443        /**
     444         * Enables enqueuing of admin.css for explanation pages.
     445         *
     446         * @access public
     447         *
     448         * @param bool $do_enqueue Should admin.css be enqueued?
     449         * @return bool True if admin.css should be enqueued, false otherwise.
     450         */
     451        public function admin_enqueue_base_scripts( $do_enqueue ) {
     452                return $do_enqueue || in_array( get_current_screen()->id, $this->screen_ids  );
     453        }
     454
     455        /**
    443456         * Enqueue JS and CSS for all parsed post types and explanation pages.
    444457         *
     
    447460        public function admin_enqueue_scripts() {
    448461
    449                 $parsed_post_types = array();
    450 
    451                 foreach ( \DevHub\get_parsed_post_types() as $post_type ) {
    452                         $parsed_post_types[] = $post_type;
    453                         $parsed_post_types[] = "edit-{$post_type}";
    454                 }
     462                $parsed_post_types_screen_ids = DevHub_Admin::get_parsed_post_types_screen_ids();
    455463
    456464                if ( in_array( get_current_screen()->id, array_merge(
    457                                 $parsed_post_types,
     465                                $parsed_post_types_screen_ids,
    458466                                $this->screen_ids
    459467                ) ) ) {
    460                         wp_enqueue_style( 'wporg-admin', get_template_directory_uri() . '/stylesheets/admin.css', array(), '20160630' );
    461468                        wp_enqueue_script( 'wporg-explanations', get_template_directory_uri() . '/js/explanations.js', array( 'jquery', 'wp-util' ), '20160630', true );
    462469
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/inc/parsed-content.php

    r3609 r7815  
    164164                // Only enqueue 'wporg-parsed-content' script and styles on Code Reference post type screens.
    165165                if ( in_array( get_current_screen()->id, $this->post_types ) ) {
    166                         wp_enqueue_style( 'wporg-admin', get_template_directory_uri() . '/stylesheets/admin.css', array(), '20160630' );
    167166                        wp_enqueue_script( 'wporg-parsed-content', get_template_directory_uri() . '/js/parsed-content.js', array( 'jquery', 'utils' ), '20150824', true );
    168167
Note: See TracChangeset for help on using the changeset viewer.