[ Index ]

PHP Cross Reference of WordPress Trunk (Updated Daily)

Search

title

Body

[close]

/wp-content/plugins/akismet/ -> class.akismet-widget.php (source)

   1  <?php
   2  /**
   3   * @package Akismet
   4   */
   5  
   6  // We plan to gradually remove all of the disabled lint rules below.
   7  // phpcs:disable WordPress.Security.EscapeOutput.OutputNotEscaped
   8  
   9  class Akismet_Widget extends WP_Widget {
  10  
  11  	function __construct() {
  12          load_plugin_textdomain( 'akismet' );
  13  
  14          add_action( 'wp_enqueue_scripts', array( $this, 'akismet_widget_enqueue_styles' ) );
  15  
  16          parent::__construct(
  17              'akismet_widget',
  18              __( 'Akismet Widget', 'akismet' ),
  19              array( 'description' => __( 'Display the number of spam comments Akismet has caught', 'akismet' ) )
  20          );
  21      }
  22  
  23  	public function akismet_widget_enqueue_styles() {
  24          // Register the stylesheet handle
  25          wp_register_style( 'akismet-widget-style', false ); // No external file, just a handle
  26  
  27          // Enqueue the registered stylesheet
  28          wp_enqueue_style( 'akismet-widget-style' );
  29  
  30          // Add inline styles
  31          $inline_css = "
  32              .a-stats {
  33                  --akismet-color-mid-green: #357b49;
  34                  --akismet-color-white: #fff;
  35                  --akismet-color-light-grey: #f6f7f7;
  36  
  37                  max-width: 350px;
  38                  width: auto;
  39              }
  40  
  41              .a-stats * {
  42                  all: unset;
  43                  box-sizing: border-box;
  44              }
  45  
  46              .a-stats strong {
  47                  font-weight: 600;
  48              }
  49  
  50              .a-stats a.a-stats__link,
  51              .a-stats a.a-stats__link:visited,
  52              .a-stats a.a-stats__link:active {
  53                  background: var(--akismet-color-mid-green);
  54                  border: none;
  55                  box-shadow: none;
  56                  border-radius: 8px;
  57                  color: var(--akismet-color-white);
  58                  cursor: pointer;
  59                  display: block;
  60                  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen-Sans', 'Ubuntu', 'Cantarell', 'Helvetica Neue', sans-serif;
  61                  font-weight: 500;
  62                  padding: 12px;
  63                  text-align: center;
  64                  text-decoration: none;
  65                  transition: all 0.2s ease;
  66              }
  67  
  68              /* Extra specificity to deal with TwentyTwentyOne focus style */
  69              .widget .a-stats a.a-stats__link:focus {
  70                  background: var(--akismet-color-mid-green);
  71                  color: var(--akismet-color-white);
  72                  text-decoration: none;
  73              }
  74  
  75              .a-stats a.a-stats__link:hover {
  76                  filter: brightness(110%);
  77                  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.06), 0 0 2px rgba(0, 0, 0, 0.16);
  78              }
  79  
  80              .a-stats .count {
  81                  color: var(--akismet-color-white);
  82                  display: block;
  83                  font-size: 1.5em;
  84                  line-height: 1.4;
  85                  padding: 0 13px;
  86                  white-space: nowrap;
  87              }
  88          ";
  89          wp_add_inline_style( 'akismet-widget-style', $inline_css );
  90      }
  91  
  92  	function form( $instance ) {
  93          if ( $instance && isset( $instance['title'] ) ) {
  94              $title = $instance['title'];
  95          } else {
  96              $title = __( 'Spam Blocked', 'akismet' );
  97          }
  98          ?>
  99  
 100          <p>
 101          <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php esc_html_e( 'Title:', 'akismet' ); ?></label>
 102          <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 ); ?>" />
 103          </p>
 104  
 105          <?php
 106      }
 107  
 108  	function update( $new_instance, $old_instance ) {
 109          $instance          = array();
 110          $instance['title'] = strip_tags( $new_instance['title'] );
 111          return $instance;
 112      }
 113  
 114  	function widget( $args, $instance ) {
 115          $count = get_option( 'akismet_spam_count' );
 116  
 117          if ( ! isset( $instance['title'] ) ) {
 118              $instance['title'] = __( 'Spam Blocked', 'akismet' );
 119          }
 120  
 121          echo $args['before_widget'];
 122          if ( ! empty( $instance['title'] ) ) {
 123              echo $args['before_title'];
 124              echo esc_html( $instance['title'] );
 125              echo $args['after_title'];
 126          }
 127          ?>
 128  
 129          <div class="a-stats">
 130              <?php // Specifying colors inline for maximum specificity without using !important ?>
 131              <a href="https://akismet.com" class="a-stats__link" target="_blank" rel="noopener" style="background-color: var(--akismet-color-mid-green); color: var(--akismet-color-white);">
 132                  <?php
 133  
 134                  echo wp_kses(
 135                      sprintf(
 136                      /* translators: The placeholder is the number of pieces of spam blocked by Akismet. */
 137                          _n(
 138                              '<strong class="count">%1$s spam</strong> blocked by <strong>Akismet</strong>',
 139                              '<strong class="count">%1$s spam</strong> blocked by <strong>Akismet</strong>',
 140                              $count,
 141                              'akismet'
 142                          ),
 143                          number_format_i18n( $count )
 144                      ),
 145                      array(
 146                          'strong' => array(
 147                              'class' => true,
 148                          ),
 149                      )
 150                  );
 151  
 152                  ?>
 153              </a>
 154          </div>
 155  
 156          <?php
 157          echo $args['after_widget'];
 158      }
 159  }
 160  
 161  function akismet_register_widgets() {
 162      register_widget( 'Akismet_Widget' );
 163  }
 164  
 165  add_action( 'widgets_init', 'akismet_register_widgets' );


Generated : Sat Feb 22 08:20:01 2025 Cross-referenced by PHPXref