| 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\Api\Utils; |
| 15 |
|
| 16 |
use Buttonizer\Core\Utils\PermissionCheck; |
| 17 |
use Buttonizer\Migration\LegacyFallback; |
| 18 |
|
| 19 |
/** |
| 20 |
* Go back to an absorbed plugin's old system. |
| 21 |
* |
| 22 |
* The counterpart of the acquired plugin's own "use legacy version" link, kept |
| 23 |
* available to users who moved to Buttonizer so the move never costs them the |
| 24 |
* escape hatch they had before. |
| 25 |
* |
| 26 |
* @endpoint /wp-json/buttonizer/use_legacy_module |
| 27 |
* @methods POST |
| 28 |
*/ |
| 29 |
class UseLegacyModule |
| 30 |
{ |
| 31 |
/** |
| 32 |
* Register route |
| 33 |
*/ |
| 34 |
public function registerRoute() |
| 35 |
{ |
| 36 |
register_rest_route('buttonizer', '/use_legacy_module', [ |
| 37 |
[ |
| 38 |
'methods' => ['POST'], |
| 39 |
'args' => [ |
| 40 |
'nonce' => [ |
| 41 |
'validate_callback' => function ($value) { |
| 42 |
return wp_verify_nonce($value, 'wp_rest'); |
| 43 |
}, |
| 44 |
'required' => true |
| 45 |
], |
| 46 |
], |
| 47 |
'callback' => [$this, 'useLegacy'], |
| 48 |
'permission_callback' => function () { |
| 49 |
return PermissionCheck::hasPermission(true); |
| 50 |
} |
| 51 |
] |
| 52 |
]); |
| 53 |
} |
| 54 |
|
| 55 |
/** |
| 56 |
* Restore the old system. |
| 57 |
*/ |
| 58 |
public function useLegacy() |
| 59 |
{ |
| 60 |
$redirect = LegacyFallback::restore(); |
| 61 |
|
| 62 |
if (!$redirect) { |
| 63 |
return new \WP_Error('no_legacy_system', 'There is no legacy system to go back to on this site.', [ |
| 64 |
'status' => 404 |
| 65 |
]); |
| 66 |
} |
| 67 |
|
| 68 |
return [ |
| 69 |
'status' => 'success', |
| 70 |
'redirect' => $redirect, |
| 71 |
]; |
| 72 |
} |
| 73 |
} |
| 74 |
|