rebase on oct-10-2023

This commit is contained in:
Rachit Bhargava
2023-10-10 17:23:21 -04:00
parent d37566ffb6
commit d096058d7d
4789 changed files with 254611 additions and 307223 deletions

View File

@@ -223,7 +223,7 @@ class WP_Widget_Block extends WP_Widget {
* @return bool Updated `is_wide` value.
*/
public function set_is_wide_widget_in_customizer( $is_wide, $widget_id ) {
if ( strpos( $widget_id, 'block-' ) === 0 ) {
if ( str_starts_with( $widget_id, 'block-' ) ) {
return false;
}

View File

@@ -69,14 +69,16 @@ class WP_Widget_Custom_HTML extends WP_Widget {
}
$this->registered = true;
wp_add_inline_script( 'custom-html-widgets', sprintf( 'wp.customHtmlWidgets.idBases.push( %s );', wp_json_encode( $this->id_base ) ) );
// Note that the widgets component in the customizer will also do
// the 'admin_print_scripts-widgets.php' action in WP_Customize_Widgets::print_scripts().
/*
* Note that the widgets component in the customizer will also do
* the 'admin_print_scripts-widgets.php' action in WP_Customize_Widgets::print_scripts().
*/
add_action( 'admin_print_scripts-widgets.php', array( $this, 'enqueue_admin_scripts' ) );
// Note that the widgets component in the customizer will also do
// the 'admin_footer-widgets.php' action in WP_Customize_Widgets::print_footer_scripts().
/*
* Note that the widgets component in the customizer will also do
* the 'admin_footer-widgets.php' action in WP_Customize_Widgets::print_footer_scripts().
*/
add_action( 'admin_footer-widgets.php', array( 'WP_Widget_Custom_HTML', 'render_control_template_scripts' ) );
// Note this action is used to ensure the help text is added to the end.
@@ -216,6 +218,8 @@ class WP_Widget_Custom_HTML extends WP_Widget {
);
wp_enqueue_script( 'custom-html-widgets' );
wp_add_inline_script( 'custom-html-widgets', sprintf( 'wp.customHtmlWidgets.idBases.push( %s );', wp_json_encode( $this->id_base ) ) );
if ( empty( $settings ) ) {
$settings = array(
'disabled' => true,

View File

@@ -239,14 +239,31 @@ class WP_Widget_Media_Image extends WP_Widget_Media {
$instance['height'] = '';
}
$image = sprintf(
'<img class="%1$s" src="%2$s" alt="%3$s" width="%4$s" height="%5$s" />',
esc_attr( $classes ),
esc_url( $instance['url'] ),
esc_attr( $instance['alt'] ),
esc_attr( $instance['width'] ),
esc_attr( $instance['height'] )
$attr = array(
'class' => $classes,
'src' => $instance['url'],
'alt' => $instance['alt'],
'width' => $instance['width'],
'height' => $instance['height'],
'decoding' => 'async',
);
$loading_optimization_attr = wp_get_loading_optimization_attributes(
'img',
$attr,
'widget_media_image'
);
$attr = array_merge( $attr, $loading_optimization_attr );
$attr = array_map( 'esc_attr', $attr );
$image = '<img';
foreach ( $attr as $name => $value ) {
$image .= ' ' . $name . '="' . $value . '"';
}
$image .= ' />';
} // End if().
$url = '';

View File

@@ -107,16 +107,20 @@ abstract class WP_Widget_Media extends WP_Widget {
}
$this->registered = true;
// Note that the widgets component in the customizer will also do
// the 'admin_print_scripts-widgets.php' action in WP_Customize_Widgets::print_scripts().
/*
* Note that the widgets component in the customizer will also do
* the 'admin_print_scripts-widgets.php' action in WP_Customize_Widgets::print_scripts().
*/
add_action( 'admin_print_scripts-widgets.php', array( $this, 'enqueue_admin_scripts' ) );
if ( $this->is_preview() ) {
add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_preview_scripts' ) );
}
// Note that the widgets component in the customizer will also do
// the 'admin_footer-widgets.php' action in WP_Customize_Widgets::print_footer_scripts().
/*
* Note that the widgets component in the customizer will also do
* the 'admin_footer-widgets.php' action in WP_Customize_Widgets::print_footer_scripts().
*/
add_action( 'admin_footer-widgets.php', array( $this, 'render_control_template_scripts' ) );
add_filter( 'display_media_states', array( $this, 'display_media_state' ), 10, 2 );

View File

@@ -44,7 +44,7 @@ class WP_Widget_Text extends WP_Widget {
}
/**
* Add hooks for enqueueing assets when registering all widget instances of this widget class.
* Adds hooks for enqueueing assets when registering all widget instances of this widget class.
*
* @param int $number Optional. The unique order number of this widget instance
* compared to other instances of the same class. Default -1.
@@ -56,18 +56,20 @@ class WP_Widget_Text extends WP_Widget {
}
$this->registered = true;
wp_add_inline_script( 'text-widgets', sprintf( 'wp.textWidgets.idBases.push( %s );', wp_json_encode( $this->id_base ) ) );
if ( $this->is_preview() ) {
add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_preview_scripts' ) );
}
// Note that the widgets component in the customizer will also do
// the 'admin_print_scripts-widgets.php' action in WP_Customize_Widgets::print_scripts().
/*
* Note that the widgets component in the customizer will also do
* the 'admin_print_scripts-widgets.php' action in WP_Customize_Widgets::print_scripts().
*/
add_action( 'admin_print_scripts-widgets.php', array( $this, 'enqueue_admin_scripts' ) );
// Note that the widgets component in the customizer will also do
// the 'admin_footer-widgets.php' action in WP_Customize_Widgets::print_footer_scripts().
/*
* Note that the widgets component in the customizer will also do
* the 'admin_footer-widgets.php' action in WP_Customize_Widgets::print_footer_scripts().
*/
add_action( 'admin_footer-widgets.php', array( 'WP_Widget_Text', 'render_control_template_scripts' ) );
}
@@ -103,7 +105,7 @@ class WP_Widget_Text extends WP_Widget {
}
$wpautop = ! empty( $instance['filter'] );
$has_line_breaks = ( false !== strpos( trim( $instance['text'] ), "\n" ) );
$has_line_breaks = ( str_contains( trim( $instance['text'] ), "\n" ) );
// If auto-paragraphs are not enabled and there are line breaks, then ensure legacy mode.
if ( ! $wpautop && $has_line_breaks ) {
@@ -111,7 +113,7 @@ class WP_Widget_Text extends WP_Widget {
}
// If an HTML comment is present, assume legacy mode.
if ( false !== strpos( $instance['text'], '<!--' ) ) {
if ( str_contains( $instance['text'], '<!--' ) ) {
return true;
}
@@ -342,7 +344,7 @@ class WP_Widget_Text extends WP_Widget {
}
/**
* Inject max-width and remove height for videos too constrained to fit inside sidebars on frontend.
* Injects max-width and removes height for videos too constrained to fit inside sidebars on frontend.
*
* @since 4.9.0
*
@@ -412,7 +414,7 @@ class WP_Widget_Text extends WP_Widget {
}
/**
* Enqueue preview scripts.
* Enqueues preview scripts.
*
* These scripts normally are enqueued just-in-time when a playlist shortcode is used.
* However, in the customizer, a playlist shortcode may be used in a text widget and
@@ -436,6 +438,7 @@ class WP_Widget_Text extends WP_Widget {
wp_enqueue_editor();
wp_enqueue_media();
wp_enqueue_script( 'text-widgets' );
wp_add_inline_script( 'text-widgets', sprintf( 'wp.textWidgets.idBases.push( %s );', wp_json_encode( $this->id_base ) ) );
wp_add_inline_script( 'text-widgets', 'wp.textWidgets.init();', 'after' );
}
@@ -511,7 +514,7 @@ class WP_Widget_Text extends WP_Widget {
}
/**
* Render form template scripts.
* Renders form template scripts.
*
* @since 4.8.0
* @since 4.9.0 The method is now static.