diff -r 34716fd837a4 -r be944660c56a wp/wp-admin/includes/class-custom-image-header.php --- a/wp/wp-admin/includes/class-custom-image-header.php Tue Dec 15 15:52:01 2020 +0100 +++ b/wp/wp-admin/includes/class-custom-image-header.php Wed Sep 21 18:19:35 2022 +0200 @@ -71,6 +71,7 @@ */ public function init() { $page = add_theme_page( __( 'Header' ), __( 'Header' ), 'edit_theme_options', 'custom-header', array( $this, 'admin_page' ) ); + if ( ! $page ) { return; } @@ -80,6 +81,7 @@ add_action( "admin_head-{$page}", array( $this, 'help' ) ); add_action( "admin_head-{$page}", array( $this, 'take_action' ), 50 ); add_action( "admin_head-{$page}", array( $this, 'js' ), 50 ); + if ( $this->admin_header_callback ) { add_action( "admin_head-{$page}", $this->admin_header_callback, 51 ); } @@ -141,7 +143,7 @@ * * @since 2.6.0 * - * @return int Current step + * @return int Current step. */ public function step() { if ( ! isset( $_GET['step'] ) ) { @@ -150,8 +152,8 @@ $step = (int) $_GET['step']; if ( $step < 1 || 3 < $step || - ( 2 == $step && ! wp_verify_nonce( $_REQUEST['_wpnonce-custom-header-upload'], 'custom-header-upload' ) ) || - ( 3 == $step && ! wp_verify_nonce( $_REQUEST['_wpnonce'], 'custom-header-crop-image' ) ) + ( 2 === $step && ! wp_verify_nonce( $_REQUEST['_wpnonce-custom-header-upload'], 'custom-header-upload' ) ) || + ( 3 === $step && ! wp_verify_nonce( $_REQUEST['_wpnonce'], 'custom-header-crop-image' ) ) ) { return 1; } @@ -167,13 +169,13 @@ public function js_includes() { $step = $this->step(); - if ( ( 1 == $step || 3 == $step ) ) { + if ( ( 1 === $step || 3 === $step ) ) { wp_enqueue_media(); wp_enqueue_script( 'custom-header' ); if ( current_theme_supports( 'custom-header', 'header-text' ) ) { wp_enqueue_script( 'wp-color-picker' ); } - } elseif ( 2 == $step ) { + } elseif ( 2 === $step ) { wp_enqueue_script( 'imgareaselect' ); } } @@ -186,9 +188,9 @@ public function css_includes() { $step = $this->step(); - if ( ( 1 == $step || 3 == $step ) && current_theme_supports( 'custom-header', 'header-text' ) ) { + if ( ( 1 === $step || 3 === $step ) && current_theme_supports( 'custom-header', 'header-text' ) ) { wp_enqueue_style( 'wp-color-picker' ); - } elseif ( 2 == $step ) { + } elseif ( 2 === $step ) { wp_enqueue_style( 'imgareaselect' ); } } @@ -211,24 +213,32 @@ if ( isset( $_POST['resetheader'] ) ) { check_admin_referer( 'custom-header-options', '_wpnonce-custom-header-options' ); + $this->reset_header_image(); + return; } if ( isset( $_POST['removeheader'] ) ) { check_admin_referer( 'custom-header-options', '_wpnonce-custom-header-options' ); + $this->remove_header_image(); + return; } if ( isset( $_POST['text-color'] ) && ! isset( $_POST['display-header-text'] ) ) { check_admin_referer( 'custom-header-options', '_wpnonce-custom-header-options' ); + set_theme_mod( 'header_textcolor', 'blank' ); } elseif ( isset( $_POST['text-color'] ) ) { check_admin_referer( 'custom-header-options', '_wpnonce-custom-header-options' ); + $_POST['text-color'] = str_replace( '#', '', $_POST['text-color'] ); - $color = preg_replace( '/[^0-9a-fA-F]/', '', $_POST['text-color'] ); - if ( strlen( $color ) == 6 || strlen( $color ) == 3 ) { + + $color = preg_replace( '/[^0-9a-fA-F]/', '', $_POST['text-color'] ); + + if ( strlen( $color ) === 6 || strlen( $color ) === 3 ) { set_theme_mod( 'header_textcolor', $color ); } elseif ( ! $color ) { set_theme_mod( 'header_textcolor', 'blank' ); @@ -237,7 +247,9 @@ if ( isset( $_POST['default-header'] ) ) { check_admin_referer( 'custom-header-options', '_wpnonce-custom-header-options' ); + $this->set_header_image( $_POST['default-header'] ); + return; } } @@ -263,9 +275,19 @@ $this->default_headers = $_wp_default_headers; $template_directory_uri = get_template_directory_uri(); $stylesheet_directory_uri = get_stylesheet_directory_uri(); + foreach ( array_keys( $this->default_headers ) as $header ) { - $this->default_headers[ $header ]['url'] = sprintf( $this->default_headers[ $header ]['url'], $template_directory_uri, $stylesheet_directory_uri ); - $this->default_headers[ $header ]['thumbnail_url'] = sprintf( $this->default_headers[ $header ]['thumbnail_url'], $template_directory_uri, $stylesheet_directory_uri ); + $this->default_headers[ $header ]['url'] = sprintf( + $this->default_headers[ $header ]['url'], + $template_directory_uri, + $stylesheet_directory_uri + ); + + $this->default_headers[ $header ]['thumbnail_url'] = sprintf( + $this->default_headers[ $header ]['thumbnail_url'], + $template_directory_uri, + $stylesheet_directory_uri + ); } } @@ -297,10 +319,12 @@ } echo '
'; + foreach ( $headers as $header_key => $header ) { $header_thumbnail = $header['thumbnail_url']; $header_url = $header['url']; $header_alt_text = empty( $header['alt_text'] ) ? '' : $header['alt_text']; + echo '
'; echo ''; echo '
'; } + echo '
'; } @@ -320,9 +345,10 @@ */ public function js() { $step = $this->step(); - if ( ( 1 == $step || 3 == $step ) && current_theme_supports( 'custom-header', 'header-text' ) ) { + + if ( ( 1 === $step || 3 === $step ) && current_theme_supports( 'custom-header', 'header-text' ) ) { $this->js_1(); - } elseif ( 2 == $step ) { + } elseif ( 2 === $step ) { $this->js_2(); } } @@ -343,7 +369,7 @@ ?>