@@ -248,6 +248,11 @@ function ( $entry ) use ( $columns ) {
248248 case PHP_Types::JSON :
249249 $ entry [ $ column ->get_name () ] = wp_json_encode ( $ entry [ $ column ->get_name () ] );
250250 break ;
251+ case PHP_Types::BLOB :
252+ $ value = $ entry [ $ column ->get_name () ];
253+ // Only encode if not already base64 encoded.
254+ $ entry [ $ column ->get_name () ] = is_string ( $ value ) && base64_decode ( $ value , true ) !== false ? $ value : base64_encode ( (string ) $ value );
255+ break ;
251256 default :
252257 break ;
253258 }
@@ -472,7 +477,11 @@ public static function paginate( array $args, int $per_page = 20, int $page = 1,
472477 $ output
473478 );
474479
475- $ results = array_map ( fn ( $ result ) => static ::transform_from_array ( self ::amend_value_types ( $ result ) ), $ results );
480+ $ results = array_map ( fn ( $ result ) => self ::amend_value_types ( $ result ), $ results );
481+
482+ if ( [ '* ' === $ columns ] ) {
483+ $ results = array_map ( fn ( $ result ) => static ::transform_from_array ( $ result ), $ results );
484+ }
476485
477486 /**
478487 * Fires after the results of the query are fetched.
@@ -731,10 +740,13 @@ private static function prepare_value_for_query( string $column, $value ): array
731740
732741 switch ( $ column ->get_php_type () ) {
733742 case PHP_Types::INT :
734- case PHP_Types::BOOL :
735743 $ value = is_array ( $ value ) ? array_map ( fn ( $ v ) => (int ) $ v , $ value ) : (int ) $ value ;
736744 $ placeholder = '%d ' ;
737745 break ;
746+ case PHP_Types::BOOL :
747+ $ value = is_array ( $ value ) ? array_map ( fn ( $ v ) => (int ) (bool ) $ v , $ value ) : (int ) (bool ) $ value ;
748+ $ placeholder = '%d ' ;
749+ break ;
738750 case PHP_Types::STRING :
739751 case PHP_Types::DATETIME :
740752 $ value = is_array ( $ value ) ?
@@ -750,6 +762,15 @@ private static function prepare_value_for_query( string $column, $value ): array
750762 $ value = is_array ( $ value ) ? array_map ( fn ( $ v ) => (float ) $ v , $ value ) : (float ) $ value ;
751763 $ placeholder = '%f ' ;
752764 break ;
765+ case PHP_Types::BLOB :
766+ // For blob, we store as base64 encoded string.
767+ if ( is_array ( $ value ) ) {
768+ $ value = array_map ( fn ( $ v ) => is_string ( $ v ) ? $ v : base64_encode ( (string ) $ v ), $ value );
769+ } else {
770+ $ value = is_string ( $ value ) && base64_decode ( $ value , true ) !== false ? $ value : base64_encode ( (string ) $ value );
771+ }
772+ $ placeholder = '%s ' ;
773+ break ;
753774 default :
754775 throw new InvalidArgumentException ( "Unsupported column type: $ column_type. " );
755776 }
@@ -870,6 +891,12 @@ public static function cast_value_based_on_type( string $type, $value ) {
870891 }
871892
872893 return $ new_value ;
894+ case PHP_Types::BLOB :
895+ // Decode base64 encoded blob data.
896+ if ( is_string ( $ value ) && base64_decode ( $ value , true ) !== false ) {
897+ return base64_decode ( $ value );
898+ }
899+ return (string ) $ value ;
873900 default :
874901 throw new InvalidArgumentException ( "Unsupported column type: {$ type }. " );
875902 }
0 commit comments