Version Description
Download this release
Release Info
Developer | navzme |
Plugin | ACF Photo Gallery Field |
Version | 1.6.4 |
Comparing to | |
See all releases |
Code changes from version 1.6.3 to 1.6.4
- assets/css/acf-photo-gallery-field.css +74 -74
- assets/css/input.css +74 -74
- assets/js/acf-photo-gallery-field.js +233 -246
- assets/js/input.js +195 -195
- fields/acf-photo_gallery-v4.php +101 -101
- includes/__construct.php +19 -19
- includes/acf_photo_gallery.php +40 -40
- includes/acf_photo_gallery_edit.php +11 -11
- includes/acf_photo_gallery_edit_save.php +46 -46
- includes/acf_photo_gallery_image_fields.php +10 -10
- includes/acf_photo_gallery_metabox_edit.php +22 -22
- includes/acf_photo_gallery_remove_photo.php +30 -30
- includes/acf_photo_gallery_resize_image.php +13 -13
- includes/acf_photo_gallery_save.php +31 -31
- includes/input_admin_enqueue_scripts.php +13 -13
- includes/render_field.php +59 -59
- includes/v4/create_options.php +19 -19
- includes/v5/render_field_settings.php +20 -20
- navz-photo-gallery.php +130 -130
- readme.txt +163 -160
assets/css/acf-photo-gallery-field.css
CHANGED
@@ -1,75 +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 |
}
|
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/css/input.css
CHANGED
@@ -1,75 +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 |
}
|
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
CHANGED
@@ -1,247 +1,234 @@
|
|
1 |
-
(function($) {
|
2 |
-
|
3 |
-
function initialize_field($el) {
|
4 |
-
//$el.doStuff();
|
5 |
-
}
|
6 |
-
|
7 |
-
function acf_photo_gallery_remove_media(
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
html
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
*
|
212 |
-
*
|
213 |
-
*
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
|
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);
|
1 |
+
(function($) {
|
2 |
+
|
3 |
+
function initialize_field($el) {
|
4 |
+
//$el.doStuff();
|
5 |
+
}
|
6 |
+
|
7 |
+
function acf_photo_gallery_remove_media( id, field ){
|
8 |
+
$('.acf-photo-gallery-group-' + field + ' .acf-photo-gallery-mediabox-' + id).fadeOut('fast').remove();
|
9 |
+
if( $('.acf-photo-gallery-group-' + field + ' .acf-photo-gallery-metabox-list li').length < 1 ){
|
10 |
+
$('.acf-photo-gallery-group-' + field + ' .acf-photo-gallery-metabox-list').append('<li class="acf-photo-gallery-media-box-placeholder"><span class="dashicons dashicons-format-image"></span></li>');
|
11 |
+
}
|
12 |
+
}
|
13 |
+
|
14 |
+
$(document).ready(function() {
|
15 |
+
$(".acf-photo-gallery-metabox-list").sortable({
|
16 |
+
containment: "parent",
|
17 |
+
placeholder: "acf-photo-gallery-sortable-placeholder",
|
18 |
+
tolerance: 'pointer'
|
19 |
+
}).disableSelection();
|
20 |
+
});
|
21 |
+
|
22 |
+
function acf_photo_gallery_edit(id, url, title, caption) {
|
23 |
+
var html;
|
24 |
+
html = '<div id="acf-photo-gallery-metabox-edit-' + id + '" class="acf-edit-photo-gallery">';
|
25 |
+
html += '<h3>Edit Image</h3>';
|
26 |
+
html += '<label>URL</label><input type="text" value="' + url + '"/>';
|
27 |
+
html += '<label><input type="checkbox" value="1"/>Open in new tab</label>';
|
28 |
+
html += '<label>Title</label><input type="text" value="' + title + '"/>';
|
29 |
+
html += '<label>Caption</label><textarea>' + caption + '</textarea>';
|
30 |
+
html += '<button class="button button-primary button-large" type="button">Save Changes</button>';
|
31 |
+
html += '<button class="button button-large button-close" type="button" data-close="' + id + '">Close</button>';
|
32 |
+
html += '</div>';
|
33 |
+
return html;
|
34 |
+
}
|
35 |
+
|
36 |
+
/**
|
37 |
+
* @param {{ index: number, splice: number }} options
|
38 |
+
*/
|
39 |
+
function acf_photo_gallery_html(attachment, field, options) {
|
40 |
+
var html, id, url, title, caption;
|
41 |
+
id = attachment.id;
|
42 |
+
url = attachment.url;
|
43 |
+
title = attachment.title;
|
44 |
+
caption = attachment.caption;
|
45 |
+
|
46 |
+
var JsonField = jQuery.parseJSON(field);
|
47 |
+
|
48 |
+
if (typeof attachment.sizes.thumbnail != 'undefined') { url = attachment.sizes.thumbnail.url; }
|
49 |
+
|
50 |
+
html = acf_photo_gallery_edit(id, url, title, caption);
|
51 |
+
$('.acf-photo-gallery-group-' + JsonField.key + ' .acf-photo-gallery-metabox-edit').append(html);
|
52 |
+
var $list = $('.acf-photo-gallery-group-' + JsonField.key + ' .acf-photo-gallery-metabox-list');
|
53 |
+
html = '<li class="acf-photo-gallery-mediabox-' + id + '" data-id="' + id + '"><a class="dashicons dashicons-dismiss" href="#" data-id="' + id + '" data-field="' + JsonField.key + '" title="Remove this photo from the gallery"></a><input type="hidden" name="' + JsonField._name + '[]" value="' + id + '"/><img src="' + url + '"/></li>';
|
54 |
+
if (options.index) {
|
55 |
+
var $cursor = $list.children().eq(options.index);
|
56 |
+
$cursor.before(html);
|
57 |
+
if (options.splice) { $cursor.remove(); }
|
58 |
+
} else {
|
59 |
+
$list.prepend(html);
|
60 |
+
}
|
61 |
+
}
|
62 |
+
|
63 |
+
function acf_photo_gallery_add_media($el) {
|
64 |
+
var acf_photo_gallery_ids = new Array();
|
65 |
+
if ($('.acf-photo-gallery-metabox-add-images').length > 0) {
|
66 |
+
if (typeof wp !== 'undefined' && wp.media && wp.media.editor) {
|
67 |
+
$(document).on('click', '.acf-photo-gallery-metabox-add-images', function(e) {
|
68 |
+
e.preventDefault();
|
69 |
+
var button = $(this);
|
70 |
+
var id = button.prev();
|
71 |
+
var field = button.attr('data-field');
|
72 |
+
var JsonField = jQuery.parseJSON(field);
|
73 |
+
|
74 |
+
var pre_selected_list = $('.acf-photo-gallery-group-' + JsonField.key + ' .acf-photo-gallery-metabox-list li');
|
75 |
+
var pre_selected = pre_selected_list.length;
|
76 |
+
|
77 |
+
wp.media.editor.send.attachment = function(props, attachment){
|
78 |
+
acf_photo_gallery_html(attachment, field, { index: 0, splice: 0 });
|
79 |
+
};
|
80 |
+
|
81 |
+
wp.media.editor.open( button, function(){} );
|
82 |
+
if ($('.acf-photo-gallery-group-' + JsonField.key + ' .acf-photo-gallery-metabox-list li.acf-photo-gallery-media-box-placeholder').length > 0) {
|
83 |
+
$('.acf-photo-gallery-group-' + JsonField.key + ' .acf-photo-gallery-metabox-list li.acf-photo-gallery-media-box-placeholder').remove();
|
84 |
+
}
|
85 |
+
|
86 |
+
return false;
|
87 |
+
});
|
88 |
+
}
|
89 |
+
};
|
90 |
+
}
|
91 |
+
|
92 |
+
$(document).on('click', '.acf-photo-gallery-metabox-list .dashicons-dismiss', function(){
|
93 |
+
var id = $(this).attr('data-id');
|
94 |
+
var field = $(this).attr('data-field');
|
95 |
+
if (confirm('You are about to remove this photo from the gallery. Are you sure?')){
|
96 |
+
acf_photo_gallery_remove_media(id, field);
|
97 |
+
}
|
98 |
+
return false;
|
99 |
+
});
|
100 |
+
|
101 |
+
$(document).on('click', '#acf-photo-gallery-metabox-edit .acf-edit-photo-gallery button.button-close', function() {
|
102 |
+
var id;
|
103 |
+
id = $(this).attr('data-close');
|
104 |
+
$('#acf-photo-gallery-metabox-edit #acf-photo-gallery-metabox-edit-' + id).fadeOut('fast');
|
105 |
+
return false;
|
106 |
+
});
|
107 |
+
|
108 |
+
$(document).on('click', '#acf-photo-gallery-metabox-edit .acf-edit-photo-gallery button.button-primary', function() {
|
109 |
+
var button, field, data, post, attachment, action, nonce, form = {};
|
110 |
+
url = $(this).attr('data-ajaxurl');
|
111 |
+
action = 'acf_photo_gallery_edit_save';
|
112 |
+
attachment = $(this).attr('data-id');
|
113 |
+
|
114 |
+
$('#acf-photo-gallery-metabox-edit-' + attachment + ' .acf-photo-gallery-edit-field').each(function(i, obj) {
|
115 |
+
if (obj.name == 'acf-pg-hidden-action') {
|
116 |
+
form['action'] = obj.value;
|
117 |
+
} else if( obj.type == 'checkbox'){
|
118 |
+
if( $(this).prop("checked") ){
|
119 |
+
form[obj.name] = obj.value;
|
120 |
+
} else {
|
121 |
+
form[obj.name] = null;
|
122 |
+
}
|
123 |
+
} else {
|
124 |
+
form[obj.name] = obj.value;
|
125 |
+
}
|
126 |
+
});
|
127 |
+
|
128 |
+
button = $(this);
|
129 |
+
button.attr('disabled', true).html('Saving...');
|
130 |
+
$.post(url, form, function(data) {
|
131 |
+
button.attr('disabled', false).html('Save Changes');
|
132 |
+
$('#acf-photo-gallery-metabox-edit #acf-photo-gallery-metabox-edit-' + attachment).fadeOut('fast');
|
133 |
+
});
|
134 |
+
return false;
|
135 |
+
});
|
136 |
+
|
137 |
+
$(document).on('click', '.acf-photo-gallery-metabox-list .dashicons-edit', function() {
|
138 |
+
var $btn = $(this);
|
139 |
+
var id = $btn.attr('data-id');
|
140 |
+
var field = $btn.attr('data-field');
|
141 |
+
var modal = $('.acf-photo-gallery-group-' + field + ' input[name="acf-photo-gallery-edit-modal"]').val();
|
142 |
+
var $list = $('.acf-photo-gallery-group-' + field + ' ul.acf-photo-gallery-metabox-list');
|
143 |
+
var index = $('.acf-photo-gallery-group-' + field + ' ul.acf-photo-gallery-metabox-list li').index();
|
144 |
+
|
145 |
+
if (modal === 'Native') {
|
146 |
+
wp.media.editor.send.attachment = function(_, attachment){
|
147 |
+
acf_photo_gallery_html(attachment, field, {
|
148 |
+
index: index,
|
149 |
+
splice: 1
|
150 |
+
});
|
151 |
+
};
|
152 |
+
|
153 |
+
var editor = wp.media.editor.open($btn, function() {}).state();
|
154 |
+
editor.set('menu', false);
|
155 |
+
|
156 |
+
var selection = editor.get('selection');
|
157 |
+
selection.multiple = false;
|
158 |
+
selection.reset([wp.media.attachment(id)]);
|
159 |
+
|
160 |
+
/**
|
161 |
+
* @param {{ id: number }} deleted
|
162 |
+
*/
|
163 |
+
var handleDestroy = function (deleted) {
|
164 |
+
$list.children().each(function () {
|
165 |
+
var $elem = $(this);
|
166 |
+
|
167 |
+
if ($elem.data('id') === deleted.id) {
|
168 |
+
remove($elem.find('.dashicons-dismiss'));
|
169 |
+
}
|
170 |
+
});
|
171 |
+
};
|
172 |
+
|
173 |
+
var library = editor.get('library');
|
174 |
+
library.on('destroy', handleDestroy);
|
175 |
+
|
176 |
+
editor.on('close', function () {
|
177 |
+
library.off('destroy', handleDestroy);
|
178 |
+
});
|
179 |
+
|
180 |
+
$('.acf-photo-gallery-group-' + field + ' .acf-photo-gallery-metabox-list li.acf-photo-gallery-media-box-placeholder').remove();
|
181 |
+
} else {
|
182 |
+
$('.acf-photo-gallery-group-' + field + ' #acf-photo-gallery-metabox-edit-' + id).fadeToggle('fast');
|
183 |
+
}
|
184 |
+
|
185 |
+
return false;
|
186 |
+
});
|
187 |
+
|
188 |
+
if (typeof acf.add_action !== 'undefined') {
|
189 |
+
/*
|
190 |
+
* ready append (ACF5)
|
191 |
+
*
|
192 |
+
* These are 2 events which are fired during the page load
|
193 |
+
* ready = on page load similar to $(document).ready()
|
194 |
+
* append = on new DOM elements appended via repeater field
|
195 |
+
*
|
196 |
+
* @type event
|
197 |
+
* @date 20/07/13
|
198 |
+
*
|
199 |
+
* @param $el (jQuery selection) the jQuery element which contains the ACF fields
|
200 |
+
* @return n/a
|
201 |
+
*/
|
202 |
+
acf.add_action('ready append', function($el) {
|
203 |
+
// search $el for fields of type 'photo_gallery'
|
204 |
+
acf.get_fields({ type: 'photo_gallery' }, $el).each(function() {
|
205 |
+
initialize_field($(this));
|
206 |
+
acf_photo_gallery_add_media( $(this) );
|
207 |
+
});
|
208 |
+
});
|
209 |
+
} else {
|
210 |
+
/*
|
211 |
+
* acf/setup_fields (ACF4)
|
212 |
+
*
|
213 |
+
* This event is triggered when ACF adds any new elements to the DOM.
|
214 |
+
*
|
215 |
+
* @type function
|
216 |
+
* @since 1.0.0
|
217 |
+
* @date 01/01/12
|
218 |
+
*
|
219 |
+
* @param event e: an event object. This can be ignored
|
220 |
+
* @param Element postbox: An element which contains the new HTML
|
221 |
+
*
|
222 |
+
* @return n/a
|
223 |
+
*/
|
224 |
+
$(document).on('acf/setup_fields', function(e, postbox) {
|
225 |
+
$(postbox).find('.field[data-field_type="photo_gallery"]').each(function() {
|
226 |
+
initialize_field($(this));
|
227 |
+
acf_photo_gallery_add_media( $(this) );
|
228 |
+
//acf_photo_gallery_edit_popover( $(this) );
|
229 |
+
//acf_photo_gallery_limit_images( $(this) );
|
230 |
+
});
|
231 |
+
});
|
232 |
+
}
|
233 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
234 |
})(jQuery);
|
assets/js/input.js
CHANGED
@@ -1,196 +1,196 @@
|
|
1 |
-
(function($) {
|
2 |
-
|
3 |
-
function initialize_field($el) {
|
4 |
-
//$el.doStuff();
|
5 |
-
}
|
6 |
-
|
7 |
-
$(document).ready(function() {
|
8 |
-
$(".acf-photo-gallery-metabox-list").sortable({
|
9 |
-
containment: "parent",
|
10 |
-
placeholder: "acf-photo-gallery-sortable-placeholder",
|
11 |
-
tolerance: 'pointer'
|
12 |
-
}).disableSelection();
|
13 |
-
});
|
14 |
-
|
15 |
-
/*function acf_photo_gallery_limit_images( $el ){
|
16 |
-
var field = $el.context.id;
|
17 |
-
$(document).on('click', '.attachments-browser ul.attachments li.attachment', function(){
|
18 |
-
var max = $('#' + field + ' input[name="acf-photo-gallery-field-max"]').val();
|
19 |
-
var selCount = $('#' + field + ' .acf-photo-gallery-metabox-list li').length;
|
20 |
-
var count = $('.attachments-browser ul.attachments li.attachment[aria-checked=true]').length;
|
21 |
-
var finalCount = selCount + +count;
|
22 |
-
if( finalCount > max ){
|
23 |
-
alert('You are only allowed to select maximum of ' + max + ' images.');
|
24 |
-
$(this).attr('aria-checked', false).removeClass('selected details');
|
25 |
-
return false;
|
26 |
-
}
|
27 |
-
});
|
28 |
-
}*/
|
29 |
-
|
30 |
-
function acf_photo_gallery_edit(id, url, title, caption) {
|
31 |
-
var html;
|
32 |
-
html = '<div id="acf-photo-gallery-metabox-edit-' + id + '" class="acf-edit-photo-gallery">';
|
33 |
-
html += '<h3>Edit Image</h3>';
|
34 |
-
html += '<label>URL</label><input type="text" value="' + url + '"/>';
|
35 |
-
html += '<label><input type="checkbox" value="1"/>Open in new tab</label>';
|
36 |
-
html += '<label>Title</label><input type="text" value="' + title + '"/>';
|
37 |
-
html += '<label>Caption</label><textarea>' + caption + '</textarea>';
|
38 |
-
html += '<button class="button button-primary button-large" type="button">Save Changes</button>';
|
39 |
-
html += '<button class="button button-large button-close" type="button" data-close="' + id + '">Close</button>';
|
40 |
-
html += '</div>';
|
41 |
-
return html;
|
42 |
-
}
|
43 |
-
|
44 |
-
function acf_photo_gallery_html(attachment, field) {
|
45 |
-
var html, id, url, title, caption;
|
46 |
-
id = attachment.id;
|
47 |
-
url = attachment.url;
|
48 |
-
title = attachment.title;
|
49 |
-
caption = attachment.caption;
|
50 |
-
|
51 |
-
if (typeof attachment.sizes.thumbnail != 'undefined') {
|
52 |
-
url = attachment.sizes.thumbnail.url
|
53 |
-
}
|
54 |
-
|
55 |
-
html = acf_photo_gallery_edit(id, url, title, caption);
|
56 |
-
$('#acf-' + field + ' .acf-photo-gallery-metabox-edit').append(html);
|
57 |
-
$('#acf-' + field + ' .acf-photo-gallery-metabox-list').prepend('<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="' + field + '[]" value="' + id + '"/><img src="' + url + '"/></li>');
|
58 |
-
}
|
59 |
-
|
60 |
-
function acf_photo_gallery_add_media($el) {
|
61 |
-
var acf_photo_gallery_ids = new Array();
|
62 |
-
if ($('#acf-photo-gallery-metabox-add-images').length > 0) {
|
63 |
-
if (typeof wp !== 'undefined' && wp.media && wp.media.editor) {
|
64 |
-
$('.wrap').on('click', '#acf-photo-gallery-metabox-add-images', function(e) {
|
65 |
-
e.preventDefault();
|
66 |
-
var button = $(this);
|
67 |
-
var id = button.prev();
|
68 |
-
var field = button.attr('data-id');
|
69 |
-
|
70 |
-
var pre_selected_list = $('#acf-' + field + ' .acf-photo-gallery-metabox-list li');
|
71 |
-
var pre_selected = pre_selected_list.length;
|
72 |
-
|
73 |
-
wp.media.editor.send.attachment = function(props, attachment){
|
74 |
-
acf_photo_gallery_html(attachment, field);
|
75 |
-
};
|
76 |
-
|
77 |
-
wp.media.editor.open( button, function(){} );
|
78 |
-
if ($('#acf-' + field + ' .acf-photo-gallery-metabox-list li.acf-photo-gallery-media-box-placeholder').length > 0) {
|
79 |
-
$('#acf-' + field + ' .acf-photo-gallery-metabox-list li.acf-photo-gallery-media-box-placeholder').remove();
|
80 |
-
}
|
81 |
-
|
82 |
-
/*if( pre_selected > 0 ){
|
83 |
-
pre_selected_list.each(function( key, item ){
|
84 |
-
var pre_selected_id = $(this).attr('data-id');
|
85 |
-
//$('.attachments-browser ul.attachments li[data-id=' + pre_selected_id + ']').attr('aria-checked', true).addClass('details selected');
|
86 |
-
console.log( $('.attachments-browser ul.attachments li[data-id=269]').attr('class') );
|
87 |
-
$('.attachments-browser ul.attachments li[data-id="' + pre_selected_id + '"]').attr('aria-checked', true);
|
88 |
-
});
|
89 |
-
}*/
|
90 |
-
|
91 |
-
return false;
|
92 |
-
});
|
93 |
-
}
|
94 |
-
};
|
95 |
-
}
|
96 |
-
|
97 |
-
$(document).on('click', '.acf-photo-gallery-metabox-list .dashicons-dismiss', function() {
|
98 |
-
var url = $(this).attr('href');
|
99 |
-
var id = $(this).attr('data-id');
|
100 |
-
var field = $(this).attr('data-field');
|
101 |
-
if (confirm('You are about to remove this photo from the gallery. Are you sure?')) {
|
102 |
-
$.get(url, function(data) {
|
103 |
-
$('#acf-' + field + ' #acf-photo-gallery-mediabox-' + id).fadeOut('fast').remove();
|
104 |
-
if ($('#acf-' + field + ' .acf-photo-gallery-metabox-list li').length < 1) {
|
105 |
-
$('#acf-' + field + ' .acf-photo-gallery-metabox-list').append('<li class="acf-photo-gallery-media-box-placeholder"><span class="dashicons dashicons-format-image"></span></li>');
|
106 |
-
}
|
107 |
-
});
|
108 |
-
}
|
109 |
-
return false;
|
110 |
-
});
|
111 |
-
|
112 |
-
$(document).on('click', '#acf-photo-gallery-metabox-edit .acf-edit-photo-gallery button.button-close', function() {
|
113 |
-
var id;
|
114 |
-
id = $(this).attr('data-close');
|
115 |
-
$('#acf-photo-gallery-metabox-edit #acf-photo-gallery-metabox-edit-' + id).fadeOut('fast');
|
116 |
-
return false;
|
117 |
-
});
|
118 |
-
|
119 |
-
$(document).on('click', '#acf-photo-gallery-metabox-edit .acf-edit-photo-gallery button.button-primary', function() {
|
120 |
-
var button, field, data, post, attachment, action, nonce, form = {};
|
121 |
-
action = 'acf_photo_gallery_edit_save';
|
122 |
-
attachment = $(this).attr('data-id');
|
123 |
-
|
124 |
-
$('#acf-photo-gallery-metabox-edit-' + attachment + ' .acf-photo-gallery-edit-field').each(function(i, obj) {
|
125 |
-
if (obj.name == 'acf-pg-hidden-action') {
|
126 |
-
form['action'] = obj.value;
|
127 |
-
} else {
|
128 |
-
form[obj.name] = obj.value;
|
129 |
-
}
|
130 |
-
});
|
131 |
-
|
132 |
-
button = $(this);
|
133 |
-
button.attr('disabled', true).html('Saving...');
|
134 |
-
$.post(acf.ajaxurl, form, function(data) {
|
135 |
-
button.attr('disabled', false).html('Save Changes');
|
136 |
-
$('#acf-photo-gallery-metabox-edit #acf-photo-gallery-metabox-edit-' + attachment).fadeOut('fast');
|
137 |
-
});
|
138 |
-
return false;
|
139 |
-
});
|
140 |
-
|
141 |
-
$(document).on('click', '.acf-photo-gallery-metabox-list .dashicons-edit', function() {
|
142 |
-
var id, field;
|
143 |
-
id = $(this).attr('data-id');
|
144 |
-
field = $(this).attr('data-field');
|
145 |
-
$('#acf-' + field + ' #acf-photo-gallery-metabox-edit-' + id).fadeToggle('fast');
|
146 |
-
return false;
|
147 |
-
});
|
148 |
-
|
149 |
-
if (typeof acf.add_action !== 'undefined') {
|
150 |
-
/*
|
151 |
-
* ready append (ACF5)
|
152 |
-
*
|
153 |
-
* These are 2 events which are fired during the page load
|
154 |
-
* ready = on page load similar to $(document).ready()
|
155 |
-
* append = on new DOM elements appended via repeater field
|
156 |
-
*
|
157 |
-
* @type event
|
158 |
-
* @date 20/07/13
|
159 |
-
*
|
160 |
-
* @param $el (jQuery selection) the jQuery element which contains the ACF fields
|
161 |
-
* @return n/a
|
162 |
-
*/
|
163 |
-
acf.add_action('ready append', function($el) {
|
164 |
-
// search $el for fields of type 'photo_gallery'
|
165 |
-
acf.get_fields({ type: 'photo_gallery' }, $el).each(function() {
|
166 |
-
initialize_field($(this));
|
167 |
-
acf_photo_gallery_add_media( $(this) );
|
168 |
-
//acf_photo_gallery_edit_popover( $(this) );
|
169 |
-
//acf_photo_gallery_limit_images( $(this) );
|
170 |
-
});
|
171 |
-
});
|
172 |
-
} else {
|
173 |
-
/*
|
174 |
-
* acf/setup_fields (ACF4)
|
175 |
-
*
|
176 |
-
* This event is triggered when ACF adds any new elements to the DOM.
|
177 |
-
*
|
178 |
-
* @type function
|
179 |
-
* @since 1.0.0
|
180 |
-
* @date 01/01/12
|
181 |
-
*
|
182 |
-
* @param event e: an event object. This can be ignored
|
183 |
-
* @param Element postbox: An element which contains the new HTML
|
184 |
-
*
|
185 |
-
* @return n/a
|
186 |
-
*/
|
187 |
-
$(document).on('acf/setup_fields', function(e, postbox) {
|
188 |
-
$(postbox).find('.field[data-field_type="photo_gallery"]').each(function() {
|
189 |
-
initialize_field($(this));
|
190 |
-
acf_photo_gallery_add_media( $(this) );
|
191 |
-
//acf_photo_gallery_edit_popover( $(this) );
|
192 |
-
//acf_photo_gallery_limit_images( $(this) );
|
193 |
-
});
|
194 |
-
});
|
195 |
-
}
|
196 |
})(jQuery);
|
1 |
+
(function($) {
|
2 |
+
|
3 |
+
function initialize_field($el) {
|
4 |
+
//$el.doStuff();
|
5 |
+
}
|
6 |
+
|
7 |
+
$(document).ready(function() {
|
8 |
+
$(".acf-photo-gallery-metabox-list").sortable({
|
9 |
+
containment: "parent",
|
10 |
+
placeholder: "acf-photo-gallery-sortable-placeholder",
|
11 |
+
tolerance: 'pointer'
|
12 |
+
}).disableSelection();
|
13 |
+
});
|
14 |
+
|
15 |
+
/*function acf_photo_gallery_limit_images( $el ){
|
16 |
+
var field = $el.context.id;
|
17 |
+
$(document).on('click', '.attachments-browser ul.attachments li.attachment', function(){
|
18 |
+
var max = $('#' + field + ' input[name="acf-photo-gallery-field-max"]').val();
|
19 |
+
var selCount = $('#' + field + ' .acf-photo-gallery-metabox-list li').length;
|
20 |
+
var count = $('.attachments-browser ul.attachments li.attachment[aria-checked=true]').length;
|
21 |
+
var finalCount = selCount + +count;
|
22 |
+
if( finalCount > max ){
|
23 |
+
alert('You are only allowed to select maximum of ' + max + ' images.');
|
24 |
+
$(this).attr('aria-checked', false).removeClass('selected details');
|
25 |
+
return false;
|
26 |
+
}
|
27 |
+
});
|
28 |
+
}*/
|
29 |
+
|
30 |
+
function acf_photo_gallery_edit(id, url, title, caption) {
|
31 |
+
var html;
|
32 |
+
html = '<div id="acf-photo-gallery-metabox-edit-' + id + '" class="acf-edit-photo-gallery">';
|
33 |
+
html += '<h3>Edit Image</h3>';
|
34 |
+
html += '<label>URL</label><input type="text" value="' + url + '"/>';
|
35 |
+
html += '<label><input type="checkbox" value="1"/>Open in new tab</label>';
|
36 |
+
html += '<label>Title</label><input type="text" value="' + title + '"/>';
|
37 |
+
html += '<label>Caption</label><textarea>' + caption + '</textarea>';
|
38 |
+
html += '<button class="button button-primary button-large" type="button">Save Changes</button>';
|
39 |
+
html += '<button class="button button-large button-close" type="button" data-close="' + id + '">Close</button>';
|
40 |
+
html += '</div>';
|
41 |
+
return html;
|
42 |
+
}
|
43 |
+
|
44 |
+
function acf_photo_gallery_html(attachment, field) {
|
45 |
+
var html, id, url, title, caption;
|
46 |
+
id = attachment.id;
|
47 |
+
url = attachment.url;
|
48 |
+
title = attachment.title;
|
49 |
+
caption = attachment.caption;
|
50 |
+
|
51 |
+
if (typeof attachment.sizes.thumbnail != 'undefined') {
|
52 |
+
url = attachment.sizes.thumbnail.url
|
53 |
+
}
|
54 |
+
|
55 |
+
html = acf_photo_gallery_edit(id, url, title, caption);
|
56 |
+
$('#acf-' + field + ' .acf-photo-gallery-metabox-edit').append(html);
|
57 |
+
$('#acf-' + field + ' .acf-photo-gallery-metabox-list').prepend('<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="' + field + '[]" value="' + id + '"/><img src="' + url + '"/></li>');
|
58 |
+
}
|
59 |
+
|
60 |
+
function acf_photo_gallery_add_media($el) {
|
61 |
+
var acf_photo_gallery_ids = new Array();
|
62 |
+
if ($('#acf-photo-gallery-metabox-add-images').length > 0) {
|
63 |
+
if (typeof wp !== 'undefined' && wp.media && wp.media.editor) {
|
64 |
+
$('.wrap').on('click', '#acf-photo-gallery-metabox-add-images', function(e) {
|
65 |
+
e.preventDefault();
|
66 |
+
var button = $(this);
|
67 |
+
var id = button.prev();
|
68 |
+
var field = button.attr('data-id');
|
69 |
+
|
70 |
+
var pre_selected_list = $('#acf-' + field + ' .acf-photo-gallery-metabox-list li');
|
71 |
+
var pre_selected = pre_selected_list.length;
|
72 |
+
|
73 |
+
wp.media.editor.send.attachment = function(props, attachment){
|
74 |
+
acf_photo_gallery_html(attachment, field);
|
75 |
+
};
|
76 |
+
|
77 |
+
wp.media.editor.open( button, function(){} );
|
78 |
+
if ($('#acf-' + field + ' .acf-photo-gallery-metabox-list li.acf-photo-gallery-media-box-placeholder').length > 0) {
|
79 |
+
$('#acf-' + field + ' .acf-photo-gallery-metabox-list li.acf-photo-gallery-media-box-placeholder').remove();
|
80 |
+
}
|
81 |
+
|
82 |
+
/*if( pre_selected > 0 ){
|
83 |
+
pre_selected_list.each(function( key, item ){
|
84 |
+
var pre_selected_id = $(this).attr('data-id');
|
85 |
+
//$('.attachments-browser ul.attachments li[data-id=' + pre_selected_id + ']').attr('aria-checked', true).addClass('details selected');
|
86 |
+
console.log( $('.attachments-browser ul.attachments li[data-id=269]').attr('class') );
|
87 |
+
$('.attachments-browser ul.attachments li[data-id="' + pre_selected_id + '"]').attr('aria-checked', true);
|
88 |
+
});
|
89 |
+
}*/
|
90 |
+
|
91 |
+
return false;
|
92 |
+
});
|
93 |
+
}
|
94 |
+
};
|
95 |
+
}
|
96 |
+
|
97 |
+
$(document).on('click', '.acf-photo-gallery-metabox-list .dashicons-dismiss', function() {
|
98 |
+
var url = $(this).attr('href');
|
99 |
+
var id = $(this).attr('data-id');
|
100 |
+
var field = $(this).attr('data-field');
|
101 |
+
if (confirm('You are about to remove this photo from the gallery. Are you sure?')) {
|
102 |
+
$.get(url, function(data) {
|
103 |
+
$('#acf-' + field + ' #acf-photo-gallery-mediabox-' + id).fadeOut('fast').remove();
|
104 |
+
if ($('#acf-' + field + ' .acf-photo-gallery-metabox-list li').length < 1) {
|
105 |
+
$('#acf-' + field + ' .acf-photo-gallery-metabox-list').append('<li class="acf-photo-gallery-media-box-placeholder"><span class="dashicons dashicons-format-image"></span></li>');
|
106 |
+
}
|
107 |
+
});
|
108 |
+
}
|
109 |
+
return false;
|
110 |
+
});
|
111 |
+
|
112 |
+
$(document).on('click', '#acf-photo-gallery-metabox-edit .acf-edit-photo-gallery button.button-close', function() {
|
113 |
+
var id;
|
114 |
+
id = $(this).attr('data-close');
|
115 |
+
$('#acf-photo-gallery-metabox-edit #acf-photo-gallery-metabox-edit-' + id).fadeOut('fast');
|
116 |
+
return false;
|
117 |
+
});
|
118 |
+
|
119 |
+
$(document).on('click', '#acf-photo-gallery-metabox-edit .acf-edit-photo-gallery button.button-primary', function() {
|
120 |
+
var button, field, data, post, attachment, action, nonce, form = {};
|
121 |
+
action = 'acf_photo_gallery_edit_save';
|
122 |
+
attachment = $(this).attr('data-id');
|
123 |
+
|
124 |
+
$('#acf-photo-gallery-metabox-edit-' + attachment + ' .acf-photo-gallery-edit-field').each(function(i, obj) {
|
125 |
+
if (obj.name == 'acf-pg-hidden-action') {
|
126 |
+
form['action'] = obj.value;
|
127 |
+
} else {
|
128 |
+
form[obj.name] = obj.value;
|
129 |
+
}
|
130 |
+
});
|
131 |
+
|
132 |
+
button = $(this);
|
133 |
+
button.attr('disabled', true).html('Saving...');
|
134 |
+
$.post(acf.ajaxurl, form, function(data) {
|
135 |
+
button.attr('disabled', false).html('Save Changes');
|
136 |
+
$('#acf-photo-gallery-metabox-edit #acf-photo-gallery-metabox-edit-' + attachment).fadeOut('fast');
|
137 |
+
});
|
138 |
+
return false;
|
139 |
+
});
|
140 |
+
|
141 |
+
$(document).on('click', '.acf-photo-gallery-metabox-list .dashicons-edit', function() {
|
142 |
+
var id, field;
|
143 |
+
id = $(this).attr('data-id');
|
144 |
+
field = $(this).attr('data-field');
|
145 |
+
$('#acf-' + field + ' #acf-photo-gallery-metabox-edit-' + id).fadeToggle('fast');
|
146 |
+
return false;
|
147 |
+
});
|
148 |
+
|
149 |
+
if (typeof acf.add_action !== 'undefined') {
|
150 |
+
/*
|
151 |
+
* ready append (ACF5)
|
152 |
+
*
|
153 |
+
* These are 2 events which are fired during the page load
|
154 |
+
* ready = on page load similar to $(document).ready()
|
155 |
+
* append = on new DOM elements appended via repeater field
|
156 |
+
*
|
157 |
+
* @type event
|
158 |
+
* @date 20/07/13
|
159 |
+
*
|
160 |
+
* @param $el (jQuery selection) the jQuery element which contains the ACF fields
|
161 |
+
* @return n/a
|
162 |
+
*/
|
163 |
+
acf.add_action('ready append', function($el) {
|
164 |
+
// search $el for fields of type 'photo_gallery'
|
165 |
+
acf.get_fields({ type: 'photo_gallery' }, $el).each(function() {
|
166 |
+
initialize_field($(this));
|
167 |
+
acf_photo_gallery_add_media( $(this) );
|
168 |
+
//acf_photo_gallery_edit_popover( $(this) );
|
169 |
+
//acf_photo_gallery_limit_images( $(this) );
|
170 |
+
});
|
171 |
+
});
|
172 |
+
} else {
|
173 |
+
/*
|
174 |
+
* acf/setup_fields (ACF4)
|
175 |
+
*
|
176 |
+
* This event is triggered when ACF adds any new elements to the DOM.
|
177 |
+
*
|
178 |
+
* @type function
|
179 |
+
* @since 1.0.0
|
180 |
+
* @date 01/01/12
|
181 |
+
*
|
182 |
+
* @param event e: an event object. This can be ignored
|
183 |
+
* @param Element postbox: An element which contains the new HTML
|
184 |
+
*
|
185 |
+
* @return n/a
|
186 |
+
*/
|
187 |
+
$(document).on('acf/setup_fields', function(e, postbox) {
|
188 |
+
$(postbox).find('.field[data-field_type="photo_gallery"]').each(function() {
|
189 |
+
initialize_field($(this));
|
190 |
+
acf_photo_gallery_add_media( $(this) );
|
191 |
+
//acf_photo_gallery_edit_popover( $(this) );
|
192 |
+
//acf_photo_gallery_limit_images( $(this) );
|
193 |
+
});
|
194 |
+
});
|
195 |
+
}
|
196 |
})(jQuery);
|
fields/acf-photo_gallery-v4.php
CHANGED
@@ -1,102 +1,102 @@
|
|
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 |
-
// 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;
|
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 |
+
// 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;
|
includes/__construct.php
CHANGED
@@ -1,19 +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;
|
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
CHANGED
@@ -1,41 +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 |
}
|
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
CHANGED
@@ -1,11 +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 |
-
}
|
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
CHANGED
@@ -1,46 +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' );
|
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
CHANGED
@@ -1,10 +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 );
|
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
CHANGED
@@ -1,23 +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>
|
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
CHANGED
@@ -1,30 +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' );
|
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
CHANGED
@@ -1,14 +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 |
}
|
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
CHANGED
@@ -1,31 +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' );
|
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/input_admin_enqueue_scripts.php
CHANGED
@@ -1,14 +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');
|
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
CHANGED
@@ -1,60 +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
|
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>
|
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 $key; ?>" 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
CHANGED
@@ -1,20 +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>
|
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/v5/render_field_settings.php
CHANGED
@@ -1,21 +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 |
));
|
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
@@ -1,130 +1,130 @@
|
|
1 |
-
<?php
|
2 |
-
/*
|
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
|
10 |
-
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
11 |
-
*/
|
12 |
-
|
13 |
-
// exit if accessed directly
|
14 |
-
if( ! defined( 'ABSPATH' ) ) exit;
|
15 |
-
|
16 |
-
|
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.
|
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' );
|
1 |
+
<?php
|
2 |
+
/*
|
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.4
|
7 |
+
Author: Navneil Naicker
|
8 |
+
Author URI: http://www.navz.me/
|
9 |
+
License: GPLv2 or later
|
10 |
+
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
11 |
+
*/
|
12 |
+
|
13 |
+
// exit if accessed directly
|
14 |
+
if( ! defined( 'ABSPATH' ) ) exit;
|
15 |
+
|
16 |
+
|
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.4',
|
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
@@ -1,161 +1,164 @@
|
|
1 |
-
=== ACF Photo Gallery Field ===
|
2 |
-
Contributors: navzme
|
3 |
-
Tags: acf, advanced, custom, fields, photo, gallery, album, fancybox, litebox, lightbox
|
4 |
-
Requires at least: 3.8
|
5 |
-
Tested up to:
|
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 "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
|
18 |
-
* Assign your fields to multiple edit pages (via custom location rules)
|
19 |
-
* Easily load data through a simple and friendly API
|
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
|
40 |
-
foreach($images as $image):
|
41 |
-
$id = $image['id']; // The attachment id of the media
|
42 |
-
$title = $image['title']; //The title
|
43 |
-
$caption= $image['caption']; //The caption
|
44 |
-
$full_image_url= $image['full_image_url']; //Full size image url
|
45 |
-
$full_image_url = acf_photo_gallery_resize_image($full_image_url, 262, 160); //Resized size to 262px width by 160px height image url
|
46 |
-
$thumbnail_image_url= $image['thumbnail_image_url']; //Get the thumbnail size image url 150px by 150px
|
47 |
-
$url= $image['url']; //Goto any link when clicked
|
48 |
-
$target= $image['target']; //Open normal or new tab
|
49 |
-
$alt = get_field('photo_gallery_alt', $id); //Get the alt which is a extra field (See below how to add extra fields)
|
50 |
-
$class = get_field('photo_gallery_class', $id); //Get the class which is a extra field (See below how to add extra fields)
|
51 |
-
?>
|
52 |
-
<div class="col-xs-6 col-md-3">
|
53 |
-
<div class="thumbnail">
|
54 |
-
<?php if( !empty($url) ){ ?><a href="<?php echo $url; ?>" <?php echo ($target == 'true' )? 'target="_blank"': ''; ?>><?php } ?>
|
55 |
-
<img src="<?php echo $full_image_url; ?>" alt="<?php echo $title; ?>" title="<?php echo $title; ?>">
|
56 |
-
<?php if( !empty($url) ){ ?></a><?php } ?>
|
57 |
-
</div>
|
58 |
-
</div>
|
59 |
-
<?php endforeach; endif; ?>`
|
60 |
-
|
61 |
-
= Add Extra Fields =
|
62 |
-
To add extra fields add the following to your themes functions.php file.
|
63 |
-
|
64 |
-
`//Create extra fields called Altnative Text and Custom Classess
|
65 |
-
function my_extra_gallery_fields( $args, $attachment_id, $field ){
|
66 |
-
$args['alt'] = array('type' => 'text', 'label' => 'Altnative Text', 'name' => 'alt', 'value' => get_field($field . '_alt', $attachment_id) ); // Creates Altnative Text field
|
67 |
-
$args['class'] = array('type' => 'text', 'label' => 'Custom Classess', 'name' => 'class', 'value' => get_field($field . '_class', $attachment_id) ); // Creates Custom Classess field
|
68 |
-
return $args;
|
69 |
-
}
|
70 |
-
add_filter( 'acf_photo_gallery_image_fields', 'my_extra_gallery_fields', 10, 3 );`
|
71 |
-
|
72 |
-
= How to get values of extra fields =
|
73 |
-
You can use ACF helper function `get_field`
|
74 |
-
|
75 |
-
`get_field('photo_gallery_alt', $id);`
|
76 |
-
`get_field('photo_gallery_class', $id);`
|
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 |
-
|
109 |
-
1. Copy the `navz-photo-gallery` folder into your `wp-content/plugins` folder
|
110 |
-
2. Activate the Advanced Custom Fields: Photo Gallery plugin via the plugins admin page
|
111 |
-
3. Create a new field via ACF and select the Photo Gallery type
|
112 |
-
4. Please refer to the description for more info regarding the field type settings
|
113 |
-
|
114 |
-
== Changelog ==
|
115 |
-
=1.6.
|
116 |
-
* [
|
117 |
-
|
118 |
-
|
119 |
-
* [Added] Support for
|
120 |
-
|
121 |
-
|
122 |
-
* [
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
* [Bugfix]
|
128 |
-
|
129 |
-
=1.6.
|
130 |
-
* [Bugfix]
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
* [Added] Support for
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
* [Added]
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
*
|
145 |
-
|
146 |
-
|
147 |
-
*
|
148 |
-
* [
|
149 |
-
|
150 |
-
|
151 |
-
* [Bugfix]
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
* [
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
|
|
|
|
|
|
161 |
* Initial Release.
|
1 |
+
=== ACF Photo Gallery Field ===
|
2 |
+
Contributors: navzme
|
3 |
+
Tags: acf, advanced, custom, fields, photo, gallery, album, fancybox, litebox, lightbox
|
4 |
+
Requires at least: 3.8
|
5 |
+
Tested up to: 5.1
|
6 |
+
Stable tag: 1.6.4
|
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
|
18 |
+
* Assign your fields to multiple edit pages (via custom location rules)
|
19 |
+
* Easily load data through a simple and friendly API
|
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
|
40 |
+
foreach($images as $image):
|
41 |
+
$id = $image['id']; // The attachment id of the media
|
42 |
+
$title = $image['title']; //The title
|
43 |
+
$caption= $image['caption']; //The caption
|
44 |
+
$full_image_url= $image['full_image_url']; //Full size image url
|
45 |
+
$full_image_url = acf_photo_gallery_resize_image($full_image_url, 262, 160); //Resized size to 262px width by 160px height image url
|
46 |
+
$thumbnail_image_url= $image['thumbnail_image_url']; //Get the thumbnail size image url 150px by 150px
|
47 |
+
$url= $image['url']; //Goto any link when clicked
|
48 |
+
$target= $image['target']; //Open normal or new tab
|
49 |
+
$alt = get_field('photo_gallery_alt', $id); //Get the alt which is a extra field (See below how to add extra fields)
|
50 |
+
$class = get_field('photo_gallery_class', $id); //Get the class which is a extra field (See below how to add extra fields)
|
51 |
+
?>
|
52 |
+
<div class="col-xs-6 col-md-3">
|
53 |
+
<div class="thumbnail">
|
54 |
+
<?php if( !empty($url) ){ ?><a href="<?php echo $url; ?>" <?php echo ($target == 'true' )? 'target="_blank"': ''; ?>><?php } ?>
|
55 |
+
<img src="<?php echo $full_image_url; ?>" alt="<?php echo $title; ?>" title="<?php echo $title; ?>">
|
56 |
+
<?php if( !empty($url) ){ ?></a><?php } ?>
|
57 |
+
</div>
|
58 |
+
</div>
|
59 |
+
<?php endforeach; endif; ?>`
|
60 |
+
|
61 |
+
= Add Extra Fields =
|
62 |
+
To add extra fields add the following to your themes functions.php file.
|
63 |
+
|
64 |
+
`//Create extra fields called Altnative Text and Custom Classess
|
65 |
+
function my_extra_gallery_fields( $args, $attachment_id, $field ){
|
66 |
+
$args['alt'] = array('type' => 'text', 'label' => 'Altnative Text', 'name' => 'alt', 'value' => get_field($field . '_alt', $attachment_id) ); // Creates Altnative Text field
|
67 |
+
$args['class'] = array('type' => 'text', 'label' => 'Custom Classess', 'name' => 'class', 'value' => get_field($field . '_class', $attachment_id) ); // Creates Custom Classess field
|
68 |
+
return $args;
|
69 |
+
}
|
70 |
+
add_filter( 'acf_photo_gallery_image_fields', 'my_extra_gallery_fields', 10, 3 );`
|
71 |
+
|
72 |
+
= How to get values of extra fields =
|
73 |
+
You can use ACF helper function `get_field`
|
74 |
+
|
75 |
+
`get_field('photo_gallery_alt', $id);`
|
76 |
+
`get_field('photo_gallery_class', $id);`
|
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 |
+
|
109 |
+
1. Copy the `navz-photo-gallery` folder into your `wp-content/plugins` folder
|
110 |
+
2. Activate the Advanced Custom Fields: Photo Gallery plugin via the plugins admin page
|
111 |
+
3. Create a new field via ACF and select the Photo Gallery type
|
112 |
+
4. Please refer to the description for more info regarding the field type settings
|
113 |
+
|
114 |
+
== Changelog ==
|
115 |
+
=1.6.4=
|
116 |
+
* [Bugfix] JavaScript error in the console when removing images from the WordPress metabox
|
117 |
+
|
118 |
+
=1.6.3=
|
119 |
+
* [Added] Support for ACF 5
|
120 |
+
* [Added] Edit gallery with built-in or WordPress native model. Thanks to Github @makepost
|
121 |
+
* [Added] Under the hood improvements of the codebase
|
122 |
+
* [Added] Support for RESTFul API with ACF to REST API plugin
|
123 |
+
|
124 |
+
=1.6.2=
|
125 |
+
* [Bugfix] Keep data synced with the attachment data
|
126 |
+
* [Bugfix] Pull caption attachment caption using add filters
|
127 |
+
* [Bugfix] PHP 7.2 count() error
|
128 |
+
|
129 |
+
=1.6.1=
|
130 |
+
* [Bugfix] Edit image box disappears on click of pencil edit button reported by @rickytoof9
|
131 |
+
|
132 |
+
=1.6.0=
|
133 |
+
* [Bugfix] Error on saving post with empty gallery. Patch provided by @ugy
|
134 |
+
* [Bugfix] Showing multiple photo gallery fields in the same page reported by @rickytoof9
|
135 |
+
* [Added] Support for srcset. Special thanks to @ugy for the code
|
136 |
+
|
137 |
+
= 1.5.0 =
|
138 |
+
* [Added] Support for SVG
|
139 |
+
* [Added] Support for legacy PHP version
|
140 |
+
* [Added] Add extra fields
|
141 |
+
|
142 |
+
= 1.4.0 =
|
143 |
+
* [Added] Can sortable gallery images
|
144 |
+
* [Bugfix] Fixed the order to follow the sort order for gallery images
|
145 |
+
|
146 |
+
= 1.3.0 =
|
147 |
+
* Change the meta_key from acf field_key to acf field_name
|
148 |
+
* [Added] Helper function acf_photo_gallery() to pull images
|
149 |
+
* [Added] Helper function acf_photo_gallery_resize_image to resize the image on fly and save it
|
150 |
+
* [Bugfix] Issue with target parameter in config
|
151 |
+
* [Bugfix] Issue with url not saving properly
|
152 |
+
|
153 |
+
= 1.2.0 =
|
154 |
+
* [Bugfix] Support for WordPress 4.6
|
155 |
+
* [Added] Some changes on on the display
|
156 |
+
* [Added] Fetch the data from the database
|
157 |
+
|
158 |
+
= 1.1.0 =
|
159 |
+
* [Bugfix] Undefined index: acf-photo-gallery-field on file acf-photo_gallery-v4
|
160 |
+
* [Bugfix] When delete the photos from the gallery, the last photo was not deleting
|
161 |
+
* [Bugfix] Gallery photos was not saving in the database
|
162 |
+
|
163 |
+
= 1.0.0 =
|
164 |
* Initial Release.
|