| 1 |
<?php |
| 2 |
/** |
| 3 |
* The one-time "turn on cleanup" prompt. |
| 4 |
* |
| 5 |
* @package Templately |
| 6 |
*/ |
| 7 |
|
| 8 |
namespace Templately\Modules\Utilities\Notice; |
| 9 |
|
| 10 |
use Templately\Modules\Utilities\Cleanup\Activation; |
| 11 |
|
| 12 |
/** |
| 13 |
* Lives OUTSIDE the settings page on purpose. |
| 14 |
* |
| 15 |
* The activation gate means an unactivated site reclaims nothing, ever — that |
| 16 |
* was a deliberate decision, and its whole cost falls on administrators who |
| 17 |
* never open the plugin's settings. If the only way to discover the prompt were |
| 18 |
* inside the tab, those are exactly the sites that would keep leaking. |
| 19 |
* |
| 20 |
* Dismissal hides the notice but is NOT consent: the tab keeps showing the |
| 21 |
* pending state and the prompt remains reachable, so dismissing once cannot |
| 22 |
* silently strand a site in "nothing is ever reclaimed and nothing says so". |
| 23 |
*/ |
| 24 |
final class ActivationNotice { |
| 25 |
|
| 26 |
public static function boot(): void { |
| 27 |
add_action( 'admin_notices', [ self::class, 'render' ] ); |
| 28 |
} |
| 29 |
|
| 30 |
public static function render(): void { |
| 31 |
if ( ! current_user_can( 'manage_options' ) ) { |
| 32 |
return; |
| 33 |
} |
| 34 |
|
| 35 |
// Only when there is genuinely something to reclaim — a site with a clean |
| 36 |
// uploads directory should never see this. |
| 37 |
if ( ! Activation::should_prompt() ) { |
| 38 |
return; |
| 39 |
} |
| 40 |
|
| 41 |
$state = Activation::state(); |
| 42 |
// The settings SPA is its OWN admin page (`templately_settings`), not a |
| 43 |
// path inside the template library. Pointing at the library page lands on |
| 44 |
// the router's catch-all and renders an unrelated view — verified in a |
| 45 |
// live instance, which is the only place that shows up. |
| 46 |
$settings = admin_url( 'admin.php?page=templately_settings&path=settings/elementor/utilities' ); |
| 47 |
|
| 48 |
printf( |
| 49 |
'<div class="notice notice-info"><p>%s</p><p><a class="button button-primary" href="%s">%s</a></p></div>', |
| 50 |
esc_html( |
| 51 |
sprintf( |
| 52 |
/* translators: %s: reclaimable size, e.g. "412 MB". */ |
| 53 |
__( 'Templately can reclaim about %s of leftover import files. Nothing is removed until you turn cleanup on.', 'templately' ), |
| 54 |
size_format( (int) $state['last_estimate_bytes'] ) |
| 55 |
) |
| 56 |
), |
| 57 |
esc_url( $settings ), |
| 58 |
esc_html__( 'Review and turn on cleanup', 'templately' ) |
| 59 |
); |
| 60 |
} |
| 61 |
} |
| 62 |
|