esc_html__( 'Show your support for the Internet Defense League.', 'jetpack' ), 'customize_selective_refresh' => true, ) ); // When enabling campaigns other than 'none' or empty, change $no_current to false above. $this->campaigns = array( '' => esc_html__( 'All current and future campaigns', 'jetpack' ), 'none' => esc_html__( 'None, just display the badge please', 'jetpack' ), ); $this->variants = array( 'banner' => esc_html__( 'Banner at the top of my site', 'jetpack' ), 'modal' => esc_html__( 'Modal (Overlay Box)', 'jetpack' ), ); $this->badges = array( 'shield_badge' => esc_html__( 'Shield Badge', 'jetpack' ), 'super_badge' => esc_html__( 'Super Badge', 'jetpack' ), 'side_bar_badge' => esc_html__( 'Red Cat Badge', 'jetpack' ), ); if ( $this->no_current === false ) { $this->badges['none'] = esc_html__( 'Don\'t display a badge (just the campaign)', 'jetpack' ); } $this->defaults = array( 'campaign' => key( $this->campaigns ), 'variant' => key( $this->variants ), 'badge' => key( $this->badges ), ); } public function widget( $args, $instance ) { $instance = wp_parse_args( $instance, $this->defaults ); if ( 'none' != $instance['badge'] ) { if ( ! isset( $this->badges[ $instance['badge'] ] ) ) { $instance['badge'] = $this->defaults['badge']; } $badge_url = esc_url( 'https://internetdefenseleague.org/images/badges/final/' . $instance['badge'] . '.png' ); $photon_badge_url = jetpack_photon_url( $badge_url ); $alt_text = esc_html__( 'Member of The Internet Defense League', 'jetpack' ); echo $args['before_widget']; echo '

' . $alt_text .'

'; echo $args['after_widget']; } if ( 'none' != $instance['campaign'] ) { $this->campaign = $instance['campaign']; $this->variant = $instance['variant']; add_action( 'wp_footer', array( $this, 'footer_script' ) ); } /** This action is already documented in modules/widgets/gravatar-profile.php */ do_action( 'jetpack_stats_extra', 'widget_view', 'internet_defense_league' ); } public function footer_script() { if ( ! isset( $this->campaigns[ $this->campaign ] ) ) { $this->campaign = $this->defaults['campaign']; } if ( ! isset( $this->variants[ $this->variant ] ) ) { $this->variant = $this->defaults['variant']; } ?> defaults ); // Hide first two form fields if no current campaigns. if ( false === $this->no_current ) { echo '

'; echo '

'; } echo '

'; /* translators: %s is a name of an internet campaign called the "Internet Defense League" */ echo '

' . sprintf( _x( 'Learn more about the %s', 'the Internet Defense League', 'jetpack' ), 'Internet Defense League' ) . '

'; } public function select( $field_name, $options, $default = null ) { echo ''; } public function update( $new_instance, $old_instance ) { $instance = array(); $instance['campaign'] = ( isset( $new_instance['campaign'] ) && isset( $this->campaigns[ $new_instance['campaign'] ] ) ) ? $new_instance['campaign'] : $this->defaults['campaign']; $instance['variant'] = ( isset( $new_instance['variant'] ) && isset( $this->variants[ $new_instance['variant'] ] ) ) ? $new_instance['variant'] : $this->defaults['variant']; $instance['badge'] = ( isset( $new_instance['badge'] ) && isset( $this->badges[ $new_instance['badge'] ] ) ) ? $new_instance['badge'] : $this->defaults['badge']; return $instance; } } function jetpack_internet_defense_league_init() { register_widget( 'Jetpack_Internet_Defense_League_Widget' ); } add_action( 'widgets_init', 'jetpack_internet_defense_league_init' );