+ * Adds extra code to a registered script.
+ *
+ * @since 4.5.0
+ * @access public
+ *
+ * @param string $handle Name of the script to add the inline script to. Must be lowercase.
+ * @param string $data String containing the javascript to be added.
+ * @param string $position Optional. Whether to add the inline script before the handle
+ * or after. Default 'after'.
+ * @return bool True on success, false on failure.
+ */
+ public function add_inline_script( $handle, $data, $position = 'after' ) {
+ if ( ! $data ) {
+ return false;
+ }
+
+ if ( 'after' !== $position ) {
+ $position = 'before';
+ }
+
+ $script = (array) $this->get_data( $handle, $position );
+ $script[] = $data;
+
+ return $this->add_data( $handle, $position, $script );
+ }
+
+ /**
+ * Prints inline scripts registered for a specific handle.
+ *
+ * @since 4.5.0
+ * @access public
+ *
+ * @param string $handle Name of the script to add the inline script to. Must be lowercase.
+ * @param string $position Optional. Whether to add the inline script before the handle
+ * or after. Default 'after'.
+ * @param bool $echo Optional. Whether to echo the script instead of just returning it.
+ * Default true.
+ * @return string|false Script on success, false otherwise.
+ */
+ public function print_inline_script( $handle, $position = 'after', $echo = true ) {
+ $output = $this->get_data( $handle, $position );
+
+ if ( empty( $output ) ) {
+ return false;
+ }
+
+ $output = trim( implode( "\n", $output ), "\n" );
+
+ if ( $echo ) {
+ printf( "<script type='text/javascript'>\n%s\n</script>\n", $output );
+ }
+
+ return $output;
+ }
+
+ /**
+ * Localizes a script, only if the script has already been added.
+ *
+ * @since 2.1.0
+ * @access public