| 1 |
<?php |
| 2 |
|
| 3 |
namespace Leadin\admin; |
| 4 |
|
| 5 |
use Leadin\data\User; |
| 6 |
use Leadin\admin\Connection; |
| 7 |
use Leadin\data\User_Metadata; |
| 8 |
use Leadin\admin\AdminConstants; |
| 9 |
use Leadin\admin\ReviewBanner; |
| 10 |
|
| 11 |
/** |
| 12 |
* Class responsible for rendering the admin notices. |
| 13 |
*/ |
| 14 |
class NoticeManager { |
| 15 |
|
| 16 |
|
| 17 |
/** |
| 18 |
* Class constructor, adds the necessary hooks. |
| 19 |
*/ |
| 20 |
public function __construct() { |
| 21 |
add_action( 'admin_notices', array( $this, 'leadin_action_required_notice' ) ); |
| 22 |
} |
| 23 |
|
| 24 |
/** |
| 25 |
* Render the disconnected banner. |
| 26 |
*/ |
| 27 |
private function leadin_render_disconnected_banner() { |
| 28 |
?> |
| 29 |
<div id="leadin-disconnected-banner" class="leadin-banner notice notice-warning is-dismissible"> |
| 30 |
<p> |
| 31 |
<img src="<?php echo esc_attr( LEADIN_ASSETS_PATH . '/images/sprocket.svg' ); ?>" height="16" style="margin-bottom: -3px" /> |
| 32 |
|
| 33 |
<?php |
| 34 |
echo sprintf( |
| 35 |
/* translators: %1$s: HTML anchor opening tag %2$s: HTML anchor closing tag */ |
| 36 |
esc_html( __( 'The HubSpot plugin is not connected right now To use HubSpot tools on your WordPress site, %1$sconnect the plugin now%2$s', 'leadin' ) ), |
| 37 |
'<a class="leadin-banner__link" href="admin.php?page=leadin&bannerClick=true">', |
| 38 |
'</a>' |
| 39 |
); |
| 40 |
?> |
| 41 |
</p> |
| 42 |
</div> |
| 43 |
<?php |
| 44 |
} |
| 45 |
|
| 46 |
/** |
| 47 |
* Find what notice (if any) needs to be rendered |
| 48 |
*/ |
| 49 |
public function leadin_action_required_notice() { |
| 50 |
$current_screen = get_current_screen(); |
| 51 |
if ( User::is_admin() ) { |
| 52 |
if ( self::should_show_disconnected_notice() ) { |
| 53 |
$this->leadin_render_disconnected_banner(); |
| 54 |
} elseif ( self::should_show_review_notice() ) { |
| 55 |
$review_banner = new ReviewBanner(); |
| 56 |
$review_banner->leadin_render_review_banner(); |
| 57 |
} |
| 58 |
} |
| 59 |
} |
| 60 |
|
| 61 |
/** |
| 62 |
* Find if disconnected notice should be shown |
| 63 |
*/ |
| 64 |
public function should_show_disconnected_notice() { |
| 65 |
$current_screen = get_current_screen(); |
| 66 |
return ! Connection::is_connected() && 'leadin' !== $current_screen->parent_base; |
| 67 |
} |
| 68 |
|
| 69 |
/** |
| 70 |
* Find if review notice should be shown |
| 71 |
*/ |
| 72 |
public function should_show_review_notice() { |
| 73 |
$current_screen = get_current_screen(); |
| 74 |
$is_dashboard = 'index' === $current_screen->parent_base; |
| 75 |
$is_not_skipped = empty( User_Metadata::get_skip_review() ); |
| 76 |
return $is_dashboard && Connection::is_connected() && $is_not_skipped; |
| 77 |
} |
| 78 |
|
| 79 |
} |
| 80 |
|