Skip to:
Content

BuddyPress.org

Changeset 10416


Ignore:
Timestamp:
12/18/2015 10:40:06 PM (11 years ago)
Author:
djpaul
Message:

Core, Admin: register scripts/styles before enqueuing.

This mirrors the change introduced in bp_core_register_common_scripts
in BP 2.1, which gave us a central place to register common,
non-component specific, scripts and styles to be used elsewhere,
without duplicating the enqueue.

This will be used by #6592.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-core/bp-core-admin.php

    r10414 r10416  
    143143
    144144                // Enqueue all admin JS and CSS.
     145                add_action( 'bp_admin_enqueue_scripts', array( $this, 'admin_register_styles' ), 1 );
     146                add_action( 'bp_admin_enqueue_scripts', array( $this, 'admin_register_scripts' ), 1 );
    145147                add_action( 'bp_admin_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
    146148
     
    474476         */
    475477        public function enqueue_scripts() {
    476                 $min = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
    477 
    478                 $file = $this->css_url . "common{$min}.css";
    479 
    480                 /**
    481                  * Filters the BuddyPress Core Admin CSS file path.
    482                  *
    483                  * @since 1.6.0
    484                  *
    485                  * @param string $file File path for the admin CSS.
    486                  */
    487                 $file = apply_filters( 'bp_core_admin_common_css', $file );
    488                 wp_enqueue_style( 'bp-admin-common-css', $file, array(), bp_get_version() );
    489 
    490                 wp_style_add_data( 'bp-admin-common-css', 'rtl', true );
    491                 if ( $min ) {
    492                         wp_style_add_data( 'bp-admin-common-css', 'suffix', $min );
    493                 }
     478                wp_enqueue_style( 'bp-admin-common-css' );
    494479        }
    495480
     
    889874                return $display;
    890875        }
     876
     877        /**
     878         * Register styles commonly used by BuddyPress wp-admin screens.
     879         *
     880         * @since 2.5.0
     881         */
     882        public function admin_register_styles() {
     883                $min = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
     884                $url = $this->css_url;
     885
     886                /**
     887                 * Filters the BuddyPress Core Admin CSS file path.
     888                 *
     889                 * @since 1.6.0
     890                 *
     891                 * @param string $file File path for the admin CSS.
     892                 */
     893                $common_css = apply_filters( 'bp_core_admin_common_css', "{$url}common{$min}.css" );
     894
     895                /**
     896                 * Filters the BuddyPress admin stylesheet files to register.
     897                 *
     898                 * @since 2.5.0
     899                 *
     900                 * @param array $value Array of admin stylesheet file information to register.
     901                 */
     902                $styles = apply_filters( 'bp_core_admin_register_styles', array(
     903                        // Legacy
     904                        'bp-admin-common-css' => array(
     905                                'file'         => $common_css,
     906                                'dependencies' => array(),
     907                        ),
     908                ) );
     909
     910
     911                $version = bp_get_version();
     912
     913                foreach ( $styles as $id => $style ) {
     914                        wp_register_style( $id, $style['file'], $style['dependencies'], $version );
     915                        wp_style_add_data( $id, 'rtl', true );
     916
     917                        if ( $min ) {
     918                                wp_style_add_data( $id, 'suffix', $min );
     919                        }
     920                }
     921        }
     922
     923        /**
     924         * Register JS commonly used by BuddyPress wp-admin screens.
     925         *
     926         * @since 2.5.0
     927         */
     928        public function admin_register_scripts() {
     929                $min = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
     930                $url = $this->js_url;
     931
     932                /**
     933                 * Filters the BuddyPress admin JS files to register.
     934                 *
     935                 * @since 2.5.0
     936                 *
     937                 * @param array $value Array of admin JS file information to register.
     938                 */
     939                $scripts = apply_filters( 'bp_core_admin_register_scripts', array(
     940                ) );
     941
     942
     943                $version = bp_get_version();
     944
     945                foreach ( $scripts as $id => $script ) {
     946                        wp_register_script( $id, $script['file'], $script['dependencies'], $version, $script['footer'] );
     947                }
     948        }
    891949}
    892950endif; // End class_exists check.
Note: See TracChangeset for help on using the changeset viewer.