Skip to content

Commit

Permalink
FIX: apply rich content on max_size & max_files attributes in Med…
Browse files Browse the repository at this point in the history
…ia Field

Crocoblock/issues-tracker#9359
  • Loading branch information
girafffee committed Jul 30, 2024
1 parent 528c0da commit 3745052
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions modules/block-parsers/file-uploader.php
Original file line number Diff line number Diff line change
Expand Up @@ -188,16 +188,19 @@ protected function sanitize_file( File $file ) {
}

public function get_max_size(): int {
$max_size = wp_max_upload_size();
$field_max_size = $max_size;
$max_size = wp_max_upload_size();

if ( ! empty( $this->settings['max_size'] ) ) {
if ( empty( $this->settings['max_size'] ) ) {
return $max_size;
}

$field_max_size = intval( floatval( $this->settings['max_size'] ) * MB_IN_BYTES );
$field_max_size = floatval(
\JFB_Modules\Rich_Content\Module::rich( $this->settings['max_size'] ?? '' )
);
$field_max_size = intval( $field_max_size * MB_IN_BYTES );

if ( $field_max_size > $max_size ) {
$field_max_size = $max_size;
}
if ( $field_max_size > $max_size ) {
return $max_size;
}

return $field_max_size;
Expand All @@ -215,7 +218,9 @@ public function count_files(): int {
}

public function get_max_files(): int {
$files = absint( $this->settings['max_files'] ?? 1 );
$files = absint(
\JFB_Modules\Rich_Content\Module::rich( $this->settings['max_files'] ?? '' )
);

return empty( $files ) ? 1 : $files;
}
Expand Down

0 comments on commit 3745052

Please sign in to comment.