Making WordPress.org


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

Developer: Centralize enqueuing of admin stylesheet.

Adds helper get_parsed_post_types_screen_ids().

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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
Note: See TracChangeset for help on using the changeset viewer.