Skip to content

Commit 531a6b4

Browse files
authored
Update Edge cache (#214)
* Show input for hidden input * update edge cache settings * update single site template add edge cache settings
1 parent 764bf0e commit 531a6b4

File tree

3 files changed

+145
-111
lines changed

3 files changed

+145
-111
lines changed

plugin/blocks/src/components/form-input/edit.js

+10-1
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ function InputFieldBlock( { attributes, setAttributes, className, context, clien
133133
/>
134134
</>
135135
)}
136-
{'checkbox' == type && (
136+
{'checkbox' === type && (
137137
<ToggleControl
138138
label={__('Display as Toggle')}
139139
checked={displayAsToggle}
@@ -144,6 +144,15 @@ function InputFieldBlock( { attributes, setAttributes, className, context, clien
144144
}}
145145
/>
146146
)}
147+
{'hidden' === type && (
148+
<TextControl
149+
label={__('Value')}
150+
value={attributes.value}
151+
onChange={(newValue) => {
152+
setAttributes({ value: newValue });
153+
}}
154+
/>
155+
)}
147156
<ToggleControl
148157
label={ __( 'Limit to Admins' ) }
149158
checked={ adminOnly }

plugin/includes/class-wpcloud-site.php

+21-28
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ public static function create( array $options, WP_Post $post = null ): WP_Post|W
104104
*
105105
* @param int $wpcloud_site_id The site ID.
106106
*/
107-
public static function get_by_id( int $wpcloud_site_id ): null|WP_Post {
107+
public static function get_by_id( ?int $wpcloud_site_id ): null|WP_Post {
108108
$site = get_posts(
109109
array(
110110
'post_type' => 'wpcloud_site',
@@ -387,21 +387,21 @@ public static function get_mutable_options(): array {
387387
'default' => false,
388388
'hint' => __( 'Site access is via SFTP by default. Enabling allows access via SSH' ),
389389
),
390-
'edge_cache' => array(
391-
'label' => __( 'Edge Cache' ),
392-
'type' => 'select',
393-
'options' => array(
394-
'on' => __( 'On' ),
395-
'off' => __( 'Off' ),
396-
'purge' => __( 'Purge' ),
397-
),
398-
'option_aliases' => array(
399-
'on' => __( 'Enabled', 'wpcloud' ),
400-
'off' => __( 'Disabled', 'wpcloud' ),
401-
),
402-
'default' => '',
403-
'hint' => __( 'Change the edge cache status. Either `on`, `off` or `purge`' ),
390+
391+
'edge_cache_toggle' => array(
392+
'label' => __( 'Edge Cache Toggle' ),
393+
'type' => 'checkbox',
394+
'default' => '',
395+
'hint' => __( 'Enable edge cache. Either `on`, `off`' ),
404396
),
397+
398+
'edge_cache_purge' => array(
399+
'label' => __( 'Edge Cache Purge' ),
400+
'type' => 'hidden',
401+
'default' => '',
402+
'hint' => __( 'Purge edge cache' ),
403+
),
404+
405405
'defensive_mode' => array(
406406
'label' => __( 'Defensive Mode' ),
407407
'type' => 'text',
@@ -580,23 +580,13 @@ public static function get_detail( int|WP_Post $post, string $key, ): mixed {
580580
// @TODO: Confirm that this is always the case, it appears that the port will be 2223 for ssh and 2221 for sftp
581581
return 2223 === $ssh_port;
582582

583-
case 'edge_cache':
583+
case 'edge_cache_toggle':
584584
$result = wpcloud_client_edge_cache_status( $wpcloud_site_id );
585585
if ( is_wp_error( $result ) ) {
586586
error_log( $result->get_error_message() );
587587
return '';
588588
}
589-
switch ( $result->status ) {
590-
case 0:
591-
return __( 'Disabled', 'wpcloud' );
592-
case 1:
593-
return __( 'Enabled', 'wpcloud' );
594-
case 2:
595-
return __( 'DDoS', 'wpcloud' );
596-
default:
597-
return __( 'Unknown', 'wpcloud' );
598-
}
599-
return '';
589+
return (bool) $result->status;
600590

601591
case 'defensive_mode':
602592
$result = wpcloud_client_edge_cache_status( $wpcloud_site_id );
@@ -678,7 +668,10 @@ function ( $value, $key ) use ( $mutable_fields ) {
678668
$value = intval( $value ) . 'G';
679669
break;
680670

681-
case 'edge_cache':
671+
case 'edge_cache_toggle':
672+
$value = $value ? 'on' : 'off';
673+
// Fallthrough intentional to make edge cache call.
674+
case 'edge_cache_purge':
682675
$result = wpcloud_client_edge_cache_update( $wpcloud_site_id, $value );
683676
break;
684677
}

0 commit comments

Comments
 (0)