class.akismet-widget.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. <?php
  2. /**
  3. * @package Akismet
  4. */
  5. class Akismet_Widget extends WP_Widget {
  6. function __construct() {
  7. load_plugin_textdomain( 'akismet' );
  8. parent::__construct(
  9. 'akismet_widget',
  10. __( 'Akismet Widget' , 'akismet'),
  11. array( 'description' => __( 'Display the number of spam comments Akismet has caught' , 'akismet') )
  12. );
  13. if ( is_active_widget( false, false, $this->id_base ) ) {
  14. add_action( 'wp_head', array( $this, 'css' ) );
  15. }
  16. }
  17. function css() {
  18. ?>
  19. <style type="text/css">
  20. .a-stats {
  21. width: auto;
  22. }
  23. .a-stats a {
  24. background: #7CA821;
  25. background-image:-moz-linear-gradient(0% 100% 90deg,#5F8E14,#7CA821);
  26. background-image:-webkit-gradient(linear,0% 0,0% 100%,from(#7CA821),to(#5F8E14));
  27. border: 1px solid #5F8E14;
  28. border-radius:3px;
  29. color: #CFEA93;
  30. cursor: pointer;
  31. display: block;
  32. font-weight: normal;
  33. height: 100%;
  34. -moz-border-radius:3px;
  35. padding: 7px 0 8px;
  36. text-align: center;
  37. text-decoration: none;
  38. -webkit-border-radius:3px;
  39. width: 100%;
  40. }
  41. .a-stats a:hover {
  42. text-decoration: none;
  43. background-image:-moz-linear-gradient(0% 100% 90deg,#6F9C1B,#659417);
  44. background-image:-webkit-gradient(linear,0% 0,0% 100%,from(#659417),to(#6F9C1B));
  45. }
  46. .a-stats .count {
  47. color: #FFF;
  48. display: block;
  49. font-size: 15px;
  50. line-height: 16px;
  51. padding: 0 13px;
  52. white-space: nowrap;
  53. }
  54. </style>
  55. <?php
  56. }
  57. function form( $instance ) {
  58. if ( $instance && isset( $instance['title'] ) ) {
  59. $title = $instance['title'];
  60. }
  61. else {
  62. $title = __( 'Spam Blocked' , 'akismet' );
  63. }
  64. ?>
  65. <p>
  66. <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php esc_html_e( 'Title:' , 'akismet'); ?></label>
  67. <input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo esc_attr( $title ); ?>" />
  68. </p>
  69. <?php
  70. }
  71. function update( $new_instance, $old_instance ) {
  72. $instance = array();
  73. $instance['title'] = strip_tags( $new_instance['title'] );
  74. return $instance;
  75. }
  76. function widget( $args, $instance ) {
  77. $count = get_option( 'akismet_spam_count' );
  78. if ( ! isset( $instance['title'] ) ) {
  79. $instance['title'] = __( 'Spam Blocked' , 'akismet' );
  80. }
  81. echo $args['before_widget'];
  82. if ( ! empty( $instance['title'] ) ) {
  83. echo $args['before_title'];
  84. echo esc_html( $instance['title'] );
  85. echo $args['after_title'];
  86. }
  87. ?>
  88. <div class="a-stats">
  89. <a href="https://akismet.com" target="_blank" rel="noopener" title="">
  90. <?php
  91. echo wp_kses(
  92. sprintf(
  93. /* translators: The placeholder is the number of pieces of spam blocked by Akismet. */
  94. _n(
  95. '<strong class="count">%1$s spam</strong> blocked by <strong>Akismet</strong>',
  96. '<strong class="count">%1$s spam</strong> blocked by <strong>Akismet</strong>',
  97. $count,
  98. 'akismet'
  99. ),
  100. number_format_i18n( $count )
  101. ),
  102. array(
  103. 'strong' => array(
  104. 'class' => true,
  105. ),
  106. )
  107. );
  108. ?>
  109. </a>
  110. </div>
  111. <?php
  112. echo $args['after_widget'];
  113. }
  114. }
  115. function akismet_register_widgets() {
  116. register_widget( 'Akismet_Widget' );
  117. }
  118. add_action( 'widgets_init', 'akismet_register_widgets' );