Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/js/media/views/uploader/inline.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ UploaderInline = View.extend(/** @lends wp.media.view.UploaderInline.prototype *

$browser.detach().text( $placeholder.text() );
$browser[0].className = $placeholder[0].className;
$browser[0].setAttribute( 'aria-labelledby', $browser[0].id + ' ' + $placeholder[0].getAttribute('aria-labelledby') );
$placeholder.replaceWith( $browser.show() );
}

Expand Down
3 changes: 2 additions & 1 deletion src/js/media/views/uploader/status.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,13 +111,14 @@ UploaderStatus = View.extend(/** @lends wp.media.view.UploaderStatus.prototype *
* @param {Backbone.Model} error
*/
error: function( error ) {
console.log('error!');
var statusError = new wp.media.view.UploaderStatusError( {
filename: this.filename( error.get( 'file' ).name ),
message: error.get( 'message' )
} );

// Can show additional info here while retrying to create image sub-sizes.
this.views.add( '.upload-errors', statusError, { at: 0 } );
this.$el.attr( 'tabindex', '-1' ).focus() };
},

dismiss: function() {
Expand Down
120 changes: 120 additions & 0 deletions src/wp-includes/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -7781,3 +7781,123 @@ function is_php_version_compatible( $required ) {
function wp_fuzzy_number_match( $expected, $actual, $precision = 1 ) {
return abs( (float) $expected - (float) $actual ) <= $precision;
}

/**
* Sanitizes an attributes array into an attributes string to be placed inside a `<script>` tag.
*
* Automatically injects type attribute if needed.
* Used by {@see wp_get_script_tag()} and {@see wp_get_inline_script_tag()}.
*
* @since 5.6.0
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* @since 5.6.0
* @since 5.7.0

*
* @param array $attributes Key-value pairs representing `<script>` tag attributes.
* @return string String made of sanitized `<script>` tag attributes.
*/
function wp_sanitize_script_attributes( $attributes ) {
$html5_script_support = ! is_admin() && ! current_theme_supports( 'html5', 'script' );
$attributes_string = '';

// If HTML5 scirpt tag is supported, only the attribute name is added
// to $attributes_string for entries with a boolean value, and that are true.
foreach ( $attributes as $attribute_name => $attribute_value ) {
if ( is_bool( $attribute_value ) ) {
if ( $attribute_value ) {
$attributes_string .= $html5_script_support ? sprintf( ' %1$s="%2$s"', $attribute_name, esc_attr( $attribute_name ) ) : ' ' . $attribute_name;
}
} else {
$attributes_string .= sprintf( ' %1$s="%2$s"', $attribute_name, esc_attr( $attribute_value ) );
}
}

return $attributes_string;
}

/**
* Formats `<script>` loader tags.
*
* It is possible to inject attributes in the `<script>` tag via the {@see 'wp_script_attributes'} filter.
* Automatically injects type attribute if needed.
*
* @since 5.6.0
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* @since 5.6.0
* @since 5.7.0

*
* @param array $attributes Key-value pairs representing `<script>` tag attributes.
* @return string String containing `<script>` opening and closing tags.
*/
function wp_get_script_tag( $attributes ) {
if ( ! isset( $attributes['type'] ) && ! is_admin() && ! current_theme_supports( 'html5', 'script' ) ) {
$attributes['type'] = 'text/javascript';
}
/**
* Filters attributes to be added to a script tag.
*
* @since 5.6.0
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* @since 5.6.0
* @since 5.7.0

*
* @param array $attributes Key-value pairs representing `<script>` tag attributes.
* Only the attribute name is added to the `<script>` tag for
* entries with a boolean value, and that are true.
*/
$attributes = apply_filters( 'wp_script_attributes', $attributes );

return sprintf( "<script%s></script>\n", wp_sanitize_script_attributes( $attributes ) );
}

/**
* Prints formatted `<script>` loader tag.
*
* It is possible to inject attributes in the `<script>` tag via the {@see 'wp_script_attributes'} filter.
* Automatically injects type attribute if needed.
*
* @since 5.6.0
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* @since 5.6.0
* @since 5.7.0

*
* @param array $attributes Key-value pairs representing `<script>` tag attributes.
*/
function wp_print_script_tag( $attributes ) {
echo wp_get_script_tag( $attributes );
}

/**
* Wraps inline JavaScript in `<script>` tag.
*
* It is possible to inject attributes in the `<script>` tag via the {@see 'wp_script_attributes'} filter.
* Automatically injects type attribute if needed.
*
* @since 5.6.0
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* @since 5.6.0
* @since 5.7.0

*
* @param string $javascript Inline JavaScript code.
* @param array $attributes Optional. Key-value pairs representing `<script>` tag attributes.
* @return string String containing inline JavaScript code wrapped around `<script>` tag.
*/
function wp_get_inline_script_tag( $javascript, $attributes = array() ) {
if ( ! isset( $attributes['type'] ) && ! is_admin() && ! current_theme_supports( 'html5', 'script' ) ) {
$attributes['type'] = 'text/javascript';
}
/**
* Filters attributes to be added to a script tag.
*
* @since 5.6.0
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* @since 5.6.0
* @since 5.7.0

*
* @param array $attributes Key-value pairs representing `<script>` tag attributes.
* Only the attribute name is added to the `<script>` tag for
* entries with a boolean value, and that are true.
*/
$attributes = apply_filters( 'wp_script_attributes', $attributes );

$javascript = "\n" . trim( $javascript, "\n\r " ) . "\n";

return sprintf( "<script%s>%s</script>\n", wp_sanitize_script_attributes( $attributes ), $javascript );
}

/**
* Prints inline JavaScript wrapped in `<script>` tag.
*
* It is possible to inject attributes in the `<script>` tag via the {@see 'wp_script_attributes'} filter.
* Automatically injects type attribute if needed.
*
* @since 5.6.0
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* @since 5.6.0
* @since 5.7.0

*
* @param string $javascript Inline JavaScript code.
* @param array $attributes Optional. Key-value pairs representing `<script>` tag attributes.
*/
function wp_print_inline_script_tag( $javascript, $attributes = array() ) {
echo wp_get_inline_script_tag( $javascript, $attributes );
}
8 changes: 4 additions & 4 deletions src/wp-includes/media-template.php
Original file line number Diff line number Diff line change
Expand Up @@ -252,12 +252,12 @@ function wp_print_media_templates() {
<div class="upload-ui">
<h2 class="upload-instructions drop-instructions"><?php _e( 'Drop files to upload' ); ?></h2>
<p class="upload-instructions drop-instructions"><?php _ex( 'or', 'Uploader: Drop files here - or - Select Files' ); ?></p>
<button type="button" class="browser button button-hero"><?php _e( 'Select Files' ); ?></button>
<button type="button" class="browser button button-hero" aria-labelledby="post-upload-info"><?php _e( 'Select Files' ); ?></button>
</div>

<div class="upload-inline-status"></div>
<div class="upload-inline-status" aria-live="assertive"></div>

<div class="post-upload-ui">
<div class="post-upload-ui" id="post-upload-info">
<?php
/** This action is documented in wp-admin/includes/media.php */
do_action( 'pre-upload-ui' ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
Expand Down Expand Up @@ -330,7 +330,7 @@ function wp_print_media_templates() {
<span class="upload-detail-separator">&ndash;</span>
<span class="upload-filename"></span>
</div>
<div class="upload-errors"></div>
<div class="upload-errors" aria-live="assertive"></div>
</script>

<?php // Template for the uploading status errors. ?>
Expand Down