Permalink Manager Lite - Version 0.3.3

Version Description

  • Hotfix for bug with dynamic function names in PHP7.
Download this release

Release Info

Developer mbis
Plugin Icon 128x128 Permalink Manager Lite
Version 0.3.3
Comparing to
See all releases

Code changes from version 0.3.2 to 0.3.3

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.
README.txt CHANGED
@@ -1,92 +1,95 @@
1
- === Permalink Manager ===
2
- Contributors: mbis
3
- Tags: urls, permalinks, slugs
4
- Requires at least: 4.0
5
- Tested up to: 4.5.2
6
- Stable tag: 0.3.2
7
- License: GPLv2 or later
8
- License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
-
10
- Permalink Manager allows you to control and reset the permalinks (slugs) in all your post types.
11
-
12
- == Description ==
13
-
14
- It is a really simple plugin that helps managing the permalinks that are used for all your Posts, Pages and other Custom Post Types. To improve the experience of the manager, you can filter the table and display only selected `post type`s or posts/pages/custom post type items with particular `post status`es.
15
-
16
- There are three main functionalities of this plugin:
17
-
18
- 1. You can manually adjust the slugs of selected posts/pages/custom post type items.
19
- 2. You can replace particular (sub)string that is a part of slug with another (sub)string.
20
- 3. You can regenerate/reset the slugs for your posts/pages/custom post types. This might be especially useful if your post titles are updated and slugs needs to be recreated.
21
- 4. You can change the default permalink bases (permastructures) for all custom post types & posts and pages (experimental functionality).
22
-
23
- = Example =
24
-
25
- If you want to quickly replace a part of slug (eg. `krakow` with another word `gdansk`):
26
-
27
- `http://example.com/hotels-in-krakow
28
- http://example.com/restaurants-in-krakow
29
- http://example.com/transport-in-krakow
30
- http://example.com/blog/krakow-the-best-city-for-tourists
31
- http://example.com/poland/cities/krakow
32
- http://example.com/poland/cities/stalowa-wola
33
- http://example.com/poland/cities/warszawa
34
- http://example.com/poland/cities/poznan`
35
-
36
- If you use the form from `Find and replace` section your URLs will be changed to:
37
-
38
- `http://example.com/hotels-in-gdansk
39
- http://example.com/restaurants-in-gdansk
40
- http://example.com/transport-in-gdansk
41
- http://example.com/blog/gdansk-the-best-city-for-tourists
42
- http://example.com/poland/cities/gdansk
43
- http://example.com/poland/cities/stalowa-wola
44
- http://example.com/poland/cities/warszawa
45
- http://example.com/poland/cities/poznan`
46
-
47
- = Upcoming features =
48
-
49
- In the next version of plugin more functionalities will be added:
50
-
51
- * Support for taxonomies
52
- * REGEX for `Find and replace` section
53
- * Two-step updater, so you can double-check which permalinks will be changed before the change is applied
54
- * AJAX support.
55
-
56
- == Installation ==
57
-
58
- Go to `Plugins -> Add New` section from your admin account and search for `Permalink Manager`.
59
-
60
- You can also install this plugin manually:
61
-
62
- 1. Download the plugin's ZIP archive and unzip it.
63
- 2. Copy the unzipped `permalink-manager` folder to the `/wp-content/plugins/` directory.
64
- 3. Activate the plugin through the 'Plugins' menu in WordPress
65
-
66
- After the plugin is installed you can access its dashboard from this page: `Tools -> Permalink Manager`.
67
-
68
- == Screenshots ==
69
-
70
- 1. Main dashboard.
71
- 2. Find and replace section.
72
- 3. Regenerate section.
73
- 4. Custom permastructures.
74
-
75
- == Changelog ==
76
-
77
- = 0.3.2 =
78
- * Hotfix for front-end permalinks. The custom permastructures worked only in wp-admin.
79
-
80
- = 0.3.1 =
81
- * Hotfix for Posts & Pages permastructures
82
-
83
- = 0.3 =
84
- * Now all permalink parts can be edited - new "Permalink Base Editor" section added.
85
- * Code optimization.
86
- * Bugfixes for Screen Options & Edit links.
87
-
88
- = 0.2 =
89
- * First public version.
90
-
91
- = 0.1 =
92
- * A first initial version.
 
 
 
