Skip to content

Commit c91a855

Browse files
2 parents 3933d3c + bf0abc7 commit c91a855

5 files changed

Lines changed: 129 additions & 100 deletions

src/class-tiny-settings.php

Lines changed: 13 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -661,85 +661,6 @@ public function render_size_checkboxes_description(
661661
echo '</p>';
662662
}
663663

664-
public function render_resize() {
665-
$strong = array(
666-
'strong' => array(),
667-
);
668-
669-
echo '<div class="tiny-resize-unavailable" style="display: none">';
670-
esc_html_e(
671-
'Enable compression of the original image size for more options.',
672-
'tiny-compress-images'
673-
);
674-
echo '</div>';
675-
676-
$id = self::get_prefixed_name( 'resize_original_enabled' );
677-
$name = self::get_prefixed_name( 'resize_original[enabled]' );
678-
$checked = ( $this->get_resize_enabled() ? ' checked="checked"' : '' );
679-
680-
$label = esc_html__(
681-
'Resize the original image',
682-
'tiny-compress-images'
683-
);
684-
685-
echo '<div class="tiny-resize-available">';
686-
echo '<input type="checkbox" id="' . $id . '" name="' . $name .
687-
'" value="on" ' . $checked . '/>';
688-
echo '<label for="' . $id . '">' . $label . '</label><br>';
689-
690-
echo '<div class="tiny-resize-available tiny-resize-resolution">';
691-
echo '<span>';
692-
echo wp_kses(
693-
__(
694-
// phpcs:ignore Generic.Files.LineLength
695-
'<strong>Save space</strong> by setting a maximum width and height for all images uploaded.',
696-
'tiny-compress-images'
697-
),
698-
$strong
699-
);
700-
echo '<br>';
701-
echo wp_kses(
702-
__(
703-
// phpcs:ignore Generic.Files.LineLength
704-
'Resizing takes <strong>1 additional compression</strong> for each image that is larger.',
705-
'tiny-compress-images'
706-
),
707-
$strong
708-
);
709-
echo '</span>';
710-
echo '<div class="tiny-resize-inputs">';
711-
printf( '%s: ', esc_html__( 'Max Width', 'tiny-compress-images' ) );
712-
$this->render_resize_input( 'width' );
713-
printf( '%s: ', esc_html__( 'Max Height', 'tiny-compress-images' ) );
714-
$this->render_resize_input( 'height' );
715-
echo '</div></div></div>';
716-
717-
$this->render_preserve_input(
718-
'creation',
719-
esc_html__(
720-
'Preserve creation date and time in the original image',
721-
'tiny-compress-images'
722-
)
723-
);
724-
725-
$this->render_preserve_input(
726-
'copyright',
727-
esc_html__(
728-
'Preserve copyright information in the original image',
729-
'tiny-compress-images'
730-
)
731-
);
732-
733-
$this->render_preserve_input(
734-
'location',
735-
esc_html__(
736-
'Preserve GPS location in the original image',
737-
'tiny-compress-images'
738-
) . ' ' .
739-
esc_html__( '(JPEG only)', 'tiny-compress-images' )
740-
);
741-
}
742-
743664
public function render_compression_timing_radiobutton(
744665
$name,
745666
$label,
@@ -776,25 +697,23 @@ public function render_compression_timing_radiobutton(
776697
}
777698

778699
public function render_preserve_input( $name, $description ) {
779-
echo '<p class="tiny-preserve">';
780-
$id = sprintf( self::get_prefixed_name( 'preserve_data_%s' ), $name );
781-
$field = sprintf( self::get_prefixed_name( 'preserve_data[%s]' ), $name );
782-
$checked = ( $this->get_preserve_enabled( $name ) ? ' checked="checked"' : '' );
783-
$label = esc_html( $description, 'tiny-compress-images' );
784-
echo '<input type="checkbox" id="' . $id . '" name="' . $field .
785-
'" value="on" ' . $checked . '/>';
786-
echo '<label for="' . $id . '">' . $label . '</label>';
787-
echo '<br>';
788-
echo '</p>';
700+
$data = array(
701+
'id' => sprintf( self::get_prefixed_name( 'preserve_data_%s' ), $name ),
702+
'field' => sprintf( self::get_prefixed_name( 'preserve_data[%s]' ), $name ),
703+
'checked' => $this->get_preserve_enabled( $name ),
704+
'label' => $description,
705+
);
706+
include plugin_dir_path( __FILE__ ) . 'views/settings-original-image-preserve.php';
789707
}
790708

791709
public function render_resize_input( $name ) {
792-
$id = sprintf( self::get_prefixed_name( 'resize_original_%s' ), $name );
793-
$field = sprintf( self::get_prefixed_name( 'resize_original[%s]' ), $name );
794710
$settings = get_option( self::get_prefixed_name( 'resize_original' ) );
795-
$value = isset( $settings[ $name ] ) ? $settings[ $name ] : '2048';
796-
echo '<input type="number" id="' . $id . '" name="' . $field .
797-
'" value="' . $value . '" size="5" />';
711+
$data = array(
712+
'id' => sprintf( self::get_prefixed_name( 'resize_original_%s' ), $name ),
713+
'field' => sprintf( self::get_prefixed_name( 'resize_original[%s]' ), $name ),
714+
'value' => isset( $settings[ $name ] ) ? $settings[ $name ] : '2048',
715+
);
716+
include plugin_dir_path( __FILE__ ) . 'views/settings-original-image-original.php';
798717
}
799718

800719
public function get_compression_count() {
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<input
2+
type="number"
3+
id="<?php echo esc_attr( $data['id'] ); ?>"
4+
name="<?php echo esc_attr( $data['field'] ); ?>"
5+
value="<?php echo esc_attr( $data['value'] ); ?>"
6+
size="5"
7+
/>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<p class="tiny-preserve">
2+
<input type="checkbox"
3+
id="<?php echo esc_attr( $data['id'] ); ?>"
4+
name="<?php echo esc_attr( $data['field'] ); ?>"
5+
<?php checked( $data['checked'] ); ?>
6+
value="on"
7+
/>
8+
<label for="<?php echo esc_attr( $data['id'] ); ?>">
9+
<?php echo esc_html( $data['label'] ); ?>
10+
</label>
11+
</p>
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
<?php
2+
3+
$strong = array(
4+
'strong' => array(),
5+
);
6+
7+
?>
8+
9+
<tr>
10+
<th scope="row"><?php esc_html_e( 'Original image', 'tiny-compress-images' ); ?></th>
11+
<td>
12+
<div class="tiny-resize-unavailable" style="display: none">
13+
<?php
14+
esc_html_e(
15+
'Enable compression of the original image size for more options.',
16+
'tiny-compress-images'
17+
);
18+
?>
19+
</div>
20+
<div class="tiny-resize-available">
21+
<?php
22+
$resize_original_enabled_id = self::get_prefixed_name( 'resize_original_enabled' );
23+
$resize_original_enabled_name = self::get_prefixed_name( 'resize_original[enabled]' );
24+
$resize_original_enabled = $this->get_resize_enabled();
25+
?>
26+
<input
27+
type="checkbox"
28+
id="<?php echo esc_attr( $resize_original_enabled_id ); ?>"
29+
name="<?php echo esc_attr( $resize_original_enabled_name ); ?>"
30+
value="on"
31+
<?php checked( $resize_original_enabled ); ?> />
32+
<label for="<?php echo esc_attr( $resize_original_enabled_id ); ?>">
33+
<?php
34+
esc_html_e(
35+
'Resize the original image',
36+
'tiny-compress-images'
37+
);
38+
?>
39+
</label><br>
40+
<div class="tiny-resize-available tiny-resize-resolution">
41+
<span>
42+
<?php
43+
echo wp_kses(
44+
__(
45+
'<strong>Save space</strong> by setting a maximum width and height for all images uploaded.',
46+
'tiny-compress-images'
47+
),
48+
$strong
49+
);
50+
?>
51+
<br>
52+
<?php
53+
echo wp_kses(
54+
__(
55+
'Resizing takes <strong>1 additional compression</strong> for each image that is larger.',
56+
'tiny-compress-images'
57+
),
58+
$strong
59+
);
60+
?>
61+
</span>
62+
63+
<div class="tiny-resize-inputs">
64+
<?php esc_html_e( 'Max Width', 'tiny-compress-images' ); ?>:
65+
<?php $this->render_resize_input( 'width' ); ?>
66+
<?php esc_html_e( 'Max Height', 'tiny-compress-images' ); ?>:
67+
<?php $this->render_resize_input( 'height' ); ?>
68+
</div>
69+
</div>
70+
71+
<?php
72+
$this->render_preserve_input(
73+
'creation',
74+
esc_html__(
75+
'Preserve creation date and time in the original image',
76+
'tiny-compress-images'
77+
)
78+
);
79+
$this->render_preserve_input(
80+
'copyright',
81+
esc_html__(
82+
'Preserve copyright information in the original image',
83+
'tiny-compress-images'
84+
)
85+
);
86+
$this->render_preserve_input(
87+
'location',
88+
esc_html__(
89+
'Preserve GPS location in the original image',
90+
'tiny-compress-images'
91+
) . ' ' .
92+
esc_html__( '(JPEG only)', 'tiny-compress-images' )
93+
);
94+
?>
95+
</div>
96+
</td>
97+
</tr>

src/views/settings.php

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,7 @@
5151
<?php $this->render_format_conversion(); ?>
5252
</td>
5353
</tr>
54-
<tr>
55-
<th scope="row"><?php esc_html_e( 'Original image', 'tiny-compress-images' ); ?></th>
56-
<td>
57-
<?php $this->render_resize(); ?>
58-
</td>
59-
</tr>
54+
<?php require plugin_dir_path( __FILE__ ) . 'settings-original-image.php'; ?>
6055
</tbody>
6156
</table>
6257

0 commit comments

Comments
 (0)