@@ 83-97 (lines=15) @@ | ||
80 | * @param string $data String containing the CSS styles to be added. |
|
81 | * @return bool True on success, false on failure. |
|
82 | */ |
|
83 | function wp_add_inline_style( $handle, $data ) { |
|
84 | _wp_scripts_maybe_doing_it_wrong( __FUNCTION__ ); |
|
85 | ||
86 | if ( false !== stripos( $data, '</style>' ) ) { |
|
87 | _doing_it_wrong( __FUNCTION__, sprintf( |
|
88 | /* translators: 1: <style>, 2: wp_add_inline_style() */ |
|
89 | __( 'Do not pass %1$s tags to %2$s.' ), |
|
90 | '<code><style></code>', |
|
91 | '<code>wp_add_inline_style()</code>' |
|
92 | ), '3.7.0' ); |
|
93 | $data = trim( preg_replace( '#<style[^>]*>(.*)</style>#is', '$1', $data ) ); |
|
94 | } |
|
95 | ||
96 | return wp_styles()->add_inline_style( $handle, $data ); |
|
97 | } |
|
98 | ||
99 | /** |
|
100 | * Register a CSS stylesheet. |
@@ 107-121 (lines=15) @@ | ||
104 | * or after. Default 'after'. |
|
105 | * @return bool True on success, false on failure. |
|
106 | */ |
|
107 | function wp_add_inline_script( $handle, $data, $position = 'after' ) { |
|
108 | _wp_scripts_maybe_doing_it_wrong( __FUNCTION__ ); |
|
109 | ||
110 | if ( false !== stripos( $data, '</script>' ) ) { |
|
111 | _doing_it_wrong( __FUNCTION__, sprintf( |
|
112 | /* translators: 1: <script>, 2: wp_add_inline_script() */ |
|
113 | __( 'Do not pass %1$s tags to %2$s.' ), |
|
114 | '<code><script></code>', |
|
115 | '<code>wp_add_inline_script()</code>' |
|
116 | ), '4.5.0' ); |
|
117 | $data = trim( preg_replace( '#<script[^>]*>(.*)</script>#is', '$1', $data ) ); |
|
118 | } |
|
119 | ||
120 | return wp_scripts()->add_inline_script( $handle, $data, $position ); |
|
121 | } |
|
122 | ||
123 | /** |
|
124 | * Register a new script. |