Link Juice Keeper - Version 2.0.0

Version Description

  • Major update - compatible with WP 5.7.x
  • Feature: Select Redirect Type (301, 302, 307)
  • Feature: Select Redirect Target (Home, Page, Post, URL)
  • Feature: Monitor/Log 404 errors
  • Feature: Send Email Alerts about 404
Download this release

Release Info

Developer pattihis
Plugin Icon 128x128 Link Juice Keeper
Version 2.0.0
Comparing to
See all releases

Code changes from version 1.2.3 to 2.0.0

LICENSE.txt ADDED
@@ -0,0 +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.
admin/class-link-juice-keeper-admin.php ADDED
@@ -0,0 +1,294 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * The admin-specific functionality of the plugin.
5
+ *
6
+ * @link https://profiles.wordpress.org/pattihis/
7
+ * @since 2.0.0
8
+ *
9
+ * @package Link_Juice_Keeper
10
+ * @subpackage Link_Juice_Keeper/admin
11
+ */
12
+
13
+ /**
14
+ * The admin-specific functionality of the plugin.
15
+ *
16
+ * Defines the plugin name, version, and two examples hooks for how to
17
+ * enqueue the admin-specific stylesheet and JavaScript.
18
+ *
19
+ * @package Link_Juice_Keeper
20
+ * @subpackage Link_Juice_Keeper/admin
21
+ * @author George Pattihis <gpattihis@gmail.com>
22
+ */
23
+ class Link_Juice_Keeper_Admin {
24
+
25
+ /**
26
+ * The ID of this plugin.
27
+ *
28
+ * @since 2.0.0
29
+ * @access private
30
+ * @var string $plugin_name The ID of this plugin.
31
+ */
32
+ private $plugin_name;
33
+
34
+ /**
35
+ * The version of this plugin.
36
+ *
37
+ * @since 2.0.0
38
+ * @access private
39
+ * @var string $version The current version of this plugin.
40
+ */
41
+ private $version;
42
+
43
+ /**
44
+ * Initialize the class and set its properties.
45
+ *
46
+ * @since 2.0.0
47
+ * @param string $plugin_name The name of this plugin.
48
+ * @param string $version The version of this plugin.
49
+ */
50
+ public function __construct( $plugin_name, $version ) {
51
+
52
+ $this->plugin_name = $plugin_name;
53
+ $this->version = $version;
54
+
55
+ }
56
+
57
+ /**
58
+ * Register the stylesheets for the admin area.
59
+ *
60
+ * @since 2.0.0
61
+ */
62
+ public function enqueue_styles() {
63
+
64
+ wp_enqueue_style( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'css/link-juice-keeper-admin.css', array(), $this->version, 'all' );
65
+
66
+ }
67
+
68
+ /**
69
+ * Register the JavaScript for the admin area.
70
+ *
71
+ * @since 2.0.0
72
+ */
73
+ public function enqueue_scripts() {
74
+
75
+ wp_enqueue_script( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'js/link-juice-keeper-admin.js', array( 'jquery' ), $this->version, false );
76
+
77
+ }
78
+
79
+ /**
80
+ * Register the admin menu
81
+ *
82
+ * @since 2.0.0
83
+ */
84
+ public function linkJuiceKeeper_admin_menu() {
85
+
86
+ add_menu_page(
87
+ __( 'Link Juice Keeper', 'link-juice-keeper' ),
88
+ __( 'Link Juice Keeper', 'link-juice-keeper' ),
89
+ 'manage_options',
90
+ $this->plugin_name,
91
+ [$this,'linkJuiceKeeper_admin_display'],
92
+ 'dashicons-editor-unlink',
93
+ 25
94
+ );
95
+
96
+ add_submenu_page( $this->plugin_name, __( 'Link Juice Keeper Settings', 'link-juice-keeper' ), __( 'Settings', 'link-juice-keeper' ), 'manage_options', $this->plugin_name, [$this,'linkJuiceKeeper_admin_display'], 0);
97
+ add_submenu_page( $this->plugin_name, __( '404 Logs', 'link-juice-keeper' ), __( '404 Logs', 'link-juice-keeper' ), 'manage_options', $this->plugin_name.'-404-logs', [$this,'linkJuiceKeeper_admin_display_logs'], 1);
98
+
99
+ }
100
+
101
+ /**
102
+ * Render the admin menu page content
103
+ *
104
+ * @since 2.0.0
105
+ */
106
+ public function linkJuiceKeeper_admin_display() {
107
+ include_once 'partials/link-juice-keeper-admin-display.php';
108
+ }
109
+
110
+ /**
111
+ * Render the logs page content
112
+ *
113
+ * @since 2.0.0
114
+ */
115
+ public function linkJuiceKeeper_admin_display_logs() {
116
+ include_once 'partials/link-juice-keeper-admin-display-logs.php';
117
+ }
118
+
119
+ /**
120
+ * Return the allowed status codes
121
+ *
122
+ * @since 2.0.0
123
+ * @return array Allowed HTTP status codes
124
+ */
125
+ public function linkJuiceKeeper_statuses() {
126
+
127
+ $statuses = array(
128
+ 301 => __( '301 Redirect (Permanent)', 'link-juice-keeper' ),
129
+ 302 => __( '302 Redirect (Found)', 'link-juice-keeper' ),
130
+ 307 => __( '307 Redirect (Temporary)', 'link-juice-keeper' ),
131
+ );
132
+
133
+ return (array) apply_filters( 'ljk_statuses', $statuses );
134
+ }
135
+
136
+ /**
137
+ * Get plugin settings value.
138
+ *
139
+ *
140
+ * @param mixed $option Option name.
141
+ * @param mixed $default Default value if not exist.
142
+ *
143
+ * @since 2.0.0
144
+ * @access public
145
+ *
146
+ * @return string|array
147
+ */
148
+ function linkJuiceKeeper_get_option( $option = false, $default = false ) {
149
+
150
+ if ( ! $option ) {
151
+ return $default;
152
+ }
153
+
154
+ // Get our plugin settings value.
155
+ $settings = (array) get_option( 'ljk_main_settings', array() );
156
+
157
+ // Return false, if not exist.
158
+ if ( empty( $settings[ $option ] ) ) {
159
+ return $default;
160
+ }
161
+
162
+ return $settings[ $option ];
163
+ }
164
+
165
+ /**
166
+ * Registering our settings options using WordPress settings API.
167
+ *
168
+ * @since 2.0.0
169
+ * @access public
170
+ * @uses hooks register_setting Hook to register options in db.
171
+ *
172
+ * @return void
173
+ */
174
+ public function register_settings() {
175
+
176
+ register_setting( 'ljk_main_settings', 'ljk_main_settings' );
177
+ }
178
+
179
+ /**
180
+ * Create dropdown HTML content of posts
181
+ *
182
+ * Supports all WP_Query arguments
183
+ * @see https://codex.wordpress.org/Class_Reference/WP_Query
184
+ *
185
+ * @since 2.0.0
186
+ *
187
+ * @param array|string $args Optional. Array or string of arguments to generate a drop-down of posts.
188
+ *
189
+ * @return string String of HTML content.
190
+ */
191
+ function wp_dropdown_posts( $args = '' ) {
192
+
193
+ $defaults = array(
194
+ 'selected' => FALSE,
195
+ 'pagination' => FALSE,
196
+ 'posts_per_page' => - 1,
197
+ 'post_status' => 'publish',
198
+ 'cache_results' => TRUE,
199
+ 'cache_post_meta_cache' => TRUE,
200
+ 'echo' => 1,
201
+ 'select_name' => 'post_id',
202
+ 'id' => '',
203
+ 'class' => '',
204
+ 'show' => 'post_title',
205
+ 'show_callback' => NULL,
206
+ 'show_option_all' => NULL,
207
+ 'show_option_none' => NULL,
208
+ 'option_none_value' => '',
209
+ 'multi' => FALSE,
210
+ 'value_field' => 'ID',
211
+ 'order' => 'ASC',
212
+ 'orderby' => 'post_title',
213
+ );
214
+
215
+ $r = wp_parse_args( $args, $defaults );
216
+
217
+ $posts = get_posts( $r );
218
+ $output = '';
219
+
220
+ $show = $r['show'];
221
+
222
+ if( ! empty($posts) ) {
223
+
224
+ $name = esc_attr( $r['select_name'] );
225
+
226
+ if( $r['multi'] && ! $r['id'] ) {
227
+ $id = '';
228
+ } else {
229
+ $id = $r['id'] ? " id='" . esc_attr( $r['id'] ) . "'" : " id='$name'";
230
+ }
231
+
232
+ $output = "<select name='{$name}'{$id} class='" . esc_attr( $r['class'] ) . "'>\n";
233
+
234
+ if( $r['show_option_all'] ) {
235
+ $output .= "\t<option value='0'>{$r['show_option_all']}</option>\n";
236
+ }
237
+
238
+ if( $r['show_option_none'] ) {
239
+ $_selected = selected( $r['show_option_none'], $r['selected'], FALSE );
240
+ $output .= "\t<option value='" . esc_attr( $r['option_none_value'] ) . "'$_selected>{$r['show_option_none']}</option>\n";
241
+ }
242
+
243
+ foreach( (array) $posts as $post ) {
244
+
245
+ $value = ! isset($r['value_field']) || ! isset($post->{$r['value_field']}) ? $post->ID : $post->{$r['value_field']};
246
+ $_selected = selected( $value, $r['selected'], FALSE );
247
+
248
+ $display = ! empty($post->$show) ? $post->$show : sprintf( __( '#%d (no title)' ), $post->ID );
249
+
250
+ if( $r['show_callback'] ) $display = call_user_func( $r['show_callback'], $display, $post->ID );
251
+
252
+ $output .= "\t<option value='{$value}'{$_selected}>" . esc_html( $display ) . "</option>\n";
253
+ }
254
+
255
+ $output .= "</select>";
256
+ }
257
+
258
+ /**
259
+ * Filter the HTML output of a list of pages as a drop down.
260
+ *
261
+ * @since 2.0.0
262
+ *
263
+ * @param string $output HTML output for drop down list of posts.
264
+ * @param array $r The parsed arguments array.
265
+ * @param array $posts List of WP_Post objects returned by `get_posts()`
266
+ */
267
+ $html = apply_filters( 'wp_dropdown_posts', $output, $r, $posts );
268
+
269
+ if( $r['echo'] ) {
270
+ echo $html;
271
+ }
272
+
273
+ return $html;
274
+ }
275
+
276
+
277
+ /**
278
+ * Output buffer function to avoid headers already sent issues.
279
+ *
280
+ * @link https://tommcfarlin.com/wp_redirect-headers-already-sent/
281
+ * @since 2.1.4
282
+ * @access public
283
+ *
284
+ * @uses ob_start() To load buffer.
285
+ *
286
+ * @return void
287
+ */
288
+ public function add_buffer() {
289
+
290
+ ob_start();
291
+ }
292
+
293
+
294
+ }
admin/class-link-juice-keeper-logs.php ADDED
@@ -0,0 +1,926 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * The class responsible for displaying the logs in a WP table
4
+ *
5
+ * @link https://profiles.wordpress.org/pattihis/
6
+ * @since 2.0.0
7
+ *
8
+ *
9
+ * @package Link_Juice_Keeper
10
+ * @subpackage Link_Juice_Keeper/logs
11
+ * @author George Pattihis <gpattihis@gmail.com>
12
+ */
13
+
14
+ // Load base class if it doesn't exist
15
+ if (!class_exists('WP_List_Table')) {
16
+ require_once(ABSPATH . 'wp-admin/includes/class-wp-list-table.php');
17
+ }
18
+
19
+ class Link_Juice_Keeper_Logs extends WP_List_Table {
20
+
21
+ /**
22
+ * Group by column name.
23
+ *
24
+ * @since 2.0.0
25
+ * @access private
26
+ * @var string
27
+ */
28
+ private $group_by = '';
29
+
30
+ /**
31
+ * Initialize the class and set properties.
32
+ *
33
+ * @since 2.0.0
34
+ * @access public
35
+ */
36
+ public function __construct() {
37
+
38
+ parent::__construct(
39
+ array(
40
+ 'singular' => __( '404 Error Log', 'link-juice-keeper' ),
41
+ 'plural' => __( '404 Error Logs', 'link-juice-keeper' ),
42
+ 'ajax' => false,
43
+ )
44
+ );
45
+ }
46
+
47
+ /**
48
+ * Prepare listing table using WP_List_Table class.
49
+ *
50
+ * This function extends the listing table class and uses our data
51
+ * to list in the table.Here we set pagination, columns, sorting etc.
52
+ *
53
+ * $this->items - Push our custom log data to the listing table.
54
+ * Registering filter - "ljk_logs_list_per_page".
55
+ *
56
+ * @since 2.0.0
57
+ * @access public
58
+ */
59
+ public function prepare_items() {
60
+
61
+ $this->_column_headers = array(
62
+ $this->get_columns(), // columns
63
+ array(), // hidden
64
+ $this->get_sortable_columns(), // sortable
65
+ );
66
+ // Execute bulk actions.
67
+ $actions = $this->process_actions();
68
+
69
+ // Redirect after actions, or after security check.
70
+ $this->safe_redirect( $actions );
71
+
72
+ // Set group by column.
73
+ $this->set_groupby();
74
+
75
+ /**
76
+ * Filter to alter no. of items per page.
77
+ *
78
+ * Change no. of items listed on a page. This value can be changed from
79
+ * error listing page screen options.
80
+ *
81
+ * @since 2.0.0
82
+ */
83
+ $per_page = apply_filters( 'ljk_logs_list_per_page', $this->get_items_per_page( 'logs_per_page', 40 ) );
84
+
85
+ // Current page number.
86
+ $page_number = $this->get_pagenum();
87
+
88
+ // Total error logs.
89
+ $total_items = $this->total_logs();
90
+
91
+ // Set pagination.
92
+ $this->set_pagination_args(
93
+ array(
94
+ 'total_items' => $total_items,
95
+ 'per_page' => $per_page,
96
+ )
97
+ );
98
+
99
+ // Set table data for the current page.
100
+ $data = $this->get_error_logs( $per_page, $page_number );
101
+ usort( $data, array( &$this, 'sort_data' ) );
102
+ $this->items = $data;
103
+ }
104
+
105
+ /**
106
+ * Get error logs data.
107
+ *
108
+ * Get error logs data from our custom database table.
109
+ * Apply all filtering, sorting and paginations.
110
+ * Registering filter - "ljk_logs_list_result".
111
+ *
112
+ * @param int $per_page Logs per page.
113
+ * @param int $page_number Current page number.
114
+ *
115
+ * @global object $wpdb WP DB object
116
+ * @since 2.0.0
117
+ * @access public
118
+ *
119
+ * @return array
120
+ */
121
+ private function get_error_logs( $per_page = 20, $page_number = 1 ) {
122
+
123
+ global $wpdb;
124
+ $table = $wpdb->prefix . 'link_juice_keeper';
125
+
126
+ // Current offset.
127
+ $offset = ( $page_number - 1 ) * $per_page;
128
+
129
+ // Sort by column.
130
+ $orderby = $this->get_order_by();
131
+
132
+ // Set group b query, if set.
133
+ $groupby_query = empty( $this->group_by ) ? '' : ' GROUP BY ' . $this->group_by;
134
+ // Get count of grouped items.
135
+ $count = empty( $this->group_by ) ? '' : ', COUNT(id) as count ';
136
+
137
+ // Sort order.
138
+ $order = $this->get_order();
139
+
140
+ // Get error logs.
141
+ $result = $wpdb->get_results( $wpdb->prepare( "SELECT *" . $count . " FROM " . $table . " WHERE status != 0 " . $groupby_query . " ORDER BY %s %s LIMIT %d OFFSET %d", array( $orderby, $order, $per_page, $offset ) ), 'ARRAY_A' );
142
+
143
+ /**
144
+ * Filter to alter the error logs listing data result.
145
+ *
146
+ * @since 2.0.0
147
+ */
148
+ return apply_filters( 'ljk_logs_list_result', $result );
149
+ }
150
+
151
+ /**
152
+ * Get sort by column name.
153
+ *
154
+ * This is used to filter the sorting parameters in order
155
+ * to prevent SQL injection atacks. We will accept only our
156
+ * required values. Else we will assign a default value.
157
+ * Registering filter - "ljk_log_list_orderby".
158
+ *
159
+ * @since 2.0.3
160
+ * @access public
161
+ * @uses esc_sql() To escape string for SQL.
162
+ *
163
+ * @return string Filtered column name.
164
+ */
165
+ private function get_order_by() {
166
+
167
+ /**
168
+ * Filter to alter the log listing orderby param.
169
+ *
170
+ * Only a valid column name will be accepted.
171
+ *
172
+ * @since 2.0.0
173
+ */
174
+ $orderby = apply_filters( 'ljk_log_list_orderby', $this->linkJuiceKeeper_from_request( 'orderby', 'date' ) );
175
+
176
+ /**
177
+ * Filter to alter the allowed order by values.
178
+ *
179
+ * @param array array of allowed column names.
180
+ *
181
+ * @since 2.0.0
182
+ */
183
+ $allowed_columns = apply_filters( 'ljk_log_list_orderby_allowed', array( 'date', 'url', 'ref', 'ip' ) );
184
+
185
+ // Make sure only valid columns are considered.
186
+ $allowed_columns = array_intersect( $allowed_columns, array_keys( $this->linkJuiceKeeper_log_columns() ) );
187
+
188
+ // Check if given column is allowed.
189
+ if ( in_array( $orderby, $allowed_columns ) ) {
190
+ return esc_sql( $orderby );
191
+ }
192
+
193
+ return 'date';
194
+ }
195
+
196
+ /**
197
+ * Filter the sorting parameters.
198
+ *
199
+ * This is used to filter the sorting parameters in order
200
+ * to prevent SQL injection attacks. We will accept only our
201
+ * required values. Else we will assign a default value.
202
+ * Registering filter - "ljk_log_list_order".
203
+ *
204
+ * @since 2.0.3
205
+ * @access private
206
+ *
207
+ * @return string Filtered column name.
208
+ */
209
+ private function get_order() {
210
+
211
+ // Get order column name from request.
212
+ $order = $this->linkJuiceKeeper_from_request( 'order', 'DESC' ) == 'asc' ? 'ASC' : 'DESC';
213
+
214
+ /**
215
+ * Filter to alter the log listing order param.
216
+ *
217
+ * Only ASC and DESC will be accepted.
218
+ *
219
+ * @since 2.0.0
220
+ */
221
+ return apply_filters( 'ljk_log_list_order', $order );
222
+ }
223
+
224
+ /**
225
+ * Set groupby value for grouping results.
226
+ *
227
+ * Groupby filter to avoid duplicate values in error log
228
+ * listing table. If a groupby column is set, it will show
229
+ * the count along with the logs.
230
+ * Registering filter - "ljk_log_list_groupby_allowed".
231
+ * Registering filter - "ljk_log_list_groupby".
232
+ *
233
+ * @since 2.0.0
234
+ * @access private
235
+ */
236
+ private function set_groupby() {
237
+
238
+ /**
239
+ * Filter to alter the allowed group by values.
240
+ *
241
+ * Only these columns will be allowed. It is a security
242
+ * measure too.
243
+ *
244
+ * @param array array of allowed column names.
245
+ *
246
+ * @since 2.0.0
247
+ */
248
+ $allowed_values = apply_filters( 'ljk_log_list_groupby_allowed', array( 'url', 'ref', 'ip', 'ua' ) );
249
+
250
+ // Make sure only valid columns are considered.
251
+ $allowed_values = array_intersect( $allowed_values, array_keys( $this->linkJuiceKeeper_log_columns() ) );
252
+
253
+ // Get group by value from request.
254
+ $group_by = $this->linkJuiceKeeper_from_request( 'group_by_top', '' );
255
+
256
+ // Verify if the group by value is allowed.
257
+ if ( ! in_array( $group_by, $allowed_values ) ) {
258
+ return;
259
+ }
260
+
261
+ /**
262
+ * Filter to alter the log listing groupby param.
263
+ *
264
+ * Only allowed column names are accepted.
265
+ *
266
+ * @since 2.0.0
267
+ */
268
+ $this->group_by = apply_filters( 'ljk_log_list_groupby', $group_by );
269
+ }
270
+
271
+ /**
272
+ * Get the count of total logs in table.
273
+ *
274
+ * Since we are using a custom table for data in
275
+ * listing, we need to get count of total items for proper pagination.
276
+ * Registering filter - "ljk_log_list_count".
277
+ *
278
+ * @global object $wpdb WP DB object
279
+ * @since 2.0.3
280
+ * @access private
281
+ *
282
+ * @return int Total count.
283
+ */
284
+ private function total_logs() {
285
+
286
+ global $wpdb;
287
+ $table = $wpdb->prefix . 'link_juice_keeper';
288
+
289
+ if ( empty( $this->group_by ) ) {
290
+ $total = $wpdb->get_var( "SELECT COUNT(id) FROM " . $table );
291
+ } else {
292
+ $total = $total = $wpdb->get_var( "SELECT COUNT(DISTINCT " . $this->group_by . ") FROM " . $table );
293
+ }
294
+
295
+ /**
296
+ * Filter to alter total logs count.
297
+ *
298
+ * @since 2.0.0
299
+ */
300
+ return apply_filters( 'ljk_log_list_count', $total );
301
+ }
302
+
303
+ /**
304
+ * Listing table column titles.
305
+ *
306
+ * Custom column titles to be displayed in listing table.
307
+ * Registering filter - "ljk_log_list_column_names".
308
+ *
309
+ * @since 2.0.0
310
+ * @access public
311
+ *
312
+ * @return array $columns Array of column titles.
313
+ */
314
+ public function get_columns() {
315
+
316
+ $columns = array(
317
+ 'cb' => '<input type="checkbox" style="width: 5%;" />',
318
+ 'date' => __( 'Date', 'link-juice-keeper' ),
319
+ 'url' => __( '404 Path', 'link-juice-keeper' ),
320
+ 'ref' => __( 'Referrer', 'link-juice-keeper' ),
321
+ 'ip' => __( 'User IP', 'link-juice-keeper' ),
322
+ 'ua' => __( 'User Agent', 'link-juice-keeper' )
323
+ );
324
+
325
+ /**
326
+ * Filter hook to change column titles.
327
+ *
328
+ * If you are adding custom columns, remember to add
329
+ * those to "ljk_log_list_column_default" filter too.
330
+ *
331
+ * @since 2.0.0
332
+ */
333
+ return apply_filters( 'ljk_log_list_column_names', $columns );
334
+ }
335
+
336
+ /**
337
+ * Make columns sortable.
338
+ *
339
+ * To make our custom columns in list table sortable.
340
+ * Do not enable sorting for ua columns.
341
+ * Registering filter - "ljk_log_list_sortable_columns".
342
+ *
343
+ * @since 2.0.0
344
+ * @access protected
345
+ *
346
+ * @return array Array of columns to enable sorting.
347
+ */
348
+ protected function get_sortable_columns() {
349
+
350
+ $columns = array(
351
+ 'date' => array( 'date', true ),
352
+ 'url' => array( 'url', false ),
353
+ 'ref' => array( 'ref', false ),
354
+ 'ip' => array( 'ip', false )
355
+ );
356
+
357
+ /**
358
+ * Filter hook to change column titles.
359
+ *
360
+ * @note DO NOT add extra columns.
361
+ *
362
+ * @since 2.0.0
363
+ */
364
+ return apply_filters( 'ljk_log_list_sortable_columns', $columns );
365
+ }
366
+
367
+ /**
368
+ * Message to be displayed when there are no items.
369
+ *
370
+ * If there are no errors logged yet, show custom error message
371
+ * instead of default one.
372
+ * Registering filter - "ljk_log_list_no_items_message".
373
+ *
374
+ * @since 2.0.0
375
+ * @access public
376
+ *
377
+ * @return void
378
+ */
379
+ public function no_items() {
380
+
381
+ /**
382
+ * Filter hook to change no items message.
383
+ *
384
+ * @since 2.0.0
385
+ */
386
+ _e( apply_filters( 'ljk_log_list_no_items_message', __( 'It seems there are no 404 errors logged yet.', 'link-juice-keeper' ) ) );
387
+ }
388
+
389
+ /**
390
+ * Default columns in list table.
391
+ *
392
+ * To show columns in error log list table. If there is nothing
393
+ * for switch, printing the whole array.
394
+ * Registering filter - "ljk_log_list_column_default".
395
+ *
396
+ * @param array $item Column data
397
+ * @param string $column_name Column name
398
+ *
399
+ * @since 2.0.0
400
+ * @access protected
401
+ *
402
+ * @return array
403
+ */
404
+ protected function column_default( $item, $column_name ) {
405
+
406
+ $columns = array_keys( $this->linkJuiceKeeper_log_columns() );
407
+
408
+ /**
409
+ * Filter hook to change column names.
410
+ *
411
+ * @note DO NOT add extra columns.
412
+ *
413
+ * @since 2.0.0
414
+ */
415
+ $columns = apply_filters( 'ljk_log_list_column_default', $columns );
416
+
417
+ // If current column is allowed.
418
+ if ( in_array( $column_name, $columns ) ) {
419
+ return $item[ $column_name ];
420
+ }
421
+
422
+ // Show the whole array for troubleshooting purposes.
423
+ return print_r( $item, true );
424
+ }
425
+
426
+ /**
427
+ * To output checkbox for bulk actions.
428
+ *
429
+ * This function is used to add new checkbox for all entries in
430
+ * the listing table. We use this checkbox to perform bulk actions.
431
+ *
432
+ * @param array $item Column data
433
+ *
434
+ * @since 2.1.0
435
+ * @access public
436
+ *
437
+ * @return string
438
+ */
439
+ function column_cb( $item ) {
440
+
441
+ return sprintf( '<input type="checkbox" name="bulk-delete[]" value="%s"/>', $item['id'] );
442
+ }
443
+
444
+ /**
445
+ * Date column content.
446
+ *
447
+ * This function is used to modify the column data for date in listing table.
448
+ * We can change styles, texts etc. using this function.
449
+ * Registering filter - "ljk_log_list_date_column".
450
+ *
451
+ * @param array $item Column data
452
+ *
453
+ * @since 2.0.0
454
+ * @access public
455
+ *
456
+ * @return string
457
+ */
458
+ function column_date( $item ) {
459
+
460
+ $delete_nonce = wp_create_nonce( 'bulk-' . $this->_args['plural'] );
461
+
462
+ $title = mysql2date( "j M Y, g:i a", $item['date'] );
463
+
464
+ $confirm = __( 'Are you sure you want to delete this item?', 'link-juice-keeper' );
465
+
466
+ $actions = array( 'delete' => sprintf( '<a href="?page=link-juice-keeper-404-logs&action=%s&bulk-delete=%s&_wpnonce=%s" onclick="return confirm(\'%s\');">' . __( 'Delete', 'link-juice-keeper' ) . '</a>', 'delete', absint( $item['id'] ), $delete_nonce, $confirm ) );
467
+
468
+ /**
469
+ * Filter to change date column html content.
470
+ *
471
+ * @since 2.0.0
472
+ */
473
+ return apply_filters( 'ljk_log_list_date_column', $title . $this->row_actions( $actions ) );
474
+ }
475
+
476
+ /**
477
+ * URL column content.
478
+ *
479
+ * This function is used to modify the column data for url in listing table.
480
+ * We can change styles, texts etc. using this function.
481
+ * Registering filter - "ljk_log_list_url_column".
482
+ *
483
+ * @param array $item Column data
484
+ *
485
+ * @since 2.0.0
486
+ * @access public
487
+ *
488
+ * @return string URL column html content
489
+ */
490
+ function column_url( $item ) {
491
+
492
+ // Get default text if empty value.
493
+ $url = $this->get_empty_content( $item['url'] );
494
+ if ( ! $url ) {
495
+ $url = esc_url( $item['url'] );
496
+ }
497
+
498
+ /**
499
+ * Filter to change url column content
500
+ *
501
+ * Remember this filter value is a partial url field
502
+ *
503
+ * @since 2.0.0
504
+ */
505
+ return apply_filters( 'ljk_log_list_url_column', $this->get_group_content( $url, 'url', $item ) );
506
+ }
507
+
508
+ /**
509
+ * Referrer column content.
510
+ *
511
+ * This function is used to modify the column data for ref in listing table.
512
+ * We can change styles, texts etc. using this function.
513
+ * Registering filter - "ljk_log_list_ref_column".
514
+ *
515
+ * @param array $item Column data
516
+ *
517
+ * @since 2.0.0
518
+ * @access public
519
+ *
520
+ * @return string Ref column html content.
521
+ */
522
+ function column_ref( $item ) {
523
+
524
+ // Get default text if empty value.
525
+ $ref = $this->get_empty_content( $item['ref'] );
526
+ if ( ! $ref ) {
527
+ $ref = '<a href="' . esc_url( $item['ref'] ) . '" target="_blank">' . esc_url( $item['ref'] ) . '</a>';
528
+ }
529
+
530
+ /**
531
+ * Filter to change referer url column content
532
+ *
533
+ * @since 2.0.0
534
+ */
535
+ return apply_filters( 'ljk_log_list_ref_column', $this->get_group_content( $ref, 'ref', $item ) );
536
+ }
537
+
538
+ /**
539
+ * User agent column content.
540
+ *
541
+ * This function is used to modify the column data for user agent in listing table.
542
+ * We can change styles, texts etc. using this function.
543
+ * Registering filter - "ljk_log_list_ua_column".
544
+ *
545
+ * @param array $item Column data
546
+ *
547
+ * @since 2.0.0
548
+ * @access public
549
+ *
550
+ * @return string User Agent column html content
551
+ */
552
+ function column_ua( $item ) {
553
+
554
+ // Sanitize text content.
555
+ $ua = sanitize_text_field( $item['ua'] );
556
+
557
+ /**
558
+ * Filter to change user agent column content.
559
+ *
560
+ * @since 2.0.0
561
+ */
562
+ return apply_filters( 'ljk_log_list_ua_column', $this->get_group_content( $ua, 'ua', $item ) );
563
+ }
564
+
565
+ /**
566
+ * IP column content.
567
+ *
568
+ * This function is used to modify the column data for ip in listing table.
569
+ * We can change styles, texts etc. using this function.
570
+ * Registering filter - "ljk_log_list_ip_column".
571
+ *
572
+ * @param array $item Column data
573
+ *
574
+ * @since 2.0.0
575
+ * @access public
576
+ *
577
+ * @return string IP column html content.
578
+ */
579
+ function column_ip( $item ) {
580
+
581
+ // Get default text if empty value.
582
+ $ip = $this->get_empty_content( $item['ip'] );
583
+ if ( ! $ip ) {
584
+ $ip = sanitize_text_field( $item['ip'] );
585
+ }
586
+
587
+ /**
588
+ * Filter to change IP column content.
589
+ *
590
+ * @since 2.0.0
591
+ */
592
+ return apply_filters( 'ljk_log_list_ip_column', $this->get_group_content( $ip, 'ip', $item ) );
593
+ }
594
+
595
+ /**
596
+ * Check if current column is grouped and add count number
597
+ *
598
+ * @param string $content Content to display.
599
+ * @param string $column Column name.
600
+ * @param array $item Items array.
601
+ *
602
+ * @since 2.0.0
603
+ * @access private
604
+ *
605
+ * @return string|boolean
606
+ */
607
+ private function get_group_content( $content, $column, $item ) {
608
+
609
+ $count_text = '';
610
+
611
+ if ( ! empty( $item['count'] ) && $item['count'] > 1 && $column === $this->group_by ) {
612
+ $count_text = " (<strong>" . $item['count'] . "</strong>)";
613
+ }
614
+
615
+ return $content . $count_text;
616
+ }
617
+
618
+ /**
619
+ * Get default text if empty.
620
+ *
621
+ * Get an error text with custom class to show if the
622
+ * current column value is empty or n/a.
623
+ *
624
+ * @param string $value Field value.
625
+ *
626
+ * @since 2.0.0
627
+ * @access private
628
+ *
629
+ * @return string|boolean
630
+ */
631
+ private function get_empty_content( $value ) {
632
+
633
+ // Get default error text.
634
+ if ( strtolower( $value ) === 'n/a' || empty( $value ) ) {
635
+ return '<i>Not available</i>';
636
+ }
637
+
638
+ return false;
639
+ }
640
+
641
+ /**
642
+ * Bulk actions drop down.
643
+ *
644
+ * Options to be added to the bulk actions drop down for users
645
+ * to select. We have added 'Delete' actions.
646
+ * Registering filter - "ljk_log_list_bulk_actions".
647
+ *
648
+ * @since 2.0.0
649
+ * @access public
650
+ *
651
+ * @return array $actions Options to be added to the action select box.
652
+ */
653
+ public function get_bulk_actions() {
654
+
655
+ $actions = array(
656
+ 'bulk_delete' => __( 'Delete Selected', 'link-juice-keeper' ),
657
+ 'bulk_clean' => __( 'Delete All', 'link-juice-keeper' ),
658
+ );
659
+
660
+ /**
661
+ * Filter hook to change actions.
662
+ *
663
+ * @note If you are adding extra actions
664
+ * Make sure it's actions are properly added.
665
+ *
666
+ * @since 2.0.0
667
+ */
668
+ return apply_filters( 'ljk_log_list_bulk_actions', $actions );
669
+ }
670
+
671
+ /**
672
+ * Add extra action dropdown for grouping the error logs.
673
+ *
674
+ * @param string $which Top or Bottom.
675
+ *
676
+ * @access protected
677
+ * @since 2.0.0
678
+ *
679
+ * @return void
680
+ */
681
+ public function extra_tablenav( $which ) {
682
+
683
+ if ( $this->has_items() && 'top' == $which ) {
684
+
685
+ // This filter is already documented above.
686
+ $allowed_values = apply_filters( 'ljk_log_list_groupby_allowed', array( 'url', 'ref', 'ip', 'ua' ) );
687
+ // Allowed/available columns.
688
+ $available_columns = $this->linkJuiceKeeper_log_columns();
689
+ // Consider only available columns.
690
+ $column_names = array_intersect( $allowed_values, array_keys( $available_columns ) );
691
+ // Add dropdown.
692
+ echo '<div class="alignleft actions bulkactions">';
693
+ echo '<select name="group_by_top" class="404_group_by">';
694
+ echo '<option value="">' . __( 'Group by', 'link-juice-keeper' ) . '</option>';
695
+ foreach ( $column_names as $column ) {
696
+ echo '<option value="' . $column . '" ' . selected( $column, $this->group_by ) . '>' . $available_columns[ $column ] . '</option>';
697
+ }
698
+ echo '</select>';
699
+ submit_button( __( 'Apply', 'link-juice-keeper' ), 'button', 'filter_action', false, array( 'id' => 'post-query' ) );
700
+ echo '</div>';
701
+
702
+ /**
703
+ * Action hook to add extra items in actions area.
704
+ *
705
+ * @param object $this Class instance.
706
+ * @param string $which Current location (top or bottom).
707
+ */
708
+ do_action( 'ljk_log_list_extra_tablenav', $this, $which );
709
+ }
710
+ }
711
+
712
+ /**
713
+ * To perform bulk actions.
714
+ *
715
+ * After security check, perform bulk actions selected by
716
+ * the user. Only allowed actions will be performed.
717
+ *
718
+ * @since 2.1.0
719
+ * @access private
720
+ * @uses check_admin_referer() For security check.
721
+ *
722
+ * @return void|boolean
723
+ */
724
+ private function process_actions() {
725
+
726
+ // Get current action.
727
+ $action = $this->current_action();
728
+
729
+ // Get allowed actions array.
730
+ $allowed_actions = array_keys( $this->get_bulk_actions() );
731
+
732
+ // Verify only allowed actions are passed.
733
+ if ( ! in_array( $action, $allowed_actions ) && 'delete' !== $action ) {
734
+ return false;
735
+ }
736
+
737
+ // IDs of log entires to process.
738
+ $ids = $this->linkJuiceKeeper_from_request( 'bulk-delete', true );
739
+
740
+ // Run custom bulk actions.
741
+ // Add other custom actions in switch..
742
+ switch ( $action ) {
743
+ // Normal selected deletes.
744
+ case 'delete':
745
+ case 'bulk_delete':
746
+ case 'bulk_clean':
747
+ $this->delete_logs( $ids, $action );
748
+ break;
749
+ // Add custom actions here.
750
+ }
751
+
752
+ return true;
753
+ }
754
+
755
+ /**
756
+ * Remove sensitive values from the URL.
757
+ *
758
+ * If WordPress nonce or admin referrer is found in url
759
+ * remove that and redirect to same page.
760
+ *
761
+ * @param boolean $action_performed If any actions performed.
762
+ *
763
+ * @access private
764
+ * @since 2.0.0
765
+ *
766
+ * @return void
767
+ */
768
+ private function safe_redirect( $action_performed = false ) {
769
+
770
+ // If sensitive data found, remove those and redirect.
771
+ if ( ! empty( $_GET['_wp_http_referer'] ) || ! empty( $_GET['_wpnonce'] ) ) {
772
+ // Redirect to current page.
773
+ wp_redirect( remove_query_arg( array( '_wp_http_referer', '_wpnonce' ), wp_unslash( $_SERVER['REQUEST_URI'] ) ) );
774
+ exit();
775
+ }
776
+
777
+ // If bulk actions performed, redirect.
778
+ if ( $action_performed === true ) {
779
+ // Redirect to current page.
780
+ wp_redirect( remove_query_arg( array( 'action', 'action2' ), wp_unslash( $_SERVER['REQUEST_URI'] ) ) );
781
+ exit();
782
+ }
783
+ }
784
+
785
+ /**
786
+ * Delete error logs.
787
+ *
788
+ * Bulk action processor to delete error logs according to
789
+ * the user selection. We are using IF ELSE loop instead of
790
+ * switch to easily handle conditions.
791
+ *
792
+ * @param mixed $ids ID(s) of the log(s).
793
+ * @param string $action Current bulk action.
794
+ *
795
+ * @since 2.0.0
796
+ * @access private
797
+ *
798
+ * @return void
799
+ */
800
+ private function delete_logs( $ids, $action ) {
801
+
802
+ global $wpdb;
803
+ $table = $wpdb->prefix . 'link_juice_keeper';
804
+
805
+ if ( is_numeric( $ids ) && 'delete' === $action ) {
806
+ // If a single log is being deleted.
807
+ $query = "DELETE FROM " . $table . " WHERE id = " . absint( $ids );
808
+ } elseif ( is_array( $ids ) && 'bulk_delete' === $action ) {
809
+ // If multiple selected logs are being deleted.
810
+ $ids = implode( ',', array_map( 'absint', $ids ) );
811
+ $query = "DELETE FROM " . $table . " WHERE id IN($ids)";
812
+ } elseif ( 'bulk_clean' === $action ) {
813
+ // If deleting all logs.
814
+ $query = "DELETE FROM " . $table;
815
+ } else {
816
+ // Incase if invalid log ids.
817
+ return;
818
+ }
819
+
820
+ // Run query to delete logs.
821
+ $wpdb->query( $query );
822
+ }
823
+
824
+
825
+ /**
826
+ * Available columns in error logs table.
827
+ * Registering filter - "ljk_redirect_statuses".
828
+ *
829
+ * @since 2.0.0
830
+ * @access private
831
+ *
832
+ * @return array Allowed HTTP status codes.
833
+ */
834
+ public function linkJuiceKeeper_log_columns() {
835
+
836
+ $columns = array(
837
+ 'date' => __( 'Date', 'link-juice-keeper' ),
838
+ 'url' => __( '404 Path', 'link-juice-keeper' ),
839
+ 'ref' => __( 'Referrer', 'link-juice-keeper' ),
840
+ 'ip' => __( 'User IP', 'link-juice-keeper' ),
841
+ 'ua' => __( 'User Agent', 'link-juice-keeper' )
842
+ );
843
+
844
+ /**
845
+ * Filter for available columns.
846
+ * Registering filter - "ljk_log_columns".
847
+ *
848
+ * @param array columns name and slug.
849
+ *
850
+ * @since 2.0.0
851
+ */
852
+ return (array) apply_filters( 'ljk_log_columns', $columns );
853
+ }
854
+
855
+ /**
856
+ * Retreive data from $_REQUEST and sanitize
857
+ *
858
+ * @param string $key Key to get from request.
859
+ * @param mixed $default Default value.
860
+ *
861
+ * @since 2.0.0
862
+ * @access public
863
+ *
864
+ * @return array|string
865
+ */
866
+ public function linkJuiceKeeper_from_request( $key = '', $default = '' ) {
867
+
868
+ // Return default value if key is not given.
869
+ if ( empty( $key ) || ! is_string( $key ) ) {
870
+ return $default;
871
+ }
872
+
873
+ // Return default value if key not set.
874
+ if ( ! isset( $_REQUEST[ $key ] ) ) {
875
+ return $default;
876
+ }
877
+
878
+ // Trim output.
879
+ if ( is_string( $_REQUEST[ $key ] ) ) {
880
+ return sanitize_text_field( $_REQUEST[ $key ] );
881
+ } elseif ( is_array( $_REQUEST[ $key ] ) ) {
882
+ return array_map( 'sanitize_text_field', $_REQUEST[ $key ] );
883
+ }
884
+
885
+ return $default;
886
+ }
887
+
888
+ /**
889
+ * Allows you to sort the data by the variables set in the $_GET
890
+ *
891
+ * @since 2.0.0
892
+ * @return Mixed
893
+ */
894
+ private function sort_data( $a, $b )
895
+ {
896
+ // Set defaults
897
+ $orderby = 'date';
898
+ $order = 'desc';
899
+
900
+ // If orderby is set, use this as the sort column
901
+ if(!empty($_GET['orderby']))
902
+ {
903
+ $orderby = sanitize_title($_GET['orderby']);
904
+ }
905
+
906
+ // If order is set use this as the order
907
+ if(!empty($_GET['order']))
908
+ {
909
+ $order = sanitize_title($_GET['order']);
910
+ }
911
+
912
+
913
+ $result = strcmp( $a[$orderby], $b[$orderby] );
914
+
915
+ if($order === 'asc')
916
+ {
917
+ return $result;
918
+ }
919
+
920
+ return -$result;
921
+ }
922
+
923
+
924
+
925
+
926
+ }
admin/css/link-juice-keeper-admin.css ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ .ljk_main_wrap {
2
+ display: flex;
3
+ flex-direction: row;
4
+ justify-content: space-between;
5
+ max-width: 1080px;
6
+ }
7
+ .ljk_main_left {
8
+ background:#ffffff;
9
+ border-radius: 10px;
10
+ padding: 0 2%;
11
+ flex-basis: 59%;
12
+ }
13
+
14
+ .ljk_main_right {
15
+ background:#ffffff;
16
+ border-radius: 10px;
17
+ padding: 20px 2%;
18
+ flex-basis: 29%;
19
+ }
20
+
21
+ @media only screen and (max-width: 992px) {
22
+ .ljk_main_wrap {
23
+ flex-direction: column;
24
+ }
25
+ .ljk_main_left, .ljk_main_right {
26
+ margin: 0 20px 30px 0;
27
+ flex-basis: 100%;
28
+ }
29
+ }
admin/index.php ADDED
@@ -0,0 +1 @@
 
