| 1 |
<?php |
| 2 |
/* |
| 3 |
* SOFTWARE LICENSE INFORMATION |
| 4 |
* |
| 5 |
* Copyright (c) 2017 Buttonizer, all rights reserved. |
| 6 |
* |
| 7 |
* This file is part of Buttonizer |
| 8 |
* |
| 9 |
* For detailed information regarding to the licensing of |
| 10 |
* this software, please review the license.txt or visit: |
| 11 |
* https://buttonizer.pro/license/ |
| 12 |
*/ |
| 13 |
|
| 14 |
namespace Buttonizer\Migration; |
| 15 |
|
| 16 |
# No script kiddies |
| 17 |
defined('ABSPATH') or die('No script kiddies please!'); |
| 18 |
|
| 19 |
/** |
| 20 |
* The one thing the user gets to see about the migration. |
| 21 |
* |
| 22 |
* Light on purpose: their plugin kept working, their settings are where they |
| 23 |
* were, and the only real change is which menu item they click. |
| 24 |
*/ |
| 25 |
class AdminNotice |
| 26 |
{ |
| 27 |
const DISMISS_ACTION = 'buttonizer_dismiss_migration_notice'; |
| 28 |
|
| 29 |
/** |
| 30 |
* Where the notice sends someone who hit a problem. |
| 31 |
*/ |
| 32 |
const SUPPORT_URL = 'https://r.buttonizer.io/support/community?utm_source=wp-plugin-migration-notice'; |
| 33 |
|
| 34 |
/** |
| 35 |
* Handle the dismiss link. |
| 36 |
*/ |
| 37 |
public static function handleDismiss(): void |
| 38 |
{ |
| 39 |
if (!isset($_GET[self::DISMISS_ACTION])) { |
| 40 |
return; |
| 41 |
} |
| 42 |
|
| 43 |
$moduleId = sanitize_text_field(wp_unslash($_GET[self::DISMISS_ACTION])); |
| 44 |
|
| 45 |
if (!isset($_GET['_wpnonce']) || !wp_verify_nonce($_GET['_wpnonce'], self::DISMISS_ACTION . $moduleId)) { |
| 46 |
return; |
| 47 |
} |
| 48 |
|
| 49 |
if (!SourcePlugins::get($moduleId)) { |
| 50 |
return; |
| 51 |
} |
| 52 |
|
| 53 |
MigrationState::set($moduleId, ['notice_dismissed' => true]); |
| 54 |
} |
| 55 |
|
| 56 |
/** |
| 57 |
* Render the notice for every module migrated on this site. |
| 58 |
*/ |
| 59 |
public static function render(): void |
| 60 |
{ |
| 61 |
if (!Handoff::currentUserCanManagePlugins()) { |
| 62 |
return; |
| 63 |
} |
| 64 |
|
| 65 |
foreach (SourcePlugins::all() as $source) { |
| 66 |
$state = MigrationState::get($source->id()); |
| 67 |
|
| 68 |
if (empty($state['status']) || $state['status'] !== MigrationState::STATUS_MIGRATED) { |
| 69 |
continue; |
| 70 |
} |
| 71 |
|
| 72 |
if (!empty($state['notice_dismissed'])) { |
| 73 |
continue; |
| 74 |
} |
| 75 |
|
| 76 |
// The user reactivated the source plugin, which now explains itself |
| 77 |
// from its own admin notice. Two notices saying the same thing in |
| 78 |
// the same screen is worse than one. |
| 79 |
if ($source->isActive()) { |
| 80 |
continue; |
| 81 |
} |
| 82 |
|
| 83 |
// The signup screen already told the user this was coming, right |
| 84 |
// before they clicked the button that did it — no need to say it |
| 85 |
// again once they land in Buttonizer. |
| 86 |
if (!empty($state['handover'])) { |
| 87 |
continue; |
| 88 |
} |
| 89 |
|
| 90 |
self::renderFor($source); |
| 91 |
|
| 92 |
// Said once, on the first screen after the move, and never again. |
| 93 |
// The Dismiss link is still there to close it on the spot rather |
| 94 |
// than having to look at it for the rest of the page. |
| 95 |
MigrationState::set($source->id(), ['notice_dismissed' => true]); |
| 96 |
} |
| 97 |
} |
| 98 |
|
| 99 |
/** |
| 100 |
* Render the notice for a single module. |
| 101 |
* |
| 102 |
* @param SourcePlugin $source Source plugin descriptor. |
| 103 |
*/ |
| 104 |
private static function renderFor(SourcePlugin $source): void |
| 105 |
{ |
| 106 |
$dismissUrl = wp_nonce_url( |
| 107 |
add_query_arg(self::DISMISS_ACTION, $source->id()), |
| 108 |
self::DISMISS_ACTION . $source->id() |
| 109 |
); |
| 110 |
|
| 111 |
// One wording for every way a site can get here. It holds for the user |
| 112 |
// whose old system is now served from inside Buttonizer, for the one |
| 113 |
// whose cloud account came across, and for the one who had nothing to |
| 114 |
// bring: in all three the features moved, and nothing looks different. |
| 115 |
$message = sprintf( |
| 116 |
/* translators: %s: link to the support community, already built. */ |
| 117 |
esc_html__('Your plugin features and related settings have been successfully migrated to our main Buttonizer plugin! Everything should look and function the same as before. If you notice any issues or have any questions, please feel free to ask our %s for assistance.', 'buttonizer-multifunctional-button'), |
| 118 |
'<a href="' . esc_url(self::SUPPORT_URL) . '" target="_blank" rel="noopener">' . esc_html__('support team', 'buttonizer-multifunctional-button') . '</a>' |
| 119 |
); |
| 120 |
|
| 121 |
// The move worked. Saying so in the colour WordPress uses for that |
| 122 |
// answers the question before the user has to ask it. |
| 123 |
echo '<div class="notice notice-success">'; |
| 124 |
echo '<p>' . $message . '</p>'; |
| 125 |
echo '<p>'; |
| 126 |
echo '<a href="' . esc_url($dismissUrl) . '">' . esc_html__('Dismiss', 'buttonizer-multifunctional-button') . '</a>'; |
| 127 |
echo '</p>'; |
| 128 |
echo '</div>'; |
| 129 |
} |
| 130 |
} |
| 131 |
|