Version Description
Download this release
Release Info
Developer | navzme |
Plugin | ACF Photo Gallery Field |
Version | 1.6.3 |
Comparing to | |
See all releases |
Code changes from version 1.6.2 to 1.6.3
- assets/css/acf-photo-gallery-field.css +75 -0
- assets/js/acf-photo-gallery-field.js +247 -0
- fields/acf-photo_gallery-v4.php +68 -307
- fields/acf-photo_gallery-v5.php +105 -0
- includes/__construct.php +19 -0
- includes/acf_photo_gallery.php +41 -0
- includes/acf_photo_gallery_edit.php +11 -0
- includes/acf_photo_gallery_edit_save.php +46 -0
- includes/acf_photo_gallery_image_fields.php +10 -0
- includes/acf_photo_gallery_metabox_edit.php +23 -0
- includes/acf_photo_gallery_remove_photo.php +30 -0
- includes/acf_photo_gallery_resize_image.php +14 -0
- includes/acf_photo_gallery_save.php +31 -0
- includes/aq_resizer.php +246 -0
- includes/index.php +2 -0
- includes/input_admin_enqueue_scripts.php +14 -0
- includes/render_field.php +60 -0
- includes/v4/create_options.php +20 -0
- includes/v4/index.php +2 -0
- includes/v5/index.php +2 -0
- includes/v5/render_field_settings.php +21 -0
- navz-photo-gallery.php +93 -136
- readme.txt +37 -8
assets/css/acf-photo-gallery-field.css
ADDED
@@ -0,0 +1,75 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
.acf-photo-gallery-metabox-list li {
|
2 |
+
display: inline-table;
|
3 |
+
padding: 3px;
|
4 |
+
border: 1px solid #ccc;
|
5 |
+
margin: 8px;
|
6 |
+
position: relative;
|
7 |
+
vertical-align: top;
|
8 |
+
width: 202px;
|
9 |
+
height: 202px;
|
10 |
+
}
|
11 |
+
|
12 |
+
.acf-photo-gallery-metabox-list li img {
|
13 |
+
width: 100%;
|
14 |
+
}
|
15 |
+
|
16 |
+
.acf-photo-gallery-metabox-list .acf-photo-gallery-media-box-placeholder {
|
17 |
+
width: 150px;
|
18 |
+
height: 150px;
|
19 |
+
border: 1px dashed #ccc;
|
20 |
+
}
|
21 |
+
|
22 |
+
.acf-photo-gallery-metabox-list .acf-photo-gallery-media-box-placeholder .dashicons-format-image {
|
23 |
+
font-size: 150px;
|
24 |
+
color: #ccc;
|
25 |
+
}
|
26 |
+
|
27 |
+
.acf-photo-gallery-metabox-list li .dashicons-dismiss {
|
28 |
+
position: absolute;
|
29 |
+
top: -9px;
|
30 |
+
right: -9px;
|
31 |
+
color: #fff;
|
32 |
+
background: #000000;
|
33 |
+
border-radius: 50%;
|
34 |
+
}
|
35 |
+
|
36 |
+
.acf-photo-gallery-metabox-list li .dashicons-edit {
|
37 |
+
position: absolute;
|
38 |
+
top: -9px;
|
39 |
+
right: 12px;
|
40 |
+
color: #fff;
|
41 |
+
background: #000000;
|
42 |
+
border-radius: 50%;
|
43 |
+
}
|
44 |
+
|
45 |
+
#acf-photo-gallery-metabox-edit .acf-edit-photo-gallery {
|
46 |
+
display: none;
|
47 |
+
background: #F3F3F3;
|
48 |
+
border: 2px solid #ccc;
|
49 |
+
width: 308px;
|
50 |
+
position: absolute;
|
51 |
+
top: 0px;
|
52 |
+
right: 0;
|
53 |
+
z-index: 9999;
|
54 |
+
padding: 15px;
|
55 |
+
}
|
56 |
+
|
57 |
+
#acf-photo-gallery-metabox-edit .acf-edit-photo-gallery .save-changes-wrap {
|
58 |
+
margin-top: 15px;
|
59 |
+
}
|
60 |
+
|
61 |
+
#acf-photo-gallery-metabox-edit .acf-edit-photo-gallery label {
|
62 |
+
margin-top: 10px;
|
63 |
+
display: block;
|
64 |
+
}
|
65 |
+
|
66 |
+
#acf-photo-gallery-metabox-edit .acf-edit-photo-gallery textarea {
|
67 |
+
min-height: 100px
|
68 |
+
}
|
69 |
+
|
70 |
+
.acf-photo-gallery-metabox-list li.acf-photo-gallery-sortable-placeholder {
|
71 |
+
border: 1px dashed #ccc;
|
72 |
+
width: 150px;
|
73 |
+
height: 150px;
|
74 |
+
display: inline-block;
|
75 |
+
}
|
assets/js/acf-photo-gallery-field.js
ADDED
@@ -0,0 +1,247 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
(function($) {
|
2 |
+
|
3 |
+
function initialize_field($el) {
|
4 |
+
//$el.doStuff();
|
5 |
+
}
|
6 |
+
|
7 |
+
function acf_photo_gallery_remove_media($btn) {
|
8 |
+
var url = $btn.attr('href');
|
9 |
+
var id = $btn.attr('data-id');
|
10 |
+
var field = $btn.attr('data-field');
|
11 |
+
|
12 |
+
var JsonField = jQuery.parseJSON(field);
|
13 |
+
$('.acf-photo-gallery-group-' + JsonField.key + ' .acf-photo-gallery-mediabox-' + id).fadeOut('fast').remove();
|
14 |
+
if( $('.acf-photo-gallery-group-' + JsonField.key + ' .acf-photo-gallery-metabox-list li').length < 1 ){
|
15 |
+
$('.acf-photo-gallery-group-' + JsonField.key + ' .acf-photo-gallery-metabox-list').append('<li class="acf-photo-gallery-media-box-placeholder"><span class="dashicons dashicons-format-image"></span></li>');
|
16 |
+
}
|
17 |
+
|
18 |
+
/*$.get(url, function() {
|
19 |
+
console.log( JsonField.key );
|
20 |
+
|
21 |
+
$('.acf-photo-gallery-group-' + JsonField.key + ' .acf-photo-gallery-mediabox-' + id).fadeOut('fast').remove();
|
22 |
+
if( $('.acf-photo-gallery-group-' + JsonField.key + ' .acf-photo-gallery-metabox-list li').length < 1 ){
|
23 |
+
$('.acf-photo-gallery-group-' + JsonField.key + ' .acf-photo-gallery-metabox-list').append('<li class="acf-photo-gallery-media-box-placeholder"><span class="dashicons dashicons-format-image"></span></li>');
|
24 |
+
}
|
25 |
+
});*/
|
26 |
+
|
27 |
+
}
|
28 |
+
|
29 |
+
$(document).ready(function() {
|
30 |
+
$(".acf-photo-gallery-metabox-list").sortable({
|
31 |
+
containment: "parent",
|
32 |
+
placeholder: "acf-photo-gallery-sortable-placeholder",
|
33 |
+
tolerance: 'pointer'
|
34 |
+
}).disableSelection();
|
35 |
+
});
|
36 |
+
|
37 |
+
function acf_photo_gallery_edit(id, url, title, caption) {
|
38 |
+
var html;
|
39 |
+
html = '<div id="acf-photo-gallery-metabox-edit-' + id + '" class="acf-edit-photo-gallery">';
|
40 |
+
html += '<h3>Edit Image</h3>';
|
41 |
+
html += '<label>URL</label><input type="text" value="' + url + '"/>';
|
42 |
+
html += '<label><input type="checkbox" value="1"/>Open in new tab</label>';
|
43 |
+
html += '<label>Title</label><input type="text" value="' + title + '"/>';
|
44 |
+
html += '<label>Caption</label><textarea>' + caption + '</textarea>';
|
45 |
+
html += '<button class="button button-primary button-large" type="button">Save Changes</button>';
|
46 |
+
html += '<button class="button button-large button-close" type="button" data-close="' + id + '">Close</button>';
|
47 |
+
html += '</div>';
|
48 |
+
return html;
|
49 |
+
}
|
50 |
+
|
51 |
+
/**
|
52 |
+
* @param {{ index: number, splice: number }} options
|
53 |
+
*/
|
54 |
+
function acf_photo_gallery_html(attachment, field, options) {
|
55 |
+
var html, id, url, title, caption;
|
56 |
+
id = attachment.id;
|
57 |
+
url = attachment.url;
|
58 |
+
title = attachment.title;
|
59 |
+
caption = attachment.caption;
|
60 |
+
|
61 |
+
var JsonField = jQuery.parseJSON(field);
|
62 |
+
|
63 |
+
if (typeof attachment.sizes.thumbnail != 'undefined') { url = attachment.sizes.thumbnail.url; }
|
64 |
+
|
65 |
+
html = acf_photo_gallery_edit(id, url, title, caption);
|
66 |
+
$('.acf-photo-gallery-group-' + JsonField.key + ' .acf-photo-gallery-metabox-edit').append(html);
|
67 |
+
var $list = $('.acf-photo-gallery-group-' + JsonField.key + ' .acf-photo-gallery-metabox-list');
|
68 |
+
html = '<li id="acf-photo-gallery-mediabox-' + id + '" data-id="' + id + '"><a class="dashicons dashicons-edit" href="#" title="Edit" data-id="' + id + '"></a><a class="dashicons dashicons-dismiss" href="#" data-id="' + id + '" data-field="' + field + '" title="Remove this photo from the gallery"></a><input type="hidden" name="' + JsonField._name + '[]" value="' + id + '"/><img src="' + url + '"/></li>';
|
69 |
+
if (options.index) {
|
70 |
+
var $cursor = $list.children().eq(options.index);
|
71 |
+
$cursor.before(html);
|
72 |
+
if (options.splice) { $cursor.remove(); }
|
73 |
+
} else {
|
74 |
+
$list.prepend(html);
|
75 |
+
}
|
76 |
+
}
|
77 |
+
|
78 |
+
function acf_photo_gallery_add_media($el) {
|
79 |
+
var acf_photo_gallery_ids = new Array();
|
80 |
+
if ($('.acf-photo-gallery-metabox-add-images').length > 0) {
|
81 |
+
if (typeof wp !== 'undefined' && wp.media && wp.media.editor) {
|
82 |
+
$(document).on('click', '.acf-photo-gallery-metabox-add-images', function(e) {
|
83 |
+
e.preventDefault();
|
84 |
+
var button = $(this);
|
85 |
+
var id = button.prev();
|
86 |
+
var field = button.attr('data-field');
|
87 |
+
var JsonField = jQuery.parseJSON(field);
|
88 |
+
|
89 |
+
var pre_selected_list = $('.acf-photo-gallery-group-' + JsonField.key + ' .acf-photo-gallery-metabox-list li');
|
90 |
+
var pre_selected = pre_selected_list.length;
|
91 |
+
|
92 |
+
wp.media.editor.send.attachment = function(props, attachment){
|
93 |
+
acf_photo_gallery_html(attachment, field, { index: 0, splice: 0 });
|
94 |
+
};
|
95 |
+
|
96 |
+
wp.media.editor.open( button, function(){} );
|
97 |
+
if ($('.acf-photo-gallery-group-' + JsonField.key + ' .acf-photo-gallery-metabox-list li.acf-photo-gallery-media-box-placeholder').length > 0) {
|
98 |
+
$('.acf-photo-gallery-group-' + JsonField.key + ' .acf-photo-gallery-metabox-list li.acf-photo-gallery-media-box-placeholder').remove();
|
99 |
+
}
|
100 |
+
|
101 |
+
return false;
|
102 |
+
});
|
103 |
+
}
|
104 |
+
};
|
105 |
+
}
|
106 |
+
|
107 |
+
$(document).on('click', '.acf-photo-gallery-metabox-list .dashicons-dismiss', function() {
|
108 |
+
if (confirm('You are about to remove this photo from the gallery. Are you sure?')) {
|
109 |
+
acf_photo_gallery_remove_media($(this));
|
110 |
+
}
|
111 |
+
return false;
|
112 |
+
});
|
113 |
+
|
114 |
+
$(document).on('click', '#acf-photo-gallery-metabox-edit .acf-edit-photo-gallery button.button-close', function() {
|
115 |
+
var id;
|
116 |
+
id = $(this).attr('data-close');
|
117 |
+
$('#acf-photo-gallery-metabox-edit #acf-photo-gallery-metabox-edit-' + id).fadeOut('fast');
|
118 |
+
return false;
|
119 |
+
});
|
120 |
+
|
121 |
+
$(document).on('click', '#acf-photo-gallery-metabox-edit .acf-edit-photo-gallery button.button-primary', function() {
|
122 |
+
var button, field, data, post, attachment, action, nonce, form = {};
|
123 |
+
url = $(this).attr('data-ajaxurl');
|
124 |
+
action = 'acf_photo_gallery_edit_save';
|
125 |
+
attachment = $(this).attr('data-id');
|
126 |
+
|
127 |
+
$('#acf-photo-gallery-metabox-edit-' + attachment + ' .acf-photo-gallery-edit-field').each(function(i, obj) {
|
128 |
+
if (obj.name == 'acf-pg-hidden-action') {
|
129 |
+
form['action'] = obj.value;
|
130 |
+
} else if( obj.type == 'checkbox'){
|
131 |
+
if( $(this).prop("checked") ){
|
132 |
+
form[obj.name] = obj.value;
|
133 |
+
} else {
|
134 |
+
form[obj.name] = null;
|
135 |
+
}
|
136 |
+
} else {
|
137 |
+
form[obj.name] = obj.value;
|
138 |
+
}
|
139 |
+
});
|
140 |
+
|
141 |
+
button = $(this);
|
142 |
+
button.attr('disabled', true).html('Saving...');
|
143 |
+
$.post(url, form, function(data) {
|
144 |
+
button.attr('disabled', false).html('Save Changes');
|
145 |
+
$('#acf-photo-gallery-metabox-edit #acf-photo-gallery-metabox-edit-' + attachment).fadeOut('fast');
|
146 |
+
});
|
147 |
+
return false;
|
148 |
+
});
|
149 |
+
|
150 |
+
$(document).on('click', '.acf-photo-gallery-metabox-list .dashicons-edit', function() {
|
151 |
+
var $btn = $(this);
|
152 |
+
var id = $btn.attr('data-id');
|
153 |
+
var field = $btn.attr('data-field');
|
154 |
+
var modal = $('.acf-photo-gallery-group-' + field + ' input[name="acf-photo-gallery-edit-modal"]').val();
|
155 |
+
var $list = $('.acf-photo-gallery-group-' + field + ' ul.acf-photo-gallery-metabox-list');
|
156 |
+
var index = $('.acf-photo-gallery-group-' + field + ' ul.acf-photo-gallery-metabox-list li').index();
|
157 |
+
|
158 |
+
if (modal === 'Native') {
|
159 |
+
wp.media.editor.send.attachment = function(_, attachment){
|
160 |
+
acf_photo_gallery_html(attachment, field, {
|
161 |
+
index: index,
|
162 |
+
splice: 1
|
163 |
+
});
|
164 |
+
};
|
165 |
+
|
166 |
+
var editor = wp.media.editor.open($btn, function() {}).state();
|
167 |
+
editor.set('menu', false);
|
168 |
+
|
169 |
+
var selection = editor.get('selection');
|
170 |
+
selection.multiple = false;
|
171 |
+
selection.reset([wp.media.attachment(id)]);
|
172 |
+
|
173 |
+
/**
|
174 |
+
* @param {{ id: number }} deleted
|
175 |
+
*/
|
176 |
+
var handleDestroy = function (deleted) {
|
177 |
+
$list.children().each(function () {
|
178 |
+
var $elem = $(this);
|
179 |
+
|
180 |
+
if ($elem.data('id') === deleted.id) {
|
181 |
+
remove($elem.find('.dashicons-dismiss'));
|
182 |
+
}
|
183 |
+
});
|
184 |
+
};
|
185 |
+
|
186 |
+
var library = editor.get('library');
|
187 |
+
library.on('destroy', handleDestroy);
|
188 |
+
|
189 |
+
editor.on('close', function () {
|
190 |
+
library.off('destroy', handleDestroy);
|
191 |
+
});
|
192 |
+
|
193 |
+
$('.acf-photo-gallery-group-' + field + ' .acf-photo-gallery-metabox-list li.acf-photo-gallery-media-box-placeholder').remove();
|
194 |
+
} else {
|
195 |
+
$('.acf-photo-gallery-group-' + field + ' #acf-photo-gallery-metabox-edit-' + id).fadeToggle('fast');
|
196 |
+
}
|
197 |
+
|
198 |
+
return false;
|
199 |
+
});
|
200 |
+
|
201 |
+
if (typeof acf.add_action !== 'undefined') {
|
202 |
+
/*
|
203 |
+
* ready append (ACF5)
|
204 |
+
*
|
205 |
+
* These are 2 events which are fired during the page load
|
206 |
+
* ready = on page load similar to $(document).ready()
|
207 |
+
* append = on new DOM elements appended via repeater field
|
208 |
+
*
|
209 |
+
* @type event
|
210 |
+
* @date 20/07/13
|
211 |
+
*
|
212 |
+
* @param $el (jQuery selection) the jQuery element which contains the ACF fields
|
213 |
+
* @return n/a
|
214 |
+
*/
|
215 |
+
acf.add_action('ready append', function($el) {
|
216 |
+
// search $el for fields of type 'photo_gallery'
|
217 |
+
acf.get_fields({ type: 'photo_gallery' }, $el).each(function() {
|
218 |
+
initialize_field($(this));
|
219 |
+
acf_photo_gallery_add_media( $(this) );
|
220 |
+
});
|
221 |
+
});
|
222 |
+
} else {
|
223 |
+
/*
|
224 |
+
* acf/setup_fields (ACF4)
|
225 |
+
*
|
226 |
+
* This event is triggered when ACF adds any new elements to the DOM.
|
227 |
+
*
|
228 |
+
* @type function
|
229 |
+
* @since 1.0.0
|
230 |
+
* @date 01/01/12
|
231 |
+
*
|
232 |
+
* @param event e: an event object. This can be ignored
|
233 |
+
* @param Element postbox: An element which contains the new HTML
|
234 |
+
*
|
235 |
+
* @return n/a
|
236 |
+
*/
|
237 |
+
$(document).on('acf/setup_fields', function(e, postbox) {
|
238 |
+
$(postbox).find('.field[data-field_type="photo_gallery"]').each(function() {
|
239 |
+
initialize_field($(this));
|
240 |
+
acf_photo_gallery_add_media( $(this) );
|
241 |
+
//acf_photo_gallery_edit_popover( $(this) );
|
242 |
+
//acf_photo_gallery_limit_images( $(this) );
|
243 |
+
});
|
244 |
+
});
|
245 |
+
}
|
246 |
+
|
247 |
+
})(jQuery);
|
fields/acf-photo_gallery-v4.php
CHANGED
@@ -3,339 +3,100 @@
|
|
3 |
// exit if accessed directly
|
4 |
if( ! defined( 'ABSPATH' ) ) exit;
|
5 |
|
6 |
-
|
7 |
-
function acf_photo_gallery_save( $post_id ){
|
8 |
-
// If this is a revision, get real post ID
|
9 |
-
if ( $parent_id = wp_is_post_revision( $post_id ) )
|
10 |
-
$post_id = $parent_id;
|
11 |
-
// unhook this function so it doesn't loop infinitely
|
12 |
-
remove_action( 'save_post', 'acf_photo_gallery_save' );
|
13 |
|
14 |
-
|
15 |
-
|
16 |
-
foreach($field as $k => $v ){
|
17 |
-
$field_id = isset($_POST['acf-photo-gallery-field-id'][$k])? $_POST['acf-photo-gallery-field-id'][$k]: null;
|
18 |
-
if( !empty($field_id) ){
|
19 |
-
$ids = !empty($field) && isset($_POST[$field_id])? $_POST[$field_id]: null;
|
20 |
-
if( !empty($ids) ){
|
21 |
-
$ids = implode(',', $ids);
|
22 |
-
update_post_meta( $post_id, $field_id, $ids );
|
23 |
-
}
|
24 |
-
}
|
25 |
-
}
|
26 |
-
}
|
27 |
-
// re-hook this function
|
28 |
-
add_action( 'save_post', 'acf_photo_gallery_save' );
|
29 |
-
}
|
30 |
-
add_action( 'save_post', 'acf_photo_gallery_save' );
|
31 |
|
32 |
//Remove photo from the database array
|
33 |
-
|
34 |
-
if( wp_verify_nonce( $_GET['_wpnonce'], 'nonce_acf_photo_gallery') and !empty($_GET['post']) and !empty($_GET['photo']) and !empty($_GET['field']) ){
|
35 |
-
$field = $_GET['field'];
|
36 |
-
$post = $_GET['post'];
|
37 |
-
$photo = $_GET['photo'];
|
38 |
-
$photo = preg_replace('/\D/', '', $photo);
|
39 |
-
$id = str_replace('acf-field-', '', $_GET['id']);
|
40 |
-
$meta = get_post_meta($post, $id, true);
|
41 |
-
$meta_arr = explode(',', $meta);
|
42 |
-
if( in_array($photo, $meta_arr) ){
|
43 |
-
foreach($meta_arr as $key => $value){
|
44 |
-
if( $photo == $value ){
|
45 |
-
unset($meta_arr[$key]);
|
46 |
-
if( count($meta_arr) > 0 ){
|
47 |
-
$meta_arr = implode(',', $meta_arr);
|
48 |
-
update_post_meta( $post, $id, $meta_arr );
|
49 |
-
} else {
|
50 |
-
delete_post_meta( $post, $id );
|
51 |
-
}
|
52 |
-
}
|
53 |
-
}
|
54 |
-
}
|
55 |
-
}
|
56 |
-
die();
|
57 |
-
}
|
58 |
-
add_action( 'wp_ajax_nopriv_acf_photo_gallery_remove_photo', 'acf_photo_gallery_remove_photo' );
|
59 |
-
add_action( 'wp_ajax_acf_photo_gallery_remove_photo', 'acf_photo_gallery_remove_photo' );
|
60 |
|
61 |
//Editing and saving photo details
|
62 |
-
|
63 |
-
|
64 |
-
if( wp_verify_nonce( $_POST['acf-pg-hidden-nonce'], 'acf_photo_gallery_edit_save') and !empty($_POST['acf-pg-hidden-field']) and !empty($_POST['acf-pg-hidden-post']) and !empty($_POST['acf-pg-hidden-attachment']) ){
|
65 |
-
|
66 |
-
$request = $_POST;
|
67 |
-
|
68 |
-
$field = sanitize_text_field($_POST['acf-pg-hidden-field']);
|
69 |
-
$post = sanitize_text_field($_POST['acf-pg-hidden-post']);
|
70 |
-
$attachment = sanitize_text_field($_POST['acf-pg-hidden-attachment']);
|
71 |
-
$title = sanitize_text_field($_POST['title']);
|
72 |
-
$caption = sanitize_text_field($_POST['caption']);
|
73 |
-
|
74 |
-
unset( $request['acf-pg-hidden-field'] );
|
75 |
-
unset( $request['acf-pg-hidden-post'] );
|
76 |
-
unset( $request['acf-pg-hidden-attachment'] );
|
77 |
-
unset( $request['action'] );
|
78 |
-
unset( $request['acf-pg-hidden-nonce'] );
|
79 |
-
unset( $request['title'] );
|
80 |
-
unset( $request['caption'] );
|
81 |
-
|
82 |
-
$acf_photo_gallery_editbox_caption_from_attachment = apply_filters( 'acf_photo_gallery_editbox_caption_from_attachment', $request);
|
83 |
-
if( $acf_photo_gallery_editbox_caption_from_attachment == 1 ){
|
84 |
-
$captionColumn = 'post_excerpt';
|
85 |
-
} else {
|
86 |
-
$captionColumn = 'post_content';
|
87 |
-
}
|
88 |
-
|
89 |
-
$post = array('ID' => $attachment, 'post_title' => $title, $captionColumn => $caption);
|
90 |
-
wp_update_post( $post );
|
91 |
-
|
92 |
-
foreach( $request as $name => $value ){
|
93 |
-
$name = sanitize_text_field( $name );
|
94 |
-
$value = sanitize_text_field( $value );
|
95 |
-
if( !empty($value) ){
|
96 |
-
update_post_meta( $attachment, $field . '_' . $name, $value);
|
97 |
-
} else {
|
98 |
-
delete_post_meta( $attachment, $field . '_' . $name);
|
99 |
-
}
|
100 |
-
}
|
101 |
-
}
|
102 |
-
die();
|
103 |
-
}
|
104 |
-
add_action( 'wp_ajax_nopriv_acf_photo_gallery_edit_save', 'acf_photo_gallery_edit_save' );
|
105 |
-
add_action( 'wp_ajax_acf_photo_gallery_edit_save', 'acf_photo_gallery_edit_save' );
|
106 |
-
|
107 |
-
//Metabox for the photo edit
|
108 |
-
function acf_photo_gallery_edit($field, $nonce, $attachment, $url = '', $title, $caption, $target = 0){
|
109 |
-
$args = array();
|
110 |
-
$args['url'] = $url;
|
111 |
-
$args['title'] = $title;
|
112 |
-
$args['caption'] = $caption;
|
113 |
-
$args['target'] = $target;
|
114 |
-
$filter_fields = apply_filters( 'acf_photo_gallery_image_fields', $args, $attachment, $field );
|
115 |
-
?>
|
116 |
-
<div id="acf-photo-gallery-metabox-edit-<?php echo $attachment; ?>" class="acf-edit-photo-gallery">
|
117 |
-
<h3>Edit Image</h3>
|
118 |
-
<input class="acf-photo-gallery-edit-field" type="hidden" name="acf-pg-hidden-field" value="<?php echo $field; ?>"/>
|
119 |
-
<input class="acf-photo-gallery-edit-field" type="hidden" name="acf-pg-hidden-post" value="<?php echo $_GET['post']; ?>"/>
|
120 |
-
<input class="acf-photo-gallery-edit-field" type="hidden" name="acf-pg-hidden-attachment" value="<?php echo $attachment; ?>"/>
|
121 |
-
<input class="acf-photo-gallery-edit-field" type="hidden" name="acf-pg-hidden-action" value="acf_photo_gallery_edit_save"/>
|
122 |
-
<input class="acf-photo-gallery-edit-field" type="hidden" name="acf-pg-hidden-nonce" value="<?php echo $nonce; ?>"/>
|
123 |
-
<?php
|
124 |
-
foreach( $filter_fields as $key => $item ){
|
125 |
-
$type = ($item['type'])?$item['type']:null;
|
126 |
-
$label = $item['label']?$item['label']:null;
|
127 |
-
$name = $item['name']?$item['name']:null;
|
128 |
-
$value = $item['value']?$item['value']:null;
|
129 |
-
?>
|
130 |
-
<?php if( $type == 'text' ){ ?>
|
131 |
-
<label><?php echo $label; ?></label><input class="acf-photo-gallery-edit-field" type="<?php echo $type; ?>" name="<?php echo $name; ?>" value="<?php echo $value; ?>"/>
|
132 |
-
<?php } else if( $type == 'checkbox' ){ ?>
|
133 |
-
<label><input class="acf-photo-gallery-edit-field" type="checkbox" name="target" value="<?php echo $value; ?>" <?php if( $target == 'true' ){?> checked<?php } ?>/><?php echo $label; ?></label>
|
134 |
-
<?php } else if( $type == 'textarea' ){ ?>
|
135 |
-
<label><?php echo $label; ?></label><textarea class="acf-photo-gallery-edit-field" name="<?php echo $name; ?>"><?php echo $value; ?></textarea>
|
136 |
-
<?php } ?>
|
137 |
-
<?php } ?>
|
138 |
-
<div class="save-changes-wrap">
|
139 |
-
<button class="button button-primary button-large" type="submit" data-id="<?php echo $attachment; ?>">Save Changes</button>
|
140 |
-
<button class="button button-large button-close" type="button" data-close="<?php echo $attachment; ?>">Close</button>
|
141 |
-
</div>
|
142 |
-
</div>
|
143 |
-
<?php }
|
144 |
|
145 |
// check if class already exists
|
146 |
if( !class_exists('acf_field_photo_gallery') ) :
|
147 |
|
148 |
-
class acf_field_photo_gallery extends acf_field {
|
149 |
-
|
150 |
-
// vars
|
151 |
-
var $settings, // will hold info such as dir / path
|
152 |
-
$defaults; // will hold default field options
|
153 |
|
154 |
-
|
155 |
-
/*
|
156 |
-
* __construct
|
157 |
-
*
|
158 |
-
* Set name / label needed for actions / filters
|
159 |
-
*
|
160 |
-
* @since 3.6
|
161 |
-
* @date 23/01/13
|
162 |
-
*/
|
163 |
-
|
164 |
-
function __construct( $settings )
|
165 |
-
{
|
166 |
// vars
|
167 |
-
$
|
168 |
-
|
169 |
-
$this->category = __("Content",'acf'); // Basic, Content, Choice, etc
|
170 |
-
$this->defaults = array(
|
171 |
-
// add default here to merge into your field.
|
172 |
-
// This makes life easy when creating the field options as you don't need to use any if( isset('') ) logic. eg:
|
173 |
-
//'preview_size' => 'thumbnail'
|
174 |
-
);
|
175 |
-
|
176 |
-
|
177 |
-
// do not delete!
|
178 |
-
parent::__construct();
|
179 |
-
|
180 |
|
181 |
-
// settings
|
182 |
-
$this->settings = $settings;
|
183 |
|
184 |
-
}
|
185 |
-
|
186 |
-
|
187 |
-
/*
|
188 |
-
* create_options()
|
189 |
-
*
|
190 |
-
* Create extra options for your field. This is rendered when editing a field.
|
191 |
-
* The value of $field['name'] can be used (like below) to save extra data to the $field
|
192 |
-
*
|
193 |
-
* @type action
|
194 |
-
* @since 3.6
|
195 |
-
* @date 23/01/13
|
196 |
-
*
|
197 |
-
* @param $field - an array holding all the field's data
|
198 |
-
*/
|
199 |
-
|
200 |
-
function test_create_options( $field ){
|
201 |
-
// defaults?
|
202 |
/*
|
203 |
-
|
|
|
|
|
|
|
|
|
|
|
204 |
*/
|
205 |
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
?>
|
211 |
-
<tr class="field_option field_option_<?php echo $this->name; ?>">
|
212 |
-
<td class="label">
|
213 |
-
<label><?php _e("Max",'acf'); ?></label>
|
214 |
-
<p class="description"><?php _e("Leave it empty for no limit",'acf'); ?></p>
|
215 |
-
</td>
|
216 |
-
<td>
|
217 |
-
<?php
|
218 |
-
do_action('acf/create_field', array(
|
219 |
-
'type' => 'number',
|
220 |
-
'name' => 'fields['.$key.'][max]',
|
221 |
-
'value' => !empty($field['max'])? preg_replace('/\D/', '', $field['max']):'',
|
222 |
-
'layout' => 'horizontal'
|
223 |
-
));
|
224 |
-
?>
|
225 |
-
</td>
|
226 |
-
</tr>
|
227 |
-
<?php }
|
228 |
-
|
229 |
-
/*
|
230 |
-
* create_field()
|
231 |
-
*
|
232 |
-
* Create the HTML interface for your field
|
233 |
-
*
|
234 |
-
* @param $field - an array holding all the field's data
|
235 |
-
*
|
236 |
-
* @type action
|
237 |
-
* @since 3.6
|
238 |
-
* @date 23/01/13
|
239 |
-
*/
|
240 |
-
|
241 |
-
function create_field( $field )
|
242 |
-
{
|
243 |
-
// create Field HTML
|
244 |
-
global $post;
|
245 |
-
$nonce_acf_photo_gallery = wp_create_nonce( 'nonce_acf_photo_gallery' );
|
246 |
-
$_name = get_post_meta($post->ID, str_replace('acf-field-', '', $field['id']), true );
|
247 |
-
?>
|
248 |
-
<div id="acf-photo-gallery-metabox">
|
249 |
-
<input type="hidden" name="acf-photo-gallery-field" value="<?php echo $field['key']; ?>"/>
|
250 |
-
<input type="hidden" name="acf-photo-gallery-field-id[]" value="<?php echo str_replace('acf-field-', '', $field['id']); ?>"/>
|
251 |
-
<!---<input type="hidden" name="acf-photo-gallery-field-max" value="<?php //echo $field['max']; ?>"/>-->
|
252 |
-
<div id="acf-photo-gallery-metabox-edit">
|
253 |
-
<?php
|
254 |
-
if( $_name ):
|
255 |
-
$acf_photo_gallery_editbox_caption_from_attachment = apply_filters( 'acf_photo_gallery_editbox_caption_from_attachment', $field);
|
256 |
-
$acf_photo_gallery_attachments = $_name;
|
257 |
-
$acf_photo_gallery_attachments = explode(',', $acf_photo_gallery_attachments);
|
258 |
-
$args = array( 'post_type' => 'attachment', 'posts_per_page' => -1, 'post__in' => $acf_photo_gallery_attachments );
|
259 |
-
$acf_photo_gallery_attachments = get_posts( $args );
|
260 |
-
$nonce = wp_create_nonce('acf_photo_gallery_edit_save');
|
261 |
-
foreach($acf_photo_gallery_attachments as $attachment):
|
262 |
-
$id = $attachment->ID;
|
263 |
-
$url = get_post_meta($id, $field['_name'] . '_url', true);
|
264 |
-
$target = get_post_meta($id, $field['_name'] . '_target', true);
|
265 |
-
$title = $attachment->post_title;
|
266 |
-
if( $acf_photo_gallery_editbox_caption_from_attachment == 1 ){
|
267 |
-
$caption = wp_get_attachment_caption( $id );
|
268 |
-
} else {
|
269 |
-
$caption = $attachment->post_content;
|
270 |
-
}
|
271 |
-
acf_photo_gallery_edit($field['_name'], $nonce, $id, $url, $title, $caption, $target);
|
272 |
-
endforeach;
|
273 |
-
endif;
|
274 |
-
?>
|
275 |
-
</div>
|
276 |
-
<ul id="acf-photo-gallery-metabox-list" class="acf-photo-gallery-metabox-list">
|
277 |
-
<?php
|
278 |
-
if( $_name ):
|
279 |
-
$acf_photo_gallery_attachments = $_name;
|
280 |
-
$acf_photo_gallery_attachments = explode(',', $acf_photo_gallery_attachments);
|
281 |
-
foreach($acf_photo_gallery_attachments as $image):
|
282 |
-
?>
|
283 |
-
<li id="acf-photo-gallery-mediabox-<?php echo $image; ?>" data-id="<?php echo $image; ?>">
|
284 |
-
<a class="dashicons dashicons-edit" href="#" title="Edit" data-id="<?php echo $image; ?>" data-field="<?php echo $field['_name']; ?>"></a>
|
285 |
-
<a class="dashicons dashicons-dismiss" href="<?php echo admin_url('admin-ajax.php'); ?>?action=acf_photo_gallery_remove_photo&_wpnonce=<?php echo $nonce_acf_photo_gallery; ?>&post=<?php echo $post->ID; ?>&photo=<?php echo $image; ?>&field=<?php echo $field['key']; ?>&id=<?php echo $field['id']; ?>" data-id="<?php echo $image; ?>" data-field="<?php echo $field['_name']; ?>" title="Remove this photo from the gallery"></a>
|
286 |
-
<input type="hidden" name="<?php echo $field['_name']; ?>[]" value="<?php echo $image; ?>"/>
|
287 |
-
<img src="<?php echo wp_get_attachment_thumb_url( $image ); ?>"/>
|
288 |
-
</li>
|
289 |
-
<?php endforeach; else: ?><li class="acf-photo-gallery-media-box-placeholder"><span class="dashicons dashicons-format-image"></span></li><?php endif; ?>
|
290 |
-
</ul>
|
291 |
-
<button class="button button-primary button-large" id="acf-photo-gallery-metabox-add-images" type="button" data-id="<?php echo $field['_name']; ?>">Add Images</button>
|
292 |
-
</p>
|
293 |
-
</div>
|
294 |
-
<?php
|
295 |
-
}
|
296 |
-
|
297 |
|
298 |
-
/*
|
299 |
-
* input_admin_enqueue_scripts()
|
300 |
-
*
|
301 |
-
* This action is called in the admin_enqueue_scripts action on the edit screen where your field is created.
|
302 |
-
* Use this action to add CSS + JavaScript to assist your create_field() action.
|
303 |
-
*
|
304 |
-
* $info http://codex.wordpress.org/Plugin_API/Action_Reference/admin_enqueue_scripts
|
305 |
-
* @type action
|
306 |
-
* @since 3.6
|
307 |
-
* @date 23/01/13
|
308 |
-
*/
|
309 |
|
310 |
-
|
311 |
-
|
312 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
313 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
314 |
|
315 |
-
|
316 |
-
|
317 |
-
|
|
|
318 |
|
319 |
|
320 |
-
|
321 |
-
|
322 |
-
|
323 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
324 |
|
325 |
-
|
326 |
-
|
327 |
-
|
|
|
328 |
|
329 |
}
|
330 |
|
331 |
-
|
332 |
-
|
333 |
-
|
334 |
-
// initialize
|
335 |
-
new acf_field_photo_gallery( $this->settings );
|
336 |
|
337 |
|
338 |
// class_exists check
|
339 |
-
endif;
|
340 |
-
|
341 |
-
?>
|
3 |
// exit if accessed directly
|
4 |
if( ! defined( 'ABSPATH' ) ) exit;
|
5 |
|
6 |
+
if( !defined('ACF_VERSION') ){ define('ACF_VERSION', $version); }
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
|
8 |
+
//Saving the gallery image ids into the database postmeta table in the same order.
|
9 |
+
include( dirname(dirname(__FILE__)) . '/includes/acf_photo_gallery_save.php' );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10 |
|
11 |
//Remove photo from the database array
|
12 |
+
include( dirname(dirname(__FILE__)) . '/includes/acf_photo_gallery_remove_photo.php' );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
|
14 |
//Editing and saving photo details
|
15 |
+
include( dirname(dirname(__FILE__)) . '/includes/acf_photo_gallery_edit_save.php' );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
16 |
|
17 |
// check if class already exists
|
18 |
if( !class_exists('acf_field_photo_gallery') ) :
|
19 |
|
20 |
+
class acf_field_photo_gallery extends acf_field {
|
|
|
|
|
|
|
|
|
21 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
22 |
// vars
|
23 |
+
var $settings, // will hold info such as dir / path
|
24 |
+
$defaults; // will hold default field options
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
25 |
|
|
|
|
|
26 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
27 |
/*
|
28 |
+
* __construct
|
29 |
+
*
|
30 |
+
* Set name / label needed for actions / filters
|
31 |
+
*
|
32 |
+
* @since 3.6
|
33 |
+
* @date 23/01/13
|
34 |
*/
|
35 |
|
36 |
+
function __construct( $settings )
|
37 |
+
{
|
38 |
+
include( dirname(dirname(__FILE__)) . '/includes/__construct.php' );
|
39 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
40 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
41 |
|
42 |
+
/*
|
43 |
+
* create_options()
|
44 |
+
*
|
45 |
+
* Create extra options for your field. This is rendered when editing a field.
|
46 |
+
* The value of $field['name'] can be used (like below) to save extra data to the $field
|
47 |
+
*
|
48 |
+
* @type action
|
49 |
+
* @since 3.6
|
50 |
+
* @date 23/01/13
|
51 |
+
*
|
52 |
+
* @param $field - an array holding all the field's data
|
53 |
+
*/
|
54 |
|
55 |
+
function create_options($field)
|
56 |
+
{
|
57 |
+
include( dirname(dirname(__FILE__)) . '/includes/v4/create_options.php' );
|
58 |
+
}
|
59 |
+
|
60 |
+
/*
|
61 |
+
* create_field()
|
62 |
+
*
|
63 |
+
* Create the HTML interface for your field
|
64 |
+
*
|
65 |
+
* @param $field - an array holding all the field's data
|
66 |
+
*
|
67 |
+
* @type action
|
68 |
+
* @since 3.6
|
69 |
+
* @date 23/01/13
|
70 |
+
*/
|
71 |
|
72 |
+
function create_field( $field )
|
73 |
+
{
|
74 |
+
include( dirname(dirname(__FILE__)) . '/includes/render_field.php' );
|
75 |
+
}
|
76 |
|
77 |
|
78 |
+
/*
|
79 |
+
* input_admin_enqueue_scripts()
|
80 |
+
*
|
81 |
+
* This action is called in the admin_enqueue_scripts action on the edit screen where your field is created.
|
82 |
+
* Use this action to add CSS + JavaScript to assist your create_field() action.
|
83 |
+
*
|
84 |
+
* $info http://codex.wordpress.org/Plugin_API/Action_Reference/admin_enqueue_scripts
|
85 |
+
* @type action
|
86 |
+
* @since 3.6
|
87 |
+
* @date 23/01/13
|
88 |
+
*/
|
89 |
|
90 |
+
function input_admin_enqueue_scripts()
|
91 |
+
{
|
92 |
+
include( dirname(dirname(__FILE__)) . '/includes/input_admin_enqueue_scripts.php' );
|
93 |
+
}
|
94 |
|
95 |
}
|
96 |
|
97 |
+
// initialize
|
98 |
+
new acf_field_photo_gallery( $this->settings );
|
|
|
|
|
|
|
99 |
|
100 |
|
101 |
// class_exists check
|
102 |
+
endif;
|
|
|
|
fields/acf-photo_gallery-v5.php
ADDED
@@ -0,0 +1,105 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
// exit if accessed directly
|
4 |
+
if( ! defined( 'ABSPATH' ) ) exit;
|
5 |
+
|
6 |
+
if( !defined('ACF_VERSION') ){ define('ACF_VERSION', $version); }
|
7 |
+
|
8 |
+
//Saving the gallery image ids into the database postmeta table in the same order.
|
9 |
+
include( dirname(dirname(__FILE__)) . '/includes/acf_photo_gallery_save.php' );
|
10 |
+
|
11 |
+
//Remove photo from the database array
|
12 |
+
include( dirname(dirname(__FILE__)) . '/includes/acf_photo_gallery_remove_photo.php' );
|
13 |
+
|
14 |
+
//Editing and saving photo details
|
15 |
+
include( dirname(dirname(__FILE__)) . '/includes/acf_photo_gallery_edit_save.php' );
|
16 |
+
|
17 |
+
// check if class already exists
|
18 |
+
if( !class_exists('acf_field_photo_gallery') ) :
|
19 |
+
|
20 |
+
class acf_field_photo_gallery extends acf_field {
|
21 |
+
|
22 |
+
|
23 |
+
/*
|
24 |
+
* __construct
|
25 |
+
*
|
26 |
+
* This function will setup the field type data
|
27 |
+
*
|
28 |
+
* @type function
|
29 |
+
* @date 5/03/2014
|
30 |
+
* @since 5.0.0
|
31 |
+
*
|
32 |
+
* @param n/a
|
33 |
+
* @return n/a
|
34 |
+
*/
|
35 |
+
|
36 |
+
function __construct( $settings )
|
37 |
+
{
|
38 |
+
include( dirname(dirname(__FILE__)) . '/includes/__construct.php' );
|
39 |
+
}
|
40 |
+
|
41 |
+
|
42 |
+
/*
|
43 |
+
* render_field_settings()
|
44 |
+
*
|
45 |
+
* Create extra settings for your field. These are visible when editing a field
|
46 |
+
*
|
47 |
+
* @type action
|
48 |
+
* @since 3.6
|
49 |
+
* @date 23/01/13
|
50 |
+
*
|
51 |
+
* @param $field (array) the $field being edited
|
52 |
+
* @return n/a
|
53 |
+
*/
|
54 |
+
|
55 |
+
function render_field_settings( $field )
|
56 |
+
{
|
57 |
+
include( dirname(dirname(__FILE__)) . '/includes/v5/render_field_settings.php' );
|
58 |
+
}
|
59 |
+
|
60 |
+
|
61 |
+
/*
|
62 |
+
* render_field()
|
63 |
+
*
|
64 |
+
* Create the HTML interface for your field
|
65 |
+
*
|
66 |
+
* @param $field (array) the $field being rendered
|
67 |
+
*
|
68 |
+
* @type action
|
69 |
+
* @since 3.6
|
70 |
+
* @date 23/01/13
|
71 |
+
*
|
72 |
+
* @param $field (array) the $field being edited
|
73 |
+
* @return n/a
|
74 |
+
*/
|
75 |
+
|
76 |
+
function render_field( $field )
|
77 |
+
{
|
78 |
+
include( dirname(dirname(__FILE__)) . '/includes/render_field.php' );
|
79 |
+
}
|
80 |
+
|
81 |
+
|
82 |
+
/*
|
83 |
+
* input_admin_enqueue_scripts()
|
84 |
+
*
|
85 |
+
* This action is called in the admin_enqueue_scripts action on the edit screen where your field is created.
|
86 |
+
* Use this action to add CSS + JavaScript to assist your create_field() action.
|
87 |
+
*
|
88 |
+
* $info http://codex.wordpress.org/Plugin_API/Action_Reference/admin_enqueue_scripts
|
89 |
+
* @type action
|
90 |
+
* @since 3.6
|
91 |
+
* @date 23/01/13
|
92 |
+
*/
|
93 |
+
|
94 |
+
function input_admin_enqueue_scripts()
|
95 |
+
{
|
96 |
+
include( dirname(dirname(__FILE__)) . '/includes/input_admin_enqueue_scripts.php' );
|
97 |
+
}
|
98 |
+
|
99 |
+
}
|
100 |
+
|
101 |
+
// initialize
|
102 |
+
new acf_field_photo_gallery( $this->settings );
|
103 |
+
|
104 |
+
// class_exists check
|
105 |
+
endif;
|
includes/__construct.php
ADDED
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
// vars
|
4 |
+
$this->name = 'photo_gallery';
|
5 |
+
$this->label = __('Photo Gallery');
|
6 |
+
$this->category = __("Content",'acf'); // Basic, Content, Choice, etc
|
7 |
+
$this->defaults = array(
|
8 |
+
// add default here to merge into your field.
|
9 |
+
// This makes life easy when creating the field options as you don't need to use any if( isset('') ) logic. eg:
|
10 |
+
'edit_modal' => 'Default',
|
11 |
+
//'preview_size' => 'thumbnail'
|
12 |
+
);
|
13 |
+
|
14 |
+
|
15 |
+
// do not delete!
|
16 |
+
parent::__construct();
|
17 |
+
|
18 |
+
// settings
|
19 |
+
$this->settings = $settings;
|
includes/acf_photo_gallery.php
ADDED
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
//Helper function that makes the images into a resuable array
|
4 |
+
function acf_photo_gallery_make_images($images, $field, $post_id, $order = 'ASC', $orderby = 'post__in'){
|
5 |
+
global $wpdb;
|
6 |
+
if( !is_array($images) ){ $images = explode(',', $images); }
|
7 |
+
$args = array( 'post_type' => 'attachment', 'posts_per_page' => -1, 'post__in' => $images, 'order' => $order, 'orderby' => $orderby );
|
8 |
+
$images = get_posts( $args );
|
9 |
+
$images = array_filter($images);
|
10 |
+
$array = array();
|
11 |
+
if( count($images) ):
|
12 |
+
foreach($images as $image):
|
13 |
+
$title = $image->post_title;
|
14 |
+
$content = $image->post_content;
|
15 |
+
$full_url = wp_get_attachment_url($image->ID);
|
16 |
+
$thumbnail_url = wp_get_attachment_thumb_url($image->ID);
|
17 |
+
$meta_data = wp_get_attachment_metadata($image->ID);
|
18 |
+
$large_srcset = wp_get_attachment_image_srcset( $image->ID,'large', $meta_data);
|
19 |
+
$medium_srcset = wp_get_attachment_image_srcset( $image->ID,'medium', $meta_data);
|
20 |
+
$url = get_post_meta($image->ID, $field . '_url', true);
|
21 |
+
$target = get_post_meta($image->ID, $field . '_target', true);
|
22 |
+
$array[] = array(
|
23 |
+
'id' => $image->ID,
|
24 |
+
'title' => $title,
|
25 |
+
'caption' => $content,
|
26 |
+
'full_image_url' => $full_url,
|
27 |
+
'thumbnail_image_url' => $thumbnail_url,
|
28 |
+
'large_srcset' => $large_srcset,
|
29 |
+
'medium_srcset' => $medium_srcset,
|
30 |
+
'url' => $url,
|
31 |
+
'target' => $target
|
32 |
+
);
|
33 |
+
endforeach;
|
34 |
+
endif;
|
35 |
+
return $array;
|
36 |
+
}
|
37 |
+
|
38 |
+
function acf_photo_gallery($field = null, $post_id, $order = 'ASC', $orderby = 'post__in'){
|
39 |
+
$images = get_post_meta($post_id, $field, true);
|
40 |
+
return acf_photo_gallery_make_images($images, $field, $post_id, $order, $orderby);
|
41 |
+
}
|
includes/acf_photo_gallery_edit.php
ADDED
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
function acf_photo_gallery_edit($field, $nonce, $attachment, $url = '', $title, $caption, $target = 0){
|
4 |
+
$args = array();
|
5 |
+
$args['url'] = $url;
|
6 |
+
$args['title'] = $title;
|
7 |
+
$args['caption'] = $caption;
|
8 |
+
$args['target'] = $target;
|
9 |
+
$fields = apply_filters( 'acf_photo_gallery_image_fields', $args, $attachment, $field );
|
10 |
+
include( dirname(__FILE__) . '/acf_photo_gallery_metabox_edit.php');
|
11 |
+
}
|
includes/acf_photo_gallery_edit_save.php
ADDED
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
//Fires off when ediitn the details of the photo
|
4 |
+
function acf_photo_gallery_edit_save(){
|
5 |
+
if( wp_verify_nonce( $_POST['acf-pg-hidden-nonce'], 'acf_photo_gallery_edit_save') and !empty($_POST['acf-pg-hidden-field']) and !empty($_POST['acf-pg-hidden-post']) and !empty($_POST['acf-pg-hidden-attachment']) ){
|
6 |
+
|
7 |
+
$request = $_POST;
|
8 |
+
$field = sanitize_text_field($request['acf-pg-hidden-field']);
|
9 |
+
$post = sanitize_text_field($request['acf-pg-hidden-post']);
|
10 |
+
$attachment = sanitize_text_field($request['acf-pg-hidden-attachment']);
|
11 |
+
$title = sanitize_text_field($request['title']);
|
12 |
+
$caption = sanitize_text_field($request['caption']);
|
13 |
+
|
14 |
+
unset( $request['acf-pg-hidden-field'] );
|
15 |
+
unset( $request['acf-pg-hidden-post'] );
|
16 |
+
unset( $request['acf-pg-hidden-attachment'] );
|
17 |
+
unset( $request['action'] );
|
18 |
+
unset( $request['acf-pg-hidden-nonce'] );
|
19 |
+
unset( $request['title'] );
|
20 |
+
unset( $request['caption'] );
|
21 |
+
|
22 |
+
$acf_photo_gallery_editbox_caption_from_attachment = apply_filters( 'acf_photo_gallery_editbox_caption_from_attachment', $request);
|
23 |
+
if( $acf_photo_gallery_editbox_caption_from_attachment == 1 ){
|
24 |
+
$captionColumn = 'post_excerpt';
|
25 |
+
} else {
|
26 |
+
$captionColumn = 'post_content';
|
27 |
+
}
|
28 |
+
|
29 |
+
$post = array('ID' => $attachment, 'post_title' => $title, $captionColumn => $caption);
|
30 |
+
wp_update_post( $post );
|
31 |
+
|
32 |
+
foreach( $request as $name => $value ){
|
33 |
+
$name = sanitize_text_field( $name );
|
34 |
+
$value = sanitize_text_field( $value );
|
35 |
+
|
36 |
+
if( !empty($value) ){
|
37 |
+
update_post_meta( $attachment, $field . '_' . $name, $value);
|
38 |
+
} else {
|
39 |
+
delete_post_meta( $attachment, $field . '_' . $name);
|
40 |
+
}
|
41 |
+
}
|
42 |
+
|
43 |
+
}
|
44 |
+
die();
|
45 |
+
}
|
46 |
+
add_action( 'wp_ajax_acf_photo_gallery_edit_save', 'acf_photo_gallery_edit_save' );
|
includes/acf_photo_gallery_image_fields.php
ADDED
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
function acf_photo_gallery_image_fields( $args, $attachment_id, $field){
|
3 |
+
return array(
|
4 |
+
'url' => array('type' => 'text', 'label' => 'URL', 'name' => 'url', 'value' => ($args['url'])?$args['url']:null),
|
5 |
+
'target' => array('type' => 'checkbox', 'label' => 'Open in new tab', 'name' => 'target', 'value' => ($args['target'])?$args['target']:null),
|
6 |
+
'title' => array('type' => 'text', 'label' => 'Title', 'name' => 'title', 'value' => ($args['title'])?$args['title']:null),
|
7 |
+
'caption' => array('type' => 'textarea', 'label' => 'Caption', 'name' => 'caption', 'value' => ($args['caption'])?$args['caption']:null)
|
8 |
+
);
|
9 |
+
}
|
10 |
+
add_filter( 'acf_photo_gallery_image_fields', 'acf_photo_gallery_image_fields', 10, 3 );
|
includes/acf_photo_gallery_metabox_edit.php
ADDED
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<div id="acf-photo-gallery-metabox-edit-<?php echo $attachment; ?>" class="acf-edit-photo-gallery">
|
2 |
+
<h3>Edit Image</h3>
|
3 |
+
<input class="acf-photo-gallery-edit-field" type="hidden" name="acf-pg-hidden-field" value="<?php echo $field; ?>"/>
|
4 |
+
<input class="acf-photo-gallery-edit-field" type="hidden" name="acf-pg-hidden-post" value="<?php echo $_GET['post']; ?>"/>
|
5 |
+
<input class="acf-photo-gallery-edit-field" type="hidden" name="acf-pg-hidden-attachment" value="<?php echo $attachment; ?>"/>
|
6 |
+
<input class="acf-photo-gallery-edit-field" type="hidden" name="acf-pg-hidden-action" value="acf_photo_gallery_edit_save"/>
|
7 |
+
<input class="acf-photo-gallery-edit-field" type="hidden" name="acf-pg-hidden-nonce" value="<?php echo $nonce; ?>"/>
|
8 |
+
<?php
|
9 |
+
foreach( $fields as $key => $item ){
|
10 |
+
$type = ($item['type'])?$item['type']:null;
|
11 |
+
$label = $item['label']?$item['label']:null;
|
12 |
+
$name = $item['name']?$item['name']:null;
|
13 |
+
$value = $item['value']?$item['value']:null;
|
14 |
+
?>
|
15 |
+
<?php if( $type == 'text' ){ ?><label><?php echo $label; ?></label><input class="acf-photo-gallery-edit-field" type="<?php echo $type; ?>" name="<?php echo $name; ?>" value="<?php echo $value; ?>"/><?php } ?>
|
16 |
+
<?php if( $type == 'checkbox' ){ ?><label><input class="acf-photo-gallery-edit-field" type="checkbox" name="<?php echo $name; ?>" value="true" <?php echo (!empty($value=='true'))?'checked':''; ?>/><?php echo $label; ?></label><?php } ?>
|
17 |
+
<?php if( $type == 'textarea' ){ ?><label><?php echo $label; ?></label><textarea class="acf-photo-gallery-edit-field" name="<?php echo $name; ?>"><?php echo $value; ?></textarea><?php } ?>
|
18 |
+
<?php } ?>
|
19 |
+
<div class="save-changes-wrap">
|
20 |
+
<button class="button button-primary button-large" type="submit" data-id="<?php echo $attachment; ?>" data-ajaxurl="<?php echo admin_url('admin-ajax.php'); ?>">Save Changes</button>
|
21 |
+
<button class="button button-large button-close" type="button" data-close="<?php echo $attachment; ?>">Close</button>
|
22 |
+
</div>
|
23 |
+
</div>
|
includes/acf_photo_gallery_remove_photo.php
ADDED
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
//Helper function that will remove photo from the gallery
|
4 |
+
function acf_photo_gallery_remove_photo(){
|
5 |
+
if( wp_verify_nonce( $_GET['_wpnonce'], 'nonce_acf_photo_gallery') and !empty($_GET['post']) and !empty($_GET['photo']) ){
|
6 |
+
$field = $_GET['field'];
|
7 |
+
$post = $_GET['post'];
|
8 |
+
$photo = $_GET['photo'];
|
9 |
+
$photo = preg_replace('/\D/', '', $photo);
|
10 |
+
$id = str_replace('acf-field-', '', $_GET['id']);
|
11 |
+
$meta = get_post_meta($post, $id, true);
|
12 |
+
$meta_arr = explode(',', $meta);
|
13 |
+
if( in_array($photo, $meta_arr) ){
|
14 |
+
foreach($meta_arr as $key => $value){
|
15 |
+
if( $photo == $value ){
|
16 |
+
unset($meta_arr[$key]);
|
17 |
+
if( count($meta_arr) > 0 ){
|
18 |
+
$meta_arr = implode(',', $meta_arr);
|
19 |
+
update_post_meta( $post, $id, $meta_arr );
|
20 |
+
} else {
|
21 |
+
delete_post_meta( $post, $id );
|
22 |
+
}
|
23 |
+
}
|
24 |
+
}
|
25 |
+
}
|
26 |
+
}
|
27 |
+
die();
|
28 |
+
}
|
29 |
+
//add_action( 'wp_ajax_nopriv_acf_photo_gallery_remove_photo', 'acf_photo_gallery_remove_photo' );
|
30 |
+
add_action( 'wp_ajax_acf_photo_gallery_remove_photo', 'acf_photo_gallery_remove_photo' );
|
includes/acf_photo_gallery_resize_image.php
ADDED
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
//Helper function that resizes the images from the specified args
|
4 |
+
function acf_photo_gallery_resize_image( $img_url, $width = 150, $height = 150){
|
5 |
+
if( !function_exists('aq_resize') ){
|
6 |
+
require_once( dirname(__FILE__) . '/aq_resizer.php');
|
7 |
+
}
|
8 |
+
$extension = explode('.', $img_url);
|
9 |
+
$extension = strtolower(end($extension));
|
10 |
+
if( $extension != 'svg' ){
|
11 |
+
$img_url = aq_resize( $img_url, $width, $height, true, true, true);
|
12 |
+
}
|
13 |
+
return $img_url;
|
14 |
+
}
|
includes/acf_photo_gallery_save.php
ADDED
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
//Fires off when the WordPress update button is clicked
|
4 |
+
function acf_photo_gallery_save( $post_id ){
|
5 |
+
|
6 |
+
// If this is a revision, get real post ID
|
7 |
+
if ( $parent_id = wp_is_post_revision( $post_id ) )
|
8 |
+
$post_id = $parent_id;
|
9 |
+
// unhook this function so it doesn't loop infinitely
|
10 |
+
remove_action( 'save_post', 'acf_photo_gallery_save' );
|
11 |
+
|
12 |
+
$field = isset($_POST['acf-photo-gallery-groups'])? $_POST['acf-photo-gallery-groups']: null;
|
13 |
+
if( !empty($field) ){
|
14 |
+
foreach($field as $k => $v ){
|
15 |
+
$field_id = isset($_POST['acf-photo-gallery-groups'][$k])? $_POST['acf-photo-gallery-groups'][$k]: null;
|
16 |
+
if (!empty($field_id)) {
|
17 |
+
$ids = !empty($field) && isset($_POST[$field_id])? $_POST[$field_id]: null;
|
18 |
+
if (!empty($ids)) {
|
19 |
+
$ids = implode(',', $ids);
|
20 |
+
update_post_meta($post_id, $field_id, $ids);
|
21 |
+
} else {
|
22 |
+
delete_post_meta($post_id, $v);
|
23 |
+
}
|
24 |
+
}
|
25 |
+
}
|
26 |
+
}
|
27 |
+
|
28 |
+
// re-hook this function
|
29 |
+
add_action( 'save_post', 'acf_photo_gallery_save' );
|
30 |
+
}
|
31 |
+
add_action( 'save_post', 'acf_photo_gallery_save' );
|
includes/aq_resizer.php
ADDED
@@ -0,0 +1,246 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* Title : Aqua Resizer
|
5 |
+
* Description : Resizes WordPress images on the fly
|
6 |
+
* Version : 1.2.1
|
7 |
+
* Author : Syamil MJ
|
8 |
+
* Author URI : http://aquagraphite.com
|
9 |
+
* License : WTFPL - http://sam.zoy.org/wtfpl/
|
10 |
+
* Documentation : https://github.com/sy4mil/Aqua-Resizer/
|
11 |
+
*
|
12 |
+
* @param string $url - (required) must be uploaded using wp media uploader
|
13 |
+
* @param int $width - (required)
|
14 |
+
* @param int $height - (optional)
|
15 |
+
* @param bool $crop - (optional) default to soft crop
|
16 |
+
* @param bool $single - (optional) returns an array if false
|
17 |
+
* @param bool $upscale - (optional) resizes smaller images
|
18 |
+
* @uses wp_upload_dir()
|
19 |
+
* @uses image_resize_dimensions()
|
20 |
+
* @uses wp_get_image_editor()
|
21 |
+
*
|
22 |
+
* @return str|array
|
23 |
+
*/
|
24 |
+
|
25 |
+
if(!class_exists('Aq_Resize')) {
|
26 |
+
class Aq_Exception extends Exception {}
|
27 |
+
|
28 |
+
class Aq_Resize
|
29 |
+
{
|
30 |
+
/**
|
31 |
+
* The singleton instance
|
32 |
+
*/
|
33 |
+
static private $instance = null;
|
34 |
+
|
35 |
+
/**
|
36 |
+
* Should an Aq_Exception be thrown on error?
|
37 |
+
* If false (default), then the error will just be logged.
|
38 |
+
*/
|
39 |
+
public $throwOnError = false;
|
40 |
+
|
41 |
+
/**
|
42 |
+
* No initialization allowed
|
43 |
+
*/
|
44 |
+
private function __construct() {}
|
45 |
+
|
46 |
+
/**
|
47 |
+
* No cloning allowed
|
48 |
+
*/
|
49 |
+
private function __clone() {}
|
50 |
+
|
51 |
+
/**
|
52 |
+
* For your custom default usage you may want to initialize an Aq_Resize object by yourself and then have own defaults
|
53 |
+
*/
|
54 |
+
static public function getInstance() {
|
55 |
+
if(self::$instance == null) {
|
56 |
+
self::$instance = new self;
|
57 |
+
}
|
58 |
+
|
59 |
+
return self::$instance;
|
60 |
+
}
|
61 |
+
|
62 |
+
/**
|
63 |
+
* Run, forest.
|
64 |
+
*/
|
65 |
+
public function process( $url, $width = null, $height = null, $crop = null, $single = true, $upscale = false ) {
|
66 |
+
try {
|
67 |
+
// Validate inputs.
|
68 |
+
if (!$url)
|
69 |
+
throw new Aq_Exception('$url parameter is required');
|
70 |
+
if (!$width)
|
71 |
+
throw new Aq_Exception('$width parameter is required');
|
72 |
+
if (!$height)
|
73 |
+
throw new Aq_Exception('$height parameter is required');
|
74 |
+
|
75 |
+
// Caipt'n, ready to hook.
|
76 |
+
if ( true === $upscale ) add_filter( 'image_resize_dimensions', array($this, 'aq_upscale'), 10, 6 );
|
77 |
+
|
78 |
+
// Define upload path & dir.
|
79 |
+
$upload_info = wp_upload_dir();
|
80 |
+
$upload_dir = $upload_info['basedir'];
|
81 |
+
$upload_url = $upload_info['baseurl'];
|
82 |
+
|
83 |
+
$http_prefix = "http://";
|
84 |
+
$https_prefix = "https://";
|
85 |
+
$relative_prefix = "//"; // The protocol-relative URL
|
86 |
+
|
87 |
+
/* if the $url scheme differs from $upload_url scheme, make them match
|
88 |
+
if the schemes differe, images don't show up. */
|
89 |
+
if(!strncmp($url,$https_prefix,strlen($https_prefix))){ //if url begins with https:// make $upload_url begin with https:// as well
|
90 |
+
$upload_url = str_replace($http_prefix,$https_prefix,$upload_url);
|
91 |
+
}
|
92 |
+
elseif(!strncmp($url,$http_prefix,strlen($http_prefix))){ //if url begins with http:// make $upload_url begin with http:// as well
|
93 |
+
$upload_url = str_replace($https_prefix,$http_prefix,$upload_url);
|
94 |
+
}
|
95 |
+
elseif(!strncmp($url,$relative_prefix,strlen($relative_prefix))){ //if url begins with // make $upload_url begin with // as well
|
96 |
+
$upload_url = str_replace(array( 0 => "$http_prefix", 1 => "$https_prefix"),$relative_prefix,$upload_url);
|
97 |
+
}
|
98 |
+
|
99 |
+
|
100 |
+
// Check if $img_url is local.
|
101 |
+
if ( false === strpos( $url, $upload_url ) )
|
102 |
+
throw new Aq_Exception('Image must be local: ' . $url);
|
103 |
+
|
104 |
+
// Define path of image.
|
105 |
+
$rel_path = str_replace( $upload_url, '', $url );
|
106 |
+
$img_path = $upload_dir . $rel_path;
|
107 |
+
|
108 |
+
// Check if img path exists, and is an image indeed.
|
109 |
+
if ( ! file_exists( $img_path ) or ! getimagesize( $img_path ) )
|
110 |
+
throw new Aq_Exception('Image file does not exist (or is not an image): ' . $img_path);
|
111 |
+
|
112 |
+
// Get image info.
|
113 |
+
$info = pathinfo( $img_path );
|
114 |
+
$ext = $info['extension'];
|
115 |
+
list( $orig_w, $orig_h ) = getimagesize( $img_path );
|
116 |
+
|
117 |
+
// Get image size after cropping.
|
118 |
+
$dims = image_resize_dimensions( $orig_w, $orig_h, $width, $height, $crop );
|
119 |
+
$dst_w = $dims[4];
|
120 |
+
$dst_h = $dims[5];
|
121 |
+
|
122 |
+
// Return the original image only if it exactly fits the needed measures.
|
123 |
+
if ( ! $dims && ( ( ( null === $height && $orig_w == $width ) xor ( null === $width && $orig_h == $height ) ) xor ( $height == $orig_h && $width == $orig_w ) ) ) {
|
124 |
+
$img_url = $url;
|
125 |
+
$dst_w = $orig_w;
|
126 |
+
$dst_h = $orig_h;
|
127 |
+
} else {
|
128 |
+
// Use this to check if cropped image already exists, so we can return that instead.
|
129 |
+
$suffix = "{$dst_w}x{$dst_h}";
|
130 |
+
$dst_rel_path = str_replace( '.' . $ext, '', $rel_path );
|
131 |
+
$destfilename = "{$upload_dir}{$dst_rel_path}-{$suffix}.{$ext}";
|
132 |
+
|
133 |
+
if ( ! $dims || ( true == $crop && false == $upscale && ( $dst_w < $width || $dst_h < $height ) ) ) {
|
134 |
+
// Can't resize, so return false saying that the action to do could not be processed as planned.
|
135 |
+
throw new Aq_Exception('Unable to resize image because image_resize_dimensions() failed');
|
136 |
+
}
|
137 |
+
// Else check if cache exists.
|
138 |
+
elseif ( file_exists( $destfilename ) && getimagesize( $destfilename ) ) {
|
139 |
+
$img_url = "{$upload_url}{$dst_rel_path}-{$suffix}.{$ext}";
|
140 |
+
}
|
141 |
+
// Else, we resize the image and return the new resized image url.
|
142 |
+
else {
|
143 |
+
|
144 |
+
$editor = wp_get_image_editor( $img_path );
|
145 |
+
|
146 |
+
if ( is_wp_error( $editor ) || is_wp_error( $editor->resize( $width, $height, $crop ) ) ) {
|
147 |
+
throw new Aq_Exception('Unable to get WP_Image_Editor: ' .
|
148 |
+
$editor->get_error_message() . ' (is GD or ImageMagick installed?)');
|
149 |
+
}
|
150 |
+
|
151 |
+
$resized_file = $editor->save();
|
152 |
+
|
153 |
+
if ( ! is_wp_error( $resized_file ) ) {
|
154 |
+
$resized_rel_path = str_replace( $upload_dir, '', $resized_file['path'] );
|
155 |
+
$img_url = $upload_url . $resized_rel_path;
|
156 |
+
} else {
|
157 |
+
throw new Aq_Exception('Unable to save resized image file: ' . $editor->get_error_message());
|
158 |
+
}
|
159 |
+
|
160 |
+
}
|
161 |
+
}
|
162 |
+
|
163 |
+
// Okay, leave the ship.
|
164 |
+
if ( true === $upscale ) remove_filter( 'image_resize_dimensions', array( $this, 'aq_upscale' ) );
|
165 |
+
|
166 |
+
// Return the output.
|
167 |
+
if ( $single ) {
|
168 |
+
// str return.
|
169 |
+
$image = $img_url;
|
170 |
+
} else {
|
171 |
+
// array return.
|
172 |
+
$image = array (
|
173 |
+
0 => $img_url,
|
174 |
+
1 => $dst_w,
|
175 |
+
2 => $dst_h
|
176 |
+
);
|
177 |
+
}
|
178 |
+
|
179 |
+
return $image;
|
180 |
+
}
|
181 |
+
catch (Aq_Exception $ex) {
|
182 |
+
error_log('Aq_Resize.process() error: ' . $ex->getMessage());
|
183 |
+
|
184 |
+
if ($this->throwOnError) {
|
185 |
+
// Bubble up exception.
|
186 |
+
throw $ex;
|
187 |
+
}
|
188 |
+
else {
|
189 |
+
// Return false, so that this patch is backwards-compatible.
|
190 |
+
return false;
|
191 |
+
}
|
192 |
+
}
|
193 |
+
}
|
194 |
+
|
195 |
+
/**
|
196 |
+
* Callback to overwrite WP computing of thumbnail measures
|
197 |
+
*/
|
198 |
+
function aq_upscale( $default, $orig_w, $orig_h, $dest_w, $dest_h, $crop ) {
|
199 |
+
if ( ! $crop ) return null; // Let the wordpress default function handle this.
|
200 |
+
|
201 |
+
// Here is the point we allow to use larger image size than the original one.
|
202 |
+
$aspect_ratio = $orig_w / $orig_h;
|
203 |
+
$new_w = $dest_w;
|
204 |
+
$new_h = $dest_h;
|
205 |
+
|
206 |
+
if ( ! $new_w ) {
|
207 |
+
$new_w = intval( $new_h * $aspect_ratio );
|
208 |
+
}
|
209 |
+
|
210 |
+
if ( ! $new_h ) {
|
211 |
+
$new_h = intval( $new_w / $aspect_ratio );
|
212 |
+
}
|
213 |
+
|
214 |
+
$size_ratio = max( $new_w / $orig_w, $new_h / $orig_h );
|
215 |
+
|
216 |
+
$crop_w = round( $new_w / $size_ratio );
|
217 |
+
$crop_h = round( $new_h / $size_ratio );
|
218 |
+
|
219 |
+
$s_x = floor( ( $orig_w - $crop_w ) / 2 );
|
220 |
+
$s_y = floor( ( $orig_h - $crop_h ) / 2 );
|
221 |
+
|
222 |
+
return array( 0, 0, (int) $s_x, (int) $s_y, (int) $new_w, (int) $new_h, (int) $crop_w, (int) $crop_h );
|
223 |
+
}
|
224 |
+
}
|
225 |
+
}
|
226 |
+
|
227 |
+
if(!function_exists('aq_resize')) {
|
228 |
+
|
229 |
+
/**
|
230 |
+
* This is just a tiny wrapper function for the class above so that there is no
|
231 |
+
* need to change any code in your own WP themes. Usage is still the same :)
|
232 |
+
*/
|
233 |
+
function aq_resize( $url, $width = null, $height = null, $crop = null, $single = true, $upscale = false ) {
|
234 |
+
/* WPML Fix */
|
235 |
+
if ( defined( 'ICL_SITEPRESS_VERSION' ) ){
|
236 |
+
global $sitepress;
|
237 |
+
$url = $sitepress->convert_url( $url, $sitepress->get_default_language() );
|
238 |
+
}
|
239 |
+
/* WPML Fix */
|
240 |
+
|
241 |
+
$aq_resize = Aq_Resize::getInstance();
|
242 |
+
return $aq_resize->process( $url, $width, $height, $crop, $single, $upscale );
|
243 |
+
}
|
244 |
+
}
|
245 |
+
|
246 |
+
|
includes/index.php
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
1 |
+
<?php
|
2 |
+
// Silence is golden.
|
includes/input_admin_enqueue_scripts.php
ADDED
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
// vars
|
4 |
+
$url = $this->settings['url'];
|
5 |
+
$version = $this->settings['version'];
|
6 |
+
|
7 |
+
// register & include JS
|
8 |
+
wp_enqueue_script( 'jquery-ui-sortable' );
|
9 |
+
wp_register_script( 'acf-input-photo_gallery', "{$url}assets/js/acf-photo-gallery-field.js", array('acf-input'), $version );
|
10 |
+
wp_enqueue_script( 'acf-input-photo_gallery');
|
11 |
+
|
12 |
+
// register & include CSS
|
13 |
+
wp_register_style( 'acf-input-photo_gallery', "{$url}assets/css/acf-photo-gallery-field.css", array('acf-input'), $version );
|
14 |
+
wp_enqueue_style('acf-input-photo_gallery');
|
includes/render_field.php
ADDED
@@ -0,0 +1,60 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
// create Field HTML
|
3 |
+
global $post;
|
4 |
+
$nonce_acf_photo_gallery = wp_create_nonce( 'nonce_acf_photo_gallery' );
|
5 |
+
if( ACF_VERSION >= 4 and ACF_VERSION < 5 ){
|
6 |
+
$filename = $field['_name'];
|
7 |
+
$value = $field['value'];
|
8 |
+
$key = $field['key'];
|
9 |
+
$edit_model = (!empty($field['edit_modal']))?$field['edit_modal']:'Default';
|
10 |
+
} else if( ACF_VERSION >= 5 and ACF_VERSION < 6 ){
|
11 |
+
$filename = $field['_name'];
|
12 |
+
$value = $field['value'];
|
13 |
+
$key = $field['key'];
|
14 |
+
$edit_model = (!empty($field['fields[' . $filename]['edit_modal']))?$field['fields[' . $filename]['edit_modal']:'Default';
|
15 |
+
}
|
16 |
+
?>
|
17 |
+
<div class="acf-photo-gallery-group-<?php echo $key; ?>">
|
18 |
+
<input type="hidden" name="acf-photo-gallery-edit-modal" value="<?php echo $edit_model; ?>" />
|
19 |
+
<input type="hidden" name="acf-photo-gallery-groups[]" value="<?php echo $field['_name']; ?>"/>
|
20 |
+
<div id="acf-photo-gallery-metabox-edit">
|
21 |
+
<?php
|
22 |
+
if( $value ):
|
23 |
+
$acf_photo_gallery_editbox_caption_from_attachment = apply_filters( 'acf_photo_gallery_editbox_caption_from_attachment', $field);
|
24 |
+
$acf_photo_gallery_attachments = $value;
|
25 |
+
$acf_photo_gallery_attachments = explode(',', $acf_photo_gallery_attachments);
|
26 |
+
$args = array( 'post_type' => 'attachment', 'posts_per_page' => -1, 'post__in' => $acf_photo_gallery_attachments );
|
27 |
+
$acf_photo_gallery_attachments = get_posts( $args );
|
28 |
+
$nonce = wp_create_nonce('acf_photo_gallery_edit_save');
|
29 |
+
foreach($acf_photo_gallery_attachments as $attachment):
|
30 |
+
$id = $attachment->ID;
|
31 |
+
$url = get_post_meta($id, $field['_name'] . '_url', true);
|
32 |
+
$target = get_post_meta($id, $field['_name'] . '_target', true);
|
33 |
+
$title = $attachment->post_title;
|
34 |
+
if( $acf_photo_gallery_editbox_caption_from_attachment == 1 ){
|
35 |
+
$caption = wp_get_attachment_caption( $id );
|
36 |
+
} else {
|
37 |
+
$caption = $attachment->post_content;
|
38 |
+
}
|
39 |
+
acf_photo_gallery_edit($field['_name'], $nonce, $id, $url, $title, $caption, $target);
|
40 |
+
endforeach;
|
41 |
+
endif;
|
42 |
+
?>
|
43 |
+
</div>
|
44 |
+
<ul id="acf-photo-gallery-metabox-list" class="acf-photo-gallery-metabox-list">
|
45 |
+
<?php
|
46 |
+
if( $value ):
|
47 |
+
$acf_photo_gallery_attachments = $value;
|
48 |
+
$acf_photo_gallery_attachments = explode(',', $acf_photo_gallery_attachments);
|
49 |
+
foreach($acf_photo_gallery_attachments as $image):
|
50 |
+
?>
|
51 |
+
<li class="acf-photo-gallery-mediabox-<?php echo $image; ?>">
|
52 |
+
<a class="dashicons dashicons-edit" href="#" title="Edit" data-id="<?php echo $image; ?>" data-field="<?php echo $key; ?>"></a>
|
53 |
+
<a class="dashicons dashicons-dismiss" href="#" data-id="<?php echo $image; ?>" data-field="<?php echo htmlspecialchars(json_encode($field), ENT_QUOTES, 'UTF-8'); ?>" title="Remove this photo from the gallery"></a>
|
54 |
+
<input type="hidden" name="<?php echo $field['_name']; ?>[]" value="<?php echo $image; ?>"/>
|
55 |
+
<img src="<?php echo wp_get_attachment_thumb_url( $image ); ?>"/>
|
56 |
+
</li>
|
57 |
+
<?php endforeach; else: ?><li class="acf-photo-gallery-media-box-placeholder"><span class="dashicons dashicons-format-image"></span></li><?php endif; ?>
|
58 |
+
</ul>
|
59 |
+
<button class="button button-primary button-large acf-photo-gallery-metabox-add-images" type="button" data-field="<?php echo htmlspecialchars(json_encode($field), ENT_QUOTES, 'UTF-8'); ?>">Add Images</button>
|
60 |
+
</div>
|
includes/v4/create_options.php
ADDED
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
$field = array_merge($this->defaults, $field);
|
3 |
+
$key = $field['name'];
|
4 |
+
?>
|
5 |
+
<tr class="field_option field_option_<?php echo $this->name; ?>">
|
6 |
+
<td class="label">
|
7 |
+
<label><?php _e("Edit modal",'acf'); ?></label>
|
8 |
+
<p class="description"><?php _e("Native lets you delete permanently or select another, but is heavier",'acf'); ?></p>
|
9 |
+
</td>
|
10 |
+
<td>
|
11 |
+
<?php
|
12 |
+
do_action('acf/create_field', array(
|
13 |
+
'type' => 'select',
|
14 |
+
'name' => 'fields['.$key.'][edit_modal]',
|
15 |
+
'value' => $field['edit_modal'],
|
16 |
+
'choices' => array('Default' => 'Default', 'Native' => 'Native')
|
17 |
+
));
|
18 |
+
?>
|
19 |
+
</td>
|
20 |
+
</tr>
|
includes/v4/index.php
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
1 |
+
<?php
|
2 |
+
// Silence is golden.
|
includes/v5/index.php
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
1 |
+
<?php
|
2 |
+
// Silence is golden.
|
includes/v5/render_field_settings.php
ADDED
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/*
|
3 |
+
* acf_render_field_setting
|
4 |
+
*
|
5 |
+
* This function will create a setting for your field. Simply pass the $field parameter and an array of field settings.
|
6 |
+
* The array of settings does not require a `value` or `prefix`; These settings are found from the $field array.
|
7 |
+
*
|
8 |
+
* More than one setting can be added by copy/paste the above code.
|
9 |
+
* Please note that you must also have a matching $defaults value for the field name (font_size)
|
10 |
+
*/
|
11 |
+
|
12 |
+
$name = $field['name'];
|
13 |
+
$value = $field['fields['.$name];
|
14 |
+
|
15 |
+
acf_render_field_setting( $field, array(
|
16 |
+
'label' => __('Edit modal','TEXTDOMAIN'),
|
17 |
+
'type' => 'select',
|
18 |
+
'name' => 'fields['.$name.'][edit_modal]',
|
19 |
+
'value' => $value,
|
20 |
+
'choices' => array('Default' => 'Default', 'Native' => 'Native')
|
21 |
+
));
|
navz-photo-gallery.php
CHANGED
@@ -3,7 +3,7 @@
|
|
3 |
Plugin Name: ACF Photo Gallery Field
|
4 |
Plugin URI: http://www.navz.me/
|
5 |
Description: An extension for Advance Custom Fields which lets you add photo gallery functionality on your websites.
|
6 |
-
Version: 1.6.
|
7 |
Author: Navneil Naicker
|
8 |
Author URI: http://www.navz.me/
|
9 |
License: GPLv2 or later
|
@@ -17,157 +17,114 @@ if( ! defined( 'ABSPATH' ) ) exit;
|
|
17 |
// check if class already exists
|
18 |
if( !class_exists('acf_plugin_photo_gallery') ) :
|
19 |
|
20 |
-
class acf_plugin_photo_gallery {
|
21 |
-
|
22 |
-
/*
|
23 |
-
* __construct
|
24 |
-
*
|
25 |
-
* This function will setup the class functionality
|
26 |
-
*
|
27 |
-
* @type function
|
28 |
-
* @date 17/02/2016
|
29 |
-
* @since 1.0.0
|
30 |
-
*
|
31 |
-
* @param n/a
|
32 |
-
* @return n/a
|
33 |
-
*/
|
34 |
-
|
35 |
-
function __construct() {
|
36 |
-
|
37 |
// vars
|
38 |
-
$
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
|
|
|
|
|
|
|
|
48 |
|
49 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
50 |
|
51 |
-
|
52 |
-
|
53 |
-
add_action('acf/register_fields', array($this, 'include_field_types')); // v4
|
54 |
|
55 |
-
|
56 |
-
|
57 |
-
}
|
58 |
-
|
59 |
-
function acf_photo_gallery_sortable($hook) {
|
60 |
-
if ( 'post.php' == $hook ) {
|
61 |
-
wp_enqueue_script( 'jquery-ui-sortable', 'jquery-ui-sortable', 'jquery', '9999', true);
|
62 |
-
}
|
63 |
-
}
|
64 |
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
*
|
70 |
-
* @type function
|
71 |
-
* @date 17/02/2016
|
72 |
-
* @since 1.0.0
|
73 |
-
*
|
74 |
-
* @param $version (int) major ACF version. Defaults to false
|
75 |
-
* @return n/a
|
76 |
-
*/
|
77 |
-
|
78 |
-
function include_field_types( $version = false ) {
|
79 |
-
|
80 |
-
// support empty $version
|
81 |
-
if( !$version ) $version = 4;
|
82 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
83 |
|
84 |
-
|
85 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
86 |
|
87 |
}
|
88 |
-
|
89 |
-
}
|
90 |
|
91 |
-
// initialize
|
92 |
-
new acf_plugin_photo_gallery();
|
93 |
|
94 |
// class_exists check
|
95 |
endif;
|
96 |
|
97 |
//Helper function for pulling the images
|
98 |
-
|
99 |
-
$images = get_post_meta($post_id, $field, true);
|
100 |
-
$images = explode(',', $images);
|
101 |
-
$args = array( 'post_type' => 'attachment', 'posts_per_page' => -1, 'post__in' => $images, 'orderby' => 'post__in' );
|
102 |
-
$images = get_posts( $args );
|
103 |
-
$images = array_filter($images);
|
104 |
-
$array = array();
|
105 |
-
if( count($images) ):
|
106 |
-
foreach($images as $image):
|
107 |
-
$title = $image->post_title;
|
108 |
-
$content = $image->post_content;
|
109 |
-
$full_url = wp_get_attachment_url($image->ID);
|
110 |
-
$thumbnail_url = wp_get_attachment_thumb_url($image->ID);
|
111 |
-
$meta_data = wp_get_attachment_metadata($image->ID);
|
112 |
-
$large_srcset = wp_get_attachment_image_srcset( $image->ID,'large', $meta_data);
|
113 |
-
$medium_srcset = wp_get_attachment_image_srcset( $image->ID,'medium', $meta_data);
|
114 |
-
$url = get_post_meta($image->ID, $field . '_url', true);
|
115 |
-
$target = get_post_meta($image->ID, $field . '_target', true);
|
116 |
-
$array[] = array(
|
117 |
-
'id' => $image->ID,
|
118 |
-
'title' => $title,
|
119 |
-
'caption' => $content,
|
120 |
-
'full_image_url' => $full_url,
|
121 |
-
'thumbnail_image_url' => $thumbnail_url,
|
122 |
-
'large_srcset' => $large_srcset,
|
123 |
-
'medium_srcset' => $medium_srcset,
|
124 |
-
'url' => $url,
|
125 |
-
'target' => $target
|
126 |
-
);
|
127 |
-
endforeach;
|
128 |
-
endif;
|
129 |
-
return $array;
|
130 |
-
}
|
131 |
|
132 |
//Resizes the image
|
133 |
-
|
134 |
-
if( !function_exists('aq_resize') ){
|
135 |
-
require_once( dirname(__FILE__) . '/aq_resizer.php');
|
136 |
-
}
|
137 |
-
$extension = explode('.', $img_url);
|
138 |
-
$extension = strtolower(end($extension));
|
139 |
-
if( $extension != 'svg' ){
|
140 |
-
$img_url = aq_resize( $img_url, $width, $height, true, true, true);
|
141 |
-
}
|
142 |
-
return $img_url;
|
143 |
-
}
|
144 |
-
|
145 |
-
function acf_photo_gallery_image_fields( $args, $attachment_id, $field){
|
146 |
-
return array(
|
147 |
-
'url' => array('type' => 'text', 'label' => 'URL', 'name' => 'url', 'value' => ($args['url'])?$args['url']:null),
|
148 |
-
'target' => array('type' => 'checkbox', 'label' => 'Open in new tab', 'name' => 'target', 'value' => ($args['target'])?$args['target']:null),
|
149 |
-
'title' => array('type' => 'text', 'label' => 'Title', 'name' => 'title', 'value' => ($args['title'])?$args['title']:null),
|
150 |
-
'caption' => array('type' => 'textarea', 'label' => 'Caption', 'name' => 'caption', 'value' => ($args['caption'])?$args['caption']:null)
|
151 |
-
);
|
152 |
-
}
|
153 |
-
add_filter( 'acf_photo_gallery_image_fields', 'acf_photo_gallery_image_fields', 10, 3 );
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
|
|
|
|
|
171 |
|
172 |
-
|
173 |
-
|
3 |
Plugin Name: ACF Photo Gallery Field
|
4 |
Plugin URI: http://www.navz.me/
|
5 |
Description: An extension for Advance Custom Fields which lets you add photo gallery functionality on your websites.
|
6 |
+
Version: 1.6.3
|
7 |
Author: Navneil Naicker
|
8 |
Author URI: http://www.navz.me/
|
9 |
License: GPLv2 or later
|
17 |
// check if class already exists
|
18 |
if( !class_exists('acf_plugin_photo_gallery') ) :
|
19 |
|
20 |
+
class acf_plugin_photo_gallery {
|
21 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
22 |
// vars
|
23 |
+
var $settings;
|
24 |
+
|
25 |
+
/*
|
26 |
+
* __construct
|
27 |
+
*
|
28 |
+
* This function will setup the class functionality
|
29 |
+
*
|
30 |
+
* @type function
|
31 |
+
* @date 17/02/2016
|
32 |
+
* @since 1.0.0
|
33 |
+
*
|
34 |
+
* @param n/a
|
35 |
+
* @return n/a
|
36 |
+
*/
|
37 |
|
38 |
+
function __construct() {
|
39 |
+
|
40 |
+
// vars
|
41 |
+
$this->settings = array(
|
42 |
+
'version' => '1.6.3',
|
43 |
+
'url' => plugin_dir_url( __FILE__ ),
|
44 |
+
'path' => plugin_dir_path( __FILE__ )
|
45 |
+
);
|
46 |
+
|
47 |
+
// set text domain
|
48 |
+
// https://codex.wordpress.org/Function_Reference/load_plugin_textdomain
|
49 |
+
load_plugin_textdomain( 'acf-photo_gallery', false, plugin_basename( dirname( __FILE__ ) ) . '/lang' );
|
50 |
+
|
51 |
+
add_action( 'admin_enqueue_scripts', array($this, 'acf_photo_gallery_sortable') );
|
52 |
+
|
53 |
+
// include field
|
54 |
+
add_action('acf/include_field_types', array($this, 'include_field_types')); // v5
|
55 |
+
add_action('acf/register_fields', array($this, 'include_field_types')); // v4
|
56 |
+
|
57 |
+
add_filter( 'acf_photo_gallery_caption_from_attachment', '__return_false' );
|
58 |
|
59 |
+
// Enable the option show in rest
|
60 |
+
add_filter( 'acf/rest_api/field_settings/show_in_rest', '__return_true' );
|
|
|
61 |
|
62 |
+
// Enable the option edit in rest
|
63 |
+
add_filter( 'acf/rest_api/field_settings/edit_in_rest', '__return_true' );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
64 |
|
65 |
+
//Get ACF Photo Gallery images as JSON object
|
66 |
+
add_filter( 'acf/rest_api/page/get_fields', array($this, 'acf_to_rest_api'), 10, 3 );
|
67 |
+
|
68 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
69 |
|
70 |
+
//Add in jquery-ui-sortable script
|
71 |
+
function acf_photo_gallery_sortable($hook) {
|
72 |
+
if ( 'post.php' == $hook ) { wp_enqueue_script( 'jquery-ui-sortable', 'jquery-ui-sortable', 'jquery', '9999', true); }
|
73 |
+
}
|
74 |
+
|
75 |
+
/*
|
76 |
+
* include_field_types
|
77 |
+
*
|
78 |
+
* This function will include the field type class
|
79 |
+
*
|
80 |
+
* @type function
|
81 |
+
* @date 17/02/2016
|
82 |
+
* @since 1.0.0
|
83 |
+
*
|
84 |
+
* @param $version (int) major ACF version. Defaults to false
|
85 |
+
* @return n/a
|
86 |
+
*/
|
87 |
|
88 |
+
function include_field_types( $version = false ) {
|
89 |
+
|
90 |
+
// support empty $version
|
91 |
+
if( !$version ) $version = 4;
|
92 |
+
|
93 |
+
// include
|
94 |
+
include_once('fields/acf-photo_gallery-v' . $version . '.php');
|
95 |
+
|
96 |
+
}
|
97 |
+
|
98 |
+
//Callback function that will get ACF Photo Gallery images as JSON object
|
99 |
+
function acf_to_rest_api( $data, $request ) {
|
100 |
+
$attributes = $request->get_params();
|
101 |
+
if( !empty($attributes['type']) and $attributes['type'] == 'photo_gallery' ){
|
102 |
+
$post_id = $attributes['id'];
|
103 |
+
$field = $attributes['field'];
|
104 |
+
$type = $attributes['type'];
|
105 |
+
$order = (!empty($attributes['order']))?$attributes['order']:null;
|
106 |
+
$orderby = (!empty($attributes['orderby']))?$attributes['orderby']:null;
|
107 |
+
$data = acf_photo_gallery_make_images($data[$field], $field, $post_id, $order, $orderby);
|
108 |
+
}
|
109 |
+
return $data;
|
110 |
+
}
|
111 |
|
112 |
}
|
|
|
|
|
113 |
|
114 |
+
// initialize
|
115 |
+
new acf_plugin_photo_gallery();
|
116 |
|
117 |
// class_exists check
|
118 |
endif;
|
119 |
|
120 |
//Helper function for pulling the images
|
121 |
+
require_once( dirname(__FILE__) . '/includes/acf_photo_gallery.php' );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
122 |
|
123 |
//Resizes the image
|
124 |
+
require_once( dirname(__FILE__) . '/includes/acf_photo_gallery_resize_image.php' );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
125 |
|
126 |
+
//Set the default fields for the edit gallery
|
127 |
+
require_once( dirname(__FILE__) . '/includes/acf_photo_gallery_image_fields.php' );
|
128 |
|
129 |
+
//Metabox for the photo edit
|
130 |
+
require_once( dirname(__FILE__) . '/includes/acf_photo_gallery_edit.php' );
|
readme.txt
CHANGED
@@ -3,16 +3,15 @@ Contributors: navzme
|
|
3 |
Tags: acf, advanced, custom, fields, photo, gallery, album, fancybox, litebox, lightbox
|
4 |
Requires at least: 3.8
|
5 |
Tested up to: 4.9.6
|
6 |
-
Stable tag: 1.6.
|
7 |
License: GPLv2 or later
|
8 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
9 |
|
10 |
-
A cool plugin that extends the Advanced Custom Fields (ACF) functionality to add
|
11 |
|
12 |
== Description ==
|
13 |
-
This plugin is alternative of ACF Gallery Pro.
|
14 |
|
15 |
-
|
16 |
|
17 |
* Visually create your Fields
|
18 |
* Add multiple photos and you can also modify title, caption and link to anything
|
@@ -21,12 +20,20 @@ We are just a lightweight extension of Advanced Custom Field (ACF) that adds ‘
|
|
21 |
* Uses the native WordPress custom post type for ease of use and fast processing
|
22 |
* Uses the native WordPress metadata for ease of use and fast processing
|
23 |
|
|
|
|
|
|
|
24 |
= Usage =
|
|
|
|
|
|
|
|
|
|
|
25 |
The following example is using Twitter Bootstrap framework to layout. You can use any framework of your choice.
|
26 |
|
27 |
`<?php
|
28 |
//Get the images ids from the post_metadata
|
29 |
-
$images = acf_photo_gallery('
|
30 |
//Check if return array has anything in it
|
31 |
if( count($images) ):
|
32 |
//Cool, we got some data so now let's loop over it
|
@@ -70,16 +77,32 @@ You can use ACF helper function `get_field`
|
|
70 |
|
71 |
= Pull caption from attachment caption field =
|
72 |
By default the caption is being pulled from description field. Add the following filter to your `function.php` to pull the caption from attachment caption field.
|
|
|
73 |
`add_filter( 'acf_photo_gallery_caption_from_attachment', '__return_true' );`
|
74 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
75 |
= Compatibility =
|
76 |
This ACF field type is compatible with:
|
77 |
* ACF 4
|
78 |
-
* ACF 5
|
79 |
|
80 |
= Issues =
|
81 |
-
|
82 |
-
If you want to talk to me directly, you can contact me via my website <https://www.navz.me/>
|
83 |
|
84 |
== Installation ==
|
85 |
|
@@ -89,6 +112,12 @@ If you want to talk to me directly, you can contact me via my website <https://w
|
|
89 |
4. Please refer to the description for more info regarding the field type settings
|
90 |
|
91 |
== Changelog ==
|
|
|
|
|
|
|
|
|
|
|
|
|
92 |
=1.6.2=
|
93 |
* [Bugfix] Keep data synced with the attachment data
|
94 |
* [Bugfix] Pull caption attachment caption using add filters
|
3 |
Tags: acf, advanced, custom, fields, photo, gallery, album, fancybox, litebox, lightbox
|
4 |
Requires at least: 3.8
|
5 |
Tested up to: 4.9.6
|
6 |
+
Stable tag: 1.6.3
|
7 |
License: GPLv2 or later
|
8 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
9 |
|
10 |
+
A cool plugin that extends the Advanced Custom Fields (ACF) functionality to add "Photo Gallery" to any post/pages of your choice.
|
11 |
|
12 |
== Description ==
|
|
|
13 |
|
14 |
+
A lightweight extension of Advanced Custom Field (ACF) that adds **Photo Gallery** field to any post/pages on your WordPress website.
|
15 |
|
16 |
* Visually create your Fields
|
17 |
* Add multiple photos and you can also modify title, caption and link to anything
|
20 |
* Uses the native WordPress custom post type for ease of use and fast processing
|
21 |
* Uses the native WordPress metadata for ease of use and fast processing
|
22 |
|
23 |
+
= Note =
|
24 |
+
This plugin is alternative of ACF Gallery Pro. You need to have knowledge of coding because you’ll be required to edit your WordPress theme source code. If you are looking for shortcodes and prebuilt gallery then this plugin is **NOT** for you. This plugin will give you PHP array of images and you’ll need to make the gallery layout as you wish.
|
25 |
+
|
26 |
= Usage =
|
27 |
+
*acf_photo_gallery* is a helper function that takes in **ACF_FIELD_NAME** and **POST_ID** will query the database and compile the images for you. The output of this function will be an array.
|
28 |
+
|
29 |
+
`acf_photo_gallery(ACF_FIELD_NAME, POST_ID);`
|
30 |
+
|
31 |
+
= Example =
|
32 |
The following example is using Twitter Bootstrap framework to layout. You can use any framework of your choice.
|
33 |
|
34 |
`<?php
|
35 |
//Get the images ids from the post_metadata
|
36 |
+
$images = acf_photo_gallery('vacation_photos', $post->ID);
|
37 |
//Check if return array has anything in it
|
38 |
if( count($images) ):
|
39 |
//Cool, we got some data so now let's loop over it
|
77 |
|
78 |
= Pull caption from attachment caption field =
|
79 |
By default the caption is being pulled from description field. Add the following filter to your `function.php` to pull the caption from attachment caption field.
|
80 |
+
|
81 |
`add_filter( 'acf_photo_gallery_caption_from_attachment', '__return_true' );`
|
82 |
|
83 |
+
= REST API =
|
84 |
+
To use the RESTful feature, you will need to install [ACF to REST API](https://wordpress.org/plugins/acf-to-rest-api/) plugin.
|
85 |
+
|
86 |
+
**How to use?**
|
87 |
+
|
88 |
+
`//Send HTTP Request to URL
|
89 |
+
http://www.example.com/wp-json/acf/v3/pages/POST_ID/ACF_FIELD_NAME?type=photo_gallery`
|
90 |
+
|
91 |
+
Where **POST_ID** refers to your WordPress Post ID and **ACF_FIELD_NAME** refers to ACF Field Name which you are trying to get the value. Below are 2 examples:
|
92 |
+
|
93 |
+
`//Get all the images of POST_ID 2 and ACF FIELD NAME vacation_photos
|
94 |
+
http://www.example.com/wp-json/acf/v3/pages/2/vacation_photos?type=photo_gallery`
|
95 |
+
|
96 |
+
`//Get all the images of POST_ID 2 and ACF FIELD NAM vacation_photos and order the images by ascending order by post_in
|
97 |
+
http://www.example.com/wp-json/acf/v3/pages/2/vacation_photos?type=photo_gallery&order=ASC&orderby=post__in`
|
98 |
+
|
99 |
= Compatibility =
|
100 |
This ACF field type is compatible with:
|
101 |
* ACF 4
|
102 |
+
* ACF 5
|
103 |
|
104 |
= Issues =
|
105 |
+
Just like any other WordPress plugin, this plugin can also cause issues with other themes and plugins. If you are facing issues making this plugin work on your WordPress site, please do ask for help in the support forum. This way we can help you out and prevent this issue from happening to someone else. If you want to talk to me directly, you can contact me via my website <http://www.navz.me/>
|
|
|
106 |
|
107 |
== Installation ==
|
108 |
|
112 |
4. Please refer to the description for more info regarding the field type settings
|
113 |
|
114 |
== Changelog ==
|
115 |
+
=1.6.3=
|
116 |
+
* [Added] Support for ACF 5
|
117 |
+
* [Added] Edit gallery with built-in or WordPress native model. Thanks to Github @makepost
|
118 |
+
* [Added] Under the hood improvements of the codebase
|
119 |
+
* [Added] Support for RESTFul API with ACF to REST API plugin
|
120 |
+
|
121 |
=1.6.2=
|
122 |
* [Bugfix] Keep data synced with the attachment data
|
123 |
* [Bugfix] Pull caption attachment caption using add filters
|