← All changes
|
vendor/ayecode/wp-ayecode-ui/includes/ayecode-ui-settings.php
+207
-117
1.2.71
→
1.2.75
View file →
| @@ -34,9 +34,9 @@ | ||
| 34 | 34 | * Class version version. |
| 35 | 35 | * |
| 36 | 36 | * @var string |
| 37 | 37 | */ |
| 38 | - public $version = '0.2.51'; | |
| 38 | + public $version = '0.2.56'; | |
| 39 | 39 | |
| 40 | 40 | /** |
| 41 | 41 | * Class textdomain. |
| 42 | 42 | * |
| @@ -151,24 +151,25 @@ | ||
| 151 | 151 | /** |
| 152 | 152 | * Setup some constants. |
| 153 | 153 | */ |
| 154 | 154 | public function constants(){ |
| 155 | - define( 'AUI_PRIMARY_COLOR_ORIGINAL', "#1e73be" ); | |
| 156 | - define( 'AUI_SECONDARY_COLOR_ORIGINAL', '#6c757d' ); | |
| 157 | - define( 'AUI_INFO_COLOR_ORIGINAL', '#17a2b8' ); | |
| 158 | - define( 'AUI_WARNING_COLOR_ORIGINAL', '#ffc107' ); | |
| 159 | - define( 'AUI_DANGER_COLOR_ORIGINAL', '#dc3545' ); | |
| 160 | - define( 'AUI_SUCCESS_COLOR_ORIGINAL', '#44c553' ); | |
| 161 | - define( 'AUI_LIGHT_COLOR_ORIGINAL', '#f8f9fa' ); | |
| 162 | - define( 'AUI_DARK_COLOR_ORIGINAL', '#343a40' ); | |
| 163 | - define( 'AUI_WHITE_COLOR_ORIGINAL', '#fff' ); | |
| 164 | - define( 'AUI_PURPLE_COLOR_ORIGINAL', '#ad6edd' ); | |
| 165 | - define( 'AUI_SALMON_COLOR_ORIGINAL', '#ff977a' ); | |
| 166 | - define( 'AUI_CYAN_COLOR_ORIGINAL', '#35bdff' ); | |
| 167 | - define( 'AUI_GRAY_COLOR_ORIGINAL', '#ced4da' ); | |
| 168 | - define( 'AUI_INDIGO_COLOR_ORIGINAL', '#502c6c' ); | |
| 169 | - define( 'AUI_ORANGE_COLOR_ORIGINAL', '#orange' ); | |
| 170 | - define( 'AUI_BLACK_COLOR_ORIGINAL', '#000' ); | |
| 155 | + // Another copy of this package may have defined these already. | |
| 156 | + defined( 'AUI_PRIMARY_COLOR_ORIGINAL' ) || define( 'AUI_PRIMARY_COLOR_ORIGINAL', "#1e73be" ); | |
| 157 | + defined( 'AUI_SECONDARY_COLOR_ORIGINAL' ) || define( 'AUI_SECONDARY_COLOR_ORIGINAL', '#6c757d' ); | |
| 158 | + defined( 'AUI_INFO_COLOR_ORIGINAL' ) || define( 'AUI_INFO_COLOR_ORIGINAL', '#17a2b8' ); | |
| 159 | + defined( 'AUI_WARNING_COLOR_ORIGINAL' ) || define( 'AUI_WARNING_COLOR_ORIGINAL', '#ffc107' ); | |
| 160 | + defined( 'AUI_DANGER_COLOR_ORIGINAL' ) || define( 'AUI_DANGER_COLOR_ORIGINAL', '#dc3545' ); | |
| 161 | + defined( 'AUI_SUCCESS_COLOR_ORIGINAL' ) || define( 'AUI_SUCCESS_COLOR_ORIGINAL', '#44c553' ); | |
| 162 | + defined( 'AUI_LIGHT_COLOR_ORIGINAL' ) || define( 'AUI_LIGHT_COLOR_ORIGINAL', '#f8f9fa' ); | |
| 163 | + defined( 'AUI_DARK_COLOR_ORIGINAL' ) || define( 'AUI_DARK_COLOR_ORIGINAL', '#343a40' ); | |
| 164 | + defined( 'AUI_WHITE_COLOR_ORIGINAL' ) || define( 'AUI_WHITE_COLOR_ORIGINAL', '#fff' ); | |
| 165 | + defined( 'AUI_PURPLE_COLOR_ORIGINAL' ) || define( 'AUI_PURPLE_COLOR_ORIGINAL', '#ad6edd' ); | |
| 166 | + defined( 'AUI_SALMON_COLOR_ORIGINAL' ) || define( 'AUI_SALMON_COLOR_ORIGINAL', '#ff977a' ); | |
| 167 | + defined( 'AUI_CYAN_COLOR_ORIGINAL' ) || define( 'AUI_CYAN_COLOR_ORIGINAL', '#35bdff' ); | |
| 168 | + defined( 'AUI_GRAY_COLOR_ORIGINAL' ) || define( 'AUI_GRAY_COLOR_ORIGINAL', '#ced4da' ); | |
| 169 | + defined( 'AUI_INDIGO_COLOR_ORIGINAL' ) || define( 'AUI_INDIGO_COLOR_ORIGINAL', '#502c6c' ); | |
| 170 | + defined( 'AUI_ORANGE_COLOR_ORIGINAL' ) || define( 'AUI_ORANGE_COLOR_ORIGINAL', '#orange' ); | |
| 171 | + defined( 'AUI_BLACK_COLOR_ORIGINAL' ) || define( 'AUI_BLACK_COLOR_ORIGINAL', '#000' ); | |
| 171 | 172 | |
| 172 | 173 | if ( ! defined( 'AUI_PRIMARY_COLOR' ) ) { |
| 173 | 174 | define( 'AUI_PRIMARY_COLOR', AUI_PRIMARY_COLOR_ORIGINAL ); |
| 174 | 175 | } |
| @@ -333,8 +334,10 @@ | ||
| 333 | 334 | add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_style' ), $priority ); |
| 334 | 335 | } |
| 335 | 336 | if ( $this->settings['css_backend'] && $this->load_admin_scripts() ) { |
| 336 | 337 | add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_style' ), 1 ); |
| 338 | + // WordPress 6.9+ iframe compatibility. | |
| 339 | + add_action( 'enqueue_block_assets', [ $this, 'enqueue_block_assets' ], 100 ); | |
| 337 | 340 | } |
| 338 | 341 | |
| 339 | 342 | // maybe load JS |
| 340 | 343 | if ( $this->settings['js'] ) { |
| @@ -449,93 +452,96 @@ | ||
| 449 | 452 | |
| 450 | 453 | /** |
| 451 | 454 | * Adds the styles. |
| 452 | 455 | */ |
| 453 | - public function enqueue_style() { | |
| 454 | - global $aui_bs5; | |
| 456 | + public function enqueue_style( $context = '' ) { | |
| 457 | + global $aui_bs5; | |
| 455 | 458 | |
| 456 | - $load_fse = false; | |
| 459 | + $load_fse = false; | |
| 457 | 460 | |
| 458 | 461 | if ( is_admin() && ! $this->is_aui_screen() ) { |
| 459 | 462 | // Don't add wp-admin scripts if not requested to. |
| 460 | 463 | } else { |
| 461 | 464 | $css_setting = current_action() == 'wp_enqueue_scripts' ? 'css' : 'css_backend'; |
| 462 | - $rtl = is_rtl() && ! $aui_bs5 ? '-rtl' : ''; | |
| 463 | - $bs_ver = $this->settings['bs_ver'] == '5' ? '-v5' : ''; | |
| 465 | + $rtl = is_rtl() && ! $aui_bs5 ? '-rtl' : ''; | |
| 466 | + $bs_ver = $this->settings['bs_ver'] == '5' ? '-v5' : ''; | |
| 464 | 467 | |
| 465 | 468 | if ( $this->settings[ $css_setting ] ) { |
| 466 | - $compatibility = $this->settings[$css_setting]=='core' ? false : true; | |
| 467 | - $url = $this->settings[$css_setting]=='core' ? $this->url.'assets'.$bs_ver.'/css/ayecode-ui'.$rtl.'.css' : $this->url.'assets'.$bs_ver.'/css/ayecode-ui-compatibility'.$rtl.'.css'; | |
| 469 | + $compatibility = $this->settings[ $css_setting ] == 'core' ? false : true; | |
| 470 | + $base_url = $this->url . 'assets' . $bs_ver . '/css/'; | |
| 471 | + $url = $this->settings[ $css_setting ] == 'core' ? $base_url . 'ayecode-ui' . $rtl . '.css' : $base_url . 'ayecode-ui-compatibility' . $rtl . '.css'; | |
| 468 | 472 | |
| 469 | 473 | wp_register_style( 'ayecode-ui', $url, array(), $this->version ); |
| 470 | 474 | wp_enqueue_style( 'ayecode-ui' ); |
| 471 | 475 | |
| 472 | - if ( is_admin() && ( !empty($_REQUEST['postType']) || self::is_block_editor() ) && ( defined( 'BLOCKSTRAP_VERSION' ) || defined( 'AUI_FSE' ) ) ) { | |
| 473 | - $url = $this->url.'assets'.$bs_ver.'/css/ayecode-ui-fse.css'; | |
| 476 | + if ( is_admin() && ( ! empty( $_REQUEST['postType'] ) || self::is_block_editor() ) && ( defined( 'BLOCKSTRAP_VERSION' ) || defined( 'AUI_FSE' ) ) ) { | |
| 477 | + $url = $base_url . 'ayecode-ui-fse.css'; | |
| 478 | + $load_fse = true; | |
| 479 | + | |
| 474 | 480 | wp_register_style( 'ayecode-ui-fse', $url, array(), $this->version ); |
| 475 | 481 | wp_enqueue_style( 'ayecode-ui-fse' ); |
| 476 | - $load_fse = true; | |
| 477 | 482 | } |
| 478 | 483 | |
| 479 | - // flatpickr | |
| 480 | - wp_register_style( 'flatpickr', $this->url.'assets'.$bs_ver.'/css/flatpickr.min.css', array(), $this->version ); | |
| 484 | + // Flatpickr | |
| 485 | + wp_register_style( 'flatpickr', $base_url . 'flatpickr.min.css', array(), $this->version ); | |
| 481 | 486 | |
| 482 | - // fix some wp-admin issues | |
| 483 | - if(is_admin()){ | |
| 484 | - $custom_css = " | |
| 485 | - body:not(.editor-styles-wrapper){ | |
| 486 | - background-color: #f1f1f1; | |
| 487 | - font-family: -apple-system,BlinkMacSystemFont,\"Segoe UI\",Roboto,Oxygen-Sans,Ubuntu,Cantarell,\"Helvetica Neue\",sans-serif; | |
| 488 | - font-size:13px; | |
| 489 | - } | |
| 490 | - a { | |
| 491 | - color: #0073aa; | |
| 492 | - text-decoration: underline; | |
| 493 | - } | |
| 494 | - label { | |
| 495 | - display: initial; | |
| 496 | - margin-bottom: 0; | |
| 497 | - } | |
| 498 | - input, select { | |
| 499 | - margin: 1px; | |
| 500 | - line-height: initial; | |
| 501 | - } | |
| 502 | - th, td, div, h2 { | |
| 503 | - box-sizing: content-box; | |
| 504 | - } | |
| 505 | - h1, h2, h3, h4, h5, h6 { | |
| 506 | - display: block; | |
| 507 | - font-weight: 600; | |
| 508 | - } | |
| 509 | - h2,h3 { | |
| 510 | - font-size: 1.3em; | |
| 511 | - margin: 1em 0 | |
| 512 | - } | |
| 513 | - .blocks-widgets-container .bsui *{ | |
| 514 | - box-sizing: border-box; | |
| 515 | - } | |
| 516 | - .bs-tooltip-top .arrow{ | |
| 517 | - margin-left:0px; | |
| 518 | - } | |
| 519 | - .custom-switch input[type=checkbox]{ | |
| 520 | - display:none; | |
| 521 | - } | |
| 522 | - "; | |
| 487 | + // Fix some wp-admin issues | |
| 488 | + if ( is_admin() ) { | |
| 489 | +$custom_css = " | |
| 490 | +body:not(.editor-styles-wrapper){ | |
| 491 | + background-color: #f1f1f1; | |
| 492 | + font-family: -apple-system,BlinkMacSystemFont,\"Segoe UI\",Roboto,Oxygen-Sans,Ubuntu,Cantarell,\"Helvetica Neue\",sans-serif; | |
| 493 | + font-size:13px; | |
| 494 | +} | |
| 495 | +a { | |
| 496 | + color: #0073aa; | |
| 497 | + text-decoration: underline; | |
| 498 | +} | |
| 499 | +label { | |
| 500 | + display: initial; | |
| 501 | + margin-bottom: 0; | |
| 502 | +} | |
| 503 | +input, select { | |
| 504 | + margin: 1px; | |
| 505 | + line-height: initial; | |
| 506 | +} | |
| 507 | +th, td, div, h2 { | |
| 508 | + box-sizing: content-box; | |
| 509 | +} | |
| 510 | +h1, h2, h3, h4, h5, h6 { | |
| 511 | + display: block; | |
| 512 | + font-weight: 600; | |
| 513 | +} | |
| 514 | +h2,h3 { | |
| 515 | + font-size: 1.3em; | |
| 516 | + margin: 1em 0 | |
| 517 | +} | |
| 518 | +.blocks-widgets-container .bsui *{ | |
| 519 | + box-sizing: border-box; | |
| 520 | +} | |
| 521 | +.bs-tooltip-top .arrow{ | |
| 522 | + margin-left:0px; | |
| 523 | +} | |
| 524 | +.custom-switch input[type=checkbox]{ | |
| 525 | + display:none; | |
| 526 | +} | |
| 527 | +"; | |
| 523 | 528 | |
| 524 | - // @todo, remove once fixed :: fix for this bug https://github.com/WordPress/gutenberg/issues/14377 | |
| 525 | - $custom_css .= " | |
| 526 | - .edit-post-sidebar input[type=color].components-text-control__input{ | |
| 527 | - padding: 0; | |
| 528 | - } | |
| 529 | - "; | |
| 529 | +// @todo, remove once fixed :: fix for this bug https://github.com/WordPress/gutenberg/issues/14377 | |
| 530 | +$custom_css .= " | |
| 531 | +.edit-post-sidebar input[type=color].components-text-control__input{ | |
| 532 | + padding: 0; | |
| 533 | +} | |
| 534 | +"; | |
| 535 | + | |
| 530 | 536 | wp_add_inline_style( 'ayecode-ui', $custom_css ); |
| 531 | 537 | } |
| 532 | 538 | |
| 533 | - // custom changes | |
| 539 | + // Custom changes. | |
| 534 | 540 | if ( $load_fse ) { |
| 535 | - wp_add_inline_style( 'ayecode-ui-fse', self::custom_css($compatibility, true) ); | |
| 536 | - }else{ | |
| 537 | - wp_add_inline_style( 'ayecode-ui', self::custom_css($compatibility) ); | |
| 541 | + wp_add_inline_style( 'ayecode-ui-fse', self::custom_css( $compatibility, true ) ); | |
| 542 | + } else { | |
| 543 | + wp_add_inline_style( 'ayecode-ui', self::custom_css( $compatibility ) ); | |
| 538 | 544 | } |
| 539 | 545 | } |
| 540 | 546 | } |
| 541 | 547 | } |
| @@ -540,8 +546,20 @@ | ||
| 540 | 546 | } |
| 541 | 547 | } |
| 542 | 548 | |
| 543 | 549 | /** |
| 550 | + * Enqueue styles for block assets (both editor and frontend). | |
| 551 | + * This ensures compatibility with WordPress 6.9+ requirements. | |
| 552 | + */ | |
| 553 | + public function enqueue_block_assets() { | |
| 554 | + global $wp_version; | |
| 555 | + | |
| 556 | + if ( is_admin() && version_compare( $wp_version, '6.9', '>=' ) ) { | |
| 557 | + $this->enqueue_style( 'block_assets' ); | |
| 558 | + } | |
| 559 | + } | |
| 560 | + | |
| 561 | + /** | |
| 544 | 562 | * Get inline script used if bootstrap enqueued |
| 545 | 563 | * |
| 546 | 564 | * If this remains small then its best to use this than to add another JS file. |
| 547 | 565 | */ |
| @@ -727,41 +745,53 @@ | ||
| 727 | 745 | wp_enqueue_style( 'iconpicker' ); |
| 728 | 746 | wp_enqueue_script( 'iconpicker' ); |
| 729 | 747 | } |
| 730 | 748 | |
| 731 | - /** | |
| 732 | - * Get the url path to the current folder. | |
| 733 | - * | |
| 734 | - * This can be called very early, hence the need for the dynamic way of getting the URL. | |
| 735 | - * | |
| 736 | - * @since 0.2.31 changed to support edge cases like bitnami containers. | |
| 737 | - * @return string | |
| 738 | - */ | |
| 739 | - public function get_url() { | |
| 740 | - $content_dir = wp_normalize_path( untrailingslashit( WP_CONTENT_DIR ) ); | |
| 741 | - $content_url = untrailingslashit( WP_CONTENT_URL ); | |
| 749 | + /** | |
| 750 | + * Get the url path to the current folder. | |
| 751 | + * | |
| 752 | + * This can be called very early, hence the need for the dynamic way of getting the URL. | |
| 753 | + * | |
| 754 | + * @since 0.2.31 changed to support edge cases like bitnami containers. | |
| 755 | + * @return string | |
| 756 | + */ | |
| 757 | + public function get_url() { | |
| 758 | + $content_dir = wp_normalize_path( untrailingslashit( WP_CONTENT_DIR ) ); | |
| 759 | + $content_url = untrailingslashit( WP_CONTENT_URL ); | |
| 742 | 760 | |
| 743 | - // maybe Replace http:// to https://. | |
| 744 | - if ( strpos( $content_url, 'http://' ) === 0 && strpos( plugins_url(), 'https://' ) === 0 ) { | |
| 745 | - $content_url = str_replace( 'http://', 'https://', $content_url ); | |
| 746 | - } | |
| 761 | + // maybe Replace http:// to https://. | |
| 762 | + if ( strpos( $content_url, 'http://' ) === 0 && strpos( plugins_url(), 'https://' ) === 0 ) { | |
| 763 | + $content_url = str_replace( 'http://', 'https://', $content_url ); | |
| 764 | + } | |
| 747 | 765 | |
| 748 | - // First find where in the path our content directory starts | |
| 749 | - $content_basename = basename($content_dir); | |
| 750 | - $file_dir = str_replace( "/includes", "", wp_normalize_path( dirname( __FILE__ ) ) ); | |
| 766 | + // First find where in the path our content directory starts | |
| 767 | + $content_basename = basename($content_dir); | |
| 768 | + $file_dir = str_replace( "/includes", "", wp_normalize_path( dirname( __FILE__ ) ) ); | |
| 751 | 769 | |
| 752 | - // Find the relative path by matching from content directory name | |
| 753 | - $after_content = substr($file_dir, strpos($file_dir, '/' . $content_basename . '/') + strlen('/' . $content_basename . '/')); | |
| 770 | + // Find the relative path by matching from content directory name | |
| 771 | + $after_content = substr($file_dir, strpos($file_dir, '/' . $content_basename . '/') + strlen('/' . $content_basename . '/')); | |
| 754 | 772 | |
| 755 | - // Build URL using WP_CONTENT_URL and the relative path | |
| 756 | - $url = trailingslashit($content_url) . $after_content; | |
| 773 | + // Build URL using WP_CONTENT_URL and the relative path | |
| 774 | + $url = trailingslashit($content_url) . $after_content; | |
| 757 | 775 | |
| 758 | - // some hosts end up with /wp-content/wp-content/ | |
| 759 | - $url = str_replace( '/wp-content/wp-content/', '/wp-content/', $url ); | |
| 776 | + // some hosts end up with /wp-content/wp-content/ | |
| 777 | + $url = str_replace( '/wp-content/wp-content/', '/wp-content/', $url ); | |
| 760 | 778 | |
| 761 | - return trailingslashit($url); | |
| 762 | - } | |
| 779 | + /** | |
| 780 | + * Filters the URL to the AyeCode UI folder. | |
| 781 | + * | |
| 782 | + * Useful when the folder URL can't be worked out from its path, e.g. a symlinked plugin. | |
| 783 | + * | |
| 784 | + * @since 0.2.54 | |
| 785 | + * | |
| 786 | + * @param string $url The AyeCode UI folder URL. | |
| 787 | + * @param string $file_dir The AyeCode UI folder path. | |
| 788 | + */ | |
| 789 | + $url = apply_filters( 'ayecode_ui_url', $url, $file_dir ); | |
| 763 | 790 | |
| 791 | + return trailingslashit($url); | |
| 792 | + } | |
| 793 | + | |
| 764 | 794 | /** |
| 765 | 795 | * Get the url path to the current folder. |
| 766 | 796 | * @todo remove |
| 767 | 797 | * @return string |
| @@ -1329,8 +1359,15 @@ | ||
| 1329 | 1359 | return defined('AYECODE_UI_BS3_COMPAT') || defined('SVQ_THEME_VERSION') || defined('FUSION_BUILDER_VERSION'); |
| 1330 | 1360 | } |
| 1331 | 1361 | |
| 1332 | 1362 | public static function hex_to_rgb( $hex ) { |
| 1363 | + $hex = trim( (string) $hex ); | |
| 1364 | + | |
| 1365 | + // CSS variables can't be resolved to RGB server side. | |
| 1366 | + if ( $hex === '' || strpos( $hex, 'var(' ) !== false ) { | |
| 1367 | + return ''; | |
| 1368 | + } | |
| 1369 | + | |
| 1333 | 1370 | // Remove '#' if present |
| 1334 | 1371 | $hex = str_replace( '#', '', $hex ); |
| 1335 | 1372 | |
| 1336 | 1373 | // Check if input is RGB |
| @@ -1343,10 +1380,15 @@ | ||
| 1343 | 1380 | |
| 1344 | 1381 | return $rgb; |
| 1345 | 1382 | } |
| 1346 | 1383 | |
| 1347 | - // Convert 3-digit hex to 6-digit hex | |
| 1348 | - if ( strlen( $hex ) == 3 ) { | |
| 1384 | + // Only 3, 4, 6 or 8 digit hex can be converted, anything else (named colours, hsl() etc.) would give a wrong value. | |
| 1385 | + if ( ! preg_match( '/^([0-9a-f]{3,4}|[0-9a-f]{6}|[0-9a-f]{8})$/i', $hex ) ) { | |
| 1386 | + return ''; | |
| 1387 | + } | |
| 1388 | + | |
| 1389 | + // Convert 3 or 4 digit hex to 6-digit hex (alpha is ignored) | |
| 1390 | + if ( strlen( $hex ) <= 4 ) { | |
| 1349 | 1391 | $hex = str_repeat( substr( $hex, 0, 1 ), 2 ) . str_repeat( substr( $hex, 1, 1 ), 2 ) . str_repeat( substr( $hex, 2, 1 ), 2 ); |
| 1350 | 1392 | } |
| 1351 | 1393 | |
| 1352 | 1394 | // Convert hex to RGB |
| @@ -1358,8 +1400,34 @@ | ||
| 1358 | 1400 | return $r . ',' . $g . ',' . $b; |
| 1359 | 1401 | } |
| 1360 | 1402 | |
| 1361 | 1403 | /** |
| 1404 | + * Replace --bs-{type}-rgb usages when the color has no RGB value (eg a CSS variable). | |
| 1405 | + * | |
| 1406 | + * rgba(var(--bs-{type}-rgb), .5) would be invalid without the -rgb variable, so use color-mix() on the color itself. | |
| 1407 | + * | |
| 1408 | + * @param string $css The generated CSS. | |
| 1409 | + * @param string $type The color slug. | |
| 1410 | + * @param string $color_code The color value. | |
| 1411 | + * | |
| 1412 | + * @return string | |
| 1413 | + */ | |
| 1414 | + public static function css_rgb_fallback( $css, $type, $color_code ) { | |
| 1415 | + $type = preg_quote( $type, '/' ); | |
| 1416 | + | |
| 1417 | + // A comma triplet is required here, so leave the value from the stylesheet in place. | |
| 1418 | + $css = preg_replace( '/--bs-btn-focus-shadow-rgb:\s*var\(--bs-' . $type . '-rgb\);/', '', $css ); | |
| 1419 | + | |
| 1420 | + return preg_replace_callback( '/rgba?\(\s*var\(--bs-' . $type . '-rgb\)\s*(?:,\s*([0-9]*\.?[0-9]+)\s*)?\)/', function( $m ) use ( $color_code ) { | |
| 1421 | + if ( ! isset( $m[1] ) || (float) $m[1] >= 1 ) { | |
| 1422 | + return $color_code; | |
| 1423 | + } | |
| 1424 | + | |
| 1425 | + return 'color-mix(in srgb, ' . $color_code . ' ' . round( (float) $m[1] * 100, 2 ) . '%, transparent)'; | |
| 1426 | + }, $css ); | |
| 1427 | + } | |
| 1428 | + | |
| 1429 | + /** | |
| 1362 | 1430 | * Build the CSS to overwrite a bootstrap color variable. |
| 1363 | 1431 | * |
| 1364 | 1432 | * @param $type |
| 1365 | 1433 | * @param $color_code |
| @@ -1476,9 +1544,9 @@ | ||
| 1476 | 1544 | } else if ( $aui_bs5 ) { |
| 1477 | 1545 | $output .= $prefix . ' .text-' . sanitize_key( $type ) . '{color: var(--bs-' . sanitize_key( $type ) . ') !important;}'; |
| 1478 | 1546 | } |
| 1479 | 1547 | |
| 1480 | - $output .= $prefix . ' .link-'.esc_attr($type).' {color: var(--bs-'.esc_attr($type).'-rgb) !important;}'; | |
| 1548 | + $output .= $prefix . ' .link-'.esc_attr($type).' {color: var(--bs-'.esc_attr($type).') !important;}'; | |
| 1481 | 1549 | $output .= $prefix . ' .link-'.esc_attr($type).':hover {color: rgba(var(--bs-'.esc_attr($type).'-rgb), .8) !important;}'; |
| 1482 | 1550 | |
| 1483 | 1551 | // buttons |
| 1484 | 1552 | $output .= $prefix . ' .btn-'.esc_attr($type).'{'; |
| @@ -1486,9 +1554,9 @@ | ||
| 1486 | 1554 | --bs-btn-bg: '.esc_attr($color_code).'; |
| 1487 | 1555 | --bs-btn-border-color: '.esc_attr($color_code).'; |
| 1488 | 1556 | --bs-btn-hover-bg: rgba(var(--bs-'.esc_attr($type).'-rgb), .9); |
| 1489 | 1557 | --bs-btn-hover-border-color: rgba(var(--bs-'.esc_attr($type).'-rgb), .9); |
| 1490 | - --bs-btn-focus-shadow-rgb: --bs-'.esc_attr($type).'-rgb; | |
| 1558 | + --bs-btn-focus-shadow-rgb: var(--bs-'.esc_attr($type).'-rgb); | |
| 1491 | 1559 | --bs-btn-active-bg: rgba(var(--bs-'.esc_attr($type).'-rgb), .9); |
| 1492 | 1560 | --bs-btn-active-border-color: rgba(var(--bs-'.esc_attr($type).'-rgb), .9); |
| 1493 | 1561 | --bs-btn-active-shadow: unset; |
| 1494 | 1562 | --bs-btn-disabled-bg: rgba(var(--bs-'.esc_attr($type).'-rgb), .5); |
| @@ -1508,9 +1576,9 @@ | ||
| 1508 | 1576 | --bs-btn-color: '.esc_attr($color_code).'; |
| 1509 | 1577 | --bs-btn-border-color: '.esc_attr($color_code).'; |
| 1510 | 1578 | --bs-btn-hover-bg: rgba(var(--bs-'.esc_attr($type).'-rgb), .9); |
| 1511 | 1579 | --bs-btn-hover-border-color: rgba(var(--bs-'.esc_attr($type).'-rgb), .9); |
| 1512 | - --bs-btn-focus-shadow-rgb: --bs-'.esc_attr($type).'-rgb; | |
| 1580 | + --bs-btn-focus-shadow-rgb: var(--bs-'.esc_attr($type).'-rgb); | |
| 1513 | 1581 | --bs-btn-active-bg: rgba(var(--bs-'.esc_attr($type).'-rgb), .9); |
| 1514 | 1582 | --bs-btn-active-border-color: rgba(var(--bs-'.esc_attr($type).'-rgb), .9); |
| 1515 | 1583 | --bs-btn-active-shadow: unset; |
| 1516 | 1584 | --bs-btn-disabled-bg: rgba(var(--bs-'.esc_attr($type).'-rgb), .5); |
| @@ -1539,16 +1607,15 @@ | ||
| 1539 | 1607 | } |
| 1540 | 1608 | |
| 1541 | 1609 | // $output .= $is_var ? 'html body {--bs-'.esc_attr($type).'-rgb: '.$color_code.'; }' : 'html body {--bs-'.esc_attr($type).'-rgb: '.self::hex_to_rgb($color_code).'; }'; |
| 1542 | 1610 | $output .= 'html body {--bs-'.esc_attr($type).': '.esc_attr($color_code).'; }'; |
| 1543 | - $output .= 'html body {--bs-'.esc_attr($type).'-rgb: '.$rgb.'; }'; | |
| 1611 | + | |
| 1612 | + if ( $rgb !== '' ) { | |
| 1613 | + $output .= 'html body {--bs-' . esc_attr( $type ) . '-rgb: ' . $rgb . '; }'; | |
| 1614 | + } | |
| 1544 | 1615 | } |
| 1545 | 1616 | |
| 1546 | - | |
| 1547 | 1617 | if ( $is_custom ) { |
| 1548 | - | |
| 1549 | -// echo '###'.$type;exit; | |
| 1550 | - | |
| 1551 | 1618 | // build rules into each type |
| 1552 | 1619 | foreach($selectors as $selector => $types){ |
| 1553 | 1620 | $selector = $compatibility ? $compatibility . " ".$selector : $selector; |
| 1554 | 1621 | $types = array_combine($types,$types); |
| @@ -1649,8 +1716,18 @@ | ||
| 1649 | 1716 | // $output .= $is_var ? '' : $prefix ." .alert-{$type} {background-color: ".$color_code."20; border-color: ".$color_code."30;color:$darker_40} "; |
| 1650 | 1717 | $output .= $prefix ." .alert-{$type} {--bs-alert-bg: rgba(var(--bs-{$type}-rgb), .1 ) !important;--bs-alert-border-color: rgba(var(--bs-{$type}-rgb), .25 ) !important;--bs-alert-color: rgba(var(--bs-{$type}-rgb), 1 ) !important;} "; |
| 1651 | 1718 | } |
| 1652 | 1719 | |
| 1720 | + if ( $rgb === '' ) { | |
| 1721 | + // The stylesheet builds these from --bs-{type}-rgb, which is not set for this color. | |
| 1722 | + if ( $aui_bs5 ) { | |
| 1723 | + $output .= $prefix . " .bg-{$type}{background-color: color-mix(in srgb, $color_code calc(var(--bs-bg-opacity, 1) * 100%), transparent) !important;} "; | |
| 1724 | + $output .= $prefix . " .border-{$type}{border-color: color-mix(in srgb, $color_code calc(var(--bs-border-opacity, 1) * 100%), transparent) !important;} "; | |
| 1725 | + } | |
| 1726 | + | |
| 1727 | + $output = self::css_rgb_fallback( $output, $type, $color_code ); | |
| 1728 | + } | |
| 1729 | + | |
| 1653 | 1730 | return $output; |
| 1654 | 1731 | } |
| 1655 | 1732 | |
| 1656 | 1733 | /** |
| @@ -1767,9 +1844,12 @@ | ||
| 1767 | 1844 | $output = ''; |
| 1768 | 1845 | |
| 1769 | 1846 | if ( $aui_bs5 ) { |
| 1770 | 1847 | // $output .= $is_var ? 'html body {--bs-'.esc_attr($type).'-rgb: '.$color_code.'; }' : 'html body {--bs-'.esc_attr($type).'-rgb: '.self::hex_to_rgb($color_code).'; }'; |
| 1771 | - $output .= 'html body {--bs-'.esc_attr($type).'-rgb: '.$rgb.'; }'; | |
| 1848 | + | |
| 1849 | + if ( $rgb !== '' ) { | |
| 1850 | + $output .= 'html body {--bs-' . esc_attr( $type ) . '-rgb: ' . $rgb . '; }'; | |
| 1851 | + } | |
| 1772 | 1852 | } |
| 1773 | 1853 | |
| 1774 | 1854 | // build rules into each type |
| 1775 | 1855 | foreach($selectors as $selector => $types){ |
| @@ -1863,8 +1943,18 @@ | ||
| 1863 | 1943 | // alerts |
| 1864 | 1944 | if ( $aui_bs5 ) { |
| 1865 | 1945 | // $output .= $is_var ? '' : $prefix ." .alert-{$type} {background-color: ".$color_code."20; border-color: ".$color_code."30;color:$darker_40} "; |
| 1866 | 1946 | $output .= $prefix ." .alert-{$type} {--bs-alert-bg: rgba(var(--bs-{$type}-rgb), .1 ) !important;--bs-alert-border-color: rgba(var(--bs-{$type}-rgb), .25 ) !important;--bs-alert-color: rgba(var(--bs-{$type}-rgb), 1 ) !important;} "; |
| 1947 | + } | |
| 1948 | + | |
| 1949 | + if ( $rgb === '' ) { | |
| 1950 | + // The stylesheet builds these from --bs-{type}-rgb, which is not set for this color. | |
| 1951 | + if ( $aui_bs5 ) { | |
| 1952 | + $output .= $prefix . " .bg-{$type}{background-color: color-mix(in srgb, $color_code calc(var(--bs-bg-opacity, 1) * 100%), transparent) !important;} "; | |
| 1953 | + $output .= $prefix . " .border-{$type}{border-color: color-mix(in srgb, $color_code calc(var(--bs-border-opacity, 1) * 100%), transparent) !important;} "; | |
| 1954 | + } | |
| 1955 | + | |
| 1956 | + $output = self::css_rgb_fallback( $output, $type, $color_code ); | |
| 1867 | 1957 | } |
| 1868 | 1958 | |
| 1869 | 1959 | return $output; |
| 1870 | 1960 | } |