admin.php 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. /**
  3. * The standard set of admin pages for the user if Jetpack is installed
  4. */
  5. class WordAds_Admin {
  6. /**
  7. * @since 4.5.0
  8. */
  9. function __construct() {
  10. global $wordads;
  11. if ( current_user_can( 'manage_options' ) && isset( $_GET['ads_debug'] ) ) {
  12. WordAds_API::update_wordads_status_from_api();
  13. add_action( 'admin_notices', array( $this, 'debug_output' ) );
  14. }
  15. }
  16. /**
  17. * Output the API connection debug
  18. * @since 4.5.0
  19. */
  20. function debug_output() {
  21. global $wordads, $wordads_status_response;
  22. $response = $wordads_status_response;
  23. if ( empty( $response ) ) {
  24. $response = 'No response from API :(';
  25. } else {
  26. $response = print_r( $response, 1 );
  27. }
  28. $status = $wordads->option( 'wordads_approved' ) ?
  29. '<span style="color:green;">Yes</span>' :
  30. '<span style="color:red;">No</span>';
  31. $type = $wordads->option( 'wordads_approved' ) ? 'updated' : 'error';
  32. echo <<<HTML
  33. <div class="notice $type is-dismissible">
  34. <p>Status: $status</p>
  35. <pre>$response</pre>
  36. </div>
  37. HTML;
  38. }
  39. }
  40. global $wordads_admin;
  41. $wordads_admin = new WordAds_Admin();