v1.3.0
This commit is contained in:
parent
a97911a978
commit
916d7845be
91 changed files with 6861 additions and 6907 deletions
|
|
@ -526,6 +526,11 @@ class Admin_Page {
|
|||
$sanitized['region'] = isset( $input['region'] ) ? sanitize_text_field( $input['region'] ) : '';
|
||||
$sanitized['domain'] = isset( $input['domain'] ) ? sanitize_text_field( $input['domain'] ) : '';
|
||||
|
||||
// Sub-sizes mode: strict whitelist, default 'all'.
|
||||
$raw_mode = isset( $input['subsizes_mode'] ) ? strtolower( (string) sanitize_text_field( $input['subsizes_mode'] ) ) : '';
|
||||
$allowed_modes = array( 'all', 'thumbnail', 'none' );
|
||||
$sanitized['subsizes_mode'] = in_array( $raw_mode, $allowed_modes, true ) ? $raw_mode : 'all';
|
||||
|
||||
return $sanitized;
|
||||
}
|
||||
|
||||
|
|
@ -565,24 +570,26 @@ class Admin_Page {
|
|||
* @return void
|
||||
*/
|
||||
public function render_settings_page(): void {
|
||||
$host = $this->config->get_host();
|
||||
$access_key = $this->config->get_key();
|
||||
$secret = $this->config->get_secret();
|
||||
$bucket = $this->config->get_bucket();
|
||||
$region = $this->config->get_region();
|
||||
$domain = $this->config->get_domain();
|
||||
$host = $this->config->get_host();
|
||||
$access_key = $this->config->get_key();
|
||||
$secret = $this->config->get_secret();
|
||||
$bucket = $this->config->get_bucket();
|
||||
$region = $this->config->get_region();
|
||||
$domain = $this->config->get_domain();
|
||||
$subsizes_mode = $this->config->get_subsizes_mode();
|
||||
|
||||
$is_configured = $this->config->is_configured();
|
||||
|
||||
// Check which fields are defined in wp-config.php.
|
||||
$host_in_config = $this->config->is_defined_in_wp_config( 'host' );
|
||||
$key_in_config = $this->config->is_defined_in_wp_config( 'key' );
|
||||
$secret_in_config = $this->config->is_defined_in_wp_config( 'secret' );
|
||||
$bucket_in_config = $this->config->is_defined_in_wp_config( 'bucket' );
|
||||
$region_in_config = $this->config->is_defined_in_wp_config( 'region' );
|
||||
$domain_in_config = $this->config->is_defined_in_wp_config( 'domain' );
|
||||
$host_in_config = $this->config->is_defined_in_wp_config( 'host' );
|
||||
$key_in_config = $this->config->is_defined_in_wp_config( 'key' );
|
||||
$secret_in_config = $this->config->is_defined_in_wp_config( 'secret' );
|
||||
$bucket_in_config = $this->config->is_defined_in_wp_config( 'bucket' );
|
||||
$region_in_config = $this->config->is_defined_in_wp_config( 'region' );
|
||||
$domain_in_config = $this->config->is_defined_in_wp_config( 'domain' );
|
||||
$subsizes_mode_in_config = $this->config->is_defined_in_wp_config( 'subsizes_mode' );
|
||||
|
||||
$any_in_config = $host_in_config || $key_in_config || $secret_in_config || $bucket_in_config || $region_in_config || $domain_in_config;
|
||||
$any_in_config = $host_in_config || $key_in_config || $secret_in_config || $bucket_in_config || $region_in_config || $domain_in_config || $subsizes_mode_in_config;
|
||||
?>
|
||||
<div class="wrap">
|
||||
<h1><?php esc_html_e( 'iDrivee2 Media Upload Settings', 'idrivee2-media-upload' ); ?></h1>
|
||||
|
|
@ -731,32 +738,80 @@ class Admin_Page {
|
|||
</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<th scope="row">
|
||||
<label for="idrivee2_domain"><?php esc_html_e( 'Custom CDN Domain', 'idrivee2-media-upload' ); ?></label>
|
||||
</th>
|
||||
<td>
|
||||
<input
|
||||
type="url"
|
||||
id="idrivee2_domain"
|
||||
name="idrivee2_media_settings[domain]"
|
||||
value="<?php echo esc_attr( $domain ); ?>"
|
||||
class="regular-text"
|
||||
placeholder="https://cdn.example.com"
|
||||
<?php echo $domain_in_config ? 'readonly' : ''; ?>
|
||||
/>
|
||||
<p class="description">
|
||||
<?php
|
||||
if ( $domain_in_config ) {
|
||||
esc_html_e( 'Defined in wp-config.php (IDRIVEE2_MEDIA_DOMAIN)', 'idrivee2-media-upload' );
|
||||
} else {
|
||||
esc_html_e( 'Optional: Custom domain for serving media files.', 'idrivee2-media-upload' );
|
||||
}
|
||||
?>
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
<tr>
|
||||
<th scope="row">
|
||||
<label for="idrivee2_domain"><?php esc_html_e( 'Custom CDN Domain', 'idrivee2-media-upload' ); ?></label>
|
||||
</th>
|
||||
<td>
|
||||
<input
|
||||
type="url"
|
||||
id="idrivee2_domain"
|
||||
name="idrivee2_media_settings[domain]"
|
||||
value="<?php echo esc_attr( $domain ); ?>"
|
||||
class="regular-text"
|
||||
placeholder="https://cdn.example.com"
|
||||
<?php echo $domain_in_config ? 'readonly' : ''; ?>
|
||||
/>
|
||||
<p class="description">
|
||||
<?php
|
||||
if ( $domain_in_config ) {
|
||||
esc_html_e( 'Defined in wp-config.php (IDRIVEE2_MEDIA_DOMAIN)', 'idrivee2-media-upload' );
|
||||
} else {
|
||||
esc_html_e( 'Optional: Custom domain for serving media files.', 'idrivee2-media-upload' );
|
||||
}
|
||||
?>
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<th scope="row">
|
||||
<label for="idrivee2_subsizes_mode"><?php esc_html_e( 'Image Sub-sizes', 'idrivee2-media-upload' ); ?></label>
|
||||
</th>
|
||||
<td>
|
||||
<select
|
||||
id="idrivee2_subsizes_mode"
|
||||
name="idrivee2_media_settings[subsizes_mode]"
|
||||
<?php echo $subsizes_mode_in_config ? 'disabled' : ''; ?>
|
||||
>
|
||||
<?php
|
||||
$mode_options = array(
|
||||
'all' => __( 'All registered sizes (WordPress default)', 'idrivee2-media-upload' ),
|
||||
'thumbnail' => __( 'Only thumbnail (faster uploads)', 'idrivee2-media-upload' ),
|
||||
'none' => __( 'No sub-sizes (original only)', 'idrivee2-media-upload' ),
|
||||
);
|
||||
foreach ( $mode_options as $value => $label ) {
|
||||
printf(
|
||||
'<option value="%s"%s>%s</option>',
|
||||
esc_attr( $value ),
|
||||
selected( $subsizes_mode, $value, false ),
|
||||
esc_html( $label )
|
||||
);
|
||||
}
|
||||
?>
|
||||
</select>
|
||||
<?php
|
||||
// Disabled selects are not submitted with the form; preserve the
|
||||
// constant-defined value via a hidden input so it is not lost on save.
|
||||
if ( $subsizes_mode_in_config ) {
|
||||
printf(
|
||||
'<input type="hidden" name="idrivee2_media_settings[subsizes_mode]" value="%s" />',
|
||||
esc_attr( $subsizes_mode )
|
||||
);
|
||||
}
|
||||
?>
|
||||
<p class="description">
|
||||
<?php
|
||||
if ( $subsizes_mode_in_config ) {
|
||||
esc_html_e( 'Defined in wp-config.php (IDRIVEE2_MEDIA_SUBSIZES_MODE)', 'idrivee2-media-upload' );
|
||||
} else {
|
||||
esc_html_e( 'Reduces work for large uploads (e.g. camera files). Also disables the -scaled derivative in thumbnail/none modes.', 'idrivee2-media-upload' );
|
||||
}
|
||||
?>
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<?php if ( ! $any_in_config ) : ?>
|
||||
|
|
@ -767,7 +822,7 @@ class Admin_Page {
|
|||
</p>
|
||||
<?php
|
||||
// Show submit button only if at least one field can be edited.
|
||||
$can_edit = ! $host_in_config || ! $key_in_config || ! $secret_in_config || ! $bucket_in_config || ! $region_in_config || ! $domain_in_config;
|
||||
$can_edit = ! $host_in_config || ! $key_in_config || ! $secret_in_config || ! $bucket_in_config || ! $region_in_config || ! $domain_in_config || ! $subsizes_mode_in_config;
|
||||
if ( $can_edit ) :
|
||||
?>
|
||||
<?php submit_button( __( 'Save Settings', 'idrivee2-media-upload' ) ); ?>
|
||||
|
|
|
|||
Loading…
Reference in a new issue