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 / PrettyLinks.php

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

126 lines 5.6 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 PrettyLinks extends MigrationNotice
9 {
10 public static $pagenow;
11 public static $failed_links = [];
12 public static $failed_clicks = [];
13 public static $total_successful_links = 0;
14 public static $total_successful_clicks = 0;
15 public static function init()
16 {
17 $self = new self();
18 if(defined('PRLI_VERSION')){
19 $self::$failed_links = \BetterLinks\Helper::btl_get_option("btl_failed_migration_prettylinks_links");
20 $self::$failed_clicks = \BetterLinks\Helper::btl_get_option("btl_failed_migration_prettylinks_clicks");
21 $self::$total_successful_links = \BetterLinks\Helper::btl_get_option("btl_migration_prettylinks_current_successful_links_count");
22 $self::$total_successful_clicks = \BetterLinks\Helper::btl_get_option("btl_migration_prettylinks_current_successful_clicks_count");
23 if (!get_option('betterlinks_notice_ptl_migrate')) {
24 global $pagenow;
25 $self::$pagenow = $pagenow;
26 if (!get_option('betterlinks_hide_notice_ptl_migrate') || $pagenow === 'admin.php') {
27 if(get_option('betterlinks_notice_ptl_migration_running_in_background')){
28 add_action('admin_notices', [$self, 'migration_running_notice'], 100);
29 }else{
30 add_action('admin_notices', [$self, 'migration_notice'], 100);
31 }
32 add_action('admin_print_footer_scripts', [$self, 'admin_scripts']);
33 }
34 } else {
35 global $pagenow;
36 $self::$pagenow = $pagenow;
37 if (!get_option('betterlinks_hide_notice_ptl_deactive')) {
38 // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- read-only post-type check, no state mutation.
39 if (!isset($_GET['post_type']) || (isset($_GET['post_type']) && $_GET['post_type'] !== 'pretty-link')) {
40 add_action('admin_notices', [$self, 'deactive_notice'], 100);
41 }
42 add_action('admin_print_footer_scripts', [$self, 'admin_scripts']);
43 }
44 }
45 }
46 }
47
48 public function migration_running_notice()
49 {
50 // todo: get the total successful links & clicks count here
51 ?>
52 <div class="notice notice-info betterlinks-notice-pt-migrate <?php echo self::$pagenow !== 'admin.php' ? 'is-dismissible' : ''; ?>">
53 <p>
54 <?php esc_html_e('Migration of Pretty Links data to BetterLinks is currently running in background. Migration might take a little while, please be patient.', 'betterlinks'); ?>
55 </p>
56 </div>
57 <?php
58 }
59
60 public function migration_notice()
61 {
62 ?>
63 <div class="notice notice-info betterlinks-notice-pt-migrate <?php echo self::$pagenow !== 'admin.php' ? 'is-dismissible' : ''; ?>">
64 <p>
65 <?php esc_html_e('Whoops! You are already using Pretty Links on your website. To migrate your Pretty Links data to BetterLinks, click here.', 'betterlinks'); ?>
66 <a href="<?php echo esc_url(admin_url('admin.php?page=betterlinks-settings&migration=prettylinks')); ?>" class="button button-primary"><?php esc_html_e('Start Migration', 'betterlinks'); ?></a>
67 </p>
68 </div>
69 <?php
70 }
71 public function deactive_notice()
72 {
73 ?>
74 <div class="notice notice-error betterlinks-notice-deactive-prettylinks <?php echo self::$pagenow !== 'admin.php' ? 'is-dismissible' : ''; ?>">
75 <p>
76 <?php esc_html_e('All Pretty Links have been successfully migrated to BetterLinks. You can now safely deactivate Pretty Links on your website.', 'betterlinks'); ?>
77 <a href="#" class="button button-primary deactive"><?php esc_html_e('Deactivate Pretty Links', 'betterlinks'); ?></a>
78 </p>
79 </div>
80 <?php
81 }
82
83 public function admin_scripts()
84 {
85 $nonce = wp_create_nonce('betterlinks_admin_nonce'); ?>
86 <script type='text/javascript'>
87 window.betterlinksAdminPrettylinksMigrationRequiredDatas = {
88 failed_links: <?php echo wp_json_encode(self::$failed_links); ?>,
89 failed_clicks: <?php echo wp_json_encode(self::$failed_clicks); ?>,
90 total_successful_links: <?php echo wp_json_encode(self::$total_successful_links); ?>,
91 total_successful_clicks: <?php echo wp_json_encode(self::$total_successful_clicks); ?>,
92 }
93 jQuery( document ).ready(function() {
94 jQuery('.betterlinks-notice-deactive-prettylinks a.deactive').on('click', function(e){
95 e.preventDefault();
96 jQuery.post(ajaxurl, {
97 'action': 'betterlinks/admin/deactive_prettylinks',
98 'security': "<?php echo esc_attr( $nonce ); ?>"
99 }, function(response) {
100 if(response.success){
101 location.reload(true);
102 }
103 });
104 })
105
106 jQuery('.betterlinks-notice-deactive-prettylinks button.notice-dismiss').on('click', function(){
107 jQuery.post(ajaxurl, {
108 'action': 'betterlinks/admin/migration_prettylinks_notice_hide',
109 'security': "<?php echo esc_attr( $nonce ); ?>",
110 'type': 'deactive'
111 }, function(response) {});
112 })
113
114 jQuery('.betterlinks-notice-pt-migrate button.notice-dismiss').on('click', function(){
115 jQuery.post(ajaxurl, {
116 'action': 'betterlinks/admin/migration_prettylinks_notice_hide',
117 'security': "<?php echo esc_attr( $nonce ); ?>",
118 'type': 'migrate'
119 }, function(response) {});
120 })
121 });
122 </script>
123 <?php
124 }
125 }
126