| 1 |
<?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName |
| 2 |
|
| 3 |
use Automattic\Jetpack\Assets; |
| 4 |
use Automattic\Jetpack\Assets\Logo; |
| 5 |
|
| 6 |
/** |
| 7 |
* Jetpack connection dashboard widget. |
| 8 |
* |
| 9 |
* @package automattic/jetpack |
| 10 |
*/ |
| 11 |
class Jetpack_Connection_Widget { |
| 12 |
/** |
| 13 |
* Static instance |
| 14 |
* |
| 15 |
* @var Jetpack_Connection_Widget |
| 16 |
*/ |
| 17 |
private static $instance = null; |
| 18 |
|
| 19 |
/** |
| 20 |
* Intiialize the class by calling the setup static function. |
| 21 |
* |
| 22 |
* @return Jetpack_Connection_Widget |
| 23 |
*/ |
| 24 |
public static function init() { |
| 25 |
if ( self::$instance === null ) { |
| 26 |
self::$instance = new Jetpack_Connection_Widget(); |
| 27 |
} |
| 28 |
|
| 29 |
return self::$instance; |
| 30 |
} |
| 31 |
|
| 32 |
/** |
| 33 |
* Jetpack_Connection_Widget constructor. |
| 34 |
*/ |
| 35 |
public function __construct() { |
| 36 |
add_action( 'current_screen', array( $this, 'maybe_initialize_hooks' ) ); |
| 37 |
} |
| 38 |
|
| 39 |
/** |
| 40 |
* Will initialize hooks to display the new connection widget. |
| 41 |
*/ |
| 42 |
public function maybe_initialize_hooks() { |
| 43 |
add_action( 'admin_print_styles', array( $this, 'admin_banner_styles' ) ); |
| 44 |
add_action( 'wp_dashboard_setup', array( $this, 'wp_dashboard_setup' ) ); |
| 45 |
} |
| 46 |
|
| 47 |
/** |
| 48 |
* Sets up the Jetpack Connection Widget in the WordPress admin dashboard. |
| 49 |
*/ |
| 50 |
public function wp_dashboard_setup() { |
| 51 |
if ( Jetpack_Options::get_option( 'dismissed_connection_banner' ) && |
| 52 |
! Jetpack::is_connection_ready() ) { |
| 53 |
$widget_title = sprintf( |
| 54 |
__( 'Jetpack - Security, Backup, Speed & Growth', 'jetpack' ) |
| 55 |
); |
| 56 |
|
| 57 |
wp_add_dashboard_widget( |
| 58 |
'jetpack_connection_widget', |
| 59 |
$widget_title, |
| 60 |
array( __CLASS__, 'connection_widget' ) |
| 61 |
); |
| 62 |
} |
| 63 |
} |
| 64 |
|
| 65 |
/** |
| 66 |
* Included the needed styles |
| 67 |
*/ |
| 68 |
public function admin_banner_styles() { |
| 69 |
wp_enqueue_style( |
| 70 |
'jetpack-connection-widget', |
| 71 |
Assets::get_file_url_for_environment( |
| 72 |
'css/jetpack-connection-widget.min.css', |
| 73 |
'css/jetpack-connection-widget.css' |
| 74 |
), |
| 75 |
array(), |
| 76 |
JETPACK__VERSION |
| 77 |
); |
| 78 |
} |
| 79 |
|
| 80 |
/** |
| 81 |
* Builds the connection url for the widget. |
| 82 |
* |
| 83 |
* @return string |
| 84 |
*/ |
| 85 |
public static function build_connect_url() { |
| 86 |
$url = Jetpack::init()->build_connect_url( |
| 87 |
true, |
| 88 |
false, |
| 89 |
'unconnected-site-widget' |
| 90 |
); |
| 91 |
|
| 92 |
return add_query_arg( 'auth_approved', 'true', $url ); |
| 93 |
} |
| 94 |
|
| 95 |
/** |
| 96 |
* Load the widget |
| 97 |
*/ |
| 98 |
public static function connection_widget() { |
| 99 |
$connect_url = self::build_connect_url(); |
| 100 |
$jetpack_logo = new Logo(); |
| 101 |
?> |
| 102 |
<div class="jp-connection-widget"> |
| 103 |
<div class="jp-connection-widget__logo"> |
| 104 |
<?php echo $jetpack_logo->get_jp_emblem_larger(); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?> |
| 105 |
</div> |
| 106 |
<img |
| 107 |
class="jp-connection-widget__image" |
| 108 |
src="<?php echo esc_url( plugins_url( 'images/dashboard-connection-widget-hero.png', JETPACK__PLUGIN_FILE ) ); ?>" /> |
| 109 |
<p class="jp-connection-widget__heading"><?php esc_html_e( 'Finish setting up your site', 'jetpack' ); ?></p> |
| 110 |
<p class="jp-connection-widget__paragraph"> |
| 111 |
<?php esc_html_e( 'Complete your setup to take advantage of security and performance features already installed by Jetpack.', 'jetpack' ); ?> |
| 112 |
</p> |
| 113 |
<p class="jp-connection-widget__tos-blurb"> |
| 114 |
<?php jetpack_render_tos_blurb(); ?> |
| 115 |
</p> |
| 116 |
<p class="jp-connection_widget__button-container"> |
| 117 |
<a class="jp-connection-widget__button" href="<?php echo esc_url( $connect_url ); ?>"><?php esc_html_e( 'Set up Jetpack for free', 'jetpack' ); ?></a> |
| 118 |
</p> |
| 119 |
</div> |
| 120 |
<?php |
| 121 |
} |
| 122 |
} |
| 123 |
|