1
+ === Permalink Manager ===
2
+ Contributors: mbis
3
+ Tags: urls, permalinks, slugs
4
+ Requires at least: 4.0
5
+ Tested up to: 4.5.2
6
+ Stable tag: 0.3.3
7
+ License: GPLv2 or later
8
+ License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
+
10
+ Permalink Manager allows you to control and reset the permalinks (slugs) in all your post types.
11
+
12
+ == Description ==
13
+
14
+ It is a really simple plugin that helps managing the permalinks that are used for all your Posts, Pages and other Custom Post Types. To improve the experience of the manager, you can filter the table and display only selected `post type`s or posts/pages/custom post type items with particular `post status`es.
15
+
16
+ There are three main functionalities of this plugin:
17
+
18
+ 1. You can manually adjust the slugs of selected posts/pages/custom post type items.
19
+ 2. You can replace particular (sub)string that is a part of slug with another (sub)string.
20
+ 3. You can regenerate/reset the slugs for your posts/pages/custom post types. This might be especially useful if your post titles are updated and slugs needs to be recreated.
21
+ 4. You can change the default permalink bases (permastructures) for all custom post types & posts and pages (experimental functionality).
22
+
23
+ = Example =
24
+
25
+ If you want to quickly replace a part of slug (eg. `krakow` with another word `gdansk`):
26
+
27
+ `http://example.com/hotels-in-krakow
28
+ http://example.com/restaurants-in-krakow
29
+ http://example.com/transport-in-krakow
30
+ http://example.com/blog/krakow-the-best-city-for-tourists
31
+ http://example.com/poland/cities/krakow
32
+ http://example.com/poland/cities/stalowa-wola
33
+ http://example.com/poland/cities/warszawa
34
+ http://example.com/poland/cities/poznan`
35
+
36
+ If you use the form from `Find and replace` section your URLs will be changed to:
37
+
38
+ `http://example.com/hotels-in-gdansk
39
+ http://example.com/restaurants-in-gdansk
40
+ http://example.com/transport-in-gdansk
41
+ http://example.com/blog/gdansk-the-best-city-for-tourists
42
+ http://example.com/poland/cities/gdansk
43
+ http://example.com/poland/cities/stalowa-wola
44
+ http://example.com/poland/cities/warszawa
45
+ http://example.com/poland/cities/poznan`
46
+
47
+ = Upcoming features =
48
+
49
+ In the next version of plugin more functionalities will be added:
50
+
51
+ * Support for taxonomies
52
+ * REGEX for `Find and replace` section
53
+ * Two-step updater, so you can double-check which permalinks will be changed before the change is applied
54
+ * AJAX support.
55
+
56
+ == Installation ==
57
+
58
+ Go to `Plugins -> Add New` section from your admin account and search for `Permalink Manager`.
59
+
60
+ You can also install this plugin manually:
61
+
62
+ 1. Download the plugin's ZIP archive and unzip it.
63
+ 2. Copy the unzipped `permalink-manager` folder to the `/wp-content/plugins/` directory.
64
+ 3. Activate the plugin through the 'Plugins' menu in WordPress
65
+
66
+ After the plugin is installed you can access its dashboard from this page: `Tools -> Permalink Manager`.
67
+
68
+ == Screenshots ==
69
+
70
+ 1. Main dashboard.
71
+ 2. Find and replace section.
72
+ 3. Regenerate section.
73
+ 4. Custom permastructures.
74
+
75
+ == Changelog ==
76
+
77
+ = 0.3.3 =
78
+ * Hotfix for bug with dynamic function names in PHP7.
79
+
80
+ = 0.3.2 =
81
+ * Hotfix for front-end permalinks. The custom permastructures worked only in wp-admin.
82
+
83
+ = 0.3.1 =
84
+ * Hotfix for Posts & Pages permastructures
85
+
86
+ = 0.3 =
87
+ * Now all permalink parts can be edited - new "Permalink Base Editor" section added.
88
+ * Code optimization.
89
+ * Bugfixes for Screen Options & Edit links.
90
+
91
+ = 0.2 =
92
+ * First public version.
93
+
94
+ = 0.1 =
95
+ * A first initial version.
css/permalink-manager-admin.css CHANGED
@@ -1,25 +1,25 @@
1
- /**
2
- * Permalink Manager Table CSS
3
- */
4
- #permalinks-table-wrap { }
5
-
6
- #permalinks-table-wrap #plugin-name-heading a { color: #959595; font-size: 60%; text-decoration: none; }
7
-
8
- #permalinks-table-wrap .tablenav { margin: 6px 0 15px; }
9
- #permalinks-table-wrap .column-post_type { width: 10%; }
10
- #permalinks-table-wrap .column-post_permalink { width: 50%; }
11
- #permalinks-table-wrap .post_name input { max-width: 100%; }
12
- #permalinks-table-wrap .post_permalink a, #permalinks-table-wrap .post_permalink .dashicons { font-size: 13px; color: #aaa; line-height: 1.5em; }
13
-
14
- #permalinks-table-wrap .alert { line-height: 19px; padding: 11px 15px; margin: 15px 0; }
15
- #permalinks-table-wrap .alert p { margin-top: 0; line-height: 200%; }
16
- #permalinks-table-wrap .alert ul, #permalinks-table-wrap .alert ol { margin-top: 0; margin-bottom: 0; }
17
- #permalinks-table-wrap .alert p:last-of-type, #permalinks-table-wrap .alert li:last-of-type { margin-bottom: 0; }
18
- #permalinks-table-wrap .warning { background: #dc3232; }
19
- #permalinks-table-wrap .warning, #permalinks-table-wrap .warning a { color: #fff; }
20
- #permalinks-table-wrap .info { background: #f9f9f9; }
21
-
22
- #permalinks-table-wrap #permalink-manager-tabs > div { display: none; }
23
- #permalinks-table-wrap #permalink-manager-tabs > div.show { display: block; }
24
-
25
- #permalinks-table-wrap #permalink-manager-tabs td label { display: block; }
1
+ /**
2
+ * Permalink Manager Table CSS
3
+ */
4
+ #permalinks-table-wrap { }
5
+
6
+ #permalinks-table-wrap #plugin-name-heading a { color: #959595; font-size: 60%; text-decoration: none; }
7
+
8
+ #permalinks-table-wrap .tablenav { margin: 6px 0 15px; }
9
+ #permalinks-table-wrap .column-post_type { width: 10%; }
10
+ #permalinks-table-wrap .column-post_permalink { width: 50%; }
11
+ #permalinks-table-wrap .post_name input { max-width: 100%; }
12
+ #permalinks-table-wrap .post_permalink a, #permalinks-table-wrap .post_permalink .dashicons { font-size: 13px; color: #aaa; line-height: 1.5em; }
13
+
14
+ #permalinks-table-wrap .alert { line-height: 19px; padding: 11px 15px; margin: 15px 0; }
15
+ #permalinks-table-wrap .alert p { margin-top: 0; line-height: 200%; }
16
+ #permalinks-table-wrap .alert ul, #permalinks-table-wrap .alert ol { margin-top: 0; margin-bottom: 0; }
17
+ #permalinks-table-wrap .alert p:last-of-type, #permalinks-table-wrap .alert li:last-of-type { margin-bottom: 0; }
18
+ #permalinks-table-wrap .warning { background: #dc3232; }
19
+ #permalinks-table-wrap .warning, #permalinks-table-wrap .warning a { color: #fff; }
20
+ #permalinks-table-wrap .info { background: #f9f9f9; }
21
+
22
+ #permalinks-table-wrap #permalink-manager-tabs > div { display: none; }
23
+ #permalinks-table-wrap #permalink-manager-tabs > div.show { display: block; }
24
+
25
+ #permalinks-table-wrap #permalink-manager-tabs td label { display: block; }
inc/permalink-manager-base-editor.php CHANGED
@@ -1,158 +1,158 @@
1
- <?php
2
- if( ! class_exists( 'WP_List_Table' ) ) {
3
- require_once( ABSPATH . 'wp-admin/includes/class-wp-list-table.php' );
4
- }
5
-
6
- /**
7
- * Create a new table class that will extend the WP_List_Table
8
- */
9
- class Permalink_Manager_Base_Editor extends WP_List_Table {
10
- public $screen_options_fields;
11
-
12
- function __construct() {
13
- global $status, $page;
14
-
15
- parent::__construct(array(
16
- 'singular' => 'slug',
17
- 'plural' => 'slugs',
18
- 'ajax' => true
19
- ));
20
- }
21
-
22
- /**
23
- * Override the parent columns method. Defines the columns to use in your listing table
24
- */
25
- public function get_columns() {
26
- $columns = array(
27
- //'cb' => '<input type="checkbox" />', //Render a checkbox instead of text
28
- 'post_type' => __('Post Type', 'permalink-manager'),
29
- 'post_permalink_base' => __('Permalink Base/Permastructure', 'permalink-manager'),
30
- 'post_type_structure_tag' => __('Permalink Base Should End With', 'permalink-manager'),
31
- 'post_type_default_base' => __('Default Permalink Base/Permastructure', 'permalink-manager'),
32
- //'post_sample_permalink' => __('Sample Permalink', 'permalink-manager')
33
- );
34
-
35
- return $columns;
36
- }
37
-
38
- /**
39
- * Hidden columns
40
- */
41
- public function get_hidden_columns() {
42
- return array('post_date_gmt');
43
- }
44
-
45
- /**
46
- * Sortable columns
47
- */
48
- public function get_sortable_columns() {
49
- return array(
50
- 'post_type' => array('post_title', false),
51
- );
52
- }
53
-
54
- /**
55
- * Data inside the columns
56
- */
57
- public function column_default( $item, $column_name ) {
58
- $permastruct = Permalink_Manager_Helper_Functions::get_permastruct($item['name'], false);
59
- $default_permastruct = Permalink_Manager_Helper_Functions::get_permastruct($item['name'], false, 'default_permastruct');
60
-
61
- switch( $column_name ) {
62
- case 'post_type':
63
- return "{$item['label']}<br /><small>({$item['name']})</small>";
64
-
65
- case 'post_permalink_base':
66
- $placeholder = $default_permastruct;
67
- $field_args = array('type' => 'text', 'default' => $permastruct, 'without_label' => true, 'input_class' => 'widefat', 'placeholder' => $placeholder);
68
- return Permalink_Manager_Helper_Functions::generate_option_field($item['name'], $field_args, 'base-editor');
69
-
70
- case 'post_type_default_base':
71
- return "<code>{$default_permastruct}</code>";
72
-
73
- case 'post_type_structure_tag':
74
- return "<code>" . Permalink_Manager_Helper_Functions::get_post_tag($item['name']) . "</code>";
75
-
76
- default:
77
- return '';
78
- }
79
- }
80
-
81
- /**
82
- * Sort the data
83
- */
84
- private function sort_data( $a, $b ) {
85
- // Set defaults
86
- $order = (!empty($_GET['order'])) ? $_GET['order'] : 'asc';
87
- $result = strnatcasecmp( $a['name'], $b['name'] );
88
-
89
- return ($order === 'asc') ? $result : -$result;
90
- }
91
-
92
- /**
93
- * The button that allows to save updated slugs
94
- */
95
- function extra_tablenav( $which ) {
96
- $save_button = __( 'Save settings', 'permalink-manager' );
97
- $flush_button = __( 'Flush rewrite rules', 'permalink-manager' );
98
-
99
- echo '<div class="alignleft actions">';
100
- submit_button( $save_button, 'primary', "save_permalink_structures[{$which}]", false, array( 'id' => 'doaction', 'value' => 'save_permalink_structures' ) );
101
- submit_button( $flush_button, 'primary', "flush_rewrite_rules[{$which}]", false, array( 'id' => 'doaction', 'value' => 'flush_rewrite_rules' ) );
102
- echo '</div>';
103
- }
104
-
105
- /**
106
- * Prepare the items for the table to process
107
- */
108
- public function prepare_items($posts_table) {
109
- $columns = $this->get_columns();
110
- $hidden = $this->get_hidden_columns();
111
- $sortable = $this->get_sortable_columns();
112
- $currentPage = $this->get_pagenum();
113
-
114
- global $wpdb;
115
-
116
- // Load options and fields
117
- $saved_options = get_option('permalink-manager');
118
- $screen_options_fields = $this->screen_options_fields;
119
- $per_page = isset($saved_options['per_page']) ? $saved_options['per_page'] : $screen_options_fields['per_page']['default'];
120
-
121
- // Load all post types
122
- $data = Permalink_Manager_Helper_Functions::get_post_types_array('full');
123
-
124
- // Attachments are excluded
125
- unset($data['attachment']);
126
-
127
- // Will be used in pagination settings
128
- $total_items = count($data);
129
-
130
- // SQL query parameters
131
- $order = (isset($_REQUEST['order']) && in_array($_REQUEST['order'], array('asc', 'desc'))) ? $_REQUEST['order'] : 'desc';
132
- $orderby = (isset($_REQUEST['orderby'])) ? $_REQUEST['orderby'] : 'ID';
133
- $offset = ($currentPage - 1) * $per_page;
134
-
135
- // Sort posts and count all posts
136
- usort( $data, array( &$this, 'sort_data' ) );
137
-
138
- // Pagination
139
- $data = array_slice($data, $offset, $per_page);
140
-
141
- $this->set_pagination_args( array(
142
- 'total_items' => $total_items,
143
- 'per_page' => $per_page
144
- ));
145
-
146
- $this->_column_headers = array($columns, $hidden, $sortable);
147
- $this->items = $data;
148
- }
149
-
150
- /**
151
- * This variable is assigned in permalink-manager.php before prepare_items() function is triggered, see permalinks_table_html() function
152
- */
153
- public function set_screen_option_fields($fields) {
154
- $this->screen_options_fields = $fields;
155
- }
156
-
157
- }
158
- ?>
1
+ <?php
2
+ if( ! class_exists( 'WP_List_Table' ) ) {
3
+ require_once( ABSPATH . 'wp-admin/includes/class-wp-list-table.php' );
4
+ }
5
+
6
+ /**
7
+ * Create a new table class that will extend the WP_List_Table
8
+ */
9
+ class Permalink_Manager_Base_Editor extends WP_List_Table {
10
+ public $screen_options_fields;
11
+
12
+ function __construct() {
13
+ global $status, $page;
14
+
15
+ parent::__construct(array(
16
+ 'singular' => 'slug',
17
+ 'plural' => 'slugs',
18
+ 'ajax' => true
19
+ ));
20
+ }
21
+
22
+ /**
23
+ * Override the parent columns method. Defines the columns to use in your listing table
24
+ */
25
+ public function get_columns() {
26
+ $columns = array(
27
+ //'cb' => '<input type="checkbox" />', //Render a checkbox instead of text
28
+ 'post_type' => __('Post Type', 'permalink-manager'),
29
+ 'post_permalink_base' => __('Permalink Base/Permastructure', 'permalink-manager'),
30
+ 'post_type_structure_tag' => __('Permalink Base Should End With', 'permalink-manager'),
31
+ 'post_type_default_base' => __('Default Permalink Base/Permastructure', 'permalink-manager'),
32
+ //'post_sample_permalink' => __('Sample Permalink', 'permalink-manager')
33
+ );
34
+
35
+ return $columns;
36
+ }
37
+
38
+ /**
39
+ * Hidden columns
40
+ */
41
+ public function get_hidden_columns() {
42
+ return array('post_date_gmt');
43
+ }
44
+
45
+ /**
46
+ * Sortable columns
47
+ */
48
+ public function get_sortable_columns() {
49
+ return array(
50
+ 'post_type' => array('post_title', false),
51
+ );
52
+ }
53
+
54
+ /**
55
+ * Data inside the columns
56
+ */
57
+ public function column_default( $item, $column_name ) {
58
+ $permastruct = Permalink_Manager_Helper_Functions::get_permastruct($item['name'], false);
59
+ $default_permastruct = Permalink_Manager_Helper_Functions::get_permastruct($item['name'], false, 'default_permastruct');
60
+
61
+ switch( $column_name ) {
62
+ case 'post_type':
63
+ return "{$item['label']}<br /><small>({$item['name']})</small>";
64
+
65
+ case 'post_permalink_base':
66
+ $placeholder = $default_permastruct;
67
+ $field_args = array('type' => 'text', 'default' => $permastruct, 'without_label' => true, 'input_class' => 'widefat', 'placeholder' => $placeholder);
68
+ return Permalink_Manager_Helper_Functions::generate_option_field($item['name'], $field_args, 'base-editor');
69
+
70
+ case 'post_type_default_base':
71
+ return "<code>{$default_permastruct}</code>";
72
+
73
+ case 'post_type_structure_tag':
74
+ return "<code>" . Permalink_Manager_Helper_Functions::get_post_tag($item['name']) . "</code>";
75
+
76
+ default:
77
+ return '';
78
+ }
79
+ }
80
+
81
+ /**
82
+ * Sort the data
83
+ */
84
+ private function sort_data( $a, $b ) {
85
+ // Set defaults
86
+ $order = (!empty($_GET['order'])) ? $_GET['order'] : 'asc';
87
+ $result = strnatcasecmp( $a['name'], $b['name'] );
88
+
89
+ return ($order === 'asc') ? $result : -$result;
90
+ }
91
+
92
+ /**
93
+ * The button that allows to save updated slugs
94
+ */
95
+ function extra_tablenav( $which ) {
96
+ $save_button = __( 'Save settings', 'permalink-manager' );
97
+ $flush_button = __( 'Flush rewrite rules', 'permalink-manager' );
98
+
99
+ echo '<div class="alignleft actions">';
100
+ submit_button( $save_button, 'primary', "save_permalink_structures[{$which}]", false, array( 'id' => 'doaction', 'value' => 'save_permalink_structures' ) );
101
+ submit_button( $flush_button, 'primary', "flush_rewrite_rules[{$which}]", false, array( 'id' => 'doaction', 'value' => 'flush_rewrite_rules' ) );
102
+ echo '</div>';
103
+ }
104
+
105
+ /**
106
+ * Prepare the items for the table to process
107
+ */
108
+ public function prepare_items() {
109
+ $columns = $this->get_columns();
110
+ $hidden = $this->get_hidden_columns();
111
+ $sortable = $this->get_sortable_columns();
112
+ $currentPage = $this->get_pagenum();
113
+
114
+ global $wpdb;
115
+
116
+ // Load options and fields
117
+ $saved_options = get_option('permalink-manager');
118
+ $screen_options_fields = $this->screen_options_fields;
119
+ $per_page = isset($saved_options['per_page']) ? $saved_options['per_page'] : $screen_options_fields['per_page']['default'];
120
+
121
+ // Load all post types
122
+ $data = Permalink_Manager_Helper_Functions::get_post_types_array('full');
123
+
124
+ // Attachments are excluded
125
+ unset($data['attachment']);
126
+
127
+ // Will be used in pagination settings
128
+ $total_items = count($data);
129
+
130
+ // SQL query parameters
131
+ $order = (isset($_REQUEST['order']) && in_array($_REQUEST['order'], array('asc', 'desc'))) ? $_REQUEST['order'] : 'desc';
132
+ $orderby = (isset($_REQUEST['orderby'])) ? $_REQUEST['orderby'] : 'ID';
133
+ $offset = ($currentPage - 1) * $per_page;
134
+
135
+ // Sort posts and count all posts
136
+ usort( $data, array( &$this, 'sort_data' ) );
137
+
138
+ // Pagination
139
+ $data = array_slice($data, $offset, $per_page);
140
+
141
+ $this->set_pagination_args( array(
142
+ 'total_items' => $total_items,
143
+ 'per_page' => $per_page
144
+ ));
145
+
146
+ $this->_column_headers = array($columns, $hidden, $sortable);
147
+ $this->items = $data;
148
+ }
149
+
150
+ /**
151
+ * This variable is assigned in permalink-manager.php before prepare_items() function is triggered, see permalinks_table_html() function
152
+ */
153
+ public function set_screen_option_fields($fields) {
154
+ $this->screen_options_fields = $fields;
155
+ }
156
+
157
+ }
158
+ ?>
inc/permalink-manager-class-wp-list-table.php ADDED
@@ -0,0 +1,1371 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Base class for displaying a list of items in an ajaxified HTML table.
4
+ *
5
+ * This class is copied from /wp-admin/includes/class-wp-list-table.php to fix strict standard issues
6
+ *
7
+ * @since 3.1.0
8
+ * @access private
9
+ */
10
+ class Permalink_WP_List_Table {
11
+
12
+ /**
13
+ * The current list of items.
14
+ *
15
+ * @since 3.1.0
16
+ * @access public
17
+ * @var array
18
+ */
19
+ public $items;
20
+
21
+ /**
22
+ * Various information about the current table.
23
+ *
24
+ * @since 3.1.0
25
+ * @access protected
26
+ * @var array
27
+ */
28
+ protected $_args;
29
+
30
+ /**
31
+ * Various information needed for displaying the pagination.
32
+ *
33
+ * @since 3.1.0
34
+ * @access protected
35
+ * @var array
36
+ */
37
+ protected $_pagination_args = array();
38
+
39
+ /**
40
+ * The current screen.
41
+ *
42
+ * @since 3.1.0
43
+ * @access protected
44
+ * @var object
45
+ */
46
+ protected $screen;
47
+
48
+ /**
49
+ * Cached bulk actions.
50
+ *
51
+ * @since 3.1.0
52
+ * @access private
53
+ * @var array
54
+ */
55
+ private $_actions;
56
+
57
+ /**
58
+ * Cached pagination output.
59
+ *
60
+ * @since 3.1.0
61
+ * @access private
62
+ * @var string
63
+ */
64
+ private $_pagination;
65
+
66
+ /**
67
+ * The view switcher modes.
68
+ *
69
+ * @since 4.1.0
70
+ * @access protected
71
+ * @var array
72
+ */
73
+ protected $modes = array();
74
+
75
+ /**
76
+ * Stores the value returned by ->get_column_info().
77
+ *
78
+ * @since 4.1.0
79
+ * @access protected
80
+ * @var array
81
+ */
82
+ protected $_column_headers;
83
+
84
+ /**
85
+ * {@internal Missing Summary}
86
+ *
87
+ * @access protected
88
+ * @var array
89
+ */
90
+ protected $compat_fields = array( '_args', '_pagination_args', 'screen', '_actions', '_pagination' );
91
+
92
+ /**
93
+ * {@internal Missing Summary}
94
+ *
95
+ * @access protected
96
+ * @var array
97
+ */
98
+ protected $compat_methods = array( 'set_pagination_args', 'get_views', 'get_bulk_actions', 'bulk_actions',
99
+ 'row_actions', 'months_dropdown', 'view_switcher', 'comments_bubble', 'get_items_per_page', 'pagination',
100
+ 'get_sortable_columns', 'get_column_info', 'get_table_classes', 'display_tablenav', 'extra_tablenav',
101
+ 'single_row_columns' );
102
+
103
+ /**
104
+ * Constructor.
105
+ *
106
+ * The child class should call this constructor from its own constructor to override
107
+ * the default $args.
108
+ *
109
+ * @since 3.1.0
110
+ * @access public
111
+ *
112
+ * @param array|string $args {
113
+ * Array or string of arguments.
114
+ *
115
+ * @type string $plural Plural value used for labels and the objects being listed.
116
+ * This affects things such as CSS class-names and nonces used
117
+ * in the list table, e.g. 'posts'. Default empty.
118
+ * @type string $singular Singular label for an object being listed, e.g. 'post'.
119
+ * Default empty
120
+ * @type bool $ajax Whether the list table supports AJAX. This includes loading
121
+ * and sorting data, for example. If true, the class will call
122
+ * the _js_vars() method in the footer to provide variables
123
+ * to any scripts handling AJAX events. Default false.
124
+ * @type string $screen String containing the hook name used to determine the current
125
+ * screen. If left null, the current screen will be automatically set.
126
+ * Default null.
127
+ * }
128
+ */
129
+ public function __construct( $args = array() ) {
130
+ $args = wp_parse_args( $args, array(
131
+ 'plural' => '',
132
+ 'singular' => '',
133
+ 'ajax' => false,
134
+ 'screen' => null,
135
+ ) );
136
+
137
+ $this->screen = convert_to_screen( $args['screen'] );
138
+
139
+ add_filter( "manage_{$this->screen->id}_columns", array( $this, 'get_columns' ), 0 );
140
+
141
+ if ( !$args['plural'] )
142
+ $args['plural'] = $this->screen->base;
143
+
144
+ $args['plural'] = sanitize_key( $args['plural'] );
145
+ $args['singular'] = sanitize_key( $args['singular'] );
146
+
147
+ $this->_args = $args;
148
+
149
+ if ( $args['ajax'] ) {
150
+ // wp_enqueue_script( 'list-table' );
151
+ add_action( 'admin_footer', array( $this, '_js_vars' ) );
152
+ }
153
+
154
+ if ( empty( $this->modes ) ) {
155
+ $this->modes = array(
156
+ 'list' => __( 'List View' ),
157
+ 'excerpt' => __( 'Excerpt View' )
158
+ );
159
+ }
160
+ }
161
+
162
+ /**
163
+ * Make private properties readable for backward compatibility.
164
+ *
165
+ * @since 4.0.0
166
+ * @access public
167
+ *
168
+ * @param string $name Property to get.
169
+ * @return mixed Property.
170
+ */
171
+ public function __get( $name ) {
172
+ if ( in_array( $name, $this->compat_fields ) ) {
173
+ return $this->$name;
174
+ }
175
+ }
176
+
177
+ /**
178
+ * Make private properties settable for backward compatibility.
179
+ *
180
+ * @since 4.0.0
181
+ * @access public
182
+ *
183
+ * @param string $name Property to check if set.
184
+ * @param mixed $value Property value.
185
+ * @return mixed Newly-set property.
186
+ */
187
+ public function __set( $name, $value ) {
188
+ if ( in_array( $name, $this->compat_fields ) ) {
189
+ return $this->$name = $value;
190
+ }
191
+ }
192
+
193
+ /**
194
+ * Make private properties checkable for backward compatibility.
195
+ *
196
+ * @since 4.0.0
197
+ * @access public
198
+ *
199
+ * @param string $name Property to check if set.
200
+ * @return bool Whether the property is set.
201
+ */
202
+ public function __isset( $name ) {
203
+ if ( in_array( $name, $this->compat_fields ) ) {
204
+ return isset( $this->$name );
205
+ }
206
+ }
207
+
208
+ /**
209
+ * Make private properties un-settable for backward compatibility.
210
+ *
211
+ * @since 4.0.0
212
+ * @access public
213
+ *
214
+ * @param string $name Property to unset.
215
+ */
216
+ public function __unset( $name ) {
217
+ if ( in_array( $name, $this->compat_fields ) ) {
218
+ unset( $this->$name );
219
+ }
220
+ }
221
+
222
+ /**
223
+ * Make private/protected methods readable for backward compatibility.
224
+ *
225
+ * @since 4.0.0
226
+ * @access public
227
+ *
228
+ * @param callable $name Method to call.
229
+ * @param array $arguments Arguments to pass when calling.
230
+ * @return mixed|bool Return value of the callback, false otherwise.
231
+ */
232
+ public function __call( $name, $arguments ) {
233
+ if ( in_array( $name, $this->compat_methods ) ) {
234
+ return call_user_func_array( array( $this, $name ), $arguments );
235
+ }
236
+ return false;
237
+ }
238
+
239
+ /**
240
+ * Checks the current user's permissions
241
+ *
242
+ * @since 3.1.0
243
+ * @access public
244
+ * @abstract
245
+ */
246
+ public function ajax_user_can() {
247
+ die( 'function WP_List_Table::ajax_user_can() must be over-ridden in a sub-class.' );
248
+ }
249
+
250
+ /**
251
+ * Prepares the list of items for displaying.
252
+ * @uses WP_List_Table::set_pagination_args()
253
+ *
254
+ * @since 3.1.0
255
+ * @access public
256
+ * @abstract
257
+ */
258
+ public function prepare_items() {
259
+ die( 'function WP_List_Table::prepare_items() must be over-ridden in a sub-class.' );
260
+ }
261
+
262
+ /**
263
+ * An internal method that sets all the necessary pagination arguments
264
+ *
265
+ * @since 3.1.0
266
+ * @access protected
267
+ *
268
+ * @param array|string $args Array or string of arguments with information about the pagination.
269
+ */
270
+ protected function set_pagination_args( $args ) {
271
+ $args = wp_parse_args( $args, array(
272
+ 'total_items' => 0,
273
+ 'total_pages' => 0,
274
+ 'per_page' => 0,
275
+ ) );
276
+
277
+ if ( !$args['total_pages'] && $args['per_page'] > 0 )
278
+ $args['total_pages'] = ceil( $args['total_items'] / $args['per_page'] );
279
+
280
+ // Redirect if page number is invalid and headers are not already sent.
281
+ if ( ! headers_sent() && ( ! defined( 'DOING_AJAX' ) || ! DOING_AJAX ) && $args['total_pages'] > 0 && $this->get_pagenum() > $args['total_pages'] ) {
282
+ wp_redirect( add_query_arg( 'paged', $args['total_pages'] ) );
283
+ exit;
284
+ }
285
+
286
+ $this->_pagination_args = $args;
287
+ }
288
+
289
+ /**
290
+ * Access the pagination args.
291
+ *
292
+ * @since 3.1.0
293
+ * @access public
294
+ *
295
+ * @param string $key Pagination argument to retrieve. Common values include 'total_items',
296
+ * 'total_pages', 'per_page', or 'infinite_scroll'.
297
+ * @return int Number of items that correspond to the given pagination argument.
298
+ */
299
+ public function get_pagination_arg( $key ) {
300
+ if ( 'page' === $key ) {
301
+ return $this->get_pagenum();
302
+ }
303
+
304
+ if ( isset( $this->_pagination_args[$key] ) ) {
305
+ return $this->_pagination_args[$key];
306
+ }
307
+ }
308
+
309
+ /**
310
+ * Whether the table has items to display or not
311
+ *
312
+ * @since 3.1.0
313
+ * @access public
314
+ *
315
+ * @return bool
316
+ */
317
+ public function has_items() {
318
+ return !empty( $this->items );
319
+ }
320
+
321
+ /**
322
+ * Message to be displayed when there are no items
323
+ *
324
+ * @since 3.1.0
325
+ * @access public
326
+ */
327
+ public function no_items() {
328
+ _e( 'No items found.' );
329
+ }
330
+
331
+ /**
332
+ * Display the search box.
333
+ *
334
+ * @since 3.1.0
335
+ * @access public
336
+ *
337
+ * @param string $text The search button text
338
+ * @param string $input_id The search input id
339
+ */
340
+ public function search_box( $text, $input_id ) {
341
+ if ( empty( $_REQUEST['s'] ) && !$this->has_items() )
342
+ return;
343
+
344
+ $input_id = $input_id . '-search-input';
345
+
346
+ if ( ! empty( $_REQUEST['orderby'] ) )
347
+ echo '<input type="hidden" name="orderby" value="' . esc_attr( $_REQUEST['orderby'] ) . '" />';
348
+ if ( ! empty( $_REQUEST['order'] ) )
349
+ echo '<input type="hidden" name="order" value="' . esc_attr( $_REQUEST['order'] ) . '" />';
350
+ if ( ! empty( $_REQUEST['post_mime_type'] ) )
351
+ echo '<input type="hidden" name="post_mime_type" value="' . esc_attr( $_REQUEST['post_mime_type'] ) . '" />';
352
+ if ( ! empty( $_REQUEST['detached'] ) )
353
+ echo '<input type="hidden" name="detached" value="' . esc_attr( $_REQUEST['detached'] ) . '" />';
354
+ ?>
355
+ <p class="search-box">
356
+ <label class="screen-reader-text" for="<?php echo $input_id ?>"><?php echo $text; ?>:</label>
357
+ <input type="search" id="<?php echo $input_id ?>" name="s" value="<?php _admin_search_query(); ?>" />
358
+ <?php submit_button( $text, 'button', '', false, array('id' => 'search-submit') ); ?>
359
+ </p>
360
+ <?php
361
+ }
362
+
363
+ /**
364
+ * Get an associative array ( id => link ) with the list
365
+ * of views available on this table.
366
+ *
367
+ * @since 3.1.0
368
+ * @access protected
369
+ *
370
+ * @return array
371
+ */
372
+ protected function get_views() {
373
+ return array();
374
+ }
375
+
376
+ /**
377
+ * Display the list of views available on this table.
378
+ *
379
+ * @since 3.1.0
380
+ * @access public
381
+ */
382
+ public function views() {
383
+ $views = $this->get_views();
384
+ /**
385
+ * Filters the list of available list table views.
386
+ *
387
+ * The dynamic portion of the hook name, `$this->screen->id`, refers
388
+ * to the ID of the current screen, usually a string.
389
+ *
390
+ * @since 3.5.0
391
+ *
392
+ * @param array $views An array of available list table views.
393
+ */
394
+ $views = apply_filters( "views_{$this->screen->id}", $views );
395
+
396
+ if ( empty( $views ) )
397
+ return;
398
+
399
+ $this->screen->render_screen_reader_content( 'heading_views' );
400
+
401
+ echo "<ul class='subsubsub'>\n";
402
+ foreach ( $views as $class => $view ) {
403
+ $views[ $class ] = "\t<li class='$class'>$view";
404
+ }
405
+ echo implode( " |</li>\n", $views ) . "</li>\n";
406
+ echo "</ul>";
407
+ }
408
+
409
+ /**
410
+ * Get an associative array ( option_name => option_title ) with the list
411
+ * of bulk actions available on this table.
412
+ *
413
+ * @since 3.1.0
414
+ * @access protected
415
+ *
416
+ * @return array
417
+ */
418
+ protected function get_bulk_actions() {
419
+ return array();
420
+ }
421
+
422
+ /**
423
+ * Display the bulk actions dropdown.
424
+ *
425
+ * @since 3.1.0
426
+ * @access protected
427
+ *
428
+ * @param string $which The location of the bulk actions: 'top' or 'bottom'.
429
+ * This is designated as optional for backward compatibility.
430
+ */
431
+ protected function bulk_actions( $which = '' ) {
432
+ if ( is_null( $this->_actions ) ) {
433
+ $no_new_actions = $this->_actions = $this->get_bulk_actions();
434
+ /**
435
+ * Filters the list table Bulk Actions drop-down.
436
+ *
437
+ * The dynamic portion of the hook name, `$this->screen->id`, refers
438
+ * to the ID of the current screen, usually a string.
439
+ *
440
+ * This filter can currently only be used to remove bulk actions.
441
+ *
442
+ * @since 3.5.0
443
+ *
444
+ * @param array $actions An array of the available bulk actions.
445
+ */
446
+ $this->_actions = apply_filters( "bulk_actions-{$this->screen->id}", $this->_actions );
447
+ $this->_actions = array_intersect_assoc( $this->_actions, $no_new_actions );
448
+ $two = '';
449
+ } else {
450
+ $two = '2';
451
+ }
452
+
453
+ if ( empty( $this->_actions ) )
454
+ return;
455
+
456
+ echo '<label for="bulk-action-selector-' . esc_attr( $which ) . '" class="screen-reader-text">' . __( 'Select bulk action' ) . '</label>';
457
+ echo '<select name="action' . $two . '" id="bulk-action-selector-' . esc_attr( $which ) . "\">\n";
458
+ echo '<option value="-1">' . __( 'Bulk Actions' ) . "</option>\n";
459
+
460
+ foreach ( $this->_actions as $name => $title ) {
461
+ $class = 'edit' === $name ? ' class="hide-if-no-js"' : '';
462
+
463
+ echo "\t" . '<option value="' . $name . '"' . $class . '>' . $title . "</option>\n";
464
+ }
465
+
466
+ echo "</select>\n";
467
+
468
+ submit_button( __( 'Apply' ), 'action', '', false, array( 'id' => "doaction$two" ) );
469
+ echo "\n";
470
+ }
471
+
472
+ /**
473
+ * Get the current action selected from the bulk actions dropdown.
474
+ *
475
+ * @since 3.1.0
476
+ * @access public
477
+ *
478
+ * @return string|false The action name or False if no action was selected
479
+ */
480
+ public function current_action() {
481
+ if ( isset( $_REQUEST['filter_action'] ) && ! empty( $_REQUEST['filter_action'] ) )
482
+ return false;
483
+
484
+ if ( isset( $_REQUEST['action'] ) && -1 != $_REQUEST['action'] )
485
+ return $_REQUEST['action'];
486
+
487
+ if ( isset( $_REQUEST['action2'] ) && -1 != $_REQUEST['action2'] )
488
+ return $_REQUEST['action2'];
489
+
490
+ return false;
491
+ }
492
+
493
+ /**
494
+ * Generate row actions div
495
+ *
496
+ * @since 3.1.0
497
+ * @access protected
498
+ *
499
+ * @param array $actions The list of actions
500
+ * @param bool $always_visible Whether the actions should be always visible
501
+ * @return string
502
+ */
503
+ protected function row_actions( $actions, $always_visible = false ) {
504
+ $action_count = count( $actions );
505
+ $i = 0;
506
+
507
+ if ( !$action_count )
508
+ return '';
509
+
510
+ $out = '<div class="' . ( $always_visible ? 'row-actions visible' : 'row-actions' ) . '">';
511
+ foreach ( $actions as $action => $link ) {
512
+ ++$i;
513
+ ( $i == $action_count ) ? $sep = '' : $sep = ' | ';
514
+ $out .= "<span class='$action'>$link$sep</span>";
515
+ }
516
+ $out .= '</div>';
517
+
518
+ $out .= '<button type="button" class="toggle-row"><span class="screen-reader-text">' . __( 'Show more details' ) . '</span></button>';
519
+
520
+ return $out;
521
+ }
522
+
523
+ /**
524
+ * Display a monthly dropdown for filtering items
525
+ *
526
+ * @since 3.1.0
527
+ * @access protected
528
+ *
529
+ * @global wpdb $wpdb
530
+ * @global WP_Locale $wp_locale
531
+ *
532
+ * @param string $post_type
533
+ */
534
+ protected function months_dropdown( $post_type ) {
535
+ global $wpdb, $wp_locale;
536
+
537
+ /**
538
+ * Filters whether to remove the 'Months' drop-down from the post list table.
539
+ *
540
+ * @since 4.2.0
541
+ *
542
+ * @param bool $disable Whether to disable the drop-down. Default false.
543
+ * @param string $post_type The post type.
544
+ */
545
+ if ( apply_filters( 'disable_months_dropdown', false, $post_type ) ) {
546
+ return;
547
+ }
548
+
549
+ $extra_checks = "AND post_status != 'auto-draft'";
550
+ if ( ! isset( $_GET['post_status'] ) || 'trash' !== $_GET['post_status'] ) {
551
+ $extra_checks .= " AND post_status != 'trash'";
552
+ } elseif ( isset( $_GET['post_status'] ) ) {
553
+ $extra_checks = $wpdb->prepare( ' AND post_status = %s', $_GET['post_status'] );
554
+ }
555
+
556
+ $months = $wpdb->get_results( $wpdb->prepare( "
557
+ SELECT DISTINCT YEAR( post_date ) AS year, MONTH( post_date ) AS month
558
+ FROM $wpdb->posts
559
+ WHERE post_type = %s
560
+ $extra_checks
561
+ ORDER BY post_date DESC
562
+ ", $post_type ) );
563
+
564
+ /**
565
+ * Filters the 'Months' drop-down results.
566
+ *
567
+ * @since 3.7.0
568
+ *
569
+ * @param object $months The months drop-down query results.
570
+ * @param string $post_type The post type.
571
+ */
572
+ $months = apply_filters( 'months_dropdown_results', $months, $post_type );
573
+
574
+ $month_count = count( $months );
575
+
576
+ if ( !$month_count || ( 1 == $month_count && 0 == $months[0]->month ) )
577
+ return;
578
+
579
+ $m = isset( $_GET['m'] ) ? (int) $_GET['m'] : 0;
580
+ ?>
581
+ <label for="filter-by-date" class="screen-reader-text"><?php _e( 'Filter by date' ); ?></label>
582
+ <select name="m" id="filter-by-date">
583
+ <option<?php selected( $m, 0 ); ?> value="0"><?php _e( 'All dates' ); ?></option>
584
+ <?php
585
+ foreach ( $months as $arc_row ) {
586
+ if ( 0 == $arc_row->year )
587
+ continue;
588
+
589
+ $month = zeroise( $arc_row->month, 2 );
590
+ $year = $arc_row->year;
591
+
592
+ printf( "<option %s value='%s'>%s</option>\n",
593
+ selected( $m, $year . $month, false ),
594
+ esc_attr( $arc_row->year . $month ),
595
+ /* translators: 1: month name, 2: 4-digit year */
596
+ sprintf( __( '%1$s %2$d' ), $wp_locale->get_month( $month ), $year )
597
+ );
598
+ }
599
+ ?>
600
+ </select>
601
+ <?php
602
+ }
603
+
604
+ /**
605
+ * Display a view switcher
606
+ *
607
+ * @since 3.1.0
608
+ * @access protected
609
+ *
610
+ * @param string $current_mode
611
+ */
612
+ protected function view_switcher( $current_mode ) {
613
+ ?>
614
+ <input type="hidden" name="mode" value="<?php echo esc_attr( $current_mode ); ?>" />
615
+ <div class="view-switch">
616
+ <?php
617
+ foreach ( $this->modes as $mode => $title ) {
618
+ $classes = array( 'view-' . $mode );
619
+ if ( $current_mode === $mode )
620
+ $classes[] = 'current';
621
+ printf(
622
+ "<a href='%s' class='%s' id='view-switch-$mode'><span class='screen-reader-text'>%s</span></a>\n",
623
+ esc_url( add_query_arg( 'mode', $mode ) ),
624
+ implode( ' ', $classes ),
625
+ $title
626
+ );
627
+ }
628
+ ?>
629
+ </div>
630
+ <?php
631
+ }
632
+
633
+ /**
634
+ * Display a comment count bubble
635
+ *
636
+ * @since 3.1.0
637
+ * @access protected
638
+ *
639
+ * @param int $post_id The post ID.
640
+ * @param int $pending_comments Number of pending comments.
641
+ */
642
+ protected function comments_bubble( $post_id, $pending_comments ) {
643
+ $approved_comments = get_comments_number();
644
+
645
+ $approved_comments_number = number_format_i18n( $approved_comments );
646
+ $pending_comments_number = number_format_i18n( $pending_comments );
647
+
648
+ $approved_only_phrase = sprintf( _n( '%s comment', '%s comments', $approved_comments ), $approved_comments_number );
649
+ $approved_phrase = sprintf( _n( '%s approved comment', '%s approved comments', $approved_comments ), $approved_comments_number );
650
+ $pending_phrase = sprintf( _n( '%s pending comment', '%s pending comments', $pending_comments ), $pending_comments_number );
651
+
652
+ // No comments at all.
653
+ if ( ! $approved_comments && ! $pending_comments ) {
654
+ printf( '<span aria-hidden="true">—</span><span class="screen-reader-text">%s</span>',
655
+ __( 'No comments' )
656
+ );
657
+ // Approved comments have different display depending on some conditions.
658
+ } elseif ( $approved_comments ) {
659
+ printf( '<a href="%s" class="post-com-count post-com-count-approved"><span class="comment-count-approved" aria-hidden="true">%s</span><span class="screen-reader-text">%s</span></a>',
660
+ esc_url( add_query_arg( array( 'p' => $post_id, 'comment_status' => 'approved' ), admin_url( 'edit-comments.php' ) ) ),
661
+ $approved_comments_number,
662
+ $pending_comments ? $approved_phrase : $approved_only_phrase
663
+ );
664
+ } else {
665
+ printf( '<span class="post-com-count post-com-count-no-comments"><span class="comment-count comment-count-no-comments" aria-hidden="true">%s</span><span class="screen-reader-text">%s</span></span>',
666
+ $approved_comments_number,
667
+ $pending_comments ? __( 'No approved comments' ) : __( 'No comments' )
668
+ );
669
+ }
670
+
671
+ if ( $pending_comments ) {
672
+ printf( '<a href="%s" class="post-com-count post-com-count-pending"><span class="comment-count-pending" aria-hidden="true">%s</span><span class="screen-reader-text">%s</span></a>',
673
+ esc_url( add_query_arg( array( 'p' => $post_id, 'comment_status' => 'moderated' ), admin_url( 'edit-comments.php' ) ) ),
674
+ $pending_comments_number,
675
+ $pending_phrase
676
+ );
677
+ } else {
678
+ printf( '<span class="post-com-count post-com-count-pending post-com-count-no-pending"><span class="comment-count comment-count-no-pending" aria-hidden="true">%s</span><span class="screen-reader-text">%s</span></span>',
679
+ $pending_comments_number,
680
+ $approved_comments ? __( 'No pending comments' ) : __( 'No comments' )
681
+ );
682
+ }
683
+ }
684
+
685
+ /**
686
+ * Get the current page number
687
+ *
688
+ * @since 3.1.0
689
+ * @access public
690
+ *
691
+ * @return int
692
+ */
693
+ public function get_pagenum() {
694
+ $pagenum = isset( $_REQUEST['paged'] ) ? absint( $_REQUEST['paged'] ) : 0;
695
+
696
+ if ( isset( $this->_pagination_args['total_pages'] ) && $pagenum > $this->_pagination_args['total_pages'] )
697
+ $pagenum = $this->_pagination_args['total_pages'];
698
+
699
+ return max( 1, $pagenum );
700
+ }
701
+
702
+ /**
703
+ * Get number of items to display on a single page
704
+ *
705
+ * @since 3.1.0
706
+ * @access protected
707
+ *
708
+ * @param string $option
709
+ * @param int $default
710
+ * @return int
711
+ */
712
+ protected function get_items_per_page( $option, $default = 20 ) {
713
+ $per_page = (int) get_user_option( $option );
714
+ if ( empty( $per_page ) || $per_page < 1 )
715
+ $per_page = $default;
716
+
717
+ /**
718
+ * Filters the number of items to be displayed on each page of the list table.
719
+ *
720
+ * The dynamic hook name, $option, refers to the `per_page` option depending
721
+ * on the type of list table in use. Possible values include: 'edit_comments_per_page',
722
+ * 'sites_network_per_page', 'site_themes_network_per_page', 'themes_network_per_page',
723
+ * 'users_network_per_page', 'edit_post_per_page', 'edit_page_per_page',
724
+ * 'edit_{$post_type}_per_page', etc.
725
+ *
726
+ * @since 2.9.0
727
+ *
728
+ * @param int $per_page Number of items to be displayed. Default 20.
729
+ */
730
+ return (int) apply_filters( $option, $per_page );
731
+ }
732
+
733
+ /**
734
+ * Display the pagination.
735
+ *
736
+ * @since 3.1.0
737
+ * @access protected
738
+ *
739
+ * @param string $which
740
+ */
741
+ protected function pagination( $which ) {
742
+ if ( empty( $this->_pagination_args ) ) {
743
+ return;
744
+ }
745
+
746
+ $total_items = $this->_pagination_args['total_items'];
747
+ $total_pages = $this->_pagination_args['total_pages'];
748
+ $infinite_scroll = false;
749
+ if ( isset( $this->_pagination_args['infinite_scroll'] ) ) {
750
+ $infinite_scroll = $this->_pagination_args['infinite_scroll'];
751
+ }
752
+
753
+ if ( 'top' === $which && $total_pages > 1 ) {
754
+ $this->screen->render_screen_reader_content( 'heading_pagination' );
755
+ }
756
+
757
+ $output = '<span class="displaying-num">' . sprintf( _n( '%s item', '%s items', $total_items ), number_format_i18n( $total_items ) ) . '</span>';
758
+
759
+ $current = $this->get_pagenum();
760
+
761
+ $current_url = set_url_scheme( 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] );
762
+
763
+ $current_url = remove_query_arg( array( 'hotkeys_highlight_last', 'hotkeys_highlight_first' ), $current_url );
764
+
765
+ $page_links = array();
766
+
767
+ $total_pages_before = '<span class="paging-input">';
768
+ $total_pages_after = '</span>';
769
+
770
+ $disable_first = $disable_last = $disable_prev = $disable_next = false;
771
+
772
+ if ( $current == 1 ) {
773
+ $disable_first = true;
774
+ $disable_prev = true;
775
+ }
776
+ if ( $current == 2 ) {
777
+ $disable_first = true;
778
+ }
779
+ if ( $current == $total_pages ) {
780
+ $disable_last = true;
781
+ $disable_next = true;
782
+ }
783
+ if ( $current == $total_pages - 1 ) {
784
+ $disable_last = true;
785
+ }
786
+
787
+ if ( $disable_first ) {
788
+ $page_links[] = '<span class="tablenav-pages-navspan" aria-hidden="true">&laquo;</span>';
789
+ } else {
790
+ $page_links[] = sprintf( "<a class='first-page' href='%s'><span class='screen-reader-text'>%s</span><span aria-hidden='true'>%s</span></a>",
791
+ esc_url( remove_query_arg( 'paged', $current_url ) ),
792
+ __( 'First page' ),
793
+ '&laquo;'
794
+ );
795
+ }
796
+
797
+ if ( $disable_prev ) {
798
+ $page_links[] = '<span class="tablenav-pages-navspan" aria-hidden="true">&lsaquo;</span>';
799
+ } else {
800
+ $page_links[] = sprintf( "<a class='prev-page' href='%s'><span class='screen-reader-text'>%s</span><span aria-hidden='true'>%s</span></a>",
801
+ esc_url( add_query_arg( 'paged', max( 1, $current-1 ), $current_url ) ),
802
+ __( 'Previous page' ),
803
+ '&lsaquo;'
804
+ );
805
+ }
806
+
807
+ if ( 'bottom' === $which ) {
808
+ $html_current_page = $current;
809
+ $total_pages_before = '<span class="screen-reader-text">' . __( 'Current Page' ) . '</span><span id="table-paging" class="paging-input">';
810
+ } else {
811
+ $html_current_page = sprintf( "%s<input class='current-page' id='current-page-selector' type='text' name='paged' value='%s' size='%d' aria-describedby='table-paging' />",
812
+ '<label for="current-page-selector" class="screen-reader-text">' . __( 'Current Page' ) . '</label>',
813
+ $current,
814
+ strlen( $total_pages )
815
+ );
816
+ }
817
+ $html_total_pages = sprintf( "<span class='total-pages'>%s</span>", number_format_i18n( $total_pages ) );
818
+ $page_links[] = $total_pages_before . sprintf( _x( '%1$s of %2$s', 'paging' ), $html_current_page, $html_total_pages ) . $total_pages_after;
819
+
820
+ if ( $disable_next ) {
821
+ $page_links[] = '<span class="tablenav-pages-navspan" aria-hidden="true">&rsaquo;</span>';
822
+ } else {
823
+ $page_links[] = sprintf( "<a class='next-page' href='%s'><span class='screen-reader-text'>%s</span><span aria-hidden='true'>%s</span></a>",
824
+ esc_url( add_query_arg( 'paged', min( $total_pages, $current+1 ), $current_url ) ),
825
+ __( 'Next page' ),
826
+ '&rsaquo;'
827
+ );
828
+ }
829
+
830
+ if ( $disable_last ) {
831
+ $page_links[] = '<span class="tablenav-pages-navspan" aria-hidden="true">&raquo;</span>';
832
+ } else {
833
+ $page_links[] = sprintf( "<a class='last-page' href='%s'><span class='screen-reader-text'>%s</span><span aria-hidden='true'>%s</span></a>",
834
+ esc_url( add_query_arg( 'paged', $total_pages, $current_url ) ),
835
+ __( 'Last page' ),
836
+ '&raquo;'
837
+ );
838
+ }
839
+
840
+ $pagination_links_class = 'pagination-links';
841
+ if ( ! empty( $infinite_scroll ) ) {
842
+ $pagination_links_class = ' hide-if-js';
843
+ }
844
+ $output .= "\n<span class='$pagination_links_class'>" . join( "\n", $page_links ) . '</span>';
845
+
846
+ if ( $total_pages ) {
847
+ $page_class = $total_pages < 2 ? ' one-page' : '';
848
+ } else {
849
+ $page_class = ' no-pages';
850
+ }
851
+ $this->_pagination = "<div class='tablenav-pages{$page_class}'>$output</div>";
852
+
853
+ echo $this->_pagination;
854
+ }
855
+
856
+ /**
857
+ * Get a list of columns. The format is:
858
+ * 'internal-name' => 'Title'
859
+ *
860
+ * @since 3.1.0
861
+ * @access public
862
+ * @abstract
863
+ *
864
+ * @return array
865
+ */
866
+ public function get_columns() {
867
+ die( 'function WP_List_Table::get_columns() must be over-ridden in a sub-class.' );
868
+ }
869
+
870
+ /**
871
+ * Get a list of sortable columns. The format is:
872
+ * 'internal-name' => 'orderby'
873
+ * or
874
+ * 'internal-name' => array( 'orderby', true )
875
+ *
876
+ * The second format will make the initial sorting order be descending
877
+ *
878
+ * @since 3.1.0
879
+ * @access protected
880
+ *
881
+ * @return array
882
+ */
883
+ protected function get_sortable_columns() {
884
+ return array();
885
+ }
886
+
887
+ /**
888
+ * Gets the name of the default primary column.
889
+ *
890
+ * @since 4.3.0
891
+ * @access protected
892
+ *
893
+ * @return string Name of the default primary column, in this case, an empty string.
894
+ */
895
+ protected function get_default_primary_column_name() {
896
+ $columns = $this->get_columns();
897
+ $column = '';
898
+
899
+ if ( empty( $columns ) ) {
900
+ return $column;
901
+ }
902
+
903
+ // We need a primary defined so responsive views show something,
904
+ // so let's fall back to the first non-checkbox column.
905
+ foreach ( $columns as $col => $column_name ) {
906
+ if ( 'cb' === $col ) {
907
+ continue;
908
+ }
909
+
910
+ $column = $col;
911
+ break;
912
+ }
913
+
914
+ return $column;
915
+ }
916
+
917
+ /**
918
+ * Public wrapper for WP_List_Table::get_default_primary_column_name().
919
+ *
920
+ * @since 4.4.0
921
+ * @access public
922
+ *
923
+ * @return string Name of the default primary column.
924
+ */
925
+ public function get_primary_column() {
926
+ return $this->get_primary_column_name();
927
+ }
928
+
929
+ /**
930
+ * Gets the name of the primary column.
931
+ *
932
+ * @since 4.3.0
933
+ * @access protected
934
+ *
935
+ * @return string The name of the primary column.
936
+ */
937
+ protected function get_primary_column_name() {
938
+ $columns = get_column_headers( $this->screen );
939
+ $default = $this->get_default_primary_column_name();
940
+
941
+ // If the primary column doesn't exist fall back to the
942
+ // first non-checkbox column.
943
+ if ( ! isset( $columns[ $default ] ) ) {
944
+ $default = WP_List_Table::get_default_primary_column_name();
945
+ }
946
+
947
+ /**
948
+ * Filters the name of the primary column for the current list table.
949
+ *
950
+ * @since 4.3.0
951
+ *
952
+ * @param string $default Column name default for the specific list table, e.g. 'name'.
953
+ * @param string $context Screen ID for specific list table, e.g. 'plugins'.
954
+ */
955
+ $column = apply_filters( 'list_table_primary_column', $default, $this->screen->id );
956
+
957
+ if ( empty( $column ) || ! isset( $columns[ $column ] ) ) {
958
+ $column = $default;
959
+ }
960
+
961
+ return $column;
962
+ }
963
+
964
+ /**
965
+ * Get a list of all, hidden and sortable columns, with filter applied
966
+ *
967
+ * @since 3.1.0
968
+ * @access protected
969
+ *
970
+ * @return array
971
+ */
972
+ protected function get_column_info() {
973
+ // $_column_headers is already set / cached
974
+ if ( isset( $this->_column_headers ) && is_array( $this->_column_headers ) ) {
975
+ // Back-compat for list tables that have been manually setting $_column_headers for horse reasons.
976
+ // In 4.3, we added a fourth argument for primary column.
977
+ $column_headers = array( array(), array(), array(), $this->get_primary_column_name() );
978
+ foreach ( $this->_column_headers as $key => $value ) {
979
+ $column_headers[ $key ] = $value;
980
+ }
981
+
982
+ return $column_headers;
983
+ }
984
+
985
+ $columns = get_column_headers( $this->screen );
986
+ $hidden = get_hidden_columns( $this->screen );
987
+
988
+ $sortable_columns = $this->get_sortable_columns();
989
+ /**
990
+ * Filters the list table sortable columns for a specific screen.
991
+ *
992
+ * The dynamic portion of the hook name, `$this->screen->id`, refers
993
+ * to the ID of the current screen, usually a string.
994
+ *
995
+ * @since 3.5.0
996
+ *
997
+ * @param array $sortable_columns An array of sortable columns.
998
+ */
999
+ $_sortable = apply_filters( "manage_{$this->screen->id}_sortable_columns", $sortable_columns );
1000
+
1001
+ $sortable = array();
1002
+ foreach ( $_sortable as $id => $data ) {
1003
+ if ( empty( $data ) )
1004
+ continue;
1005
+
1006
+ $data = (array) $data;
1007
+ if ( !isset( $data[1] ) )
1008
+ $data[1] = false;
1009
+
1010
+ $sortable[$id] = $data;
1011
+ }
1012
+
1013
+ $primary = $this->get_primary_column_name();
1014
+ $this->_column_headers = array( $columns, $hidden, $sortable, $primary );
1015
+
1016
+ return $this->_column_headers;
1017
+ }
1018
+
1019
+ /**
1020
+ * Return number of visible columns
1021
+ *
1022
+ * @since 3.1.0
1023
+ * @access public
1024
+ *
1025
+ * @return int
1026
+ */
1027
+ public function get_column_count() {
1028
+ list ( $columns, $hidden ) = $this->get_column_info();
1029
+ $hidden = array_intersect( array_keys( $columns ), array_filter( $hidden ) );
1030
+ return count( $columns ) - count( $hidden );
1031
+ }
1032
+
1033
+ /**
1034
+ * Print column headers, accounting for hidden and sortable columns.
1035
+ *
1036
+ * @since 3.1.0
1037
+ * @access public
1038
+ *
1039
+ * @staticvar int $cb_counter
1040
+ *
1041
+ * @param bool $with_id Whether to set the id attribute or not
1042
+ */
1043
+ public function print_column_headers( $with_id = true ) {
1044
+ list( $columns, $hidden, $sortable, $primary ) = $this->get_column_info();
1045
+
1046
+ $current_url = set_url_scheme( 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] );
1047
+ $current_url = remove_query_arg( 'paged', $current_url );
1048
+
1049
+ if ( isset( $_GET['orderby'] ) ) {
1050
+ $current_orderby = $_GET['orderby'];
1051
+ } else {
1052
+ $current_orderby = '';
1053
+ }
1054
+
1055
+ if ( isset( $_GET['order'] ) && 'desc' === $_GET['order'] ) {
1056
+ $current_order = 'desc';
1057
+ } else {
1058
+ $current_order = 'asc';
1059
+ }
1060
+
1061
+ if ( ! empty( $columns['cb'] ) ) {
1062
+ static $cb_counter = 1;
1063
+ $columns['cb'] = '<label class="screen-reader-text" for="cb-select-all-' . $cb_counter . '">' . __( 'Select All' ) . '</label>'
1064
+ . '<input id="cb-select-all-' . $cb_counter . '" type="checkbox" />';
1065
+ $cb_counter++;
1066
+ }
1067
+
1068
+ foreach ( $columns as $column_key => $column_display_name ) {
1069
+ $class = array( 'manage-column', "column-$column_key" );
1070
+
1071
+ if ( in_array( $column_key, $hidden ) ) {
1072
+ $class[] = 'hidden';
1073
+ }
1074
+
1075
+ if ( 'cb' === $column_key )
1076
+ $class[] = 'check-column';
1077
+ elseif ( in_array( $column_key, array( 'posts', 'comments', 'links' ) ) )
1078
+ $class[] = 'num';
1079
+
1080
+ if ( $column_key === $primary ) {
1081
+ $class[] = 'column-primary';
1082
+ }
1083
+
1084
+ if ( isset( $sortable[$column_key] ) ) {
1085
+ list( $orderby, $desc_first ) = $sortable[$column_key];
1086
+
1087
+ if ( $current_orderby === $orderby ) {
1088
+ $order = 'asc' === $current_order ? 'desc' : 'asc';
1089
+ $class[] = 'sorted';
1090
+ $class[] = $current_order;
1091
+ } else {
1092
+ $order = $desc_first ? 'desc' : 'asc';
1093
+ $class[] = 'sortable';
1094
+ $class[] = $desc_first ? 'asc' : 'desc';
1095
+ }
1096
+
1097
+ $column_display_name = '<a href="' . esc_url( add_query_arg( compact( 'orderby', 'order' ), $current_url ) ) . '"><span>' . $column_display_name . '</span><span class="sorting-indicator"></span></a>';
1098
+ }
1099
+
1100
+ $tag = ( 'cb' === $column_key ) ? 'td' : 'th';
1101
+ $scope = ( 'th' === $tag ) ? 'scope="col"' : '';
1102
+ $id = $with_id ? "id='$column_key'" : '';
1103
+
1104
+ if ( !empty( $class ) )
1105
+ $class = "class='" . join( ' ', $class ) . "'";
1106
+
1107
+ echo "<$tag $scope $id $class>$column_display_name</$tag>";
1108
+ }
1109
+ }
1110
+
1111
+ /**
1112
+ * Display the table
1113
+ *
1114
+ * @since 3.1.0
1115
+ * @access public
1116
+ */
1117
+ public function display() {
1118
+ $singular = $this->_args['singular'];
1119
+
1120
+ $this->display_tablenav( 'top' );
1121
+
1122
+ $this->screen->render_screen_reader_content( 'heading_list' );
1123
+ ?>
1124
+ <table class="wp-list-table <?php echo implode( ' ', $this->get_table_classes() ); ?>">
1125
+ <thead>
1126
+ <tr>
1127
+ <?php $this->print_column_headers(); ?>
1128
+ </tr>
1129
+ </thead>
1130
+
1131
+ <tbody id="the-list"<?php
1132
+ if ( $singular ) {
1133
+ echo " data-wp-lists='list:$singular'";
1134
+ } ?>>
1135
+ <?php $this->display_rows_or_placeholder(); ?>
1136
+ </tbody>
1137
+
1138
+ <tfoot>
1139
+ <tr>
1140
+ <?php $this->print_column_headers( false ); ?>
1141
+ </tr>
1142
+ </tfoot>
1143
+
1144
+ </table>
1145
+ <?php
1146
+ $this->display_tablenav( 'bottom' );
1147
+ }
1148
+
1149
+ /**
1150
+ * Get a list of CSS classes for the WP_List_Table table tag.
1151
+ *
1152
+ * @since 3.1.0
1153
+ * @access protected
1154
+ *
1155
+ * @return array List of CSS classes for the table tag.
1156
+ */
1157
+ protected function get_table_classes() {
1158
+ return array( 'widefat', 'fixed', 'striped', $this->_args['plural'] );
1159
+ }
1160
+
1161
+ /**
1162
+ * Generate the table navigation above or below the table
1163
+ *
1164
+ * @since 3.1.0
1165
+ * @access protected
1166
+ * @param string $which
1167
+ */
1168
+ protected function display_tablenav( $which ) {
1169
+ if ( 'top' === $which ) {
1170
+ wp_nonce_field( 'bulk-' . $this->_args['plural'] );
1171
+ }
1172
+ ?>
1173
+ <div class="tablenav <?php echo esc_attr( $which ); ?>">
1174
+
1175
+ <?php if ( $this->has_items() ): ?>
1176
+ <div class="alignleft actions bulkactions">
1177
+ <?php $this->bulk_actions( $which ); ?>
1178
+ </div>
1179
+ <?php endif;
1180
+ $this->extra_tablenav( $which );
1181
+ $this->pagination( $which );
1182
+ ?>
1183
+
1184
+ <br class="clear" />
1185
+ </div>
1186
+ <?php
1187
+ }
1188
+
1189
+ /**
1190
+ * Extra controls to be displayed between bulk actions and pagination
1191
+ *
1192
+ * @since 3.1.0
1193
+ * @access protected
1194
+ *
1195
+ * @param string $which
1196
+ */
1197
+ protected function extra_tablenav( $which ) {}
1198
+
1199
+ /**
1200
+ * Generate the tbody element for the list table.
1201
+ *
1202
+ * @since 3.1.0
1203
+ * @access public
1204
+ */
1205
+ public function display_rows_or_placeholder() {
1206
+ if ( $this->has_items() ) {
1207
+ $this->display_rows();
1208
+ } else {
1209
+ echo '<tr class="no-items"><td class="colspanchange" colspan="' . $this->get_column_count() . '">';
1210
+ $this->no_items();
1211
+ echo '</td></tr>';
1212
+ }
1213
+ }
1214
+
1215
+ /**
1216
+ * Generate the table rows
1217
+ *
1218
+ * @since 3.1.0
1219
+ * @access public
1220
+ */
1221
+ public function display_rows() {
1222
+ foreach ( $this->items as $item )
1223
+ $this->single_row( $item );
1224
+ }
1225
+
1226
+ /**
1227
+ * Generates content for a single row of the table
1228
+ *
1229
+ * @since 3.1.0
1230
+ * @access public
1231
+ *
1232
+ * @param object $item The current item
1233
+ */
1234
+ public function single_row( $item ) {
1235
+ echo '<tr>';
1236
+ $this->single_row_columns( $item );
1237
+ echo '</tr>';
1238
+ }
1239
+
1240
+ /**
1241
+ *
1242
+ * @param object $item
1243
+ * @param string $column_name
1244
+ */
1245
+ protected function column_default( $item, $column_name ) {}
1246
+
1247
+ /**
1248
+ *
1249
+ * @param object $item
1250
+ */
1251
+ protected function column_cb( $item ) {}
1252
+
1253
+ /**
1254
+ * Generates the columns for a single row of the table
1255
+ *
1256
+ * @since 3.1.0
1257
+ * @access protected
1258
+ *
1259
+ * @param object $item The current item
1260
+ */
1261
+ protected function single_row_columns( $item ) {
1262
+ list( $columns, $hidden, $sortable, $primary ) = $this->get_column_info();
1263
+
1264
+ foreach ( $columns as $column_name => $column_display_name ) {
1265
+ $classes = "$column_name column-$column_name";
1266
+ if ( $primary === $column_name ) {
1267
+ $classes .= ' has-row-actions column-primary';
1268
+ }
1269
+
1270
+ if ( in_array( $column_name, $hidden ) ) {
1271
+ $classes .= ' hidden';
1272
+ }
1273
+
1274
+ // Comments column uses HTML in the display name with screen reader text.
1275
+ // Instead of using esc_attr(), we strip tags to get closer to a user-friendly string.
1276
+ $data = 'data-colname="' . wp_strip_all_tags( $column_display_name ) . '"';
1277
+
1278
+ $attributes = "class='$classes' $data";
1279
+
1280
+ if ( 'cb' === $column_name ) {
1281
+ echo '<th scope="row" class="check-column">';
1282
+ echo $this->column_cb( $item );
1283
+ echo '</th>';
1284
+ } elseif ( method_exists( $this, '_column_' . $column_name ) ) {
1285
+ echo call_user_func(
1286
+ array( $this, '_column_' . $column_name ),
1287
+ $item,
1288
+ $classes,
1289
+ $data,
1290
+ $primary
1291
+ );
1292
+ } elseif ( method_exists( $this, 'column_' . $column_name ) ) {
1293
+ echo "<td $attributes>";
1294
+ echo call_user_func( array( $this, 'column_' . $column_name ), $item );
1295
+ echo $this->handle_row_actions( $item, $column_name, $primary );
1296
+ echo "</td>";
1297
+ } else {
1298
+ echo "<td $attributes>";
1299
+ echo $this->column_default( $item, $column_name );
1300
+ echo $this->handle_row_actions( $item, $column_name, $primary );
1301
+ echo "</td>";
1302
+ }
1303
+ }
1304
+ }
1305
+
1306
+ /**
1307
+ * Generates and display row actions links for the list table.
1308
+ *
1309
+ * @since 4.3.0
1310
+ * @access protected
1311
+ *
1312
+ * @param object $item The item being acted upon.
1313
+ * @param string $column_name Current column name.
1314
+ * @param string $primary Primary column name.
1315
+ * @return string The row actions HTML, or an empty string if the current column is the primary column.
1316
+ */
1317
+ protected function handle_row_actions( $item, $column_name, $primary ) {
1318
+ return $column_name === $primary ? '<button type="button" class="toggle-row"><span class="screen-reader-text">' . __( 'Show more details' ) . '</span></button>' : '';
1319
+ }
1320
+
1321
+ /**
1322
+ * Handle an incoming ajax request (called from admin-ajax.php)
1323
+ *
1324
+ * @since 3.1.0
1325
+ * @access public
1326
+ */
1327
+ public function ajax_response() {
1328
+ $this->prepare_items();
1329
+
1330
+ ob_start();
1331
+ if ( ! empty( $_REQUEST['no_placeholder'] ) ) {
1332
+ $this->display_rows();
1333
+ } else {
1334
+ $this->display_rows_or_placeholder();
1335
+ }
1336
+
1337
+ $rows = ob_get_clean();
1338
+
1339
+ $response = array( 'rows' => $rows );
1340
+
1341
+ if ( isset( $this->_pagination_args['total_items'] ) ) {
1342
+ $response['total_items_i18n'] = sprintf(
1343
+ _n( '%s item', '%s items', $this->_pagination_args['total_items'] ),
1344
+ number_format_i18n( $this->_pagination_args['total_items'] )
1345
+ );
1346
+ }
1347
+ if ( isset( $this->_pagination_args['total_pages'] ) ) {
1348
+ $response['total_pages'] = $this->_pagination_args['total_pages'];
1349
+ $response['total_pages_i18n'] = number_format_i18n( $this->_pagination_args['total_pages'] );
1350
+ }
1351
+
1352
+ die( wp_json_encode( $response ) );
1353
+ }
1354
+
1355
+ /**
1356
+ * Send required variables to JavaScript land
1357
+ *
1358
+ * @access public
1359
+ */
1360
+ public function _js_vars() {
1361
+ $args = array(
1362
+ 'class' => get_class( $this ),
1363
+ 'screen' => array(
1364
+ 'id' => $this->screen->id,
1365
+ 'base' => $this->screen->base,
1366
+ )
1367
+ );
1368
+
1369
+ printf( "<script type='text/javascript'>list_args = %s;</script>\n", wp_json_encode( $args ) );
1370
+ }
1371
+ }
inc/permalink-manager-helper-functions.php CHANGED
@@ -1,237 +1,238 @@
1
- <?php
2
-
3
- /**
4
- * Additional functions used in classes and another subclasses
5
- */
6
-
7
- class Permalink_Manager_Helper_Functions extends Permalink_Manager_Class {
8
-
9
- public function __construct() {}
10
-
11
- /**
12
- * Display error/info message
13
- */
14
- static function display_alert($alert_content, $alert_type, $before_tabs = false) {
15
- $output = sprintf( "<div class='{$alert_type} is-dismissible notice'><p> %s </p></div>", $alert_content );
16
-
17
- if($before_tabs) {
18
- add_filter('permalink-manager-before-tabs', function( $arg ) use ( $output ) {
19
- return $output;
20
- });
21
- } else {
22
- return $output;
23
- }
24
- }
25
-
26
- /**
27
- * Display the permalink in a better way
28
- */
29
- static function get_correct_permalink($id, $correct_slug, $highlight = false) {
30
- $output = get_permalink($id);
31
-
32
- // Get last part of URI
33
- $old_slug = end((explode('/', get_page_uri($id))));
34
- $correct_slug = ($highlight) ? "<code>{$correct_slug}</code>" : $correct_slug;
35
- $output = Permalink_Manager_Helper_Functions::str_lreplace($old_slug, $correct_slug, $output);
36
-
37
- return $output;
38
- }
39
-
40
- /**
41
- * Get post_types array
42
- */
43
- static function get_post_types_array($format = null, $cpt = null) {
44
- $post_types = get_post_types( array('public' => true), 'objects' );
45
-
46
- $post_types_array = array();
47
- if($format == 'full') {
48
- foreach ( $post_types as $post_type ) {
49
- $post_types_array[$post_type->name] = array('label' => $post_type->labels->name, 'name' => $post_type->name);
50
- }
51
- } else {
52
- foreach ( $post_types as $post_type ) {
53
- $post_types_array[$post_type->name] = $post_type->labels->name;
54
- }
55
- }
56
-
57
- return (empty($cpt)) ? $post_types_array : $post_types_array[$cpt];
58
- }
59
-
60
- /**
61
- * Replace last occurence
62
- */
63
- static function str_lreplace($search, $replace, $subject) {
64
- $pos = strrpos($subject, $search);
65
- return ($pos !== false) ? substr_replace($subject, $replace, $pos, strlen($search)) : $subject;
66
- }
67
-
68
- /**
69
- * Generate the fields
70
- */
71
- static public function generate_option_field($name, $args, $group = null) {
72
- // Load values from options if needed
73
- $saved_values = get_option('permalink-manager');
74
-
75
- // Reset $fields variable
76
- $fields = '';
77
-
78
- // Load default value
79
- $default_value = (isset($args['default'])) ? $args['default'] : '';
80
- $label = (isset($args['label'])) ? $args['label'] : '';
81
- $placeholder = (isset($args['placeholder'])) ? "placeholder=\"{$args['placeholder']}\"" : '';
82
- $input_class = (isset($args['input_class'])) ? "class=\"{$args['input_class']}\"" : '';
83
- $input_name = ($group) ? "permalink-manager[{$group}][{$name}]" : $name;
84
-
85
- switch($args['type']) {
86
- case 'checkbox' :
87
- $fields .= '<div class="checkboxes">';
88
- foreach($args['choices'] as $value => $label) {
89
- $all_checked = (isset($saved_values[$group][$name])) ? $saved_values[$group][$name] : $args['default'];
90
- $checked = in_array($value, $all_checked) ? "checked='checked'" : "";
91
- $fields .= "<label for='{$input_name}[]'><input type='checkbox' {$input_class} value='{$value}' name='{$input_name}[]' {$checked} /> {$label}</label>";
92
- }
93
- $fields .= '</div>';
94
- break;
95
-
96
- case 'number' :
97
- $value = (isset($saved_values[$group][$name])) ? $saved_values[$group][$name] : $default_value;
98
- $fields .= "<input type='number' {$input_class} value='{$value}' name='{$input_name}' />";
99
- break;
100
-
101
- default :
102
- $value = (isset($saved_values[$group][$name])) ? $saved_values[$group][$name] : $default_value;
103
- $fields .= "<input type='text' {$input_class} value='{$value}' name='{$input_name}' {$placeholder}/>";
104
- }
105
-
106
- // Get all variables into one final variable
107
- if(isset($group) && !($group === 'screen-options')) {
108
- $output = "<legend>{$label}</legend>";
109
- $output .= "<div class='metabox-prefs'><div class='{$name}-container'>{$fields}</div></div>";
110
- } else if (isset($args['without_label']) && $args['without_label'] == true) {
111
- $output = $fields;
112
- } else {
113
- $output = "<tr><th><label for='{$input_name}'>{$args['label']}</label></th>";
114
- $output .= "<td>{$fields}</td>";
115
- }
116
-
117
- return $output;
118
- }
119
-
120
- /**
121
- * Check if the provided slug is unique and then update it with SQL query.
122
- */
123
- static function update_slug_by_id($slug, $id) {
124
- global $wpdb;
125
-
126
- // Update slug and make it unique
127
- $slug = (empty($slug)) ? sanitize_title(get_the_title($id)) : $slug;
128
- $new_slug = wp_unique_post_slug($slug, $id, get_post_status($id), get_post_type($id), null);
129
- $wpdb->query("UPDATE $wpdb->posts SET post_name = '$new_slug' WHERE ID = '$id'");
130
-
131
- return $new_slug;
132
- }
133
-
134
- /**
135
- * Save option
136
- */
137
- static function save_option($field = null, $value = null) {
138
- $options = get_option('permalink-manager', array());
139
- if($field) {
140
- $options[$field] = $value;
141
-
142
- // The snippet belows prevent duplicates in permastructures
143
- if($field == 'base-editor') {
144
-
145
- //print_r($value);
146
-
147
- // Algorithm below works like array_count_values(), but we also need to make the permastructs unique
148
- $unique_permastructures = array();
149
- foreach($value as $key => $permastruct) {
150
- // Trim whitespaces & slashes at first
151
- $permastruct = trim(trim($permastruct, "/"));
152
-
153
- // The permastruct is not unique!
154
- if(empty($permastruct)) {
155
- $permastruct = Permalink_Manager_Helper_Functions::get_permastruct($key, false, 'default_permastruct');
156
- } else if(isset($unique_permastructures[$permastruct])) {
157
- $unique_permastructures[$permastruct]++;
158
- // Alter the permastruct
159
- $permastruct = "{$key}/{$permastruct}";
160
- } else {
161
- $unique_permastructures[$permastruct] = 1;
162
- }
163
-
164
- // Trim one more time
165
- $permastruct = trim(trim($permastruct, "/"));
166
-
167
- // Alter the permastruct
168
- $options[$field][$key] = $permastruct;
169
- }
170
-
171
- }
172
-
173
- update_option('permalink-manager', $options);
174
- }
175
- }
176
-
177
- /**
178
- * Get permastruct
179
- */
180
- static function get_permastruct($post_type = 'page', $title_replace = false, $return = 'permastruct') {
181
- global $wp_rewrite;
182
-
183
- // Load permastruct from options
184
- $options = get_option('permalink-manager', array());
185
- $permastructs = $options['base-editor'];
186
-
187
- // Get default permastruct
188
- if($post_type == 'page') {
189
- $default_permastruct = $wp_rewrite->get_page_permastruct();
190
- } else if($post_type == 'post') {
191
- $default_permastruct = get_option('permalink_structure');
192
- } else {
193
- $default_permastruct = $wp_rewrite->get_extra_permastruct($post_type);
194
- }
195
-
196
- // If the permastruct is not saved for post type or empty return default permastruct
197
- $permastruct = (isset($permastructs[$post_type]) && $permastructs[$post_type]) ? $permastructs[$post_type] : $default_permastruct;
198
-
199
- // Remove post name to enable support for hierarchical post types
200
- $permastruct = ($title_replace) ? str_replace(array("%pagename%", "%postname%", "%{$post_type}%"), '', $permastruct) : "";
201
-
202
- return trim($$return, '/');
203
- }
204
-
205
- /**
206
- * Structure Tags & Rewrite functions
207
- */
208
- static function get_all_structure_tags($code = true, $seperator = ', ') {
209
- global $wp_rewrite;
210
-
211
- $tags = $wp_rewrite->rewritecode;
212
- $output = "";
213
- $last_tag_index = count($tags);
214
- $i = 1;
215
-
216
- foreach($tags as $tag) {
217
- $sep = ($last_tag_index == $i) ? "" : $seperator;
218
- $output .= ($code) ? "<code>{$tag}</code>{$sep}" : "{$tag}{$sep}";
219
- $i++;
220
- }
221
-
222
- return $output;
223
- }
224
-
225
- static function get_post_tag($post_type) {
226
- // Get the post type (with fix for posts & pages)
227
- if($post_type == 'page') {
228
- $post_type_tag = '%pagename%';
229
- } else if ($post_type == 'post') {
230
- $post_type_tag = '%postname%';
231
- } else {
232
- $post_type_tag = "%{$post_type}%";
233
- }
234
- return $post_type_tag;
235
- }
236
-
237
- }
 
