| 1 |
<?php |
| 2 |
|
| 3 |
namespace BetterLinks\Admin\Notice; |
| 4 |
if ( ! defined( 'ABSPATH' ) ) { exit; } |
| 5 |
|
| 6 |
use BetterLinks\Abstracts\MigrationNotice; |
| 7 |
|
| 8 |
class Simple301 extends MigrationNotice |
| 9 |
{ |
| 10 |
public static $pagenow; |
| 11 |
public static function init() |
| 12 |
{ |
| 13 |
$self = new self(); |
| 14 |
global $pagenow; |
| 15 |
$self::$pagenow = $pagenow; |
| 16 |
if (defined('SIMPLE301REDIRECTS_VERSION') && !get_option('betterlinks_notice_s301r_migrate')) { |
| 17 |
if (!get_option('betterlinks_hide_notice_s301r_migrate')) { |
| 18 |
add_action('admin_notices', [$self, 'migration_notice'], 100); |
| 19 |
add_action('admin_print_footer_scripts', [$self, 'admin_scripts']); |
| 20 |
} |
| 21 |
} elseif (defined('SIMPLE301REDIRECTS_VERSION') && get_option('betterlinks_notice_s301r_migrate')) { |
| 22 |
if (!get_option('betterlinks_hide_notice_s301r_deactive')) { |
| 23 |
// phpcs:ignore WordPress.Security.NonceVerification.Recommended -- read-only page check, no state mutation. |
| 24 |
if (!isset($_GET['page']) || (isset($_GET['page']) && $_GET['page'] !== '301options')) { |
| 25 |
add_action('admin_notices', [$self, 'deactive_notice'], 100); |
| 26 |
} |
| 27 |
add_action('admin_print_footer_scripts', [$self, 'admin_scripts']); |
| 28 |
} |
| 29 |
} |
| 30 |
} |
| 31 |
|
| 32 |
public function migration_notice() |
| 33 |
{ |
| 34 |
?> |
| 35 |
<div class="notice notice-info betterlinks-notice-simple301redirects-migrate <?php echo self::$pagenow !== 'admin.php' ? 'is-dismissible' : ''; ?>"> |
| 36 |
<p> |
| 37 |
<?php esc_html_e('Whoops! You are already using Simple 301 Redirects on your website. To migrate your Simple 301 Redirects data to BetterLinks, click here.', 'betterlinks'); ?> |
| 38 |
<a href="<?php echo esc_url(admin_url('admin.php?page=betterlinks-settings&migration=simple301redirects')); ?>" class="button button-primary"><?php esc_html_e( |
| 39 |
'Start Migration', |
| 40 |
'betterlinks' |
| 41 |
); ?></a> |
| 42 |
</p> |
| 43 |
</div> |
| 44 |
<?php |
| 45 |
} |
| 46 |
public function deactive_notice() |
| 47 |
{ |
| 48 |
?> |
| 49 |
<div class="notice notice-error betterlinks-notice-deactive-simple301redirects <?php echo self::$pagenow !== 'admin.php' ? 'is-dismissible' : ''; ?>"> |
| 50 |
<p> |
| 51 |
<?php esc_html_e('All Simple 301 Redirects have been successfully migrated to BetterLinks. You can now safely deactivate Simple 301 Redirects on your website.', 'betterlinks'); ?> |
| 52 |
<a href="#" class="button button-primary deactive"><?php esc_html_e('Deactivate Simple 301 Redirects', 'betterlinks'); ?></a> |
| 53 |
</p> |
| 54 |
</div> |
| 55 |
<?php |
| 56 |
} |
| 57 |
|
| 58 |
public function admin_scripts() |
| 59 |
{ |
| 60 |
$nonce = wp_create_nonce('betterlinks_admin_nonce'); ?> |
| 61 |
<script type='text/javascript'> |
| 62 |
jQuery( document ).ready(function() { |
| 63 |
jQuery('.betterlinks-notice-deactive-simple301redirects a.deactive').on('click', function(e){ |
| 64 |
e.preventDefault(); |
| 65 |
jQuery.post(ajaxurl, { |
| 66 |
'action': 'betterlinks/admin/deactive_simple301redirects', |
| 67 |
'security': "<?php echo esc_attr($nonce); ?>" |
| 68 |
}, function(response) { |
| 69 |
if(response.success){ |
| 70 |
location.reload(true); |
| 71 |
} |
| 72 |
}); |
| 73 |
}) |
| 74 |
jQuery('.betterlinks-notice-deactive-simple301redirects button.notice-dismiss').on('click', function(){ |
| 75 |
jQuery.post(ajaxurl, { |
| 76 |
'action': 'betterlinks/admin/migration_simple301redirects_notice_hide', |
| 77 |
'security': "<?php echo esc_attr($nonce); ?>", |
| 78 |
'type': 'deactive' |
| 79 |
}, function(response) {}); |
| 80 |
}) |
| 81 |
jQuery('.betterlinks-notice-simple301redirects-migrate button.notice-dismiss').on('click', function(){ |
| 82 |
jQuery.post(ajaxurl, { |
| 83 |
'action': 'betterlinks/admin/migration_simple301redirects_notice_hide', |
| 84 |
'security': "<?php echo esc_attr($nonce); ?>", |
| 85 |
'type': 'migrate' |
| 86 |
}, function(response) {}); |
| 87 |
}) |
| 88 |
}); |
| 89 |
</script> |
| 90 |
<?php |
| 91 |
} |
| 92 |
} |
| 93 |
|