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