1
+ <?php // Silence is golden
admin/js/link-juice-keeper-admin.js ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ (function( $ ) {
2
+ 'use strict';
3
+ window.addEventListener("load", function(event) {
4
+
5
+ if ( $('.ljk_main_wrap').length ) {
6
+ toggleOptions();
7
+ $( '#ljk_redirect_to' ).change(function() {
8
+ toggleOptions();
9
+ });
10
+ }
11
+
12
+
13
+ });
14
+
15
+ function toggleOptions () {
16
+ $('#custom_page').hide();
17
+ $('#custom_post').hide();
18
+ $('#custom_url').hide();
19
+ var set = $('#ljk_redirect_to').val();
20
+ switch(set) {
21
+ case 'page':
22
+ $('#custom_page').show();
23
+ break;
24
+ case 'post':
25
+ $('#custom_post').show();
26
+ break;
27
+ case 'link':
28
+ $('#custom_url').show();
29
+ break;
30
+ }
31
+ }
32
+
33
+ })( jQuery );
admin/partials/link-juice-keeper-admin-display-logs.php ADDED
@@ -0,0 +1,64 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Provide an admin area view for the plugin
5
+ *
6
+ * This file is used to markup the admin-facing aspects of the plugin.
7
+ *
8
+ * @link https://profiles.wordpress.org/pattihis/
9
+ * @since 2.0.0
10
+ *
11
+ * @package Link_Juice_Keeper
12
+ * @subpackage Link_Juice_Keeper/admin/partials
13
+ */
14
+
15
+ global $wpdb;
16
+
17
+ $table = new Link_Juice_Keeper_Logs();
18
+
19
+ ?>
20
+
21
+ <h1>404 Logs</h1>
22
+ <div class="wrap">
23
+ <h4><?php _e( 'All Page Not Found (404) errors recorded in our database', 'link-juice-keeper' ); ?></h4>
24
+ <div id="poststuff">
25
+ <div id="post-body" class="metabox-holder">
26
+ <div id="post-body-content">
27
+ <div class="meta-box-sortables ui-sortable">
28
+ <?php $table->prepare_items();
29
+ /**
30
+ * Action hook to add something above listing page.
31
+ *
32
+ * Use this action hook to add custom filters and search
33
+ * boxes to the listing table top section.
34
+ *
35
+ * @param object $this Listing page class object.
36
+ *
37
+ * @since 2.0.0
38
+ */
39
+ do_action( 'ljk_log_list_above_form', $table );
40
+ ?>
41
+ <form method="get">
42
+ <input type="hidden" name="page" value="link-juice-keeper-404-logs"/>
43
+ <?php $table->display(); ?>
44
+ </form>
45
+ <?php
46
+ /**
47
+ * Action hook to add something below the listing page.
48
+ *
49
+ * Use this action hook to add custom filters and search
50
+ * boxes to the listing table bottom section.
51
+ *
52
+ * @param object $this Listing page class object.
53
+ *
54
+ * @since 2.0.0
55
+ */
56
+ do_action( 'ljk_log_list_below_form', $table );
57
+ ?>
58
+ </div>
59
+ </div>
60
+ </div>
61
+ <br class="clear">
62
+ </div>
63
+ </div>
64
+ <?php
admin/partials/link-juice-keeper-admin-display.php ADDED
@@ -0,0 +1,124 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Provide an admin area view for the plugin
5
+ *
6
+ * This file is used to markup the admin-facing aspects of the plugin.
7
+ *
8
+ * @link https://profiles.wordpress.org/pattihis/
9
+ * @since 2.0.0
10
+ *
11
+ * @package Link_Juice_Keeper
12
+ * @subpackage Link_Juice_Keeper/admin/partials
13
+ */
14
+
15
+ $plugin_admin = new Link_Juice_Keeper_Admin('link-juice-keeper', LINK_JUICE_KEEPER_VERSION );
16
+ $statuses = $plugin_admin->linkJuiceKeeper_statuses();
17
+
18
+ $hide = ' style="display: none;"';
19
+ ?>
20
+
21
+ <!-- This file should primarily consist of HTML with a little bit of PHP. -->
22
+
23
+ <h1><?php _e( 'Link Juice Keeper', 'link-juice-keeper' ); ?></h1>
24
+ <h3><?php _e( 'No more 404 errors', 'link-juice-keeper' ); ?></h3>
25
+ <div class="ljk_main_wrap">
26
+ <div class="ljk_main_left">
27
+ <form method="post" action="options.php">
28
+ <?php settings_fields( 'ljk_main_settings' ); ?>
29
+ <?php $options = get_option( 'ljk_main_settings' ); ?>
30
+ <table class="form-table">
31
+ <tbody>
32
+ <?php if ( !empty( $statuses ) ) : ?>
33
+ <tr>
34
+ <th><?php _e( 'Redirect type', 'link-juice-keeper' ); ?></th>
35
+ <td>
36
+ <select name='ljk_main_settings[redirect_type]'>
37
+ <?php foreach ( $statuses as $status => $label ) : ?>
38
+ <option value='<?php echo $status; ?>' <?php selected( $options['redirect_type'], $status ); ?>><?php echo $label; ?></option>
39
+ <?php endforeach; ?>
40
+ </select>
41
+ </td>
42
+ </tr>
43
+ <?php endif; ?>
44
+ <tr>
45
+ <th><?php _e( 'Redirect target', 'link-juice-keeper' ); ?></th>
46
+ <td>
47
+ <select name='ljk_main_settings[redirect_to]' id='ljk_redirect_to'>
48
+ <option value='home' <?php selected( $options['redirect_to'], 'home' ); ?>><?php _e( 'Home Page', 'link-juice-keeper' ); ?></option>
49
+ <option value='page' <?php selected( $options['redirect_to'], 'page' ); ?>><?php _e( 'Existing Page', 'link-juice-keeper' ); ?></option>
50
+ <option value='post' <?php selected( $options['redirect_to'], 'post' ); ?>><?php _e( 'Existing Post', 'link-juice-keeper' ); ?></option>
51
+ <option value='link' <?php selected( $options['redirect_to'], 'link' ); ?>><?php _e( 'Custom URL', 'link-juice-keeper' ); ?></option>
52
+ <option value='0' <?php selected( $options['redirect_to'], 0 ); ?>><?php _e( 'No Redirect', 'link-juice-keeper' ); ?></option>
53
+ </select>
54
+ </td>
55
+ </tr>
56
+ <tr id="custom_page"<?php echo ( $options['redirect_to'] !== 'page' ) ? $hide : ''; ?>>
57
+ <th><?php _e( 'Select a Page', 'link-juice-keeper' ); ?></th>
58
+ <td>
59
+ <?php wp_dropdown_pages( array( 'name' => 'ljk_main_settings[redirect_page]', 'selected' => $options['redirect_page'] ) ); ?>
60
+ <p><?php _e( 'Select a <b>Page</b> form this list to redirect all 404 errors to.', 'link-juice-keeper' ); ?></p>
61
+
62
+ </td>
63
+ </tr>
64
+ <tr id="custom_post"<?php echo ( $options['redirect_to'] !== 'post' ) ? $hide : ''; ?>>
65
+ <th><?php _e( 'Select a Post', 'link-juice-keeper' ); ?></th>
66
+ <td>
67
+ <?php $plugin_admin->wp_dropdown_posts( array( 'selected' => $options['redirect_post'], 'select_name' => 'ljk_main_settings[redirect_post]' ) ); ?>
68
+ <p><?php _e( 'Select a <b>Post</b> form this list to redirect all 404 errors to.', 'link-juice-keeper' ); ?></p>
69
+
70
+ </td>
71
+ </tr>
72
+ <tr id="custom_url"<?php echo ( $options['redirect_to'] !== 'link' ) ? $hide : ''; ?>>
73
+ <th><?php _e( 'Custom URL', 'link-juice-keeper' ); ?></th>
74
+ <td>
75
+ <input type="url" placeholder="<?php echo home_url(); ?>" name="ljk_main_settings[redirect_link]" value="<?php echo $options['redirect_link']; ?>">
76
+ <p><?php _e( 'Enter any <b>custom link</b> to redirect all 404 errors to.', 'link-juice-keeper' ); ?></p>
77
+ </td>
78
+ </tr>
79
+ <tr>
80
+ <th><?php _e( 'Log 404 Errors', 'link-juice-keeper' ); ?></th>
81
+ <td>
82
+ <label><input type="checkbox" name="ljk_main_settings[redirect_log]" value="1" <?php checked( $plugin_admin->linkJuiceKeeper_get_option( 'redirect_log' ), 1 ); ?> /><?php _e( 'Keep track of 404 errors', 'link-juice-keeper' ); ?></label>
83
+ </td>
84
+ </tr>
85
+ <tr>
86
+ <th><?php _e( 'Enable notifications', 'link-juice-keeper' ); ?></th>
87
+ <td>
88
+ <label><input type="checkbox" name="ljk_main_settings[email_notify]" value="1" <?php checked( $plugin_admin->linkJuiceKeeper_get_option( 'email_notify' ), 1 ); ?> />
89
+ <?php _e( 'Get notified by email on every 404 error', 'link-juice-keeper' ); ?></label>
90
+ </td>
91
+ </tr>
92
+ <tr>
93
+ <th><?php _e( 'Send notifications to', 'link-juice-keeper' ); ?></th>
94
+ <td>
95
+ <?php $notify_address = ( isset( $options['notify_to'] ) ) ? $options['notify_to'] : get_option( 'admin_email' ); ?>
96
+ <input type="email" placeholder="<?php echo get_option( 'admin_email' ); ?>" name="ljk_main_settings[notify_to]" value="<?php echo $notify_address; ?>">
97
+ <p><?php _e( 'Set the recipient email address for error log notifications', 'link-juice-keeper' ); ?></p>
98
+ </td>
99
+ </tr>
100
+ </tbody>
101
+ </table>
102
+ <?php submit_button( __( 'Save settings', 'link-juice-keeper' ) ); ?>
103
+ </form><!-- /.form -->
104
+ </div>
105
+ <div class="ljk_main_right">
106
+ <h3><?php _e( 'Usage', 'link-juice-keeper' ); ?></h3>
107
+ <hr>
108
+ <h4><?php _e( 'Select a redirect type', 'link-juice-keeper' ); ?></h4>
109
+ <p>
110
+ <?php _e( 'The 301 redirect is the best method in most cases and recommended for your SEO', 'link-juice-keeper' ); ?>.<br><a target="_blank" href="https://moz.com/learn/seo/redirection"><strong><?php _e( 'Learn more', 'link-juice-keeper' ); ?></strong></a> <?php _e( 'about these redirect types', 'link-juice-keeper' ); ?>
111
+ </p>
112
+ <h4><?php _e( 'Select a redirect target', 'link-juice-keeper' ); ?></h4>
113
+ <p>
114
+ 1. <strong><?php _e( 'Home Page', 'link-juice-keeper' ); ?>:</strong> <?php _e( 'Redirect any 404 not-found request to your homepage', 'link-juice-keeper' ); ?>.<br>
115
+ 2. <strong><?php _e( 'Existing Page', 'link-juice-keeper' ); ?>:</strong> <?php _e( 'Select any of your existing WordPress Pages as a 404 page', 'link-juice-keeper' ); ?>.<br>
116
+ 3. <strong><?php _e( 'Existing Post', 'link-juice-keeper' ); ?>:</strong> <?php _e( 'Select any of your existing WordPress Posts as a 404 page', 'link-juice-keeper' ); ?>.<br>
117
+ 4. <strong><?php _e( 'Custom URL', 'link-juice-keeper' ); ?>:</strong> <?php _e( 'Redirect 404 requests to any URL of your choice', 'link-juice-keeper' ); ?>.<br>
118
+ 5. <strong><?php _e( 'No Redirect', 'link-juice-keeper' ); ?>:</strong> <?php _e( 'Use this option to disable redirects on 404 errors', 'link-juice-keeper' ); ?>.
119
+ </p>
120
+ </div>
121
+ </div>
122
+ <p>
123
+ <?php _e( 'This is a free plugin so if you find it useful then please', 'link-juice-keeper' ); ?> <a target="_blank" href="https://wordpress.org/support/plugin/link-juice-keeper/reviews/?rate=5#new-post" title="Rate the plugin"><?php _e( 'rate the plugin', 'link-juice-keeper' ); ?> ★★★★★</a> <?php _e( 'to support us. Thank you!', 'link-juice-keeper' ); ?>
124
+ </p>
includes/class-link-juice-keeper-activator.php ADDED
@@ -0,0 +1,110 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Fired during plugin activation
5
+ *
6
+ * @link https://profiles.wordpress.org/pattihis/
7
+ * @since 2.0.0
8
+ *
9
+ * @package Link_Juice_Keeper
10
+ * @subpackage Link_Juice_Keeper/includes
11
+ */
12
+
13
+ /**
14
+ * Fired during plugin activation.
15
+ *
16
+ * This class defines all code necessary to run during the plugin's activation.
17
+ *
18
+ * @since 2.0.0
19
+ * @package Link_Juice_Keeper
20
+ * @subpackage Link_Juice_Keeper/includes
21
+ * @author George Pattihis <gpattihis@gmail.com>
22
+ */
23
+ class Link_Juice_Keeper_Activator {
24
+
25
+ /**
26
+ *
27
+ * We register default options to WordPress if they do not exist.
28
+ *
29
+ * @since 2.0.0
30
+ */
31
+ public static function activate() {
32
+
33
+ // Default settings for our plugin.
34
+ $options = array(
35
+ 'redirect_type' => '301',
36
+ 'redirect_link' => home_url(),
37
+ 'redirect_log' => 1,
38
+ 'redirect_to' => 'link',
39
+ 'redirect_page' => '',
40
+ 'redirect_post' => '',
41
+ 'notify' => 0,
42
+ 'notify_to' => get_option( 'admin_email' )
43
+ );
44
+
45
+ // Get existing options if exists.
46
+ $existing = get_option( 'ljk_main_settings' );
47
+ // Check if valid settings exist.
48
+ if ( $existing && is_array( $existing ) ) {
49
+ foreach ( $options as $key => $value ) {
50
+ if ( array_key_exists( $key, $existing ) ) {
51
+ $options[ $key ] = $existing[ $key ];
52
+ }
53
+ }
54
+ }
55
+
56
+ // Update/create our settings.
57
+ update_option( 'ljk_main_settings', $options );
58
+
59
+ // Manage error log table.
60
+ self::create_db();
61
+
62
+ }
63
+
64
+ /**
65
+ *
66
+ * Create or update database table for error logs
67
+ *
68
+ * @global object $wpdb WordPress database helper object.
69
+ * @uses dbDelta() For safe db upgrades.
70
+ *
71
+ * @return void
72
+ */
73
+ private static function create_db() {
74
+
75
+ // Get db version number.
76
+ $db = get_option( 'ljk_db_version' );
77
+
78
+ // If table is up to date, do nothing.
79
+ if ( defined( LINK_JUICE_KEEPER_VERSION ) && $db === LINK_JUICE_KEEPER_VERSION ) {
80
+ return;
81
+ }
82
+
83
+ global $wpdb;
84
+
85
+ // Our custom table name.
86
+ $table = $wpdb->prefix . 'link_juice_keeper';
87
+
88
+ // Define the table schema query.
89
+ $query = "CREATE TABLE $table (
90
+ id BIGINT NOT NULL AUTO_INCREMENT,
91
+ date DATETIME NOT NULL,
92
+ url VARCHAR(512) NOT NULL,
93
+ ref VARCHAR(512) NOT NULL default '',
94
+ ip VARCHAR(40) NOT NULL default '',
95
+ ua VARCHAR(512) NOT NULL default '',
96
+ status BIGINT NOT NULL default 1,
97
+ PRIMARY KEY (id)
98
+ );";
99
+
100
+ // Handle DB upgrades in proper WordPress way.
101
+ require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
102
+
103
+ // Update or create table in database.
104
+ dbDelta( $query );
105
+
106
+ // Update the db version number.
107
+ update_option( 'ljk_db_version', LINK_JUICE_KEEPER_VERSION );
108
+ }
109
+
110
+ }
includes/class-link-juice-keeper-deactivator.php ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Fired during plugin deactivation
5
+ *
6
+ * @link https://profiles.wordpress.org/pattihis/
7
+ * @since 2.0.0
8
+ *
9
+ * @package Link_Juice_Keeper
10
+ * @subpackage Link_Juice_Keeper/includes
11
+ */
12
+
13
+ /**
14
+ * Fired during plugin deactivation.
15
+ *
16
+ * This class defines all code necessary to run during the plugin's deactivation.
17
+ *
18
+ * @since 2.0.0
19
+ * @package Link_Juice_Keeper
20
+ * @subpackage Link_Juice_Keeper/includes
21
+ * @author George Pattihis <gpattihis@gmail.com>
22
+ */
23
+ class Link_Juice_Keeper_Deactivator {
24
+
25
+ /**
26
+ * Short Description. (use period)
27
+ *
28
+ * Long Description.
29
+ *
30
+ * @since 2.0.0
31
+ */
32
+ public static function deactivate() {
33
+
34
+ }
35
+
36
+ }
includes/class-link-juice-keeper-i18n.php ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Define the internationalization functionality
5
+ *
6
+ * Loads and defines the internationalization files for this plugin
7
+ * so that it is ready for translation.
8
+ *
9
+ * @link https://profiles.wordpress.org/pattihis/
10
+ * @since 2.0.0
11
+ *
12
+ * @package Link_Juice_Keeper
13
+ * @subpackage Link_Juice_Keeper/includes
14
+ */
15
+
16
+ /**
17
+ * Define the internationalization functionality.
18
+ *
19
+ * Loads and defines the internationalization files for this plugin
20
+ * so that it is ready for translation.
21
+ *
22
+ * @since 2.0.0
23
+ * @package Link_Juice_Keeper
24
+ * @subpackage Link_Juice_Keeper/includes
25
+ * @author George Pattihis <gpattihis@gmail.com>
26
+ */
27
+ class Link_Juice_Keeper_i18n {
28
+
29
+
30
+ /**
31
+ * Load the plugin text domain for translation.
32
+ *
33
+ * @since 2.0.0
34
+ */
35
+ public function load_plugin_textdomain() {
36
+
37
+ load_plugin_textdomain(
38
+ 'link-juice-keeper',
39
+ false,
40
+ dirname( dirname( plugin_basename( __FILE__ ) ) ) . '/languages/'
41
+ );
42
+
43
+ }
44
+
45
+
46
+
47
+ }
includes/class-link-juice-keeper-loader.php ADDED
@@ -0,0 +1,129 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Register all actions and filters for the plugin
5
+ *
6
+ * @link https://profiles.wordpress.org/pattihis/
7
+ * @since 2.0.0
8
+ *
9
+ * @package Link_Juice_Keeper
10
+ * @subpackage Link_Juice_Keeper/includes
11
+ */
12
+
13
+ /**
14
+ * Register all actions and filters for the plugin.
15
+ *
16
+ * Maintain a list of all hooks that are registered throughout
17
+ * the plugin, and register them with the WordPress API. Call the
18
+ * run function to execute the list of actions and filters.
19
+ *
20
+ * @package Link_Juice_Keeper
21
+ * @subpackage Link_Juice_Keeper/includes
22
+ * @author George Pattihis <gpattihis@gmail.com>
23
+ */
24
+ class Link_Juice_Keeper_Loader {
25
+
26
+ /**
27
+ * The array of actions registered with WordPress.
28
+ *
29
+ * @since 2.0.0
30
+ * @access protected
31
+ * @var array $actions The actions registered with WordPress to fire when the plugin loads.
32
+ */
33
+ protected $actions;
34
+
35
+ /**
36
+ * The array of filters registered with WordPress.
37
+ *
38
+ * @since 2.0.0
39
+ * @access protected
40
+ * @var array $filters The filters registered with WordPress to fire when the plugin loads.
41
+ */
42
+ protected $filters;
43
+
44
+ /**
45
+ * Initialize the collections used to maintain the actions and filters.
46
+ *
47
+ * @since 2.0.0
48
+ */
49
+ public function __construct() {
50
+
51
+ $this->actions = array();
52
+ $this->filters = array();
53
+
54
+ }
55
+
56
+ /**
57
+ * Add a new action to the collection to be registered with WordPress.
58
+ *
59
+ * @since 2.0.0
60
+ * @param string $hook The name of the WordPress action that is being registered.
61
+ * @param object $component A reference to the instance of the object on which the action is defined.
62
+ * @param string $callback The name of the function definition on the $component.
63
+ * @param int $priority Optional. The priority at which the function should be fired. Default is 10.
64
+ * @param int $accepted_args Optional. The number of arguments that should be passed to the $callback. Default is 1.
65
+ */
66
+ public function add_action( $hook, $component, $callback, $priority = 10, $accepted_args = 1 ) {
67
+ $this->actions = $this->add( $this->actions, $hook, $component, $callback, $priority, $accepted_args );
68
+ }
69
+
70
+ /**
71
+ * Add a new filter to the collection to be registered with WordPress.
72
+ *
73
+ * @since 2.0.0
74
+ * @param string $hook The name of the WordPress filter that is being registered.
75
+ * @param object $component A reference to the instance of the object on which the filter is defined.
76
+ * @param string $callback The name of the function definition on the $component.
77
+ * @param int $priority Optional. The priority at which the function should be fired. Default is 10.
78
+ * @param int $accepted_args Optional. The number of arguments that should be passed to the $callback. Default is 1
79
+ */
80
+ public function add_filter( $hook, $component, $callback, $priority = 10, $accepted_args = 1 ) {
81
+ $this->filters = $this->add( $this->filters, $hook, $component, $callback, $priority, $accepted_args );
82
+ }
83
+
84
+ /**
85
+ * A utility function that is used to register the actions and hooks into a single
86
+ * collection.
87
+ *
88
+ * @since 2.0.0
89
+ * @access private
90
+ * @param array $hooks The collection of hooks that is being registered (that is, actions or filters).
91
+ * @param string $hook The name of the WordPress filter that is being registered.
92
+ * @param object $component A reference to the instance of the object on which the filter is defined.
93
+ * @param string $callback The name of the function definition on the $component.
94
+ * @param int $priority The priority at which the function should be fired.
95
+ * @param int $accepted_args The number of arguments that should be passed to the $callback.
96
+ * @return array The collection of actions and filters registered with WordPress.
97
+ */
98
+ private function add( $hooks, $hook, $component, $callback, $priority, $accepted_args ) {
99
+
100
+ $hooks[] = array(
101
+ 'hook' => $hook,
102
+ 'component' => $component,
103
+ 'callback' => $callback,
104
+ 'priority' => $priority,
105
+ 'accepted_args' => $accepted_args
106
+ );
107
+
108
+ return $hooks;
109
+
110
+ }
111
+
112
+ /**
113
+ * Register the filters and actions with WordPress.
114
+ *
115
+ * @since 2.0.0
116
+ */
117
+ public function run() {
118
+
119
+ foreach ( $this->filters as $hook ) {
120
+ add_filter( $hook['hook'], array( $hook['component'], $hook['callback'] ), $hook['priority'], $hook['accepted_args'] );
121
+ }
122
+
123
+ foreach ( $this->actions as $hook ) {
124
+ add_action( $hook['hook'], array( $hook['component'], $hook['callback'] ), $hook['priority'], $hook['accepted_args'] );
125
+ }
126
+
127
+ }
128
+
129
+ }
includes/class-link-juice-keeper.php ADDED
@@ -0,0 +1,232 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * The file that defines the core plugin class
5
+ *
6
+ * A class definition that includes attributes and functions used across both the
7
+ * public-facing side of the site and the admin area.
8
+ *
9
+ * @link https://profiles.wordpress.org/pattihis/
10
+ * @since 2.0.0
11
+ *
12
+ * @package Link_Juice_Keeper
13
+ * @subpackage Link_Juice_Keeper/includes
14
+ */
15
+
16
+ /**
17
+ * The core plugin class.
18
+ *
19
+ * This is used to define internationalization, admin-specific hooks, and
20
+ * public-facing site hooks.
21
+ *
22
+ * Also maintains the unique identifier of this plugin as well as the current
23
+ * version of the plugin.
24
+ *
25
+ * @since 2.0.0
26
+ * @package Link_Juice_Keeper
27
+ * @subpackage Link_Juice_Keeper/includes
28
+ * @author George Pattihis <gpattihis@gmail.com>
29
+ */
30
+ class Link_Juice_Keeper {
31
+
32
+ /**
33
+ * The loader that's responsible for maintaining and registering all hooks that power
34
+ * the plugin.
35
+ *
36
+ * @since 2.0.0
37
+ * @access protected
38
+ * @var Link_Juice_Keeper_Loader $loader Maintains and registers all hooks for the plugin.
39
+ */
40
+ protected $loader;
41
+
42
+ /**
43
+ * The unique identifier of this plugin.
44
+ *
45
+ * @since 2.0.0
46
+ * @access protected
47
+ * @var string $plugin_name The string used to uniquely identify this plugin.
48
+ */
49
+ protected $plugin_name;
50
+
51
+ /**
52
+ * The current version of the plugin.
53
+ *
54
+ * @since 2.0.0
55
+ * @access protected
56
+ * @var string $version The current version of the plugin.
57
+ */
58
+ protected $version;
59
+
60
+ /**
61
+ * Define the core functionality of the plugin.
62
+ *
63
+ * Set the plugin name and the plugin version that can be used throughout the plugin.
64
+ * Load the dependencies, define the locale, and set the hooks for the admin area and
65
+ * the public-facing side of the site.
66
+ *
67
+ * @since 2.0.0
68
+ */
69
+ public function __construct() {
70
+ if ( defined( 'LINK_JUICE_KEEPER_VERSION' ) ) {
71
+ $this->version = LINK_JUICE_KEEPER_VERSION;
72
+ } else {
73
+ $this->version = '2.0.0';
74
+ }
75
+ $this->plugin_name = 'link-juice-keeper';
76
+
77
+ $this->load_dependencies();
78
+ $this->set_locale();
79
+ $this->define_admin_hooks();
80
+ $this->define_public_hooks();
81
+
82
+ }
83
+
84
+ /**
85
+ * Load the required dependencies for this plugin.
86
+ *
87
+ * Include the following files that make up the plugin:
88
+ *
89
+ * - Link_Juice_Keeper_Loader. Orchestrates the hooks of the plugin.
90
+ * - Link_Juice_Keeper_i18n. Defines internationalization functionality.
91
+ * - Link_Juice_Keeper_Admin. Defines all hooks for the admin area.
92
+ * - Link_Juice_Keeper_Public. Defines all hooks for the public side of the site.
93
+ *
94
+ * Create an instance of the loader which will be used to register the hooks
95
+ * with WordPress.
96
+ *
97
+ * @since 2.0.0
98
+ * @access private
99
+ */
100
+ private function load_dependencies() {
101
+
102
+ /**
103
+ * The class responsible for orchestrating the actions and filters of the
104
+ * core plugin.
105
+ */
106
+ require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-link-juice-keeper-loader.php';
107
+
108
+ /**
109
+ * The class responsible for defining internationalization functionality
110
+ * of the plugin.
111
+ */
112
+ require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-link-juice-keeper-i18n.php';
113
+
114
+ /**
115
+ * The class responsible for defining all actions that occur in the admin area.
116
+ */
117
+ require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-link-juice-keeper-admin.php';
118
+
119
+ /**
120
+ * The class responsible for displaying logs in a WP_List_Table format
121
+ */
122
+ require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-link-juice-keeper-logs.php';
123
+
124
+ /**
125
+ * The class responsible for defining all actions that occur in the public-facing
126
+ * side of the site.
127
+ */
128
+ require_once plugin_dir_path( dirname( __FILE__ ) ) . 'public/class-link-juice-keeper-public.php';
129
+
130
+ $this->loader = new Link_Juice_Keeper_Loader();
131
+
132
+ }
133
+
134
+ /**
135
+ * Define the locale for this plugin for internationalization.
136
+ *
137
+ * Uses the Link_Juice_Keeper_i18n class in order to set the domain and to register the hook
138
+ * with WordPress.
139
+ *
140
+ * @since 2.0.0
141
+ * @access private
142
+ */
143
+ private function set_locale() {
144
+
145
+ $plugin_i18n = new Link_Juice_Keeper_i18n();
146
+
147
+ $this->loader->add_action( 'plugins_loaded', $plugin_i18n, 'load_plugin_textdomain' );
148
+
149
+ }
150
+
151
+ /**
152
+ * Register all of the hooks related to the admin area functionality
153
+ * of the plugin.
154
+ *
155
+ * @since 2.0.0
156
+ * @access private
157
+ */
158
+ private function define_admin_hooks() {
159
+
160
+ $plugin_admin = new Link_Juice_Keeper_Admin( $this->get_plugin_name(), $this->get_version() );
161
+
162
+ $this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_styles' );
163
+ $this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_scripts' );
164
+
165
+ // admin setup
166
+ $this->loader->add_filter( 'admin_init', $plugin_admin, 'add_buffer' );
167
+ $this->loader->add_action( 'admin_init', $plugin_admin, 'register_settings' );
168
+ $this->loader->add_action( 'admin_menu', $plugin_admin, 'linkJuiceKeeper_admin_menu' );
169
+
170
+
171
+ }
172
+
173
+ /**
174
+ * Register all of the hooks related to the public-facing functionality
175
+ * of the plugin.
176
+ *
177
+ * @since 2.0.0
178
+ * @access private
179
+ */
180
+ private function define_public_hooks() {
181
+
182
+ $plugin_public = new Link_Juice_Keeper_Public( $this->get_plugin_name(), $this->get_version() );
183
+
184
+ $this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'enqueue_styles' );
185
+ $this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'enqueue_scripts' );
186
+
187
+ // init 404 actions
188
+ $this->loader->add_action( 'template_redirect', $plugin_public, 'handle_404' );
189
+
190
+ }
191
+
192
+ /**
193
+ * Run the loader to execute all of the hooks with WordPress.
194
+ *
195
+ * @since 2.0.0
196
+ */
197
+ public function run() {
198
+ $this->loader->run();
199
+ }
200
+
201
+ /**
202
+ * The name of the plugin used to uniquely identify it within the context of
203
+ * WordPress and to define internationalization functionality.
204
+ *
205
+ * @since 2.0.0
206
+ * @return string The name of the plugin.
207
+ */
208
+ public function get_plugin_name() {
209
+ return $this->plugin_name;
210
+ }
211
+
212
+ /**
213
+ * The reference to the class that orchestrates the hooks with the plugin.
214
+ *
215
+ * @since 2.0.0
216
+ * @return Link_Juice_Keeper_Loader Orchestrates the hooks of the plugin.
217
+ */
218
+ public function get_loader() {
219
+ return $this->loader;
220
+ }
221
+
222
+ /**
223
+ * Retrieve the version number of the plugin.
224
+ *
225
+ * @since 2.0.0
226
+ * @return string The version number of the plugin.
227
+ */
228
+ public function get_version() {
229
+ return $this->version;
230
+ }
231
+
232
+ }
includes/index.php ADDED
@@ -0,0 +1 @@
 