1
+ <?php
2
+
3
+ /**
4
+ * Additional functions used in classes and another subclasses
5
+ */
6
+
7
+ class Permalink_Manager_Helper_Functions extends Permalink_Manager_Class {
8
+
9
+ public function __construct() {}
10
+
11
+ /**
12
+ * Display error/info message
13
+ */
14
+ static function display_alert($alert_content, $alert_type, $before_tabs = false) {
15
+ $output = sprintf( "<div class='{$alert_type} is-dismissible notice'><p> %s </p></div>", $alert_content );
16
+
17
+ if($before_tabs) {
18
+ add_filter('permalink-manager-before-tabs', function( $arg ) use ( $output ) {
19
+ return $output;
20
+ });
21
+ } else {
22
+ return $output;
23
+ }
24
+ }
25
+
26
+ /**
27
+ * Display the permalink in a better way
28
+ */
29
+ static function get_correct_permalink($id, $correct_slug, $highlight = false) {
30
+ $output = get_permalink($id);
31
+
32
+ // Get last part of URI
33
+ $page_uri = explode('/', get_page_uri($id));
34
+ $old_slug = end($page_uri);
35
+ $correct_slug = ($highlight) ? "<code>{$correct_slug}</code>" : $correct_slug;
36
+ $output = Permalink_Manager_Helper_Functions::str_lreplace($old_slug, $correct_slug, $output);
37
+
38
+ return $output;
39
+ }
40
+
41
+ /**
42
+ * Get post_types array
43
+ */
44
+ static function get_post_types_array($format = null, $cpt = null) {
45
+ $post_types = get_post_types( array('public' => true), 'objects' );
46
+
47
+ $post_types_array = array();
48
+ if($format == 'full') {
49
+ foreach ( $post_types as $post_type ) {
50
+ $post_types_array[$post_type->name] = array('label' => $post_type->labels->name, 'name' => $post_type->name);
51
+ }
52
+ } else {
53
+ foreach ( $post_types as $post_type ) {
54
+ $post_types_array[$post_type->name] = $post_type->labels->name;
55
+ }
56
+ }
57
+
58
+ return (empty($cpt)) ? $post_types_array : $post_types_array[$cpt];
59
+ }
60
+
61
+ /**
62
+ * Replace last occurence
63
+ */
64
+ static function str_lreplace($search, $replace, $subject) {
65
+ $pos = strrpos($subject, $search);
66
+ return ($pos !== false) ? substr_replace($subject, $replace, $pos, strlen($search)) : $subject;
67
+ }
68
+
69
+ /**
70
+ * Generate the fields
71
+ */
72
+ static public function generate_option_field($name, $args, $group = null) {
73
+ // Load values from options if needed
74
+ $saved_values = get_option('permalink-manager');
75
+
76
+ // Reset $fields variable
77
+ $fields = '';
78
+
79
+ // Load default value
80
+ $default_value = (isset($args['default'])) ? $args['default'] : '';
81
+ $label = (isset($args['label'])) ? $args['label'] : '';
82
+ $placeholder = (isset($args['placeholder'])) ? "placeholder=\"{$args['placeholder']}\"" : '';
83
+ $input_class = (isset($args['input_class'])) ? "class=\"{$args['input_class']}\"" : '';
84
+ $input_name = ($group) ? "permalink-manager[{$group}][{$name}]" : $name;
85
+
86
+ switch($args['type']) {
87
+ case 'checkbox' :
88
+ $fields .= '<div class="checkboxes">';
89
+ foreach($args['choices'] as $value => $label) {
90
+ $all_checked = (isset($saved_values[$group][$name])) ? $saved_values[$group][$name] : $args['default'];
91
+ $checked = in_array($value, $all_checked) ? "checked='checked'" : "";
92
+ $fields .= "<label for='{$input_name}[]'><input type='checkbox' {$input_class} value='{$value}' name='{$input_name}[]' {$checked} /> {$label}</label>";
93
+ }
94
+ $fields .= '</div>';
95
+ break;
96
+
97
+ case 'number' :
98
+ $value = (isset($saved_values[$group][$name])) ? $saved_values[$group][$name] : $default_value;
99
+ $fields .= "<input type='number' {$input_class} value='{$value}' name='{$input_name}' />";
100
+ break;
101
+
102
+ default :
103
+ $value = (isset($saved_values[$group][$name])) ? $saved_values[$group][$name] : $default_value;
104
+ $fields .= "<input type='text' {$input_class} value='{$value}' name='{$input_name}' {$placeholder}/>";
105
+ }
106
+
107
+ // Get all variables into one final variable
108
+ if(isset($group) && !($group === 'screen-options')) {
109
+ $output = "<legend>{$label}</legend>";
110
+ $output .= "<div class='metabox-prefs'><div class='{$name}-container'>{$fields}</div></div>";
111
+ } else if (isset($args['without_label']) && $args['without_label'] == true) {
112
+ $output = $fields;
113
+ } else {
114
+ $output = "<tr><th><label for='{$input_name}'>{$args['label']}</label></th>";
115
+ $output .= "<td>{$fields}</td>";
116
+ }
117
+
118
+ return $output;
119
+ }
120
+
121
+ /**
122
+ * Check if the provided slug is unique and then update it with SQL query.
123
+ */
124
+ static function update_slug_by_id($slug, $id) {
125
+ global $wpdb;
126
+
127
+ // Update slug and make it unique
128
+ $slug = (empty($slug)) ? sanitize_title(get_the_title($id)) : $slug;
129
+ $new_slug = wp_unique_post_slug($slug, $id, get_post_status($id), get_post_type($id), null);
130
+ $wpdb->query("UPDATE $wpdb->posts SET post_name = '$new_slug' WHERE ID = '$id'");
131
+
132
+ return $new_slug;
133
+ }
134
+
135
+ /**
136
+ * Save option
137
+ */
138
+ static function save_option($field = null, $value = null) {
139
+ $options = get_option('permalink-manager', array());
140
+ if($field) {
141
+ $options[$field] = $value;
142
+
143
+ // The snippet belows prevent duplicates in permastructures
144
+ if($field == 'base-editor') {
145
+
146
+ //print_r($value);
147
+
148
+ // Algorithm below works like array_count_values(), but we also need to make the permastructs unique
149
+ $unique_permastructures = array();
150
+ foreach($value as $key => $permastruct) {
151
+ // Trim whitespaces & slashes at first
152
+ $permastruct = trim(trim($permastruct, "/"));
153
+
154
+ // The permastruct is not unique!
155
+ if(empty($permastruct)) {
156
+ $permastruct = Permalink_Manager_Helper_Functions::get_permastruct($key, false, 'default_permastruct');
157
+ } else if(isset($unique_permastructures[$permastruct])) {
158
+ $unique_permastructures[$permastruct]++;
159
+ // Alter the permastruct
160
+ $permastruct = "{$key}/{$permastruct}";
161
+ } else {
162
+ $unique_permastructures[$permastruct] = 1;
163
+ }
164
+
165
+ // Trim one more time
166
+ $permastruct = trim(trim($permastruct, "/"));
167
+
168
+ // Alter the permastruct
169
+ $options[$field][$key] = $permastruct;
170
+ }
171
+
172
+ }
173
+
174
+ update_option('permalink-manager', $options);
175
+ }
176
+ }
177
+
178
+ /**
179
+ * Get permastruct
180
+ */
181
+ static function get_permastruct($post_type = 'page', $title_replace = false, $return = 'permastruct') {
182
+ global $wp_rewrite;
183
+
184
+ // Load permastruct from options
185
+ $options = get_option('permalink-manager', array());
186
+ $permastructs = isset($options['base-editor']) ? $options['base-editor'] : array();
187
+
188
+ // Get default permastruct
189
+ if($post_type == 'page') {
190
+ $default_permastruct = $wp_rewrite->get_page_permastruct();
191
+ } else if($post_type == 'post') {
192
+ $default_permastruct = get_option('permalink_structure');
193
+ } else {
194
+ $default_permastruct = $wp_rewrite->get_extra_permastruct($post_type);
195
+ }
196
+
197
+ // If the permastruct is not saved for post type or empty return default permastruct
198
+ $permastruct = (isset($permastructs[$post_type]) && $permastructs[$post_type]) ? $permastructs[$post_type] : $default_permastruct;
199
+
200
+ // Remove post name to enable support for hierarchical post types
201
+ $permastruct = ($title_replace) ? str_replace(array("%pagename%", "%postname%", "%{$post_type}%"), '', $permastruct) : "";
202
+
203
+ return trim($$return, '/');
204
+ }
205
+
206
+ /**
207
+ * Structure Tags & Rewrite functions
208
+ */
209
+ static function get_all_structure_tags($code = true, $seperator = ', ') {
210
+ global $wp_rewrite;
211
+
212
+ $tags = $wp_rewrite->rewritecode;
213
+ $output = "";
214
+ $last_tag_index = count($tags);
215
+ $i = 1;
216
+
217
+ foreach($tags as $tag) {
218
+ $sep = ($last_tag_index == $i) ? "" : $seperator;
219
+ $output .= ($code) ? "<code>{$tag}</code>{$sep}" : "{$tag}{$sep}";
220
+ $i++;
221
+ }
222
+
223
+ return $output;
224
+ }
225
+
226
+ static function get_post_tag($post_type) {
227
+ // Get the post type (with fix for posts & pages)
228
+ if($post_type == 'page') {
229
+ $post_type_tag = '%pagename%';
230
+ } else if ($post_type == 'post') {
231
+ $post_type_tag = '%postname%';
232
+ } else {
233
+ $post_type_tag = "%{$post_type}%";
234
+ }
235
+ return $post_type_tag;
236
+ }
237
+
238
+ }
inc/permalink-manager-screen-options.php CHANGED
@@ -1,40 +1,40 @@
1
- <?php
2
-
3
- /**
4
- * Additional Screen Options that helps to manage the permalinks in the table
5
- */
6
-
7
- class Permalink_Manager_Screen_Options extends Permalink_Manager_Class {
8
-
9
- public function __construct() {
10
- $admin_page = PERMALINK_MANAGER_MENU_PAGE;
11
-
12
- if(isset($_GET['page']) && $_GET['page'] == 'permalink-manager.php') {
13
- add_action( "load-{$admin_page}", array($this, "save_screen_options") );
14
- add_filter( "screen_settings", array($this, "add_screen_options") );
15
- }
16
- }
17
-
18
- /**
19
- * Add scren options
20
- */
21
- public function add_screen_options() {
22
- $button = get_submit_button( __( 'Apply', 'permalink-manager' ), 'primary', 'screen-options-apply', false );
23
- $return = "<fieldset>";
24
-
25
- foreach(parent::fields_arrays('screen_options') as $field_name => $field_args) {
26
- $return .= Permalink_Manager_Helper_Functions::generate_option_field($field_name, $field_args, 'screen-options');
27
- }
28
-
29
- $return .= "</fieldset><br class='clear'>{$button}";
30
- return $return;
31
- }
32
-
33
- /**
34
- * Save fields
35
- */
36
- public function save_screen_options() {
37
- if(isset($_POST['screen-options-apply'])) Permalink_Manager_Helper_Functions::save_option('screen-options', $_POST['permalink-manager']['screen-options']);
38
- }
39
-
40
- }
1
+ <?php
2
+
3
+ /**
4
+ * Additional Screen Options that helps to manage the permalinks in the table
5
+ */
6
+
7
+ class Permalink_Manager_Screen_Options extends Permalink_Manager_Class {
8
+
9
+ public function __construct() {
10
+ $admin_page = PERMALINK_MANAGER_MENU_PAGE;
11
+
12
+ if(isset($_GET['page']) && $_GET['page'] == 'permalink-manager.php') {
13
+ add_action( "load-{$admin_page}", array($this, "save_screen_options") );
14
+ add_filter( "screen_settings", array($this, "add_screen_options") );
15
+ }
16
+ }
17
+
18
+ /**
19
+ * Add scren options
20
+ */
21
+ public function add_screen_options() {
22
+ $button = get_submit_button( __( 'Apply', 'permalink-manager' ), 'primary', 'screen-options-apply', false );
23
+ $return = "<fieldset>";
24
+
25
+ foreach(parent::fields_arrays('screen_options') as $field_name => $field_args) {
26
+ $return .= Permalink_Manager_Helper_Functions::generate_option_field($field_name, $field_args, 'screen-options');
27
+ }
28
+
29
+ $return .= "</fieldset><br class='clear'>{$button}";
30
+ return $return;
31
+ }
32
+
33
+ /**
34
+ * Save fields
35
+ */
36
+ public function save_screen_options() {
37
+ if(isset($_POST['screen-options-apply'])) Permalink_Manager_Helper_Functions::save_option('screen-options', $_POST['permalink-manager']['screen-options']);
38
+ }
39
+
40
+ }
inc/permalink-manager-slug-editor.php CHANGED
@@ -1,169 +1,169 @@
1
- <?php
2
- if( ! class_exists( 'WP_List_Table' ) ) {
3
- require_once( ABSPATH . 'wp-admin/includes/class-wp-list-table.php' );
4
- }
5
-
6
- /**
7
- * Create a new table class that will extend the WP_List_Table
8
- */
9
- class Permalink_Manager_Slug_Editor extends WP_List_Table {
10
- public $screen_options_fields;
11
-
12
- function __construct() {
13
- global $status, $page;
14
-
15
- parent::__construct(array(
16
- 'singular' => 'slug',
17
- 'plural' => 'slugs',
18
- 'ajax' => true
19
- ));
20
- }
21
-
22
- /**
23
- * Override the parent columns method. Defines the columns to use in your listing table
24
- */
25
- public function get_columns() {
26
- $columns = array(
27
- //'cb' => '<input type="checkbox" />', //Render a checkbox instead of text
28
- 'post_title' => __('Title', 'permalink-manager'),
29
- 'post_name' => __('Slug', 'permalink-manager'),
30
- 'post_date_gmt' => __('Date', 'permalink-manager'),
31
- 'post_permalink' => __('Permalink', 'permalink-manager'),
32
- 'post_status' => __('Post Status', 'permalink-manager'),
33
- 'post_type' => __('Post Type', 'permalink-manager')
34
- );
35
-
36
- return $columns;
37
- }
38
-
39
- /**
40
- * Hidden columns
41
- */
42
- public function get_hidden_columns() {
43
- return array('post_date_gmt');
44
- }
45
-
46
- /**
47
- * Sortable columns
48
- */
49
- public function get_sortable_columns() {
50
- return array(
51
- 'post_title' => array('post_title', false),
52
- 'post_name' => array('post_name', false),
53
- 'post_status' => array('post_status', false),
54
- 'post_type' => array('post_type', false),
55
- );
56
- }
57
-
58
- /**
59
- * Data inside the columns
60
- */
61
- public function column_default( $item, $column_name ) {
62
- switch( $column_name ) {
63
- case 'post_type':
64
- $post_type_labels = Permalink_Manager_Helper_Functions::get_post_types_array('full', $item['post_type']);
65
- return "{$post_type_labels['label']}<br /><small>({$post_type_labels['name']})</small>";
66
-
67
- case 'post_status':
68
- $post_statuses_array = get_post_statuses();
69
- return "{$post_statuses_array[$item[ $column_name ]]}<br /><small>({$item[ $column_name ]})</small>";
70
-
71
- case 'post_permalink':
72
- return ($item['post_status'] != 'publish') ? '-' : Permalink_Manager_Helper_Functions::get_correct_permalink($item[ 'ID' ], $item[ 'post_name' ], true) . ' <a href="' . Permalink_Manager_Helper_Functions::get_correct_permalink($item[ 'ID' ], $item[ 'post_name' ]) . '" target="_blank"><span class="dashicons dashicons-admin-links"></span></a>';
73
-
74
- case 'post_name':
75
- $field_name = "slug[{$item['ID']}]";
76
- $field_args = array('type' => 'text', 'default' => $item[ 'post_name' ], 'without_label' => true, 'input_class' => 'widefat');
77
- return Permalink_Manager_Helper_Functions::generate_option_field($field_name, $field_args);
78
-
79
- case 'post_title':
80
- $edit_post = $item[ 'post_title' ] . '<div class="row-actions">';
81
- $edit_post .= '<span class="edit"><a target="_blank" href="' . home_url() . '/wp-admin/post.php?post=' . $item[ 'ID' ] . '&amp;action=edit" title="' . __('Edit', 'permalink-manager') . '">' . __('Edit', 'permalink-manager') . '</a> | </span>';
82
- $edit_post .= '<span class="view"><a target="_blank" href="' . Permalink_Manager_Helper_Functions::get_correct_permalink($item[ 'ID' ], $item[ 'post_name' ]) . '" title="' . __('View', 'permalink-manager') . ' ' . $item[ 'post_title' ] . '" rel="permalink">' . __('View', 'permalink-manager') . '</a> | </span>';
83
- $edit_post .= '<span class="id">#' . $item[ 'ID' ] . '</span>';
84
- $edit_post .= '</div>';
85
- return $edit_post;
86
-
87
- default:
88
- return $item[ $column_name ];
89
- }
90
- }
91
-
92
- /**
93
- * Sort the data
94
- */
95
- private function sort_data( $a, $b ) {
96
- // Set defaults
97
- $orderby = (!empty($_GET['orderby'])) ? $_GET['orderby'] : 'post_title';
98
- $order = (!empty($_GET['order'])) ? $_GET['order'] : 'asc';
99
- $result = strnatcasecmp( $a[$orderby], $b[$orderby] );
100
-
101
- return ($order === 'asc') ? $result : -$result;
102
- }
103
-
104
- /**
105
- * The button that allows to save updated slugs
106
- */
107
- function extra_tablenav( $which ) {
108
- $button_top = __( 'Update all slugs below', 'permalink-manager' );
109
- $button_bottom = __( 'Update all slugs above', 'permalink-manager' );
110
-
111
- echo '<div class="alignleft actions">';
112
- submit_button( ${"button_$which"}, 'primary', "update_all_slugs[{$which}]", false, array( 'id' => 'doaction', 'value' => 'update_all_slugs' ) );
113
- echo '</div>';
114
- }
115
-
116
- /**
117
- * Prepare the items for the table to process
118
- */
119
- public function prepare_items($posts_table) {
120
- $columns = $this->get_columns();
121
- $hidden = $this->get_hidden_columns();
122
- $sortable = $this->get_sortable_columns();
123
- $currentPage = $this->get_pagenum();
124
-
125
- global $wpdb;
126
-
127
- // Load options and fields
128
- $saved_options = get_option('permalink-manager');
129
- $saved_options = isset($saved_options['screen-options']) ? $saved_options['screen-options'] : array();
130
- $screen_options_fields = $this->screen_options_fields;
131
- $per_page = isset($saved_options['per_page']) ? $saved_options['per_page'] : $screen_options_fields['per_page']['default'];
132
- $post_types_array = isset($saved_options['post_types']) ? $saved_options['post_types'] : $screen_options_fields['post_types']['default'];
133
- $post_types = "'" . implode("', '", $post_types_array) . "'";
134
- $post_statuses_array = isset($saved_options['post_statuses']) ? $saved_options['post_statuses'] : $screen_options_fields['post_statuses']['default'];
135
- $post_statuses = "'" . implode("', '", $post_statuses_array) . "'";
136
-
137
- // Will be used in pagination settings
138
- $total_items = $wpdb->get_var("SELECT COUNT(id) FROM $posts_table WHERE post_status IN ($post_statuses) AND post_type IN ($post_types)");
139
-
140
- // SQL query parameters
141
- $order = (isset($_REQUEST['order']) && in_array($_REQUEST['order'], array('asc', 'desc'))) ? $_REQUEST['order'] : 'desc';
142
- $orderby = (isset($_REQUEST['orderby'])) ? $_REQUEST['orderby'] : 'ID';
143
- $offset = ($currentPage - 1) * $per_page;
144
-
145
- // Grab posts from database
146
- $sql_query = "SELECT * FROM $posts_table WHERE post_status IN ($post_statuses) AND post_type IN ($post_types) ORDER BY $orderby $order LIMIT $per_page OFFSET $offset";
147
- $data = $wpdb->get_results($sql_query, ARRAY_A);
148
-
149
- // Sort posts and count all posts
150
- usort( $data, array( &$this, 'sort_data' ) );
151
-
152
- $this->set_pagination_args( array(
153
- 'total_items' => $total_items,
154
- 'per_page' => $per_page
155
- ));
156
-
157
- $this->_column_headers = array($columns, $hidden, $sortable);
158
- $this->items = $data;
159
- }
160
-
161
- /**
162
- * This variable is assigned in permalink-manager.php before prepare_items() function is triggered, see permalinks_table_html() function
163
- */
164
- public function set_screen_option_fields($fields) {
165
- $this->screen_options_fields = $fields;
166
- }
167
-
168
- }
169
- ?>
1
+ <?php
2
+ if( ! class_exists( 'WP_List_Table' ) ) {
3
+ require_once( ABSPATH . 'wp-admin/includes/class-wp-list-table.php' );
4
+ }
5
+
6
+ /**
7
+ * Create a new table class that will extend the WP_List_Table
8
+ */
9
+ class Permalink_Manager_Slug_Editor extends WP_List_Table {
10
+ public $screen_options_fields;
11
+
12
+ function __construct() {
13
+ global $status, $page;
14
+
15
+ parent::__construct(array(
16
+ 'singular' => 'slug',
17
+ 'plural' => 'slugs',
18
+ 'ajax' => true
19
+ ));
20
+ }
21
+
22
+ /**
23
+ * Override the parent columns method. Defines the columns to use in your listing table
24
+ */
25
+ public function get_columns() {
26
+ $columns = array(
27
+ //'cb' => '<input type="checkbox" />', //Render a checkbox instead of text
28
+ 'post_title' => __('Title', 'permalink-manager'),
29
+ 'post_name' => __('Slug', 'permalink-manager'),
30
+ 'post_date_gmt' => __('Date', 'permalink-manager'),
31
+ 'post_permalink' => __('Permalink', 'permalink-manager'),
32
+ 'post_status' => __('Post Status', 'permalink-manager'),
33
+ 'post_type' => __('Post Type', 'permalink-manager')
34
+ );
35
+
36
+ return $columns;
37
+ }
38
+
39
+ /**
40
+ * Hidden columns
41
+ */
42
+ public function get_hidden_columns() {
43
+ return array('post_date_gmt');
44
+ }
45
+
46
+ /**
47
+ * Sortable columns
48
+ */
49
+ public function get_sortable_columns() {
50
+ return array(
51
+ 'post_title' => array('post_title', false),
52
+ 'post_name' => array('post_name', false),
53
+ 'post_status' => array('post_status', false),
54
+ 'post_type' => array('post_type', false),
55
+ );
56
+ }
57
+
58
+ /**
59
+ * Data inside the columns
60
+ */
61
+ public function column_default( $item, $column_name ) {
62
+ switch( $column_name ) {
63
+ case 'post_type':
64
+ $post_type_labels = Permalink_Manager_Helper_Functions::get_post_types_array('full', $item['post_type']);
65
+ return "{$post_type_labels['label']}<br /><small>({$post_type_labels['name']})</small>";
66
+
67
+ case 'post_status':
68
+ $post_statuses_array = get_post_statuses();
69
+ return "{$post_statuses_array[$item[ $column_name ]]}<br /><small>({$item[ $column_name ]})</small>";
70
+
71
+ case 'post_permalink':
72
+ return ($item['post_status'] != 'publish') ? '-' : Permalink_Manager_Helper_Functions::get_correct_permalink($item[ 'ID' ], $item[ 'post_name' ], true) . ' <a href="' . Permalink_Manager_Helper_Functions::get_correct_permalink($item[ 'ID' ], $item[ 'post_name' ]) . '" target="_blank"><span class="dashicons dashicons-admin-links"></span></a>';
73
+
74
+ case 'post_name':
75
+ $field_name = "slug[{$item['ID']}]";
76
+ $field_args = array('type' => 'text', 'default' => $item[ 'post_name' ], 'without_label' => true, 'input_class' => 'widefat');
77
+ return Permalink_Manager_Helper_Functions::generate_option_field($field_name, $field_args);
78
+
79
+ case 'post_title':
80
+ $edit_post = $item[ 'post_title' ] . '<div class="row-actions">';
81
+ $edit_post .= '<span class="edit"><a target="_blank" href="' . home_url() . '/wp-admin/post.php?post=' . $item[ 'ID' ] . '&amp;action=edit" title="' . __('Edit', 'permalink-manager') . '">' . __('Edit', 'permalink-manager') . '</a> | </span>';
82
+ $edit_post .= '<span class="view"><a target="_blank" href="' . Permalink_Manager_Helper_Functions::get_correct_permalink($item[ 'ID' ], $item[ 'post_name' ]) . '" title="' . __('View', 'permalink-manager') . ' ' . $item[ 'post_title' ] . '" rel="permalink">' . __('View', 'permalink-manager') . '</a> | </span>';
83
+ $edit_post .= '<span class="id">#' . $item[ 'ID' ] . '</span>';
84
+ $edit_post .= '</div>';
85
+ return $edit_post;
86
+
87
+ default:
88
+ return $item[ $column_name ];
89
+ }
90
+ }
91
+
92
+ /**
93
+ * Sort the data
94
+ */
95
+ private function sort_data( $a, $b ) {
96
+ // Set defaults
97
+ $orderby = (!empty($_GET['orderby'])) ? $_GET['orderby'] : 'post_title';
98
+ $order = (!empty($_GET['order'])) ? $_GET['order'] : 'asc';
99
+ $result = strnatcasecmp( $a[$orderby], $b[$orderby] );
100
+
101
+ return ($order === 'asc') ? $result : -$result;
102
+ }
103
+
104
+ /**
105
+ * The button that allows to save updated slugs
106
+ */
107
+ function extra_tablenav( $which ) {
108
+ $button_top = __( 'Update all slugs below', 'permalink-manager' );
109
+ $button_bottom = __( 'Update all slugs above', 'permalink-manager' );
110
+
111
+ echo '<div class="alignleft actions">';
112
+ submit_button( ${"button_$which"}, 'primary', "update_all_slugs[{$which}]", false, array( 'id' => 'doaction', 'value' => 'update_all_slugs' ) );
113
+ echo '</div>';
114
+ }
115
+
116
+ /**
117
+ * Prepare the items for the table to process
118
+ */
119
+ public function prepare_items() {
120
+ $columns = $this->get_columns();
121
+ $hidden = $this->get_hidden_columns();
122
+ $sortable = $this->get_sortable_columns();
123
+ $currentPage = $this->get_pagenum();
124
+
125
+ global $wpdb;
126
+
127
+ // Load options and fields
128
+ $saved_options = get_option('permalink-manager');
129
+ $saved_options = isset($saved_options['screen-options']) ? $saved_options['screen-options'] : array();
130
+ $screen_options_fields = $this->screen_options_fields;
131
+ $per_page = isset($saved_options['per_page']) ? $saved_options['per_page'] : $screen_options_fields['per_page']['default'];
132
+ $post_types_array = isset($saved_options['post_types']) ? $saved_options['post_types'] : $screen_options_fields['post_types']['default'];
133
+ $post_types = "'" . implode("', '", $post_types_array) . "'";
134
+ $post_statuses_array = isset($saved_options['post_statuses']) ? $saved_options['post_statuses'] : $screen_options_fields['post_statuses']['default'];
135
+ $post_statuses = "'" . implode("', '", $post_statuses_array) . "'";
136
+
137
+ // Will be used in pagination settings
138
+ $total_items = $wpdb->get_var("SELECT COUNT(id) FROM {$wpdb->posts} WHERE post_status IN ($post_statuses) AND post_type IN ($post_types)");
139
+
140
+ // SQL query parameters
141
+ $order = (isset($_REQUEST['order']) && in_array($_REQUEST['order'], array('asc', 'desc'))) ? $_REQUEST['order'] : 'desc';
142
+ $orderby = (isset($_REQUEST['orderby'])) ? $_REQUEST['orderby'] : 'ID';
143
+ $offset = ($currentPage - 1) * $per_page;
144
+
145
+ // Grab posts from database
146
+ $sql_query = "SELECT * FROM {$wpdb->posts} WHERE post_status IN ($post_statuses) AND post_type IN ($post_types) ORDER BY $orderby $order LIMIT $per_page OFFSET $offset";
147
+ $data = $wpdb->get_results($sql_query, ARRAY_A);
148
+
149
+ // Sort posts and count all posts
150
+ usort( $data, array( &$this, 'sort_data' ) );
151
+
152
+ $this->set_pagination_args( array(
153
+ 'total_items' => $total_items,
154
+ 'per_page' => $per_page
155
+ ));
156
+
157
+ $this->_column_headers = array($columns, $hidden, $sortable);
158
+ $this->items = $data;
159
+ }
160
+
161
+ /**
162
+ * This variable is assigned in permalink-manager.php before prepare_items() function is triggered, see permalinks_table_html() function
163
+ */
164
+ public function set_screen_option_fields($fields) {
165
+ $this->screen_options_fields = $fields;
166
+ }
167
+
168
+ }
169
+ ?>
js/permalink-manager-admin.js CHANGED
@@ -1,35 +1,35 @@
1
- jQuery(document).ready(function() {
2
-
3
- /*
4
- * Tab navigation
5
- */
6
- jQuery('#permalink-manager-tabs-nav a').on('click', function(){
7
-
8
- // Disable current active tab in navigation
9
- jQuery('#permalink-manager-tabs-nav .nav-tab-active').removeClass('nav-tab-active');
10
- jQuery('#permalink-manager-tabs .show').removeClass('show');
11
-
12
- // Get current tab name
13
- var tab_to_open = jQuery(this).data("tab");
14
-
15
- // Add "active" class to the clicked tab
16
- jQuery(this).addClass('nav-tab-active');
17
- jQuery('#permalink-manager-tabs div[data-tab="'+tab_to_open+'"]').addClass('show');
18
-
19
- // Disable native click event
20
- return false;
21
- });
22
-
23
- /*
24
- * "Select all" checkbox
25
- */
26
- jQuery('input[value="all"]').on('change', function() {
27
- // Uncheck "Select all"
28
- jQuery(this).prop('checked', false);
29
-
30
- jQuery(this).parents('.checkboxes').find('input[type="checkbox"]').not(this).each(function() {
31
- jQuery(this).prop('checked', true);
32
- });
33
- });
34
-
35
  });
