Skip to content

Commit

Permalink
Merge pull request #201 from 10up/fix/large-svg-items
Browse files Browse the repository at this point in the history
Add option to enable large SVGs
  • Loading branch information
dkotter authored Nov 20, 2024
2 parents 79c257a + 0e6bdfe commit fa36531
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"email": "[email protected]",
"homepage": "https://10up.com/",
"role": "Developer"
},
},
{
"name": "Daryll Doyle",
"email": "[email protected]",
Expand Down
28 changes: 28 additions & 0 deletions includes/safe-svg-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,15 @@ 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',
[
'type' => 'integer',
'default' => 0,
'sanitize_callback' => 'absint',
]
);

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

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

/**
Expand Down Expand Up @@ -162,4 +179,15 @@ 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', 'safe-svg' ); ?>
</label>
<p class="description"><?php esc_html_e( 'Turning this on will allow SVG files larger than 10MB to be uploaded. This can impact performance and is not recommended unless needed.', 'safe-svg' ); ?></p>
<?php
}
}
5 changes: 5 additions & 0 deletions safe-svg.php
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,11 @@ protected function sanitize( $file ) {
}
}

// Allow large SVGs if the setting is on.
if ( get_option( 'safe_svg_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 fa36531

Please sign in to comment.