Skip to content

Commit

Permalink
Add option to enable large SVG items
Browse files Browse the repository at this point in the history
  • Loading branch information
kirtangajjar committed May 19, 2024
1 parent 3a19716 commit 962bd2c
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
19 changes: 19 additions & 0 deletions includes/safe-svg-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public function __construct() {
*/
public function settings_init() {
register_setting( 'media', 'safe_svg_upload_roles', [ $this, 'sanitize_safe_svg_roles' ] );
register_setting( 'media', 'safe_svg_large_svg', [ $this, 'sanitize_safe_svg_large_svg' ] );

add_settings_section(
'safe_svg_settings',
Expand All @@ -40,6 +41,14 @@ public function settings_init() {
'media',
'safe_svg_settings'
);

add_settings_field(
'safe_svg_large_svg',
__( 'Large SVG Files', 'safe-svg' ),
[ $this, 'safe_svg_large_svg_cb' ],
'media',
'safe_svg_settings'
);
}

/**
Expand Down Expand Up @@ -162,4 +171,14 @@ public function update_capability( $new_roles, $old_roles ) {
return $new_roles;
}

/**
* Large SVG files field callback function.
*/
public function safe_svg_large_svg_cb() {
?>
<label>
<input type="checkbox" name="safe_svg_large_svg" value="1" <?php checked( get_option( 'safe_svg_large_svg' ), 1 ); ?> /> <?php esc_html_e( 'Allow large SVG files(>10MB) to be uploaded.', 'safe-svg' ); ?>
</label>
<?php
}
}
6 changes: 6 additions & 0 deletions safe-svg.php
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,12 @@ protected function sanitize( $file ) {
}
}

$large_svg = get_option( 'safe_svg_large_svg' );

if ( $large_svg ) {
$this->sanitizer->setAllowHugeFiles( true );
}

/**
* Load extra filters to allow devs to access the safe tags and attrs by themselves.
*/
Expand Down

0 comments on commit 962bd2c

Please sign in to comment.