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 ( false === $this->no_current ) { $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 ), ); add_filter( 'widget_types_to_hide_from_legacy_widget_block', array( $this, 'hide_widget_in_block_editor' ) ); } /** * Remove the "Internet Defense League" widget from the Legacy Widget block * * @param array $widget_types List of widgets that are currently removed from the Legacy Widget block. * @return array $widget_types New list of widgets that will be removed. */ public function hide_widget_in_block_editor( $widget_types ) { $widget_types[] = 'internet_defense_league_widget'; return $widget_types; } /** * Display the Widget. * * @see WP_Widget::widget() * * @param array $args Display arguments. * @param array $instance The settings for the particular instance of the widget. */ 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://www.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']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped echo '
'; echo $args['after_widget']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped } 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' ); } /** * Inline footer script. */ 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']; } // On AMP endpoints, prevent a validation error from the inline script. if ( class_exists( 'Jetpack_AMP_Support' ) && Jetpack_AMP_Support::is_amp_request() ) { return; } ?> defaults ); // Hide first two form fields if no current campaigns. if ( false === $this->no_current ) { echo ''; echo ''; } echo ''; echo '' . wp_kses( sprintf( /* translators: %s is an HTML link to the website of an internet campaign called the "Internet Defense League" */ _x( 'Learn more about the %s', 'the Internet Defense League', 'jetpack' ), 'Internet Defense League' ), array( 'a' => array( 'href' => array(), ), ) ) . '
'; } /** * Display a select form field. * * @param string $field_name Name of the field. * @param array $options Array of options. * @param string $default Default option. */ public function select( $field_name, $options, $default = null ) { echo ''; } /** * Update widget. * * @see WP_Widget::update() * * @param array $new_instance New widget instance data. * @param array $old_instance Old widget instance data. */ public function update( $new_instance, $old_instance ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable $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; } } /** * Register the widget. */ function jetpack_internet_defense_league_init() { register_widget( 'Jetpack_Internet_Defense_League_Widget' ); } add_action( 'widgets_init', 'jetpack_internet_defense_league_init' );