Нет описания

class-jetpack-stats-dashboard-widget.php 4.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. <?php
  2. /**
  3. * Adds the Jetpack stats widget to the WordPress admin dashboard.
  4. *
  5. * @package jetpack
  6. */
  7. use Automattic\Jetpack\Assets\Logo as Jetpack_Logo;
  8. use Automattic\Jetpack\Status;
  9. /**
  10. * Class that adds the Jetpack stats widget to the WordPress admin dashboard.
  11. */
  12. class Jetpack_Stats_Dashboard_Widget {
  13. /**
  14. * Indicates whether the class initialized or not.
  15. *
  16. * @var bool
  17. */
  18. private static $initialized = false;
  19. /**
  20. * Initialize the class by calling the setup static function.
  21. *
  22. * @return void
  23. */
  24. public static function init() {
  25. if ( ! self::$initialized ) {
  26. self::$initialized = true;
  27. self::wp_dashboard_setup();
  28. }
  29. }
  30. /**
  31. * Sets up the Jetpack Stats widget in the WordPress admin dashboard.
  32. */
  33. public static function wp_dashboard_setup() {
  34. if ( Jetpack::is_connection_ready() ) {
  35. add_action( 'jetpack_dashboard_widget', array( __CLASS__, 'dashboard_widget_footer' ), 999 );
  36. }
  37. if ( has_action( 'jetpack_dashboard_widget' ) ) {
  38. $jetpack_logo = new Jetpack_Logo();
  39. $widget_title = sprintf(
  40. // translators: Placeholder is a Jetpack logo.
  41. __( 'Stats by %s', 'jetpack' ),
  42. $jetpack_logo->get_jp_emblem( true )
  43. );
  44. // Wrap title in span so Logo can be properly styled.
  45. $widget_title = sprintf(
  46. '<span>%s</span>',
  47. $widget_title
  48. );
  49. wp_add_dashboard_widget(
  50. 'jetpack_summary_widget',
  51. $widget_title,
  52. array( __CLASS__, 'dashboard_widget' )
  53. );
  54. wp_enqueue_style( 'jetpack-dashboard-widget', plugins_url( 'css/dashboard-widget.css', JETPACK__PLUGIN_FILE ), array(), JETPACK__VERSION );
  55. wp_style_add_data( 'jetpack-dashboard-widget', 'rtl', 'replace' );
  56. }
  57. }
  58. /**
  59. * Fires dashboard widget action.
  60. * Both the footer from this file and the stats graph from modules/stats.php hook into this action.
  61. */
  62. public static function dashboard_widget() {
  63. /**
  64. * Fires when the dashboard is loaded.
  65. *
  66. * @since 3.4.0
  67. */
  68. do_action( 'jetpack_dashboard_widget' );
  69. }
  70. /**
  71. * Load the widget footer showing Akismet stats.
  72. */
  73. public static function dashboard_widget_footer() {
  74. ?>
  75. <footer>
  76. <div class="protect">
  77. <h3><?php esc_html_e( 'Brute force attack protection', 'jetpack' ); ?></h3>
  78. <?php if ( Jetpack::is_module_active( 'protect' ) ) : ?>
  79. <p class="blocked-count">
  80. <?php echo esc_html( number_format_i18n( get_site_option( 'jetpack_protect_blocked_attempts', 0 ) ) ); ?>
  81. </p>
  82. <p><?php echo esc_html_x( 'Blocked malicious login attempts', '{#} Blocked malicious login attempts -- number is on a prior line, text is a caption.', 'jetpack' ); ?></p>
  83. <?php elseif ( current_user_can( 'jetpack_activate_modules' ) && ! ( new Status() )->is_offline_mode() ) : ?>
  84. <a href="
  85. <?php
  86. echo esc_url(
  87. wp_nonce_url(
  88. Jetpack::admin_url(
  89. array(
  90. 'action' => 'activate',
  91. 'module' => 'protect',
  92. )
  93. ),
  94. 'jetpack_activate-protect'
  95. )
  96. );
  97. ?>
  98. " class="button button-jetpack" title="<?php esc_attr_e( 'Protect helps to keep you secure from brute-force login attacks.', 'jetpack' ); ?>">
  99. <?php esc_html_e( 'Activate brute force attack protection', 'jetpack' ); ?>
  100. </a>
  101. <?php else : ?>
  102. <?php esc_html_e( 'Brute force attack protection is inactive.', 'jetpack' ); ?>
  103. <?php endif; ?>
  104. </div>
  105. <div class="akismet">
  106. <h3><?php esc_html_e( 'Anti-spam', 'jetpack' ); ?></h3>
  107. <?php if ( is_plugin_active( 'akismet/akismet.php' ) ) : ?>
  108. <p class="blocked-count">
  109. <?php echo esc_html( number_format_i18n( get_option( 'akismet_spam_count', 0 ) ) ); ?>
  110. </p>
  111. <p><?php echo esc_html_x( 'Blocked spam comments.', '{#} Spam comments blocked by Akismet -- number is on a prior line, text is a caption.', 'jetpack' ); ?></p>
  112. <?php elseif ( current_user_can( 'activate_plugins' ) && ! is_wp_error( validate_plugin( 'akismet/akismet.php' ) ) ) : ?>
  113. <a href="
  114. <?php
  115. echo esc_url(
  116. wp_nonce_url(
  117. add_query_arg(
  118. array(
  119. 'action' => 'activate',
  120. 'plugin' => 'akismet/akismet.php',
  121. ),
  122. admin_url( 'plugins.php' )
  123. ),
  124. 'activate-plugin_akismet/akismet.php'
  125. )
  126. );
  127. ?>
  128. " class="button button-jetpack">
  129. <?php esc_html_e( 'Activate Anti-spam', 'jetpack' ); ?>
  130. </a>
  131. <?php else : ?>
  132. <p><a href="<?php echo esc_url( 'https://akismet.com/?utm_source=jetpack&utm_medium=link&utm_campaign=Jetpack%20Dashboard%20Widget%20Footer%20Link' ); ?>"><?php esc_html_e( 'Anti-spam can help to keep your blog safe from spam!', 'jetpack' ); ?></a></p>
  133. <?php endif; ?>
  134. </div>
  135. </footer>
  136. <?php
  137. }
  138. }