Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 29 |
|
0.00% |
0 / 5 |
CRAP | |
0.00% |
0 / 1 |
| tlkio_widget_init | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| Tlkio_Widget | |
0.00% |
0 / 27 |
|
0.00% |
0 / 4 |
42 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
2 | |||
| widget | |
0.00% |
0 / 9 |
|
0.00% |
0 / 1 |
12 | |||
| form | |
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
2 | |||
| update | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php // phpcs:ignore Squiz.Commenting.FileComment.Missing |
| 2 | |
| 3 | /* |
| 4 | Plugin Name: Tlkio |
| 5 | Description: Widget to add a tlk.io webchat. |
| 6 | Version: 0.1 |
| 7 | Author: Automattic Inc. |
| 8 | Author URI: http://automattic.com/ |
| 9 | License: GPLv2 or later |
| 10 | */ |
| 11 | |
| 12 | /* |
| 13 | * This widget has been copied verbatum from WordPress.com. |
| 14 | */ |
| 15 | |
| 16 | /** |
| 17 | * Tlkio widget from WordPress.com |
| 18 | */ |
| 19 | class Tlkio_Widget extends WP_Widget { |
| 20 | /** |
| 21 | * Widget settings. |
| 22 | * |
| 23 | * @var array $defaults |
| 24 | */ |
| 25 | private $defaults = array( |
| 26 | 'title' => '', |
| 27 | 'channel' => 'lobby', |
| 28 | 'height' => '400', |
| 29 | ); |
| 30 | |
| 31 | /** |
| 32 | * Constructor. |
| 33 | */ |
| 34 | public function __construct() { |
| 35 | $widget_ops = array( |
| 36 | 'classname' => 'tlkio-widget', |
| 37 | 'description' => __( 'Add a tlk.io webchat.', 'wpcomsh' ), |
| 38 | ); |
| 39 | parent::__construct( 'tlkio_widget', __( 'tlk.io Webchat', 'wpcomsh' ), $widget_ops ); |
| 40 | } |
| 41 | |
| 42 | /** |
| 43 | * Display the widget. |
| 44 | * |
| 45 | * @param array $args Widget arguments. |
| 46 | * @param array $instance Widget instance. |
| 47 | */ |
| 48 | public function widget( $args, $instance ) { |
| 49 | $instance = wp_parse_args( (array) $instance, $this->defaults ); |
| 50 | $instance['title'] = apply_filters( 'widget_title', $instance['title'], $instance, $this->id_base ); |
| 51 | |
| 52 | echo $args['before_widget']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 53 | if ( $instance['title'] ) { |
| 54 | echo $args['before_title'] . esc_html( $instance['title'] ) . $args['after_title']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 55 | } |
| 56 | |
| 57 | echo '<div id="tlkio" class="tlkio-container" data-channel="' . esc_attr( $instance['channel'] ) . '" style="width:100%; height:' . esc_attr( $instance['height'] ) . 'px;"></div>'; |
| 58 | |
| 59 | if ( ! wp_script_is( 'tlkio-js', 'enqueued' ) ) { |
| 60 | wp_enqueue_script( 'tlkio-js', plugins_url( 'tlkio.js', __FILE__ ), array(), '140115', true ); |
| 61 | } |
| 62 | |
| 63 | echo $args['after_widget']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 64 | } |
| 65 | |
| 66 | /** |
| 67 | * Display the widget settings form. |
| 68 | * |
| 69 | * @param array $instance Current settings. |
| 70 | * @return never |
| 71 | */ |
| 72 | public function form( $instance ) { |
| 73 | $instance = wp_parse_args( (array) $instance, $this->defaults ); |
| 74 | ?> |
| 75 | <p> |
| 76 | <label for="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>"><?php esc_html_e( 'Title:', 'wpcomsh' ); ?></label> |
| 77 | <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( $instance['title'] ); ?>" /> |
| 78 | </p> |
| 79 | <p> |
| 80 | <label for="<?php echo esc_attr( $this->get_field_id( 'channel' ) ); ?>"><?php esc_html_e( 'Channel:', 'wpcomsh' ); ?></label> |
| 81 | <input class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'channel' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'channel' ) ); ?>" type="text" value="<?php echo esc_attr( $instance['channel'] ); ?>" /> |
| 82 | </p> |
| 83 | <p> |
| 84 | <label for="<?php echo esc_attr( $this->get_field_id( 'height' ) ); ?>"><?php esc_html_e( 'Height (in pixel):', 'wpcomsh' ); ?></label> |
| 85 | <input id="<?php echo esc_attr( $this->get_field_id( 'height' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'height' ) ); ?>" type="text" value="<?php echo esc_attr( $instance['height'] ); ?>" size="3" /> |
| 86 | </p> |
| 87 | <?php |
| 88 | } |
| 89 | |
| 90 | /** |
| 91 | * Update the widget settings. |
| 92 | * |
| 93 | * @param array $new_instance New settings. |
| 94 | * @param array $old_instance Old settings. |
| 95 | */ |
| 96 | public function update( $new_instance, $old_instance ) { |
| 97 | $instance = $old_instance; |
| 98 | $instance['title'] = wp_strip_all_tags( $new_instance['title'] ); |
| 99 | $instance['channel'] = wp_strip_all_tags( $new_instance['channel'] ); |
| 100 | $instance['height'] = intval( $new_instance['height'] ); |
| 101 | |
| 102 | return $instance; |
| 103 | } |
| 104 | } |
| 105 | |
| 106 | /** |
| 107 | * Register widget. |
| 108 | */ |
| 109 | function tlkio_widget_init() { // phpcs:ignore Universal.Files.SeparateFunctionsFromOO.Mixed |
| 110 | register_widget( 'Tlkio_Widget' ); |
| 111 | } |
| 112 | add_action( 'widgets_init', 'tlkio_widget_init' ); |