| 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 | */ |
| 22 | function 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 | */ |
| 53 | function 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 | */ |
| 67 | function 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 | */ |
| 83 | function 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 | */ |
| 108 | function 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 | */ |
| 130 | function 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 |