| [ Index ] |
PHP Cross Reference of WordPress Trunk (Updated Daily) |
[Summary view] [Print] [Text view]
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 /** 10 * Akismet Widget Class 11 */ 12 class Akismet_Widget extends WP_Widget { 13 14 function __construct() { 15 parent::__construct( 16 'akismet_widget', 17 __( 'Akismet Widget', 'akismet' ), 18 array( 'description' => __( 'Display the number of spam comments Akismet has caught', 'akismet' ) ) 19 ); 20 } 21 22 /** 23 * Outputs the widget settings form 24 * 25 * @param array $instance The widget options 26 */ 27 public function form( $instance ) { 28 if ( $instance && isset( $instance['title'] ) ) { 29 $title = $instance['title']; 30 } else { 31 $title = __( 'Spam Blocked', 'akismet' ); 32 } 33 ?> 34 35 <p> 36 <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php esc_html_e( 'Title:', 'akismet' ); ?></label> 37 <input class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'title' ) ); ?>" type="text" value="<?php echo esc_attr( $title ); ?>" /> 38 </p> 39 40 <?php 41 } 42 43 /** 44 * Updates the widget settings 45 * 46 * @param array $new_instance New widget instance 47 * @param array $old_instance Old widget instance 48 * @return array Updated widget instance 49 */ 50 public function update( $new_instance, $old_instance ) { 51 $instance = array(); 52 $instance['title'] = sanitize_text_field( $new_instance['title'] ); 53 return $instance; 54 } 55 56 /** 57 * Outputs the widget content 58 * 59 * @param array $args Widget arguments 60 * @param array $instance Widget instance 61 */ 62 public function widget( $args, $instance ) { 63 $count = get_option( 'akismet_spam_count' ); 64 65 if ( ! isset( $instance['title'] ) ) { 66 $instance['title'] = __( 'Spam Blocked', 'akismet' ); 67 } 68 69 echo $args['before_widget']; 70 if ( ! empty( $instance['title'] ) ) { 71 echo $args['before_title']; 72 echo esc_html( $instance['title'] ); 73 echo $args['after_title']; 74 } 75 ?> 76 77 <style> 78 .a-stats { 79 --akismet-color-mid-green: #357b49; 80 --akismet-color-white: #fff; 81 --akismet-color-light-grey: #f6f7f7; 82 83 max-width: 350px; 84 width: auto; 85 } 86 87 .a-stats * { 88 all: unset; 89 box-sizing: border-box; 90 } 91 92 /* Re-hide screen reader text — the all: unset reset above would otherwise render it as visible text. */ 93 .a-stats .screen-reader-text { 94 border: 0; 95 clip: rect(1px, 1px, 1px, 1px); 96 clip-path: inset(50%); 97 height: 1px; 98 margin: -1px; 99 overflow: hidden; 100 padding: 0; 101 position: absolute; 102 width: 1px; 103 word-wrap: normal; 104 } 105 106 .a-stats strong { 107 font-weight: 600; 108 } 109 110 .a-stats a.a-stats__link, 111 .a-stats a.a-stats__link:visited, 112 .a-stats a.a-stats__link:active { 113 background: var(--akismet-color-mid-green); 114 border: none; 115 box-shadow: none; 116 border-radius: 8px; 117 color: var(--akismet-color-white); 118 cursor: pointer; 119 display: block; 120 font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen-Sans', 'Ubuntu', 'Cantarell', 'Helvetica Neue', sans-serif; 121 font-weight: 500; 122 padding: 12px; 123 text-align: center; 124 text-decoration: none; 125 transition: all 0.2s ease; 126 } 127 128 /* Extra specificity to deal with TwentyTwentyOne focus style */ 129 .widget .a-stats a.a-stats__link:focus { 130 background: var(--akismet-color-mid-green); 131 color: var(--akismet-color-white); 132 text-decoration: none; 133 } 134 135 .a-stats a.a-stats__link:hover { 136 filter: brightness(110%); 137 box-shadow: 0 4px 12px rgba(0, 0, 0, 0.06), 0 0 2px rgba(0, 0, 0, 0.16); 138 } 139 140 .a-stats .count { 141 color: var(--akismet-color-white); 142 display: block; 143 font-size: 1.5em; 144 line-height: 1.4; 145 padding: 0 13px; 146 white-space: nowrap; 147 } 148 </style> 149 150 <div class="a-stats"> 151 <a href="https://akismet.com?utm_source=akismet_plugin&utm_campaign=plugin_static_link&utm_medium=in_plugin&utm_content=widget_stats" class="a-stats__link" target="_blank" rel="noopener" style="background-color: var(--akismet-color-mid-green); color: var(--akismet-color-white);"> 152 <?php 153 154 echo wp_kses( 155 sprintf( 156 /* translators: The placeholder is the number of pieces of spam blocked by Akismet. */ 157 _n( 158 '<strong class="count">%1$s spam</strong> blocked by <strong>Akismet</strong>', 159 '<strong class="count">%1$s spam</strong> blocked by <strong>Akismet</strong>', 160 $count, 161 'akismet' 162 ), 163 number_format_i18n( $count ) 164 ), 165 array( 166 'strong' => array( 167 'class' => true, 168 ), 169 ) 170 ); 171 172 ?> 173 <?php echo Akismet::get_new_tab_screen_reader_html(); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Returns markup escaped in the helper. ?> 174 </a> 175 </div> 176 177 <?php 178 echo $args['after_widget']; 179 } 180 } 181 182 /** 183 * Register the Akismet widget 184 */ 185 function akismet_register_widgets() { 186 register_widget( 'Akismet_Widget' ); 187 } 188 189 add_action( 'widgets_init', 'akismet_register_widgets' );
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated : Tue Sep 8 08:20:28 2026 | Cross-referenced by PHPXref |