| 1 |
<?php |
| 2 |
defined( 'ABSPATH' ) or die( 'Cheatin\' uh?' ); |
| 3 |
|
| 4 |
/** |
| 5 |
* Round UP to nearest half integer |
| 6 |
* |
| 7 |
* @since 1.0 |
| 8 |
* @source http://stackoverflow.com/a/13526408 |
| 9 |
* |
| 10 |
* @param int $number The number to round up |
| 11 |
* @return int $number The formatted number |
| 12 |
*/ |
| 13 |
function imagify_round_half_five( $number ) { |
| 14 |
$number = strval( $number ); |
| 15 |
$number = explode( '.', $number ); |
| 16 |
|
| 17 |
if ( ! isset( $number[1] ) ) { |
| 18 |
return $number[0]; |
| 19 |
} |
| 20 |
|
| 21 |
$decimal = floatval( '0.' . substr( $number[1], 0 , 2 ) ); // cut only 2 number |
| 22 |
if ( $decimal > 0 ) { |
| 23 |
if( $decimal <= 0.5 ) { |
| 24 |
return floatval( $number[0] ) + 0.5; |
| 25 |
} elseif ( $decimal > 0.5 && $decimal <= 0.99 ) { |
| 26 |
return floatval( $number[0]) + 1; |
| 27 |
} |
| 28 |
} else { |
| 29 |
return floatval( $number ); |
| 30 |
} |
| 31 |
} |
| 32 |
|
| 33 |
/** |
| 34 |
* Get the Imagify attachment class name depending to a context |
| 35 |
* |
| 36 |
* @since 1.5 |
| 37 |
* @source Jonathan Buttigieg |
| 38 |
* |
| 39 |
* @param string $context The context to determine the class name |
| 40 |
* @return string $class_name The Imagify attachment class name |
| 41 |
*/ |
| 42 |
function get_imagify_attachment_class_name( $context = 'wp' ) { |
| 43 |
$class_name = 'Imagify_'; |
| 44 |
$class_name .= 'wp' !== $context ? $context . '_Attachment' : 'Attachment'; |
| 45 |
|
| 46 |
return $class_name; |
| 47 |
} |