PageRenderTime 45ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

/public/frontend/wp-includes/functions.wp-styles.php

https://bitbucket.org/floppyxyz/musical
PHP | 194 lines | 85 code | 19 blank | 90 comment | 19 complexity | 8cc6f1ce23b2cf99451bd25d54ba5dc4 MD5 | raw file
Possible License(s): GPL-2.0, AGPL-1.0, LGPL-2.1
  1. <?php
  2. /**
  3. * BackPress styles procedural API.
  4. *
  5. * @package BackPress
  6. * @since r79
  7. */
  8. /**
  9. * Display styles that are in the queue or part of $handles.
  10. *
  11. * @since r79
  12. * @uses do_action() Calls 'wp_print_styles' hook.
  13. * @global object $wp_styles The WP_Styles object for printing styles.
  14. *
  15. * @param array|bool $handles Styles to be printed. An empty array prints the queue,
  16. * an array with one string prints that style, and an array of strings prints those styles.
  17. * @return bool True on success, false on failure.
  18. */
  19. function wp_print_styles( $handles = false ) {
  20. if ( '' === $handles ) // for wp_head
  21. $handles = false;
  22. if ( ! $handles )
  23. do_action( 'wp_print_styles' );
  24. global $wp_styles;
  25. if ( ! is_a( $wp_styles, 'WP_Styles' ) ) {
  26. if ( ! did_action( 'init' ) )
  27. _doing_it_wrong( __FUNCTION__, sprintf( __( 'Scripts and styles should not be registered or enqueued until the %1$s, %2$s, or %3$s hooks.' ),
  28. '<code>wp_enqueue_scripts</code>', '<code>admin_enqueue_scripts</code>', '<code>init</code>' ), '3.3' );
  29. if ( !$handles )
  30. return array(); // No need to instantiate if nothing is there.
  31. else
  32. $wp_styles = new WP_Styles();
  33. }
  34. return $wp_styles->do_items( $handles );
  35. }
  36. /**
  37. * Adds extra CSS.
  38. *
  39. * Works only if the stylesheet has already been added.
  40. * Accepts a string $data containing the CSS. If two or more CSS code blocks are
  41. * added to the same stylesheet $handle, they will be printed in the order
  42. * they were added, i.e. the latter added styles can redeclare the previous.
  43. *
  44. * @since 3.3.0
  45. * @see WP_Scripts::add_inline_style()
  46. */
  47. function wp_add_inline_style( $handle, $data ) {
  48. global $wp_styles;
  49. if ( ! is_a( $wp_styles, 'WP_Styles' ) ) {
  50. if ( ! did_action( 'init' ) )
  51. _doing_it_wrong( __FUNCTION__, sprintf( __( 'Scripts and styles should not be registered or enqueued until the %1$s, %2$s, or %3$s hooks.' ),
  52. '<code>wp_enqueue_scripts</code>', '<code>admin_enqueue_scripts</code>', '<code>init</code>' ), '3.3' );
  53. $wp_styles = new WP_Styles();
  54. }
  55. return $wp_styles->add_inline_style( $handle, $data );
  56. }
  57. /**
  58. * Register CSS style file.
  59. *
  60. * @since r79
  61. * @see WP_Styles::add() For additional information.
  62. * @global object $wp_styles The WP_Styles object for printing styles.
  63. * @link http://www.w3.org/TR/CSS2/media.html#media-types List of CSS media types.
  64. *
  65. * @param string $handle Name of the stylesheet.
  66. * @param string|bool $src Path to the stylesheet from the root directory of WordPress. Example: '/css/mystyle.css'.
  67. * @param array $deps Array of handles of any stylesheet that this stylesheet depends on.
  68. * (Stylesheets that must be loaded before this stylesheet.) Pass an empty array if there are no dependencies.
  69. * @param string|bool $ver String specifying the stylesheet version number. Set to null to disable.
  70. * Used to ensure that the correct version is sent to the client regardless of caching.
  71. * @param string $media The media for which this stylesheet has been defined.
  72. */
  73. function wp_register_style( $handle, $src, $deps = array(), $ver = false, $media = 'all' ) {
  74. global $wp_styles;
  75. if ( ! is_a( $wp_styles, 'WP_Styles' ) ) {
  76. if ( ! did_action( 'init' ) )
  77. _doing_it_wrong( __FUNCTION__, sprintf( __( 'Scripts and styles should not be registered or enqueued until the %1$s, %2$s, or %3$s hooks.' ),
  78. '<code>wp_enqueue_scripts</code>', '<code>admin_enqueue_scripts</code>', '<code>init</code>' ), '3.3' );
  79. $wp_styles = new WP_Styles();
  80. }
  81. $wp_styles->add( $handle, $src, $deps, $ver, $media );
  82. }
  83. /**
  84. * Remove a registered CSS file.
  85. *
  86. * @since r79
  87. * @see WP_Styles::remove() For additional information.
  88. * @global object $wp_styles The WP_Styles object for printing styles.
  89. *
  90. * @param string $handle Name of the stylesheet.
  91. */
  92. function wp_deregister_style( $handle ) {
  93. global $wp_styles;
  94. if ( ! is_a( $wp_styles, 'WP_Styles' ) ) {
  95. if ( ! did_action( 'init' ) )
  96. _doing_it_wrong( __FUNCTION__, sprintf( __( 'Scripts and styles should not be registered or enqueued until the %1$s, %2$s, or %3$s hooks.' ),
  97. '<code>wp_enqueue_scripts</code>', '<code>admin_enqueue_scripts</code>', '<code>init</code>' ), '3.3' );
  98. $wp_styles = new WP_Styles();
  99. }
  100. $wp_styles->remove( $handle );
  101. }
  102. /**
  103. * Enqueue a CSS style file.
  104. *
  105. * Registers the style if src provided (does NOT overwrite) and enqueues.
  106. *
  107. * @since r79
  108. * @see WP_Styles::add(), WP_Styles::enqueue()
  109. * @global object $wp_styles The WP_Styles object for printing styles.
  110. * @link http://www.w3.org/TR/CSS2/media.html#media-types List of CSS media types.
  111. *
  112. * @param string $handle Name of the stylesheet.
  113. * @param string|bool $src Path to the stylesheet from the root directory of WordPress. Example: '/css/mystyle.css'.
  114. * @param array $deps Array of handles (names) of any stylesheet that this stylesheet depends on.
  115. * (Stylesheets that must be loaded before this stylesheet.) Pass an empty array if there are no dependencies.
  116. * @param string|bool $ver String specifying the stylesheet version number, if it has one. This parameter
  117. * is used to ensure that the correct version is sent to the client regardless of caching, and so should be included
  118. * if a version number is available and makes sense for the stylesheet.
  119. * @param string $media The media for which this stylesheet has been defined.
  120. */
  121. function wp_enqueue_style( $handle, $src = false, $deps = array(), $ver = false, $media = 'all' ) {
  122. global $wp_styles;
  123. if ( ! is_a( $wp_styles, 'WP_Styles' ) ) {
  124. if ( ! did_action( 'init' ) )
  125. _doing_it_wrong( __FUNCTION__, sprintf( __( 'Scripts and styles should not be registered or enqueued until the %1$s, %2$s, or %3$s hooks.' ),
  126. '<code>wp_enqueue_scripts</code>', '<code>admin_enqueue_scripts</code>', '<code>init</code>' ), '3.3' );
  127. $wp_styles = new WP_Styles();
  128. }
  129. if ( $src ) {
  130. $_handle = explode('?', $handle);
  131. $wp_styles->add( $_handle[0], $src, $deps, $ver, $media );
  132. }
  133. $wp_styles->enqueue( $handle );
  134. }
  135. /**
  136. * Remove an enqueued style.
  137. *
  138. * @since WP 3.1
  139. * @see WP_Styles::dequeue() For parameter information.
  140. */
  141. function wp_dequeue_style( $handle ) {
  142. global $wp_styles;
  143. if ( ! is_a( $wp_styles, 'WP_Styles' ) ) {
  144. if ( ! did_action( 'init' ) )
  145. _doing_it_wrong( __FUNCTION__, sprintf( __( 'Scripts and styles should not be registered or enqueued until the %1$s, %2$s, or %3$s hooks.' ),
  146. '<code>wp_enqueue_scripts</code>', '<code>admin_enqueue_scripts</code>', '<code>init</code>' ), '3.3' );
  147. $wp_styles = new WP_Styles();
  148. }
  149. $wp_styles->dequeue( $handle );
  150. }
  151. /**
  152. * Check whether style has been added to WordPress Styles.
  153. *
  154. * The values for list defaults to 'queue', which is the same as wp_enqueue_style().
  155. *
  156. * @since WP unknown; BP unknown
  157. * @global object $wp_styles The WP_Styles object for printing styles.
  158. *
  159. * @param string $handle Name of the stylesheet.
  160. * @param string $list Values are 'registered', 'done', 'queue' and 'to_do'.
  161. * @return bool True on success, false on failure.
  162. */
  163. function wp_style_is( $handle, $list = 'queue' ) {
  164. global $wp_styles;
  165. if ( ! is_a( $wp_styles, 'WP_Styles' ) ) {
  166. if ( ! did_action( 'init' ) )
  167. _doing_it_wrong( __FUNCTION__, sprintf( __( 'Scripts and styles should not be registered or enqueued until the %1$s, %2$s, or %3$s hooks.' ),
  168. '<code>wp_enqueue_scripts</code>', '<code>admin_enqueue_scripts</code>', '<code>init</code>' ), '3.3' );
  169. $wp_styles = new WP_Styles();
  170. }
  171. $query = $wp_styles->query( $handle, $list );
  172. if ( is_object( $query ) )
  173. return true;
  174. return $query;
  175. }