Completed
Push — add/implement_wizard_banner ( e29254 )
by
unknown
06:33
created

Jetpack_Wizard_Banner::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * Displays the first page of the Wizard in a banner form
4
 *
5
 * @package none
6
 */
7
8
use Automattic\Jetpack\Assets;
9
use Automattic\Jetpack\Assets\Logo as Jetpack_Logo;
10
11
/**
12
 * Jetpack_Wizard_Banner
13
 **/
14
class Jetpack_Wizard_Banner {
15
	/**
16
	 * Jetpack_Wizard_Banner
17
	 *
18
	 * @var Jetpack_Wizard_Banner
19
	 **/
20
	private static $instance = null;
21
22
	/**
23
	 * Factory method
24
	 */
25
	public static function init() {
26
		if ( is_null( self::$instance ) ) {
27
			self::$instance = new Jetpack_Wizard_Banner();
28
		}
29
30
		return self::$instance;
31
	}
32
33
	/**
34
	 * Jetpack_Wizard_Banner constructor.
35
	 */
36
	private function __construct() {
37
		add_action( 'current_screen', array( $this, 'maybe_initialize_hooks' ) );
38
	}
39
40
	/**
41
	 * Initialize hooks to display the banner
42
	 */
43
	public function maybe_initialize_hooks() {
44
		// Kill if banner has been dismissed.
45
		if ( Jetpack_Options::get_option( 'dismissed_wizard_banner' ) ) {
46
			return;
47
		}
48
49
		add_action( 'admin_print_styles', array( $this, 'admin_banner_styles' ) );
50
		add_action( 'admin_notices', array( $this, 'render_banner' ) );
51
		add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_banner_scripts' ) );
52
	}
53
54
	/**
55
	 * Enqueue JavaScript files.
56
	 */
57 View Code Duplication
	public static function enqueue_banner_scripts() {
58
		wp_enqueue_script(
59
			'jetpack-wizard-banner-js',
60
			Assets::get_file_url_for_environment(
61
				'_inc/build/jetpack-wizard-banner.min.js',
62
				'_inc/jetpack-wizard-banner.js'
63
			),
64
			array( 'jquery' ),
65
			JETPACK__VERSION,
66
			true
67
		);
68
69
		wp_localize_script(
70
			'jetpack-wizard-banner-js',
71
			'jp_banner',
72
			array(
73
				'ajax_url'          => admin_url( 'admin-ajax.php' ),
74
				'wizardBannerNonce' => wp_create_nonce( 'jp-wizard-banner-nonce' ),
75
			)
76
		);
77
	}
78
79
	/**
80
	 * Include the needed styles
81
	 */
82
	public function admin_banner_styles() {
83
		$min = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '' : '.min';
84
85
		wp_enqueue_style(
86
			'jetpack',
87
			plugins_url( "css/jetpack-wizard-banner{$min}.css", JETPACK__PLUGIN_FILE ),
88
			array(),
89
			JETPACK__VERSION
90
		);
91
	}
92
93
	/**
94
	 * AJAX callback
95
	 */
96 View Code Duplication
	public static function ajax_callback() {
97
		check_ajax_referer( 'jp-wizard-banner-nonce', 'nonce' );
98
99
		if ( isset( $_REQUEST['dismissBanner'] ) ) {
100
			Jetpack_Options::update_option( 'dismissed_wizard_banner', 1 );
101
			wp_send_json_success();
102
		}
103
104
		wp_die();
105
	}
106
107
	/**
108
	 * Renders the Wizard Banner
109
	 */
110
	public function render_banner() {
111
		$jetpack_logo = new Jetpack_Logo();
112
		?>
113
114
		<div id="jp-wizard-banner" class="">
115
			<div class="jp-setup-wizard-intro">
116
				<span
117
					class="notice-dismiss wizard-banner-dismiss"
118
					title="<?php esc_attr_e( 'Dismiss this notice', 'jetpack' ); ?>">
119
				</span>
120
				<div class="jp-emblem">
121
				<?php
122
					echo $jetpack_logo->get_jp_emblem_larger(); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
123
				?>
124
				</div>
125
				<img
126
					width="200px"
127
					height="200px"
128
					src="
129
					<?php
130
					esc_attr_e( plugins_url( 'images/jetpack-powering-up.svg', JETPACK__PLUGIN_FILE ), 'jetpack' ); // phpcs:ignore WordPress.WP.I18n.NonSingularStringLiteralText
131
					?>
132
					"
133
					alt="<?php esc_attr_e( 'A jetpack site powering up', 'jetpack' ); ?>"
134
				/>
135
				<h1 class="jp-setup-wizard-header">
136
					<?php esc_html_e( 'Set up Jetpack for better site security, performance, and more', 'jetpack' ); ?>
137
				</h1>
138
				<p class="jp-setup-wizard-paragraph">
139
					<?php esc_html_e( 'Jetpack is a cloud-powered tool built by Automattic.', 'jetpack' ); ?>
140
				</p>
141
				<p class="jp-setup-wizard-paragraph">
142
					<?php esc_html_e( 'Answer a few questions and we’ll help you secure, speed up, customize, and grow your WordPress website.', 'jetpack' ); ?>
143
				</p>
144
				<div class="jp-setup-wizard-intro-question">
145
					<h2>
146
						<?php
147
						/* translators: %s is the site name */
148
						esc_html_e( sprintf( 'What will %s be used for?', get_bloginfo( 'name' ) ), 'jetpack' ); // phpcs:ignore WordPress.WP.I18n.NonSingularStringLiteralText
149
						?>
150
					</h2>
151
					<div class="jp-setup-wizard-answer-buttons">
152
						<a class="button button-primary jp-setup-wizard-button" href="setup/income?use=personal">
153
						<?php esc_html_e( 'Personal Use', 'jetpack' ); ?>
154
						</a>
155
						<a class="button button-primary jp-setup-wizard-button" href="setup/income?use=business">
156
							<?php esc_html_e( 'Business Use', 'jetpack' ); ?>
157
						</a>
158
					</div>
159
					<a class="jp-setup-wizard-skip-link" href="setup/features">
160
						<?php esc_html_e( 'Skip to recommended features', 'jetpack' ); ?>
161
					</a>
162
				</div>
163
			</div>
164
		</div>
165
		<?php
166
	}
167
}
168