This repository has been archived by the owner on Dec 5, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
wp-cloudflare-api.php
2956 lines (2740 loc) · 109 KB
/
wp-cloudflare-api.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/**
* Library for accessing the CloudFlare API on WordPress
*
* @link https://api.cloudflare.com/ API Documentation
* @package WP-API-Libraries\WP-IDX-Cloudflare-API
*/
/*
* Plugin Name: Cloudflare API
* Plugin URI: https://wp-api-libraries.com/
* Description: Perform API requests.
* Author: WP API Libraries
* Version: 1.0.0
* Author URI: https://wp-api-libraries.com
* GitHub Plugin URI: https://github.com/imforza
* GitHub Branch: master
*/
/* Exit if accessed directly */
if ( ! defined( 'ABSPATH' ) ) { exit; }
if ( ! class_exists( 'CloudFlareAPI' ) ) {
/**
* A WordPress API library for accessing the Cloudflare API.
*
* @version 1.1.0
* @link https://api.cloudflare.com/ API Documentation
* @package WP-API-Libraries\WP-IDX-Cloudflare-API
* @author Santiago Garza <https://github.com/sfgarza>
* @author imFORZA <https://github.com/imforza>
*/
class CloudFlareAPI {
/**
* API Key.
*
* @var string
*/
static protected $api_key;
/**
* Auth Email
*
* @var string
*/
static protected $auth_email;
/**
* User Service Key
*
* @var string
*/
static protected $user_service_key;
/**
* CloudFlare BaseAPI Endpoint
*
* @var string
* @access protected
*/
protected $base_uri = 'https://api.cloudflare.com/client/v4/';
/**
* Route being called.
*
* @var string
*/
protected $route = '';
/**
* Class constructor.
*
* @param string $api_key Cloudflare API Key.
* @param string $auth_email Email associated to the account.
* @param string $user_service_key User Service key.
*/
public function __construct( $api_key, $auth_email, $user_service_key = '' ) {
static::$api_key = $api_key;
static::$auth_email = $auth_email;
static::$user_service_key = $user_service_key;
}
/**
* Prepares API request.
*
* @param string $route API route to make the call to.
* @param array $args Arguments to pass into the API call.
* @param array $method HTTP Method to use for request.
* @return self Returns an instance of itself so it can be chained to the fetch method.
*/
protected function build_request( $route, $args = array(), $method = 'GET' ) {
// Start building query.
$this->set_headers();
$this->args['method'] = $method;
$this->route = $route;
// Generate query string for GET requests.
if ( 'GET' === $method ) {
$this->route = add_query_arg( array_filter( $args ), $route );
} elseif ( 'application/json' === $this->args['headers']['Content-Type'] ) {
$this->args['body'] = wp_json_encode( $args );
} else {
$this->args['body'] = $args;
}
$this->args['timeout'] = 20;
return $this;
}
/**
* Fetch the request from the API.
*
* @access private
* @return array|WP_Error Request results or WP_Error on request failure.
*/
protected function fetch() {
// Make the request.
// pp( $this->base_uri . $this->route, $this->args );
$response = wp_remote_request( $this->base_uri . $this->route, $this->args );
// pp( $response );
// Retrieve Status code & body.
$code = wp_remote_retrieve_response_code( $response );
$body = json_decode( wp_remote_retrieve_body( $response ) );
$this->clear();
// Return WP_Error if request is not successful.
if ( ! $this->is_status_ok( $code ) ) {
return new WP_Error( 'response-error', sprintf( __( 'Status: %d', 'wp-postmark-api' ), $code ), $body );
}
return $body;
}
/**
* Set request headers.
*/
protected function set_headers() {
// Set request headers.
$this->args['headers'] = array(
'Content-Type' => 'application/json',
'X-Auth-Email' => static::$auth_email,
'X-Auth-Key' => static::$api_key,
);
}
/**
* Clear query data.
*/
protected function clear() {
$this->args = array();
$this->query_args = array();
}
/**
* Check if HTTP status code is a success.
*
* @param int $code HTTP status code.
* @return boolean True if status is within valid range.
*/
protected function is_status_ok( $code ) {
return ( 200 <= $code && 300 > $code );
}
/**
* Get User Properties
*
* Account Access: FREE, PRO, Business, Enterprise
*
* @api GET
* @see https://api.cloudflare.com/#user-user-details Documentation.
* @access public
* @return array User information.
*/
public function get_user() {
return $this->build_request( 'user' )->fetch();
}
/**
* Update User
*
* Account Access: FREE, PRO, Business, Enterprise
*
* @api PATCH
* @see https://api.cloudflare.com/#user-update-user Documentation.
* @access public
* @param string $first_name User's first name.
* @param string $last_name User's last name.
* @param string $phone User's telephone number.
* @param string $country User's The country in which the user lives.
* @param string $zipcode The zipcode or postal code where the user lives.
* @return array Updated user info.
*/
public function update_user( $first_name = null, $last_name = null, $phone = null, $country = null, $zipcode = null ) {
$args = array();
if ( null !== $first_name ) {
$args['first_name'] = $first_name;
}
if ( null !== $last_name ) {
$args['last_name'] = $last_name;
}
if ( null !== $phone ) {
$args['telephone'] = $phone;
}
if ( null !== $country ) {
$args['country'] = $country;
}
if ( null !== $zipcode ) {
$args['zipcode'] = $zipcode;
}
return $this->build_request( 'user', $args, 'PATCH' )->fetch();
}
/**
* Get User Billing Profile.
*
* Account Access: FREE, PRO, Business, Enterprise
*
* @api GET
* @see https://api.cloudflare.com/#user-billing-profile-billing-profile Documentation.
* @access public
* @return array User billing profile.
*/
public function get_user_billing_profile() {
return $this->build_request( 'user/billing/profile' )->fetch();
}
/**
* Get User Billing History
*
* @api GET
* @see https://api.cloudflare.com/#user-billing-history-billing-history Documentation
* @access public
* @return array User billing history.
*/
public function get_user_billing_history() {
return $this->build_request( 'user/billing/history' )->fetch();
}
/**
* Get User Subscriptions.
*
* @api GET
* @see https://api.cloudflare.com/#user-billing-history-billing-history Documentation
* @return array User subscriptions history.
*/
public function get_user_subscriptions() {
return $this->build_request( 'user/subscriptions' )->fetch();
}
/**
* Update a User Subscription.
*
* @api PUT
* @see https://api.cloudflare.com/#user-subscription-update-a-user-subscription Documentation
* @param string $subscription_id Subscription identifier tag.
* @param int $price The price of the subscription that will be billed, in US dollars.
* @param string $currency The monetary unit in which pricing information is displayed.
* @param string $frequency How often the subscription is renewed automatically.
* @param array $optional_args Array with optional parameters. See API docs for details.
* @return array Updated user subscription info.
*/
public function update_user_subscriptions( $subscription_id, $price, $currency, $frequency, $optional_args = array() ) {
$args = array(
'id' => $subscription_id,
'price' => $price,
'currency' => $currency,
'frequency' => $frequency,
);
$args = array_merge( $optional_args, $args );
return $this->build_request( "user/subscriptions/$subscription_id", $args, 'PUT' )->fetch();
}
/**
* Deletes a user's subscriptions
*
* @api DELETE
* @see https://api.cloudflare.com/#user-subscription-delete-user-subscriptions Documentation
* @param string $subscription_id Subscription identifier tag.
* @return array JSON array with deleted subscription ID.
*/
public function delete_user_subscriptions( $subscription_id ) {
return $this->build_request( "user/subscriptions/$subscription_id", '', 'DELETE' )->fetch();
}
/**
* List access rules.
*
* Search, sort, and filter IP/country access rules
*
* @api GET
* @see https://api.cloudflare.com/#user-level-firewall-access-rule-list-access-rules Documentation
* @param array $args Array with optional parameters. See API docs for details.
* @return array List of user-level firewall access rules.
*/
public function get_user_access_rules( $args = array() ) {
return $this->build_request( 'user/firewall/access_rules/rules', $args )->fetch();
}
/**
* Create access rule
*
* Make a new IP, IP range, or country access rule for all zones owned by the user. Note: If you would like to create
* an access rule that applies to a specific zone only, use the zone firewall endpoints.
*
* @api POST
* @see https://api.cloudflare.com/#user-level-firewall-access-rule-create-access-rule Documentation
* @param string $mode The action to apply to a matched request. Valid values: block, challenge, whitelist.
* @param string $config_target Rule configuration target. valid values: ip, ip_range, country.
* @param string $config_value Rule configuration value. See API docs for details.
* @param string $notes A personal note about the rule. Typically used as a reminder or explanation for the rule.
* @return array New access rule info.
*/
public function create_user_accesss_rule( $mode, $config_target, $config_value, $notes = '' ) {
$args = array(
'mode' => $mode,
'configuration' => array(
'target' => $config_target,
'value' => $config_value,
),
'notes' => $notes,
);
return $this->build_request( 'user/firewall/access_rules/rules', $args, 'POST' )->fetch();
}
/**
* Update access rule.
*
* Update rule state and/or configuration. This will be applied across all zones owned by the user.
*
* @param string $id Access rule ID.
* @param string $mode The action to apply to a matched request. Valid values: block, challenge, whitelist.
* @param string $config_target Rule configuration target. valid values: ip, ip_range, country.
* @param string $config_value Rule configuration value. See API docs for details.
* @param string $notes A personal note about the rule. Typically used as a reminder or explanation for the rule.
* @return array Updated access rule info.
*/
public function update_user_access_rule( $id, $mode, $config_target, $config_value, $notes = '' ) {
$args = array(
'mode' => $mode,
'configuration' => array(
'target' => $config_target,
'value' => $config_value,
),
'notes' => $notes,
);
return $this->build_request( "user/firewall/access_rules/rules/$id", $args, 'PATCH' )->fetch();
}
/**
* Delete access rule.
*
* Remove an access rule so it is no longer evaluated during requests. This will apply to all zones owned by the user.
*
* @api DELETE
* @see https://api.cloudflare.com/#user-level-firewall-access-rule-delete-access-rule Documentation
* @param string $id Subscription identifier tag.
* @return array Array with deleted access rule ID.
*/
public function delete_user_accesss_rule( $id ) {
return $this->build_request( "user/firewall/access_rules/rules/$id", '', 'DELETE' )->fetch();
}
/* User Organization routes. Enterprise Only */
/**
* List organizations.
*
* List organizations the user is associated with.
*
* @api GET
* @see https://api.cloudflare.com/#user-s-organizations-list-organizations Documentation
* @param array $args Array with optional parameters. See API docs for details.
* @return array List of user organizations.
*/
public function get_user_orgs( $args = array() ) {
return $this->build_request( 'user/organizations', $args )->fetch();
}
/**
* Organization details.
*
* Get a specific organization the user is associated with.
*
* @api GET
* @see https://api.cloudflare.com/#user-s-organizations-organization-details Documentation
* @param string $id Organization id.
* @return array Array with org details.
*/
public function get_user_org_details( $id ) {
return $this->build_request( "user/organizations/$id" )->fetch();
}
/**
* Leave organization
*
* Remove association to an organization.
*
* @api DELETE
* @see https://api.cloudflare.com/#user-s-organizations-leave-organization Documentation
* @param string $id Organization id.
* @return array Array with removed org ID.
*/
public function leave_user_org( $id ) {
return $this->build_request( "user/organizations/$id", '', 'DELETE' )->fetch();
}
/* User invitations route. Enterprise Only */
/**
* List invitations
*
* List all invitations associated with my user.
*
* @api GET
* @see https://api.cloudflare.com/#user-s-invites-list-invitations Documentation
* @return array List of user invites
*/
public function get_user_invites() {
return $this->build_request( 'user/invites' )->fetch();
}
/**
* Invitation details
*
* Get a specific organization the user is associated with.
*
* @api GET
* @see https://api.cloudflare.com/#user-s-invites-invitation-details Documentation
* @param string $id Invite id.
* @return array Array with invites details.
*/
public function get_user_invite_details( $id ) {
return $this->build_request( "user/invites/$id" )->fetch();
}
/**
* Respond to Invitation
*
* @api PATCH
* @see https://api.cloudflare.com/#user-s-invites-respond-to-invitation Documentation
* @param string $id Invite id.
* @param bool $status Invite status. Set to true to accept, and false to reject.
* @return array Array with invites details.
*/
public function respond_user_invite( $id, bool $status ) {
$args = array(
'status' => ( true === $status ) ? 'accepted' : 'rejected',
);
return $this->build_request( "user/invites/$id", $args, 'PATCH' )->fetch();
}
/* Welcome to.. the Danger Zones.(´・_・`). Cloudflare Zone routes that is. */
/**
* Create a zone.
*
* @api POST
* @see https://api.cloudflare.com/#zone-create-a-zone Documentation
* @param string $domain The domain name. i.e. "example.com".
* @param bool $jump_start Automatically attempt to fetch existing DNS records.
* @param array $org To create a zone owned by an organization, specify the organization parameter.
* Organization objects can be found in the User or User's Organizations endpoints. You
* must pass at least the ID of the organization.
* @return array New zone details.
*/
public function create_zone( $domain, bool $jump_start = true, $org = array() ) {
$args = array(
'name' => $domain,
'jump_start' => $jump_start,
// 'organization' => $org,
);
if ( ! empty( $org ) ) {
$args['organization'] = $org;
}
return $this->build_request( 'zones', $args, 'POST' )->fetch();
}
/**
* Initiate another zone activation check.
*
* @api PUT
* @see https://api.cloudflare.com/#zone-initiate-another-zone-activation-check Documentation
* @param string $id Zone ID.
* @return array Array with results.
*/
public function initiate_zone_activation_check( $id ) {
return $this->build_request( "zones/$id/activation_check", '', 'PUT' )->fetch();
}
/**
* List zones.
*
* List, search, sort, and filter your zones.
*
* @api GET
* @see https://api.cloudflare.com/#zone-list-zones Documentation
* @param array $args Query args to send in to API call. See API docs for details.
* @return array List of available zones.
*/
public function get_zones( $args = array() ) {
return $this->build_request( 'zones', $args )->fetch();
}
/**
* Zone details.
*
* @api GET
* @see https://api.cloudflare.com/#zone-zone-details Documentation
* @param array $args Query args to send in to API call. See API docs for details.
* @return array Zone details.
*/
public function get_zone_details( string $id ) {
if ( empty( $id ) ) {
return new WP_Error( 'data-error', __( 'Error: ID field is empty' ) );
}
return $this->build_request( "zones/$id" )->fetch();
}
/**
* Edit Zone Properties.
*
* Only one zone property can be changed at a time.
*
* @api PATCH
* @see https://api.cloudflare.com/#zone-edit-zone-properties Documentation
* @param string $id Zone ID.
* @param bool $paused Indicates if the zone is only using Cloudflare DNS services. A true value
* means the zone will not receive security or performance benefits.
* Valid values: true|false.
* @param array $vanity_name_servers An array of domains used for custom name servers. This is only available for
* Business and Enterprise plans.
* @param array $plan The desired plan for the zone. Changing this value will create/cancel
* associated subscriptions. To view available plans for this zone, see Zone Plans.
* @return array Updated zone info.
*/
public function update_zone( $id, bool $paused = null, array $vanity_name_servers = null, array $plan = null ) {
$args = array(
'paused' => $paused,
'vanity_name_servers' => $vanity_name_servers,
'plan' => $plan,
);
return $this->build_request( "zones/$id", $args, 'PATCH' )->fetch();
}
/**
* Purge all files.
*
* Remove ALL files from Cloudflare's cache.
*
* @api DELETE
* @see https://api.cloudflare.com/#zone-purge-all-files Documentation
* @param string $id Zone Id.
* @return array Purge results.
*/
public function purge_zone_cache_all( string $id ) {
$args = array(
'purge_everything' => true,
);
return $this->build_request( "zones/$id/purge_cache", $args, 'DELETE' )->fetch();
}
/**
* Purge individual files by URL and Cache-Tags.
*
* Granularly remove one or more files from Cloudflare's cache either by specifying the URL or the associated
* Cache-Tag. All tiers can purge by URL. Cache-Tag is for Enterprise only.
*
* Cache-Tag purging has a rate limit of up to 2,000 purge API calls in every 24 hour period. You may purge up to 30
* tags in one API call.
*
* @api DELETE
* @see https://api.cloudflare.com/#zone-purge-individual-files-by-url-and-cache-tags Documentation
* @param string $id Zone Id.
* @param array $files An array of URLs that should be removed from cache.
* @param array $tags Any assets served with a Cache-Tag header that matches one of the provided values will be
* purged from the Cloudflare cache.
* @return array Purge results.
*/
public function purge_zone_cache_individual( string $id, array $files = null, array $tags = null ) {
$args = array(
'files' => $files,
'tags' => $tags,
);
return $this->build_request( "zones/$id/purge_cache", $args, 'DELETE' )->fetch();
}
/**
* Delete a zone.
*
* @api DELETE
* @see https://api.cloudflare.com/#zone-delete-a-zone Documentation
* @param string $id Zone ID.
* @return array Deleted zone info.
*/
public function delete_zone( string $id ) {
return $this->build_request( "zones/$id/purge_cache", '', 'DELETE' )->fetch();
}
/**
* Available Rate Plans.
*
* List all rate plans the zone can subscribe to.
*
* @api GET
* @see https://api.cloudflare.com/#zone-rate-plan-available-rate-plans Documentation
* @param string $id Zone ID.
* @return array Available rate plan info.
*/
public function get_zone_available_rate_plans( string $id ) {
return $this->build_request( "zones/$id/available_rate_plans" )->fetch();
}
/**
* Get all Zone settings
*
* Available settings for your user in relation to a zone
*
* @api GET
* @see https://api.cloudflare.com/#zone-settings-get-all-zone-settings Documentation
* @param string $id Zone ID.
* @return array Zone setting info.
*/
public function get_zone_settings( string $id ) {
return $this->build_request( "zones/$id/settings" )->fetch();
}
/**
* TODO: Complete method.
*/
public function get_zone_settings_advanced_ddos(){}
/**
* Get Always Online setting
*
* When enabled, Always Online will serve pages from our cache if your server is offline
* (https://support.cloudflare.com/hc/en-us/articles/200168006)
*
* @api GET
* @see https://api.cloudflare.com/#zone-settings-get-always-online-setting Documentation
* @param string $id Zone ID.
* @return array Always online setting info.
*/
public function get_zone_settings_always_online( $id ) {
return $this->build_request( "zones/$id/settings/always_online" )->fetch();
}
/**
* Get Always Use HTTPS setting
*
* Reply to all requests for URLs that use "http" with a 301 redirect to the equivalent "https" URL. If you only
* want to redirect for a subset of requests, consider creating an "Always use HTTPS" page rule.
*
* @api GET
* @see https://api.cloudflare.com/#zone-settings-get-always-use-https-setting Documentation
* @param string $id Zone ID.
* @return array Always online setting info.
*/
public function get_zone_settings_always_use_https( $id ) {
return $this->build_request( "zones/$id/settings/always_use_https" )->fetch();
}
/**
* Get Automatic HTTPS Rewrites setting.
*
* Enable the Automatic HTTPS Rewrites feature for this zone.
*
* @api GET
* @see https://api.cloudflare.com/#zone-settings-get-automatic-https-rewrites-setting Documentation
* @param string $id Zone ID.
* @return array Auto https rewrites setting info.
*/
public function get_zone_settings_automatic_https_rewrites( $id ) {
return $this->build_request( "zones/$id/settings/automatic_https_rewrites" )->fetch();
}
/**
* Get Browser Cache TTL setting.
*
* Browser Cache TTL (in seconds) specifies how long Cloudflare-cached resources will remain on your visitors'
* computers. Cloudflare will honor any larger times specified by your server.
* (https://support.cloudflare.com/hc/en-us/articles/200168276).
*
* @api GET
* @see https://api.cloudflare.com/#zone-settings-get-browser-cache-ttl-setting Documentation
* @param string $id Zone ID.
* @return array Browser cache ttl setting info.
*/
public function get_zone_settings_browser_cache_ttl( $id ) {
return $this->build_request( "zones/$id/settings/browser_cache_ttl" )->fetch();
}
/**
* Get Browser Check setting.
*
* Browser Integrity Check is similar to Bad Behavior and looks for common HTTP headers abused most commonly by
* spammers and denies access to your page. It will also challenge visitors that do not have a user agent or a non
* standard user agent (also commonly used by abuse bots, crawlers or visitors).
* (https://support.cloudflare.com/hc/en-us/articles/200170086).
*
* @api GET
* @see https://api.cloudflare.com/#zone-settings-get-browser-check-setting Documentation
* @param string $id Zone ID.
* @return array Browser check info.
*/
public function get_zone_settings_browser_check( $id ) {
return $this->build_request( "zones/$id/settings/browser_check" )->fetch();
}
/**
* Get Cache Level setting.
*
* Cache Level functions based off the setting level. The basic setting will cache most static resources
* (i.e., css, images, and JavaScript). The simplified setting will ignore the query string when delivering a cached
* resource. The aggressive setting will cache all static resources, including ones with a query string.
* (https://support.cloudflare.com/hc/en-us/articles/200168256).
*
* @api GET
* @see https://api.cloudflare.com/#zone-settings-get-cache-level-setting Documentation
* @param string $id Zone ID.
* @return array Cache level seting info.
*/
public function get_zone_settings_cache_level( $id ) {
return $this->build_request( "zones/$id/settings/cache_level" )->fetch();
}
/**
* Get Challenge TTL setting.
*
* Specify how long a visitor is allowed access to your site after successfully completing a challenge (such as a
* CAPTCHA). After the TTL has expired the visitor will have to complete a new challenge. We recommend a 15 - 45
* minute setting and will attempt to honor any setting above 45 minutes.
* (https://support.cloudflare.com/hc/en-us/articles/200170136).
*
* @api GET
* @see https://api.cloudflare.com/#zone-settings-get-challenge-ttl-setting Documentation
* @param string $id Zone ID.
* @return array Challenge TTL setting info.
*/
public function get_zone_settings_challenge_ttl( $id ) {
return $this->build_request( "zones/$id/settings/challenge_ttl" )->fetch();
}
/**
* Get Development Mode setting.
*
* Development Mode temporarily allows you to enter development mode for your websites if you need to make changes
* to your site. This will bypass Cloudflare's accelerated cache and slow down your site, but is useful if you are
* making changes to cacheable content (like images, css, or JavaScript) and would like to see those changes right
* away. Once entered, development mode will last for 3 hours and then automatically toggle off.
*
* @api GET
* @see https://api.cloudflare.com/#zone-settings-get-development-mode-setting Documentation
* @param string $id Zone ID.
* @return array Development mode setting info.
*/
public function get_zone_settings_development_mode( $id ) {
return $this->build_request( "zones/$id/settings/development_mode" )->fetch();
}
/**
* Get Email Obfuscation setting.
*
* Encrypt email adresses on your web page from bots, while keeping them visible to humans.
* (https://support.cloudflare.com/hc/en-us/articles/200170016).
*
* @api GET
* @see https://api.cloudflare.com/#zone-settings-get-email-obfuscation-setting Documentation
* @param string $id Zone ID.
* @return array Email obfuscation setting info.
*/
public function get_zone_settings_email_obfuscation( $id ) {
return $this->build_request( "zones/$id/settings/email_obfuscation" )->fetch();
}
/**
* Get Hotlink Protection setting.
*
* When enabled, the Hotlink Protection option ensures that other sites cannot suck up your bandwidth by building
* pages that use images hosted on your site. Anytime a request for an image on your site hits Cloudflare, we check
* to ensure that it's not another site requesting them. People will still be able to download and view images from
* your page, but other sites won't be able to steal them for use on their own pages.
* (https://support.cloudflare.com/hc/en-us/articles/200170026).
*
* @api GET
* @see https://api.cloudflare.com/#zone-settings-get-hotlink-protection-setting Documentation
* @param string $id Zone ID.
* @return array Hotlink protection setting info.
*/
public function get_zone_settings_hotlink_protection( $id ) {
return $this->build_request( "zones/$id/settings/hotlink_protection" )->fetch();
}
/**
* Get IP Geolocation setting.
*
* Enable IP Geolocation to have Cloudflare geolocate visitors to your website and pass the country code to you.
* (https://support.cloudflare.com/hc/en-us/articles/200168236).
*
* @api GET
* @see https://api.cloudflare.com/#zone-settings-get-ip-geolocation-setting Documentation
* @param string $id Zone ID.
* @return array Hotlink protection setting info.
*/
public function get_zone_settings_ip_geolocation( $id ) {
return $this->build_request( "zones/$id/settings/ip_geolocation" )->fetch();
}
/**
* Get IPv6 setting.
*
* Enable IPv6 on all subdomains that are Cloudflare enabled.
* (https://support.cloudflare.com/hc/en-us/articles/200168586).
*
* @api GET
* @see https://api.cloudflare.com/#zone-settings-get-ipv6-setting Documentation
* @param string $id Zone ID.
* @return array Ipv6 setting info.
*/
public function get_zone_settings_ipv6( $id ) {
return $this->build_request( "zones/$id/settings/ipv6" )->fetch();
}
/**
* Get Minify setting.
*
* Automatically minify certain assets for your website
* (https://support.cloudflare.com/hc/en-us/articles/200168196).
*
* @api GET
* @see https://api.cloudflare.com/#zone-settings-get-minify-setting Documentation
* @param string $id Zone ID.
* @return array Minify setting info.
*/
public function get_zone_settings_minify( $id ) {
return $this->build_request( "zones/$id/settings/minify" )->fetch();
}
/**
* Get Mobile Redirect setting.
*
* Automatically redirect visitors on mobile devices to a mobile-optimized subdomain
* (https://support.cloudflare.com/hc/en-us/articles/200168336).
*
* @api GET
* @see https://api.cloudflare.com/#zone-settings-get-mobile-redirect-setting Documentation
* @param string $id Zone ID.
* @return array Mobile redirect setting info.
*/
public function get_zone_settings_mobile_redirect( $id ) {
return $this->build_request( "zones/$id/settings/mobile_redirect" )->fetch();
}
/**
* Get Mirage setting.
*
* Automatically optimize image loading for website visitors on mobile devices
* (http://blog.cloudflare.com/mirage2-solving-mobile-speed).
*
* @api GET
* @see https://api.cloudflare.com/#zone-settings-get-mirage-setting Documentation
* @param string $id Zone ID.
* @return array Mirage setting info.
*/
public function get_zone_settings_mirage( $id ) {
return $this->build_request( "zones/$id/settings/mirage" )->fetch();
}
/**
* TODO: Complete.
*/
public function get_zone_settings_origin_error_page_pass_thru(){}
/**
* Get Opportunistic Encryption setting.
*
* Enable the Opportunistic Encryption feature for this zone.
*
* @api GET
* @see https://api.cloudflare.com/#zone-settings-get-opportunistic-encryption-setting Documentation
* @param string $id Zone ID.
* @return array Opportunistic encryption setting info.
*/
public function get_zone_settings_opportunistic_encryption( $id ) {
return $this->build_request( "zones/$id/settings/opportunistic_encryption" )->fetch();
}
/**
* Get Polish setting.
*
* Strips metadata and compresses your images for faster page load times. Basic (Lossless): Reduce the size of PNG,
* JPEG, and GIF files - no impact on visual quality. Basic + JPEG (Lossy): Further reduce the size of JPEG files
* for faster image loading. Larger JPEGs are converted to progressive images, loading a lower-resolution image
* first and ending in a higher-resolution version. Not recommended for hi-res photography sites.
*
* @api GET
* @see https://api.cloudflare.com/#zone-settings-get-polish-setting Documentation
* @param string $id Zone ID.
* @return array Polish setting info.
*/
public function get_zone_settings_polish( $id ) {
return $this->build_request( "zones/$id/settings/polish" )->fetch();
}
/**
* Get WebP setting.
*
* When the client requesting the image supports the WebP image codec, Cloudflare will serve a WebP version of the
* image when WebP offers a performance advantage over the original image format.
*
* @api GET
* @see https://api.cloudflare.com/#zone-settings-get-webp-setting Documentation
* @param string $id Zone ID.
* @return array WebP setting info.
*/
public function get_zone_settings_webp( $id ) {
return $this->build_request( "zones/$id/settings/webp" )->fetch();
}
/**
* Get Prefetch Preload setting.
*
* Cloudflare will prefetch any URLs that are included in the response headers. This is limited to Enterprise Zones.
*
* @api GET
* @see https://api.cloudflare.com/#zone-settings-get-prefetch-preload-setting Documentation
* @param string $id Zone ID.
* @return array Prefetch Preload setting info.
*/
public function get_zone_settings_prefetch_preload( $id ) {
return $this->build_request( "zones/$id/settings/prefetch_preload" )->fetch();
}
/**
* TODO: Complete.
*/
public function get_zone_settings_response_buffering(){}
/**
* Get Rocket Loader setting.
*
* Rocket Loader is a general-purpose asynchronous JavaScript loader coupled with a lightweight virtual browser
* which can safely run any JavaScript code after window.onload. Turning on Rocket Loader will immediately improve
* a web page's window.onload time (assuming there is JavaScript on the page), which can have a positive impact on
* your Google search ranking. Automatic Mode: Rocket Loader will automatically run on the JavaScript resources on
* your site, with no configuration required after turning on automatic mode. Manual Mode: In order to have Rocket
* Loader execute for a particular script, you must add the following attribute to the script tag: "data-cfasync='true'".
* As your page passes through Cloudflare, we'll enable Rocket Loader for that particular script. All other
* JavaScript will continue to execute without Cloudflare touching the script.
* (https://support.cloudflare.com/hc/en-us/articles/200168056).
*
* @api GET
* @see https://api.cloudflare.com/#zone-settings-get-rocket-loader-setting Documentation
* @param string $id Zone ID.
* @return array Rocket Loader setting info.
*/
public function get_zone_settings_rocket_loader( $id ) {
return $this->build_request( "zones/$id/settings/rocket_loader" )->fetch();
}
/**
* Get Security Header (HSTS) setting.
*
* Cloudflare security header for a zone.
*
* @api GET
* @see https://api.cloudflare.com/#zone-settings-get-security-header-hsts-setting Documentation
* @param string $id Zone ID.
* @return array Security header setting info.
*/
public function get_zone_settings_security_header( $id ) {
return $this->build_request( "zones/$id/settings/security_header" )->fetch();
}
/**
* Get Security Level setting.
*
* Choose the appropriate security profile for your website, which will automatically adjust each of the security
* settings. If you choose to customize an individual security setting, the profile will become Custom.
* (https://support.cloudflare.com/hc/en-us/articles/200170056).
*
* @api GET
* @see https://api.cloudflare.com/#zone-settings-get-security-level-setting Documentation