--- a/wp/wp-admin/includes/class-custom-background.php Thu Sep 29 08:06:27 2022 +0200
+++ b/wp/wp-admin/includes/class-custom-background.php Fri Sep 05 18:40:08 2025 +0200
@@ -11,6 +11,7 @@
*
* @since 3.0.0
*/
+#[AllowDynamicProperties]
class Custom_Background {
/**
@@ -38,11 +39,14 @@
private $updated;
/**
- * Constructor - Register administration header callback.
+ * Constructor - Registers administration header callback.
*
* @since 3.0.0
- * @param callable $admin_header_callback
- * @param callable $admin_image_div_callback Optional custom image div output callback.
+ *
+ * @param callable $admin_header_callback Optional. Administration header callback.
+ * Default empty string.
+ * @param callable $admin_image_div_callback Optional. Custom image div output callback.
+ * Default empty string.
*/
public function __construct( $admin_header_callback = '', $admin_image_div_callback = '' ) {
$this->admin_header_callback = $admin_header_callback;
@@ -57,12 +61,19 @@
}
/**
- * Set up the hooks for the Custom Background admin page.
+ * Sets up the hooks for the Custom Background admin page.
*
* @since 3.0.0
*/
public function init() {
- $page = add_theme_page( __( 'Background' ), __( 'Background' ), 'edit_theme_options', 'custom-background', array( $this, 'admin_page' ) );
+ $page = add_theme_page(
+ _x( 'Background', 'custom background' ),
+ _x( 'Background', 'custom background' ),
+ 'edit_theme_options',
+ 'custom-background',
+ array( $this, 'admin_page' )
+ );
+
if ( ! $page ) {
return;
}
@@ -77,7 +88,7 @@
}
/**
- * Set up the enqueue for the CSS & JavaScript files.
+ * Sets up the enqueue for the CSS & JavaScript files.
*
* @since 3.0.0
*/
@@ -97,7 +108,7 @@
get_current_screen()->set_help_sidebar(
'<p><strong>' . __( 'For more information:' ) . '</strong></p>' .
'<p>' . __( '<a href="https://codex.wordpress.org/Appearance_Background_Screen">Documentation on Custom Background</a>' ) . '</p>' .
- '<p>' . __( '<a href="https://wordpress.org/support/">Support</a>' ) . '</p>'
+ '<p>' . __( '<a href="https://wordpress.org/support/forums/">Support forums</a>' ) . '</p>'
);
wp_enqueue_media();
@@ -106,7 +117,7 @@
}
/**
- * Execute custom background modification.
+ * Executes custom background modification.
*
* @since 3.0.0
*/
@@ -222,7 +233,7 @@
}
/**
- * Display the custom background page.
+ * Displays the custom background page.
*
* @since 3.0.0
*/
@@ -231,30 +242,37 @@
<div class="wrap" id="custom-background">
<h1><?php _e( 'Custom Background' ); ?></h1>
- <?php if ( current_user_can( 'customize' ) ) { ?>
-<div class="notice notice-info hide-if-no-customize">
- <p>
- <?php
- printf(
+ <?php
+ if ( current_user_can( 'customize' ) ) {
+ $message = sprintf(
/* translators: %s: URL to background image configuration in Customizer. */
__( 'You can now manage and live-preview Custom Backgrounds in the <a href="%s">Customizer</a>.' ),
admin_url( 'customize.php?autofocus[control]=background_image' )
);
- ?>
- </p>
-</div>
- <?php } ?>
+ wp_admin_notice(
+ $message,
+ array(
+ 'type' => 'info',
+ 'additional_classes' => array( 'hide-if-no-customize' ),
+ )
+ );
+ }
- <?php if ( ! empty( $this->updated ) ) { ?>
-<div id="message" class="updated">
- <p>
- <?php
- /* translators: %s: Home URL. */
- printf( __( 'Background updated. <a href="%s">Visit your site</a> to see how it looks.' ), home_url( '/' ) );
- ?>
- </p>
-</div>
- <?php } ?>
+ if ( ! empty( $this->updated ) ) {
+ $updated_message = sprintf(
+ /* translators: %s: Home URL. */
+ __( 'Background updated. <a href="%s">Visit your site</a> to see how it looks.' ),
+ esc_url( home_url( '/' ) )
+ );
+ wp_admin_notice(
+ $updated_message,
+ array(
+ 'id' => 'message',
+ 'additional_classes' => array( 'updated' ),
+ )
+ );
+ }
+ ?>
<h2><?php _e( 'Background Image' ); ?></h2>
@@ -306,7 +324,7 @@
<td>
<form method="post">
<?php wp_nonce_field( 'custom-background-remove', '_wpnonce-custom-background-remove' ); ?>
- <?php submit_button( __( 'Remove Background Image' ), '', 'remove-background', false ); ?><br/>
+ <?php submit_button( __( 'Remove Background Image' ), '', 'remove-background', false ); ?><br />
<?php _e( 'This will remove the background image. You will not be able to restore any customizations.' ); ?>
</form>
</td>
@@ -320,7 +338,7 @@
<td>
<form method="post">
<?php wp_nonce_field( 'custom-background-reset', '_wpnonce-custom-background-reset' ); ?>
- <?php submit_button( __( 'Restore Original Image' ), '', 'reset-background', false ); ?><br/>
+ <?php submit_button( __( 'Restore Original Image' ), '', 'reset-background', false ); ?><br />
<?php _e( 'This will restore the original background image. You will not be able to restore any customizations.' ); ?>
</form>
</td>
@@ -412,7 +430,12 @@
?>
<tr>
<th scope="row"><?php _e( 'Image Position' ); ?></th>
-<td><fieldset><legend class="screen-reader-text"><span><?php _e( 'Image Position' ); ?></span></legend>
+<td><fieldset><legend class="screen-reader-text"><span>
+ <?php
+ /* translators: Hidden accessibility text. */
+ _e( 'Image Position' );
+ ?>
+</span></legend>
<div class="background-position-control">
<?php foreach ( $background_position_options as $group ) : ?>
<div class="button-group">
@@ -431,7 +454,12 @@
<tr>
<th scope="row"><label for="background-size"><?php _e( 'Image Size' ); ?></label></th>
-<td><fieldset><legend class="screen-reader-text"><span><?php _e( 'Image Size' ); ?></span></legend>
+<td><fieldset><legend class="screen-reader-text"><span>
+ <?php
+ /* translators: Hidden accessibility text. */
+ _e( 'Image Size' );
+ ?>
+</span></legend>
<select id="background-size" name="background-size">
<option value="auto"<?php selected( 'auto', get_theme_mod( 'background_size', get_theme_support( 'custom-background', 'default-size' ) ) ); ?>><?php _ex( 'Original', 'Original Size' ); ?></option>
<option value="contain"<?php selected( 'contain', get_theme_mod( 'background_size', get_theme_support( 'custom-background', 'default-size' ) ) ); ?>><?php _e( 'Fit to Screen' ); ?></option>
@@ -442,7 +470,12 @@
<tr>
<th scope="row"><?php _ex( 'Repeat', 'Background Repeat' ); ?></th>
-<td><fieldset><legend class="screen-reader-text"><span><?php _ex( 'Repeat', 'Background Repeat' ); ?></span></legend>
+<td><fieldset><legend class="screen-reader-text"><span>
+ <?php
+ /* translators: Hidden accessibility text. */
+ _ex( 'Repeat', 'Background Repeat' );
+ ?>
+</span></legend>
<input name="background-repeat" type="hidden" value="no-repeat">
<label><input type="checkbox" name="background-repeat" value="repeat"<?php checked( 'repeat', get_theme_mod( 'background_repeat', get_theme_support( 'custom-background', 'default-repeat' ) ) ); ?>> <?php _e( 'Repeat Background Image' ); ?></label>
</fieldset></td>
@@ -450,7 +483,12 @@
<tr>
<th scope="row"><?php _ex( 'Scroll', 'Background Scroll' ); ?></th>
-<td><fieldset><legend class="screen-reader-text"><span><?php _ex( 'Scroll', 'Background Scroll' ); ?></span></legend>
+<td><fieldset><legend class="screen-reader-text"><span>
+ <?php
+ /* translators: Hidden accessibility text. */
+ _ex( 'Scroll', 'Background Scroll' );
+ ?>
+</span></legend>
<input name="background-attachment" type="hidden" value="fixed">
<label><input name="background-attachment" type="checkbox" value="scroll" <?php checked( 'scroll', get_theme_mod( 'background_attachment', get_theme_support( 'custom-background', 'default-attachment' ) ) ); ?>> <?php _e( 'Scroll with Page' ); ?></label>
</fieldset></td>
@@ -458,7 +496,12 @@
<?php endif; // get_background_image() ?>
<tr>
<th scope="row"><?php _e( 'Background Color' ); ?></th>
-<td><fieldset><legend class="screen-reader-text"><span><?php _e( 'Background Color' ); ?></span></legend>
+<td><fieldset><legend class="screen-reader-text"><span>
+ <?php
+ /* translators: Hidden accessibility text. */
+ _e( 'Background Color' );
+ ?>
+</span></legend>
<?php
$default_color = '';
if ( current_theme_supports( 'custom-background', 'default-color' ) ) {
@@ -480,7 +523,7 @@
}
/**
- * Handle an Image upload for the background image.
+ * Handles an Image upload for the background image.
*
* @since 3.0.0
*/
@@ -526,18 +569,19 @@
wp_update_attachment_metadata( $id, wp_generate_attachment_metadata( $id, $file ) );
update_post_meta( $id, '_wp_attachment_is_custom_background', get_option( 'stylesheet' ) );
- set_theme_mod( 'background_image', esc_url_raw( $url ) );
+ set_theme_mod( 'background_image', sanitize_url( $url ) );
$thumbnail = wp_get_attachment_image_src( $id, 'thumbnail' );
- set_theme_mod( 'background_image_thumb', esc_url_raw( $thumbnail[0] ) );
+ set_theme_mod( 'background_image_thumb', sanitize_url( $thumbnail[0] ) );
- /** This action is documented in wp-admin/includes/class-custom-image-header.php */
- do_action( 'wp_create_file_in_uploads', $file, $id ); // For replication.
+ /** This filter is documented in wp-admin/includes/class-custom-image-header.php */
+ $file = apply_filters( 'wp_create_file_in_uploads', $file, $id ); // For replication.
+
$this->updated = true;
}
/**
- * Ajax handler for adding custom background context to an attachment.
+ * Handles Ajax request for adding custom background context to an attachment.
*
* Triggers when the user adds a new background image from the
* Media Manager.
@@ -618,8 +662,8 @@
$url = wp_get_attachment_image_src( $attachment_id, $size );
$thumbnail = wp_get_attachment_image_src( $attachment_id, 'thumbnail' );
- set_theme_mod( 'background_image', esc_url_raw( $url[0] ) );
- set_theme_mod( 'background_image_thumb', esc_url_raw( $thumbnail[0] ) );
+ set_theme_mod( 'background_image', sanitize_url( $url[0] ) );
+ set_theme_mod( 'background_image_thumb', sanitize_url( $thumbnail[0] ) );
exit;
}
}