1
+ jQuery(document).ready(function() {
2
+
3
+ /*
4
+ * Tab navigation
5
+ */
6
+ jQuery('#permalink-manager-tabs-nav a').on('click', function(){
7
+
8
+ // Disable current active tab in navigation
9
+ jQuery('#permalink-manager-tabs-nav .nav-tab-active').removeClass('nav-tab-active');
10
+ jQuery('#permalink-manager-tabs .show').removeClass('show');
11
+
12
+ // Get current tab name
13
+ var tab_to_open = jQuery(this).data("tab");
14
+
15
+ // Add "active" class to the clicked tab
16
+ jQuery(this).addClass('nav-tab-active');
17
+ jQuery('#permalink-manager-tabs div[data-tab="'+tab_to_open+'"]').addClass('show');
18
+
19
+ // Disable native click event
20
+ return false;
21
+ });
22
+
23
+ /*
24
+ * "Select all" checkbox
25
+ */
26
+ jQuery('input[value="all"]').on('change', function() {
27
+ // Uncheck "Select all"
28
+ jQuery(this).prop('checked', false);
29
+
30
+ jQuery(this).parents('.checkboxes').find('input[type="checkbox"]').not(this).each(function() {
31
+ jQuery(this).prop('checked', true);
32
+ });
33
+ });
34
+
35
  });
