1
0

PluginExtension.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. <?php
  2. namespace YahnisElsts\PluginUpdateChecker\v5p1\DebugBar;
  3. use YahnisElsts\PluginUpdateChecker\v5p1\Plugin\UpdateChecker;
  4. if ( !class_exists(PluginExtension::class, false) ):
  5. class PluginExtension extends Extension {
  6. /** @var UpdateChecker */
  7. protected $updateChecker;
  8. public function __construct($updateChecker) {
  9. parent::__construct($updateChecker, PluginPanel::class);
  10. add_action('wp_ajax_puc_v5_debug_request_info', array($this, 'ajaxRequestInfo'));
  11. }
  12. /**
  13. * Request plugin info and output it.
  14. */
  15. public function ajaxRequestInfo() {
  16. //phpcs:ignore WordPress.Security.NonceVerification.Missing -- Nonce is checked in preAjaxRequest().
  17. if ( !isset($_POST['uid']) || ($_POST['uid'] !== $this->updateChecker->getUniqueName('uid')) ) {
  18. return;
  19. }
  20. $this->preAjaxRequest();
  21. $info = $this->updateChecker->requestInfo();
  22. if ( $info !== null ) {
  23. echo 'Successfully retrieved plugin info from the metadata URL:';
  24. //phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_print_r -- For debugging output.
  25. echo '<pre>', esc_html(print_r($info, true)), '</pre>';
  26. } else {
  27. echo 'Failed to retrieve plugin info from the metadata URL.';
  28. }
  29. exit;
  30. }
  31. }
  32. endif;