PluginProbe
BetterLinks – Link Shortener, Link Cloaking, Redirects, Affiliate Link Manager & MCP / trunk
BetterLinks – Link Shortener, Link Cloaking, Redirects, Affiliate Link Manager & MCP vtrunk
3.1.3 3.1.2 3.1.1 3.1.0 3.0.1 3.0.0 2.4.13 2.4.12 2.4.11 2.4.10 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.0.4 1.0.5 1.1.0 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.1.6 1.1.7 All 110 releases
betterlinks / includes / Admin / Notice / Simple301.php

Simple301.php in BetterLinks – Link Shortener, Link Cloaking, Redirects, Affiliate Link Manager & MCP trunk, at includes/Admin/Notice/Simple301.php

93 lines 3.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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