permalink-manager.php CHANGED
@@ -1,665 +1,666 @@
1
- <?php
2
-
3
- /**
4
- * Plugin Name: Permalink Manager
5
- * Plugin URI: http://maciejbis.net/
6
- * Description: A simple tool that allows to mass update of slugs that are used to build permalinks for Posts, Pages and Custom Post Types.
7
- * Version: 0.3.2
8
- * Author: Maciej Bis
9
- * Author URI: http://maciejbis.net/
10
- * License: GPL-2.0+
11
- * License URI: http://www.gnu.org/licenses/gpl-2.0.txt
12
- * Text Domain: permalink-manager
13
- * Domain Path: /languages
14
- */
15
-
16
- // If this file is called directly, abort.
17
- if ( ! defined( 'WPINC' ) ) {
18
- die;
19
- }
20
-
21
- // Define the directories used to load plugin files.
22
- define( 'PERMALINK_MANAGER_PLUGIN_NAME', 'permalink-manager' );
23
- define( 'PERMALINK_MANAGER_VERSION', '0.3.2' );
24
- define( 'PERMALINK_MANAGER_DIR', untrailingslashit( dirname( __FILE__ ) ) );
25
- define( 'PERMALINK_MANAGER_URL', untrailingslashit( plugins_url( '', __FILE__ ) ) );
26
- define( 'PERMALINK_MANAGER_WEBSITE', 'http://maciejbis.net' );
27
- define( 'PERMALINK_MANAGER_MENU_PAGE', 'tools_page_permalink-manager' );
28
- define( 'PERMALINK_MANAGER_OPTIONS_PAGE', PERMALINK_MANAGER_PLUGIN_NAME . '.php' );
29
-
30
- class Permalink_Manager_Class {
31
-
32
- protected $permalink_manager, $admin_page, $permalink_manager_options_page, $permalink_manager_options;
33
-
34
- public function __construct() {
35
-
36
- $this->permalink_manager_options = get_option('permalink-manager');
37
-
38
- if( is_admin() ) {
39
- add_action( 'plugins_loaded', array($this, 'localize_me') );
40
- add_action( 'init', array($this, 'flush_rewrite_rules') );
41
- add_action( 'admin_init', array($this, 'bulk_actions') );
42
- add_action( 'admin_menu', array($this, 'add_menu_page') );
43
- add_filter( 'plugin_action_links_' . plugin_basename(__FILE__), array($this, 'plugins_page_links') );
44
-
45
- add_filter( 'page_rewrite_rules', array($this, 'custom_page_rewrite_rules'), 999, 1);
46
- add_filter( 'post_rewrite_rules', array($this, 'custom_post_rewrite_rules'), 999, 1);
47
- add_filter( 'rewrite_rules_array', array($this, 'custom_cpt_rewrite_rules'), 999, 1);
48
- }
49
-
50
- // Public functions
51
- add_filter( '_get_page_link', array($this, 'custom_permalinks'), 999, 2);
52
- add_filter( 'page_link', array($this, 'custom_permalinks'), 999, 2);
53
- add_filter( 'post_link', array($this, 'custom_permalinks'), 999, 2);
54
- add_filter( 'post_type_link', array($this, 'custom_permalinks'), 999, 2);
55
-
56
- }
57
-
58
- /**
59
- * Localize this plugin
60
- */
61
- function localize_me() {
62
- load_plugin_textdomain( 'permalink-manager', false, PERMALINK_MANAGER_DIR );
63
- }
64
-
65
- /**
66
- * Add menu page and load CSS & JS.
67
- */
68
- function add_menu_page() {
69
- add_management_page( __('Permalink Manager', 'permalink-manager'), __('Permalink Manager', 'permalink-manager'), 'manage_options', PERMALINK_MANAGER_OPTIONS_PAGE, array($this, 'list_slugs_admin_page') );
70
-
71
- // Make sure thata the CSS and JS files are loaded only on plugin admin page.
72
- add_action( 'admin_print_scripts-' . PERMALINK_MANAGER_MENU_PAGE, array($this, 'enqueue_styles' ) );
73
- add_action( 'admin_print_scripts-' . PERMALINK_MANAGER_MENU_PAGE, array($this, 'enqueue_scripts' ) );
74
- }
75
-
76
- /**
77
- * Display the table with slugs.
78
- */
79
- function slug_editor_html() {
80
- global $wpdb;
81
-
82
- $Permalink_Manager_Slug_Editor = new Permalink_Manager_Slug_Editor();
83
- $Permalink_Manager_Slug_Editor->set_screen_option_fields($this->fields_arrays('screen_options'));
84
- $Permalink_Manager_Slug_Editor->prepare_items($wpdb->posts);
85
-
86
- ?>
87
-
88
- <form id="permalinks-table" method="post">
89
- <input type="hidden" name="tab" value="slug_editor" />
90
- <?php echo $Permalink_Manager_Slug_Editor->display(); ?>
91
- </form>
92
- <?php
93
- }
94
-
95
- /**
96
- * Mass replace options page.
97
- */
98
- function find_and_replace_html() {
99
- $button = get_submit_button( __( 'Find & Replace', 'permalink-manager' ), 'primary', 'find-replace-button', false );
100
-
101
- $return = "<form id=\"permalinks-table-find-replace\" method=\"post\">";
102
- $return .= "<input type=\"hidden\" name=\"tab\" value=\"find_and_replace\" />";
103
- $return .= "<table class=\"form-table\">";
104
-
105
- foreach($this->fields_arrays('find_and_replace') as $field_name => $field_args) {
106
- $return .= Permalink_Manager_Helper_Functions::generate_option_field($field_name, $field_args, 'find-replace');
107
- }
108
-
109
- $return .= "</table>{$button}";
110
- $return .= "</form>";
111
-
112
- echo $return;
113
- }
114
-
115
- /**
116
- * Reset slugs page.
117
- */
118
- function regenerate_slugs_html() {
119
- $button = get_submit_button( __( 'Regenerate', 'permalink-manager' ), 'primary', 'regenerate-button', false );
120
-
121
- $return = "<form id=\"permalinks-table-regenerate\" method=\"post\">";
122
- $return .= "<input type=\"hidden\" name=\"tab\" value=\"regenerate_slugs\" />";
123
- $return .= "<table class=\"form-table\">";
124
-
125
- foreach($this->fields_arrays('regenerate_slugs') as $field_name => $field_args) {
126
- $return .= Permalink_Manager_Helper_Functions::generate_option_field($field_name, $field_args, 'regenerate_slugs');
127
- }
128
-
129
- $return .= "</table>{$button}";
130
- $return .= "</form>";
131
-
132
- echo $return;
133
- }
134
-
135
- /**
136
- * Permalink Base Editor
137
- */
138
- function base_editor_html() {
139
- global $wpdb, $wp_rewrite;
140
-
141
- $Permalink_Manager_Base_Editor = new Permalink_Manager_Base_Editor();
142
- $Permalink_Manager_Base_Editor->set_screen_option_fields($this->fields_arrays('screen_options'));
143
- $Permalink_Manager_Base_Editor->prepare_items($wpdb->posts);
144
-
145
- //echo '<pre>';
146
- //print_r($wp_rewrite);
147
- //echo '</pre>';
148
-
149
- ?>
150
-
151
- <form id="permalinks-base-table" method="post">
152
- <input type="hidden" name="tab" value="base_editor" />
153
- <?php echo $Permalink_Manager_Base_Editor->display(); ?>
154
- </form>
155
- <?php
156
- }
157
-
158
- /**
159
- * Display the plugin dashboard.
160
- */
161
- function list_slugs_admin_page() {
162
- global $wpdb;
163
-
164
- // Check which tab is active now.
165
- if(isset($_POST['tab'])) {
166
- $active_tab = $_POST['tab'];
167
- } else if(isset($_GET['tab'])) {
168
- $active_tab = $_GET['tab'];
169
- } else {
170
- $active_tab = 'slug_editor';
171
- }
172
-
173
- // Tabs array with assigned functions used to display HTML content.
174
- $tabs = array(
175
- 'slug_editor' => array(
176
- 'name' => __('Slug Editor', 'permalink-manager'),
177
- 'function' => 'slug_editor_html',
178
- 'description' => __('You can disable/enable selected post types from the table below using <strong>"Screen Options"</strong> (click on the upper-right button to show it) section above.', 'permalink-manager')
179
- ),
180
- 'find_and_replace' => array(
181
- 'name' => __('Find and replace', 'permalink-manager'),
182
- 'function' => 'find_and_replace_html',
183
- 'warning' => (__('<strong>You are doing it at your own risk!</strong>', 'permalink-manager') . '<br />' . __('A backup of MySQL database before using this tool is highly recommended. The search & replace operation might be not revertible!', 'permalink-manager'))
184
- ),
185
- 'regenerate_slugs' => array(
186
- 'name' => __('Regenerate slugs', 'permalink-manager'),
187
- 'function' => 'regenerate_slugs_html',
188
- 'warning' => (__('<strong>You are doing it at your own risk!</strong>', 'permalink-manager') . '<br />' . __('A backup of MySQL database before using this tool is highly recommended. The regenerate process of slugs might be not revertible!', 'permalink-manager'))
189
- ),
190
- 'base_editor' => array(
191
- 'name' => __('Permalinks Base Editor', 'permalink-manager'),
192
- 'function' => 'base_editor_html',
193
- 'warning' => array(
194
- sprintf(__('<strong>This is an experimental feature!</strong> Please report all the bugs & issues <a href="%s">here</a>.', 'permalink-manager'), 'https://wordpress.org/support/plugin/permalink-manager'),
195
- __('Custom Post Types should have their own, unique front, eg. <em>products/%product%!</em>', 'permalink-manager'),
196
- __('After you update & save the settings below, you need to flush the rewrite rules!', 'permalink-manager'),
197
- ),
198
- 'description' => (sprintf( __('All the <a href="%s" target="_blank">Structure Tags</a> allowed are listed below. Please note that some of them can be used only for particular Post Types.', 'permalink-manager'), "https://codex.wordpress.org/Using_Permalinks#Structure_Tags") . "<br />" . Permalink_Manager_Helper_Functions::get_all_structure_tags())
199
- ),
200
- );
201
-
202
- ?>
203
- <div id="permalinks-table-wrap" class="wrap">
204
-
205
- <?php
206
- // Display alerts and another content if needed
207
- echo apply_filters('permalink-manager-before-tabs','');
208
- ?>
209
-
210
- <div id="icon-themes" class="icon32"></div>
211
- <h2 id="plugin-name-heading"><?php _e('Permalink Manager', 'permalink-manager'); ?> <a href="<?php echo PERMALINK_MANAGER_WEBSITE; ?>" target="_blank"><?php _e('by Maciej Bis', 'permalink-manager'); ?></a></h2>
212
-
213
- <h2 id="permalink-manager-tabs-nav" class="nav-tab-wrapper">
214
- <?php
215
- foreach($tabs as $tab_id => $tab_properties) {
216
- $active_class = ($active_tab === $tab_id) ? 'nav-tab-active nav-tab' : 'nav-tab';
217
- echo '<a data-tab="' . $tab_id . '" href="' . admin_url('admin.php?page=' . PERMALINK_MANAGER_PLUGIN_NAME . '.php&tab=' . $tab_id) . '" class="' . $active_class . '">' . $tab_properties['name'] . '</a>';
218
- } ?>
219
- </h2>
220
-
221
- <div id="permalink-manager-tabs">
222
- <?php
223
- foreach($tabs as $tab_id => $tab_properties) {
224
- $active_show = ($active_tab === $tab_id) ? 'show' : '';
225
-
226
- // Prepare warning & description texts
227
- $warning = (isset($tab_properties['warning'])) ? $tab_properties['warning'] : '';
228
- $description = (isset($tab_properties['description'])) ? $tab_properties['description'] : '';
229
-
230
- if(is_array($warning)) {
231
- $warning = "<ol>"; // Overwrite the variable
232
- foreach($tab_properties['warning'] as $point) { $warning .= "<li>{$point}</li>"; }
233
- $warning .= "</ol>";
234
- }
235
-
236
- if(is_array($description)) {
237
- $description = "<ol>"; // Overwrite the variable
238
- foreach($tab_properties['description'] as $point) { $description .= "<li>{$point}</li>"; }
239
- $description .= "</ol>";
240
- }
241
-
242
- echo '<div data-tab="' . $tab_id . '" id="' . $tab_id . '" class="' . $active_show . '">';
243
- echo ($warning) ? "<div class=\"warning alert\">" . wpautop($warning) . "</div>" : "";
244
- echo (isset($tab_properties['description'])) ? "<div class=\"info alert\">" . wpautop($description) . "</div>" : "";
245
- $this->$tab_properties['function']();
246
- echo '</div>';
247
- } ?>
248
- </div>
249
-
250
- <?php
251
- // Display alerts and another content if needed
252
- echo apply_filters('permalink-manager-after-tabs','');
253
- ?>
254
-
255
- </div>
256
- <?php
257
- }
258
-
259
- /**
260
- * Register the stylesheets for the Dashboard.
261
- */
262
- function enqueue_styles() {
263
- wp_enqueue_style( PERMALINK_MANAGER_PLUGIN_NAME, PERMALINK_MANAGER_URL . '/css/permalink-manager-admin.css', array(), PERMALINK_MANAGER_VERSION, 'all' );
264
- }
265
-
266
- /**
267
- * Register the JavaScript for the dashboard.
268
- */
269
- function enqueue_scripts() {
270
- wp_enqueue_script( PERMALINK_MANAGER_PLUGIN_NAME, PERMALINK_MANAGER_URL . '/js/permalink-manager-admin.js', array( 'jquery' ), PERMALINK_MANAGER_VERSION, false );
271
- }
272
-
273
- /**
274
- * Additional links on "Plugins" page
275
- */
276
- function plugins_page_links( $links ) {
277
- $links[] = '<a href="' . esc_url( get_admin_url(null, "tools.php?page=" . PERMALINK_MANAGER_OPTIONS_PAGE) ) .'">' . __( 'Go To Permalink Manager', 'permalink-manager' ) . '</a>';
278
- return $links;
279
- }
280
-
281
- /**
282
- * Fields for "Screen Options"
283
- */
284
- function fields_arrays($array) {
285
-
286
- // All registered post types array
287
- $all_post_statuses_array = get_post_statuses();
288
- $all_post_types = Permalink_Manager_Helper_Functions::get_post_types_array();
289
-
290
- // Fields for "Screen Options"
291
- $screen_options = array(
292
- 'post_types' => array(
293
- 'label' => __( 'Post Types', 'permalink-manager' ),
294
- 'type' => 'checkbox',
295
- 'choices' => array_merge(array('all' => '<strong>' . __('All Post Types', 'permalink-manager') . '</strong>'), $all_post_types),
296
- 'default' => array('post', 'page')
297
- ),
298
- 'post_statuses' => array(
299
- 'label' => __( 'Post Statuses', 'permalink-manager' ),
300
- 'type' => 'checkbox',
301
- 'choices' => array_merge(array('all' => '<strong>' . __('All Post Statuses', 'permalink-manager') . '</strong>'), $all_post_statuses_array),
302
- 'default' => array('publish')
303
- ),
304
- 'per_page' => array(
305
- 'label' => __( 'Per page', 'permalink-manager' ),
306
- 'type' => 'number',
307
- 'default' => 10
308
- )
309
- );
310
-
311
- // Fields for "Find and replace"
312
- $find_and_replace = array(
313
- 'old_string' => array(
314
- 'label' => __( 'Find ...', 'permalink-manager' ),
315
- 'type' => 'text',
316
- ),
317
- 'new_string' => array(
318
- 'label' => __( 'Replace with ...', 'permalink-manager' ),
319
- 'type' => 'text',
320
- ),
321
- 'post_types' => array(
322
- 'label' => __( 'Post Types that should be affected', 'permalink-manager' ),
323
- 'type' => 'checkbox',
324
- 'choices' => array_merge(array('all' => '<strong>' . __('All Post Types', 'permalink-manager') . '</strong>'), $all_post_types),
325
- 'default' => array('post', 'page')
326
- ),
327
- 'post_statuses' => array(
328
- 'label' => __( 'Post Statuses that should be affected', 'permalink-manager' ),
329
- 'type' => 'checkbox',
330
- 'choices' => array_merge(array('all' => '<strong>' . __('All Post Statuses', 'permalink-manager') . '</strong>'), $all_post_statuses_array),
331
- 'default' => array('publish')
332
- )
333
- );
334
-
335
- // Fields for "Regenerate slugs"
336
- $regenerate_slugs = array(
337
- 'post_types' => array(
338
- 'label' => __( 'Post Types that should be affected', 'permalink-manager' ),
339
- 'type' => 'checkbox',
340
- 'choices' => array_merge(array('all' => '<strong>' . __('All Post Types', 'permalink-manager') . '</strong>'), $all_post_types),
341
- 'default' => array('post', 'page')
342
- ),
343
- 'post_statuses' => array(
344
- 'label' => __( 'Post Statuses that should be affected', 'permalink-manager' ),
345
- 'type' => 'checkbox',
346
- 'choices' => array_merge(array('all' => '<strong>' . __('All Post Statuses', 'permalink-manager') . '</strong>'), $all_post_statuses_array),
347
- 'default' => array('publish')
348
- )
349
- );
350
-
351
- return isset($array) ? ${$array} : array();
352
-
353
- }
354
-
355
- /**
356
- * Bulk actions functions
357
- */
358
- function bulk_actions() {
359
- global $wpdb;
360
-
361
- $updated_slugs_count = 0;
362
- $updated_array = array();
363
- $alert_type = $alert_content = $errors = $main_content = '';
364
-
365
- if (isset($_POST['update_all_slugs'])) {
366
-
367
- $slugs = isset($_POST['slug']) ? $_POST['slug'] : array();
368
-
369
- // Double check if the slugs and ids are stored in arrays
370
- if (!is_array($slugs)) $slugs = explode(',', $slugs);
371
-
372
- if (!empty($slugs)) {
373
- foreach($slugs as $id => $new_slug) {
374
- $this_post = get_post($id);
375
-
376
- // Check if slug was changed
377
- if($this_post->post_name != $new_slug) {
378
- // Update slugs
379
- Permalink_Manager_Helper_Functions::update_slug_by_id($new_slug, $id);
380
-
381
- $updated_array[] = array('post_title' => get_the_title($id), 'old_slug' => $this_post->post_name, 'new_slug' => $new_slug);
382
- $updated_slugs_count++;
383
- }
384
-
385
- // Reset slug
386
- $slug = '';
387
- }
388
- }
389
-
390
- } else if (isset($_POST['find-replace-button'])) {
391
-
392
- $var['old_string'] = esc_sql($_POST['permalink-manager']['find-replace']['old_string']);
393
- $var['new_string'] = esc_sql($_POST['permalink-manager']['find-replace']['new_string']);
394
- $post_types_array = ($_POST['permalink-manager']['find-replace']['post_types']);
395
- $post_statuses_array = ($_POST['permalink-manager']['find-replace']['post_statuses']);
396
- $var['post_types'] = implode("', '", $post_types_array);
397
- $var['post_statuses'] = implode("', '", $post_statuses_array);
398
-
399
- // Check if any of variables is not empty
400
- $find_and_replace_fields = $this->fields_arrays('find_and_replace');
401
- foreach($var as $key => $val) {
402
- if(empty($val)) $errors .= '<p>' . sprintf( __( '<strong>"%1s"</strong> field is empty!', 'permalink-manager' ), $find_and_replace_fields[$key]['label'] ) . '</p>';
403
- }
404
-
405
- // Save the rows before they are updated to an array
406
- $posts_to_update = $wpdb->get_results("SELECT post_title, post_name, ID FROM {$wpdb->posts} WHERE post_status IN ('{$var['post_statuses']}') AND post_name LIKE '%{$var['old_string']}%' AND post_type IN ('{$var['post_types']}')", ARRAY_A);
407
-
408
- // Now if the array is not empty use IDs from each subarray as a key
409
- if($posts_to_update && empty($errors)) {
410
- foreach ($posts_to_update as $row) {
411
- // Get new slug
412
- $old_slug = $row['post_name'];
413
- $new_slug = str_replace($var['old_string'], $var['new_string'], $old_slug);
414
-
415
- // Update slugs
416
- Permalink_Manager_Helper_Functions::update_slug_by_id($new_slug, $row['ID']);
417
-
418
- $updated_array[] = array('post_title' => $row['post_title'], 'old_slug' => $old_slug, 'new_slug' => $new_slug);
419
- $updated_slugs_count++;
420
-
421
- // Reset slug
422
- $slug = '';
423
- }
424
- } else {
425
- $alert_type = 'error';
426
- $alert_content = $errors;
427
- }
428
-
429
- } else if (isset($_POST['regenerate-button'])) {
430
-
431
- // Setup needed variables
432
- $post_types_array = ($_POST['permalink-manager']['regenerate_slugs']['post_types']);
433
- $post_statuses_array = ($_POST['permalink-manager']['regenerate_slugs']['post_statuses']);
434
-
435
- // Reset query
436
- $reset_query = new WP_Query( array( 'post_type' => $post_types_array, 'post_status' => $post_statuses_array, 'posts_per_page' => -1 ) );
437
-
438
- // The Loop
439
- if ( $reset_query->have_posts() ) {
440
- while ( $reset_query->have_posts() ) {
441
- $reset_query->the_post();
442
- $this_post = get_post(get_the_ID());
443
-
444
- $correct_slug = sanitize_title(get_the_title());
445
- $old_slug = $this_post->post_name;
446
- $new_slug = wp_unique_post_slug($correct_slug, get_the_ID(), get_post_status(get_the_ID()), get_post_type(get_the_ID()), null);
447
-
448
- if($old_slug != $new_slug) {
449
- $updated_slugs_count++;
450
-
451
- Permalink_Manager_Helper_Functions::update_slug_by_id($new_slug, get_the_ID());
452
- $updated_array[] = array('post_title' => get_the_title(), 'old_slug' => $old_slug, 'new_slug' => $new_slug);
453
- }
454
- }
455
- }
456
-
457
- // Restore original Post Data
458
- wp_reset_postdata();
459
-
460
- // Save Permalink Structures/Permalinks Bases
461
- } else if (isset($_POST['save_permalink_structures'])) {
462
- Permalink_Manager_Helper_Functions::save_option('base-editor', $_POST['permalink-manager']['base-editor']);
463
-
464
- $alert_type = 'updated';
465
- $alert_content = sprintf( __( '<a href="%s">Click here</a> to flush the rewrite rules (it is required to make the new permalinks working).', 'permalink-manager' ), admin_url('admin.php?page=' . PERMALINK_MANAGER_PLUGIN_NAME . '.php&flush_rewrite_rules=true&tab=base_editor'));
466
- Permalink_Manager_Helper_Functions::display_alert($alert_content, $alert_type, true);
467
- return;
468
- // Flush rewrite rules
469
- } else if (isset($_POST['flush_rewrite_rules'])) {
470
- $this->flush_rewrite_rules();
471
- return;
472
- }
473
-
474
- /**
475
- * Display results
476
- */
477
- if((isset($_POST['permalink-manager']) || isset($_POST['update_all_slugs'])) && !(isset($_POST['screen-options-apply']))) {
478
- // Display errors or success message
479
-
480
- // Check how many rows/slugs were affected
481
- if($updated_slugs_count > 0) {
482
- $alert_type = 'updated';
483
- $alert_content = sprintf( _n( '<strong>%d</strong> slug were updated!', '<strong>%d</strong> slugs were updated!', $updated_slugs_count, 'permalink-manager' ), $updated_slugs_count ) . ' ';
484
- $alert_content .= sprintf( __( '<a href="%s">Click here</a> to go to the list of updated slugs', 'permalink-manager' ), '#updated-list');
485
- } else {
486
- $alert_type = 'error';
487
- $alert_content = ($alert_content) ? $alert_content : __( '<strong>No slugs</strong> were updated!', 'permalink-manager' );
488
- }
489
-
490
- Permalink_Manager_Helper_Functions::display_alert($alert_content, $alert_type, true);
491
-
492
- // Display summary after update
493
- // Display only if there are any slugs updated
494
- if ( $updated_slugs_count > 0 && $updated_array ) {
495
- add_filter('permalink-manager-after-tabs', function( $arg ) use ( $alert_content, $alert_type, $errors, $updated_array, $main_content ) {
496
-
497
- $header_footer = '<tr>';
498
- $header_footer .= '<th class="column-primary">' . __('Title', 'permalink-manager') . '</th>';
499
- $header_footer .= '<th>' . __('Old slug', 'permalink-manager') . '</th>';
500
- $header_footer .= '<th>' . __('New slug', 'permalink-manager') . '</th>';
501
- $header_footer .= '</tr>';
502
-
503
- $updated_slugs_count = 0;
504
- foreach($updated_array as $row) {
505
- // Odd/even class
506
- $updated_slugs_count++;
507
- $alternate_class = ($updated_slugs_count % 2 == 1) ? ' class="alternate"' : '';
508
-
509
- $main_content .= "<tr{$alternate_class}>";
510
- $main_content .= '<td class="row-title column-primary" data-colname="' . __('Title', 'permalink-manager') . '">' . $row['post_title'] . '<button type="button" class="toggle-row"><span class="screen-reader-text">' . __('Show more details', 'permalink-manager') . '</span></button></td>';
511
- $main_content .= '<td data-colname="' . __('Old slug', 'permalink-manager') . '">' . $row['old_slug'] . '</td>';
512
- $main_content .= '<td data-colname="' . __('New slug', 'permalink-manager') . '">' . $row['new_slug'] . '</td>';
513
- $main_content .= '</tr>';
514
- }
515
-
516
- // Merge header, footer and content
517
- $output = '<h3 id="updated-list">' . __('List of updated posts', 'permalink-manager') . '</h3>';
518
- $output .= '<table class="widefat wp-list-table">';
519
- $output .= "<thead>{$header_footer}</thead><tbody>{$main_content}</tbody><tfoot>{$header_footer}</tfoot>";
520
- $output .= '</table>';
521
-
522
- return $output ;
523
-
524
- });
525
- }
526
- }
527
- }
528
-
529
- /**
530
- * Change permalinks for posts, pages & custom post types
531
- */
532
- function custom_permalinks($permalink, $post) {
533
- $post = (is_integer($post)) ? get_post($post) : $post;
534
- $post_type = $post->post_type;
535
- $permastruct = isset($this->permalink_manager_options['base-editor'][$post_type]) ? $this->permalink_manager_options['base-editor'][$post_type] : '';
536
-
537
- // Ignore empty permastructures (do not change them)
538
- if(empty($permastruct) || $post->post_status != 'publish') return $permalink;
539
-
540
- // Get options
541
- if($permastruct) {
542
- $permalink = home_url() . "/" . trim($permastruct, '/');
543
- }
544
-
545
- /**
546
- * Replace Structure Tags
547
- */
548
-
549
- // Get the date
550
- $date = explode(" ",date('Y m d H i s', strtotime($post->post_date)));
551
-
552
- // Get the category (if needed)
553
- $category = '';
554
- if ( strpos($permalink, '%category%') !== false ) {
555
- $cats = get_the_category($post->ID);
556
- if ( $cats ) {
557
- usort($cats, '_usort_terms_by_ID'); // order by ID
558
- $category_object = apply_filters( 'post_link_category', $cats[0], $cats, $post );
559
- $category_object = get_term( $category_object, 'category' );
560
- $category = $category_object->slug;
561
- if ( $parent = $category_object->parent )
562
- $category = get_category_parents($parent, false, '/', true) . $category;
563
- }
564
- // show default category in permalinks, without having to assign it explicitly
565
- if ( empty($category) ) {
566
- $default_category = get_term( get_option( 'default_category' ), 'category' );
567
- $category = is_wp_error( $default_category ) ? '' : $default_category->slug;
568
- }
569
- }
570
-
571
- // Get the author (if needed)
572
- $author = '';
573
- if ( strpos($permalink, '%author%') !== false ) {
574
- $authordata = get_userdata($post->post_author);
575
- $author = $authordata->user_nicename;
576
- }
577
-
578
- // Fix for hierarchical CPT (start)
579
- $full_slug = get_page_uri($post);
580
- $post_type_tag = Permalink_Manager_Helper_Functions::get_post_tag($post_type);
581
-
582
- // Do the replacement (post tag is removed now to enable support for hierarchical CPT)
583
- $tags = array('%year%', '%monthnum%', '%day%', '%hour%', '%minute%', '%second%', '%post_id%', '%category%', '%author%', $post_type_tag);
584
- $replacements = array($date[0], $date[1], $date[2], $date[3], $date[4], $date[5], $post->ID, $category, $author, '');
585
-
586
- return str_replace($tags, $replacements, "{$permalink}{$full_slug}");
587
- }
588
-
589
- /**
590
- * Add rewrite rules
591
- */
592
- function custom_cpt_rewrite_rules($rules) {
593
-
594
- global $wp_rewrite;
595
-
596
- $new_rules = array();
597
- $permastructures = $this->permalink_manager_options['base-editor'];
598
-
599
- // Rewrite rules for Posts & Pages are defined in different filters
600
- unset($permastructures['post'], $permastructures['page']);
601
-
602
- foreach($permastructures as $post_type => $permastruct) {
603
- // Ignore empty permastructures (do not add them)
604
- if(empty($permastruct)) continue;
605
-
606
- $new_rule = $wp_rewrite->generate_rewrite_rules($wp_rewrite->root . $permastruct, EP_PERMALINK);
607
- $rules = array_merge($new_rule, $rules);
608
- }
609
- return $rules;
610
- }
611
-
612
- /**
613
- * Post Rewrite Rules
614
- */
615
- function custom_post_rewrite_rules($rules) {
616
- global $wp_rewrite;
617
- if(isset($this->permalink_manager_options['base-editor']['post'])) {
618
- $rules = $wp_rewrite->generate_rewrite_rules($wp_rewrite->root . $this->permalink_manager_options['base-editor']['post'], EP_PERMALINK);
619
- }
620
- return $rules;
621
- }
622
-
623
- /**
624
- * Page Rewrite Rules
625
- */
626
- function custom_page_rewrite_rules($rules) {
627
- global $wp_rewrite;
628
- if(isset($this->permalink_manager_options['base-editor']['page'])) {
629
- $rules = $wp_rewrite->generate_rewrite_rules($wp_rewrite->root . $this->permalink_manager_options['base-editor']['page'], EP_PERMALINK);
630
- }
631
- return $rules;
632
- }
633
-
634
- /**
635
- * Flush rewrite rules
636
- */
637
- function flush_rewrite_rules() {
638
- if(isset($_REQUEST['flush_rewrite_rules'])) {
639
- flush_rewrite_rules();
640
-
641
- $alert_type = 'updated';
642
- $alert_content = __( 'The rewrite rules are flushed!', 'permalink-manager' );
643
- return Permalink_Manager_Helper_Functions::display_alert($alert_content, $alert_type, true);
644
- }
645
- }
646
-
647
- }
648
-
649
- /**
650
- * Begins execution of the plugin.
651
- */
652
- function run_permalink_manager() {
653
-
654
- // Load plugin files.
655
- require_once PERMALINK_MANAGER_DIR . '/inc/permalink-manager-slug-editor.php';
656
- require_once PERMALINK_MANAGER_DIR . '/inc/permalink-manager-base-editor.php';
657
- require_once PERMALINK_MANAGER_DIR . '/inc/permalink-manager-screen-options.php';
658
- require_once PERMALINK_MANAGER_DIR . '/inc/permalink-manager-helper-functions.php';
659
-
660
- $Permalink_Manager_Class = new Permalink_Manager_Class();
661
- $Permalink_Manager_Screen_Options = new Permalink_Manager_Screen_Options();
662
-
663
- }
664
-
665
- run_permalink_manager();
 
