-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathplugin.php
More file actions
1312 lines (1221 loc) · 44.3 KB
/
plugin.php
File metadata and controls
1312 lines (1221 loc) · 44.3 KB
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 // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName
/**
* Plugin Name: Updates API Inspector
* Description: Inspect various aspects of the Updates API.
* Author: Paul V. Biron/Sparrow Hawk Computing
* Author URI: https://sparrowhawkcomputing.com/
* Plugin URI: https://wordpress.org/plugins/updates-api-inspector/
* GitHub Plugin URI: https://github.com/pbiron/updates-api-inspector
* Network: true
* Version: 0.1.1
* License: GPLv2 or later
* License URI: http://www.gnu.org/licenses/gpl-2.0.html
*/
namespace SHC\Updates_API_Inspector;
use WP_Error;
defined( 'ABSPATH' ) || die;
/**
* Our main plugin class.
*
* @since 0.1.0
*
* @todo add a11y suport (e.g., screen-reader-text, @aria-xxx, etc).
* @todo make the strings displayed easier to deal with, there is ALOT of
* repeation and it's a pain to keep the request-type specific strings
* in sync with one other.
*/
class Plugin {
/**
* Our static instance.
*
* @since 0.1.0
*
* @var Plugin
*/
protected static $instance;
/**
* Our version number.
*
* @since 0.1.1
*
* @var string
*/
const VERSION = '0.1.1';
/**
* The URL of the current request.
*
* @since 0.1.0
*
* @var string
*/
protected $request_url = '';
/**
* The current request arguments.
*
* @since 0.1.0
*
* @var array()
*/
protected $request = array();
/**
* The successful response for the current request.
*
* @since 0.1.0
*
* @var array
*/
protected $response = array();
/**
* The site transient value as set.
*
* @since 0.1.1
*
* @var object
*/
protected $transient_as_set;
/**
* The error response for the current request.
*
* @since 0.1.0
*
* @var WP_Error|array
*/
protected $error;
/**
* Add hooks.
*
* @since 0.1.0
*
* @return void
*/
protected function add_hooks() {
if ( ! is_multisite() ) {
add_action( 'admin_menu', array( $this, 'admin_menu' ) );
add_action( 'load-tools_page_updates-api-inspector', array( $this, 'maybe_do_update_check' ) );
add_action( 'load-tools_page_updates-api-inspector', array( $this, 'add_help' ) );
add_action( 'admin_print_styles-tools_page_updates-api-inspector', array( $this, 'print_styles' ) );
} else {
add_action( 'network_admin_menu', array( $this, 'admin_menu' ) );
add_action( 'load-toplevel_page_updates-api-inspector', array( $this, 'maybe_do_update_check' ) );
add_action( 'load-toplevel_page_updates-api-inspector', array( $this, 'add_help' ) );
add_action( 'admin_print_styles-toplevel_page_updates-api-inspector', array( $this, 'print_styles' ) );
}
return;
}
/**
* If this WP request is to run one of our update checks, verify the nonce
* and do the update check.
*
* This is run very early so that we can do a proper `wp_die()` screen if necessary.
* Waiting until {@see Plugin::render_tools_page()} it is too late to offer a
* standard WP UX.
*
* @since 0.1.1
*
* @return void
*
* @action load-tools_page_updates-api-inspector
*/
public function maybe_do_update_check() {
// just in case the user has bypassed the caps check for the menu item.
if ( ! current_user_can( is_multisite() ? 'manage_network_options' : 'manage_options' ) ) {
wp_die( esc_html__( 'Sorry, you are not allowed to inspect the Updates API.', 'updates-api-inspector' ) );
}
// phpcs:ignore WordPress.Security.NonceVerification.NoNonceVerification
$type = isset( $_REQUEST['type'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['type'] ) ) : '';
if ( $type ) {
check_admin_referer( 'updates-api-inspector' );
if ( ! in_array( $type, array( 'core', 'plugins', 'themes' ), true ) ) {
wp_die(
esc_html(
sprintf(
/* translators: Updates API endpoint. */
__( 'Unknown Updates API Inspector type: %s', 'updates-api-inspector' ),
$type
)
)
);
}
$this->update_check( $type );
}
return;
}
/**
* Query the Updates API for the type specified.
*
* This is where the magic happens :-)
*
* @since 0.1.0
*
* @param string $type The Updates API endpoint type. Accepts 'core', 'plugins', 'themes'.
* @return void
*/
protected function update_check( $type ) {
$transient_name = "update_{$type}";
// wp_version_check(), i.e., the core check, doesn't need this.
if ( 'plugins' === $type || 'themes' === $type ) {
// trick core into thinking the transient has not been set recently,
// so that it's throttling mechanism doesn't cause it to return early.
$current = get_site_transient( $transient_name );
if ( ! is_object( $current ) ) {
$current = new \stdClass();
}
$current->last_checked = time() - ( 12 * HOUR_IN_SECONDS ) - 1;
set_site_transient( $transient_name, $current );
}
// add our capture hooks.
// priority is as late as possible, so that we capture any modifications made by
// by anything else hooking into the various Requests hooks.
add_action( 'http_api_debug', array( $this, 'capture_request_response' ), PHP_INT_MAX, 5 );
add_action( "set_site_transient_{$transient_name}", array( $this, 'capture_transient_as_set' ), PHP_INT_MAX );
// Query the API.
switch ( $type ) {
case 'core':
wp_version_check( array(), true );
break;
case 'plugins':
wp_update_plugins();
break;
case 'themes':
wp_update_themes();
break;
}
// remove our capture hooks.
remove_action( "set_site_transient_{$transient_name}", array( $this, 'capture_transient_as_set' ), PHP_INT_MAX );
remove_action( 'http_api_debug', array( $this, 'capture_request_response' ) );
return;
}
/**
* Capture the API request and response.
*
* For the request, we only capture query args and `$options` explicitly passed
* to {@link https://developer.wordpress.org/reference/functions/wp_remote_post/ wp_remote_post()}.
*
* @since 0.1.0
*
* @param array|WP_Error $response HTTP response or WP_Error object.
* @param string $context Context under which the hook is fired.
* @param string $class HTTP transport used.
* @param array $parsed_args HTTP request arguments.
* @param string $url The request URL.
* @return void
*
* @action http_api_debug
*/
public function capture_request_response( $response, $context, $class, $parsed_args, $url ) {
// Even though this method is hooked/unhooked right around the core functions
// that access the API, we check the URL just to be sure that we don't
// capture incorrect info should something do additional wp_remote_xxx() calls
// as part of hooks they fire while the API request is being processed.
if ( ! preg_match( '@^https?://api.wordpress.org/(core/version-check|(plugins|themes)/update-check)/\d+(\.\d+)*/@', $url ) ) {
return;
}
// First, capture the request.
$this->url = $url;
$keys = array(
'timeout',
'user-agent',
'body',
// headers is only used for core update check.
'headers',
);
$this->request = array_filter(
$parsed_args,
function( $key ) use ( $keys ) {
return in_array( $key, $keys, true );
},
ARRAY_FILTER_USE_KEY
);
if ( preg_match( '@^https?://api.wordpress.org/core/version-check/\d+(\.\d+)*/@', $url ) ) {
// core update check.
// parse the query string and add it to the request and then
// strip off the query_string from our local copy of it.
parse_str( wp_parse_url( $url, PHP_URL_QUERY ), $this->request['query_string'] );
$this->url = preg_replace( '@\?.*$@', '', $url );
} else {
// plugins or themes check.
// since core only adds headers to core update checks,
// remove it just in case some other hook added it...so as to be
// more "educational".
unset( $this->request['headers'] );
}
$this->request['body'] = array_map( 'json_decode', $this->request['body'] );
// Now, capture the "response", whether an error or a successful response.
if ( is_wp_error( $response ) || 200 !== wp_remote_retrieve_response_code( $response ) ) {
$this->error = $response;
$this->response = array();
} else {
$this->error = array();
$this->response = json_decode( wp_remote_retrieve_body( $response ), true );
}
return;
}
/**
* Capture the site transient as set.
*
* Note that this will be called multiple times during each update check,
* because of the way those are done (1 or 2 times to update the `last_checked` value,
* and once for setting the actual value). Ulimately, the last call is the one
* shown in our UI.
*
* @since 0.1.1
*
* @param mixed $value Site transient value.
* @return void
*
* @action set_site_transient_update_core, set_site_transient_update_plugins,
* set_site_transient_update_themes
*/
public function capture_transient_as_set( $value ) {
$this->transient_as_set = $value;
return;
}
/**
* Render our tools page.
*
* @since 0.1.0
*
* @return void
*
* @todo figure out a convient way to store the strings for the "explanation" in each
* fieldset in an array and iterate over it because there is ALOT of duplication
* and it is silly to repeat things over and over again. core does that and
* I hate it!
*/
public function render_tools_page() {
if ( ! current_user_can( is_multisite() ? 'manage_network_options' : 'manage_options' ) ) {
// this won't produce a "normal" WP die screen (it's too late for that),
// but it's better than letting the user see the inspection.
// @see Plugin::maybe_do_update_check().
wp_die( esc_html__( 'Sorry, you are not allowed to inspect the Updates API.', 'updates-api-inspector' ) );
}
$checks = array(
'core' => __( 'Core', 'updates-api-inspector' ),
'plugins' => __( 'Plugins', 'updates-api-inspector' ),
'themes' => __( 'Themes', 'updates-api-inspector' ),
);
// phpcs:ignore WordPress.Security.NonceVerification.NoNonceVerification
$current = isset( $_REQUEST['type'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['type'] ) ) : '';
if ( $current ) {
// The nonce check should aready have happened in {@see Plugin::maybe_do_update_check()}
// but it doesn't help to check it again, just to be sure.
check_admin_referer( 'updates-api-inspector' );
}
?>
<div class='wrap updates-api-inspector'>
<h1><?php echo esc_html( get_admin_page_title() ); ?></h1>
<p><?php esc_html_e( 'This tool will allow you to inspect requests/responses from the Updates API and the site transients core sets as a result.', 'updates-api-inspector' ); ?></p>
<nav role='tablist' class='nav-tab-wrapper wp-clearfix'>
<?php
foreach ( $checks as $type => $label ) {
$href = wp_nonce_url( add_query_arg( 'type', $type ), 'updates-api-inspector' );
$class = 'nav-tab';
$class .= $current === $type ? ' nav-tab-active' : '';
?>
<a href='<?php echo esc_url( $href ); ?>' role='tab' aria-selected='<?php echo ( $current === $type ? 'true' : 'false' ); ?>' class='<?php echo esc_attr( $class ); ?>'><?php echo esc_html( $label ); ?></a>
<?php
}
?>
</nav>
<?php
if ( $current ) {
?>
<div id='result'>
<?php
switch ( $current ) {
case 'core':
?>
<p>
<?php
esc_html_e( 'The results of querying for core updates are displayed below. You can jump to a specific section with any of the links.', 'updates-api-inspector' );
?>
</p>
<?php
break;
case 'plugins':
?>
<p>
<?php
esc_html_e( 'The results of querying for plugin updates are displayed below.', 'updates-api-inspector' );
?>
</p>
<?php
break;
case 'themes':
?>
<p>
<?php
esc_html_e( 'The results of querying for theme updates are displayed below.', 'updates-api-inspector' );
?>
</p>
<?php
break;
}
?>
<nav>
<ul>
<li><a href='#request'><?php esc_html_e( 'Request', 'updates-api-inspector' ); ?></a></li>
<?php
if ( $this->error ) {
?>
<li><a href='#error'><?php esc_html_e( 'Error', 'updates-api-inspector' ); ?></a></li>
<?php
} else {
?>
<li><a href='#response'><?php esc_html_e( 'API Response', 'updates-api-inspector' ); ?></a></li>
<li><a href='#transient-set'><?php esc_html_e( 'Transient Value as Set', 'updates-api-inspector' ); ?></a></li>
<li><a href='#transient-read'><?php esc_html_e( 'Transient Value as Read', 'updates-api-inspector' ); ?></a></li>
<?php
}
?>
</ul>
</nav>
<section id='request'>
<h3><?php esc_html_e( 'Request', 'updates-api-inspector' ); ?></h3>
<?php
switch ( $current ) {
case 'core':
?>
<p>
<?php
printf(
/* translators: 1: a variable name, 2: function call, 3: link to code reference */
esc_html__( 'This is the value of %1$s in %2$s, as called in %3$s.', 'updates-api-inspector' ),
'<code>$options</code>',
"<code>wp_remote_post( '" . esc_html( $this->url ) . "', \$options )</code>",
// @todo in RTL, the '()' part of the link text appears at the other end of the line. I don't know why.
sprintf(
'<a href="%s">wp_version_check()</a>',
esc_url( __( 'https://developer.wordpress.org/reference/functions/wp_version_check/', 'updates-api-inspector' ) )
)
);
?>
</p>
<p>
<?php
printf(
/* translators: 1: variable name, 2 URL query string separator, 3 variable name */
esc_html__( '%1$s is transmitted as part of the query string (the part after %2$s in the URL) but is displayed as part of %3$s here to make the output easier to read.', 'updates-api-inspector' ),
'<code>query_string</code>',
'<code>?</code>',
'<code>$options</code>'
);
?>
</p>
<?php
break;
case 'plugins':
?>
<p>
<?php
printf(
/* translators: 1: variable name, 2: function call, 3: link to code reference */
esc_html__( 'This is the value of %1$s in %2$s, as called in %3$s.', 'updates-api-inspector' ),
'<code>$options</code>',
"<code>wp_remote_post( '" . esc_html( $this->url ) . "', \$options )</code>",
// @todo in RTL, the '()' part of the link text appears at the other end of the line. I don't know why.
sprintf(
'<a href="%s">wp_update_plugins()</a>',
esc_url( __( 'https://developer.wordpress.org/reference/functions/wp_update_plugins/', 'updates-api-inspector' ) )
)
);
?>
</p>
<?php
break;
case 'themes':
?>
<p>
<?php
printf(
/* translators: 1: variable name, 2: function call, 3: link to code reference */
esc_html__( 'This is the value of %1$s in %2$s, as called in %3$s.', 'updates-api-inspector' ),
'<code>$options</code>',
"<code>wp_remote_post( '" . esc_html( $this->url ) . "', \$options )</code>",
// @todo in RTL, the '()' part of the link text appears at the other end of the line. I don't know why.
sprintf(
'<a href="%s">wp_update_themes()</a>',
esc_url( __( 'https://developer.wordpress.org/reference/functions/wp_update_themes/', 'updates-api-inspector' ) )
)
);
?>
</p>
<?php
break;
}
?>
<p>
<?php
printf(
/* translators: variable name */
esc_html__( '%s is json encoded when the request is made but has been decoded here to make the output easier to read.', 'updates-api-inspector' ),
'<code>body</code>'
);
?>
</p>
<form>
<textarea rows='25' readonly><?php echo esc_html( $this->pretty_print( $this->request ) ); ?></textarea>
</form>
<nav>
<ul>
<li><a href='#top'><?php esc_html_e( 'Back to top', 'updates-api-inspector' ); ?></a></li>
<li><?php esc_html_e( 'Request', 'updates-api-inspector' ); ?></li>
<?php
if ( $this->error ) {
?>
<li><a href='#request'><?php esc_html_e( 'Error', 'updates-api-inspector' ); ?></a></li>
<?php
} else {
?>
<li><a href='#response'><?php esc_html_e( 'API Response', 'updates-api-inspector' ); ?></a></li>
<li><a href='#transient-set'><?php esc_html_e( 'Transient Value as Set', 'updates-api-inspector' ); ?></a></li>
<li><a href='#transient-read'><?php esc_html_e( 'Transient Value as Read', 'updates-api-inspector' ); ?></a></li>
<?php
}
?>
</ul>
</nav>
</section>
<?php
if ( $this->error ) {
?>
<section id='error'>
<h3><?php esc_html_e( 'Error', 'updates-api-inspector' ); ?></h3>
<p>
<?php esc_html_e( 'An error occured during the request.', 'updates-api-inspector' ); ?>
</p>
<form>
<textarea rows='25' readonly><?php echo esc_html( $this->pretty_print( $this->error ) ); ?></textarea>
</form>
<nav>
<ul>
<li><a href='#top'><?php esc_html_e( 'Back to top', 'updates-api-inspector' ); ?></a></li>
<li><a href='#request'><?php esc_html_e( 'Request', 'updates-api-inspector' ); ?></a></li>
</ul>
</nav>
</section>
<?php
} else {
$transient_as_read = get_site_transient( "update_{$current}" );
?>
<section id='response'>
<h3><?php esc_html_e( 'API Response', 'updates-api-inspector' ); ?></h3>
<p>
<?php esc_html_e( 'This is the response from the API.', 'updates-api-inspector' ); ?>
</p>
<p>
<?php
esc_html_e( 'The fields in this response are not documented anywhere, so do not take what is displayed here as all-and-only what may ever be returned!!', 'updates-api-inspector' );
?>
</p>
<?php
switch ( $current ) {
case 'plugins':
?>
<p>
<?php esc_html_e( 'In general, only plugins hosted in the .org repo will be included here; however, in rare cases, something may have hooked into one of the lower-level hooks to inject directly into the API response information about externally hosted plugins.', 'updates-api-inspector' ); ?>
</p>
<?php
break;
case 'themes':
?>
<p>
<?php esc_html_e( 'In general, only themes hosted in the .org repo will be included here; however, in rare cases, something may have hooked into one of the lower-level hooks to inject directly into the API response information about externally hosted themes.', 'updates-api-inspector' ); ?>
</p>
<?php
break;
}
?>
<form>
<textarea rows='25' readonly><?php echo esc_html( $this->pretty_print( $this->response ) ); ?></textarea>
</form>
<nav>
<ul>
<li><a href='#top'><?php esc_html_e( 'Back to top', 'updates-api-inspector' ); ?></a></li>
<li><a href='#request'><?php esc_html_e( 'Request', 'updates-api-inspector' ); ?></a></li>
<li><?php esc_html_e( 'API Response', 'updates-api-inspector' ); ?></li>
<li><a href='#transient-set'><?php esc_html_e( 'Transient Value as Set', 'updates-api-inspector' ); ?></a></li>
<li><a href='#transient-read'><?php esc_html_e( 'Transient Value as Read', 'updates-api-inspector' ); ?></a></li>
</ul>
</nav>
</section>
<section id='transient-set'>
<h3><?php esc_html_e( 'Transient Value As Set', 'updates-api-inspector' ); ?></h3>
<?php
switch ( $current ) {
case 'core':
?>
<p>
<?php
printf(
/* translators: 1: variable name, 2: function call, 3: link to code reference */
esc_html__( 'This is the value of %1$s in %2$s, as called in %3$s.', 'updates-api-inspector' ),
'<code>$updates</code>',
"<code>set_site_transient( 'update_core', \$updates )</code>",
// @todo in RTL, the '()' part of the link text appears at the other end of the line. I don't know why.
sprintf(
'<a href="%s">wp_version_check()</a>',
esc_url( __( 'https://developer.wordpress.org/reference/functions/wp_version_check/', 'updates-api-inspector' ) )
)
);
?>
</p>
<?php
// Display an info notice if the transient as set is different from as read.
// Must use loose comparison here otherwise PHP could test with they
// are the same object.
// phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison
if ( $transient_as_read != $this->transient_as_set ) {
?>
<div class='notice notice-info inline'>
<p>
<?php
printf(
/* translators: link to another section of this page */
esc_html__( 'The transient value here is different than it\'s value in %s.', 'updates-api-inspector' ),
'<a href="#transient-read">' . esc_html__( 'Transient Value as Read', 'updates-api-inspector' ) . '</a>'
);
echo '  ';
printf(
/* translators: 1: link to code reference, 2: link to code reference */
esc_html__( 'There are a number of different ways this could happen, but it often is the result of something hooking into %1$s rather that %2$s.', 'updates-api-inspector' ),
sprintf(
'<a href="%s">site_transient_update_core</a>',
esc_url( __( 'https://developer.wordpress.org/reference/hooks/set_site_transient_transient/', 'updates-api-inspector' ) )
),
sprintf(
'<a href="%s">pre_set_site_transient_update_core</a>',
esc_url( __( 'https://developer.wordpress.org/reference/hooks/pre_set_site_transient_transient/', 'updates-api-inspector' ) )
)
);
?>
</p>
</div>
<?php
}
break;
case 'plugins':
?>
<p>
<?php
printf(
/* translators: 1: variable name, 2: function call, 3: link to code reference */
esc_html__( 'This is the value of %1$s in %2$s, as called in %3$s.', 'updates-api-inspector' ),
'<code>$new_option</code>',
"<code>set_site_transient( 'update_plugins', \$new_option )</code>",
// @todo in RTL, the '()' part of the link text appears at the other end of the line. I don't know why.
sprintf(
'<a href="%s">wp_update_plugins()</a>',
esc_url( __( 'https://developer.wordpress.org/reference/functions/wp_update_plugins/', 'updates-api-inspector' ) )
)
);
?>
</p>
<?php
// Display an info notice if the transient as set is different from as read.
// Must use loose comparison here otherwise PHP could test with they
// are the same object.
// phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison
if ( $transient_as_read != $this->transient_as_set ) {
?>
<div class='notice notice-info inline'>
<p>
<?php
printf(
/* translators: link to another section of this page */
esc_html__( 'The transient value here is different than it\'s value in %s.', 'updates-api-inspector' ),
'<a href="#transient-read">' . esc_html__( 'Transient Value as Read', 'updates-api-inspector' ) . '</a>'
);
echo '  ';
printf(
/* translators: 1: link to code reference, 2: link to code reference */
esc_html__( 'There are a number of different ways this could happen, but it often is the result of something hooking into %1$s rather that %2$s.', 'updates-api-inspector' ),
sprintf(
'<a href="%s">site_transient_update_plugins</a>',
esc_url( __( 'https://developer.wordpress.org/reference/hooks/set_site_transient_transient/', 'updates-api-inspector' ) )
),
sprintf(
'<a href="%s">pre_set_site_transient_update_plugins</a>',
esc_url( __( 'https://developer.wordpress.org/reference/hooks/pre_set_site_transient_transient/', 'updates-api-inspector' ) )
)
);
?>
</p>
</div>
<?php
}
break;
case 'themes':
?>
<p>
<?php
printf(
/* translators: 1: variable name, 2: function call, 3: link to code reference */
esc_html__( 'This is the value of %1$s in %2$s, as called in %3$s.', 'updates-api-inspector' ),
'<code>$new_option</code>',
"<code>set_site_transient( 'update_themes', \$new_option )</code>",
// @todo in RTL, the '()' part of the link text appears at the other end of the line. I don't know why.
sprintf(
'<a href="%s">wp_update_themes()</a>',
esc_url( __( 'https://developer.wordpress.org/reference/hooks/wp_update_themes/', 'updates-api-inspector' ) )
)
);
?>
</p>
<?php
// Display an info notice if the transient as set is different from as read.
// Must use loose comparison here otherwise PHP could test with they
// are the same object.
// phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison
if ( $transient_as_read != $this->transient_as_set ) {
?>
<div class='notice notice-info inline'>
<p>
<?php
printf(
/* translators: link to another section of this page */
esc_html__( 'The transient value here is different than it\'s value in %s.', 'updates-api-inspector' ),
'<a href="#transient-read">' . esc_html__( 'Transient Value as Read', 'updates-api-inspector' ) . '</a>'
);
echo '  ';
printf(
/* translators: 1: link to code reference, 2: link to code reference */
esc_html__( 'There are a number of different ways this could happen, but it often is the result of something hooking into %1$s rather that %2$s.', 'updates-api-inspector' ),
sprintf(
'<a href="%s">site_transient_update_themes</a>',
esc_url( __( 'https://developer.wordpress.org/reference/hooks/set_site_transient_transient/', 'updates-api-inspector' ) )
),
sprintf(
'<a href="%s">pre_set_site_transient_update_themes</a>',
esc_url( __( 'https://developer.wordpress.org/reference/hooks/pre_set_site_transient_transient/', 'updates-api-inspector' ) )
)
);
?>
</p>
</div>
<?php
}
break;
}
?>
<p>
<?php
esc_html_e( 'The fields in this transient are not documented anywhere, so do not take what is displayed here as all-and-only what may ever be returned!!', 'updates-api-inspector' );
?>
</p>
<form>
<textarea rows='25' readonly><?php echo esc_html( $this->pretty_print( $this->transient_as_set ) ); ?></textarea>
</form>
<nav>
<ul>
<li><a href='#top'><?php esc_html_e( 'Back to top', 'updates-api-inspector' ); ?></a></li>
<li><a href='#request'><?php esc_html_e( 'Request', 'updates-api-inspector' ); ?></a></li>
<li><a href='#response'><?php esc_html_e( 'API Response', 'updates-api-inspector' ); ?></a></li>
<li><?php esc_html_e( 'Transient Value as Set', 'updates-api-inspector' ); ?></li>
<li><a href='#transient-read'><?php esc_html_e( 'Transient Value as Read', 'updates-api-inspector' ); ?></a></li>
</ul>
</nav>
</section>
<section id='transient-read'>
<h3><?php esc_html_e( 'Transient Value As Read', 'updates-api-inspector' ); ?></h3>
<?php
switch ( $current ) {
case 'core':
?>
<p>
<?php
printf(
/* translators: function call */
esc_html__( 'This is the value returned by %s.', 'updates-api-inspector' ),
"<code>get_site_transient( 'update_core' )</code>"
);
echo ' ';
printf(
/* translators: variable name */
esc_html__( 'In this value, %s is what determines which core updates are available, both manually in the dashboad and as auto-updates.', 'updates-api-inspector' ),
'<code>updates</code>'
);
echo ' ';
printf(
/* translators: link to code reference */
esc_html__( 'For auto-updates, the %s filter is applied and a falsey return value will prevent core from auto-updating.', 'updates-api-inspector' ),
sprintf(
'<a href="%s">auto_update_core</a>',
esc_url( __( 'https://developer.wordpress.org/reference/hooks/auto_update_core/', 'updates-api-inspector' ) )
)
);
?>
</p>
<?php
// Display an info notice if the transient as set is different from as read.
// Must use loose comparison here otherwise PHP could test with they
// are the same object.
// phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison
if ( $transient_as_read != $this->transient_as_set ) {
?>
<div class='notice notice-info inline'>
<p>
<?php
printf(
/* translators: link to another section of this page */
esc_html__( 'The transient value here is different than it\'s value in %s.', 'updates-api-inspector' ),
'<a href="#transient-set">' . esc_html__( 'Transient Value as Set', 'updates-api-inspector' ) . '</a>'
);
echo '  ';
printf(
/* translators: 1: link to code reference, 2: link to code reference */
esc_html__( 'There are a number of different ways this could happen, but it often is the result of something hooking into %1$s rather that %2$s.', 'updates-api-inspector' ),
sprintf(
'<a href="%s">site_transient_update_core</a>',
esc_url( __( 'https://developer.wordpress.org/reference/hooks/set_site_transient_transient/', 'updates-api-inspector' ) )
),
sprintf(
'<a href="%s">pre_set_site_transient_update_core</a>',
esc_url( __( 'https://developer.wordpress.org/reference/hooks/pre_set_site_transient_transient/', 'updates-api-inspector' ) )
)
);
?>
</p>
</div>
<?php
}
break;
case 'plugins':
?>
<p>
<?php
printf(
/* translators: function call */
esc_html__( 'This is the value returned by %s.', 'updates-api-inspector' ),
"<code>get_site_transient( 'update_plugins' )</code>"
);
echo ' ';
printf(
/* translators: variable name */
esc_html__( 'In this value, %s is what determines which plugin updates are available, both manually in the dashboad and as auto-updates.', 'updates-api-inspector' ),
'<code>response</code>'
);
echo ' ';
printf(
/* translators: link to code reference */
esc_html__( 'For auto-updates, the %s filter is applied and a falsey return value will prevent the plugin from auto-updating.', 'updates-api-inspector' ),
sprintf(
'<a href="%s">auto_update_plugin</a>',
esc_url( __( 'https://developer.wordpress.org/reference/hooks/auto_update_type/', 'updates-api-inspector' ) )
)
);
?>
</p>
<p>
<?php
printf(
/* translators: 1: variable name, 2: variable name, 3: ??? */
esc_html__( 'The values of %1$s and %2$s will contain plugins that are externally hosted (if any) and are arrays of %3$s.', 'updates-api-inspector' ),
'<code>response</code>',
'<code>no_update</code>',
'<strong>' . esc_html_x( 'objects', 'PHP data type', 'updates-api-inspector' ) . '</strong>'
);
?>
</p>
<div class='notice notice-warning inline'>
<p>
<?php
echo '<strong>' . esc_html__( 'Important', 'updates-api-inspector' ) . '</strong>:' .
sprintf(
/* translators: variable name */
esc_html__( 'The Auto-updates UI, introduced in WordPress 5.5.0, will not work correctly for externally hosted plugins that do not populate %s with information about their plugin!', 'updates-api-inspector' ),
'<code>no_update</code>'
);
echo ' ';
esc_html_e( 'For more infomration, see the sidebar in the Help tab on this screen.', 'updates-api-inspector' );
?>
</p>
</div>
<?php
// Display an info notice if the transient as set is different from as read.
// Must use loose comparison here otherwise PHP could test with they
// are the same object.
// phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison
if ( $transient_as_read != $this->transient_as_set ) {
?>
<div class='notice notice-info inline'>
<p>
<?php
printf(
/* translators: link to another section of this page */
esc_html__( 'The transient value here is different than it\'s value in %s.', 'updates-api-inspector' ),
'<a href="#transient-set">' . esc_html__( 'Transient Value as Set', 'updates-api-inspector' ) . '</a>'
);
echo '  ';
printf(
/* translators: 1: link to code reference, 2: link to code reference */
esc_html__( 'There are a number of different ways this could happen, but it often is the result of something hooking into %1$s rather that %2$s.', 'updates-api-inspector' ),
sprintf(
'<a href="%s">site_transient_update_plugins</a>',
esc_url( __( 'https://developer.wordpress.org/reference/hooks/set_site_transient_transient/', 'updates-api-inspector' ) )
),
sprintf(
'<a href="%s">pre_set_site_transient_update_plugins</a>',
esc_url( __( 'https://developer.wordpress.org/reference/hooks/pre_set_site_transient_transient/', 'updates-api-inspector' ) )
)
);
?>
</p>
</div>
<?php
}
break;
case 'themes':
?>
<p>
<?php
printf(
/* translators: function call */
esc_html__( 'This is the value returned by %s.', 'updates-api-inspector' ),
"<code>get_site_transient( 'update_themes' )</code>"
);
echo ' ';
printf(
/* translators: variable name */
esc_html__( 'In this value, %s is what determines which theme updates are available, both manually in the dashboad and as auto-updates.', 'updates-api-inspector' ),
'<code>response</code>'
);
echo ' ';
printf(
/* translators: link to code reference */
esc_html__( 'For auto-updates, the %s filter is applied and a falsey return value will prevent the theme from auto-updating.', 'updates-api-inspector' ),
sprintf(
'<a href="%s">auto_update_theme</a>',
esc_url( __( 'https://developer.wordpress.org/reference/hooks/auto_update_type/', 'updates-api-inspector' ) )
)
);
?>
</p>
<p>
<?php
printf(
/* translators: 1: variable name, 2: variable name, 3: ??? */
esc_html__( 'The values of %1$s and %2$s will contain themes that are externally hosted (if any) and are arrays of %3$s.', 'updates-api-inspector' ),
'<code>response</code>',
'<code>no_update</code>',
'<strong>' . esc_html_x( 'arrays', 'PHP data type', 'updates-api-inspector' ) . '</strong>'
);
?>
</p>
<div class='notice notice-warning inline'>
<p>
<?php
echo '<strong>' . esc_html__( 'Important', 'updates-api-inspector' ) . '</strong>:' .
sprintf(
/* translators: variable name */
esc_html__( 'The Auto-updates UI, introduced in WordPress 5.5.0, will not work correctly for externally hosted themes that do not populate %s with information about their theme!', 'updates-api-inspector' ),
'<code>no_update</code>'
);
echo ' ';
esc_html_e( 'For more infomration, see the sidebar in the Help tab on this screen.', 'updates-api-inspector' );
?>
</p>
</div>
<?php
// Display an info notice if the transient as set is different from as read.
// Must use loose comparison here otherwise PHP could test with they
// are the same object.
// phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison
if ( $transient_as_read != $this->transient_as_set ) {
?>
<div class='notice notice-info inline'>
<p>
<?php
printf(
/* translators: link to another section of this page */
esc_html__( 'The transient value here is different than it\'s value in %s.', 'updates-api-inspector' ),
'<a href="#transient-set">' . esc_html__( 'Transient Value as Set', 'updates-api-inspector' ) . '</a>'
);
echo '  ';
printf(
/* translators: 1: link to code reference, 2: link to code reference */
esc_html__( 'There are a number of different ways this could happen, but it often is the result of something hooking into %1$s rather that %2$s.', 'updates-api-inspector' ),
sprintf(
'<a href="%s">site_transient_update_themes</a>',
esc_url( __( 'https://developer.wordpress.org/reference/hooks/set_site_transient_transient/', 'updates-api-inspector' ) )
),
sprintf(
'<a href="%s">pre_set_site_transient_update_themes</a>',
esc_url( __( 'https://developer.wordpress.org/reference/hooks/pre_set_site_transient_transient/', 'updates-api-inspector' ) )
)
);
?>
</p>