Changeset 3487706
- Timestamp:
- 03/21/2026 10:03:11 AM (7 days ago)
- Location:
- loginhue-admin-login-customiser
- Files:
-
- 2 edited
-
tags/1.0.0/loginhue-admin-login-customiser.php (modified) (7 diffs)
-
trunk/loginhue-admin-login-customiser.php (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
loginhue-admin-login-customiser/tags/1.0.0/loginhue-admin-login-customiser.php
r3455857 r3487706 31 31 add_action( 'admin_post_lcalc_reset', array( __CLASS__, 'lcalc_handle_reset' ) ); 32 32 add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), array( __CLASS__, 'lcalc_add_settings_link' ) ); 33 add_filter( 'plugin_row_meta', array( __CLASS__, 'lcalc_add_plugin_meta_links' ), 10, 2 ); 33 34 } 34 35 … … 41 42 42 43 array_unshift( $links, $settings_link ); 44 return $links; 45 } 46 47 public static function lcalc_add_plugin_meta_links( $links, $file ) { 48 if ( plugin_basename( __FILE__ ) !== $file ) { 49 return $links; 50 } 51 52 $links[] = sprintf( 53 '<a href="%s" target="_blank" rel="noopener noreferrer">%s</a>', 54 esc_url( 'https://wordpress.org/support/plugin/loginhue-admin-login-customiser/reviews' ), 55 esc_html__( 'Leave a review', 'loginhue-admin-login-customiser' ) 56 ); 57 43 58 return $links; 44 59 } … … 337 352 } 338 353 354 /** 355 * Normalize CSS dimensions. If a plain number is provided, default to px. 356 */ 357 private static function lcalc_sanitize_css_dimension( $value, $default = '' ) { 358 $value = trim( sanitize_text_field( (string) $value ) ); 359 if ( '' === $value ) { 360 return $default; 361 } 362 363 if ( preg_match( '/^\d+(\.\d+)?$/', $value ) ) { 364 return $value . 'px'; 365 } 366 367 if ( preg_match( '/^\d+(\.\d+)?(px|%|em|rem|vh|vw|vmin|vmax)$/i', $value ) ) { 368 return strtolower( $value ); 369 } 370 371 if ( in_array( strtolower( $value ), array( 'auto', 'inherit', 'initial', 'unset' ), true ) ) { 372 return strtolower( $value ); 373 } 374 375 return $default; 376 } 377 339 378 public static function lcalc_sanitize_options( $input ) { 340 379 $out = array(); … … 348 387 $out['custom_admin_slug'] = $raw_slug; 349 388 $out['logo_url'] = isset( $input['logo_url'] ) ? esc_url( trim( $input['logo_url'] ) ) : ''; 350 $out['logo_width'] = isset( $input['logo_width'] ) ? s anitize_text_field( $input['logo_width']) : '200px';351 $out['logo_height'] = isset( $input['logo_height'] ) ? s anitize_text_field( $input['logo_height']) : '';389 $out['logo_width'] = isset( $input['logo_width'] ) ? self::lcalc_sanitize_css_dimension( $input['logo_width'], '200px' ) : '200px'; 390 $out['logo_height'] = isset( $input['logo_height'] ) ? self::lcalc_sanitize_css_dimension( $input['logo_height'], '' ) : ''; 352 391 $out['hide_wp_logo'] = isset( $input['hide_wp_logo'] ) ? '1' : '0'; 353 392 … … 462 501 $opts = self::lcalc_get_options(); 463 502 printf( '<input type="text" name="%1$s[logo_height]" value="%2$s" class="regular-text" />', esc_attr( self::LCALC_OPTION_KEY ), esc_attr( $opts['logo_height'] ) ); 503 ?> 504 <p class="description"> 505 <?php esc_html_e( 506 'CSS height value, e.g. 120px or 20%. If you enter only a number, px is applied automatically.', 507 'loginhue-admin-login-customiser' 508 ); ?> 509 </p> 510 <?php 464 511 } 465 512 … … 633 680 <p class="description"> 634 681 <?php esc_html_e( 635 'CSS width value, e.g. 200px or 40%. ',682 'CSS width value, e.g. 200px or 40%. If you enter only a number, px is applied automatically.', 636 683 'loginhue-admin-login-customiser' 637 684 ); ?> … … 804 851 // Logo 805 852 if ( ! empty( $opts['logo_url'] ) && empty( $opts['hide_wp_logo'] ) ) { 806 $height = ! empty( $opts['logo_height'] ) ? 'height:' . esc_attr( $opts['logo_height'] ) . ';' : ''; 807 $custom_css .= "#login h1 a{background-image:url('" . esc_url( $opts['logo_url'] ) . "');background-size:contain;width:" . esc_attr( $opts['logo_width'] ) . ';' . $height . "background-repeat:no-repeat;}\n"; 853 $width = self::lcalc_sanitize_css_dimension( isset( $opts['logo_width'] ) ? $opts['logo_width'] : '', '200px' ); 854 $height = self::lcalc_sanitize_css_dimension( isset( $opts['logo_height'] ) ? $opts['logo_height'] : '', '' ); 855 $size = ! empty( $height ) ? 'contain' : 'auto 100%'; 856 $custom_css .= "#login h1{display:flex;justify-content:center;align-items:center;}\n"; 857 $custom_css .= "#login h1 a{background-image:url('" . esc_url( $opts['logo_url'] ) . "');background-size:" . esc_attr( $size ) . ';width:' . esc_attr( $width ) . ';' . ( ! empty( $height ) ? 'height:' . esc_attr( $height ) . ';' : '' ) . "max-width:none;background-repeat:no-repeat;background-position:center;display:block;position:static;left:auto;transform:none;margin-left:0;margin-right:0;}\n"; 808 858 } elseif ( ! empty( $opts['hide_wp_logo'] ) ) { 809 859 $custom_css .= "#login h1 a{display:none!important;}\n"; -
loginhue-admin-login-customiser/trunk/loginhue-admin-login-customiser.php
r3455857 r3487706 31 31 add_action( 'admin_post_lcalc_reset', array( __CLASS__, 'lcalc_handle_reset' ) ); 32 32 add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), array( __CLASS__, 'lcalc_add_settings_link' ) ); 33 add_filter( 'plugin_row_meta', array( __CLASS__, 'lcalc_add_plugin_meta_links' ), 10, 2 ); 33 34 } 34 35 … … 41 42 42 43 array_unshift( $links, $settings_link ); 44 return $links; 45 } 46 47 public static function lcalc_add_plugin_meta_links( $links, $file ) { 48 if ( plugin_basename( __FILE__ ) !== $file ) { 49 return $links; 50 } 51 52 $links[] = sprintf( 53 '<a href="%s" target="_blank" rel="noopener noreferrer">%s</a>', 54 esc_url( 'https://wordpress.org/support/plugin/loginhue-admin-login-customiser/reviews' ), 55 esc_html__( 'Leave a review', 'loginhue-admin-login-customiser' ) 56 ); 57 43 58 return $links; 44 59 } … … 337 352 } 338 353 354 /** 355 * Normalize CSS dimensions. If a plain number is provided, default to px. 356 */ 357 private static function lcalc_sanitize_css_dimension( $value, $default = '' ) { 358 $value = trim( sanitize_text_field( (string) $value ) ); 359 if ( '' === $value ) { 360 return $default; 361 } 362 363 if ( preg_match( '/^\d+(\.\d+)?$/', $value ) ) { 364 return $value . 'px'; 365 } 366 367 if ( preg_match( '/^\d+(\.\d+)?(px|%|em|rem|vh|vw|vmin|vmax)$/i', $value ) ) { 368 return strtolower( $value ); 369 } 370 371 if ( in_array( strtolower( $value ), array( 'auto', 'inherit', 'initial', 'unset' ), true ) ) { 372 return strtolower( $value ); 373 } 374 375 return $default; 376 } 377 339 378 public static function lcalc_sanitize_options( $input ) { 340 379 $out = array(); … … 348 387 $out['custom_admin_slug'] = $raw_slug; 349 388 $out['logo_url'] = isset( $input['logo_url'] ) ? esc_url( trim( $input['logo_url'] ) ) : ''; 350 $out['logo_width'] = isset( $input['logo_width'] ) ? s anitize_text_field( $input['logo_width']) : '200px';351 $out['logo_height'] = isset( $input['logo_height'] ) ? s anitize_text_field( $input['logo_height']) : '';389 $out['logo_width'] = isset( $input['logo_width'] ) ? self::lcalc_sanitize_css_dimension( $input['logo_width'], '200px' ) : '200px'; 390 $out['logo_height'] = isset( $input['logo_height'] ) ? self::lcalc_sanitize_css_dimension( $input['logo_height'], '' ) : ''; 352 391 $out['hide_wp_logo'] = isset( $input['hide_wp_logo'] ) ? '1' : '0'; 353 392 … … 462 501 $opts = self::lcalc_get_options(); 463 502 printf( '<input type="text" name="%1$s[logo_height]" value="%2$s" class="regular-text" />', esc_attr( self::LCALC_OPTION_KEY ), esc_attr( $opts['logo_height'] ) ); 503 ?> 504 <p class="description"> 505 <?php esc_html_e( 506 'CSS height value, e.g. 120px or 20%. If you enter only a number, px is applied automatically.', 507 'loginhue-admin-login-customiser' 508 ); ?> 509 </p> 510 <?php 464 511 } 465 512 … … 633 680 <p class="description"> 634 681 <?php esc_html_e( 635 'CSS width value, e.g. 200px or 40%. ',682 'CSS width value, e.g. 200px or 40%. If you enter only a number, px is applied automatically.', 636 683 'loginhue-admin-login-customiser' 637 684 ); ?> … … 804 851 // Logo 805 852 if ( ! empty( $opts['logo_url'] ) && empty( $opts['hide_wp_logo'] ) ) { 806 $height = ! empty( $opts['logo_height'] ) ? 'height:' . esc_attr( $opts['logo_height'] ) . ';' : ''; 807 $custom_css .= "#login h1 a{background-image:url('" . esc_url( $opts['logo_url'] ) . "');background-size:contain;width:" . esc_attr( $opts['logo_width'] ) . ';' . $height . "background-repeat:no-repeat;}\n"; 853 $width = self::lcalc_sanitize_css_dimension( isset( $opts['logo_width'] ) ? $opts['logo_width'] : '', '200px' ); 854 $height = self::lcalc_sanitize_css_dimension( isset( $opts['logo_height'] ) ? $opts['logo_height'] : '', '' ); 855 $size = ! empty( $height ) ? 'contain' : 'auto 100%'; 856 $custom_css .= "#login h1{display:flex;justify-content:center;align-items:center;}\n"; 857 $custom_css .= "#login h1 a{background-image:url('" . esc_url( $opts['logo_url'] ) . "');background-size:" . esc_attr( $size ) . ';width:' . esc_attr( $width ) . ';' . ( ! empty( $height ) ? 'height:' . esc_attr( $height ) . ';' : '' ) . "max-width:none;background-repeat:no-repeat;background-position:center;display:block;position:static;left:auto;transform:none;margin-left:0;margin-right:0;}\n"; 808 858 } elseif ( ! empty( $opts['hide_wp_logo'] ) ) { 809 859 $custom_css .= "#login h1 a{display:none!important;}\n";
Note: See TracChangeset
for help on using the changeset viewer.