1
+ <?php // Silence is golden
index.php ADDED
@@ -0,0 +1 @@
 
1
+ <?php // Silence is golden
languages/link-juice-keeper.pot ADDED
File without changes
link-juice-keeper.php CHANGED
@@ -1,73 +1,121 @@
1
- <?php
2
- /*
3
- Plugin Name: Link Juice Keeper
4
- Plugin URI: http://www.poradnik-webmastera.com/projekty/link_juice_keeper/
5
- Description: This plugin helps you to keep the link juice by redirecting all non-existing URLs which normally return a 404 error to the front blog page using 301 redirect.
6
- Author: Daniel Frużyński
7
- Version: 1.2.3
8
- Author URI: http://www.poradnik-webmastera.com/
9
- License: GPL2
10
- */
11
-
12
- /* Copyright 2009,2011 Daniel Frużyński (email : daniel [A-T] poradnik-webmastera.com)
13
-
14
- This program is free software; you can redistribute it and/or modify
15
- it under the terms of the GNU General Public License, version 2, as
16
- published by the Free Software Foundation.
17
-
18
- This program is distributed in the hope that it will be useful,
19
- but WITHOUT ANY WARRANTY; without even the implied warranty of
20
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21
- GNU General Public License for more details.
22
-
23
- You should have received a copy of the GNU General Public License
24
- along with this program; if not, write to the Free Software
25
- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
26
- */
27
-
28
-
29
- if ( !class_exists( 'LinkJuiceKeeper' ) || ( defined( 'WP_DEBUG' ) && WP_DEBUG ) ) {
30
-
31
- class LinkJuiceKeeper {
32
- // Constructor
33
- function LinkJuiceKeeper() {
34
-
35
- //add_action( 'init', array( &$this, 'init' ) );
36
-
37
- add_filter( 'status_header', array( &$this, 'status_header' ), 100, 2 );
38
- }
39
-
40
- /*// Initialise plugin
41
- function init() {
42
- if ( function_exists( 'load_plugin_textdomain' ) ) {
43
- load_plugin_textdomain( 'link-juice-keeper', PLUGINDIR.'/'.dirname(plugin_basename(__FILE__)) );
44
- }
45
- }*/
46
-
47
- function status_header( $status_header, $header ) {
48
- if ( $header == 404 ) {
49
- // Extract root dir from blog url
50
- $root = '/';
51
- if ( preg_match( '#^http://[^/]+(/.+)$#', get_option( 'siteurl' ), $matches ) ) {
52
- $root = $matches[1];
53
- }
54
- // Make sure it ends with slash
55
- if ( $root[ strlen($root) - 1 ] != '/' ) {
56
- $root .= '/';
57
- }
58
- // Check if request is not for GWT verification file
59
- if ( strpos( $_SERVER['REQUEST_URI'], $root.'noexist_' ) !== 0 ) {
60
- wp_redirect( get_bloginfo( 'siteurl' ) , 301 );
61
- exit();
62
- }
63
- }
64
-
65
- return $status_header;
66
- }
67
- }
68
-
69
- $wp_link_juice_keeper = new LinkJuiceKeeper();
70
-
71
- } // END
72
-
73
- ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Link Juice Keeper
4
+ *
5
+ * @package Link_Juice_Keeper
6
+ * @author George Pattihis
7
+ * @copyright 2021 George Pattihis
8
+ * @license GPL-2.0-or-later
9
+ * @link https://profiles.wordpress.org/pattihis/
10
+ * @since 2.0.0
11
+ *
12
+ * @wordpress-plugin
13
+ * Plugin Name: Link Juice Keeper
14
+ * Plugin URI: https://wordpress.org/plugins/link-juice-keeper/
15
+ * Description: Improve your SEO and keep your link juice by automatically redirecting all 404 errors to any page/post/url. User friendly options and log feature.
16
+ * Version: 2.0.0
17
+ * Requires at least: 5.2
18
+ * Requires PHP: 7.2
19
+ * Author: George Pattihis
20
+ * Author URI: https://profiles.wordpress.org/pattihis/
21
+ * License: GPL-2.0+
22
+ * License URI: http://www.gnu.org/licenses/gpl-2.0.txt
23
+ * Text Domain: link-juice-keeper
24
+ * Domain Path: /languages
25
+ */
26
+
27
+ /* Copyright 2009,2011 Daniel Frużyński (daniel@poradnik-webmastera.com)
28
+
29
+ This program is free software; you can redistribute it and/or modify
30
+ it under the terms of the GNU General Public License, version 2, as
31
+ published by the Free Software Foundation.
32
+
33
+ This program is distributed in the hope that it will be useful,
34
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
35
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
36
+ GNU General Public License for more details.
37
+
38
+ You should have received a copy of the GNU General Public License
39
+ along with this program; if not, write to the Free Software
40
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
41
+ */
42
+
43
+ /* Copyright 2021 George Pattihis (gpattihis@gmail.com)
44
+
45
+ "Link Juice Keeper" is free software: you can redistribute it and/or modify
46
+ it under the terms of the GNU General Public License as published by
47
+ the Free Software Foundation, either version 2 of the License, or
48
+ any later version.
49
+
50
+ "Link Juice Keeper" is distributed in the hope that it will be useful,
51
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
52
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
53
+ GNU General Public License for more details.
54
+
55
+ You should have received a copy of the GNU General Public License
56
+ "along with Link Juice Keeper". If not, see http://www.gnu.org/licenses/gpl-2.0.txt.
57
+ */
58
+
59
+ // If this file is called directly, abort.
60
+ if ( ! defined( 'WPINC' ) ) {
61
+ die;
62
+ }
63
+
64
+ /**
65
+ * Current plugin version.
66
+ */
67
+ define( 'LINK_JUICE_KEEPER_VERSION', '2.0.0' );
68
+
69
+ /**
70
+ * The code that runs during plugin activation.
71
+ * This action is documented in includes/class-link-juice-keeper-activator.php
72
+ */
73
+ function activate_link_juice_keeper($network_wide) {
74
+ require_once plugin_dir_path( __FILE__ ) . 'includes/class-link-juice-keeper-activator.php';
75
+
76
+ if ( is_multisite() && $network_wide ) {
77
+ foreach (get_sites(['fields'=>'ids']) as $blog_id) {
78
+ switch_to_blog($blog_id);
79
+ Link_Juice_Keeper_Activator::activate();
80
+ restore_current_blog();
81
+ }
82
+ } else {
83
+ Link_Juice_Keeper_Activator::activate();
84
+ }
85
+
86
+ }
87
+
88
+ /**
89
+ * The code that runs during plugin deactivation.
90
+ * This action is documented in includes/class-link-juice-keeper-deactivator.php
91
+ */
92
+ function deactivate_link_juice_keeper() {
93
+ require_once plugin_dir_path( __FILE__ ) . 'includes/class-link-juice-keeper-deactivator.php';
94
+ Link_Juice_Keeper_Deactivator::deactivate();
95
+ }
96
+
97
+ register_activation_hook( __FILE__, 'activate_link_juice_keeper' );
98
+ register_deactivation_hook( __FILE__, 'deactivate_link_juice_keeper' );
99
+
100
+ /**
101
+ * The core plugin class that is used to define internationalization,
102
+ * admin-specific hooks, and public-facing site hooks.
103
+ */
104
+ require plugin_dir_path( __FILE__ ) . 'includes/class-link-juice-keeper.php';
105
+
106
+ /**
107
+ * Begins execution of the plugin.
108
+ *
109
+ * Since everything within the plugin is registered via hooks,
110
+ * then kicking off the plugin from this point in the file does
111
+ * not affect the page life cycle.
112
+ *
113
+ * @since 2.0.0
114
+ */
115
+ function run_link_juice_keeper() {
116
+
117
+ $plugin = new Link_Juice_Keeper();
118
+ $plugin->run();
119
+
120
+ }
121
+ run_link_juice_keeper();
public/class-link-juice-keeper-public.php ADDED
@@ -0,0 +1,268 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * The public-facing functionality of the plugin.
5
+ *
6
+ * @link https://profiles.wordpress.org/pattihis/
7
+ * @since 2.0.0
8
+ *
9
+ * @package Link_Juice_Keeper
10
+ * @subpackage Link_Juice_Keeper/public
11
+ */
12
+
13
+ /**
14
+ * The public-facing functionality of the plugin.
15
+ *
16
+ * Defines the plugin name, version, and two examples hooks for how to
17
+ * enqueue the public-facing stylesheet and JavaScript.
18
+ *
19
+ * @package Link_Juice_Keeper
20
+ * @subpackage Link_Juice_Keeper/public
21
+ * @author George Pattihis <gpattihis@gmail.com>
22
+ */
23
+ class Link_Juice_Keeper_Public {
24
+
25
+ /**
26
+ * The ID of this plugin.
27
+ *
28
+ * @since 2.0.0
29
+ * @access private
30
+ * @var string $plugin_name The ID of this plugin.
31
+ */
32
+ private $plugin_name;
33
+
34
+ /**
35
+ * The version of this plugin.
36
+ *
37
+ * @since 2.0.0
38
+ * @access private
39
+ * @var string $version The current version of this plugin.
40
+ */
41
+ private $version;
42
+
43
+ /**
44
+ * Initialize the class and set its properties.
45
+ *
46
+ * @since 2.0.0
47
+ * @param string $plugin_name The name of the plugin.
48
+ * @param string $version The version of this plugin.
49
+ */
50
+ public function __construct( $plugin_name, $version ) {
51
+
52
+ $this->plugin_name = $plugin_name;
53
+ $this->version = $version;
54
+
55
+ }
56
+
57
+ /**
58
+ * Register the stylesheets for the public-facing side of the site.
59
+ *
60
+ * @since 2.0.0
61
+ */
62
+ public function enqueue_styles() {
63
+
64
+ wp_enqueue_style( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'css/link-juice-keeper-public.css', array(), $this->version, 'all' );
65
+
66
+ }
67
+
68
+ /**
69
+ * Register the JavaScript for the public-facing side of the site.
70
+ *
71
+ * @since 2.0.0
72
+ */
73
+ public function enqueue_scripts() {
74
+
75
+ wp_enqueue_script( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'js/link-juice-keeper-public.js', array( 'jquery' ), $this->version, false );
76
+
77
+ }
78
+
79
+ /**
80
+ * Execute 404 actions.
81
+ *
82
+ * Perform required actions when 404 is encountered.
83
+ * Log error details, Alert via email, Redirect.
84
+ *
85
+ * @since 2.0.0
86
+ * @access public
87
+ *
88
+ * @return void
89
+ */
90
+ public function handle_404() {
91
+
92
+ if ( ! is_404() || is_admin() ) {
93
+ return;
94
+ }
95
+
96
+ $plugin_admin = new Link_Juice_Keeper_Admin('link-juice-keeper', LINK_JUICE_KEEPER_VERSION );
97
+
98
+ // Get redirect target
99
+ $to = $plugin_admin->linkJuiceKeeper_get_option( 'redirect_to' );
100
+ if ( 'home' === $to ) {
101
+ $target = get_home_url();
102
+ } elseif ( 'page' === $to ) {
103
+ $target = get_permalink( $plugin_admin->linkJuiceKeeper_get_option( 'redirect_page' ) );
104
+ } elseif ( 'post' === $to ) {
105
+ $target = get_permalink( $plugin_admin->linkJuiceKeeper_get_option( 'redirect_post' ) );
106
+ } elseif ( 'link' === $to ) {
107
+ $target = $plugin_admin->linkJuiceKeeper_get_option( 'redirect_link' );
108
+ }
109
+
110
+ if ( '0' == $to ) {
111
+ return;
112
+ } else {
113
+
114
+ // Get redirect type
115
+ $options = get_option( 'ljk_main_settings' );
116
+ $type = $options['redirect_type'];
117
+
118
+ // Get incident details
119
+ $this->get_data();
120
+
121
+ // Log error details to database
122
+ $this->log_error( (bool)$options['redirect_log'] );
123
+
124
+ // Send email notification
125
+ $this->email_alert( (bool)$options['email_notify'] );
126
+
127
+ // Redirect the user.
128
+ $this->redirect( $type, $target );
129
+
130
+ }
131
+
132
+ }
133
+
134
+ /**
135
+ * Collect data about the incident and save in array
136
+ *
137
+ * @since 2.0.0
138
+ * @access public
139
+ *
140
+ * @return void
141
+ */
142
+ public function get_data() {
143
+ global $ljk_track_data;
144
+
145
+ // Set visitor's IP address.
146
+ $ips = array( 'HTTP_CLIENT_IP', 'HTTP_X_FORWARDED_FOR', 'REMOTE_ADDR' );
147
+ foreach ( $ips as $ip ) {
148
+ if ( isset( $_SERVER[ $ip ] ) ) {
149
+ $ip = esc_attr( $_SERVER[ $ip ] );
150
+ }
151
+ }
152
+
153
+ // Set visitor's user agent/browser.
154
+ if ( isset( $_SERVER['HTTP_USER_AGENT'] ) ) {
155
+ $ua = esc_attr( $_SERVER['HTTP_USER_AGENT'] );
156
+ }
157
+
158
+ // Set visitor's referring link.
159
+ if ( isset( $_SERVER['HTTP_REFERER'] ) ) {
160
+ $ref = esc_url( $_SERVER['HTTP_REFERER'] );
161
+ }
162
+
163
+ // Set visitor's referring link
164
+ if ( isset( $_SERVER['REQUEST_URI'] ) ) {
165
+ $url = untrailingslashit( esc_url( $_SERVER['REQUEST_URI'] ) );
166
+ }
167
+
168
+ // Set current time.
169
+ $time = current_time( 'mysql' );
170
+
171
+ $ljk_track_data = array(
172
+ 'date' => $time,
173
+ 'ip' => $ip,
174
+ 'url' => $url,
175
+ 'ref' => is_null($ref) ? '' : $ref,
176
+ 'ua' => $ua,
177
+ 'status' => 1,
178
+ );
179
+ }
180
+
181
+ /**
182
+ * Log details of error to the database.
183
+ *
184
+ * @since 2.0.0
185
+ * @access public
186
+ *
187
+ * @return void
188
+ */
189
+ public function log_error( $enabled ) {
190
+
191
+ if ( ! $enabled ) {
192
+ return;
193
+ }
194
+
195
+ global $wpdb;
196
+ global $ljk_track_data;
197
+ $save_data = [];
198
+ $table = $wpdb->prefix . 'link_juice_keeper';
199
+
200
+ if ( is_array( $ljk_track_data ) ) {
201
+ $save_data = array_map( 'sanitize_text_field', $ljk_track_data );
202
+
203
+ // Insert data to database
204
+ $wpdb->insert( $table, $save_data );
205
+ }
206
+
207
+ }
208
+
209
+ /**
210
+ * Send email about the error.
211
+ *
212
+ * @since 2.0.0
213
+ * @access public
214
+ *
215
+ * @return void
216
+ */
217
+ public function email_alert( $enabled ) {
218
+
219
+ if ( ! $enabled ) {
220
+ return;
221
+ }
222
+
223
+ global $ljk_track_data;
224
+
225
+ // Recipient
226
+ $options = get_option( 'ljk_main_settings' );
227
+ $notify_to = ( !empty( $options['notify_to'] ) ) ? $options['notify_to'] : get_option( 'admin_email' );
228
+ // Headers
229
+ $headers = array('Content-Type: text/html; charset=UTF-8');
230
+ // Subject
231
+ $subject = __( 'A 404 Not Found error at ', 'link-juice-keeper' ) . get_bloginfo( 'name' );
232
+ // Email Body
233
+ $body = '<p>' . __( 'Notice: One more 404 error has just happened on your website at ', 'link-juice-keeper' ) . get_home_url().'</p>';
234
+ $body .= '<p>' . __( 'If you have enabled 404 redirection then visitor was sent to your selected page and you can ignore this message', 'link-juice-keeper' ) . '</p>';
235
+ $body .= '<table>';
236
+ $body .= '<tr><th align="left">' . __( '404 Not Found', 'link-juice-keeper' ) . ': </th><td align="left">' . $ljk_track_data['url'] . '</td></tr>';
237
+ $body .= '<tr><th align="left">' . __( 'Visitor IP', 'link-juice-keeper' ) . ': </th><td align="left">' . $ljk_track_data['ip'] . '</td></tr>';
238
+ $body .= '<tr><th align="left">' . __( 'Time', 'link-juice-keeper' ) . ': </th><td align="left">' . $ljk_track_data['date'] . '</td></tr>';
239
+ $body .= '<tr><th align="left">' . __( 'Referrer', 'link-juice-keeper' ) . ': </th><td align="left">' . $ljk_track_data['ref'] . '</td></tr>';
240
+ $body .= '</table>';
241
+ $body .= '<p>' . sprintf( __( 'Alert sent by the %sLink Juice Keeper%s plugin for WordPress.', 'link-juice-keeper' ), '<strong>', '</strong>' ) . '</p>';
242
+
243
+ //Send email enotifcation
244
+ wp_mail( $notify_to, $subject, $body, $headers );
245
+ }
246
+
247
+ /**
248
+ * Redirect 404 errors
249
+ *
250
+ * @since 2.0.0
251
+ * @return void
252
+ */
253
+ public function redirect( $type, $target) {
254
+
255
+ if ( empty( $target ) ) {
256
+ return;
257
+ } else {
258
+ // Perform redirect using WordPress function
259
+ wp_redirect( $target, $type );
260
+ // WordPress will not exit automatically
261
+ exit;
262
+ }
263
+
264
+ }
265
+
266
+
267
+
268
+ }
public/css/link-juice-keeper-public.css ADDED
@@ -0,0 +1,4 @@
 
 
 
 
1
+ /**
2
+ * All of the CSS for your public-facing functionality should be
3
+ * included in this file.
4
+ */
public/index.php ADDED
@@ -0,0 +1 @@
 
