PluginProbe
Automatic YouTube Gallery – Embed Auto-Updating YouTube Video Galleries, Feeds, Playlists & Channels / 2.3.5
Automatic YouTube Gallery – Embed Auto-Updating YouTube Video Galleries, Feeds, Playlists & Channels v2.3.5
2.9.1 2.9.0 trunk 1.0.0 1.1.0 1.2.0 1.3.0 1.4.0 1.5.0 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.6.5 2.0.0 2.1.0 2.2.0 2.3.2 2.3.3 2.3.5 2.3.6 2.3.8 2.3.9 2.4.3 All 37 releases
automatic-youtube-gallery / widget / widget.php

widget.php in Automatic YouTube Gallery – Embed Auto-Updating YouTube Video Galleries, Feeds, Playlists & Channels 2.3.5, at widget/widget.php

133 lines 3.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Automatic YouTube Gallery Widget.
5 *
6 * @link https://plugins360.com
7 * @since 2.1.0
8 *
9 * @package Automatic_YouTube_Gallery
10 */
11
12 // Exit if accessed directly
13 if ( ! defined( 'WPINC' ) ) {
14 die;
15 }
16
17 /**
18 * AYG_Widget class.
19 *
20 * @since 2.1.0
21 */
22 class AYG_Widget extends WP_Widget {
23
24 /**
25 * Get things going.
26 *
27 * @since 2.1.0
28 */
29 public function __construct() {
30 $widget_slug = 'ayg-widget';
31
32 parent::__construct(
33 $widget_slug,
34 __( 'Automatic YouTube Gallery', 'automatic-youtube-gallery' ),
35 array(
36 'classname' => $widget_slug,
37 'description' => __( 'Displays automated YouTube video gallery.', 'automatic-youtube-gallery' )
38 )
39 );
40 }
41
42 /**
43 * Outputs the content of the widget.
44 *
45 * @since 2.1.0
46 * @param array $args The array of form elements.
47 * @param array $instance The current instance of the widget.
48 */
49 public function widget( $args, $instance ) {
50 // Process output
51 echo $args['before_widget'];
52
53 if ( ! empty( $instance['title'] ) ) {
54 echo $args['before_title'] . apply_filters( 'widget_title', $instance['title'] ) . $args['after_title'];
55 }
56
57 if ( isset( $args['widget_id'] ) ) {
58 $instance['uid'] = md5( $args['widget_id'] );
59 }
60
61 echo ayg_build_gallery( $instance );
62
63 echo $args['after_widget'];
64 }
65
66 /**
67 * Processes the widget's options to be saved.
68 *
69 * @since 2.1.0
70 * @param array $new_instance The new instance of values to be generated via the update.
71 * @param array $old_instance The previous instance of values before the update.
72 */
73 public function update( $new_instance, $old_instance ) {
74 $instance = array();
75
76 $instance['title'] = isset( $new_instance['title'] ) ? strip_tags( $new_instance['title'] ) : '';
77
78 $fields = ayg_get_editor_fields();
79
80 foreach ( $fields as $key => $value ) {
81 foreach ( $value['fields'] as $field ) {
82 $field_name = $field['name'];
83 $field_type = $field['type'];
84
85 if ( 'number' == $field_type ) {
86 if ( ! empty( $new_instance[ $field_name ] ) ) {
87 $instance[ $field_name ] = false === strpos( $new_instance[ $field_name ], '.' ) ? (int) $new_instance[ $field_name ] : (float) $new_instance[ $field_name ];
88 } else {
89 $instance[ $field_name ] = 0;
90 }
91 } elseif ( 'checkbox' == $field_type ) {
92 $instance[ $field_name ] = isset( $new_instance[ $field_name ] ) ? (int) $new_instance[ $field_name ] : 0;
93 } else {
94 $instance[ $field_name ] = ! empty( $new_instance[ $field_name ] ) ? sanitize_text_field( $new_instance[ $field_name ] ) : '';
95 }
96 }
97 }
98
99 return $instance;
100 }
101
102 /**
103 * Generates the administration form for the widget.
104 *
105 * @since 2.1.0
106 * @param array $instance The array of keys and values for the widget.
107 */
108 public function form( $instance ) {
109 // Define the array of defaults
110 $fields = ayg_get_editor_fields();
111
112 $defaults = array(
113 'title' => __( 'Automatic YouTube Gallery', 'automatic-youtube-gallery' )
114 );
115
116 foreach ( $fields as $key => $value ) {
117 foreach ( $value['fields'] as $field ) {
118 $defaults[ $field['name'] ] = $field['value'];
119 }
120 }
121
122 // Parse incoming $instance into an array and merge it with $defaults
123 $instance = wp_parse_args(
124 (array) $instance,
125 $defaults
126 );
127
128 // Display the admin form
129 include AYG_DIR . 'widget/templates/admin.php';
130 }
131
132 }
133