wc_light_or_dark با توجه به ورودی داده شده پشت زمینه را روشن یا تاریک می کند ؟

wc_light_or_dark با توجه به ورودی داده شده پشت زمینه را روشن یا تاریک می کند ؟

تابع ووکامرسی wc_light_or_dark – با توجه به ورودی داده شده پشت زمینه را روشن یا تاریک می کند ؟

Syntax – سینتکس

(string) wc_light_or_dark( (mixed) $color, (string) $dark = '#000000', (string) $light = '#FFFFFF' ); 

Parameters – پارامتر ها (3)

  • 1- $color (mixed)
  • 2- $dark (string)
  • 3- $light (string)

Usage – نحوه استفاده

if ( !function_exists( 'wc_light_or_dark' ) ) { 
    require_once ABSPATH . PLUGINDIR . 'woocommerce/includes/wc-formatting-functions.php'; 
} 
  
// The color. 
$color = null; 
  
// (default: '#000000') 
$dark = '#000000'; 
  
// (default: '#FFFFFF') 
$light = '#FFFFFF'; 
  
// NOTICE! Understand what this does before running. 
$result = wc_light_or_dark($color, $dark, $light); 
    

Defined – محل تعریف

/includes/wc-formatting-functions.php

function wc_light_or_dark( $color, $dark = '#000000', $light = '#FFFFFF' ) { 
 
    $hex = str_replace( '#', '', $color ); 
 
    $c_r = hexdec( substr( $hex, 0, 2 ) ); 
    $c_g = hexdec( substr( $hex, 2, 2 ) ); 
    $c_b = hexdec( substr( $hex, 4, 2 ) ); 
 
    $brightness = ( ( $c_r * 299 ) + ( $c_g * 587 ) + ( $c_b * 114 ) ) / 1000; 
 
    return $brightness > 155 ? $dark : $light; 
} 

versions – نسخه ها

از نسخه : 3.0.2

نسخه فعلی : 3.0.6

دیگر نسخه ها : 3.0.6 , 3.0.5 , 3.0.4 , 3.0.3 , 3.0.2

ارسال نظر

جهت استفاده از کد حتما از تگ pre استفاده نمایید .

contact us