PluginProbe
Powerkit – Supercharge your WordPress Site / 2.3.7
Powerkit – Supercharge your WordPress Site v2.3.7
3.1.1 3.1.0 3.0.9 3.0.8 trunk 2.2.6 2.2.7 2.2.8 2.2.9 2.3.0 2.3.1 2.3.2 2.3.3 2.3.4 2.3.5 2.3.6 2.3.7 2.3.8 2.3.9 2.4.0 2.4.1 2.4.2 2.4.3 2.4.4 2.4.5 All 87 releases
powerkit / modules / instagram / public / class-powerkit-instagram-widget.php

class-powerkit-instagram-widget.php in Powerkit – Supercharge your WordPress Site 2.3.7, at modules/instagram/public/class-powerkit-instagram-widget.php

181 lines 7.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Widget Instagram
4 *
5 * @link https://codesupply.co
6 * @since 1.0.0
7 *
8 * @package PowerKit
9 * @subpackage PowerKit/widgets
10 */
11
12 /**
13 * Widget Instagram Class
14 */
15 class Powerkit_Instagram_Widget extends WP_Widget {
16
17 /**
18 * Sets up a new widget instance.
19 */
20 public function __construct() {
21
22 $this->default_settings = apply_filters( 'powerkit_instagram_widget_settings', array(
23 'title' => esc_html__( 'Instagram', 'powerkit' ),
24 'user_id' => '',
25 'header' => true,
26 'button' => true,
27 'number' => 6,
28 'columns' => 2,
29 'size' => 'auto',
30 'target' => '_blank',
31 'template' => 'default',
32 ) );
33
34 $widget_details = array(
35 'classname' => 'powerkit_instagram_widget',
36 'description' => esc_html__( 'Instagram widget.', 'powerkit' ),
37 );
38 parent::__construct( 'powerkit_instagram_widget', esc_html__( 'Instagram', 'powerkit' ), $widget_details );
39 }
40
41 /**
42 * Outputs the content for the current widget instance.
43 *
44 * @param array $args Display arguments including 'before_title', 'after_title',
45 * 'before_widget', and 'after_widget'.
46 * @param array $instance Settings for the current widget instance.
47 */
48 public function widget( $args, $instance ) {
49 $params = array_merge( $this->default_settings, $instance );
50
51 $widget_id = isset( $args['widget_id'] ) ? $args['widget_id'] : 0;
52
53 // Before Widget.
54 echo $args['before_widget']; // XSS OK.
55 ?>
56
57 <div class="widget-body">
58 <?php
59 // Title.
60 if ( $params['title'] ) {
61 echo $args['before_title'] . apply_filters( 'widget_title', $params['title'], $instance, $this->id_base ) . $args['after_title']; // XSS.
62 }
63
64 // Instagram output.
65 powerkit_instagram_get_recent( $params, sprintf( 'powerkit_instagram_recent_%s', $widget_id ) );
66 ?>
67 </div>
68
69 <?php
70
71 // After Widget.
72 echo $args['after_widget']; // XSS OK.
73 }
74
75 /**
76 * Handles updating settings for the current widget instance.
77 *
78 * @param array $new_instance New settings for this instance as input by the user via
79 * WP_Widget::form().
80 * @param array $old_instance Old settings for this instance.
81 * @return array Settings to save or bool false to cancel saving.
82 */
83 public function update( $new_instance, $old_instance ) {
84 $instance = $new_instance;
85
86 // Display header.
87 if ( ! isset( $instance['header'] ) ) {
88 $instance['header'] = false;
89 }
90
91 // Display follow button.
92 if ( ! isset( $instance['button'] ) ) {
93 $instance['button'] = false;
94 }
95
96 return $instance;
97 }
98
99 /**
100 * Outputs the widget settings form.
101 *
102 * @param array $instance Current settings.
103 */
104 public function form( $instance ) {
105 $params = array_merge( $this->default_settings, $instance );
106
107 $templates = apply_filters( 'powerkit_instagram_templates', array() );
108 ?>
109 <!-- Title -->
110 <p>
111 <label for="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>"><?php esc_html_e( 'Title:', 'powerkit' ); ?></label>
112 <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( $params['title'] ); ?>" />
113 </p>
114
115 <!-- User Id -->
116 <p>
117 <label for="<?php echo esc_attr( $this->get_field_id( 'user_id' ) ); ?>"><?php esc_html_e( 'User ID:', 'powerkit' ); ?></label>
118 <input class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'user_id' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'user_id' ) ); ?>" type="text" value="<?php echo esc_attr( $params['user_id'] ); ?>" />
119 </p>
120
121 <!-- Display header -->
122 <p><input id="<?php echo esc_attr( $this->get_field_id( 'header' ) ); ?>" class="checkbox" name="<?php echo esc_attr( $this->get_field_name( 'header' ) ); ?>" type="checkbox" <?php checked( (bool) $params['header'] ); ?> />
123 <label for="<?php echo esc_attr( $this->get_field_id( 'header' ) ); ?>"><?php esc_html_e( 'Display header', 'powerkit' ); ?></label></p>
124
125 <!-- Display follow button -->
126 <p><input id="<?php echo esc_attr( $this->get_field_id( 'button' ) ); ?>" class="checkbox" name="<?php echo esc_attr( $this->get_field_name( 'button' ) ); ?>" type="checkbox" <?php checked( (bool) $params['button'] ); ?> />
127 <label for="<?php echo esc_attr( $this->get_field_id( 'button' ) ); ?>"><?php esc_html_e( 'Display follow button', 'powerkit' ); ?></label></p>
128
129 <!-- Number of photos -->
130 <p>
131 <label for="<?php echo esc_attr( $this->get_field_id( 'number' ) ); ?>"><?php esc_html_e( 'Number of images (maximum 12):', 'powerkit' ); ?></label>
132 <input id="<?php echo esc_attr( $this->get_field_id( 'number' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'number' ) ); ?>" type="text" value="<?php echo absint( $params['number'] ); ?>" size="3" />
133 </p>
134
135 <!-- Number of columns -->
136 <p>
137 <label for="<?php echo esc_attr( $this->get_field_id( 'columns' ) ); ?>"><?php esc_html_e( 'Number of columns:', 'powerkit' ); ?></label>
138 <select id="<?php echo esc_attr( $this->get_field_id( 'columns' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'columns' ) ); ?>" class="widefat">
139 <option value="1" <?php selected( $params['columns'], '1' ); ?>><?php esc_html_e( '1', 'powerkit' ); ?></option>
140 <option value="2" <?php selected( $params['columns'], '2' ); ?>><?php esc_html_e( '2', 'powerkit' ); ?></option>
141 <option value="3" <?php selected( $params['columns'], '3' ); ?>><?php esc_html_e( '3', 'powerkit' ); ?></option>
142 </select>
143 </p>
144
145 <!-- Open links in -->
146 <p>
147 <label for="<?php echo esc_attr( $this->get_field_id( 'target' ) ); ?>"><?php esc_html_e( 'Open links in:', 'powerkit' ); ?></label>
148 <select id="<?php echo esc_attr( $this->get_field_id( 'target' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'target' ) ); ?>" class="widefat">
149 <option value="_blank" <?php selected( $params['target'], '_blank' ); ?>><?php esc_html_e( 'New window (_blank)', 'powerkit' ); ?></option>
150 <option value="_self" <?php selected( $params['target'], '_self' ); ?>><?php esc_html_e( 'Current window (_self)', 'powerkit' ); ?></option>
151 </select>
152 </p>
153
154 <!-- Template -->
155 <?php if ( count( (array) $templates ) > 1 ) : ?>
156 <p><label for="<?php echo esc_attr( $this->get_field_id( 'Template' ) ); ?>"><?php esc_html_e( 'Template', 'powerkit' ); ?></label>
157 <select name="<?php echo esc_attr( $this->get_field_name( 'template' ) ); ?>" id="<?php echo esc_attr( $this->get_field_id( 'template' ) ); ?>" class="widefat">
158 <?php
159 if ( $templates ) {
160 foreach ( $templates as $key => $item ) {
161 ?>
162 <option value="<?php echo esc_attr( $key ); ?>" <?php selected( $params['template'], $key ); ?>><?php echo esc_attr( $item['name'] ); ?></option>
163 <?php
164 }
165 }
166 ?>
167 </select>
168 </p>
169 <?php endif; ?>
170 <?php
171 }
172 }
173
174 /**
175 * Register Widget
176 */
177 function powerkit_widget_init_instagram() {
178 register_widget( 'Powerkit_Instagram_Widget' );
179 }
180 add_action( 'widgets_init', 'powerkit_widget_init_instagram' );
181