Skip to content

Commit

Permalink
NumericVal meta value when create column
Browse files Browse the repository at this point in the history
  • Loading branch information
parsakafi committed Sep 1, 2023
1 parent 03673f7 commit 93953a8
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions inc/Helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ public function addTableColumn( $table, $type, $field, $metaValue ) {
$collate = '';

$value = maybe_serialize( $metaValue );
$value = $this->numericVal( $value );
$columnType = $this->getFieldType( $value );
$valueLength = mb_strlen( $value );

Expand Down Expand Up @@ -261,6 +262,23 @@ public function addTableColumn( $table, $type, $field, $metaValue ) {
return $addTableColumn;
}

/**
* Get the numeric (integer, float) value of a variable
*
* @param mixed $value The scalar value being converted to an integer or float
*
* @return float|int|mixed|string
*/
public function numericVal( $value ) {
if ( is_numeric( $value ) )
if ( intval( $value ) == $value )
return intval( $value );
elseif ( floatval( $value ) == $value )
return floatval( $value );

return $value;
}

/**
* Check column exists in plugin tables
*
Expand Down

0 comments on commit 93953a8

Please sign in to comment.