ACF Photo Gallery Field - Version 1.6.5

Version Description

Download this release

Release Info

Developer navzme
Plugin Icon 128x128 ACF Photo Gallery Field
Version 1.6.5
Comparing to
See all releases

Code changes from version 1.6.4 to 1.6.5

LICENSE.txt CHANGED
@@ -1,339 +1,339 @@
1
- GNU GENERAL PUBLIC LICENSE
2
- Version 2, June 1991
3
-
4
- Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
5
- 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
6
- Everyone is permitted to copy and distribute verbatim copies
7
- of this license document, but changing it is not allowed.
8
-
9
- Preamble
10
-
11
- The licenses for most software are designed to take away your
12
- freedom to share and change it. By contrast, the GNU General Public
13
- License is intended to guarantee your freedom to share and change free
14
- software--to make sure the software is free for all its users. This
15
- General Public License applies to most of the Free Software
16
- Foundation's software and to any other program whose authors commit to
17
- using it. (Some other Free Software Foundation software is covered by
18
- the GNU Lesser General Public License instead.) You can apply it to
19
- your programs, too.
20
-
21
- When we speak of free software, we are referring to freedom, not
22
- price. Our General Public Licenses are designed to make sure that you
23
- have the freedom to distribute copies of free software (and charge for
24
- this service if you wish), that you receive source code or can get it
25
- if you want it, that you can change the software or use pieces of it
26
- in new free programs; and that you know you can do these things.
27
-
28
- To protect your rights, we need to make restrictions that forbid
29
- anyone to deny you these rights or to ask you to surrender the rights.
30
- These restrictions translate to certain responsibilities for you if you
31
- distribute copies of the software, or if you modify it.
32
-
33
- For example, if you distribute copies of such a program, whether
34
- gratis or for a fee, you must give the recipients all the rights that
35
- you have. You must make sure that they, too, receive or can get the
36
- source code. And you must show them these terms so they know their
37
- rights.
38
-
39
- We protect your rights with two steps: (1) copyright the software, and
40
- (2) offer you this license which gives you legal permission to copy,
41
- distribute and/or modify the software.
42
-
43
- Also, for each author's protection and ours, we want to make certain
44
- that everyone understands that there is no warranty for this free
45
- software. If the software is modified by someone else and passed on, we
46
- want its recipients to know that what they have is not the original, so
47
- that any problems introduced by others will not reflect on the original
48
- authors' reputations.
49
-
50
- Finally, any free program is threatened constantly by software
51
- patents. We wish to avoid the danger that redistributors of a free
52
- program will individually obtain patent licenses, in effect making the
53
- program proprietary. To prevent this, we have made it clear that any
54
- patent must be licensed for everyone's free use or not licensed at all.
55
-
56
- The precise terms and conditions for copying, distribution and
57
- modification follow.
58
-
59
- GNU GENERAL PUBLIC LICENSE
60
- TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
61
-
62
- 0. This License applies to any program or other work which contains
63
- a notice placed by the copyright holder saying it may be distributed
64
- under the terms of this General Public License. The "Program", below,
65
- refers to any such program or work, and a "work based on the Program"
66
- means either the Program or any derivative work under copyright law:
67
- that is to say, a work containing the Program or a portion of it,
68
- either verbatim or with modifications and/or translated into another
69
- language. (Hereinafter, translation is included without limitation in
70
- the term "modification".) Each licensee is addressed as "you".
71
-
72
- Activities other than copying, distribution and modification are not
73
- covered by this License; they are outside its scope. The act of
74
- running the Program is not restricted, and the output from the Program
75
- is covered only if its contents constitute a work based on the
76
- Program (independent of having been made by running the Program).
77
- Whether that is true depends on what the Program does.
78
-
79
- 1. You may copy and distribute verbatim copies of the Program's
80
- source code as you receive it, in any medium, provided that you
81
- conspicuously and appropriately publish on each copy an appropriate
82
- copyright notice and disclaimer of warranty; keep intact all the
83
- notices that refer to this License and to the absence of any warranty;
84
- and give any other recipients of the Program a copy of this License
85
- along with the Program.
86
-
87
- You may charge a fee for the physical act of transferring a copy, and
88
- you may at your option offer warranty protection in exchange for a fee.
89
-
90
- 2. You may modify your copy or copies of the Program or any portion
91
- of it, thus forming a work based on the Program, and copy and
92
- distribute such modifications or work under the terms of Section 1
93
- above, provided that you also meet all of these conditions:
94
-
95
- a) You must cause the modified files to carry prominent notices
96
- stating that you changed the files and the date of any change.
97
-
98
- b) You must cause any work that you distribute or publish, that in
99
- whole or in part contains or is derived from the Program or any
100
- part thereof, to be licensed as a whole at no charge to all third
101
- parties under the terms of this License.
102
-
103
- c) If the modified program normally reads commands interactively
104
- when run, you must cause it, when started running for such
105
- interactive use in the most ordinary way, to print or display an
106
- announcement including an appropriate copyright notice and a
107
- notice that there is no warranty (or else, saying that you provide
108
- a warranty) and that users may redistribute the program under
109
- these conditions, and telling the user how to view a copy of this
110
- License. (Exception: if the Program itself is interactive but
111
- does not normally print such an announcement, your work based on
112
- the Program is not required to print an announcement.)
113
-
114
- These requirements apply to the modified work as a whole. If
115
- identifiable sections of that work are not derived from the Program,
116
- and can be reasonably considered independent and separate works in
117
- themselves, then this License, and its terms, do not apply to those
118
- sections when you distribute them as separate works. But when you
119
- distribute the same sections as part of a whole which is a work based
120
- on the Program, the distribution of the whole must be on the terms of
121
- this License, whose permissions for other licensees extend to the
122
- entire whole, and thus to each and every part regardless of who wrote it.
123
-
124
- Thus, it is not the intent of this section to claim rights or contest
125
- your rights to work written entirely by you; rather, the intent is to
126
- exercise the right to control the distribution of derivative or
127
- collective works based on the Program.
128
-
129
- In addition, mere aggregation of another work not based on the Program
130
- with the Program (or with a work based on the Program) on a volume of
131
- a storage or distribution medium does not bring the other work under
132
- the scope of this License.
133
-
134
- 3. You may copy and distribute the Program (or a work based on it,
135
- under Section 2) in object code or executable form under the terms of
136
- Sections 1 and 2 above provided that you also do one of the following:
137
-
138
- a) Accompany it with the complete corresponding machine-readable
139
- source code, which must be distributed under the terms of Sections
140
- 1 and 2 above on a medium customarily used for software interchange; or,
141
-
142
- b) Accompany it with a written offer, valid for at least three
143
- years, to give any third party, for a charge no more than your
144
- cost of physically performing source distribution, a complete
145
- machine-readable copy of the corresponding source code, to be
146
- distributed under the terms of Sections 1 and 2 above on a medium
147
- customarily used for software interchange; or,
148
-
149
- c) Accompany it with the information you received as to the offer
150
- to distribute corresponding source code. (This alternative is
151
- allowed only for noncommercial distribution and only if you
152
- received the program in object code or executable form with such
153
- an offer, in accord with Subsection b above.)
154
-
155
- The source code for a work means the preferred form of the work for
156
- making modifications to it. For an executable work, complete source
157
- code means all the source code for all modules it contains, plus any
158
- associated interface definition files, plus the scripts used to
159
- control compilation and installation of the executable. However, as a
160
- special exception, the source code distributed need not include
161
- anything that is normally distributed (in either source or binary
162
- form) with the major components (compiler, kernel, and so on) of the
163
- operating system on which the executable runs, unless that component
164
- itself accompanies the executable.
165
-
166
- If distribution of executable or object code is made by offering
167
- access to copy from a designated place, then offering equivalent
168
- access to copy the source code from the same place counts as
169
- distribution of the source code, even though third parties are not
170
- compelled to copy the source along with the object code.
171
-
172
- 4. You may not copy, modify, sublicense, or distribute the Program
173
- except as expressly provided under this License. Any attempt
174
- otherwise to copy, modify, sublicense or distribute the Program is
175
- void, and will automatically terminate your rights under this License.
176
- However, parties who have received copies, or rights, from you under
177
- this License will not have their licenses terminated so long as such
178
- parties remain in full compliance.
179
-
180
- 5. You are not required to accept this License, since you have not
181
- signed it. However, nothing else grants you permission to modify or
182
- distribute the Program or its derivative works. These actions are
183
- prohibited by law if you do not accept this License. Therefore, by
184
- modifying or distributing the Program (or any work based on the
185
- Program), you indicate your acceptance of this License to do so, and
186
- all its terms and conditions for copying, distributing or modifying
187
- the Program or works based on it.
188
-
189
- 6. Each time you redistribute the Program (or any work based on the
190
- Program), the recipient automatically receives a license from the
191
- original licensor to copy, distribute or modify the Program subject to
192
- these terms and conditions. You may not impose any further
193
- restrictions on the recipients' exercise of the rights granted herein.
194
- You are not responsible for enforcing compliance by third parties to
195
- this License.
196
-
197
- 7. If, as a consequence of a court judgment or allegation of patent
198
- infringement or for any other reason (not limited to patent issues),
199
- conditions are imposed on you (whether by court order, agreement or
200
- otherwise) that contradict the conditions of this License, they do not
201
- excuse you from the conditions of this License. If you cannot
202
- distribute so as to satisfy simultaneously your obligations under this
203
- License and any other pertinent obligations, then as a consequence you
204
- may not distribute the Program at all. For example, if a patent
205
- license would not permit royalty-free redistribution of the Program by
206
- all those who receive copies directly or indirectly through you, then
207
- the only way you could satisfy both it and this License would be to
208
- refrain entirely from distribution of the Program.
209
-
210
- If any portion of this section is held invalid or unenforceable under
211
- any particular circumstance, the balance of the section is intended to
212
- apply and the section as a whole is intended to apply in other
213
- circumstances.
214
-
215
- It is not the purpose of this section to induce you to infringe any
216
- patents or other property right claims or to contest validity of any
217
- such claims; this section has the sole purpose of protecting the
218
- integrity of the free software distribution system, which is
219
- implemented by public license practices. Many people have made
220
- generous contributions to the wide range of software distributed
221
- through that system in reliance on consistent application of that
222
- system; it is up to the author/donor to decide if he or she is willing
223
- to distribute software through any other system and a licensee cannot
224
- impose that choice.
225
-
226
- This section is intended to make thoroughly clear what is believed to
227
- be a consequence of the rest of this License.
228
-
229
- 8. If the distribution and/or use of the Program is restricted in
230
- certain countries either by patents or by copyrighted interfaces, the
231
- original copyright holder who places the Program under this License
232
- may add an explicit geographical distribution limitation excluding
233
- those countries, so that distribution is permitted only in or among
234
- countries not thus excluded. In such case, this License incorporates
235
- the limitation as if written in the body of this License.
236
-
237
- 9. The Free Software Foundation may publish revised and/or new versions
238
- of the General Public License from time to time. Such new versions will
239
- be similar in spirit to the present version, but may differ in detail to
240
- address new problems or concerns.
241
-
242
- Each version is given a distinguishing version number. If the Program
243
- specifies a version number of this License which applies to it and "any
244
- later version", you have the option of following the terms and conditions
245
- either of that version or of any later version published by the Free
246
- Software Foundation. If the Program does not specify a version number of
247
- this License, you may choose any version ever published by the Free Software
248
- Foundation.
249
-
250
- 10. If you wish to incorporate parts of the Program into other free
251
- programs whose distribution conditions are different, write to the author
252
- to ask for permission. For software which is copyrighted by the Free
253
- Software Foundation, write to the Free Software Foundation; we sometimes
254
- make exceptions for this. Our decision will be guided by the two goals
255
- of preserving the free status of all derivatives of our free software and
256
- of promoting the sharing and reuse of software generally.
257
-
258
- NO WARRANTY
259
-
260
- 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
261
- FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
262
- OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
263
- PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
264
- OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
265
- MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
266
- TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
267
- PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
268
- REPAIR OR CORRECTION.
269
-
270
- 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
271
- WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
272
- REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
273
- INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
274
- OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
275
- TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
276
- YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
277
- PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
278
- POSSIBILITY OF SUCH DAMAGES.
279
-
280
- END OF TERMS AND CONDITIONS
281
-
282
- How to Apply These Terms to Your New Programs
283
-
284
- If you develop a new program, and you want it to be of the greatest
285
- possible use to the public, the best way to achieve this is to make it
286
- free software which everyone can redistribute and change under these terms.
287
-
288
- To do so, attach the following notices to the program. It is safest
289
- to attach them to the start of each source file to most effectively
290
- convey the exclusion of warranty; and each file should have at least
291
- the "copyright" line and a pointer to where the full notice is found.
292
-
293
- <one line to give the program's name and a brief idea of what it does.>
294
- Copyright (C) <year> <name of author>
295
-
296
- This program is free software; you can redistribute it and/or modify
297
- it under the terms of the GNU General Public License as published by
298
- the Free Software Foundation; either version 2 of the License, or
299
- (at your option) any later version.
300
-
301
- This program is distributed in the hope that it will be useful,
302
- but WITHOUT ANY WARRANTY; without even the implied warranty of
303
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
304
- GNU General Public License for more details.
305
-
306
- You should have received a copy of the GNU General Public License along
307
- with this program; if not, write to the Free Software Foundation, Inc.,
308
- 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
309
-
310
- Also add information on how to contact you by electronic and paper mail.
311
-
312
- If the program is interactive, make it output a short notice like this
313
- when it starts in an interactive mode:
314
-
315
- Gnomovision version 69, Copyright (C) year name of author
316
- Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
317
- This is free software, and you are welcome to redistribute it
318
- under certain conditions; type `show c' for details.
319
-
320
- The hypothetical commands `show w' and `show c' should show the appropriate
321
- parts of the General Public License. Of course, the commands you use may
322
- be called something other than `show w' and `show c'; they could even be
323
- mouse-clicks or menu items--whatever suits your program.
324
-
325
- You should also get your employer (if you work as a programmer) or your
326
- school, if any, to sign a "copyright disclaimer" for the program, if
327
- necessary. Here is a sample; alter the names:
328
-
329
- Yoyodyne, Inc., hereby disclaims all copyright interest in the program
330
- `Gnomovision' (which makes passes at compilers) written by James Hacker.
331
-
332
- <signature of Ty Coon>, 1 April 1989
333
- Ty Coon, President of Vice
334
-
335
- This General Public License does not permit incorporating your program into
336
- proprietary programs. If your program is a subroutine library, you may
337
- consider it more useful to permit linking proprietary applications with the
338
- library. If this is what you want to do, use the GNU Lesser General
339
- Public License instead of this License.
1
+ GNU GENERAL PUBLIC LICENSE
2
+ Version 2, June 1991
3
+
4
+ Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
5
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
6
+ Everyone is permitted to copy and distribute verbatim copies
7
+ of this license document, but changing it is not allowed.
8
+
9
+ Preamble
10
+
11
+ The licenses for most software are designed to take away your
12
+ freedom to share and change it. By contrast, the GNU General Public
13
+ License is intended to guarantee your freedom to share and change free
14
+ software--to make sure the software is free for all its users. This
15
+ General Public License applies to most of the Free Software
16
+ Foundation's software and to any other program whose authors commit to
17
+ using it. (Some other Free Software Foundation software is covered by
18
+ the GNU Lesser General Public License instead.) You can apply it to
19
+ your programs, too.
20
+
21
+ When we speak of free software, we are referring to freedom, not
22
+ price. Our General Public Licenses are designed to make sure that you
23
+ have the freedom to distribute copies of free software (and charge for
24
+ this service if you wish), that you receive source code or can get it
25
+ if you want it, that you can change the software or use pieces of it
26
+ in new free programs; and that you know you can do these things.
27
+
28
+ To protect your rights, we need to make restrictions that forbid
29
+ anyone to deny you these rights or to ask you to surrender the rights.
30
+ These restrictions translate to certain responsibilities for you if you
31
+ distribute copies of the software, or if you modify it.
32
+
33
+ For example, if you distribute copies of such a program, whether
34
+ gratis or for a fee, you must give the recipients all the rights that
35
+ you have. You must make sure that they, too, receive or can get the
36
+ source code. And you must show them these terms so they know their
37
+ rights.
38
+
39
+ We protect your rights with two steps: (1) copyright the software, and
40
+ (2) offer you this license which gives you legal permission to copy,
41
+ distribute and/or modify the software.
42
+
43
+ Also, for each author's protection and ours, we want to make certain
44
+ that everyone understands that there is no warranty for this free
45
+ software. If the software is modified by someone else and passed on, we
46
+ want its recipients to know that what they have is not the original, so
47
+ that any problems introduced by others will not reflect on the original
48
+ authors' reputations.
49
+
50
+ Finally, any free program is threatened constantly by software
51
+ patents. We wish to avoid the danger that redistributors of a free
52
+ program will individually obtain patent licenses, in effect making the
53
+ program proprietary. To prevent this, we have made it clear that any
54
+ patent must be licensed for everyone's free use or not licensed at all.
55
+
56
+ The precise terms and conditions for copying, distribution and
57
+ modification follow.
58
+
59
+ GNU GENERAL PUBLIC LICENSE
60
+ TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
61
+
62
+ 0. This License applies to any program or other work which contains
63
+ a notice placed by the copyright holder saying it may be distributed
64
+ under the terms of this General Public License. The "Program", below,
65
+ refers to any such program or work, and a "work based on the Program"
66
+ means either the Program or any derivative work under copyright law:
67
+ that is to say, a work containing the Program or a portion of it,
68
+ either verbatim or with modifications and/or translated into another
69
+ language. (Hereinafter, translation is included without limitation in
70
+ the term "modification".) Each licensee is addressed as "you".
71
+
72
+ Activities other than copying, distribution and modification are not
73
+ covered by this License; they are outside its scope. The act of
74
+ running the Program is not restricted, and the output from the Program
75
+ is covered only if its contents constitute a work based on the
76
+ Program (independent of having been made by running the Program).
77
+ Whether that is true depends on what the Program does.
78
+
79
+ 1. You may copy and distribute verbatim copies of the Program's
80
+ source code as you receive it, in any medium, provided that you
81
+ conspicuously and appropriately publish on each copy an appropriate
82
+ copyright notice and disclaimer of warranty; keep intact all the
83
+ notices that refer to this License and to the absence of any warranty;
84
+ and give any other recipients of the Program a copy of this License
85
+ along with the Program.
86
+
87
+ You may charge a fee for the physical act of transferring a copy, and
88
+ you may at your option offer warranty protection in exchange for a fee.
89
+
90
+ 2. You may modify your copy or copies of the Program or any portion
91
+ of it, thus forming a work based on the Program, and copy and
92
+ distribute such modifications or work under the terms of Section 1
93
+ above, provided that you also meet all of these conditions:
94
+
95
+ a) You must cause the modified files to carry prominent notices
96
+ stating that you changed the files and the date of any change.
97
+
98
+ b) You must cause any work that you distribute or publish, that in
99
+ whole or in part contains or is derived from the Program or any
100
+ part thereof, to be licensed as a whole at no charge to all third
101
+ parties under the terms of this License.
102
+
103
+ c) If the modified program normally reads commands interactively
104
+ when run, you must cause it, when started running for such
105
+ interactive use in the most ordinary way, to print or display an
106
+ announcement including an appropriate copyright notice and a
107
+ notice that there is no warranty (or else, saying that you provide
108
+ a warranty) and that users may redistribute the program under
109
+ these conditions, and telling the user how to view a copy of this
110
+ License. (Exception: if the Program itself is interactive but
111
+ does not normally print such an announcement, your work based on
112
+ the Program is not required to print an announcement.)
113
+
114
+ These requirements apply to the modified work as a whole. If
115
+ identifiable sections of that work are not derived from the Program,
116
+ and can be reasonably considered independent and separate works in
117
+ themselves, then this License, and its terms, do not apply to those
118
+ sections when you distribute them as separate works. But when you
119
+ distribute the same sections as part of a whole which is a work based
120
+ on the Program, the distribution of the whole must be on the terms of
121
+ this License, whose permissions for other licensees extend to the
122
+ entire whole, and thus to each and every part regardless of who wrote it.
123
+
124
+ Thus, it is not the intent of this section to claim rights or contest
125
+ your rights to work written entirely by you; rather, the intent is to
126
+ exercise the right to control the distribution of derivative or
127
+ collective works based on the Program.
128
+
129
+ In addition, mere aggregation of another work not based on the Program
130
+ with the Program (or with a work based on the Program) on a volume of
131
+ a storage or distribution medium does not bring the other work under
132
+ the scope of this License.
133
+
134
+ 3. You may copy and distribute the Program (or a work based on it,
135
+ under Section 2) in object code or executable form under the terms of
136
+ Sections 1 and 2 above provided that you also do one of the following:
137
+
138
+ a) Accompany it with the complete corresponding machine-readable
139
+ source code, which must be distributed under the terms of Sections
140
+ 1 and 2 above on a medium customarily used for software interchange; or,
141
+
142
+ b) Accompany it with a written offer, valid for at least three
143
+ years, to give any third party, for a charge no more than your
144
+ cost of physically performing source distribution, a complete
145
+ machine-readable copy of the corresponding source code, to be
146
+ distributed under the terms of Sections 1 and 2 above on a medium
147
+ customarily used for software interchange; or,
148
+
149
+ c) Accompany it with the information you received as to the offer
150
+ to distribute corresponding source code. (This alternative is
151
+ allowed only for noncommercial distribution and only if you
152
+ received the program in object code or executable form with such
153
+ an offer, in accord with Subsection b above.)
154
+
155
+ The source code for a work means the preferred form of the work for
156
+ making modifications to it. For an executable work, complete source
157
+ code means all the source code for all modules it contains, plus any
158
+ associated interface definition files, plus the scripts used to
159
+ control compilation and installation of the executable. However, as a
160
+ special exception, the source code distributed need not include
161
+ anything that is normally distributed (in either source or binary
162
+ form) with the major components (compiler, kernel, and so on) of the
163
+ operating system on which the executable runs, unless that component
164
+ itself accompanies the executable.
165
+
166
+ If distribution of executable or object code is made by offering
167
+ access to copy from a designated place, then offering equivalent
168
+ access to copy the source code from the same place counts as
169
+ distribution of the source code, even though third parties are not
170
+ compelled to copy the source along with the object code.
171
+
172
+ 4. You may not copy, modify, sublicense, or distribute the Program
173
+ except as expressly provided under this License. Any attempt
174
+ otherwise to copy, modify, sublicense or distribute the Program is
175
+ void, and will automatically terminate your rights under this License.
176
+ However, parties who have received copies, or rights, from you under
177
+ this License will not have their licenses terminated so long as such
178
+ parties remain in full compliance.
179
+
180
+ 5. You are not required to accept this License, since you have not
181
+ signed it. However, nothing else grants you permission to modify or
182
+ distribute the Program or its derivative works. These actions are
183
+ prohibited by law if you do not accept this License. Therefore, by
184
+ modifying or distributing the Program (or any work based on the
185
+ Program), you indicate your acceptance of this License to do so, and
186
+ all its terms and conditions for copying, distributing or modifying
187
+ the Program or works based on it.
188
+
189
+ 6. Each time you redistribute the Program (or any work based on the
190
+ Program), the recipient automatically receives a license from the
191
+ original licensor to copy, distribute or modify the Program subject to
192
+ these terms and conditions. You may not impose any further
193
+ restrictions on the recipients' exercise of the rights granted herein.
194
+ You are not responsible for enforcing compliance by third parties to
195
+ this License.
196
+
197
+ 7. If, as a consequence of a court judgment or allegation of patent
198
+ infringement or for any other reason (not limited to patent issues),
199
+ conditions are imposed on you (whether by court order, agreement or
200
+ otherwise) that contradict the conditions of this License, they do not
201
+ excuse you from the conditions of this License. If you cannot
202
+ distribute so as to satisfy simultaneously your obligations under this
203
+ License and any other pertinent obligations, then as a consequence you
204
+ may not distribute the Program at all. For example, if a patent
205
+ license would not permit royalty-free redistribution of the Program by
206
+ all those who receive copies directly or indirectly through you, then
207
+ the only way you could satisfy both it and this License would be to
208
+ refrain entirely from distribution of the Program.
209
+
210
+ If any portion of this section is held invalid or unenforceable under
211
+ any particular circumstance, the balance of the section is intended to
212
+ apply and the section as a whole is intended to apply in other
213
+ circumstances.
214
+
215
+ It is not the purpose of this section to induce you to infringe any
216
+ patents or other property right claims or to contest validity of any
217
+ such claims; this section has the sole purpose of protecting the
218
+ integrity of the free software distribution system, which is
219
+ implemented by public license practices. Many people have made
220
+ generous contributions to the wide range of software distributed
221
+ through that system in reliance on consistent application of that
222
+ system; it is up to the author/donor to decide if he or she is willing
223
+ to distribute software through any other system and a licensee cannot
224
+ impose that choice.
225
+
226
+ This section is intended to make thoroughly clear what is believed to
227
+ be a consequence of the rest of this License.
228
+
229
+ 8. If the distribution and/or use of the Program is restricted in
230
+ certain countries either by patents or by copyrighted interfaces, the
231
+ original copyright holder who places the Program under this License
232
+ may add an explicit geographical distribution limitation excluding
233
+ those countries, so that distribution is permitted only in or among
234
+ countries not thus excluded. In such case, this License incorporates
235
+ the limitation as if written in the body of this License.
236
+
237
+ 9. The Free Software Foundation may publish revised and/or new versions
238
+ of the General Public License from time to time. Such new versions will
239
+ be similar in spirit to the present version, but may differ in detail to
240
+ address new problems or concerns.
241
+
242
+ Each version is given a distinguishing version number. If the Program
243
+ specifies a version number of this License which applies to it and "any
244
+ later version", you have the option of following the terms and conditions
245
+ either of that version or of any later version published by the Free
246
+ Software Foundation. If the Program does not specify a version number of
247
+ this License, you may choose any version ever published by the Free Software
248
+ Foundation.
249
+
250
+ 10. If you wish to incorporate parts of the Program into other free
251
+ programs whose distribution conditions are different, write to the author
252
+ to ask for permission. For software which is copyrighted by the Free
253
+ Software Foundation, write to the Free Software Foundation; we sometimes
254
+ make exceptions for this. Our decision will be guided by the two goals
255
+ of preserving the free status of all derivatives of our free software and
256
+ of promoting the sharing and reuse of software generally.
257
+
258
+ NO WARRANTY
259
+
260
+ 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
261
+ FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
262
+ OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
263
+ PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
264
+ OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
265
+ MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
266
+ TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
267
+ PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
268
+ REPAIR OR CORRECTION.
269
+
270
+ 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
271
+ WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
272
+ REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
273
+ INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
274
+ OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
275
+ TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
276
+ YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
277
+ PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
278
+ POSSIBILITY OF SUCH DAMAGES.
279
+
280
+ END OF TERMS AND CONDITIONS
281
+
282
+ How to Apply These Terms to Your New Programs
283
+
284
+ If you develop a new program, and you want it to be of the greatest
285
+ possible use to the public, the best way to achieve this is to make it
286
+ free software which everyone can redistribute and change under these terms.
287
+
288
+ To do so, attach the following notices to the program. It is safest
289
+ to attach them to the start of each source file to most effectively
290
+ convey the exclusion of warranty; and each file should have at least
291
+ the "copyright" line and a pointer to where the full notice is found.
292
+
293
+ <one line to give the program's name and a brief idea of what it does.>
294
+ Copyright (C) <year> <name of author>
295
+
296
+ This program is free software; you can redistribute it and/or modify
297
+ it under the terms of the GNU General Public License as published by
298
+ the Free Software Foundation; either version 2 of the License, or
299
+ (at your option) any later version.
300
+
301
+ This program is distributed in the hope that it will be useful,
302
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
303
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
304
+ GNU General Public License for more details.
305
+
306
+ You should have received a copy of the GNU General Public License along
307
+ with this program; if not, write to the Free Software Foundation, Inc.,
308
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
309
+
310
+ Also add information on how to contact you by electronic and paper mail.
311
+
312
+ If the program is interactive, make it output a short notice like this
313
+ when it starts in an interactive mode:
314
+
315
+ Gnomovision version 69, Copyright (C) year name of author
316
+ Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
317
+ This is free software, and you are welcome to redistribute it
318
+ under certain conditions; type `show c' for details.
319
+
320
+ The hypothetical commands `show w' and `show c' should show the appropriate
321
+ parts of the General Public License. Of course, the commands you use may
322
+ be called something other than `show w' and `show c'; they could even be
323
+ mouse-clicks or menu items--whatever suits your program.
324
+
325
+ You should also get your employer (if you work as a programmer) or your
326
+ school, if any, to sign a "copyright disclaimer" for the program, if
327
+ necessary. Here is a sample; alter the names:
328
+
329
+ Yoyodyne, Inc., hereby disclaims all copyright interest in the program
330
+ `Gnomovision' (which makes passes at compilers) written by James Hacker.
331
+
332
+ <signature of Ty Coon>, 1 April 1989
333
+ Ty Coon, President of Vice
334
+
335
+ This General Public License does not permit incorporating your program into
336
+ proprietary programs. If your program is a subroutine library, you may
337
+ consider it more useful to permit linking proprietary applications with the
338
+ library. If this is what you want to do, use the GNU Lesser General
339
+ Public License instead of this License.
aq_resizer.php CHANGED
@@ -1,250 +1,250 @@
1
- <?php
2
-
3
- /**
4
- * Title : Aqua Resizer
5
- * Description : Resizes WordPress images on the fly
6
- * Version : 1.2.1
7
- * Author : Syamil MJ
8
- * Author URI : http://aquagraphite.com
9
- * License : WTFPL - http://sam.zoy.org/wtfpl/
10
- * Documentation : https://github.com/sy4mil/Aqua-Resizer/
11
- *
12
- * @param string $url - (required) must be uploaded using wp media uploader
13
- * @param int $width - (required)
14
- * @param int $height - (optional)
15
- * @param bool $crop - (optional) default to soft crop
16
- * @param bool $single - (optional) returns an array if false
17
- * @param bool $upscale - (optional) resizes smaller images
18
- * @uses wp_upload_dir()
19
- * @uses image_resize_dimensions()
20
- * @uses wp_get_image_editor()
21
- *
22
- * @return str|array
23
- */
24
-
25
- if(!class_exists('Aq_Resize')) {
26
- class Aq_Exception extends Exception {}
27
-
28
- class Aq_Resize
29
- {
30
- /**
31
- * The singleton instance
32
- */
33
- static private $instance = null;
34
-
35
- /**
36
- * Should an Aq_Exception be thrown on error?
37
- * If false (default), then the error will just be logged.
38
- */
39
- public $throwOnError = false;
40
-
41
- /**
42
- * No initialization allowed
43
- */
44
- private function __construct() {}
45
-
46
- /**
47
- * No cloning allowed
48
- */
49
- private function __clone() {}
50
-
51
- /**
52
- * For your custom default usage you may want to initialize an Aq_Resize object by yourself and then have own defaults
53
- */
54
- static public function getInstance() {
55
- if(self::$instance == null) {
56
- self::$instance = new self;
57
- }
58
-
59
- return self::$instance;
60
- }
61
-
62
- /**
63
- * Run, forest.
64
- */
65
- public function process( $url, $width = null, $height = null, $crop = null, $single = true, $upscale = false ) {
66
- try {
67
- // Validate inputs.
68
- if (!$url)
69
- throw new Aq_Exception('$url parameter is required');
70
- if (!$width)
71
- throw new Aq_Exception('$width parameter is required');
72
- if (!$height)
73
- throw new Aq_Exception('$height parameter is required');
74
-
75
- // Caipt'n, ready to hook.
76
- if ( true === $upscale ) add_filter( 'image_resize_dimensions', array($this, 'aq_upscale'), 10, 6 );
77
-
78
- // Define upload path & dir.
79
- $upload_info = wp_upload_dir();
80
- $upload_dir = $upload_info['basedir'];
81
- $upload_url = $upload_info['baseurl'];
82
-
83
- $http_prefix = "http://";
84
- $https_prefix = "https://";
85
- $relative_prefix = "//"; // The protocol-relative URL
86
-
87
- /* if the $url scheme differs from $upload_url scheme, make them match
88
- if the schemes differe, images don't show up. */
89
- if(!strncmp($url,$https_prefix,strlen($https_prefix))){ //if url begins with https:// make $upload_url begin with https:// as well
90
- $upload_url = str_replace($http_prefix,$https_prefix,$upload_url);
91
- }
92
- elseif(!strncmp($url,$http_prefix,strlen($http_prefix))){ //if url begins with http:// make $upload_url begin with http:// as well
93
- $upload_url = str_replace($https_prefix,$http_prefix,$upload_url);
94
- }
95
- elseif(!strncmp($url,$relative_prefix,strlen($relative_prefix))){ //if url begins with // make $upload_url begin with // as well
96
- $upload_url = str_replace(array( 0 => "$http_prefix", 1 => "$https_prefix"),$relative_prefix,$upload_url);
97
- }
98
-
99
-
100
- // Check if $img_url is local.
101
- if ( false === strpos( $url, $upload_url ) )
102
- throw new Aq_Exception('Image must be local: ' . $url);
103
-
104
- // Define path of image.
105
- $rel_path = str_replace( $upload_url, '', $url );
106
- $img_path = $upload_dir . $rel_path;
107
-
108
- // Check if img path exists, and is an image indeed.
109
- if ( ! file_exists( $img_path ) or ! getimagesize( $img_path ) )
110
- throw new Aq_Exception('Image file does not exist (or is not an image): ' . $img_path);
111
-
112
- // Get image info.
113
- $info = pathinfo( $img_path );
114
- $ext = $info['extension'];
115
- list( $orig_w, $orig_h ) = getimagesize( $img_path );
116
-
117
- // Get image size after cropping.
118
- $dims = image_resize_dimensions( $orig_w, $orig_h, $width, $height, $crop );
119
- $dst_w = $dims[4];
120
- $dst_h = $dims[5];
121
-
122
- // Return the original image only if it exactly fits the needed measures.
123
- if ( ! $dims && ( ( ( null === $height && $orig_w == $width ) xor ( null === $width && $orig_h == $height ) ) xor ( $height == $orig_h && $width == $orig_w ) ) ) {
124
- $img_url = $url;
125
- $dst_w = $orig_w;
126
- $dst_h = $orig_h;
127
- } else {
128
- // Use this to check if cropped image already exists, so we can return that instead.
129
- $suffix = "{$dst_w}x{$dst_h}";
130
- $dst_rel_path = str_replace( '.' . $ext, '', $rel_path );
131
- $destfilename = "{$upload_dir}{$dst_rel_path}-{$suffix}.{$ext}";
132
-
133
- if ( ! $dims || ( true == $crop && false == $upscale && ( $dst_w < $width || $dst_h < $height ) ) ) {
134
- // Can't resize, so return false saying that the action to do could not be processed as planned.
135
- throw new Aq_Exception('Unable to resize image because image_resize_dimensions() failed');
136
- }
137
- // Else check if cache exists.
138
- elseif ( file_exists( $destfilename ) && getimagesize( $destfilename ) ) {
139
- $img_url = "{$upload_url}{$dst_rel_path}-{$suffix}.{$ext}";
140
- }
141
- // Else, we resize the image and return the new resized image url.
142
- else {
143
-
144
- $editor = wp_get_image_editor( $img_path );
145
-
146
- if ( is_wp_error( $editor ) || is_wp_error( $editor->resize( $width, $height, $crop ) ) ) {
147
- throw new Aq_Exception('Unable to get WP_Image_Editor: ' .
148
- $editor->get_error_message() . ' (is GD or ImageMagick installed?)');
149
- }
150
-
151
- $resized_file = $editor->save();
152
-
153
- if ( ! is_wp_error( $resized_file ) ) {
154
- $resized_rel_path = str_replace( $upload_dir, '', $resized_file['path'] );
155
- $img_url = $upload_url . $resized_rel_path;
156
- } else {
157
- throw new Aq_Exception('Unable to save resized image file: ' . $editor->get_error_message());
158
- }
159
-
160
- }
161
- }
162
-
163
- // Okay, leave the ship.
164
- if ( true === $upscale ) remove_filter( 'image_resize_dimensions', array( $this, 'aq_upscale' ) );
165
-
166
- // Return the output.
167
- if ( $single ) {
168
- // str return.
169
- $image = $img_url;
170
- } else {
171
- // array return.
172
- $image = array (
173
- 0 => $img_url,
174
- 1 => $dst_w,
175
- 2 => $dst_h
176
- );
177
- }
178
-
179
- return $image;
180
- }
181
- catch (Aq_Exception $ex) {
182
- error_log('Aq_Resize.process() error: ' . $ex->getMessage());
183
-
184
- if ($this->throwOnError) {
185
- // Bubble up exception.
186
- throw $ex;
187
- }
188
- else {
189
- // Return false, so that this patch is backwards-compatible.
190
- return false;
191
- }
192
- }
193
- }
194
-
195
- /**
196
- * Callback to overwrite WP computing of thumbnail measures
197
- */
198
- function aq_upscale( $default, $orig_w, $orig_h, $dest_w, $dest_h, $crop ) {
199
- if ( ! $crop ) return null; // Let the wordpress default function handle this.
200
-
201
- // Here is the point we allow to use larger image size than the original one.
202
- $aspect_ratio = $orig_w / $orig_h;
203
- $new_w = $dest_w;
204
- $new_h = $dest_h;
205
-
206
- if ( ! $new_w ) {
207
- $new_w = intval( $new_h * $aspect_ratio );
208
- }
209
-
210
- if ( ! $new_h ) {
211
- $new_h = intval( $new_w / $aspect_ratio );
212
- }
213
-
214
- $size_ratio = max( $new_w / $orig_w, $new_h / $orig_h );
215
-
216
- $crop_w = round( $new_w / $size_ratio );
217
- $crop_h = round( $new_h / $size_ratio );
218
-
219
- $s_x = floor( ( $orig_w - $crop_w ) / 2 );
220
- $s_y = floor( ( $orig_h - $crop_h ) / 2 );
221
-
222
- return array( 0, 0, (int) $s_x, (int) $s_y, (int) $new_w, (int) $new_h, (int) $crop_w, (int) $crop_h );
223
- }
224
- }
225
- }
226
-
227
-
228
-
229
-
230
-
231
- if(!function_exists('aq_resize')) {
232
-
233
- /**
234
- * This is just a tiny wrapper function for the class above so that there is no
235
- * need to change any code in your own WP themes. Usage is still the same :)
236
- */
237
- function aq_resize( $url, $width = null, $height = null, $crop = null, $single = true, $upscale = false ) {
238
- /* WPML Fix */
239
- if ( defined( 'ICL_SITEPRESS_VERSION' ) ){
240
- global $sitepress;
241
- $url = $sitepress->convert_url( $url, $sitepress->get_default_language() );
242
- }
243
- /* WPML Fix */
244
-
245
- $aq_resize = Aq_Resize::getInstance();
246
- return $aq_resize->process( $url, $width, $height, $crop, $single, $upscale );
247
- }
248
- }
249
-
250
-
1
+ <?php
2
+
3
+ /**
4
+ * Title : Aqua Resizer
5
+ * Description : Resizes WordPress images on the fly
6
+ * Version : 1.2.1
7
+ * Author : Syamil MJ
8
+ * Author URI : http://aquagraphite.com
9
+ * License : WTFPL - http://sam.zoy.org/wtfpl/
10
+ * Documentation : https://github.com/sy4mil/Aqua-Resizer/
11
+ *
12
+ * @param string $url - (required) must be uploaded using wp media uploader
13
+ * @param int $width - (required)
14
+ * @param int $height - (optional)
15
+ * @param bool $crop - (optional) default to soft crop
16
+ * @param bool $single - (optional) returns an array if false
17
+ * @param bool $upscale - (optional) resizes smaller images
18
+ * @uses wp_upload_dir()
19
+ * @uses image_resize_dimensions()
20
+ * @uses wp_get_image_editor()
21
+ *
22
+ * @return str|array
23
+ */
24
+
25
+ if(!class_exists('Aq_Resize')) {
26
+ class Aq_Exception extends Exception {}
27
+
28
+ class Aq_Resize
29
+ {
30
+ /**
31
+ * The singleton instance
32
+ */
33
+ static private $instance = null;
34
+
35
+ /**
36
+ * Should an Aq_Exception be thrown on error?
37
+ * If false (default), then the error will just be logged.
38
+ */
39
+ public $throwOnError = false;
40
+
41
+ /**
42
+ * No initialization allowed
43
+ */
44
+ private function __construct() {}
45
+
46
+ /**
47
+ * No cloning allowed
48
+ */
49
+ private function __clone() {}
50
+
51
+ /**
52
+ * For your custom default usage you may want to initialize an Aq_Resize object by yourself and then have own defaults
53
+ */
54
+ static public function getInstance() {
55
+ if(self::$instance == null) {
56
+ self::$instance = new self;
57
+ }
58
+
59
+ return self::$instance;
60
+ }
61
+
62
+ /**
63
+ * Run, forest.
64
+ */
65
+ public function process( $url, $width = null, $height = null, $crop = null, $single = true, $upscale = false ) {
66
+ try {
67
+ // Validate inputs.
68
+ if (!$url)
69
+ throw new Aq_Exception('$url parameter is required');
70
+ if (!$width)
71
+ throw new Aq_Exception('$width parameter is required');
72
+ if (!$height)
73
+ throw new Aq_Exception('$height parameter is required');
74
+
75
+ // Caipt'n, ready to hook.
76
+ if ( true === $upscale ) add_filter( 'image_resize_dimensions', array($this, 'aq_upscale'), 10, 6 );
77
+
78
+ // Define upload path & dir.
79
+ $upload_info = wp_upload_dir();
80
+ $upload_dir = $upload_info['basedir'];
81
+ $upload_url = $upload_info['baseurl'];
82
+
83
+ $http_prefix = "http://";
84
+ $https_prefix = "https://";
85
+ $relative_prefix = "//"; // The protocol-relative URL
86
+
87
+ /* if the $url scheme differs from $upload_url scheme, make them match
88
+ if the schemes differe, images don't show up. */
89
+ if(!strncmp($url,$https_prefix,strlen($https_prefix))){ //if url begins with https:// make $upload_url begin with https:// as well
90
+ $upload_url = str_replace($http_prefix,$https_prefix,$upload_url);
91
+ }
92
+ elseif(!strncmp($url,$http_prefix,strlen($http_prefix))){ //if url begins with http:// make $upload_url begin with http:// as well
93
+ $upload_url = str_replace($https_prefix,$http_prefix,$upload_url);
94
+ }
95
+ elseif(!strncmp($url,$relative_prefix,strlen($relative_prefix))){ //if url begins with // make $upload_url begin with // as well
96
+ $upload_url = str_replace(array( 0 => "$http_prefix", 1 => "$https_prefix"),$relative_prefix,$upload_url);
97
+ }
98
+
99
+
100
+ // Check if $img_url is local.
101
+ if ( false === strpos( $url, $upload_url ) )
102
+ throw new Aq_Exception('Image must be local: ' . $url);
103
+
104
+ // Define path of image.
105
+ $rel_path = str_replace( $upload_url, '', $url );
106
+ $img_path = $upload_dir . $rel_path;
107
+
108
+ // Check if img path exists, and is an image indeed.
109
+ if ( ! file_exists( $img_path ) or ! getimagesize( $img_path ) )
110
+ throw new Aq_Exception('Image file does not exist (or is not an image): ' . $img_path);
111
+
112
+ // Get image info.
113
+ $info = pathinfo( $img_path );
114
+ $ext = $info['extension'];
115
+ list( $orig_w, $orig_h ) = getimagesize( $img_path );
116
+
117
+ // Get image size after cropping.
118
+ $dims = image_resize_dimensions( $orig_w, $orig_h, $width, $height, $crop );
119
+ $dst_w = $dims[4];
120
+ $dst_h = $dims[5];
121
+
122
+ // Return the original image only if it exactly fits the needed measures.
123
+ if ( ! $dims && ( ( ( null === $height && $orig_w == $width ) xor ( null === $width && $orig_h == $height ) ) xor ( $height == $orig_h && $width == $orig_w ) ) ) {
124
+ $img_url = $url;
125
+ $dst_w = $orig_w;
126
+ $dst_h = $orig_h;
127
+ } else {
128
+ // Use this to check if cropped image already exists, so we can return that instead.
129
+ $suffix = "{$dst_w}x{$dst_h}";
130
+ $dst_rel_path = str_replace( '.' . $ext, '', $rel_path );
131
+ $destfilename = "{$upload_dir}{$dst_rel_path}-{$suffix}.{$ext}";
132
+
133
+ if ( ! $dims || ( true == $crop && false == $upscale && ( $dst_w < $width || $dst_h < $height ) ) ) {
134
+ // Can't resize, so return false saying that the action to do could not be processed as planned.
135
+ throw new Aq_Exception('Unable to resize image because image_resize_dimensions() failed');
136
+ }
137
+ // Else check if cache exists.
138
+ elseif ( file_exists( $destfilename ) && getimagesize( $destfilename ) ) {
139
+ $img_url = "{$upload_url}{$dst_rel_path}-{$suffix}.{$ext}";
140
+ }
141
+ // Else, we resize the image and return the new resized image url.
142
+ else {
143
+
144
+ $editor = wp_get_image_editor( $img_path );
145
+
146
+ if ( is_wp_error( $editor ) || is_wp_error( $editor->resize( $width, $height, $crop ) ) ) {
147
+ throw new Aq_Exception('Unable to get WP_Image_Editor: ' .
148
+ $editor->get_error_message() . ' (is GD or ImageMagick installed?)');
149
+ }
150
+
151
+ $resized_file = $editor->save();
152
+
153
+ if ( ! is_wp_error( $resized_file ) ) {
154
+ $resized_rel_path = str_replace( $upload_dir, '', $resized_file['path'] );
155
+ $img_url = $upload_url . $resized_rel_path;
156
+ } else {
157
+ throw new Aq_Exception('Unable to save resized image file: ' . $editor->get_error_message());
158
+ }
159
+
160
+ }
161
+ }
162
+
163
+ // Okay, leave the ship.
164
+ if ( true === $upscale ) remove_filter( 'image_resize_dimensions', array( $this, 'aq_upscale' ) );
165
+
166
+ // Return the output.
167
+ if ( $single ) {
168
+ // str return.
169
+ $image = $img_url;
170
+ } else {
171
+ // array return.
172
+ $image = array (
173
+ 0 => $img_url,
174
+ 1 => $dst_w,
175
+ 2 => $dst_h
176
+ );
177
+ }
178
+
179
+ return $image;
180
+ }
181
+ catch (Aq_Exception $ex) {
182
+ error_log('Aq_Resize.process() error: ' . $ex->getMessage());
183
+
184
+ if ($this->throwOnError) {
185
+ // Bubble up exception.
186
+ throw $ex;
187
+ }
188
+ else {
189
+ // Return false, so that this patch is backwards-compatible.
190
+ return false;
191
+ }
192
+ }
193
+ }
194
+
195
+ /**
196
+ * Callback to overwrite WP computing of thumbnail measures
197
+ */
198
+ function aq_upscale( $default, $orig_w, $orig_h, $dest_w, $dest_h, $crop ) {
199
+ if ( ! $crop ) return null; // Let the wordpress default function handle this.
200
+
201
+ // Here is the point we allow to use larger image size than the original one.
202
+ $aspect_ratio = $orig_w / $orig_h;
203
+ $new_w = $dest_w;
204
+ $new_h = $dest_h;
205
+
206
+ if ( ! $new_w ) {
207
+ $new_w = intval( $new_h * $aspect_ratio );
208
+ }
209
+
210
+ if ( ! $new_h ) {
211
+ $new_h = intval( $new_w / $aspect_ratio );
212
+ }
213
+
214
+ $size_ratio = max( $new_w / $orig_w, $new_h / $orig_h );
215
+
216
+ $crop_w = round( $new_w / $size_ratio );
217
+ $crop_h = round( $new_h / $size_ratio );
218
+
219
+ $s_x = floor( ( $orig_w - $crop_w ) / 2 );
220
+ $s_y = floor( ( $orig_h - $crop_h ) / 2 );
221
+
222
+ return array( 0, 0, (int) $s_x, (int) $s_y, (int) $new_w, (int) $new_h, (int) $crop_w, (int) $crop_h );
223
+ }
224
+ }
225
+ }
226
+
227
+
228
+
229
+
230
+
231
+ if(!function_exists('aq_resize')) {
232
+
233
+ /**
234
+ * This is just a tiny wrapper function for the class above so that there is no
235
+ * need to change any code in your own WP themes. Usage is still the same :)
236
+ */
237
+ function aq_resize( $url, $width = null, $height = null, $crop = null, $single = true, $upscale = false ) {
238
+ /* WPML Fix */
239
+ if ( defined( 'ICL_SITEPRESS_VERSION' ) ){
240
+ global $sitepress;
241
+ $url = $sitepress->convert_url( $url, $sitepress->get_default_language() );
242
+ }
243
+ /* WPML Fix */
244
+
245
+ $aq_resize = Aq_Resize::getInstance();
246
+ return $aq_resize->process( $url, $width, $height, $crop, $single, $upscale );
247
+ }
248
+ }
249
+
250
+
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/index.php CHANGED
@@ -1,2 +1,2 @@
1
- <?php
2
- // Silence is golden.
1
+ <?php
2
+ // Silence is golden.
assets/js/acf-photo-gallery-field.js CHANGED
@@ -1,234 +1,235 @@
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);
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
+ console.log('Hello: ' + JsonField.key);
48
+
49
+ if (typeof attachment.sizes.thumbnail != 'undefined') { url = attachment.sizes.thumbnail.url; }
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, fieldname, form = {};
110
+ button = $(this);
111
+ url = $(this).attr('data-ajaxurl');
112
+ action = 'acf_photo_gallery_edit_save';
113
+ attachment = $(this).attr('data-id');
114
+ fieldname = button.attr('data-fieldname');
115
+
116
+ $('div.acf-photo-gallery-group-' + fieldname + ' #acf-photo-gallery-metabox-edit-' + attachment + ' .acf-photo-gallery-edit-field').each(function(i, obj) {
117
+ if (obj.name == 'acf-pg-hidden-action') {
118
+ form['action'] = obj.value;
119
+ } else if( obj.type == 'checkbox'){
120
+ if( $(this).prop("checked") ){
121
+ form[obj.name] = obj.value;
122
+ } else {
123
+ form[obj.name] = null;
124
+ }
125
+ } else {
126
+ form[obj.name] = obj.value;
127
+ }
128
+ });
129
+
130
+ button.attr('disabled', true).html('Saving...');
131
+ $.post(url, form, function(data) {
132
+ button.attr('disabled', false).html('Save Changes');
133
+ $('#acf-photo-gallery-metabox-edit #acf-photo-gallery-metabox-edit-' + attachment).fadeOut('fast');
134
+ });
135
+ return false;
136
+ });
137
+
138
+ $(document).on('click', '.acf-photo-gallery-metabox-list .dashicons-edit', function() {
139
+ var $btn = $(this);
140
+ var id = $btn.attr('data-id');
141
+ var field = $btn.attr('data-field');
142
+ var modal = $('.acf-photo-gallery-group-' + field + ' input[name="acf-photo-gallery-edit-modal"]').val();
143
+ var $list = $('.acf-photo-gallery-group-' + field + ' ul.acf-photo-gallery-metabox-list');
144
+ var index = $('.acf-photo-gallery-group-' + field + ' ul.acf-photo-gallery-metabox-list li').index();
145
+
146
+ if (modal === 'Native') {
147
+ wp.media.editor.send.attachment = function(_, attachment){
148
+ acf_photo_gallery_html(attachment, field, {
149
+ index: index,
150
+ splice: 1
151
+ });
152
+ };
153
+
154
+ var editor = wp.media.editor.open($btn, function() {}).state();
155
+ editor.set('menu', false);
156
+
157
+ var selection = editor.get('selection');
158
+ selection.multiple = false;
159
+ selection.reset([wp.media.attachment(id)]);
160
+
161
+ /**
162
+ * @param {{ id: number }} deleted
163
+ */
164
+ var handleDestroy = function (deleted) {
165
+ $list.children().each(function () {
166
+ var $elem = $(this);
167
+
168
+ if ($elem.data('id') === deleted.id) {
169
+ remove($elem.find('.dashicons-dismiss'));
170
+ }
171
+ });
172
+ };
173
+
174
+ var library = editor.get('library');
175
+ library.on('destroy', handleDestroy);
176
+
177
+ editor.on('close', function () {
178
+ library.off('destroy', handleDestroy);
179
+ });
180
+
181
+ $('.acf-photo-gallery-group-' + field + ' .acf-photo-gallery-metabox-list li.acf-photo-gallery-media-box-placeholder').remove();
182
+ } else {
183
+ $('.acf-photo-gallery-group-' + field + ' #acf-photo-gallery-metabox-edit-' + id).fadeToggle('fast');
184
+ }
185
+
186
+ return false;
187
+ });
188
+
189
+ if (typeof acf.add_action !== 'undefined') {
190
+ /*
191
+ * ready append (ACF5)
192
+ *
193
+ * These are 2 events which are fired during the page load
194
+ * ready = on page load similar to $(document).ready()
195
+ * append = on new DOM elements appended via repeater field
196
+ *
197
+ * @type event
198
+ * @date 20/07/13
199
+ *
200
+ * @param $el (jQuery selection) the jQuery element which contains the ACF fields
201
+ * @return n/a
202
+ */
203
+ acf.add_action('ready append', function($el) {
204
+ // search $el for fields of type 'photo_gallery'
205
+ acf.get_fields({ type: 'photo_gallery' }, $el).each(function() {
206
+ initialize_field($(this));
207
+ acf_photo_gallery_add_media( $(this) );
208
+ });
209
+ });
210
+ } else {
211
+ /*
212
+ * acf/setup_fields (ACF4)
213
+ *
214
+ * This event is triggered when ACF adds any new elements to the DOM.
215
+ *
216
+ * @type function
217
+ * @since 1.0.0
218
+ * @date 01/01/12
219
+ *
220
+ * @param event e: an event object. This can be ignored
221
+ * @param Element postbox: An element which contains the new HTML
222
+ *
223
+ * @return n/a
224
+ */
225
+ $(document).on('acf/setup_fields', function(e, postbox) {
226
+ $(postbox).find('.field[data-field_type="photo_gallery"]').each(function() {
227
+ initialize_field($(this));
228
+ acf_photo_gallery_add_media( $(this) );
229
+ //acf_photo_gallery_edit_popover( $(this) );
230
+ //acf_photo_gallery_limit_images( $(this) );
231
+ });
232
+ });
233
+ }
234
+
235
  })(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;
fields/acf-photo_gallery-v5.php CHANGED
@@ -1,105 +1,105 @@
1
- <?php
2
-
3
- // exit if accessed directly
4
- if( ! defined( 'ABSPATH' ) ) exit;
5
-
6
- if( !defined('ACF_VERSION') ){ define('ACF_VERSION', $version); }
7
-
8
- //Saving the gallery image ids into the database postmeta table in the same order.
9
- include( dirname(dirname(__FILE__)) . '/includes/acf_photo_gallery_save.php' );
10
-
11
- //Remove photo from the database array
12
- include( dirname(dirname(__FILE__)) . '/includes/acf_photo_gallery_remove_photo.php' );
13
-
14
- //Editing and saving photo details
15
- include( dirname(dirname(__FILE__)) . '/includes/acf_photo_gallery_edit_save.php' );
16
-
17
- // check if class already exists
18
- if( !class_exists('acf_field_photo_gallery') ) :
19
-
20
- class acf_field_photo_gallery extends acf_field {
21
-
22
-
23
- /*
24
- * __construct
25
- *
26
- * This function will setup the field type data
27
- *
28
- * @type function
29
- * @date 5/03/2014
30
- * @since 5.0.0
31
- *
32
- * @param n/a
33
- * @return n/a
34
- */
35
-
36
- function __construct( $settings )
37
- {
38
- include( dirname(dirname(__FILE__)) . '/includes/__construct.php' );
39
- }
40
-
41
-
42
- /*
43
- * render_field_settings()
44
- *
45
- * Create extra settings for your field. These are visible when editing a field
46
- *
47
- * @type action
48
- * @since 3.6
49
- * @date 23/01/13
50
- *
51
- * @param $field (array) the $field being edited
52
- * @return n/a
53
- */
54
-
55
- function render_field_settings( $field )
56
- {
57
- include( dirname(dirname(__FILE__)) . '/includes/v5/render_field_settings.php' );
58
- }
59
-
60
-
61
- /*
62
- * render_field()
63
- *
64
- * Create the HTML interface for your field
65
- *
66
- * @param $field (array) the $field being rendered
67
- *
68
- * @type action
69
- * @since 3.6
70
- * @date 23/01/13
71
- *
72
- * @param $field (array) the $field being edited
73
- * @return n/a
74
- */
75
-
76
- function render_field( $field )
77
- {
78
- include( dirname(dirname(__FILE__)) . '/includes/render_field.php' );
79
- }
80
-
81
-
82
- /*
83
- * input_admin_enqueue_scripts()
84
- *
85
- * This action is called in the admin_enqueue_scripts action on the edit screen where your field is created.
86
- * Use this action to add CSS + JavaScript to assist your create_field() action.
87
- *
88
- * $info http://codex.wordpress.org/Plugin_API/Action_Reference/admin_enqueue_scripts
89
- * @type action
90
- * @since 3.6
91
- * @date 23/01/13
92
- */
93
-
94
- function input_admin_enqueue_scripts()
95
- {
96
- include( dirname(dirname(__FILE__)) . '/includes/input_admin_enqueue_scripts.php' );
97
- }
98
-
99
- }
100
-
101
- // initialize
102
- new acf_field_photo_gallery( $this->settings );
103
-
104
- // class_exists check
105
  endif;
1
+ <?php
2
+
3
+ // exit if accessed directly
4
+ if( ! defined( 'ABSPATH' ) ) exit;
5
+
6
+ if( !defined('ACF_VERSION') ){ define('ACF_VERSION', $version); }
7
+
8
+ //Saving the gallery image ids into the database postmeta table in the same order.
9
+ include( dirname(dirname(__FILE__)) . '/includes/acf_photo_gallery_save.php' );
10
+
11
+ //Remove photo from the database array
12
+ include( dirname(dirname(__FILE__)) . '/includes/acf_photo_gallery_remove_photo.php' );
13
+
14
+ //Editing and saving photo details
15
+ include( dirname(dirname(__FILE__)) . '/includes/acf_photo_gallery_edit_save.php' );
16
+
17
+ // check if class already exists
18
+ if( !class_exists('acf_field_photo_gallery') ) :
19
+
20
+ class acf_field_photo_gallery extends acf_field {
21
+
22
+
23
+ /*
24
+ * __construct
25
+ *
26
+ * This function will setup the field type data
27
+ *
28
+ * @type function
29
+ * @date 5/03/2014
30
+ * @since 5.0.0
31
+ *
32
+ * @param n/a
33
+ * @return n/a
34
+ */
35
+
36
+ function __construct( $settings )
37
+ {
38
+ include( dirname(dirname(__FILE__)) . '/includes/__construct.php' );
39
+ }
40
+
41
+
42
+ /*
43
+ * render_field_settings()
44
+ *
45
+ * Create extra settings for your field. These are visible when editing a field
46
+ *
47
+ * @type action
48
+ * @since 3.6
49
+ * @date 23/01/13
50
+ *
51
+ * @param $field (array) the $field being edited
52
+ * @return n/a
53
+ */
54
+
55
+ function render_field_settings( $field )
56
+ {
57
+ include( dirname(dirname(__FILE__)) . '/includes/v5/render_field_settings.php' );
58
+ }
59
+
60
+
61
+ /*
62
+ * render_field()
63
+ *
64
+ * Create the HTML interface for your field
65
+ *
66
+ * @param $field (array) the $field being rendered
67
+ *
68
+ * @type action
69
+ * @since 3.6
70
+ * @date 23/01/13
71
+ *
72
+ * @param $field (array) the $field being edited
73
+ * @return n/a
74
+ */
75
+
76
+ function render_field( $field )
77
+ {
78
+ include( dirname(dirname(__FILE__)) . '/includes/render_field.php' );
79
+ }
80
+
81
+
82
+ /*
83
+ * input_admin_enqueue_scripts()
84
+ *
85
+ * This action is called in the admin_enqueue_scripts action on the edit screen where your field is created.
86
+ * Use this action to add CSS + JavaScript to assist your create_field() action.
87
+ *
88
+ * $info http://codex.wordpress.org/Plugin_API/Action_Reference/admin_enqueue_scripts
89
+ * @type action
90
+ * @since 3.6
91
+ * @date 23/01/13
92
+ */
93
+
94
+ function input_admin_enqueue_scripts()
95
+ {
96
+ include( dirname(dirname(__FILE__)) . '/includes/input_admin_enqueue_scripts.php' );
97
+ }
98
+
99
+ }
100
+
101
+ // initialize
102
+ new acf_field_photo_gallery( $this->settings );
103
+
104
+ // class_exists check
105
  endif;
fields/index.php CHANGED
@@ -1,2 +1,2 @@
1
- <?php
2
- // Silence is golden.
1
+ <?php
2
+ // Silence is golden.
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, $acf_fieldkey){
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, $acf_fieldkey);
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 ($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-fieldname="<?php echo $acf_fieldkey; ?>" 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/aq_resizer.php CHANGED
@@ -1,246 +1,246 @@
1
- <?php
2
-
3
- /**
4
- * Title : Aqua Resizer
5
- * Description : Resizes WordPress images on the fly
6
- * Version : 1.2.1
7
- * Author : Syamil MJ
8
- * Author URI : http://aquagraphite.com
9
- * License : WTFPL - http://sam.zoy.org/wtfpl/
10
- * Documentation : https://github.com/sy4mil/Aqua-Resizer/
11
- *
12
- * @param string $url - (required) must be uploaded using wp media uploader
13
- * @param int $width - (required)
14
- * @param int $height - (optional)
15
- * @param bool $crop - (optional) default to soft crop
16
- * @param bool $single - (optional) returns an array if false
17
- * @param bool $upscale - (optional) resizes smaller images
18
- * @uses wp_upload_dir()
19
- * @uses image_resize_dimensions()
20
- * @uses wp_get_image_editor()
21
- *
22
- * @return str|array
23
- */
24
-
25
- if(!class_exists('Aq_Resize')) {
26
- class Aq_Exception extends Exception {}
27
-
28
- class Aq_Resize
29
- {
30
- /**
31
- * The singleton instance
32
- */
33
- static private $instance = null;
34
-
35
- /**
36
- * Should an Aq_Exception be thrown on error?
37
- * If false (default), then the error will just be logged.
38
- */
39
- public $throwOnError = false;
40
-
41
- /**
42
- * No initialization allowed
43
- */
44
- private function __construct() {}
45
-
46
- /**
47
- * No cloning allowed
48
- */
49
- private function __clone() {}
50
-
51
- /**
52
- * For your custom default usage you may want to initialize an Aq_Resize object by yourself and then have own defaults
53
- */
54
- static public function getInstance() {
55
- if(self::$instance == null) {
56
- self::$instance = new self;
57
- }
58
-
59
- return self::$instance;
60
- }
61
-
62
- /**
63
- * Run, forest.
64
- */
65
- public function process( $url, $width = null, $height = null, $crop = null, $single = true, $upscale = false ) {
66
- try {
67
- // Validate inputs.
68
- if (!$url)
69
- throw new Aq_Exception('$url parameter is required');
70
- if (!$width)
71
- throw new Aq_Exception('$width parameter is required');
72
- if (!$height)
73
- throw new Aq_Exception('$height parameter is required');
74
-
75
- // Caipt'n, ready to hook.
76
- if ( true === $upscale ) add_filter( 'image_resize_dimensions', array($this, 'aq_upscale'), 10, 6 );
77
-
78
- // Define upload path & dir.
79
- $upload_info = wp_upload_dir();
80
- $upload_dir = $upload_info['basedir'];
81
- $upload_url = $upload_info['baseurl'];
82
-
83
- $http_prefix = "http://";
84
- $https_prefix = "https://";
85
- $relative_prefix = "//"; // The protocol-relative URL
86
-
87
- /* if the $url scheme differs from $upload_url scheme, make them match
88
- if the schemes differe, images don't show up. */
89
- if(!strncmp($url,$https_prefix,strlen($https_prefix))){ //if url begins with https:// make $upload_url begin with https:// as well
90
- $upload_url = str_replace($http_prefix,$https_prefix,$upload_url);
91
- }
92
- elseif(!strncmp($url,$http_prefix,strlen($http_prefix))){ //if url begins with http:// make $upload_url begin with http:// as well
93
- $upload_url = str_replace($https_prefix,$http_prefix,$upload_url);
94
- }
95
- elseif(!strncmp($url,$relative_prefix,strlen($relative_prefix))){ //if url begins with // make $upload_url begin with // as well
96
- $upload_url = str_replace(array( 0 => "$http_prefix", 1 => "$https_prefix"),$relative_prefix,$upload_url);
97
- }
98
-
99
-
100
- // Check if $img_url is local.
101
- if ( false === strpos( $url, $upload_url ) )
102
- throw new Aq_Exception('Image must be local: ' . $url);
103
-
104
- // Define path of image.
105
- $rel_path = str_replace( $upload_url, '', $url );
106
- $img_path = $upload_dir . $rel_path;
107
-
108
- // Check if img path exists, and is an image indeed.
109
- if ( ! file_exists( $img_path ) or ! getimagesize( $img_path ) )
110
- throw new Aq_Exception('Image file does not exist (or is not an image): ' . $img_path);
111
-
112
- // Get image info.
113
- $info = pathinfo( $img_path );
114
- $ext = $info['extension'];
115
- list( $orig_w, $orig_h ) = getimagesize( $img_path );
116
-
117
- // Get image size after cropping.
118
- $dims = image_resize_dimensions( $orig_w, $orig_h, $width, $height, $crop );
119
- $dst_w = $dims[4];
120
- $dst_h = $dims[5];
121
-
122
- // Return the original image only if it exactly fits the needed measures.
123
- if ( ! $dims && ( ( ( null === $height && $orig_w == $width ) xor ( null === $width && $orig_h == $height ) ) xor ( $height == $orig_h && $width == $orig_w ) ) ) {
124
- $img_url = $url;
125
- $dst_w = $orig_w;
126
- $dst_h = $orig_h;
127
- } else {
128
- // Use this to check if cropped image already exists, so we can return that instead.
129
- $suffix = "{$dst_w}x{$dst_h}";
130
- $dst_rel_path = str_replace( '.' . $ext, '', $rel_path );
131
- $destfilename = "{$upload_dir}{$dst_rel_path}-{$suffix}.{$ext}";
132
-
133
- if ( ! $dims || ( true == $crop && false == $upscale && ( $dst_w < $width || $dst_h < $height ) ) ) {
134
- // Can't resize, so return false saying that the action to do could not be processed as planned.
135
- throw new Aq_Exception('Unable to resize image because image_resize_dimensions() failed');
136
- }
137
- // Else check if cache exists.
138
- elseif ( file_exists( $destfilename ) && getimagesize( $destfilename ) ) {
139
- $img_url = "{$upload_url}{$dst_rel_path}-{$suffix}.{$ext}";
140
- }
141
- // Else, we resize the image and return the new resized image url.
142
- else {
143
-
144
- $editor = wp_get_image_editor( $img_path );
145
-
146
- if ( is_wp_error( $editor ) || is_wp_error( $editor->resize( $width, $height, $crop ) ) ) {
147
- throw new Aq_Exception('Unable to get WP_Image_Editor: ' .
148
- $editor->get_error_message() . ' (is GD or ImageMagick installed?)');
149
- }
150
-
151
- $resized_file = $editor->save();
152
-
153
- if ( ! is_wp_error( $resized_file ) ) {
154
- $resized_rel_path = str_replace( $upload_dir, '', $resized_file['path'] );
155
- $img_url = $upload_url . $resized_rel_path;
156
- } else {
157
- throw new Aq_Exception('Unable to save resized image file: ' . $editor->get_error_message());
158
- }
159
-
160
- }
161
- }
162
-
163
- // Okay, leave the ship.
164
- if ( true === $upscale ) remove_filter( 'image_resize_dimensions', array( $this, 'aq_upscale' ) );
165
-
166
- // Return the output.
167
- if ( $single ) {
168
- // str return.
169
- $image = $img_url;
170
- } else {
171
- // array return.
172
- $image = array (
173
- 0 => $img_url,
174
- 1 => $dst_w,
175
- 2 => $dst_h
176
- );
177
- }
178
-
179
- return $image;
180
- }
181
- catch (Aq_Exception $ex) {
182
- error_log('Aq_Resize.process() error: ' . $ex->getMessage());
183
-
184
- if ($this->throwOnError) {
185
- // Bubble up exception.
186
- throw $ex;
187
- }
188
- else {
189
- // Return false, so that this patch is backwards-compatible.
190
- return false;
191
- }
192
- }
193
- }
194
-
195
- /**
196
- * Callback to overwrite WP computing of thumbnail measures
197
- */
198
- function aq_upscale( $default, $orig_w, $orig_h, $dest_w, $dest_h, $crop ) {
199
- if ( ! $crop ) return null; // Let the wordpress default function handle this.
200
-
201
- // Here is the point we allow to use larger image size than the original one.
202
- $aspect_ratio = $orig_w / $orig_h;
203
- $new_w = $dest_w;
204
- $new_h = $dest_h;
205
-
206
- if ( ! $new_w ) {
207
- $new_w = intval( $new_h * $aspect_ratio );
208
- }
209
-
210
- if ( ! $new_h ) {
211
- $new_h = intval( $new_w / $aspect_ratio );
212
- }
213
-
214
- $size_ratio = max( $new_w / $orig_w, $new_h / $orig_h );
215
-
216
- $crop_w = round( $new_w / $size_ratio );
217
- $crop_h = round( $new_h / $size_ratio );
218
-
219
- $s_x = floor( ( $orig_w - $crop_w ) / 2 );
220
- $s_y = floor( ( $orig_h - $crop_h ) / 2 );
221
-
222
- return array( 0, 0, (int) $s_x, (int) $s_y, (int) $new_w, (int) $new_h, (int) $crop_w, (int) $crop_h );
223
- }
224
- }
225
- }
226
-
227
- if(!function_exists('aq_resize')) {
228
-
229
- /**
230
- * This is just a tiny wrapper function for the class above so that there is no
231
- * need to change any code in your own WP themes. Usage is still the same :)
232
- */
233
- function aq_resize( $url, $width = null, $height = null, $crop = null, $single = true, $upscale = false ) {
234
- /* WPML Fix */
235
- if ( defined( 'ICL_SITEPRESS_VERSION' ) ){
236
- global $sitepress;
237
- $url = $sitepress->convert_url( $url, $sitepress->get_default_language() );
238
- }
239
- /* WPML Fix */
240
-
241
- $aq_resize = Aq_Resize::getInstance();
242
- return $aq_resize->process( $url, $width, $height, $crop, $single, $upscale );
243
- }
244
- }
245
-
246
-
1
+ <?php
2
+
3
+ /**
4
+ * Title : Aqua Resizer
5
+ * Description : Resizes WordPress images on the fly
6
+ * Version : 1.2.1
7
+ * Author : Syamil MJ
8
+ * Author URI : http://aquagraphite.com
9
+ * License : WTFPL - http://sam.zoy.org/wtfpl/
10
+ * Documentation : https://github.com/sy4mil/Aqua-Resizer/
11
+ *
12
+ * @param string $url - (required) must be uploaded using wp media uploader
13
+ * @param int $width - (required)
14
+ * @param int $height - (optional)
15
+ * @param bool $crop - (optional) default to soft crop
16
+ * @param bool $single - (optional) returns an array if false
17
+ * @param bool $upscale - (optional) resizes smaller images
18
+ * @uses wp_upload_dir()
19
+ * @uses image_resize_dimensions()
20
+ * @uses wp_get_image_editor()
21
+ *
22
+ * @return str|array
23
+ */
24
+
25
+ if(!class_exists('Aq_Resize')) {
26
+ class Aq_Exception extends Exception {}
27
+
28
+ class Aq_Resize
29
+ {
30
+ /**
31
+ * The singleton instance
32
+ */
33
+ static private $instance = null;
34
+
35
+ /**
36
+ * Should an Aq_Exception be thrown on error?
37
+ * If false (default), then the error will just be logged.
38
+ */
39
+ public $throwOnError = false;
40
+
41
+ /**
42
+ * No initialization allowed
43
+ */
44
+ private function __construct() {}
45
+
46
+ /**
47
+ * No cloning allowed
48
+ */
49
+ private function __clone() {}
50
+
51
+ /**
52
+ * For your custom default usage you may want to initialize an Aq_Resize object by yourself and then have own defaults
53
+ */
54
+ static public function getInstance() {
55
+ if(self::$instance == null) {
56
+ self::$instance = new self;
57
+ }
58
+
59
+ return self::$instance;
60
+ }
61
+
62
+ /**
63
+ * Run, forest.
64
+ */
65
+ public function process( $url, $width = null, $height = null, $crop = null, $single = true, $upscale = false ) {
66
+ try {
67
+ // Validate inputs.
68
+ if (!$url)
69
+ throw new Aq_Exception('$url parameter is required');
70
+ if (!$width)
71
+ throw new Aq_Exception('$width parameter is required');
72
+ if (!$height)
73
+ throw new Aq_Exception('$height parameter is required');
74
+
75
+ // Caipt'n, ready to hook.
76
+ if ( true === $upscale ) add_filter( 'image_resize_dimensions', array($this, 'aq_upscale'), 10, 6 );
77
+
78
+ // Define upload path & dir.
79
+ $upload_info = wp_upload_dir();
80
+ $upload_dir = $upload_info['basedir'];
81
+ $upload_url = $upload_info['baseurl'];
82
+
83
+ $http_prefix = "http://";
84
+ $https_prefix = "https://";
85
+ $relative_prefix = "//"; // The protocol-relative URL
86
+
87
+ /* if the $url scheme differs from $upload_url scheme, make them match
88
+ if the schemes differe, images don't show up. */
89
+ if(!strncmp($url,$https_prefix,strlen($https_prefix))){ //if url begins with https:// make $upload_url begin with https:// as well
90
+ $upload_url = str_replace($http_prefix,$https_prefix,$upload_url);
91
+ }
92
+ elseif(!strncmp($url,$http_prefix,strlen($http_prefix))){ //if url begins with http:// make $upload_url begin with http:// as well
93
+ $upload_url = str_replace($https_prefix,$http_prefix,$upload_url);
94
+ }
95
+ elseif(!strncmp($url,$relative_prefix,strlen($relative_prefix))){ //if url begins with // make $upload_url begin with // as well
96
+ $upload_url = str_replace(array( 0 => "$http_prefix", 1 => "$https_prefix"),$relative_prefix,$upload_url);
97
+ }
98
+
99
+
100
+ // Check if $img_url is local.
101
+ if ( false === strpos( $url, $upload_url ) )
102
+ throw new Aq_Exception('Image must be local: ' . $url);
103
+
104
+ // Define path of image.
105
+ $rel_path = str_replace( $upload_url, '', $url );
106
+ $img_path = $upload_dir . $rel_path;
107
+
108
+ // Check if img path exists, and is an image indeed.
109
+ if ( ! file_exists( $img_path ) or ! getimagesize( $img_path ) )
110
+ throw new Aq_Exception('Image file does not exist (or is not an image): ' . $img_path);
111
+
112
+ // Get image info.
113
+ $info = pathinfo( $img_path );
114
+ $ext = $info['extension'];
115
+ list( $orig_w, $orig_h ) = getimagesize( $img_path );
116
+
117
+ // Get image size after cropping.
118
+ $dims = image_resize_dimensions( $orig_w, $orig_h, $width, $height, $crop );
119
+ $dst_w = $dims[4];
120
+ $dst_h = $dims[5];
121
+
122
+ // Return the original image only if it exactly fits the needed measures.
123
+ if ( ! $dims && ( ( ( null === $height && $orig_w == $width ) xor ( null === $width && $orig_h == $height ) ) xor ( $height == $orig_h && $width == $orig_w ) ) ) {
124
+ $img_url = $url;
125
+ $dst_w = $orig_w;
126
+ $dst_h = $orig_h;
127
+ } else {
128
+ // Use this to check if cropped image already exists, so we can return that instead.
129
+ $suffix = "{$dst_w}x{$dst_h}";
130
+ $dst_rel_path = str_replace( '.' . $ext, '', $rel_path );
131
+ $destfilename = "{$upload_dir}{$dst_rel_path}-{$suffix}.{$ext}";
132
+
133
+ if ( ! $dims || ( true == $crop && false == $upscale && ( $dst_w < $width || $dst_h < $height ) ) ) {
134
+ // Can't resize, so return false saying that the action to do could not be processed as planned.
135
+ throw new Aq_Exception('Unable to resize image because image_resize_dimensions() failed');
136
+ }
137
+ // Else check if cache exists.
138
+ elseif ( file_exists( $destfilename ) && getimagesize( $destfilename ) ) {
139
+ $img_url = "{$upload_url}{$dst_rel_path}-{$suffix}.{$ext}";
140
+ }
141
+ // Else, we resize the image and return the new resized image url.
142
+ else {
143
+
144
+ $editor = wp_get_image_editor( $img_path );
145
+
146
+ if ( is_wp_error( $editor ) || is_wp_error( $editor->resize( $width, $height, $crop ) ) ) {
147
+ throw new Aq_Exception('Unable to get WP_Image_Editor: ' .
148
+ $editor->get_error_message() . ' (is GD or ImageMagick installed?)');
149
+ }
150
+
151
+ $resized_file = $editor->save();
152
+
153
+ if ( ! is_wp_error( $resized_file ) ) {
154
+ $resized_rel_path = str_replace( $upload_dir, '', $resized_file['path'] );
155
+ $img_url = $upload_url . $resized_rel_path;
156
+ } else {
157
+ throw new Aq_Exception('Unable to save resized image file: ' . $editor->get_error_message());
158
+ }
159
+
160
+ }
161
+ }
162
+
163
+ // Okay, leave the ship.
164
+ if ( true === $upscale ) remove_filter( 'image_resize_dimensions', array( $this, 'aq_upscale' ) );
165
+
166
+ // Return the output.
167
+ if ( $single ) {
168
+ // str return.
169
+ $image = $img_url;
170
+ } else {
171
+ // array return.
172
+ $image = array (
173
+ 0 => $img_url,
174
+ 1 => $dst_w,
175
+ 2 => $dst_h
176
+ );
177
+ }
178
+
179
+ return $image;
180
+ }
181
+ catch (Aq_Exception $ex) {
182
+ error_log('Aq_Resize.process() error: ' . $ex->getMessage());
183
+
184
+ if ($this->throwOnError) {
185
+ // Bubble up exception.
186
+ throw $ex;
187
+ }
188
+ else {
189
+ // Return false, so that this patch is backwards-compatible.
190
+ return false;
191
+ }
192
+ }
193
+ }
194
+
195
+ /**
196
+ * Callback to overwrite WP computing of thumbnail measures
197
+ */
198
+ function aq_upscale( $default, $orig_w, $orig_h, $dest_w, $dest_h, $crop ) {
199
+ if ( ! $crop ) return null; // Let the wordpress default function handle this.
200
+
201
+ // Here is the point we allow to use larger image size than the original one.
202
+ $aspect_ratio = $orig_w / $orig_h;
203
+ $new_w = $dest_w;
204
+ $new_h = $dest_h;
205
+
206
+ if ( ! $new_w ) {
207
+ $new_w = intval( $new_h * $aspect_ratio );
208
+ }
209
+
210
+ if ( ! $new_h ) {
211
+ $new_h = intval( $new_w / $aspect_ratio );
212
+ }
213
+
214
+ $size_ratio = max( $new_w / $orig_w, $new_h / $orig_h );
215
+
216
+ $crop_w = round( $new_w / $size_ratio );
217
+ $crop_h = round( $new_h / $size_ratio );
218
+
219
+ $s_x = floor( ( $orig_w - $crop_w ) / 2 );
220
+ $s_y = floor( ( $orig_h - $crop_h ) / 2 );
221
+
222
+ return array( 0, 0, (int) $s_x, (int) $s_y, (int) $new_w, (int) $new_h, (int) $crop_w, (int) $crop_h );
223
+ }
224
+ }
225
+ }
226
+
227
+ if(!function_exists('aq_resize')) {
228
+
229
+ /**
230
+ * This is just a tiny wrapper function for the class above so that there is no
231
+ * need to change any code in your own WP themes. Usage is still the same :)
232
+ */
233
+ function aq_resize( $url, $width = null, $height = null, $crop = null, $single = true, $upscale = false ) {
234
+ /* WPML Fix */
235
+ if ( defined( 'ICL_SITEPRESS_VERSION' ) ){
236
+ global $sitepress;
237
+ $url = $sitepress->convert_url( $url, $sitepress->get_default_language() );
238
+ }
239
+ /* WPML Fix */
240
+
241
+ $aq_resize = Aq_Resize::getInstance();
242
+ return $aq_resize->process( $url, $width, $height, $crop, $single, $upscale );
243
+ }
244
+ }
245
+
246
+
includes/index.php CHANGED
@@ -1,2 +1,2 @@
1
- <?php
2
- // Silence is golden.
1
+ <?php
2
+ // Silence is golden.
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 $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>
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, $key);
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/v4/index.php CHANGED
@@ -1,2 +1,2 @@
1
- <?php
2
- // Silence is golden.
1
+ <?php
2
+ // Silence is golden.
includes/v5/index.php CHANGED
@@ -1,2 +1,2 @@
1
- <?php
2
- // Silence is golden.
1
+ <?php
2
+ // Silence is golden.
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
  ));
index.php CHANGED
@@ -1,2 +1,2 @@
1
- <?php
2
- // Silence is golden.
1
+ <?php
2
+ // Silence is golden.
lang/index.php CHANGED
@@ -1,2 +1,2 @@
1
- <?php
2
- // Silence is golden.
1
+ <?php
2
+ // Silence is golden.
navz-photo-gallery.php CHANGED
@@ -1,130 +1,137 @@
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' );
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ Plugin Name: ACF Photo Gallery Field
5
+ Plugin URI: http://www.navz.me/
6
+ Description: An extension for Advance Custom Fields which lets you add photo gallery functionality on your websites.
7
+ Version: 1.6.5
8
+ Author: Navneil Naicker
9
+ Author URI: http://www.navz.me/
10
+ License: GPLv2 or later
11
+ License URI: http://www.gnu.org/licenses/gpl-2.0.html
12
+ */
13
+
14
+ // exit if accessed directly
15
+ if( ! defined( 'ABSPATH' ) ) exit;
16
+
17
+
18
+ // check if class already exists
19
+ if( !class_exists('acf_plugin_photo_gallery') ) :
20
+
21
+ class acf_plugin_photo_gallery{
22
+
23
+ // vars
24
+ var $settings;
25
+
26
+ /*
27
+ * __construct
28
+ *
29
+ * This function will setup the class functionality
30
+ *
31
+ * @type function
32
+ * @date 17/02/2016
33
+ * @since 1.0.0
34
+ *
35
+ * @param n/a
36
+ * @return n/a
37
+ */
38
+
39
+ function __construct() {
40
+
41
+ // vars
42
+ $this->settings = array(
43
+ 'version' => '1.6.5',
44
+ 'url' => plugin_dir_url( __FILE__ ),
45
+ 'path' => plugin_dir_path( __FILE__ )
46
+ );
47
+
48
+ // set text domain
49
+ // https://codex.wordpress.org/Function_Reference/load_plugin_textdomain
50
+ load_plugin_textdomain( 'acf-photo_gallery', false, plugin_basename( dirname( __FILE__ ) ) . '/lang' );
51
+
52
+ add_action( 'admin_enqueue_scripts', array($this, 'acf_photo_gallery_sortable') );
53
+
54
+ // include field
55
+ add_action('acf/include_field_types', array($this, 'include_field_types')); // v5
56
+ add_action('acf/register_fields', array($this, 'include_field_types')); // v4
57
+
58
+ //Pull the caption from attachment caption field
59
+ add_filter( 'acf_photo_gallery_caption_from_attachment', '__return_false' );
60
+
61
+ //Add support for REST API
62
+ add_filter("rest_prepare_page", array($this, 'rest_prepare_post'), 10, 3);
63
+
64
+ }
65
+
66
+ //Add in jquery-ui-sortable script
67
+ function acf_photo_gallery_sortable($hook) {
68
+ if ( 'post.php' == $hook ) { wp_enqueue_script( 'jquery-ui-sortable', 'jquery-ui-sortable', 'jquery', '9999', true); }
69
+ }
70
+
71
+ /*
72
+ * include_field_types
73
+ *
74
+ * This function will include the field type class
75
+ *
76
+ * @type function
77
+ * @date 17/02/2016
78
+ * @since 1.0.0
79
+ *
80
+ * @param $version (int) major ACF version. Defaults to false
81
+ * @return n/a
82
+ */
83
+
84
+ function include_field_types( $version = false ) {
85
+
86
+ // support empty $version
87
+ if( !$version ) $version = 4;
88
+
89
+ // include
90
+ include_once('fields/acf-photo_gallery-v' . $version . '.php');
91
+
92
+ }
93
+
94
+ function rest_prepare_post( $data, $post, $request ){
95
+ $images = array();
96
+ $field_groups = acf_get_field_groups(array('post_id' => $post->ID));
97
+ foreach ( $field_groups as $group ){
98
+ $fields = get_posts(array(
99
+ 'posts_per_page' => -1,
100
+ 'post_type' => 'acf-field',
101
+ 'orderby' => 'menu_order',
102
+ 'order' => 'ASC',
103
+ 'suppress_filters' => true,
104
+ 'post_parent' => $group['ID'],
105
+ 'post_status' => 'publish',
106
+ 'update_post_meta_cache' => false
107
+ ));
108
+ foreach ( $fields as $field ) {
109
+ $object = get_field_object($field->post_name);
110
+ if( $object['type'] == 'photo_gallery' ){
111
+ $images[] = acf_photo_gallery($object['name'], $post->ID);
112
+ $data->data['acf']['photo_gallery'][$object['name']] = $images;
113
+ }
114
+ }
115
+ }
116
+ return $data;
117
+ }
118
+
119
+ }
120
+
121
+ // initialize
122
+ new acf_plugin_photo_gallery();
123
+
124
+ // class_exists check
125
+ endif;
126
+
127
+ //Helper function for pulling the images
128
+ require_once( dirname(__FILE__) . '/includes/acf_photo_gallery.php' );
129
+
130
+ //Resizes the image
131
+ require_once( dirname(__FILE__) . '/includes/acf_photo_gallery_resize_image.php' );
132
+
133
+ //Set the default fields for the edit gallery
134
+ require_once( dirname(__FILE__) . '/includes/acf_photo_gallery_image_fields.php' );
135
+
136
+ //Metabox for the photo edit
137
+ require_once( dirname(__FILE__) . '/includes/acf_photo_gallery_edit.php' );
readme.txt CHANGED
@@ -1,164 +1,167 @@
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.
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.2.1
6
+ Stable tag: 1.6.5
7
+ License: GPLv2 or later
8
+ License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
+
10
+ A lightweight extension of Advanced Custom Field (ACF) that adds Photo Gallery field to any post/pages on your WordPress website.
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
+ = Need Help? =
27
+ Do you need help with the installation, configuration and creating the gallery layout? You can purchase my service on Fiverr.com by following the link <https://www.fiverr.com/share/2KAjR8>
28
+
29
+ = Usage =
30
+ *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.
31
+
32
+ `acf_photo_gallery(ACF_FIELD_NAME, POST_ID);`
33
+
34
+ = Example =
35
+ The following example is using Twitter Bootstrap framework to layout. You can use any framework of your choice.
36
+
37
+ `<?php
38
+ //Get the images ids from the post_metadata
39
+ $images = acf_photo_gallery('vacation_photos', $post->ID);
40
+ //Check if return array has anything in it
41
+ if( count($images) ):
42
+ //Cool, we got some data so now let's loop over it
43
+ foreach($images as $image):
44
+ $id = $image['id']; // The attachment id of the media
45
+ $title = $image['title']; //The title
46
+ $caption= $image['caption']; //The caption
47
+ $full_image_url= $image['full_image_url']; //Full size image url
48
+ $full_image_url = acf_photo_gallery_resize_image($full_image_url, 262, 160); //Resized size to 262px width by 160px height image url
49
+ $thumbnail_image_url= $image['thumbnail_image_url']; //Get the thumbnail size image url 150px by 150px
50
+ $url= $image['url']; //Goto any link when clicked
51
+ $target= $image['target']; //Open normal or new tab
52
+ $alt = get_field('photo_gallery_alt', $id); //Get the alt which is a extra field (See below how to add extra fields)
53
+ $class = get_field('photo_gallery_class', $id); //Get the class which is a extra field (See below how to add extra fields)
54
+ ?>
55
+ <div class="col-xs-6 col-md-3">
56
+ <div class="thumbnail">
57
+ <?php if( !empty($url) ){ ?><a href="<?php echo $url; ?>" <?php echo ($target == 'true' )? 'target="_blank"': ''; ?>><?php } ?>
58
+ <img src="<?php echo $full_image_url; ?>" alt="<?php echo $title; ?>" title="<?php echo $title; ?>">
59
+ <?php if( !empty($url) ){ ?></a><?php } ?>
60
+ </div>
61
+ </div>
62
+ <?php endforeach; endif; ?>`
63
+
64
+ = Add Extra Fields =
65
+ To add extra fields add the following to your themes functions.php file.
66
+
67
+ `//Create extra fields called Altnative Text and Custom Classess
68
+ function my_extra_gallery_fields( $args, $attachment_id, $field ){
69
+ $args['alt'] = array('type' => 'text', 'label' => 'Altnative Text', 'name' => 'alt', 'value' => get_field($field . '_alt', $attachment_id) ); // Creates Altnative Text field
70
+ $args['class'] = array('type' => 'text', 'label' => 'Custom Classess', 'name' => 'class', 'value' => get_field($field . '_class', $attachment_id) ); // Creates Custom Classess field
71
+ return $args;
72
+ }
73
+ add_filter( 'acf_photo_gallery_image_fields', 'my_extra_gallery_fields', 10, 3 );`
74
+
75
+ = How to get values of extra fields =
76
+ You can use ACF helper function `get_field`
77
+
78
+ `get_field('photo_gallery_alt', $id);`
79
+ `get_field('photo_gallery_class', $id);`
80
+
81
+ = Pull caption from attachment caption field =
82
+ 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.
83
+
84
+ `add_filter( 'acf_photo_gallery_caption_from_attachment', '__return_true' );`
85
+
86
+ = REST API =
87
+ Send HTTP Request to URL to get JSON response of all posts
88
+
89
+ `http://{domain}/wp-json/wp/v2/{POST_TYPE}/`
90
+
91
+ Send HTTP Request to URL to get JSON response of specific post
92
+
93
+ `http://{domain}/wp-json/wp/v2/{POST_TYPE}/{POST_ID}/`
94
+
95
+ When you receive the response, see the ACF item which contains ACF photo gallery name and array of images.
96
+
97
+ = Compatibility =
98
+ This ACF field type is compatible with:
99
+ * ACF 4
100
+ * ACF 5
101
+
102
+ = Issues =
103
+ 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/>
104
+
105
+ == Installation ==
106
+
107
+ 1. Copy the `navz-photo-gallery` folder into your `wp-content/plugins` folder
108
+ 2. Activate the Advanced Custom Fields: Photo Gallery plugin via the plugins admin page
109
+ 3. Create a new field via ACF and select the Photo Gallery type
110
+ 4. Please refer to the description for more info regarding the field type settings
111
+
112
+ == Changelog ==
113
+ =1.6.5=
114
+ * [Bugfix] Remove not empty condition from checkbox item on edit
115
+ * [Remove] Remove support for ACF to REST API plugin
116
+ * [Add] Native support for REST API
117
+
118
+ =1.6.4=
119
+ * [Bugfix] JavaScript error in the console when removing images from the WordPress metabox
120
+
121
+ =1.6.3=
122
+ * [Added] Support for ACF 5
123
+ * [Added] Edit gallery with built-in or WordPress native model. Thanks to Github @makepost
124
+ * [Added] Under the hood improvements of the codebase
125
+ * [Added] Support for RESTFul API with ACF to REST API plugin
126
+
127
+ =1.6.2=
128
+ * [Bugfix] Keep data synced with the attachment data
129
+ * [Bugfix] Pull caption attachment caption using add filters
130
+ * [Bugfix] PHP 7.2 count() error
131
+
132
+ =1.6.1=
133
+ * [Bugfix] Edit image box disappears on click of pencil edit button reported by @rickytoof9
134
+
135
+ =1.6.0=
136
+ * [Bugfix] Error on saving post with empty gallery. Patch provided by @ugy
137
+ * [Bugfix] Showing multiple photo gallery fields in the same page reported by @rickytoof9
138
+ * [Added] Support for srcset. Special thanks to @ugy for the code
139
+
140
+ = 1.5.0 =
141
+ * [Added] Support for SVG
142
+ * [Added] Support for legacy PHP version
143
+ * [Added] Add extra fields
144
+
145
+ = 1.4.0 =
146
+ * [Added] Can sortable gallery images
147
+ * [Bugfix] Fixed the order to follow the sort order for gallery images
148
+
149
+ = 1.3.0 =
150
+ * Change the meta_key from acf field_key to acf field_name
151
+ * [Added] Helper function acf_photo_gallery() to pull images
152
+ * [Added] Helper function acf_photo_gallery_resize_image to resize the image on fly and save it
153
+ * [Bugfix] Issue with target parameter in config
154
+ * [Bugfix] Issue with url not saving properly
155
+
156
+ = 1.2.0 =
157
+ * [Bugfix] Support for WordPress 4.6
158
+ * [Added] Some changes on on the display
159
+ * [Added] Fetch the data from the database
160
+
161
+ = 1.1.0 =
162
+ * [Bugfix] Undefined index: acf-photo-gallery-field on file acf-photo_gallery-v4
163
+ * [Bugfix] When delete the photos from the gallery, the last photo was not deleting
164
+ * [Bugfix] Gallery photos was not saving in the database
165
+
166
+ = 1.0.0 =
167
  * Initial Release.