PluginProbe ʕ •ᴥ•ʔ
Gallery : FooGallery / 3.2.6
Gallery : FooGallery v3.2.6
3.3.0 3.1.31 3.1.32 3.1.34 3.1.36 3.2.0 3.2.6 trunk 1.10.3 2.0.24 2.1.34 2.2.44 2.3.3 2.4.32 3.0.6 3.1.11 3.1.12 3.1.13 3.1.20 3.1.25 3.1.26 3.1.26.1 3.1.26.2
foogallery / includes / class-override-thumbnail.php
foogallery / includes Last commit date
abilities 4 weeks ago admin 4 weeks ago compatibility 4 weeks ago extensions 4 weeks ago foopluginbase 4 weeks ago public 4 weeks ago thumbs 4 weeks ago asset-manifest.php 4 weeks ago class-attachment-filters.php 4 weeks ago class-command-palette.php 4 weeks ago class-foogallery-animated-gif-support.php 4 weeks ago class-foogallery-attachment-custom-class.php 4 weeks ago class-foogallery-attachment-filename.php 4 weeks ago class-foogallery-attachment-type.php 4 weeks ago class-foogallery-attachment.php 4 weeks ago class-foogallery-cache.php 4 weeks ago class-foogallery-common-fields.php 4 weeks ago class-foogallery-crop-position.php 4 weeks ago class-foogallery-datasource-media_library.php 4 weeks ago class-foogallery-debug.php 4 weeks ago class-foogallery-delayed-runtime-loader.php 4 weeks ago class-foogallery-extensions-compatibility.php 4 weeks ago class-foogallery-force-https.php 4 weeks ago class-foogallery-lazyload.php 4 weeks ago class-foogallery-license-constant-handler.php 4 weeks ago class-foogallery-lightbox.php 4 weeks ago class-foogallery-paging.php 4 weeks ago class-foogallery-password-protect.php 4 weeks ago class-foogallery-sitemaps.php 4 weeks ago class-foogallery-widget.php 4 weeks ago class-foogallery.php 4 weeks ago class-gallery-advanced-settings.php 4 weeks ago class-il8n.php 4 weeks ago class-override-thumbnail.php 4 weeks ago class-posttypes.php 4 weeks ago class-previews.php 4 weeks ago class-retina.php 4 weeks ago class-thumbnail-dimensions.php 4 weeks ago class-thumbnails.php 4 weeks ago class-version-check.php 4 weeks ago constants.php 4 weeks ago functions.php 4 weeks ago gallery-management-functions.php 4 weeks ago includes.php 4 weeks ago index.php 4 weeks ago render-functions.php 4 weeks ago
class-override-thumbnail.php
149 lines
1 <?php
2
3 if ( ! defined( 'ABSPATH' ) ) {
4 exit;
5 }
6
7 /*
8 * FooGallery Attachment Override Thumbnail
9 */
10
11 if ( ! class_exists( 'FooGallery_Override_Thumbnail' ) ) {
12
13 class FooGallery_Override_Thumbnail {
14
15 /**
16 * Primary class constructor.
17 */
18 public function __construct() {
19 add_filter( 'foogallery_attachment_custom_fields', array( $this, 'foogallery_add_override_thumbnail_field' ) );
20 add_action( 'foogallery_attachment_modal_tab_content_thumbnails', array( $this, 'display_modal_fields' ), 10, 1 );
21 add_action( 'wp_ajax_foogallery_remove_alternate_img', array( $this, 'ajax_remove_override' ) );
22 add_action( 'foogallery_attachment_modal_after_tab_container', array( $this, 'extra_content_for_override_thumbnail' ), 50, 1 );
23 }
24
25 function display_modal_fields( $modal_data ) {
26 ?>
27 <div class="foogallery-attachments-list-bar">
28 <div class="settings">
29 <span class="setting override-thumbnail <?php echo esc_attr( $modal_data['override_class'] ); ?>" data-setting="override-thumbnail">
30 <label for="attachment-details-two-column-override-thumbnail" class="name"><?php esc_html_e('Alternate Thumbnail URL', 'foogallery'); ?></label>
31 <input type="text" id="attachments-foogallery-override-thumbnail" value="<?php echo esc_url( $modal_data['alternate_img_src'] ); ?>" readonly>
32 <input type="hidden" name="foogallery[override-thumbnail-id]" id="attachments-foogallery-override-thumbnail-id" value="<?php echo esc_attr( $modal_data['foogallery_override_thumbnail'] ); ?>">
33 </span>
34 <span class="setting override-thumbnail-preview <?php echo esc_attr( $modal_data['override_class'] ); ?>" data-setting="override-thumbnail-preview">
35 <label for="attachment-details-two-column-override-thumbnail-preview" class="name"><?php esc_html_e('Alternate Thumbnail Preview', 'foogallery'); ?></label>
36 <img id="attachment-details-two-column-override-thumbnail-preview" src="<?php echo esc_url( $modal_data['alternate_img_src'] ); ?>" alt="Alternate Thumbnail">
37 </span>
38 <span class="setting alternate-image-upload-settings" data-setting="alternate-image-upload">
39 <div class="alternate-image-upload-wrap">
40 <button type="button" class="button button-primary button-large" id="foogallery-img-modal-alternate-image-upload"
41 data-uploader-title="<?php esc_attr_e( 'Override Thumbnail Image', 'foogallery' ); ?>"
42 data-uploader-button-text="<?php esc_attr_e( 'Override Thumbnail Image', 'foogallery' ); ?>"
43 data-img-id="<?php echo esc_attr( $modal_data['img_id'] ); ?>">
44 <?php esc_html_e( 'Override Thumbnail Image', 'foogallery' ); ?>
45 </button>
46 <button type="button" class="button button-primary button-large <?php echo esc_attr( $modal_data['override_class'] ); ?>" id="foogallery-img-modal-alternate-image-delete"
47 data-uploader-title="<?php esc_attr_e( 'Clear Override Thumbnail', 'foogallery' ); ?>"
48 data-uploader-button-text="<?php esc_attr_e( 'Clear Override Thumbnail', 'foogallery' ); ?>"
49 data-img-id="<?php echo esc_attr( $modal_data['img_id'] ); ?>">
50 <?php esc_html_e( 'Clear Override Thumbnail', 'foogallery' ); ?>
51 </button>
52 <span id="foogallery_clear_alternate_img_spinner" class="spinner"></span>
53 </div>
54 </span>
55 </div>
56 </div>
57 <?php
58 }
59
60 /**
61 * Adds a custom field to the attachments for override thumbnail
62 *
63 * @param $fields array
64 *
65 * @return array
66 */
67 public function foogallery_add_override_thumbnail_field( $fields ) {
68 $fields['foogallery_override_thumbnail'] = array(
69 'label' => __( 'Override Thumbnail', 'foogallery' ),
70 'input' => 'text',
71 'helps' => __( 'Add another image to override this attachment', 'foogallery' ),
72 );
73
74 return $fields;
75 }
76
77 /**
78 * Ajax function to remove override thumbnail from the attachment
79 */
80 public function ajax_remove_override() {
81
82 if ( ! check_ajax_referer( 'foogallery-modal-nonce', 'nonce', false ) ) {
83 wp_send_json_error(
84 array( 'message' => __( 'Invalid security token.', 'foogallery' ) ),
85 403
86 );
87 }
88
89 $img_id = isset( $_POST['img_id'] ) ? absint( wp_unslash( $_POST['img_id'] ) ) : 0;
90
91 if ( ! $img_id ) {
92 wp_send_json_error(
93 array( 'message' => __( 'Invalid attachment data.', 'foogallery' ) ),
94 400
95 );
96 }
97
98 if ( ! current_user_can( 'edit_post', $img_id ) ) {
99 wp_send_json_error(
100 array( 'message' => __( 'Insufficient permissions.', 'foogallery' ) ),
101 403
102 );
103 }
104
105 delete_post_meta( $img_id, '_foogallery_override_thumbnail' );
106
107 wp_send_json_success();
108 }
109
110 public function extra_content_for_override_thumbnail( $modal_data ) {
111 ?>
112 <script>
113 jQuery( function() {
114 $(document).on('click', '#foogallery-img-modal-alternate-image-upload', function(e) {
115 e.preventDefault();
116 $('#foogallery-image-edit-modal').data('img_type', 'alternate');
117 FOOGALLERY.mediaModalTitle = $(this).data( 'uploader-title' );
118 FOOGALLERY.mediaModalButtonText = $(this).data( 'uploader-button-text' );
119 var img_id = $(this).data('img-id');
120 FOOGALLERY.openMediaModal(img_id);
121 });
122
123 $(document).on('click', '#foogallery-img-modal-alternate-image-delete', function () {
124 $('#foogallery_clear_alternate_img_spinner').addClass('is-active');
125 var img_id = $(this).attr('data-img-id');
126 var nonce = $('#foogallery-panel-main').data('nonce');
127 $.ajax({
128 type: "POST",
129 url: ajaxurl,
130 data: {
131 'action': 'foogallery_remove_alternate_img',
132 'img_id': img_id,
133 'nonce': nonce
134 },
135 success: function (data) {
136 $('#foogallery_clear_alternate_img_spinner').removeClass('is-active');
137 $('#foogallery-image-edit-modal .tab-panels .settings span.setting.override-thumbnail').removeClass('is-override-thumbnail');
138 $('#foogallery-image-edit-modal .tab-panels .settings span.setting.override-thumbnail-preview').removeClass('is-override-thumbnail');
139 $('#foogallery-image-edit-modal .tab-panels .settings span.setting.alternate-image-delete').removeClass('is-override-thumbnail');
140 }
141 });
142 });
143 });
144 </script>
145 <?php
146 }
147 }
148 }
149