abilities
1 week ago
admin
1 week ago
compatibility
1 week ago
extensions
1 week ago
foopluginbase
1 week ago
public
1 week ago
thumbs
1 week ago
asset-manifest.php
1 week ago
class-attachment-filters.php
1 week ago
class-command-palette.php
1 week ago
class-foogallery-animated-gif-support.php
1 week ago
class-foogallery-attachment-custom-class.php
1 week ago
class-foogallery-attachment-filename.php
1 week ago
class-foogallery-attachment-type.php
1 week ago
class-foogallery-attachment.php
1 week ago
class-foogallery-cache.php
1 week ago
class-foogallery-common-fields.php
1 week ago
class-foogallery-crop-position.php
1 week ago
class-foogallery-datasource-media_library.php
1 week ago
class-foogallery-debug.php
1 week ago
class-foogallery-delayed-runtime-loader.php
1 week ago
class-foogallery-extensions-compatibility.php
1 week ago
class-foogallery-force-https.php
1 week ago
class-foogallery-lazyload.php
1 week ago
class-foogallery-license-constant-handler.php
1 week ago
class-foogallery-lightbox.php
1 week ago
class-foogallery-no-javascript-fallback.php
1 week ago
class-foogallery-paging.php
1 week ago
class-foogallery-password-protect.php
1 week ago
class-foogallery-sitemaps.php
1 week ago
class-foogallery-widget.php
1 week ago
class-foogallery.php
1 week ago
class-gallery-advanced-settings.php
1 week ago
class-il8n.php
1 week ago
class-override-thumbnail.php
1 week ago
class-posttypes.php
1 week ago
class-previews.php
1 week ago
class-retina.php
1 week ago
class-thumbnail-dimensions.php
1 week ago
class-thumbnails.php
1 week ago
class-version-check.php
1 week ago
constants.php
1 week ago
functions.php
1 week ago
gallery-management-functions.php
1 week ago
includes.php
1 week ago
index.php
1 week ago
render-functions.php
1 week ago
class-foogallery-widget.php
118 lines
| 1 | <?php |
| 2 | |
| 3 | if ( ! defined( 'ABSPATH' ) ) { |
| 4 | exit; |
| 5 | } |
| 6 | |
| 7 | /** |
| 8 | * Widget to insert a FooGallery |
| 9 | */ |
| 10 | |
| 11 | if ( ! class_exists( 'FooGallery_Widget_Init' ) ) { |
| 12 | class FooGallery_Widget_Init |
| 13 | { |
| 14 | public function __construct() |
| 15 | { |
| 16 | add_action('widgets_init', array($this, 'register_widget')); |
| 17 | } |
| 18 | |
| 19 | public function register_widget() |
| 20 | { |
| 21 | register_widget('FooGallery_Widget'); |
| 22 | } |
| 23 | } |
| 24 | } |
| 25 | |
| 26 | if ( ! class_exists( 'FooGallery_Widget' ) ) { |
| 27 | class FooGallery_Widget extends WP_Widget |
| 28 | { |
| 29 | |
| 30 | /** |
| 31 | * Sets up the widgets name etc |
| 32 | */ |
| 33 | public function __construct() |
| 34 | { |
| 35 | $widget_ops = array( |
| 36 | 'classname' => 'foogallery_widget', |
| 37 | 'description' => __('Insert a FooGallery', 'foogallery'), |
| 38 | ); |
| 39 | |
| 40 | parent::__construct('foogallery_widget', __('FooGallery Widget', 'foogallery'), $widget_ops); |
| 41 | } |
| 42 | |
| 43 | |
| 44 | /** |
| 45 | * Outputs the content of the widget |
| 46 | * |
| 47 | * @param array $args |
| 48 | * @param array $instance |
| 49 | */ |
| 50 | public function widget($args, $instance) |
| 51 | { |
| 52 | // outputs the content of the widget |
| 53 | echo $args['before_widget']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 54 | if (!empty($instance['title'])) { |
| 55 | echo $args['before_title'] . apply_filters('widget_title', $instance['title']) . $args['after_title']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 56 | } |
| 57 | //output the gallery here |
| 58 | $foogallery_id = isset( $instance['foogallery_id'] ) ? intval( $instance['foogallery_id'] ) : 0; |
| 59 | if ( $foogallery_id > 0 ) { |
| 60 | foogallery_render_gallery( $foogallery_id ); |
| 61 | } |
| 62 | |
| 63 | echo $args['after_widget']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 64 | } |
| 65 | |
| 66 | |
| 67 | /** |
| 68 | * Outputs the options form on admin |
| 69 | * |
| 70 | * @param array $instance The widget options |
| 71 | * @return string|void |
| 72 | */ |
| 73 | public function form($instance) |
| 74 | { |
| 75 | // outputs the options form on admin |
| 76 | $title = !empty($instance['title']) ? $instance['title'] : __('New title', 'foogallery'); |
| 77 | $foogallery_id = !empty($instance['foogallery_id']) ? intval($instance['foogallery_id']) : 0; |
| 78 | $galleries = foogallery_get_all_galleries(); |
| 79 | ?> |
| 80 | <p> |
| 81 | <label for="<?php echo esc_attr( $this->get_field_id('title') ); ?>"><?php esc_html_e('Title:', 'foogallery'); ?></label> |
| 82 | <input class="widefat" id="<?php echo esc_attr( $this->get_field_id('title') ); ?>" |
| 83 | name="<?php echo esc_attr( $this->get_field_name('title') ); ?>" type="text" |
| 84 | value="<?php echo esc_attr($title); ?>"> |
| 85 | </p> |
| 86 | <p> |
| 87 | <label for="<?php echo esc_attr( $this->get_field_id('foogallery_id') ); ?>"><?php esc_html_e('Select Gallery:', 'foogallery'); ?></label> |
| 88 | <select class="widefat" id="<?php echo esc_attr( $this->get_field_id('foogallery_id') ); ?>" |
| 89 | name="<?php echo esc_attr( $this->get_field_name('foogallery_id') ); ?>" |
| 90 | value="<?php echo esc_attr($title); ?>"> |
| 91 | <?php foreach ( $galleries as $gallery ) {?> |
| 92 | <option <?php echo $gallery->ID == $foogallery_id ? 'selected="selected"' : ''; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?> value="<?php echo esc_attr( $gallery->ID ); ?>"><?php echo esc_html( $gallery->name . ' [' . $gallery->ID . ']' ); ?></option> |
| 93 | <?php } ?> |
| 94 | </select> |
| 95 | </p> |
| 96 | <?php |
| 97 | } |
| 98 | |
| 99 | |
| 100 | /** |
| 101 | * Processing widget options on save |
| 102 | * |
| 103 | * @param array $new_instance The new options |
| 104 | * @param array $old_instance The previous options |
| 105 | * @return array|mixed |
| 106 | */ |
| 107 | public function update($new_instance, $old_instance) |
| 108 | { |
| 109 | // processes widget options to be saved |
| 110 | foreach ($new_instance as $key => $value) { |
| 111 | $updated_instance[$key] = sanitize_text_field($value); |
| 112 | } |
| 113 | |
| 114 | return $updated_instance; |
| 115 | } |
| 116 | } |
| 117 | } |
| 118 |