| 1 |
<?php |
| 2 |
/** |
| 3 |
* UI: Parse.ly wp-admin warning class |
| 4 |
* |
| 5 |
* @package Parsely |
| 6 |
* @since 3.0.0 |
| 7 |
*/ |
| 8 |
|
| 9 |
declare(strict_types=1); |
| 10 |
|
| 11 |
namespace Parsely\UI; |
| 12 |
|
| 13 |
use Parsely\Parsely; |
| 14 |
|
| 15 |
/** |
| 16 |
* Conditionally renders a warning message on wp-admin. |
| 17 |
* |
| 18 |
* @since 3.0.0 |
| 19 |
*/ |
| 20 |
final class Admin_Warning { |
| 21 |
/** |
| 22 |
* Instance of Parsely class. |
| 23 |
* |
| 24 |
* @var Parsely |
| 25 |
*/ |
| 26 |
private $parsely; |
| 27 |
|
| 28 |
/** |
| 29 |
* Constructor. |
| 30 |
* |
| 31 |
* @param Parsely $parsely Instance of Parsely class. |
| 32 |
*/ |
| 33 |
public function __construct( Parsely $parsely ) { |
| 34 |
$this->parsely = $parsely; |
| 35 |
} |
| 36 |
|
| 37 |
/** |
| 38 |
* Registers admin warning. |
| 39 |
* |
| 40 |
* @since 3.0.0 |
| 41 |
*/ |
| 42 |
public function run(): void { |
| 43 |
add_action( 'admin_notices', array( $this, 'display_admin_warning' ) ); |
| 44 |
} |
| 45 |
|
| 46 |
/** |
| 47 |
* Displays the admin warning if needed. |
| 48 |
*/ |
| 49 |
public function display_admin_warning(): void { |
| 50 |
if ( ! $this->should_display_admin_warning() ) { |
| 51 |
return; |
| 52 |
} |
| 53 |
|
| 54 |
$message = sprintf( |
| 55 |
/* translators: %s: Plugin settings page URL */ |
| 56 |
__( '<strong>The Parse.ly plugin is not active.</strong> You need to <a href="%s">provide your Parse.ly Dash Site ID</a> before things get cooking.', 'wp-parsely' ), |
| 57 |
esc_url( Parsely::get_settings_url() ) |
| 58 |
); |
| 59 |
?> |
| 60 |
<div id="wp-parsely-apikey-error-notice" class="notice notice-error"><p><?php echo wp_kses_post( $message ); ?></p></div> |
| 61 |
<?php |
| 62 |
} |
| 63 |
|
| 64 |
/** |
| 65 |
* Returns whether the admin display warning should be displayed. |
| 66 |
* |
| 67 |
* @since 2.6.0 |
| 68 |
* |
| 69 |
* @return bool True if the admin warning should be displayed. |
| 70 |
*/ |
| 71 |
private function should_display_admin_warning(): bool { |
| 72 |
if ( is_network_admin() ) { |
| 73 |
return false; |
| 74 |
} |
| 75 |
|
| 76 |
return $this->parsely->api_key_is_missing(); |
| 77 |
} |
| 78 |
} |
| 79 |
|