Skip to content

Commit

Permalink
Pass proper options to register_setting. Minor adjustments to text fo…
Browse files Browse the repository at this point in the history
…r the setting
  • Loading branch information
dkotter committed Nov 20, 2024
1 parent 037bb35 commit 3d61762
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
15 changes: 12 additions & 3 deletions includes/safe-svg-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +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', [ $this, 'sanitize_safe_svg_large_svg' ] );
register_setting(
'media',
'safe_svg_large_svg',
[
'type' => 'integer',
'default' => 0,
'sanitize_callback' => 'absint',
]
);

add_settings_section(
'safe_svg_settings',
Expand All @@ -44,7 +52,7 @@ public function settings_init() {

add_settings_field(
'safe_svg_large_svg',
__( 'Large SVG Files', 'safe-svg' ),
__( 'Large Files', 'safe-svg' ),
[ $this, 'safe_svg_large_svg_cb' ],
'media',
'safe_svg_settings'
Expand Down Expand Up @@ -177,8 +185,9 @@ public function update_capability( $new_roles, $old_roles ) {
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' ); ?>
<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: 2 additions & 3 deletions safe-svg.php
Original file line number Diff line number Diff line change
Expand Up @@ -287,9 +287,8 @@ protected function sanitize( $file ) {
}
}

$large_svg = get_option( 'safe_svg_large_svg' );

if ( $large_svg ) {
// Allow large SVGs if the setting is on.
if ( get_option( 'safe_svg_large_svg' ) ) {
$this->sanitizer->setAllowHugeFiles( true );
}

Expand Down

0 comments on commit 3d61762

Please sign in to comment.