1
+ <?php // Silence is golden
public/js/link-juice-keeper-public.js ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ (function( $ ) {
2
+ 'use strict';
3
+
4
+ /**
5
+ * All of the code for your public-facing JavaScript source
6
+ * should reside in this file.
7
+ *
8
+ * Note: It has been assumed you will write jQuery code here, so the
9
+ * $ function reference has been prepared for usage within the scope
10
+ * of this function.
11
+ *
12
+ * This enables you to define handlers, for when the DOM is ready:
13
+ *
14
+ * $(function() {
15
+ *
16
+ * });
17
+ *
18
+ * When the window is loaded:
19
+ *
20
+ * $( window ).load(function() {
21
+ *
22
+ * });
23
+ *
24
+ * ...and/or other possibilities.
25
+ *
26
+ * Ideally, it is not considered best practise to attach more than a
27
+ * single DOM-ready or window-load handler for a particular page.
28
+ * Although scripts in the WordPress core, Plugins and Themes may be
29
+ * practising this, we should strive to set a better example in our own work.
30
+ */
31
+
32
+ })( jQuery );
public/partials/link-juice-keeper-public-display.php ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Provide a public-facing view for the plugin
5
+ *
6
+ * This file is used to markup the public-facing aspects of the plugin.
7
+ *
8
+ * @link https://profiles.wordpress.org/pattihis/
9
+ * @since 2.0.0
10
+ *
11
+ * @package Link_Juice_Keeper
12
+ * @subpackage Link_Juice_Keeper/public/partials
13
+ */
14
+ ?>
15
+
16
+ <!-- This file should primarily consist of HTML with a little bit of PHP. -->
readme.html DELETED
@@ -1,78 +0,0 @@
1
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
2
- <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
3
- <head>
4
- <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
5
- <title>Link Juice Keeper 1.2.3 Readme</title>
6
- </head>
7
- <body>
8
- <h1>Link Juice Keeper 1.2.3 Readme</h1>
9
- <p>This plugin helps you to keep the link juice by redirecting all non-existing URLs which normally return a 404 error to the blog front page using 301 redirect.</p>
10
- <p><b>Plugin Homepage:</b> <a href="http://www.poradnik-webmastera.com/projekty/link_juice_keeper/">Link Juice Keeper</a></p>
11
- <p><b>Plugin Homepage on WordPress.org:</b> <a href="http://wordpress.org/extend/plugins/link-juice-keeper/">Link Juice Keeper</a></p>
12
- <p><b>Author Homepage:</b> <a href="http://www.poradnik-webmastera.com/">Poradnik Webmastera</a></p>
13
- <p><b>Author:</b> Daniel Frużyński</p>
14
-
15
- <h2>Description</h2>
16
- <p>As you probably know, incoming links play important role in ranking well in Google and other search engines. Therefore you should assure that every incoming link leads to one of pages on your blog. This may be a challenge, because World Wide Web is dynamic and changes every day:</p>
17
- <ul>
18
- <li>you can remove some posts or pages on your blog;</li>
19
- <li>you can change URL scheme on whole blog;</li>
20
- <li>incoming links may became broken (e.g. due to some automatic text formatting);</li>
21
- <li>someone may simply put wrong (broken) link somewhere.</li>
22
- </ul>
23
- <p>All of the above leads to link juice waste. You can avoid this by using this plugin. It redirects all non-existing URLs which normally return a 404 error to the blog front page using 301 (permanent) redirect. This way everyone who comes to your blog via broken link (both people and robots) will be redirected to the front page.</p>
24
- <p>The only one exception are files in root blog directory with names starting with `noexist_`. They are used by Google to verify page in Google Webmasters Tools, so Link Juice Keeper does not redirect them.</p>
25
-
26
- <h2>Installation</h2>
27
- <ol>
28
- <li>Upload <code>link-juice-keeper</code> directory to the <code>/wp-content/plugins/</code> directory</li>
29
- <li>Activate the plugin through the 'Plugins' menu in WordPress</li>
30
- <li>Configure and enjoy :)</li>
31
- </ol>
32
-
33
- <h2>Changelog</h2>
34
- <p>1.2.3</p>
35
- <ul>
36
- <li>Marked as compatible with WP 3.2.x</li>
37
- </ul>
38
- <p>1.2.2</p>
39
- <ul>
40
- <li>Marked as compatible with WP 2.9.x</li>
41
- </ul>
42
- <p>1.2.1</p>
43
- <ul>
44
- <li>Marked as compatible with WP 2.8.5</li>
45
- </ul>
46
- <p>1.2</p>
47
- <ul>
48
- <li>Fix: does not redirect Google Bot doing page verification for Google Webmasters Tools</li>
49
- </ul>
50
- <p>1.1.1</p>
51
- <ul>
52
- <li>Make plugin compatible with WordPress 2.8</li>
53
- </ul>
54
- <p>1.1</p>
55
- <ul>
56
- <li>Decreased filter priority, so now it will run after ones with default priority</li>
57
- </ul>
58
- <p>1.0</p>
59
- <ul>
60
- <li>Initial version</li>
61
- </ul>
62
-
63
- <h2>Licence</h2>
64
- <p>Copyright 2009 Daniel Frużyński (email : daniel [A-T] poradnik-webmastera.com)</p>
65
- <p>This program is free software; you can redistribute it and/or modify
66
- it under the terms of the GNU General Public License as published by
67
- the Free Software Foundation; either version 2 of the License, or
68
- (at your option) any later version.</p>
69
- <p>This program is distributed in the hope that it will be useful,
70
- but WITHOUT ANY WARRANTY; without even the implied warranty of
71
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
72
- GNU General Public License for more details.</p>
73
- <p>You should have received a copy of the GNU General Public License
74
- along with this program; if not, write to the Free Software
75
- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA</p>
76
-
77
- </body>
78
- </html>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
readme.txt CHANGED
@@ -1,52 +1,102 @@
1
- === Plugin Name ===
2
- Contributors: sirzooro
3
- Tags: google, link, links, redirect, seo
4
- Requires at least: 2.2
5
- Tested up to: 3.2.9
6
- Stable tag: 1.2.3
7
-
8
- This plugin helps you to keep the link juice by redirecting all non-existing URLs (they return error 404) to the blog front page using 301 redirect.
9
-
10
- == Description ==
11
-
12
- As you probably know, incoming links play important role in ranking well in Google and other search engines. Therefore you should assure that every incoming link leads to one of pages on your blog. This may be a challenge, because World Wide Web is dynamic and changes every day:
13
-
14
- * you can remove some posts or pages on your blog;
15
- * you can change URL scheme on whole blog;
16
- * incoming links may became broken (e.g. due to some automatic text formatting);
17
- * someone may simply put wrong (broken) link somewhere.
18
-
19
- All of the above leads to link juice waste. You can avoid this by using this plugin. It redirects all non-existing URLs which normally return a 404 error to the blog front page using 301 (permanent) redirect. This way everyone who comes to your blog via broken link (both people and robots) will be redirected to the front page.
20
-
21
- The only one exception are files in root blog directory with names starting with `noexist_`. They are used by Google to verify page in Google Webmasters Tools, so Link Juice Keeper does not redirect them.
22
-
23
- [Changelog](http://wordpress.org/extend/plugins/link-juice-keeper/changelog/)
24
-
25
- == Installation ==
26
-
27
- 1. Upload `link-juice-keeper` directory to the `/wp-content/plugins/` directory
28
- 1. Activate the plugin through the 'Plugins' menu in WordPress
29
- 1. Configure and enjoy :)
30
-
31
- == Changelog ==
32
-
33
- = 1.2.3 =
34
- * Marked as compatible with WP 3.2.x
35
-
36
- = 1.2.2 =
37
- * Marked as compatible with WP 2.9.x
38
-
39
- = 1.2.1 =
40
- * Marked as compatible with WP 2.8.5
41
-
42
- = 1.2 =
43
- * Fix: does not redirect Google Bot doing page verification for Google Webmasters Tools
44
-
45
- = 1.1.1 =
46
- * Make plugin compatible with WordPress 2.8
47
-
48
- = 1.1 =
49
- * Decreased filter priority, so now it will run after ones with default priority
50
-
51
- = 1.0 =
52
- * Initial version
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ === Link Juice Keeper ===
2
+ Contributors: sirzooro, pattihis
3
+ Tags: 404, not found, link, links, error, redirect, seo
4
+ Donate link: https://profiles.wordpress.org/pattihis/
5
+ Requires at least: 3.0.1
6
+ Tested up to: 5.7
7
+ Requires PHP: 5.6
8
+ Stable tag: 2.0.0
9
+ License: GPLv2 or later
10
+ License URI: http://www.gnu.org/licenses/gpl-2.0.html
11
+
12
+ Improve your SEO and keep your link juice by automatically redirecting all 404 errors to any page/post/url. User friendly options and log feature.
13
+
14
+ == Description ==
15
+
16
+ **Error 404** ( `Page not Found` ) is very common and one of the main reasons a search engine, like Google, can give you a lower ranking. Taking steps to handle 404 errors can be complex for non-techy users. With this free plugin you can finally eliminate all 404 errors with just 1 click, once and for all!
17
+
18
+ ### What are 404 errors?
19
+
20
+ As you probably know, incoming links play important role in ranking well in Google and other search engines. Therefore you should assure that every incoming link leads to one of your valid pages on your blog. This may be a challenge because your website is dynamic and it changes every day:
21
+
22
+ * you might remove or unpublish posts or pages;
23
+ * you might change your URL structure on your blog;
24
+ * links may brake because of technical misconfiguration;
25
+ * a webmaster might add your link in their posts with a typo;
26
+ * a visitor may simply mis-type your post's URL
27
+
28
+ Any of the above will lead to link juice waste and a 404 error. You can avoid this simply by installing this plugin.
29
+
30
+ **Link Juice Keeper** redirects all non-existing URLs, that normally return a 404 error, to the page/post of your choice. This way everyone who comes to your blog via a broken link (both people and robots) will be redirected to a valid page.
31
+
32
+ ### Features
33
+
34
+ * You can redirect errors to your homepage, an existing page, post or even a custom link
35
+ * You can optionally monitor/log all 404 errors
36
+ * You can choose which redirect method to be used (301,302,307)
37
+ * You can configure email notifications for every 404 incident
38
+ * Translations ready
39
+ * Free with lifetime updates
40
+ * Build according to best practices and WordPress coding standards
41
+ * Never have a 404 error again!
42
+
43
+ *Link Juice Keeper* was originally developed by [Daniel Frużyński](https://profiles.wordpress.org/sirzooro/). The plugin has been adopted and updated by [George Pattihis](https://profiles.wordpress.org/pattihis/) who will continue development.
44
+
45
+ [Changelog](http://wordpress.org/extend/plugins/link-juice-keeper/changelog/)
46
+
47
+ == Installation ==
48
+
49
+ 1. In your WordPress admin panel, go to Plugins > New Plugin, search for "Link Juice Keeper" and click "Install now"
50
+ 2. Alternatively, download the plugin and upload the contents of link-juice-keeper.zip to your plugins directory, which usually is /wp-content/plugins/
51
+ 3. Activate the plugin
52
+ 4. Go to "link Juice Keeper" tab on your admin menus
53
+ 5. Configure the plugin options with available settings
54
+
55
+ == Frequently Asked Questions ==
56
+
57
+ = When is "Link Juice Keeper" needed? =
58
+
59
+ If you want to automatically handle all 'Page Not Found' errors on your WordpRess website then this plugin is all you need. Install it, enable it and your visitors will never get another 404 error. This way you get to keep all your link juice!
60
+
61
+ = Does it require manual coding or file editing? =
62
+
63
+ Absolutely not. No technical knowledge is needed and with a few clicks you have handled 404 errors once and for all! Check out the screenshots above.
64
+
65
+ = Is "Link Juice Keeper" compatible with my theme/plugins? =
66
+
67
+ Of course! "Link Juice Keeper" is compatible with any theme and plugin that follows WordPress coding standards.
68
+
69
+ == Screenshots ==
70
+
71
+ 1. Plugin settings page
72
+ 2. Log table to monitor 404 errors
73
+
74
+ == Changelog ==
75
+
76
+ = 2.0.0 =
77
+ * Major update - compatible with WP 5.7.x
78
+ * Feature: Select Redirect Type (301, 302, 307)
79
+ * Feature: Select Redirect Target (Home, Page, Post, URL)
80
+ * Feature: Monitor/Log 404 errors
81
+ * Feature: Send Email Alerts about 404
82
+
83
+ = 1.2.3 =
84
+ * Marked as compatible with WP 3.2.x
85
+
86
+ = 1.2.2 =
87
+ * Marked as compatible with WP 2.9.x
88
+
89
+ = 1.2.1 =
90
+ * Marked as compatible with WP 2.8.5
91
+
92
+ = 1.2 =
93
+ * Fix: does not redirect Google Bot doing page verification for Google Webmasters Tools
94
+
95
+ = 1.1.1 =
96
+ * Make plugin compatible with WordPress 2.8
97
+
98
+ = 1.1 =
99
+ * Decreased filter priority, so now it will run after ones with default priority
100
+
101
+ = 1.0 =
102
+ * Initial version
uninstall.php ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Fired when the plugin is uninstalled.
5
+ *
6
+ *
7
+ * @link https://profiles.wordpress.org/pattihis/
8
+ * @since 2.0.0
9
+ *
10
+ * @package Link_Juice_Keeper
11
+ */
12
+
13
+ // If uninstall not called from WordPress, then exit.
14
+ if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) {
15
+ exit;
16
+ }
17
+
18
+ // If we are on a multisite installation clean up all subsites
19
+ if ( is_multisite() ) {
20
+
21
+ foreach (get_sites(['fields'=>'ids']) as $blog_id) {
22
+ switch_to_blog($blog_id);
23
+ linkJuiceKeeper_cleanup();
24
+ restore_current_blog();
25
+ }
26
+
27
+ } else {
28
+ linkJuiceKeeper_cleanup();
29
+ }
30
+
31
+ function linkJuiceKeeper_cleanup(){
32
+
33
+ // Plugin options.
34
+ $options = array(
35
+ 'ljk_main_settings',
36
+ 'ljk_activated_time',
37
+ 'ljk_db_version',
38
+ 'ljk_version_no',
39
+ );
40
+
41
+ // Loop through each option.
42
+ foreach ( $options as $option ) {
43
+ delete_option( $option );
44
+ }
45
+
46
+ global $wpdb;
47
+
48
+ // Drop our custom table.
49
+ $wpdb->query( "DROP TABLE IF EXISTS " . $wpdb->prefix . "link_juice_keeper" );
50
+ }