Make WordPress Core

Ticket #13296: plugin-queue-idea.patch

File plugin-queue-idea.patch, 6.7 KB (added by johnjamesjacoby, 14 years ago)
  • wp-includes/class.wp-plugins.php

     
     1<?php
     2/**
     3 * Plugins enqueue.
     4 *
     5 * @since WP unknown; BP unknown
     6 *
     7 */
     8
     9/**
     10 * Plugins enqueue class.
     11 *
     12 * @uses WP_Dependencies
     13 *
     14 * @since WP unknown; BP unknown
     15 *
     16 */
     17class WP_Plugins extends WP_Dependencies {
     18        var $base_url; // Full URL with trailing slash
     19        var $content_url;
     20
     21        function __construct() {
     22                do_action_ref_array( 'wp_default_plugins', array( &$this ) );
     23        }
     24
     25        /**
     26         * Prints plugins
     27         *
     28         * Prints the plugins passed to it or the print queue.  Also prints all necessary dependencies.
     29         *
     30         * @param mixed handles (optional) Plugins to be printed.  (void) prints queue, (string) prints that plugin, (array of strings) prints those plugins.
     31         * @param int group (optional) If plugins were queued in groups prints this group number.
     32         * @return array Plugins that have been printed
     33         */
     34        function print_plugins( $handles = false, $group = false ) {
     35                return $this->do_items( $handles, $group );
     36        }
     37
     38        function do_item( $handle, $group = false ) {
     39                if ( !parent::do_item( $handle ) )
     40                        return false;
     41
     42                if ( 0 === $group && $this->groups[$handle] > 0 )
     43                        return false;
     44
     45                if ( null === $this->registered[$handle]->ver )
     46                        $ver = '';
     47                else
     48                        $ver = $this->registered[$handle]->ver ? $this->registered[$handle]->ver : $this->default_version;
     49
     50                if ( isset($this->args[$handle]) )
     51                        $ver = $ver ? $ver . '&amp;' . $this->args[$handle] : $this->args[$handle];
     52
     53                $src = $this->registered[$handle]->src;
     54
     55                if ( !preg_match('|^https?://|', $src) && ! ( $this->content_url && 0 === strpos( $src, $this->content_url ) ) )
     56                        $src = $this->base_url . $src;
     57
     58                if ( !empty( $ver ) )
     59                        $src = add_query_arg( 'ver', $ver, $src );
     60
     61                $src = esc_url( apply_filters( 'plugin_loader_src', $src, $handle ) );
     62
     63                return true;
     64        }
     65
     66        function set_group( $handle, $recursion, $group = false ) {
     67                $grp = isset( $this->registered[$handle]->extra['group'] ) ? (int) $this->registered[$handle]->extra['group'] : 0;
     68
     69                if ( false !== $group && $grp > $group )
     70                        $grp = $group;
     71
     72                return parent::set_group( $handle, $recursion, $grp );
     73        }
     74
     75        function all_deps( $handles, $recursion = false, $group = false ) {
     76                $r = parent::all_deps( $handles, $recursion );
     77
     78                if ( !$recursion )
     79                        $this->to_do = apply_filters( 'print_plugins_array', $this->to_do );
     80
     81                return $r;
     82        }
     83
     84        function reset() {
     85               
     86        }
     87}
  • wp-includes/functions.wp-plugins.php

     
     1<?php
     2/**
     3 * Plugin procedural API.
     4 *
     5 * @since WP unknown; BP unknown
     6 *
     7 */
     8
     9/**
     10 * Prints plugin tags in document head.
     11 *
     12 * Called by admin-header.php and by wp_head hook. Since it is called by wp_head
     13 * on every page load, the function does not instantiate the WP_Plugins object
     14 * unless plugin names are explicitly passed. Does make use of already
     15 * instantiated $wp_plugins if present. Use provided wp_print_plugins hook to
     16 * register/enqueue new plugins.
     17 *
     18 * @since WP unknown; BP unknown
     19 *
     20 * @see WP_Dependencies::print_plugins()
     21 */
     22function wp_print_plugins( $handles = false ) {
     23        global $wp_plugins;
     24
     25        do_action( 'wp_print_plugins' );
     26
     27        if ( '' === $handles )
     28                $handles = false;
     29
     30        if ( !is_a( $wp_plugins, 'WP_Plugins' ) ) {
     31                if ( !$handles ) {
     32                        // No need to instantiate if nothing is here.
     33                        return array();
     34                } else {
     35                        $wp_plugins = new WP_Plugins();
     36                }
     37        }
     38
     39        return $wp_plugins->do_items( $handles );
     40}
     41
     42/**
     43 * Register new Plugin file.
     44 *
     45 * @since WP unknown; BP unknown
     46 *
     47 * @param string $handle Plugin name
     48 * @param string $src Plugin url
     49 * @param array $deps (optional) Array of plugin names on which this plugin depends
     50 * @param string|bool $ver (optional) Plugin version (used for dependency checks), set to NULL to disable
     51 * @return null
     52 */
     53function wp_register_plugin( $handle, $src, $deps = array(), $ver = false ) {
     54        global $wp_plugins;
     55
     56        $wp_plugins = wp_plugin_is_a();
     57        $wp_plugins->add( $handle, $src, $deps, $ver );
     58}
     59
     60/**
     61 * Remove a registered plugin.
     62 *
     63 * @since WP unknown; BP unknown
     64 *
     65 * @see WP_Plugins::remove() For parameter information.
     66 */
     67function wp_deregister_plugin( $handle ) {
     68        global $wp_plugins;
     69
     70        $wp_plugins = wp_plugin_is_a();
     71        $wp_plugins->remove( $handle );
     72}
     73
     74/**
     75 * Enqueues plugin.
     76 *
     77 * Registers the plugin if src provided (does NOT overwrite) and enqueues.
     78 *
     79 * @since WP unknown; BP unknown
     80 *
     81 * @see wp_register_plugin() For parameter information.
     82 */
     83function wp_enqueue_plugin( $handle, $src = false, $deps = array(), $ver = false ) {
     84        global $wp_plugins;
     85
     86        $wp_plugins = wp_plugin_is_a();
     87
     88        if ( $src ) {
     89                $_handle = explode( '?', $handle );
     90                $wp_plugins->add( $_handle[0], $src, $deps, $ver );
     91        }
     92
     93        $wp_plugins->enqueue( $handle );
     94}
     95
     96/**
     97 * Check whether plugin has been added to WordPress Plugins.
     98 *
     99 * The values for list defaults to 'queue', which is the same as enqueue for
     100 * plugins.
     101 *
     102 * @since WP unknown; BP unknown
     103 *
     104 * @param string $handle Handle used to add plugin.
     105 * @param string $list Optional, defaults to 'queue'. Others values are 'registered', 'queue', 'done', 'to_do'
     106 * @return bool
     107 */
     108function wp_plugin_is( $handle, $list = 'queue' ) {
     109        global $wp_plugins;
     110
     111        $wp_plugins = wp_plugin_is_a();
     112        $query = $wp_plugins->query( $handle, $list );
     113
     114        if ( is_object( $query ) )
     115                return true;
     116
     117        return $query;
     118}
     119
     120/**
     121 * wp_plugin_is_a
     122 *
     123 * Checks if global $wp_plugins exists and creates it if it does not
     124 *
     125 * @since WP unknown; BP unknown
     126 *
     127 * @global WP_Plugins $wp_plugins Dependency class for plugins
     128 * @return WP_Plugins
     129 */
     130function wp_plugin_is_a() {
     131        global $wp_plugins;
     132
     133        if ( !is_a( $wp_plugins, 'WP_Plugins' ) )
     134                $wp_plugins = new WP_Plugins();
     135
     136        return $wp_plugins;
     137}
     138 No newline at end of file
  • wp-settings.php

     
    141141        require( ABSPATH . WPINC . '/ms-deprecated.php' );
    142142}
    143143
     144// Load plugin queueing files
     145require( ABSPATH . WPINC . '/class.wp-plugins.php' );
     146require( ABSPATH . WPINC . '/functions.wp-plugins.php' );
     147
    144148// Define constants that rely on the API to obtain the default value.
    145149// Define must-use plugin directory constants, which may be overridden in the sunrise.php drop-in.
    146150wp_plugin_directory_constants( );