@@ -104,7 +104,7 @@ public static function create( array $options, WP_Post $post = null ): WP_Post|W
104
104
*
105
105
* @param int $wpcloud_site_id The site ID.
106
106
*/
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 {
108
108
$ site = get_posts (
109
109
array (
110
110
'post_type ' => 'wpcloud_site ' ,
@@ -387,21 +387,21 @@ public static function get_mutable_options(): array {
387
387
'default ' => false ,
388
388
'hint ' => __ ( 'Site access is via SFTP by default. Enabling allows access via SSH ' ),
389
389
),
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` ' ),
404
396
),
397
+
398
+ 'edge_cache_purge ' => array (
399
+ 'label ' => __ ( 'Edge Cache Purge ' ),
400
+ 'type ' => 'hidden ' ,
401
+ 'default ' => '' ,
402
+ 'hint ' => __ ( 'Purge edge cache ' ),
403
+ ),
404
+
405
405
'defensive_mode ' => array (
406
406
'label ' => __ ( 'Defensive Mode ' ),
407
407
'type ' => 'text ' ,
@@ -580,23 +580,13 @@ public static function get_detail( int|WP_Post $post, string $key, ): mixed {
580
580
// @TODO: Confirm that this is always the case, it appears that the port will be 2223 for ssh and 2221 for sftp
581
581
return 2223 === $ ssh_port ;
582
582
583
- case 'edge_cache ' :
583
+ case 'edge_cache_toggle ' :
584
584
$ result = wpcloud_client_edge_cache_status ( $ wpcloud_site_id );
585
585
if ( is_wp_error ( $ result ) ) {
586
586
error_log ( $ result ->get_error_message () );
587
587
return '' ;
588
588
}
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 ;
600
590
601
591
case 'defensive_mode ' :
602
592
$ result = wpcloud_client_edge_cache_status ( $ wpcloud_site_id );
@@ -678,7 +668,10 @@ function ( $value, $key ) use ( $mutable_fields ) {
678
668
$ value = intval ( $ value ) . 'G ' ;
679
669
break ;
680
670
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 ' :
682
675
$ result = wpcloud_client_edge_cache_update ( $ wpcloud_site_id , $ value );
683
676
break ;
684
677
}
0 commit comments