PluginProbe
Wp-Insert / 2.6.0
Wp-Insert v2.6.0
trunk 1.0 1.1 1.2 1.2.1 1.2.2 1.3.0 1.3.1 1.3.3 1.4 1.5.0 1.5.1 1.5.2 1.5.3 1.6.0 1.6.1 1.6.2 1.7 1.7.1 1.7.2 1.7.3 1.7.4 1.7.5 1.7.6 2.0 All 63 releases
wp-insert / includes / modules / general / widgets / class-wpinsertadwidget.php

class-wpinsertadwidget.php in Wp-Insert 2.6.0, at includes/modules/general/widgets/class-wpinsertadwidget.php

61 lines 2.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Wp-Insert ad widget.
4 *
5 * @package wp-insert
6 */
7
8 class wpInsertAdWidget extends WP_Widget {
9 public function __construct() {
10 parent::__construct( 'wp_insert_ad_widget', 'Wp-Insert Ad Widget', [ 'description' => 'Wp-Insert Ad Widget' ] );
11 }
12
13 public function widget( $args, $instance ) {
14 $title = apply_filters( 'widget_title', ( isset( $instance['title'] ) ? $instance['title'] : '' ) );
15 $adwidgets = get_option( 'wp_insert_adwidgets' );
16 if ( isset( $instance['instance'], $adwidgets[ $instance['instance'] ] ) && is_array( $adwidgets[ $instance['instance'] ] ) ) {
17 if ( wp_insert_get_ad_status( $adwidgets[ $instance['instance'] ] ) ) {
18 // Theme-supplied wrappers are trusted markup, matching core widget behavior.
19 wp_insert_echo_html( $args['before_widget'] ?? '' );
20 if ( ! empty( $title ) ) {
21 wp_insert_echo_html( ( $args['before_title'] ?? '' ) . esc_html( $title ) . ( $args['after_title'] ?? '' ) );
22 }
23 wp_insert_echo_ad_code( wp_insert_get_ad_unit( $adwidgets[ $instance['instance'] ] ) );
24 wp_insert_echo_html( $args['after_widget'] ?? '' );
25 }
26 }
27 }
28
29 public function update( $new_opts, $old_opts ) {
30 $opts = [];
31 $opts['title'] = sanitize_text_field( $new_opts['title'] ?? '' );
32 $opts['instance'] = sanitize_key( $new_opts['instance'] ?? '' );
33 return $opts;
34 }
35
36 public function form( $instance ) {
37 $adwidgets = get_option( 'wp_insert_adwidgets' );
38 echo '<p>';
39 echo '<label for="' . esc_attr( $this->get_field_id( 'title' ) ) . '">' . esc_html__( 'Title:', 'wp-insert' ) . '</label>';
40 echo '<input class="widefat" id="' . esc_attr( $this->get_field_id( 'title' ) ) . '" name="' . esc_attr( $this->get_field_name( 'title' ) ) . '" type="text" value="' . esc_attr( $instance['title'] ?? '' ) . '" />';
41 echo '</p>';
42 echo '<p>';
43 if ( is_array( $adwidgets ) && ( count( $adwidgets ) > 0 ) ) {
44 echo '<label for="' . esc_attr( $this->get_field_id( 'instance' ) ) . '">' . esc_html__( 'Select Ad-Widget:', 'wp-insert' ) . '</label>';
45 echo '<select class="widefat" id="' . esc_attr( $this->get_field_id( 'instance' ) ) . '" name="' . esc_attr( $this->get_field_name( 'instance' ) ) . '">';
46 foreach ( $adwidgets as $identifier => $adwidget ) {
47 echo '<option value="' . esc_attr( $identifier ) . '" ' . selected( $identifier, ( $instance['instance'] ?? '' ), false ) . '>' . esc_html( 'Ad Widget : ' . ( $adwidget['title'] ?? '' ) ) . '</option>';
48 }
49 echo '</select>';
50 } else {
51 printf(
52 /* translators: %s: URL of the Wp-Insert settings page. */
53 esc_html__( 'Please %s to Proceed.', 'wp-insert' ),
54 '<a href="' . esc_url( admin_url( 'admin.php?page=wp-insert' ) ) . '">' . esc_html__( 'Configure an Ad-Widget', 'wp-insert' ) . '</a>'
55 );
56 echo '<input class="widefat" id="' . esc_attr( $this->get_field_id( 'instance' ) ) . '" name="' . esc_attr( $this->get_field_name( 'instance' ) ) . '" type="hidden" value="" />';
57 }
58 echo '</p>';
59 }
60 }
61