PluginProbe
SEO Redirection Plugin – 301 Redirect Manager / 9.19
SEO Redirection Plugin – 301 Redirect Manager v9.19
9.19 trunk 4.17 7.1 7.2 7.3 7.4 7.5 7.6 7.7 7.8 7.9 8.1 8.2 8.3 8.4 8.5 8.6 8.7 8.8 8.9 9.1 9.10 9.11 9.12 All 39 releases
seo-redirection / seo-redirection.php

seo-redirection.php in SEO Redirection Plugin – 301 Redirect Manager 9.19, at seo-redirection.php

1,659 lines 71.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /*
3 Plugin Name: SEO Redirection
4 Plugin URI: https://www.wp-buy.com/product/seo-redirection-premium-wordpress-plugin/
5 Description: By this plugin you can manage all your website redirection types easily.
6 Author: wp-buy
7 Version: 9.19
8 Author URI: https://www.wp-buy.com
9 Text Domain: seo-redirection
10 */
11
12 require_once('common/controls.php');
13 require_once('custom/controls.php');
14 require_once('custom/controls/cf.SR_redirect_cache.class.php');
15
16 define('WPSR_PATH', plugin_dir_path(__FILE__));
17
18 if (!defined('WPSR_URL')) define('WPSR_URL', plugin_dir_url(__FILE__));
19
20
21 if (!defined('WP_SEO_REDIRECTION_OPTIONS')) {
22 define('WP_SEO_REDIRECTION_OPTIONS', 'wp-seo-redirection-group');
23 }
24
25 if (!defined('WP_SEO_REDIRECTION_VERSION')) {
26 define('WP_SEO_REDIRECTION_VERSION', 9.17);
27 }
28
29 $util = new clogica_util_1();
30 $util->init(WP_SEO_REDIRECTION_OPTIONS, __FILE__);
31
32
33 add_action('admin_enqueue_scripts', 'WPSR_header_code');
34 add_action('admin_menu', 'WPSR_admin_menu');
35 add_action('wp', 'WPSR_redirect', 1);
36 add_action('save_post', 'WPSR_get_post_redirection');
37 add_action('add_meta_boxes', 'WPSR_adding_custom_meta_boxes', 10, 3);
38 add_action('admin_head', 'WPSR_check_default_permalink');
39 add_action('plugins_loaded', 'WPSR_check_and_upgrade');
40 register_activation_hook(__FILE__, 'WPSR_upgrade');
41
42 register_uninstall_hook(__FILE__, 'WPSR_uninstall');
43
44 /////////////////////////////////////////////////////////////////////////
45
46 if (!function_exists("WPSR__filter_action_links")) {
47 function WPSR__filter_action_links($links)
48 {
49 $links['settings'] = sprintf('<a href="%s">Settings</a>', admin_url('options-general.php?page=seo-redirection.php'));
50 $network_dir_append = "";
51 if (is_multisite()) $network_dir_append = "network/";
52 $links['MorePlugins'] = sprintf('<a href="%s"><b style="color:#f18500">More Plugins</b></a>', admin_url($network_dir_append . 'plugin-install.php?s=wp-buy&tab=search&type=author'));
53 return $links;
54 }
55 add_filter('plugin_action_links_' . plugin_basename(__FILE__), 'WPSR__filter_action_links', 10, 1);
56 }
57
58 /////////////////////////////////////////////////////////////////////////
59 if (!function_exists("WPSR_add_link_to_admin_bar")) {
60 function WPSR_add_link_to_admin_bar($wp_admin_bar)
61 {
62 global $util;
63
64 if (current_user_can('manage_options')) {
65
66 global $wpdb;
67
68 if (!is_admin_bar_showing()) {
69 return;
70 }
71
72 $table_name = $wpdb->prefix . 'WP_SEO_Redirection';
73
74 $current_url = (is_ssl() ? 'https://' : 'http://') . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
75 $relative_url = str_replace(home_url(), '', $current_url);
76
77 $imgpath = $util->get_plugin_url() . 'custom/images/';
78
79 $wp_admin_bar->add_node(array(
80 'id' => 'seo_redirection',
81 'title' => '<img src="' . $imgpath . 'icon.png" style="width: 20px; height: 20px; vertical-align: middle;" alt="Icon" /> SEO Redirection',
82 'href' => '#',
83 'meta' => array(
84 'class' => 'seo-redirection-admin-bar', // Add a custom CSS class
85 ),
86 ));
87
88
89 // Check if we are on an admin page or not
90 if (is_admin()) {
91 // Fetch the total number of 404 errors
92 $total_404_errors = WPSR_Get_total_404();
93 // Format the number with commas for readability
94 $formatted_404_errors = number_format($total_404_errors);
95
96 // Admin pages sub-nodes
97 $wp_admin_bar->add_node(array(
98 'id' => 'manage_redirects',
99 'title' => 'Manage Redirects',
100 'href' => admin_url('options-general.php?page=seo-redirection.php&tab=cutom'),
101 'parent' => 'seo_redirection',
102 ));
103
104 $wp_admin_bar->add_node(array(
105 'id' => 'post_redirects',
106 'title' => 'Post Redirects',
107 'href' => admin_url('options-general.php?page=seo-redirection.php&tab=posts'),
108 'parent' => 'seo_redirection',
109 ));
110
111 $wp_admin_bar->add_node(array(
112 'id' => 'history_redirects',
113 'title' => 'History',
114 'href' => admin_url('options-general.php?page=seo-redirection.php&tab=history'),
115 'parent' => 'seo_redirection',
116 ));
117
118 // Add the 404 errors node with a dynamic total and red background
119 $wp_admin_bar->add_node(array(
120 'id' => 'manage_404_errors',
121 'title' => '404 Errors (' . $formatted_404_errors . ')', // Display number of 404 errors with formatting
122 'href' => admin_url('options-general.php?page=seo-redirection.php&tab=404'),
123 'parent' => 'seo_redirection',
124 'meta' => array(
125 'class' => 'wpsr-404-errors-admin-bar', // Custom class for styling
126 ),
127 ));
128 } else {
129 // Front-end sub-nodes (same as your original function)
130 $result = $wpdb->get_results($wpdb->prepare("SELECT * FROM $table_name WHERE redirect_from = %s", $relative_url));
131
132 if (!empty($result)) {
133 $wp_admin_bar->add_node(array(
134 'id' => 'edit_redirection',
135 'title' => 'Edit Redirection',
136 'href' => admin_url('options-general.php?page=seo-redirection.php&tab=cutom&redirect_from=' . $relative_url),
137 'parent' => 'seo_redirection',
138 ));
139
140 $wp_admin_bar->add_node(array(
141 'id' => 'view_history',
142 'title' => 'View History',
143 'href' => admin_url('options-general.php?page=seo-redirection.php&tab=history'),
144 'parent' => 'seo_redirection',
145 ));
146 } else {
147 $wp_admin_bar->add_node(array(
148 'id' => 'add_redirection',
149 'title' => 'Redirect this page',
150 'href' => admin_url('options-general.php?page=seo-redirection.php&tab=cutom&redirect_from=' . $relative_url),
151 'parent' => 'seo_redirection',
152 ));
153 }
154 }
155 }
156 }
157
158 add_action('admin_bar_menu', 'WPSR_add_link_to_admin_bar', 999);
159 }
160 /////////////////////////////////////////////////////////////////////////
161
162 function custom_admin_bar_styles()
163 {
164 if (is_admin_bar_showing()) {
165 echo '<style>
166 #wp-admin-bar-seo_redirection > .ab-item {
167 background-color: #114e0e; /* Light green background color */
168 color: white;
169 display: flex;
170 align-items: center;
171 padding: 0 10px; /* Add padding for better alignment */
172 }
173
174 #wp-admin-bar-seo_redirection > .ab-item:hover {
175 background-color: #7ccd7c; /* Darker green on hover */
176 }
177
178 .wpsr-404-notice {
179 border-left: 4px solid red;
180 padding: 15px;
181 background-color: #ffebe6; /* Light red background */
182 }
183
184 .wpsr-404-notice .button-primary {
185 background-color: orange;
186 border-color: orange;
187 }
188
189 #wp-admin-bar-seo_redirection .seo-redirection-icon {
190 width: 20px !important; /* Resize the image to a smaller size */
191 height: 20px !important; /* Keep it proportional */
192 vertical-align: middle; /* Align icon vertically */
193 }
194
195 #wp-admin-bar-seo_redirection .ab-item .seo-redirection-icon {
196 max-width: 100%;
197 max-height: 100%;
198 }
199
200 /* Custom style for the 404 node with red background */
201 #wp-admin-bar-manage_404_errors > .ab-item {
202 background-color: red; /* Red background for the 404 node */
203 color: white; /* White text color */
204 font-weight: bold; /* Bold text to highlight the 404 count */
205 }
206
207 #wp-admin-bar-manage_404_errors > .ab-item:hover {
208 background-color: darkred; /* Darker red on hover */
209 }
210 </style>';
211 }
212 }
213
214 // Apply styles to the front-end
215 add_action('wp_head', 'custom_admin_bar_styles');
216
217 // Apply styles to the admin dashboard
218 add_action('admin_head', 'custom_admin_bar_styles');
219
220
221
222 /////////////////////////////////////////////////////////////////////////
223 if (!function_exists('wpsr_dashboard_notice')) {
224
225 function wpsr_dashboard_notice()
226 {
227 global $util;
228 // Get the total number of 404 errors
229 $total_404_errors = WPSR_Get_total_404();
230
231 // Only show the notice if there are more than 100 broken links and if the user has not dismissed it
232 if ($total_404_errors > 100 && !get_user_meta(get_current_user_id(), 'wpsr_404_notice_dismissed')) {
233 // Image URL for the icon (Replace with your own uploaded image or the default WordPress icon)
234
235 $icon_url = $util->get_plugin_url() . 'custom/images/';
236
237 // Message content with buttons
238 $message = __('<strong>SEO Redirection</strong>: You have', 'seo-redirection') . ' <b style="color:red; padding:3px;">' . intval($total_404_errors) . '</b>' . __(' broken links (404). Manage them now to fix the issue and improve your site\'s SEO performance.', 'seo-redirection');
239
240 $imgpath = $util->get_plugin_url() . 'custom/images/';
241 // Display the message with inline styles
242 echo '
243 <div class="notice notice-error is-dismissible wpsr-404-notice" style="border-left: 4px solid red; display: flex; align-items: center;">
244 <div style="display: flex; align-items: center;">
245 <img src="' . $imgpath . 'icon.png" style="margin-right: 15px; width: 40px; height: 40px;" alt="Error icon" />
246 <div>
247 <p>' . $message . '</p>
248 <p>
249 <a href="' . admin_url('options-general.php?page=seo-redirection.php&tab=404') . '" class="button button-primary" style="background-color: green; border-color: green; margin-right: 10px;">' . __('Fix Now', 'seo-redirection') . '</a>
250 <button type="button" class="button button-secondary wpsr-dismiss-notice" style="border-color: #0073aa; color: #0073aa;">' . __('Dismiss', 'seo-redirection') . '</button>
251 </p>
252 </div>
253 </div>
254 </div>
255 ';
256
257 // Add the script for handling the dismiss action
258 echo '
259 <script type="text/javascript">
260 jQuery(document).ready(function($) {
261 $(\'.wpsr-dismiss-notice\').on(\'click\', function() {
262 var ajaxurl = "' . admin_url('admin-ajax.php') . '";
263 $.post(ajaxurl, {
264 action: "wpsr_dismiss_404_notice",
265 user_id: ' . get_current_user_id() . '
266 });
267 $(this).closest(\'.wpsr-404-notice\').remove();
268 });
269 });
270 </script>
271 ';
272 }
273 }
274 add_action('admin_notices', 'wpsr_dashboard_notice');
275 }
276
277
278 if (!function_exists('wpsr_dismiss_404_notice')) {
279
280 function wpsr_dismiss_404_notice()
281 {
282 // Update the user meta to mark the notice as dismissed
283 update_user_meta(get_current_user_id(), 'wpsr_404_notice_dismissed', true);
284 wp_die(); // This is required to terminate immediately and return a proper response
285 }
286 add_action('wp_ajax_wpsr_dismiss_404_notice', 'wpsr_dismiss_404_notice');
287 }
288 //////////////////////////////////////////////////////////////////////////////////////////////////
289 if (!function_exists("WPSR_multiple_plugin_activate_trial")) {
290 function WPSR_multiple_plugin_activate_trial()
291 {
292 global $wpdb;
293 if (is_multisite()) {
294 if (is_plugin_active_for_network(__FILE__)) {
295 $blogids = $wpdb->get_col("SELECT blog_id FROM $wpdb->blogs");
296 foreach ($blogids as $blog_id) {
297 switch_to_blog($blog_id);
298 }
299 }
300 }
301 }
302
303 register_activation_hook(__FILE__, 'WPSR_multiple_plugin_activate_trial');
304 }
305
306 if (!function_exists("WPSR_adding_custom_meta_boxes")) {
307
308 function WPSR_adding_custom_meta_boxes()
309 {
310 global $util;
311 if ($util->get_option_value('show_redirect_box') == '1') {
312
313 $screens = array('post', 'page');
314
315 foreach ($screens as $screen) {
316
317 add_meta_box(
318 'WPSR_meta_box',
319 __('SEO Redirection'),
320 'WPSR_render_meta_box',
321 $screen
322 );
323 }
324 }
325 }
326 }
327 if (!function_exists("WPSR_render_meta_box")) {
328
329 function WPSR_render_meta_box($post)
330 {
331 global $wpdb, $table_prefix, $util;
332 $table_name = $table_prefix . 'WP_SEO_Redirection';
333
334 if (get_post_status() != 'auto-draft') {
335 $permalink = "";
336 if (in_array($post->post_status, array('draft', 'pending'))) {
337 list($permalink, $postname) = get_sample_permalink($post->ID);
338 $permalink = str_replace('%postname%', $postname, $permalink);
339 } else {
340
341 $permalink = get_permalink($post->ID);
342 }
343
344 $permalink = $util->make_relative_url(urldecode($permalink));
345
346 $postID = $post->ID;
347
348
349 $theurl = $wpdb->get_row($wpdb->prepare(" select redirect_to,redirect_from from $table_name where postID=%d ", $postID));
350
351 $urlredirect_to = '';
352 if ($wpdb->num_rows > 0)
353 $urlredirect_to = $theurl->redirect_to;
354
355 if ($urlredirect_to != '' && $theurl->redirect_from != $permalink) {
356 // the post_name field changed!
357 $wpdb->query($wpdb->prepare(" update $table_name set redirect_from=%s where postID=%d ", $permalink, $postID));
358 if ($util->get_option_value('reflect_modifications') == '1') {
359 $wpdb->query($wpdb->prepare(" update $table_name set redirect_to=%s where redirect_to=%s ", $permalink, $theurl->redirect_from));
360 $util->info_option_msg('<b>' . __("SEO Redirection", 'seo-redirection') . '</b>' . __('has detected a change in Permalink, this will be reflected to the redirection records!', 'seo-redirection'));
361 }
362 //-------------------------------------------
363 }
364
365 echo '
366 <table border="0" width="100%" cellpadding="2">
367 <tr>
368 <td width="99%"><input onchange="redirect_check_click()" type="checkbox" name="redirect_check" id="redirect_check" value="ON">
369 Redirect&nbsp;<font id="wp_seo_redirection_url_from_label" color="#008000">' . esc_html($permalink) . '</font><input type="hidden" ID="wp_seo_redirection_url_from" name="wp_seo_redirection_url_from" value="' . esc_attr($permalink) . '"></td>
370 </tr>
371 </table>
372 <div id="redirect_frame">
373 <table border="0" width="100%" cellpadding="2">
374 <tr>
375 <td>
376
377 <b>' . __(" Redirect to", 'seo-redirection') . '</b><input type="text" name="wp_seo_redirection_url" id="wp_seo_redirection_url" value="' . esc_attr($urlredirect_to) . '" size="62"></td>
378 </tr>
379 <tr>
380 <td>
381 <ul>
382 <li>' . __(" To make a redirection, put the", 'seo-redirection') . ' <b>' . __("URL", 'seo-redirection') . '</b> ' . __("in the text field above and then click the button ", 'seo-redirection') . '<b>' . __("Update", 'seo-redirection') . '</b>.</li>
383 <li>' . __("If you have a caching plugin installed, clear cache to reflect the
384 changes immediately.", 'seo-redirection') . '</li>
385
386 <li>' . __("To remove the redirection, just uncheck the check box above and then click the button", 'seo-redirection') . ' <b>' . __("Update", 'seo-redirection') . '</b>.</li>
387 </ul>
388 </td>
389 </tr>
390 </table>
391 </div>';
392
393 echo "
394
395 <script type='text/javascript'>
396 function WSR_check_status(x)
397 {
398
399 if(x==0)
400 {
401 document.getElementById('redirect_check').checked=false;
402 document.getElementById('redirect_frame').style.display = 'none';
403 document.getElementById('wp_seo_redirection_url').value='';
404 }else
405 {
406 document.getElementById('redirect_check').checked=true;
407 document.getElementById('redirect_frame').style.display= 'block';
408 }
409
410 }
411
412 function redirect_check_click()
413 {
414 if(document.getElementById('redirect_check').checked)
415 WSR_check_status(1);
416 else
417 WSR_check_status(0);
418 }
419 </script>
420 ";
421
422 if ($urlredirect_to == '')
423 echo "<script type='text/javascript'>WSR_check_status(0);</script>";
424 else
425 echo "<script type='text/javascript'>WSR_check_status(1);</script>";
426 } else {
427 echo __('You can not make a redirection for the new posts before saving them.', 'seo-redirection');
428 }
429 }
430 }
431
432 //--------------------------------------------------------------------------------------------
433
434 //---------------------------------------------------------------
435 // added 2/2/2020
436 if (!function_exists("WPSR_get_site_404_page_path")) {
437
438 function WPSR_get_site_404_page_path()
439 {
440 $url = str_ireplace("://", "", site_url());
441 $site_404_page = substr($url, stripos($url, "/"));
442
443 if (stripos($url, "/") === FALSE || $site_404_page == "/")
444 $site_404_page = "/index.php?error=404";
445 else
446 $site_404_page = $site_404_page . "/index.php?error=404";
447
448 return $site_404_page;
449 }
450 }
451 //---------------------------------------------------------------
452 // updated 2/2/2020
453
454 function WPSR_check_default_permalink()
455 {
456 $file = get_home_path() . "/.htaccess";
457 $content = "ErrorDocument 404 " . WPSR_get_site_404_page_path();
458
459 $marker_name = "FRedirect_ErrorDocument";
460 $filestr = "";
461
462
463 if (is_readable($file)) {
464 $f = @fopen($file, 'r+');
465 if ($f !== false) {
466 $filestr = @fread($f, filesize($file));
467 if (strpos($filestr, $marker_name) === false) {
468 insert_with_markers($file, $marker_name, $content);
469 }
470 }
471 } else {
472 echo $file . ' is not readable!';
473 }
474 }
475
476 //------------------------------------------------------------------------
477
478
479 /**
480 * Recursive sanitation for text or array
481 *
482 * @param $array_or_string (array|string)
483 * @since 0.1
484 * @return mixed
485 */
486 if (!function_exists("WPSR_sanitize_text_or_array_field")) {
487
488 function WPSR_sanitize_text_or_array_field($array_or_string)
489 {
490 if (is_string($array_or_string)) {
491 $array_or_string = sanitize_text_field($array_or_string);
492 } elseif (is_array($array_or_string)) {
493 foreach ($array_or_string as $key => &$value) {
494 if (is_array($value)) {
495 $value = WPSR_sanitize_text_or_array_field($value);
496 } else {
497 $value = sanitize_text_field($value);
498 }
499 }
500 }
501
502 return $array_or_string;
503 }
504 }
505 if (!function_exists("WPSR_get_post_redirection")) {
506
507 function WPSR_get_post_redirection($post_id)
508 {
509
510 global $wpdb, $util, $table_prefix;
511 $table_name = $table_prefix . 'WP_SEO_Redirection';
512
513 // Autosave
514 if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE)
515 return;
516 // AJAX
517 if (defined('DOING_AJAX') && DOING_AJAX)
518 return;
519 // REST API (block editor) — our meta box fields are not sent via REST
520 if (defined('REST_REQUEST') && REST_REQUEST)
521 return;
522 // Post revision
523 if (false !== wp_is_post_revision($post_id))
524 return;
525 // Permission check
526 if (!current_user_can('edit_post', $post_id))
527 return;
528
529 $redirect_from = isset($_POST['wp_seo_redirection_url_from']) ? WPSR_sanitize_text_or_array_field($_POST['wp_seo_redirection_url_from']) : '';
530 $redirect_to = isset($_POST['wp_seo_redirection_url']) ? WPSR_sanitize_text_or_array_field($_POST['wp_seo_redirection_url']) : '';
531
532 if ($redirect_to != '') {
533
534
535 $wpdb->get_results($wpdb->prepare("select ID from $table_name where postID=%d ", $post_id));
536
537 if ($wpdb->num_rows > 0) {
538
539 $sql = $wpdb->prepare("update $table_name set redirect_to=%s,redirect_from=%s,redirect_type='301',url_type=2 where postID=%d", $redirect_to, $redirect_from, $post_id);
540 $wpdb->query($sql);
541 } else {
542 $wpdb->query($wpdb->prepare("delete from $table_name where redirect_from=%s", $redirect_from));
543 $sql = $wpdb->prepare("insert into $table_name(redirect_from,redirect_to,redirect_type,url_type,postID) values (%s,%s,'301',2,%d) ", $redirect_from, $redirect_to, $post_id);
544 $wpdb->query($sql);
545 }
546 } else {
547 $wpdb->query($wpdb->prepare("delete from $table_name where postID=%d", $post_id));
548 }
549
550 $SR_redirect_cache = new free_SR_redirect_cache();
551 $SR_redirect_cache->free_cache();
552 }
553 }
554 //-------------------------------------------------------------
555 if (!function_exists("WPSR_log_404_redirection")) {
556
557 function WPSR_log_404_redirection($link)
558 {
559 global $wpdb, $table_prefix, $util;
560 $table_name = $table_prefix . 'WP_SEO_404_links';
561
562 $referrer = $util->get_ref();
563 $ip = $util->get_visitor_IP();
564 $country = ""; //$util->get_visitor_country();
565 $os = $util->get_visitor_OS();
566 $browser = $util->get_visitor_Browser();
567
568
569 // Check if the request is from a known bot or suspicious source
570 $user_agent = $_SERVER['HTTP_USER_AGENT'] ?? '';
571 $bots = ['bot', 'crawl', 'spider', 'slurp', 'Mediapartners-Google', 'AhrefsBot', 'SemrushBot', 'Bingbot', 'YandexBot'];
572 foreach ($bots as $bot) {
573 if (stripos($user_agent, $bot) !== false) {
574 return; // Ignore requests from bots
575 }
576 }
577
578 // Check if the request is missing essential headers (likely non-browser)
579 if (empty($_SERVER['HTTP_ACCEPT']) || empty($_SERVER['HTTP_ACCEPT_LANGUAGE']) || empty($_SERVER['HTTP_USER_AGENT'])) {
580 return; // Ignore suspicious requests without essential headers
581 }
582
583 // Check if the link belongs to the site's domain to avoid injected URLs
584 $parsed_link = parse_url($link);
585 $site_host = parse_url(home_url(), PHP_URL_HOST);
586 if (isset($parsed_link['host']) && $parsed_link['host'] !== $site_host) {
587 return; // Ignore external or injected URLs
588 }
589
590 // Log the redirect
591
592
593
594
595 if ($os != 'Unknown' || $browser != 'Unknown') {
596 $wpdb->query($wpdb->prepare(" insert IGNORE into $table_name(ctime,link,referrer,ip,country,os,browser) values(NOW(),%s,%s,%s,%s,%s,%s) ", $link, $referrer, $ip, $country, $os, $browser));
597 }
598 }
599 }
600 //-------------------------------------------------------------
601 if (!function_exists("WPSR_log_redirection_history")) {
602
603 function WPSR_log_redirection_history($rID, $postID, $rfrom, $rto, $rtype, $rsrc)
604 {
605 global $wpdb, $table_prefix, $util;
606 $SR_redirect_cache = new free_SR_redirect_cache();
607 $SR_redirect_cache->free_cache();
608 $table_name = $table_prefix . 'WP_SEO_Redirection_LOG';
609 $rfrom = esc_url($rfrom);
610 $referrer = $util->get_ref();
611 $ip = $util->get_visitor_IP();
612 $country = ""; //$util->get_visitor_country();
613 $os = $util->get_visitor_OS();
614 $browser = $util->get_visitor_Browser();
615
616 $wpdb->query($wpdb->prepare(" insert into $table_name(rID,postID,rfrom,rto,rtype,rsrc,ctime,referrer,ip,country,os,browser) values(%d ,%d,%s,%s,%s,%s,NOW(),%s,%s,%s,%s,%s) ", $rID, $postID, $rfrom, $rto, $rtype, $rsrc, $referrer, $ip, $country, $os, $browser));
617
618 $limit = $util->get_option_value('history_limit');
619
620 $expdate = date('Y-n-j', time() - (intval($limit) * 24 * 60 * 60));
621 $wpdb->query("delete FROM $table_name WHERE date_format(date(ctime),'%Y-%m-%d') < date_format(date('$expdate'),'%Y-%m-%d')");
622 }
623 }
624 //-------------------------------------------------------------
625 if (!function_exists("WPSR_make_redirect")) {
626
627 function WPSR_make_redirect($redirect_to, $redirect_type, $redirect_from, $obj = '')
628 {
629
630 global $wpdb, $util, $table_prefix, $post;
631
632 if (is_admin()) {
633 return 0;
634 }
635 $SR_redirect_cache = new free_SR_redirect_cache();
636 if ($redirect_to == $redirect_from || !$util->is_valid_url($redirect_to))
637 return 0;
638
639 if ($util->make_relative_url($redirect_from) == $util->make_relative_url($redirect_to))
640 return 0;
641
642 // Path-level loop guard: catches /page/ vs /page/?ref=x
643 $rfpath = strtok($util->make_relative_url($redirect_from), '?');
644 $rtpath = strtok($util->make_relative_url($redirect_to), '?');
645 if ($rfpath !== '' && $rfpath === $rtpath)
646 return 0;
647
648 if (substr($redirect_from, -1) == "/" || substr($redirect_to, -1) == "/") {
649 if (substr($redirect_from, -1) != "/") {
650 if (($redirect_from . "/") == $redirect_to)
651 return 0;
652 } else {
653 if (($redirect_to . "/") == $redirect_from)
654 return 0;
655 }
656 }
657
658
659 if ($util->make_relative_url($redirect_from) == $util->make_relative_url($redirect_to))
660 return 0;
661
662 if (is_object($obj)) {
663 if ($obj->ID > 0) {
664 $table_name = $table_prefix . 'WP_SEO_Redirection';
665 $sql = "update " . $table_name . " set hits=hits+1, access_date= NOW() where ID='" . $obj->ID . "'";
666 $wpdb->query($sql);
667 }
668 }
669
670 if (is_object($obj) && $obj->redirect_to_type == 'Folder' && $obj->redirect_to_folder_settings == '2') {
671
672 if ($obj->redirect_from_type == 'Folder') {
673
674 if ($obj->redirect_from_folder_settings == '2' || $obj->redirect_from_folder_settings == '3') {
675 if (strlen($redirect_from) > strlen($obj->redirect_from)) {
676 $difference = substr($redirect_from, intval(strlen($obj->redirect_from) - strlen($redirect_from)));
677 $redirect_to = $redirect_to . $difference;
678 }
679 }
680 } else if ($obj->redirect_from_type == 'Regex') {
681 $page = substr(strrchr($redirect_from, "/"), 1);
682 $redirect_to = $redirect_to . '/' . $page;
683 }
684 }
685
686 $rID = 0;
687 $rsrc = '404';
688 $postID = 0;
689
690 if (is_object($obj)) {
691 $rID = $obj->ID;
692 $postID = $obj->postID;
693 if ($obj->url_type == 1)
694 $rsrc = 'Custom';
695 else if ($obj->url_type == 2)
696 $rsrc = 'Post';
697 }
698
699 if ($util->get_option_value('history_status') == '1') {
700
701 WPSR_log_redirection_history($rID, $postID, $redirect_from, $redirect_to, $redirect_type, $rsrc);
702 }
703
704 $redirect_to = $util->make_absolute_url($redirect_to);
705
706
707 if (is_singular()) {
708 //$SR_redirect_cache = new free_SR_redirect_cache();
709
710 $SR_redirect_cache->add_redirect($post->ID, 1, $redirect_from, $redirect_to, $redirect_type);
711 $SR_redirect_cache->free_cache();
712 }
713
714 if ($redirect_type == '301') {
715 header('HTTP/1.1 301 Moved Permanently');
716 header("Location: " . $redirect_to);
717 exit();
718 } else if ($redirect_type == '307') {
719 header('HTTP/1.0 307 Temporary Redirect');
720 header("Location: " . $redirect_to);
721 exit();
722 } else if ($redirect_type == '302') {
723 header("Location: " . $redirect_to);
724 exit();
725 }
726 }
727 }
728 add_filter('pre_get_table_charset', function ($charset, $table) {
729 global $table_prefix;
730 $table_name = $table_prefix . 'WP_SEO_Redirection';
731 if ($table == $table_name) {
732 return 'utf8mb4';
733 }
734 }, 10, 2);
735 //-------------------------------------------------------------
736 if (!function_exists("WPSR_strip_tracking_params")) {
737 /**
738 * Strip known tracking/analytics parameters from a URL before redirect matching.
739 * Regex rules are unaffected — they receive the full original permalink.
740 */
741 function WPSR_strip_tracking_params($url)
742 {
743 $tracking_params = array(
744 'fbclid', 'gclid', 'gclsrc', 'dclid', 'msclkid', 'ttclid', 'mc_eid',
745 'utm_source', 'utm_medium', 'utm_campaign', 'utm_content', 'utm_term',
746 'utm_id', 'utm_source_platform', '_ga', '_gl', 'ref', 'igshid', 'srsltid',
747 );
748 $pos = strpos($url, '?');
749 if ($pos === false) return $url;
750 $path = substr($url, 0, $pos);
751 parse_str(substr($url, $pos + 1), $params);
752 foreach ($tracking_params as $k) unset($params[$k]);
753 return empty($params) ? $path : $path . '?' . http_build_query($params);
754 }
755 }
756 //-------------------------------------------------------------
757 if (!function_exists("WPSR_redirect")) {
758
759 function WPSR_redirect()
760 {
761 global $wpdb, $post, $table_prefix, $util;
762
763
764 if ($util->get_option_value('plugin_status') != '0') { // if not disabled
765
766 // if disable for admin and the user is admin
767 if (current_user_can('manage_options') == 1 && $util->get_option_value('plugin_status') == 2) {
768 // nothing
769
770 } else {
771
772 $table_name = $table_prefix . 'WP_SEO_Redirection';
773 $permalink = urldecode($util->get_current_relative_url());
774 // Strip tracking/UTM params so rules match campaign traffic (fbclid, utm_*, etc.)
775 $permalink = WPSR_strip_tracking_params($permalink);
776
777 if (substr($permalink, 0, 1) == ":") {
778 $first_slash = stripos($permalink, "/");
779 $permalink = substr($permalink, $first_slash, strlen($permalink) - $first_slash);
780 }
781 $permalink_alternative = "";
782 if (substr($permalink, -1) == '/') {
783 $permalink_alternative = substr($permalink, 0, intval(strlen($permalink) - 1));
784 } else {
785 $permalink_alternative = $permalink . '/';
786 }
787
788 $post_cache_result = "";
789 $SR_redirect_cache = new free_SR_redirect_cache();
790 if (is_singular()) {
791 $post_cache_result = $SR_redirect_cache->redirect_cached($post->ID);
792 }
793
794 if ($post_cache_result == 'not_redirected') {
795
796 return 0;
797 }
798
799 $permalink_options = $wpdb->prepare("( redirect_from = %s OR redirect_from = %s)", $permalink, $permalink_alternative);
800
801 $permalink_regex_options = $wpdb->prepare("(%s regexp regex or %s regexp regex )", $permalink, $permalink_alternative);
802
803
804 if (($util->get_option_value('redirect_control_panel') != '1') || ($util->get_option_value('redirect_control_panel') == '1' && !preg_match('/^' . str_replace('/', '\/', get_admin_url()) . '/i', $permalink) && !preg_match('/^' . str_replace('/', '\/', site_url()) . '\/wp-login.php/i', $permalink))) {
805
806 $theurl = $wpdb->get_row(" select * from $table_name where enabled=1 and regex='' and $permalink_options ");
807 if ($wpdb->num_rows > 0 && $theurl->redirect_to != '') {
808 WPSR_make_redirect($theurl->redirect_to, $theurl->redirect_type, $permalink, $theurl);
809 }
810
811 $theurl = $wpdb->get_row(" select * from $table_name where enabled=1 and regex<>'' and $permalink_regex_options order by LENGTH(regex) desc ");
812
813 if ($wpdb->num_rows > 0 && $theurl->redirect_to != '') {
814 WPSR_make_redirect($theurl->redirect_to, $theurl->redirect_type, $permalink, $theurl);
815 }
816
817
818 if (is_404()) {
819
820 if ($util->get_option_value('p404_discovery_status') == '1') {
821 WPSR_log_404_redirection($permalink);
822 }
823
824 $options = $util->get_my_options();
825 if ($options['p404_status'] == '1') {
826
827 WPSR_make_redirect($options['p404_redirect_to'], '301', $permalink);
828 }
829 }
830 }
831
832 if (is_singular() && $post_cache_result == 'not_found') {
833 $SR_redirect_cache->add_redirect($post->ID, 0, '', '', 0);
834 }
835 }
836 }
837 }
838 }
839 //---------------------------------------------------------------
840 if (!function_exists("WPSR_header_code")) {
841
842 function WPSR_header_code()
843 {
844
845 $my_page = isset($_REQUEST['page']) ? $_REQUEST['page'] : '';
846 if ($my_page == 'seo-redirection.php') {
847
848 // Use filemtime() as version so browser fetches fresh files after every update.
849 // Use wpsr_ prefixed handles to avoid conflicts with other plugins.
850 $plugin_dir = plugin_dir_path(__FILE__);
851 $plugin_url = plugin_dir_url(__FILE__);
852
853 wp_enqueue_style('wpsr-bootstrap', $plugin_url . 'common/bootstrap.css', array(), filemtime($plugin_dir . 'common/bootstrap.css'));
854 wp_enqueue_style('wpsr-sweetalert', $plugin_url . 'common/sweetalert.css', array(), filemtime($plugin_dir . 'common/sweetalert.css'));
855 wp_enqueue_style('wpsr-style', $plugin_url . 'common/style.css', array(), filemtime($plugin_dir . 'common/style.css'));
856 wp_enqueue_style('wpsr-custom-css', $plugin_url . 'common/custom.css', array(), filemtime($plugin_dir . 'common/custom.css'));
857 wp_enqueue_style('wpsr-custom-skin', $plugin_url . 'custom/style.css', array(), filemtime($plugin_dir . 'custom/style.css'));
858
859 wp_enqueue_script('jquery');
860 wp_enqueue_script('wpsr-bootstrap-js', $plugin_url . 'common/js/bootstrap.min.js', array('jquery'), filemtime($plugin_dir . 'common/js/bootstrap.min.js'), true);
861 wp_enqueue_script('wpsr-sweetalert-js', $plugin_url . 'common/js/sweetalert.min.js', array('jquery'), filemtime($plugin_dir . 'common/js/sweetalert.min.js'), true);
862 wp_enqueue_script('wpsr-main-js', $plugin_url . 'common/customJs.js', array('jquery', 'wpsr-bootstrap-js', 'wpsr-sweetalert-js'), filemtime($plugin_dir . 'common/customJs.js'), true);
863
864 // Pass msg directly here — eliminates timing dependency on inline script
865 $wpsr_404_count = WPSR_Get_total_404();
866 $wpsr_msg = '';
867 if ($wpsr_404_count > 10) {
868 $wpsr_msg = 'You have <b>' . intval($wpsr_404_count) . '</b> broken link (404 links), ';
869 }
870 wp_localize_script('jquery', 'seoredirection', array(
871 'ajax_url' => admin_url('admin-ajax.php'),
872 'msg' => $wpsr_msg,
873 ));
874
875 }
876 }
877 }
878 //---------------------------------------------------------------
879 if (!function_exists("WPSR_customAddUpdate_callback")) {
880
881 add_action("wp_ajax_customAddUpdate", "WPSR_customAddUpdate_callback");
882
883 function WPSR_customAddUpdate_callback()
884 {
885 // Security: writing redirect rules is an admin-only operation.
886 if (!current_user_can('manage_options')) {
887 wp_die(-1);
888 }
889 global $wpdb, $table_prefix, $util;
890 $table_name = $table_prefix . 'WP_SEO_Redirection';
891 $table_name_404 = $table_prefix . 'WP_SEO_404_links';
892 parse_str($_POST['formData'], $_POST);
893 $nonce = "";
894 if (isset($_POST['_wpnonce']))
895 $nonce = WPSR_sanitize_text_or_array_field($_POST['_wpnonce']);
896 $data = array();
897 $data['error_string'] = array();
898 $data['inputerror'] = array();
899 $data['bool'] = TRUE;
900 if (trim($_POST['redirect_from']) == '') {
901 $data['inputerror'][] = 'redirect_from';
902 $data['error_string'][] = __("You must input the 'Redirect From' URL", "seo-redirection");
903 $data['bool'] = FALSE;
904 }
905
906 $redirect_from = isset($_POST['redirect_from']) ? WPSR_sanitize_text_or_array_field($_POST['redirect_from']) : '';
907
908 /* $wpdb->get_results(" select ID from $table_name where redirect_from='" . trim($redirect_from) . "' ");
909 if ($wpdb->num_rows > 0) {
910 $data['inputerror'][] = 'redirect_from';
911 $data['error_string'][] = __("This 'Redirect From' value already exists in database!", "seo-redirection");
912 $data['bool'] = FALSE;
913 }
914
915 */
916 // elseif (!preg_match( '/((http|https)\:\/\/)?[a-zA-Z0-9\.\/\?\:@\-_=#]+\.([a-zA-Z0-9\&\.\/\?\:@\-_=#])*/', $_POST['redirect_from'])) {
917 // $data['inputerror'][] = 'redirect_from';
918 // $data['error_string'][] = __("Invalid redirect from target URL!",'seo-redirection');
919 // $data['bool'] = FALSE;
920 // }
921 if (trim($_POST['redirect_to']) == '') {
922 $data['inputerror'][] = 'redirect_to';
923 $data['error_string'][] = __("You must input the 'Redirect To' URL", "seo-redirection");
924 $data['bool'] = FALSE;
925 } elseif ($_POST['edit_exist'] == '' && substr(strtolower($_POST['redirect_to']), 0, 4) != "http" && substr(strtolower($_POST['redirect_to']), 0, 1) != "/") {
926 $data['inputerror'][] = 'redirect_to';
927 $data['error_string'][] = __("Invalid redirect target URL!", 'seo-redirection');
928 $data['bool'] = FALSE;
929 }
930 if ($data['bool'] === FALSE) {
931 echo json_encode($data);
932 exit();
933 } else {
934 if ($_POST['redirect_from'] != '' && wp_verify_nonce($nonce, 'seoredirection')) {
935
936
937 $redirect_from = isset($_POST['redirect_from']) ? WPSR_sanitize_text_or_array_field($_POST['redirect_from']) : '';
938 $redirect_to = isset($_POST['redirect_to']) ? WPSR_sanitize_text_or_array_field($_POST['redirect_to']) : '';
939
940
941 $redirect_from = urldecode($util->make_relative_url($redirect_from));
942
943 $redirect_to = $util->make_relative_url($redirect_to);
944 $redirect_type = WPSR_sanitize_text_or_array_field($_POST['redirect_type']);
945
946 $redirect_from_type = WPSR_sanitize_text_or_array_field($_POST['redirect_from_type']);
947 $redirect_from_folder_settings = WPSR_sanitize_text_or_array_field($_POST['redirect_from_folder_settings']);
948 $redirect_from_subfolders = WPSR_sanitize_text_or_array_field($_POST['redirect_from_subfolders']);
949
950 $redirect_to_type = WPSR_sanitize_text_or_array_field($_POST['redirect_to_type']);
951 $redirect_to_folder_settings = WPSR_sanitize_text_or_array_field($_POST['redirect_to_folder_settings']);
952
953 $enabled = WPSR_sanitize_text_or_array_field($_POST['enabled']);
954
955 $regex = "";
956
957 if ($redirect_from_type == 'Folder') {
958
959 if (substr($redirect_from, -1) != '/')
960 $redirect_from = $redirect_from . '/';
961
962 if ($redirect_from_folder_settings == 2) {
963 if ($redirect_from_subfolders == 0) {
964 $regex = '^' . $util->regex_prepare($redirect_from) . '.*';;
965 } else {
966 $regex = '^' . $util->regex_prepare($redirect_from) . '[^/]*$';
967 }
968 } else if ($redirect_from_folder_settings == 3) {
969 if ($redirect_from_subfolders == 0) {
970 $regex = '^' . $util->regex_prepare($redirect_from) . '.+';
971 } else {
972 $regex = '^' . $util->regex_prepare($redirect_from) . '[^/]+$';
973 }
974 }
975 } else if ($redirect_from_type == 'Regex') {
976 $regex = $redirect_from;
977 }
978
979 if ($redirect_from_type == 'Page' || $redirect_from_type == 'Regex') {
980 $redirect_from_folder_settings = "";
981 $redirect_from_subfolders = "";
982 }
983
984 if ($redirect_to_type == 'Page') {
985 $redirect_to_folder_settings = "";
986 }
987
988 if ($redirect_to_type == 'Folder') {
989 if (substr($redirect_to, -1) != '/')
990 $redirect_to = $redirect_to . '/';
991 }
992
993
994 if ($_POST['add_new'] != '') {
995
996 $theurl = $wpdb->get_row($wpdb->prepare(" select count(ID) as cnt from $table_name where redirect_from=%s ", $redirect_from));
997
998 if ($theurl->cnt > 0) {
999 $msg = __("This URL", 'seo-redirection') . " <b>" . esc_html($redirect_from) . "</b>" . __("is added previously!", 'seo-redirection');
1000 echo json_encode(array('status' => 'error', 'msg' => $msg));
1001 // $util->failure_option_msg(__("This URL",'seo-redirection')." <b>'$redirect_from'</b>". __("is added previously!",'seo-redirection'));
1002 } else {
1003
1004
1005 if ($redirect_from == '' || $redirect_to == '' || $redirect_type == '') {
1006 $util->failure_option_msg(__('Please input all required fields!', 'seo-redirection'));
1007 } elseif (strtok($redirect_from, '?') === strtok($redirect_to, '?')) {
1008 $msg = __("Redirect loop detected: 'From' and 'To' point to the same path. This would cause an infinite redirect.", 'seo-redirection');
1009 echo json_encode(array('status' => 'error', 'msg' => $msg));
1010 die;
1011 } else {
1012
1013 $wpdb->insert($table_name, array(
1014 'redirect_from' => $redirect_from,
1015 'redirect_to' => $redirect_to,
1016 'redirect_type' => $redirect_type,
1017 'url_type' => 1,
1018 'redirect_from_type' => $redirect_from_type,
1019 'redirect_from_folder_settings' => $redirect_from_folder_settings,
1020 'redirect_from_subfolders' => $redirect_from_subfolders,
1021 'redirect_to_type' => $redirect_to_type,
1022 'redirect_to_folder_settings' => $redirect_to_folder_settings,
1023 'regex' => $regex,
1024 'enabled' => $enabled
1025
1026 ));
1027
1028 $wpdb->query($wpdb->prepare(" delete from $table_name_404 where link=%s ", $redirect_from));
1029 $SR_redirect_cache = new free_SR_redirect_cache();
1030 $SR_redirect_cache->free_cache();
1031 $msg = "Redirection Added Successfully";
1032 echo json_encode(array('status' => 'success', 'msg' => $msg, 'url' => admin_url('options-general.php?page=seo-redirection.php')));
1033 die;
1034 }
1035 }
1036 } else if ($_POST['edit_exist'] != '') {
1037
1038 $edit = WPSR_sanitize_text_or_array_field($_POST['edit']);
1039
1040 if ($redirect_from == '' || $redirect_to == '' || $redirect_type == '') {
1041 $util->failure_option_msg('Please input all required fields!');
1042 } elseif (strtok($redirect_from, '?') === strtok($redirect_to, '?')) {
1043 $msg = __("Redirect loop detected: 'From' and 'To' point to the same path. This would cause an infinite redirect.", 'seo-redirection');
1044 echo json_encode(array('status' => 'error', 'msg' => $msg));
1045 die;
1046 } else {
1047
1048 $wpdb->query($wpdb->prepare("update $table_name set redirect_from=%s,redirect_to=%s,redirect_type=%s,redirect_from_type=%s ,redirect_from_folder_settings=%d,redirect_from_subfolders=%d ,redirect_to_type=%s ,redirect_to_folder_settings=%d ,regex=%s,enabled=%s where ID=%d ", $redirect_from, $redirect_to, $redirect_type, $redirect_from_type, $redirect_from_folder_settings, $redirect_from_subfolders, $redirect_to_type, $redirect_to_folder_settings, $regex, $enabled, $edit));
1049
1050 $SR_redirect_cache = new free_SR_redirect_cache();
1051 $SR_redirect_cache->free_cache();
1052 }
1053 $msg = "Redirection Update Successfully";
1054 echo json_encode(array('status' => 'success', 'msg' => $msg, 'url' => admin_url('options-general.php?page=seo-redirection.php')));
1055 die;
1056 }
1057
1058 if ($util->there_is_cache() != '')
1059 $util->info_option_msg(__("You have a cache plugin installed", 'seo-redirection') . " <b>'" . $util->there_is_cache() . "'</b>, " . __("you have to clear cache after any changes to get the changes reflected immediately! ", 'seo-redirection'));
1060 }
1061 }
1062
1063
1064 die;
1065 }
1066 }
1067 if (!function_exists("WPSR_customUpdateRec_callback")) {
1068
1069 add_action("wp_ajax_customUpdateRec", "WPSR_customUpdateRec_callback");
1070 function WPSR_customUpdateRec_callback()
1071 {
1072
1073 // Security: this handler exposes redirect rule configuration, which is
1074 // admin-only data. Require the same capability that gates the settings
1075 // screen, and verify the nonce, matching the add/update & delete handlers.
1076 if (!current_user_can('manage_options')) {
1077 wp_die(-1);
1078 }
1079 check_ajax_referer('seoredirection', '_wpnonce');
1080
1081 global $wpdb, $table_prefix, $util;
1082
1083 $table_name = $table_prefix . 'WP_SEO_Redirection';
1084 $table_name_404 = $table_prefix . 'WP_SEO_404_links';
1085
1086 $myid = isset($_POST['ID']) ? absint($_POST['ID']) : 0;
1087 $item = $wpdb->get_row($wpdb->prepare(" select * from $table_name where ID=%d ", $myid));
1088
1089 if ($wpdb->num_rows == 0) {
1090 echo json_encode(array('status' => 'error', 'msg' => __("Sorry, this redirect rule is not found, it may deleted by the user!", 'seo-redirection')));
1091 die;
1092 }
1093
1094
1095 $data = array(
1096 "redirect_from" => $item->redirect_from,
1097 "redirect_to" => $item->redirect_to,
1098 "redirect_type" => $item->redirect_type,
1099
1100 "redirect_from_type" => $item->redirect_from_type,
1101 "redirect_from_folder_settings" => $item->redirect_from_folder_settings,
1102 "redirect_from_subfolders" => $item->redirect_from_subfolders,
1103
1104 "redirect_to_type" => $item->redirect_to_type,
1105 "redirect_to_folder_settings" => $item->redirect_to_folder_settings,
1106
1107 "enabled" => $item->enabled
1108 );
1109 echo json_encode(array('status' => 'success', 'rec' => $data));
1110 die;
1111 }
1112 }
1113
1114 if (!function_exists("WPSR_admin_menu")) {
1115
1116 function WPSR_admin_menu()
1117 {
1118 add_options_page('SEO Redirection', 'SEO Redirection', 'manage_options', basename(__FILE__), 'WPSR_options_menu');
1119 }
1120 }
1121 //---------------------------------------------------------------
1122 if (!function_exists("WPSR_options_menu")) {
1123
1124 function WPSR_options_menu()
1125 {
1126 global $util;
1127
1128 if (!current_user_can('manage_options')) {
1129 wp_die(__('You do not have sufficient permissions to access this page.', 'seo-redirection'));
1130 }
1131
1132
1133 if ($util->get_option_value('plugin_status') == '0') {
1134 $util->info_option_msg(__('SEO Redirection is disabled now, you can go to option tab and enable it!', 'seo-redirection'));
1135 } else if ($util->get_option_value('plugin_status') == '2') {
1136 $util->info_option_msg(__('SEO Redirection is', 'seo-redirection') . ' <b>' . __('disabled for admin', 'seo-redirection') . '</b>' . __(' only, you can go to option tab and enable it!', 'seo-redirection'));
1137 }
1138 $total_404_errors = (WPSR_Get_total_404() > 10) ? __('You have', 'seo-redirection') . ' <b style="color:red; background-color:yellow; padding:3px;">' . intval(WPSR_Get_total_404()) . '</b>' . __(' broken link (404 links)', 'seo-redirection') . ', <br>' : '';
1139
1140
1141 echo '<div class="wrap">';
1142 echo '<div style="display:flex;align-items:center;justify-content:space-between;padding:14px 18px 10px;border-bottom:1.5px solid #d1d9e6;gap:12px;flex-wrap:wrap">';
1143 echo '<h2 style="margin:0;padding:0;border:none;font-size:16px;font-weight:600;color:#111827">' . __("SEO Redirection Free", 'seo-redirection') . '</h2>';
1144 echo '<span style="display:inline-flex;align-items:center;gap:5px;background:#fef9c3;border:1.5px solid #fde68a;color:#92400e;font-size:11px;font-weight:600;padding:4px 10px;border-radius:20px">&#11088; <a target="_blank" href="https://www.wp-buy.com/product/seo-redirection-premium-wordpress-plugin/" style="color:inherit;text-decoration:none">' . __('Upgrade to Pro', 'seo-redirection') . ' &middot; 50% OFF</a></span>';
1145 echo '</div>';
1146
1147 if ($total_404_errors != '') {
1148 ?>
1149 <script type="text/javascript">
1150 seoredirection.msg = '<?php echo wp_kses_post($total_404_errors); ?>';
1151 </script>
1152
1153 <?php
1154 }
1155
1156 if (is_multisite()) {
1157
1158 echo '<div class="error" id="message"><p></p><div class="warning_icon"></div>' . __('This version does not support Multisite WordPress installation, you may face troubles like losing redirects when adding new sites to your network, the premium version supports multisite well', 'seo-redirection') . '(<a target="_blank" href="https://www.wp-buy.com/product/seo-redirection-premium-wordpress-plugin/">
1159 https://www.wp-buy.com/product/seo-redirection-premium-wordpress-plugin/</a>) <p></p></div>';
1160 }
1161
1162 $mytabs = new phptab();
1163
1164 $mytabs->set_ignore_parameter(array('search', 'page_num', 'add', 'edit', 'page404', 'do_404_del'));
1165 $mytabs->add_file_tab('cutom', __('Custom Redirects', 'seo-redirection'), 'option_page_custome_redirection.php', 'file');
1166 $mytabs->add_file_tab('posts', __('Post Redirects', 'seo-redirection'), 'option_page_post_redirection_list.php', 'file');
1167 $mytabs->add_file_tab('history', __('History', 'seo-redirection'), 'option_page_history.php', 'file');
1168 $mytabs->add_file_tab('404', '<span style="color:red;"><b>404 Errors</b></span>', 'option_page_404.php', 'file');
1169 $mytabs->add_file_tab('goptions', __('Options', 'seo-redirection'), 'option_page_goptions.php', 'file');
1170 $mytabs->add_file_tab('help', '<span style="color:green;"><b>' . __('Help', 'seo-redirection') . '</b></span>', 'help.php', 'file');
1171 $mytabs->add_file_tab('premium', '<span style="color:brown;"><b>&#9658; ' . __('Premium Features', 'seo-redirection') . '</b></span>', 'premium.php', 'file');
1172 $mytabs->run();
1173
1174 $imgpath = $util->get_plugin_url() . 'custom/images/';
1175
1176 echo '<div style="text-align:center;padding:14px 20px 6px;">'
1177 . '<p style="font-size:15px;font-weight:600;color:#111827;margin:0 0 6px">'
1178 . '&#128640; ' . __("You're one step away from fixing ALL your broken links automatically", "wsr")
1179 . '</p>'
1180 . '<p style="font-size:13px;color:#4b5563;margin:0 0 12px">'
1181 . __("Pro users get bulk redirect, wildcard rules, smart suggestions & real-time monitoring — everything the free version can't do.", "wsr")
1182 . '</p>'
1183 . '<a target="_blank" href="https://www.wp-buy.com/product/seo-redirection-premium-wordpress-plugin/" '
1184 . 'style="display:inline-flex;align-items:center;gap:8px;background:#16a34a;color:#fff;text-decoration:none;'
1185 . 'font-size:14px;font-weight:600;padding:10px 24px;border-radius:8px;border:none;">'
1186 . '&#11088; ' . __("Upgrade to Pro &amp; Fix Everything — 50% OFF", "wsr")
1187 . '</a>'
1188 . '<p style="font-size:11px;color:#9ca3af;margin:8px 0 0">'
1189 . __("Join thousands of site owners who stopped losing traffic to broken links.", "wsr")
1190 . '</p>'
1191 . '</div>';
1192 echo '<p style="text-align:center;margin:0 0 8px"><a href="https://www.wp-buy.com/product/seo-redirection-premium-wordpress-plugin" target="_blank"><img src="' . $imgpath . 'seopro.png" style="width:95%;max-width:900px;height:auto;display:block;margin:0 auto" /></a></p>';
1193 }
1194 }
1195 function WPSR_check_and_upgrade()
1196 {
1197 $util = new clogica_util_1();
1198 $util->init('clogica_option_group', __FILE__); // Initialize the class
1199
1200 $stored_version = $util->get_option_value('plugin_version');
1201 $current_version = WP_SEO_REDIRECTION_VERSION;
1202
1203 // Run the upgrade only if the stored version is older
1204 if (!$stored_version || version_compare($stored_version, $current_version, '<')) {
1205 WPSR_upgrade();
1206 }
1207 }
1208
1209 function WPSR_upgrade()
1210 {
1211 $util = new clogica_util_1();
1212 $util->init('clogica_option_group', __FILE__); // Initialize the class
1213
1214 WPSR_install(); // Custom installation/upgrade logic
1215 $util->update_option('plugin_version', WP_SEO_REDIRECTION_VERSION); // Update version
1216 }
1217
1218 //-----------------------------------------------------
1219
1220 if (!function_exists("WPSR_install")) {
1221
1222 function WPSR_install()
1223 {
1224 global $wpdb, $table_prefix;
1225
1226 $util = new clogica_util_1();
1227 $util->init(WP_SEO_REDIRECTION_OPTIONS, __FILE__);
1228
1229 $options = get_option(WP_SEO_REDIRECTION_OPTIONS);
1230 if (!is_array($options)) {
1231 add_option(WP_SEO_REDIRECTION_OPTIONS);
1232 $options = array();
1233 }
1234
1235
1236 if (!array_key_exists('plugin_status', $options))
1237 $options['plugin_status'] = '1';
1238
1239 if (!array_key_exists('ip_logging_status', $options))
1240 $options['ip_logging_status'] = '1';
1241
1242 if (!array_key_exists('redirection_base', $options))
1243 $options['redirection_base'] = site_url();
1244
1245 if (!array_key_exists('redirect_control_panel', $options))
1246 $options['redirect_control_panel'] = '1';
1247
1248 if (!array_key_exists('show_redirect_box', $options))
1249 $options['show_redirect_box'] = '1';
1250
1251 if (!array_key_exists('reflect_modifications', $options))
1252 $options['reflect_modifications'] = '1';
1253
1254 if (!array_key_exists('history_status', $options))
1255 $options['history_status'] = '1';
1256
1257 if (!array_key_exists('history_limit', $options))
1258 $options['history_limit'] = '30';
1259
1260 if (!array_key_exists('p404_discovery_status', $options))
1261 $options['p404_discovery_status'] = '1';
1262
1263 if (!array_key_exists('p404_redirect_to', $options))
1264 $options['p404_redirect_to'] = site_url();
1265
1266 if (!array_key_exists('p404_status', $options))
1267 $options['p404_status'] = '2';
1268
1269 if (!array_key_exists('keep_data', $options))
1270 $options['keep_data'] = '1';
1271
1272 update_option(WP_SEO_REDIRECTION_OPTIONS, $options);
1273
1274
1275 $table_name = $table_prefix . 'WP_SEO_Redirection';
1276 if (strtolower($wpdb->get_var("show tables like '$table_name'")) != strtolower($table_name)) {
1277 $sql = "CREATE TABLE IF NOT EXISTS `$table_name` (
1278 `ID` int(11) unsigned NOT NULL AUTO_INCREMENT,
1279 `enabled` int(1) NOT NULL DEFAULT '1',
1280 `redirect_from` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL,
1281 `redirect_from_type` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
1282 `redirect_from_folder_settings` int(1) NOT NULL,
1283 `redirect_from_subfolders` int(1) NOT NULL DEFAULT '1',
1284 `redirect_to` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
1285 `redirect_to_type` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
1286 `redirect_to_folder_settings` int(1) NOT NULL DEFAULT '1',
1287 `regex` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
1288 `redirect_type` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
1289 `url_type` int(2) NOT NULL DEFAULT 1,
1290 `postID` int(11) unsigned DEFAULT NULL,
1291 `import_flag` tinyint(1) NOT NULL DEFAULT 0,
1292 `hits` int(11) unsigned NOT NULL DEFAULT 0,
1293 `access_date` datetime DEFAULT NULL,
1294 PRIMARY KEY (`ID`),
1295 UNIQUE KEY `redirect_from` (`redirect_from`)
1296 )ENGINE = MyISAM ;";
1297 $wpdb->query($sql);
1298 } else {
1299 //check if Innodb convert it to myisam.
1300 $status = $wpdb->get_row("SHOW TABLE STATUS WHERE Name = '$table_name'");
1301 if ($status->Engine == 'InnoDB') {
1302 $wpdb->query("alter table $table_name engine = MyISAM;");
1303 }
1304
1305 /* add column for import flag */
1306 $column_data = $wpdb->get_row("SHOW COLUMNS FROM $table_name LIKE 'import_flag'");
1307
1308 if (!$column_data) {
1309 $wpdb->query("ALTER TABLE $table_name ADD COLUMN import_flag tinyint(1) DEFAULT 0");
1310 }
1311
1312 $wpdb->query("ALTER TABLE $table_name CHANGE `redirect_from` `redirect_from` VARCHAR(191) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL;");
1313
1314 // if the table exists
1315 $redirects = $wpdb->get_results(" select redirect_from,redirect_to,ID from $table_name; ");
1316 foreach ($redirects as $redirect) {
1317 $redirect_from = $util->make_relative_url($redirect->redirect_from);
1318 $redirect_to = $util->make_relative_url($redirect->redirect_to);
1319 $ID = $redirect->ID;
1320 $wpdb->query($wpdb->prepare(" update $table_name set redirect_from=%s,redirect_to=%s where ID=%d", $redirect_from, $redirect_to, $ID));
1321 }
1322
1323 // Fix add blog field if not exist.
1324 if ($wpdb->get_var(" SELECT count(*) as cnt FROM INFORMATION_SCHEMA.COLUMNS
1325 WHERE TABLE_NAME = '$table_name'
1326 AND table_schema = DATABASE()
1327 AND COLUMN_NAME = 'hits' ") == '0') {
1328
1329 $sql = "
1330 ALTER TABLE $table_name
1331 ADD COLUMN `hits` int(11) unsigned NOT NULL DEFAULT 0,
1332 ADD COLUMN `access_date` datetime DEFAULT NULL;
1333 ";
1334
1335 $wpdb->query($sql);
1336 }
1337 }
1338
1339 $table_name = $table_prefix . 'WP_SEO_Cache';
1340 if (strtolower($wpdb->get_var("show tables like '$table_name'")) != strtolower($table_name)) {
1341 $sql = "CREATE TABLE IF NOT EXISTS `$table_name` (
1342 `ID` int(11) unsigned NOT NULL,
1343 `is_redirected` int(1) unsigned NOT NULL,
1344 `redirect_from` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
1345 `redirect_to` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
1346 `redirect_type` int(3) unsigned NOT NULL DEFAULT 301,
1347 PRIMARY KEY (`ID`)
1348 ) ENGINE = MyISAM ;
1349 ";
1350 $wpdb->query($sql);
1351 } else {
1352 //check if Innodb convert it to myisam.
1353 $status = $wpdb->get_row("SHOW TABLE STATUS WHERE Name = '$table_name'");
1354 if ($status->Engine == 'InnoDB') {
1355 $wpdb->query("alter table $table_name engine = MyISAM;");
1356 }
1357 }
1358
1359
1360 $res = $wpdb->get_var(" SELECT count(*) as cnt FROM INFORMATION_SCHEMA.COLUMNS
1361 WHERE TABLE_NAME = '$table_name'
1362 AND table_schema = DATABASE()
1363 AND COLUMN_NAME = 'redirect_from' ");
1364
1365 if ($res == '0') {
1366
1367 $sql = "
1368 ALTER TABLE $table_name
1369 ADD COLUMN `redirect_from` varchar(255) COLLATE utf8_unicode_ci NOT NULL;
1370 ";
1371 $wpdb->query($sql);
1372 }
1373
1374 $table_name = $table_prefix . 'WP_SEO_404_links';
1375 if (strtolower($wpdb->get_var("show tables like '$table_name'")) != strtolower($table_name)) {
1376 $sql = "CREATE TABLE IF NOT EXISTS `$table_name` (
1377 `ID` int(11) unsigned NOT NULL AUTO_INCREMENT,
1378 `ctime` datetime NOT NULL,
1379 `link` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
1380 `referrer` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
1381 `ip` varchar(20) COLLATE utf8_unicode_ci NOT NULL,
1382 `country` varchar(100) COLLATE utf8_unicode_ci NOT NULL,
1383 `os` varchar(20) COLLATE utf8_unicode_ci NOT NULL,
1384 `browser` varchar(20) COLLATE utf8_unicode_ci NOT NULL,
1385 PRIMARY KEY (`ID`),
1386 UNIQUE KEY `link` (`link`)
1387 ) ENGINE = MyISAM ;
1388 ";
1389 $wpdb->query($sql);
1390 } else {
1391 //check if Innodb convert it to myisam.
1392 $status = $wpdb->get_row("SHOW TABLE STATUS WHERE Name = '$table_name'");
1393 if ($status->Engine == 'InnoDB') {
1394 $wpdb->query("alter table $table_name engine = MyISAM;");
1395 }
1396 }
1397
1398
1399 $table_name = $wpdb->prefix . 'WP_SEO_Redirection_LOG';
1400
1401 if (strtolower($wpdb->get_var("SHOW TABLES LIKE '$table_name'")) != strtolower($table_name)) {
1402 $sql = "CREATE TABLE IF NOT EXISTS `$table_name` (
1403 `ID` int(11) unsigned NOT NULL AUTO_INCREMENT,
1404 `rID` int(11) unsigned DEFAULT NULL,
1405 `postID` int(11) unsigned DEFAULT NULL,
1406 `ctime` datetime NOT NULL,
1407 `rfrom` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
1408 `rto` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
1409 `rtype` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
1410 `rsrc` varchar(20) COLLATE utf8_unicode_ci NOT NULL,
1411 `referrer` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
1412 `ip` varchar(20) COLLATE utf8_unicode_ci NOT NULL,
1413 `country` varchar(100) COLLATE utf8_unicode_ci NOT NULL,
1414 `os` varchar(20) COLLATE utf8_unicode_ci NOT NULL,
1415 `browser` varchar(20) COLLATE utf8_unicode_ci NOT NULL,
1416 PRIMARY KEY (`ID`)
1417 ) ENGINE = MyISAM;";
1418
1419 $wpdb->query($sql);
1420 } else {
1421 // Check if InnoDB and convert to MyISAM if necessary
1422 $status = $wpdb->get_row("SHOW TABLE STATUS WHERE Name = '$table_name'");
1423 if ($status->Engine == 'InnoDB') {
1424 $wpdb->query("ALTER TABLE $table_name ENGINE = MyISAM;");
1425 }
1426
1427 // Check if the postID column exists and add it if missing
1428 $res = $wpdb->get_var("SELECT count(*) as cnt FROM INFORMATION_SCHEMA.COLUMNS
1429 WHERE TABLE_NAME = '$table_name'
1430 AND COLUMN_NAME = 'postID'
1431 AND table_schema = DATABASE()");
1432
1433 if ($res == '0') {
1434 $sql = "ALTER TABLE $table_name ADD COLUMN `postID` int(11) unsigned DEFAULT NULL;";
1435 $wpdb->query($sql);
1436 }
1437 }
1438 }
1439 }
1440 //---------------------------------------------------------------
1441
1442 if (!function_exists("WPSR_uninstall")) {
1443
1444 function WPSR_uninstall()
1445 {
1446 global $wpdb, $table_prefix;
1447
1448 $util = new clogica_util_1();
1449 $util->init(WP_SEO_REDIRECTION_OPTIONS, __FILE__);
1450
1451
1452 if ($util->get_option_value('keep_data') != '1') {
1453
1454 $table_name = $table_prefix . 'WP_SEO_Redirection';
1455 $wpdb->query($wpdb->prepare(" DROP TABLE %s ", $table_name));
1456
1457 $table_name = $table_prefix . 'WP_SEO_Cache';
1458 $wpdb->query($wpdb->prepare(" DROP TABLE %s ", $table_name));
1459
1460 $table_name = $table_prefix . 'WP_SEO_404_links';
1461 $wpdb->query($wpdb->prepare(" DROP TABLE %s ", $table_name));
1462
1463 $table_name = $table_prefix . 'WP_SEO_Redirection_LOG';
1464 $wpdb->query($wpdb->prepare(" DROP TABLE %s ", $table_name));
1465
1466
1467 $util->delete_my_options();
1468 }
1469 }
1470 }
1471 //---------------------------------------------------------------
1472 if (!function_exists("WPSR_HideMessageAjaxFunction")) {
1473
1474 function WPSR_HideMessageAjaxFunction()
1475 {
1476 add_option('nsr_upgrade_message', 'yes');
1477 }
1478 }
1479 //---------------------------------------------------------------
1480 if (!function_exists("WPSR_admin_notice_callback")) {
1481
1482 /* display import from redirection plugin in admin notice */
1483 function WPSR_admin_notice_callback()
1484 {
1485 global $wpdb;
1486 global $current_user;
1487 $plugins = get_option('active_plugins', array());
1488 $found = false;
1489 $user_id = $current_user->ID;
1490 $val = get_user_meta($user_id, 'sr_notice_dismissed', true);
1491
1492 foreach ($plugins as $plugin) {
1493 if (strpos(strval($plugin), 'redirection.php') == true && $val != 1 && strpos(strval($plugin), 'seo-redirection.php') == FALSE) {
1494 $found = true;
1495 //$total = $wpdb->get_var( "SELECT COUNT(*) FROM {$wpdb->prefix}redirection_items");
1496 $total = WPSR_getRedirectCount();
1497 if ($total > 0) {
1498 ?>
1499 <div class="notice-success notice is-dismissible sr_notice">
1500 <p>
1501 <strong><?php _e('SEO Redirection : ', 'seo-redirection'); ?></strong><?php echo __('The plugin detected ', 'seo-redirection') . intval($total) . __(' redirects in the Redirection plugin, Import it now. ', 'seo-redirection'); ?>
1502 <?php
1503 $SR_import = isset($_GET['SR_import']) ? sanitize_text_field($_GET['SR_import']) : '';
1504 if ($SR_import == 'yes') { ?>
1505 <button type='button' data-toggle="modal" class="button" href="#" data-target="#import_modal" value="btn_import"><span style="margin-top: 3px;" class="dashicons dashicons-migrate"></span>&nbsp; <?php _e('Import Now', 'seo-redirection'); ?></button>
1506 <?php } else { ?>
1507 <a href="options-general.php?page=seo-redirection.php&tab=export_import&SR_import=yes" data-target="#import_modal" value="btn_import"><?php _e('Import', 'seo-redirection'); ?></a>
1508 <?php } ?>
1509 </p>
1510 </div>
1511 <?php
1512 }
1513 break;
1514 }
1515 }
1516 }
1517 add_action('admin_notices', 'WPSR_admin_notice_callback');
1518 }
1519
1520 if (!function_exists("WPSR_dismiss_notice_callback")) {
1521
1522 add_action('wp_ajax_sr_dismiss_notice', 'WPSR_dismiss_notice_callback');
1523 function WPSR_dismiss_notice_callback()
1524 {
1525 global $current_user;
1526 $user_id = $current_user->ID;
1527 update_user_meta($user_id, 'sr_notice_dismissed', '1');
1528 echo "1";
1529 exit;
1530 }
1531 }
1532 if (!function_exists("WPSR_getRedirectCount")) {
1533
1534 function WPSR_getRedirectCount()
1535 {
1536 global $wpdb;
1537
1538 $table_name_ = $wpdb->prefix . 'redirection_items';
1539 if (strtolower($wpdb->get_var("show tables like '$table_name_'")) == strtolower($table_name_)) {
1540 $result = $wpdb->get_results("SELECT url FROM {$wpdb->prefix}redirection_items");
1541 $cnt = 0;
1542 $table_name = $wpdb->prefix . 'WP_SEO_Redirection';
1543 if ($result) {
1544 foreach ($result as $redirect) {
1545 $redirect_from = stripslashes($redirect->url);
1546 $redirect_from_slash = ltrim(stripslashes($redirect->url), '/');
1547 $redirectID = $wpdb->get_var($wpdb->prepare("select ID from $table_name where redirect_from=%s or redirect_from=%s", $redirect_from, $redirect_from_slash));
1548 if ($redirectID > 0) {
1549 } else {
1550 $cnt++;
1551 }
1552 }
1553 }
1554 return $cnt;
1555 } else {
1556 return 0;
1557 }
1558 }
1559 }
1560 if (!function_exists("SR_init_delete_callback")) {
1561
1562 add_action('admin_init', 'SR_init_delete_callback');
1563 function SR_init_delete_callback()
1564 {
1565 if (isset($_POST['redirect_id']) && count($_POST['redirect_id']) > 0) {
1566
1567 // Security: deleting redirect rules is an admin-only operation.
1568 if (!current_user_can('manage_options')) {
1569 return;
1570 }
1571
1572 $nonce = '';
1573 if (isset($_REQUEST['_wpnonce']))
1574 $nonce = WPSR_sanitize_text_or_array_field($_REQUEST['_wpnonce']);
1575
1576 if (wp_verify_nonce($nonce, 'seoredirection')) {
1577
1578 global $wpdb, $table_prefix, $util;
1579 $table_name = $wpdb->prefix . 'WP_SEO_Redirection';
1580 foreach ($_POST['redirect_id'] as $post_id) {
1581 $post_id = (int)$post_id;
1582 $wpdb->query($wpdb->prepare(" delete from $table_name where ID=%s ", $post_id));
1583 $SR_redirect_cache = new free_SR_redirect_cache();
1584 $SR_redirect_cache->free_cache();
1585 }
1586 }
1587 }
1588 }
1589 }
1590
1591
1592
1593
1594 //---------------------------------------------------------------
1595
1596 function WPSR_HideMessageAjaxFunction()
1597 {
1598 add_option('nsr_upgrade_message', 'yes');
1599 }
1600
1601
1602 function WPSR_after_plugin_row($plugin_file, $plugin_data, $status)
1603 {
1604
1605 if (get_option('nsr_upgrade_message') != 'yes') {
1606 $class_name = $plugin_data['slug'];
1607 $class_name = isset($plugin_data['slug']) ? $plugin_data['slug'] : 'seo-redirection';
1608
1609 echo '<tr id="' . $class_name . '-plugin-update-tr" class="plugin-update-tr active">';
1610 echo '<td colspan="6" class="plugin-update">';
1611 echo '<div id="' . $class_name . '-upgradeMsg" class="update-message notice inline notice-warning notice-alt" >';
1612
1613 echo 'You are running SEO redirection free. To get more features, you can <a href="http://www.wp-buy.com/product/seo-redirection-premium-wordpress-plugin" target="_blank"><strong>upgrade now</strong></a> or ';
1614
1615 echo '<span id="HideMe" style="cursor:pointer" ><a href="javascript:void(0)"><strong>dismiss</strong></a> this message</span>';
1616 echo '</div>';
1617 echo '</td>';
1618 echo '</tr>';
1619
1620 ?>
1621
1622 <script type="text/javascript">
1623 jQuery(document).ready(function() {
1624 var row = jQuery('#<?php echo $class_name; ?>-plugin-update-tr').closest('tr').prev();
1625 jQuery(row).addClass('update');
1626
1627 jQuery("#HideMe").click(function() {
1628 jQuery.ajax({
1629 type: 'POST',
1630 url: '<?php echo admin_url(); ?>/admin-ajax.php',
1631 data: {
1632 action: 'WPSR_HideMessageAjaxFunction'
1633 },
1634 success: function(data, textStatus, XMLHttpRequest) {
1635
1636 jQuery("#<?php echo $class_name; ?>-upgradeMsg").hide();
1637
1638 },
1639 error: function(MLHttpRequest, textStatus, errorThrown) {
1640 alert(errorThrown);
1641 }
1642 });
1643 });
1644
1645 });
1646 </script>
1647
1648 <?php
1649 }
1650 }
1651
1652 $path = plugin_basename(__FILE__);
1653 add_action("after_plugin_row_{$path}", 'WPSR_after_plugin_row', 10, 3);
1654 // creating Ajax call for WordPress
1655 add_action('wp_ajax_nopriv_WPSR_HideMessageAjaxFunction', 'WPSR_HideMessageAjaxFunction');
1656 add_action('wp_ajax_WPSR_HideMessageAjaxFunction', 'WPSR_HideMessageAjaxFunction');
1657 //---------------------------------------------------------------
1658
1659 ?>