1
+ <?php
2
+
3
+ /**
4
+ * Plugin Name: Permalink Manager
5
+ * Plugin URI: http://maciejbis.net/
6
+ * Description: A simple tool that allows to mass update of slugs that are used to build permalinks for Posts, Pages and Custom Post Types.
7
+ * Version: 0.3.3
8
+ * Author: Maciej Bis
9
+ * Author URI: http://maciejbis.net/
10
+ * License: GPL-2.0+
11
+ * License URI: http://www.gnu.org/licenses/gpl-2.0.txt
12
+ * Text Domain: permalink-manager
13
+ * Domain Path: /languages
14
+ */
15
+
16
+ // If this file is called directly, abort.
17
+ if ( ! defined( 'WPINC' ) ) {
18
+ die;
19
+ }
20
+
21
+ // Define the directories used to load plugin files.
22
+ define( 'PERMALINK_MANAGER_PLUGIN_NAME', 'permalink-manager' );
23
+ define( 'PERMALINK_MANAGER_VERSION', '0.3.3' );
24
+ define( 'PERMALINK_MANAGER_DIR', untrailingslashit( dirname( __FILE__ ) ) );
25
+ define( 'PERMALINK_MANAGER_URL', untrailingslashit( plugins_url( '', __FILE__ ) ) );
26
+ define( 'PERMALINK_MANAGER_WEBSITE', 'http://maciejbis.net' );
27
+ define( 'PERMALINK_MANAGER_MENU_PAGE', 'tools_page_permalink-manager' );
28
+ define( 'PERMALINK_MANAGER_OPTIONS_PAGE', PERMALINK_MANAGER_PLUGIN_NAME . '.php' );
29
+
30
+ class Permalink_Manager_Class {
31
+
32
+ protected $permalink_manager, $admin_page, $permalink_manager_options_page, $permalink_manager_options;
33
+
34
+ public function __construct() {
35
+
36
+ $this->permalink_manager_options = get_option('permalink-manager');
37
+
38
+ if( is_admin() ) {
39
+ add_action( 'plugins_loaded', array($this, 'localize_me') );
40
+ add_action( 'init', array($this, 'flush_rewrite_rules') );
41
+ add_action( 'admin_init', array($this, 'bulk_actions') );
42
+ add_action( 'admin_menu', array($this, 'add_menu_page') );
43
+ add_filter( 'plugin_action_links_' . plugin_basename(__FILE__), array($this, 'plugins_page_links') );
44
+
45
+ add_filter( 'page_rewrite_rules', array($this, 'custom_page_rewrite_rules'), 999, 1);
46
+ add_filter( 'post_rewrite_rules', array($this, 'custom_post_rewrite_rules'), 999, 1);
47
+ add_filter( 'rewrite_rules_array', array($this, 'custom_cpt_rewrite_rules'), 999, 1);
48
+ }
49
+
50
+ // Public functions
51
+ add_filter( '_get_page_link', array($this, 'custom_permalinks'), 999, 2);
52
+ add_filter( 'page_link', array($this, 'custom_permalinks'), 999, 2);
53
+ add_filter( 'post_link', array($this, 'custom_permalinks'), 999, 2);
54
+ add_filter( 'post_type_link', array($this, 'custom_permalinks'), 999, 2);
55
+
56
+ }
57
+
58
+ /**
59
+ * Localize this plugin
60
+ */
61
+ function localize_me() {
62
+ load_plugin_textdomain( 'permalink-manager', false, PERMALINK_MANAGER_DIR );
63
+ }
64
+
65
+ /**
66
+ * Add menu page and load CSS & JS.
67
+ */
68
+ function add_menu_page() {
69
+ add_management_page( __('Permalink Manager', 'permalink-manager'), __('Permalink Manager', 'permalink-manager'), 'manage_options', PERMALINK_MANAGER_OPTIONS_PAGE, array($this, 'list_slugs_admin_page') );
70
+
71
+ // Make sure thata the CSS and JS files are loaded only on plugin admin page.
72
+ add_action( 'admin_print_scripts-' . PERMALINK_MANAGER_MENU_PAGE, array($this, 'enqueue_styles' ) );
73
+ add_action( 'admin_print_scripts-' . PERMALINK_MANAGER_MENU_PAGE, array($this, 'enqueue_scripts' ) );
74
+ }
75
+
76
+ /**
77
+ * Display the table with slugs.
78
+ */
79
+ function slug_editor_html() {
80
+ global $wpdb;
81
+
82
+ $Permalink_Manager_Slug_Editor = new Permalink_Manager_Slug_Editor();
83
+ $Permalink_Manager_Slug_Editor->set_screen_option_fields($this->fields_arrays('screen_options'));
84
+ $Permalink_Manager_Slug_Editor->prepare_items($wpdb->posts);
85
+
86
+ ?>
87
+
88
+ <form id="permalinks-table" method="post">
89
+ <input type="hidden" name="tab" value="slug_editor" />
90
+ <?php echo $Permalink_Manager_Slug_Editor->display(); ?>
91
+ </form>
92
+ <?php
93
+ }
94
+
95
+ /**
96
+ * Mass replace options page.
97
+ */
98
+ function find_and_replace_html() {
99
+ $button = get_submit_button( __( 'Find & Replace', 'permalink-manager' ), 'primary', 'find-replace-button', false );
100
+
101
+ $return = "<form id=\"permalinks-table-find-replace\" method=\"post\">";
102
+ $return .= "<input type=\"hidden\" name=\"tab\" value=\"find_and_replace\" />";
103
+ $return .= "<table class=\"form-table\">";
104
+
105
+ foreach($this->fields_arrays('find_and_replace') as $field_name => $field_args) {
106
+ $return .= Permalink_Manager_Helper_Functions::generate_option_field($field_name, $field_args, 'find-replace');
107
+ }
108
+
109
+ $return .= "</table>{$button}";
110
+ $return .= "</form>";
111
+
112
+ echo $return;
113
+ }
114
+
115
+ /**
116
+ * Reset slugs page.
117
+ */
118
+ function regenerate_slugs_html() {
119
+ $button = get_submit_button( __( 'Regenerate', 'permalink-manager' ), 'primary', 'regenerate-button', false );
120
+
121
+ $return = "<form id=\"permalinks-table-regenerate\" method=\"post\">";
122
+ $return .= "<input type=\"hidden\" name=\"tab\" value=\"regenerate_slugs\" />";
123
+ $return .= "<table class=\"form-table\">";
124
+
125
+ foreach($this->fields_arrays('regenerate_slugs') as $field_name => $field_args) {
126
+ $return .= Permalink_Manager_Helper_Functions::generate_option_field($field_name, $field_args, 'regenerate_slugs');
127
+ }
128
+
129
+ $return .= "</table>{$button}";
130
+ $return .= "</form>";
131
+
132
+ echo $return;
133
+ }
134
+
135
+ /**
136
+ * Permalink Base Editor
137
+ */
138
+ function base_editor_html() {
139
+ global $wpdb, $wp_rewrite;
140
+
141
+ $Permalink_Manager_Base_Editor = new Permalink_Manager_Base_Editor();
142
+ $Permalink_Manager_Base_Editor->set_screen_option_fields($this->fields_arrays('screen_options'));
143
+ $Permalink_Manager_Base_Editor->prepare_items($wpdb->posts);
144
+
145
+ //echo '<pre>';
146
+ //print_r($wp_rewrite);
147
+ //echo '</pre>';
148
+
149
+ ?>
150
+
151
+ <form id="permalinks-base-table" method="post">
152
+ <input type="hidden" name="tab" value="base_editor" />
153
+ <?php echo $Permalink_Manager_Base_Editor->display(); ?>
154
+ </form>
155
+ <?php
156
+ }
157
+
158
+ /**
159
+ * Display the plugin dashboard.
160
+ */
161
+ function list_slugs_admin_page() {
162
+ global $wpdb;
163
+
164
+ // Check which tab is active now.
165
+ if(isset($_POST['tab'])) {
166
+ $active_tab = $_POST['tab'];
167
+ } else if(isset($_GET['tab'])) {
168
+ $active_tab = $_GET['tab'];
169
+ } else {
170
+ $active_tab = 'slug_editor';
171
+ }
172
+
173
+ // Tabs array with assigned functions used to display HTML content.
174
+ $tabs = array(
175
+ 'slug_editor' => array(
176
+ 'name' => __('Slug Editor', 'permalink-manager'),
177
+ 'function' => 'slug_editor_html',
178
+ 'description' => __('You can disable/enable selected post types from the table below using <strong>"Screen Options"</strong> (click on the upper-right button to show it) section above.', 'permalink-manager')
179
+ ),
180
+ 'find_and_replace' => array(
181
+ 'name' => __('Find and replace', 'permalink-manager'),
182
+ 'function' => 'find_and_replace_html',
183
+ 'warning' => (__('<strong>You are doing it at your own risk!</strong>', 'permalink-manager') . '<br />' . __('A backup of MySQL database before using this tool is highly recommended. The search & replace operation might be not revertible!', 'permalink-manager'))
184
+ ),
185
+ 'regenerate_slugs' => array(
186
+ 'name' => __('Regenerate slugs', 'permalink-manager'),
187
+ 'function' => 'regenerate_slugs_html',
188
+ 'warning' => (__('<strong>You are doing it at your own risk!</strong>', 'permalink-manager') . '<br />' . __('A backup of MySQL database before using this tool is highly recommended. The regenerate process of slugs might be not revertible!', 'permalink-manager'))
189
+ ),
190
+ 'base_editor' => array(
191
+ 'name' => __('Permalinks Base Editor', 'permalink-manager'),
192
+ 'function' => 'base_editor_html',
193
+ 'warning' => array(
194
+ sprintf(__('<strong>This is an experimental feature!</strong> Please report all the bugs & issues <a href="%s">here</a>.', 'permalink-manager'), 'https://wordpress.org/support/plugin/permalink-manager'),
195
+ __('Custom Post Types should have their own, unique front, eg. <em>products/%product%!</em>', 'permalink-manager'),
196
+ __('After you update & save the settings below, you need to flush the rewrite rules!', 'permalink-manager'),
197
+ ),
198
+ 'description' => (sprintf( __('All the <a href="%s" target="_blank">Structure Tags</a> allowed are listed below. Please note that some of them can be used only for particular Post Types.', 'permalink-manager'), "https://codex.wordpress.org/Using_Permalinks#Structure_Tags") . "<br />" . Permalink_Manager_Helper_Functions::get_all_structure_tags())
199
+ ),
200
+ );
201
+
202
+ ?>
203
+ <div id="permalinks-table-wrap" class="wrap">
204
+
205
+ <?php
206
+ // Display alerts and another content if needed
207
+ echo apply_filters('permalink-manager-before-tabs','');
208
+ ?>
209
+
210
+ <div id="icon-themes" class="icon32"></div>
211
+ <h2 id="plugin-name-heading"><?php _e('Permalink Manager', 'permalink-manager'); ?> <a href="<?php echo PERMALINK_MANAGER_WEBSITE; ?>" target="_blank"><?php _e('by Maciej Bis', 'permalink-manager'); ?></a></h2>
212
+
213
+ <h2 id="permalink-manager-tabs-nav" class="nav-tab-wrapper">
214
+ <?php
215
+ foreach($tabs as $tab_id => $tab_properties) {
216
+ $active_class = ($active_tab === $tab_id) ? 'nav-tab-active nav-tab' : 'nav-tab';
217
+ echo '<a data-tab="' . $tab_id . '" href="' . admin_url('admin.php?page=' . PERMALINK_MANAGER_PLUGIN_NAME . '.php&tab=' . $tab_id) . '" class="' . $active_class . '">' . $tab_properties['name'] . '</a>';
218
+ } ?>
219
+ </h2>
220
+
221
+ <div id="permalink-manager-tabs">
222
+ <?php
223
+ foreach($tabs as $tab_id => $tab_properties) {
224
+ $active_show = ($active_tab === $tab_id) ? 'show' : '';
225
+
226
+ // Prepare warning & description texts
227
+ $warning = (isset($tab_properties['warning'])) ? $tab_properties['warning'] : '';
228
+ $description = (isset($tab_properties['description'])) ? $tab_properties['description'] : '';
229
+
230
+ if(is_array($warning)) {
231
+ $warning = "<ol>"; // Overwrite the variable
232
+ foreach($tab_properties['warning'] as $point) { $warning .= "<li>{$point}</li>"; }
233
+ $warning .= "</ol>";
234
+ }
235
+
236
+ if(is_array($description)) {
237
+ $description = "<ol>"; // Overwrite the variable
238
+ foreach($tab_properties['description'] as $point) { $description .= "<li>{$point}</li>"; }
239
+ $description .= "</ol>";
240
+ }
241
+
242
+ echo '<div data-tab="' . $tab_id . '" id="' . $tab_id . '" class="' . $active_show . '">';
243
+ echo ($warning) ? "<div class=\"warning alert\">" . wpautop($warning) . "</div>" : "";
244
+ echo (isset($tab_properties['description'])) ? "<div class=\"info alert\">" . wpautop($description) . "</div>" : "";
245
+ $function_name = $tab_properties['function'];
246
+ $this->$function_name();
247
+ echo '</div>';
248
+ } ?>
249
+ </div>
250
+
251
+ <?php
252
+ // Display alerts and another content if needed
253
+ echo apply_filters('permalink-manager-after-tabs','');
254
+ ?>
255
+
256
+ </div>
257
+ <?php
258
+ }
259
+
260
+ /**
261
+ * Register the stylesheets for the Dashboard.
262
+ */
263
+ function enqueue_styles() {
264
+ wp_enqueue_style( PERMALINK_MANAGER_PLUGIN_NAME, PERMALINK_MANAGER_URL . '/css/permalink-manager-admin.css', array(), PERMALINK_MANAGER_VERSION, 'all' );
265
+ }
266
+
267
+ /**
268
+ * Register the JavaScript for the dashboard.
269
+ */
270
+ function enqueue_scripts() {
271
+ wp_enqueue_script( PERMALINK_MANAGER_PLUGIN_NAME, PERMALINK_MANAGER_URL . '/js/permalink-manager-admin.js', array( 'jquery' ), PERMALINK_MANAGER_VERSION, false );
272
+ }
273
+
274
+ /**
275
+ * Additional links on "Plugins" page
276
+ */
277
+ function plugins_page_links( $links ) {
278
+ $links[] = '<a href="' . esc_url( get_admin_url(null, "tools.php?page=" . PERMALINK_MANAGER_OPTIONS_PAGE) ) .'">' . __( 'Go To Permalink Manager', 'permalink-manager' ) . '</a>';
279
+ return $links;
280
+ }
281
+
282
+ /**
283
+ * Fields for "Screen Options"
284
+ */
285
+ function fields_arrays($array) {
286
+
287
+ // All registered post types array
288
+ $all_post_statuses_array = get_post_statuses();
289
+ $all_post_types = Permalink_Manager_Helper_Functions::get_post_types_array();
290
+
291
+ // Fields for "Screen Options"
292
+ $screen_options = array(
293
+ 'post_types' => array(
294
+ 'label' => __( 'Post Types', 'permalink-manager' ),
295
+ 'type' => 'checkbox',
296
+ 'choices' => array_merge(array('all' => '<strong>' . __('All Post Types', 'permalink-manager') . '</strong>'), $all_post_types),
297
+ 'default' => array('post', 'page')
298
+ ),
299
+ 'post_statuses' => array(
300
+ 'label' => __( 'Post Statuses', 'permalink-manager' ),
301
+ 'type' => 'checkbox',
302
+ 'choices' => array_merge(array('all' => '<strong>' . __('All Post Statuses', 'permalink-manager') . '</strong>'), $all_post_statuses_array),
303
+ 'default' => array('publish')
304
+ ),
305
+ 'per_page' => array(
306
+ 'label' => __( 'Per page', 'permalink-manager' ),
307
+ 'type' => 'number',
308
+ 'default' => 10
309
+ )
310
+ );
311
+
312
+ // Fields for "Find and replace"
313
+ $find_and_replace = array(
314
+ 'old_string' => array(
315
+ 'label' => __( 'Find ...', 'permalink-manager' ),
316
+ 'type' => 'text',
317
+ ),
318
+ 'new_string' => array(
319
+ 'label' => __( 'Replace with ...', 'permalink-manager' ),
320
+ 'type' => 'text',
321
+ ),
322
+ 'post_types' => array(
323
+ 'label' => __( 'Post Types that should be affected', 'permalink-manager' ),
324
+ 'type' => 'checkbox',
325
+ 'choices' => array_merge(array('all' => '<strong>' . __('All Post Types', 'permalink-manager') . '</strong>'), $all_post_types),
326
+ 'default' => array('post', 'page')
327
+ ),
328
+ 'post_statuses' => array(
329
+ 'label' => __( 'Post Statuses that should be affected', 'permalink-manager' ),
330
+ 'type' => 'checkbox',
331
+ 'choices' => array_merge(array('all' => '<strong>' . __('All Post Statuses', 'permalink-manager') . '</strong>'), $all_post_statuses_array),
332
+ 'default' => array('publish')
333
+ )
334
+ );
335
+
336
+ // Fields for "Regenerate slugs"
337
+ $regenerate_slugs = array(
338
+ 'post_types' => array(
339
+ 'label' => __( 'Post Types that should be affected', 'permalink-manager' ),
340
+ 'type' => 'checkbox',
341
+ 'choices' => array_merge(array('all' => '<strong>' . __('All Post Types', 'permalink-manager') . '</strong>'), $all_post_types),
342
+ 'default' => array('post', 'page')
343
+ ),
344
+ 'post_statuses' => array(
345
+ 'label' => __( 'Post Statuses that should be affected', 'permalink-manager' ),
346
+ 'type' => 'checkbox',
347
+ 'choices' => array_merge(array('all' => '<strong>' . __('All Post Statuses', 'permalink-manager') . '</strong>'), $all_post_statuses_array),
348
+ 'default' => array('publish')
349
+ )
350
+ );
351
+
352
+ return isset($array) ? ${$array} : array();
353
+
354
+ }
355
+
356
+ /**
357
+ * Bulk actions functions
358
+ */
359
+ function bulk_actions() {
360
+ global $wpdb;
361
+
362
+ $updated_slugs_count = 0;
363
+ $updated_array = array();
364
+ $alert_type = $alert_content = $errors = $main_content = '';
365
+
366
+ if (isset($_POST['update_all_slugs'])) {
367
+
368
+ $slugs = isset($_POST['slug']) ? $_POST['slug'] : array();
369
+
370
+ // Double check if the slugs and ids are stored in arrays
371
+ if (!is_array($slugs)) $slugs = explode(',', $slugs);
372
+
373
+ if (!empty($slugs)) {
374
+ foreach($slugs as $id => $new_slug) {
375
+ $this_post = get_post($id);
376
+
377
+ // Check if slug was changed
378
+ if($this_post->post_name != $new_slug) {
379
+ // Update slugs
380
+ Permalink_Manager_Helper_Functions::update_slug_by_id($new_slug, $id);
381
+
382
+ $updated_array[] = array('post_title' => get_the_title($id), 'old_slug' => $this_post->post_name, 'new_slug' => $new_slug);
383
+ $updated_slugs_count++;
384
+ }
385
+
386
+ // Reset slug
387
+ $slug = '';
388
+ }
389
+ }
390
+
391
+ } else if (isset($_POST['find-replace-button'])) {
392
+
393
+ $var['old_string'] = esc_sql($_POST['permalink-manager']['find-replace']['old_string']);
394
+ $var['new_string'] = esc_sql($_POST['permalink-manager']['find-replace']['new_string']);
395
+ $post_types_array = ($_POST['permalink-manager']['find-replace']['post_types']);
396
+ $post_statuses_array = ($_POST['permalink-manager']['find-replace']['post_statuses']);
397
+ $var['post_types'] = implode("', '", $post_types_array);
398
+ $var['post_statuses'] = implode("', '", $post_statuses_array);
399
+
400
+ // Check if any of variables is not empty
401
+ $find_and_replace_fields = $this->fields_arrays('find_and_replace');
402
+ foreach($var as $key => $val) {
403
+ if(empty($val)) $errors .= '<p>' . sprintf( __( '<strong>"%1s"</strong> field is empty!', 'permalink-manager' ), $find_and_replace_fields[$key]['label'] ) . '</p>';
404
+ }
405
+
406
+ // Save the rows before they are updated to an array
407
+ $posts_to_update = $wpdb->get_results("SELECT post_title, post_name, ID FROM {$wpdb->posts} WHERE post_status IN ('{$var['post_statuses']}') AND post_name LIKE '%{$var['old_string']}%' AND post_type IN ('{$var['post_types']}')", ARRAY_A);
408
+
409
+ // Now if the array is not empty use IDs from each subarray as a key
410
+ if($posts_to_update && empty($errors)) {
411
+ foreach ($posts_to_update as $row) {
412
+ // Get new slug
413
+ $old_slug = $row['post_name'];
414
+ $new_slug = str_replace($var['old_string'], $var['new_string'], $old_slug);
415
+
416
+ // Update slugs
417
+ Permalink_Manager_Helper_Functions::update_slug_by_id($new_slug, $row['ID']);
418
+
419
+ $updated_array[] = array('post_title' => $row['post_title'], 'old_slug' => $old_slug, 'new_slug' => $new_slug);
420
+ $updated_slugs_count++;
421
+
422
+ // Reset slug
423
+ $slug = '';
424
+ }
425
+ } else {
426
+ $alert_type = 'error';
427
+ $alert_content = $errors;
428
+ }
429
+
430
+ } else if (isset($_POST['regenerate-button'])) {
431
+
432
+ // Setup needed variables
433
+ $post_types_array = ($_POST['permalink-manager']['regenerate_slugs']['post_types']);
434
+ $post_statuses_array = ($_POST['permalink-manager']['regenerate_slugs']['post_statuses']);
435
+
436
+ // Reset query
437
+ $reset_query = new WP_Query( array( 'post_type' => $post_types_array, 'post_status' => $post_statuses_array, 'posts_per_page' => -1 ) );
438
+
439
+ // The Loop
440
+ if ( $reset_query->have_posts() ) {
441
+ while ( $reset_query->have_posts() ) {
442
+ $reset_query->the_post();
443
+ $this_post = get_post(get_the_ID());
444
+
445
+ $correct_slug = sanitize_title(get_the_title());
446
+ $old_slug = $this_post->post_name;
447
+ $new_slug = wp_unique_post_slug($correct_slug, get_the_ID(), get_post_status(get_the_ID()), get_post_type(get_the_ID()), null);
448
+
449
+ if($old_slug != $new_slug) {
450
+ $updated_slugs_count++;
451
+
452
+ Permalink_Manager_Helper_Functions::update_slug_by_id($new_slug, get_the_ID());
453
+ $updated_array[] = array('post_title' => get_the_title(), 'old_slug' => $old_slug, 'new_slug' => $new_slug);
454
+ }
455
+ }
456
+ }
457
+
458
+ // Restore original Post Data
459
+ wp_reset_postdata();
460
+
461
+ // Save Permalink Structures/Permalinks Bases
462
+ } else if (isset($_POST['save_permalink_structures'])) {
463
+ Permalink_Manager_Helper_Functions::save_option('base-editor', $_POST['permalink-manager']['base-editor']);
464
+
465
+ $alert_type = 'updated';
466
+ $alert_content = sprintf( __( '<a href="%s">Click here</a> to flush the rewrite rules (it is required to make the new permalinks working).', 'permalink-manager' ), admin_url('admin.php?page=' . PERMALINK_MANAGER_PLUGIN_NAME . '.php&flush_rewrite_rules=true&tab=base_editor'));
467
+ Permalink_Manager_Helper_Functions::display_alert($alert_content, $alert_type, true);
468
+ return;
469
+ // Flush rewrite rules
470
+ } else if (isset($_POST['flush_rewrite_rules'])) {
471
+ $this->flush_rewrite_rules();
472
+ return;
473
+ }
474
+
475
+ /**
476
+ * Display results
477
+ */
478
+ if((isset($_POST['permalink-manager']) || isset($_POST['update_all_slugs'])) && !(isset($_POST['screen-options-apply']))) {
479
+ // Display errors or success message
480
+
481
+ // Check how many rows/slugs were affected
482
+ if($updated_slugs_count > 0) {
483
+ $alert_type = 'updated';
484
+ $alert_content = sprintf( _n( '<strong>%d</strong> slug were updated!', '<strong>%d</strong> slugs were updated!', $updated_slugs_count, 'permalink-manager' ), $updated_slugs_count ) . ' ';
485
+ $alert_content .= sprintf( __( '<a href="%s">Click here</a> to go to the list of updated slugs', 'permalink-manager' ), '#updated-list');
486
+ } else {
487
+ $alert_type = 'error';
488
+ $alert_content = ($alert_content) ? $alert_content : __( '<strong>No slugs</strong> were updated!', 'permalink-manager' );
489
+ }
490
+
491
+ Permalink_Manager_Helper_Functions::display_alert($alert_content, $alert_type, true);
492
+
493
+ // Display summary after update
494
+ // Display only if there are any slugs updated
495
+ if ( $updated_slugs_count > 0 && $updated_array ) {
496
+ add_filter('permalink-manager-after-tabs', function( $arg ) use ( $alert_content, $alert_type, $errors, $updated_array, $main_content ) {
497
+
498
+ $header_footer = '<tr>';
499
+ $header_footer .= '<th class="column-primary">' . __('Title', 'permalink-manager') . '</th>';
500
+ $header_footer .= '<th>' . __('Old slug', 'permalink-manager') . '</th>';
501
+ $header_footer .= '<th>' . __('New slug', 'permalink-manager') . '</th>';
502
+ $header_footer .= '</tr>';
503
+
504
+ $updated_slugs_count = 0;
505
+ foreach($updated_array as $row) {
506
+ // Odd/even class
507
+ $updated_slugs_count++;
508
+ $alternate_class = ($updated_slugs_count % 2 == 1) ? ' class="alternate"' : '';
509
+
510
+ $main_content .= "<tr{$alternate_class}>";
511
+ $main_content .= '<td class="row-title column-primary" data-colname="' . __('Title', 'permalink-manager') . '">' . $row['post_title'] . '<button type="button" class="toggle-row"><span class="screen-reader-text">' . __('Show more details', 'permalink-manager') . '</span></button></td>';
512
+ $main_content .= '<td data-colname="' . __('Old slug', 'permalink-manager') . '">' . $row['old_slug'] . '</td>';
513
+ $main_content .= '<td data-colname="' . __('New slug', 'permalink-manager') . '">' . $row['new_slug'] . '</td>';
514
+ $main_content .= '</tr>';
515
+ }
516
+
517
+ // Merge header, footer and content
518
+ $output = '<h3 id="updated-list">' . __('List of updated posts', 'permalink-manager') . '</h3>';
519
+ $output .= '<table class="widefat wp-list-table">';
520
+ $output .= "<thead>{$header_footer}</thead><tbody>{$main_content}</tbody><tfoot>{$header_footer}</tfoot>";
521
+ $output .= '</table>';
522
+
523
+ return $output ;
524
+
525
+ });
526
+ }
527
+ }
528
+ }
529
+
530
+ /**
531
+ * Change permalinks for posts, pages & custom post types
532
+ */
533
+ function custom_permalinks($permalink, $post) {
534
+ $post = (is_integer($post)) ? get_post($post) : $post;
535
+ $post_type = $post->post_type;
536
+ $permastruct = isset($this->permalink_manager_options['base-editor'][$post_type]) ? $this->permalink_manager_options['base-editor'][$post_type] : '';
537
+
538
+ // Ignore empty permastructures (do not change them)
539
+ if(empty($permastruct) || $post->post_status != 'publish') return $permalink;
540
+
541
+ // Get options
542
+ if($permastruct) {
543
+ $permalink = home_url() . "/" . trim($permastruct, '/');
544
+ }
545
+
546
+ /**
547
+ * Replace Structure Tags
548
+ */
549
+
550
+ // Get the date
551
+ $date = explode(" ",date('Y m d H i s', strtotime($post->post_date)));
552
+
553
+ // Get the category (if needed)
554
+ $category = '';
555
+ if ( strpos($permalink, '%category%') !== false ) {
556
+ $cats = get_the_category($post->ID);
557
+ if ( $cats ) {
558
+ usort($cats, '_usort_terms_by_ID'); // order by ID
559
+ $category_object = apply_filters( 'post_link_category', $cats[0], $cats, $post );
560
+ $category_object = get_term( $category_object, 'category' );
561
+ $category = $category_object->slug;
562
+ if ( $parent = $category_object->parent )
563
+ $category = get_category_parents($parent, false, '/', true) . $category;
564
+ }
565
+ // show default category in permalinks, without having to assign it explicitly
566
+ if ( empty($category) ) {
567
+ $default_category = get_term( get_option( 'default_category' ), 'category' );
568
+ $category = is_wp_error( $default_category ) ? '' : $default_category->slug;
569
+ }
570
+ }
571
+
572
+ // Get the author (if needed)
573
+ $author = '';
574
+ if ( strpos($permalink, '%author%') !== false ) {
575
+ $authordata = get_userdata($post->post_author);
576
+ $author = $authordata->user_nicename;
577
+ }
578
+
579
+ // Fix for hierarchical CPT (start)
580
+ $full_slug = get_page_uri($post);
581
+ $post_type_tag = Permalink_Manager_Helper_Functions::get_post_tag($post_type);
582
+
583
+ // Do the replacement (post tag is removed now to enable support for hierarchical CPT)
584
+ $tags = array('%year%', '%monthnum%', '%day%', '%hour%', '%minute%', '%second%', '%post_id%', '%category%', '%author%', $post_type_tag);
585
+ $replacements = array($date[0], $date[1], $date[2], $date[3], $date[4], $date[5], $post->ID, $category, $author, '');
586
+
587
+ return str_replace($tags, $replacements, "{$permalink}{$full_slug}");
588
+ }
589
+
590
+ /**
591
+ * Add rewrite rules
592
+ */
593
+ function custom_cpt_rewrite_rules($rules) {
594
+
595
+ global $wp_rewrite;
596
+
597
+ $new_rules = array();
598
+ $permastructures = $this->permalink_manager_options['base-editor'];
599
+
600
+ // Rewrite rules for Posts & Pages are defined in different filters
601
+ unset($permastructures['post'], $permastructures['page']);
602
+
603
+ foreach($permastructures as $post_type => $permastruct) {
604
+ // Ignore empty permastructures (do not add them)
605
+ if(empty($permastruct)) continue;
606
+
607
+ $new_rule = $wp_rewrite->generate_rewrite_rules($wp_rewrite->root . $permastruct, EP_PERMALINK);
608
+ $rules = array_merge($new_rule, $rules);
609
+ }
610
+ return $rules;
611
+ }
612
+
613
+ /**
614
+ * Post Rewrite Rules
615
+ */
616
+ function custom_post_rewrite_rules($rules) {
617
+ global $wp_rewrite;
618
+ if(isset($this->permalink_manager_options['base-editor']['post'])) {
619
+ $rules = $wp_rewrite->generate_rewrite_rules($wp_rewrite->root . $this->permalink_manager_options['base-editor']['post'], EP_PERMALINK);
620
+ }
621
+ return $rules;
622
+ }
623
+
624
+ /**
625
+ * Page Rewrite Rules
626
+ */
627
+ function custom_page_rewrite_rules($rules) {
628
+ global $wp_rewrite;
629
+ if(isset($this->permalink_manager_options['base-editor']['page'])) {
630
+ $rules = $wp_rewrite->generate_rewrite_rules($wp_rewrite->root . $this->permalink_manager_options['base-editor']['page'], EP_PERMALINK);
631
+ }
632
+ return $rules;
633
+ }
634
+
635
+ /**
636
+ * Flush rewrite rules
637
+ */
638
+ function flush_rewrite_rules() {
639
+ if(isset($_REQUEST['flush_rewrite_rules'])) {
640
+ flush_rewrite_rules();
641
+
642
+ $alert_type = 'updated';
643
+ $alert_content = __( 'The rewrite rules are flushed!', 'permalink-manager' );
644
+ return Permalink_Manager_Helper_Functions::display_alert($alert_content, $alert_type, true);
645
+ }
646
+ }
647
+
648
+ }
649
+
650
+ /**
651
+ * Begins execution of the plugin.
652
+ */
653
+ function run_permalink_manager() {
654
+
655
+ // Load plugin files.
656
+ require_once PERMALINK_MANAGER_DIR . '/inc/permalink-manager-slug-editor.php';
657
+ require_once PERMALINK_MANAGER_DIR . '/inc/permalink-manager-base-editor.php';
658
+ require_once PERMALINK_MANAGER_DIR . '/inc/permalink-manager-screen-options.php';
659
+ require_once PERMALINK_MANAGER_DIR . '/inc/permalink-manager-helper-functions.php';
660
+
661
+ $Permalink_Manager_Class = new Permalink_Manager_Class();
662
+ $Permalink_Manager_Screen_Options = new Permalink_Manager_Screen_Options();
663
+
664
+ }
665
+
666
+ run_permalink_manager();