Completed
Push — add/mailerlite-subscriber-shor... ( f04272...b85f15 )
by
unknown
09:15
created

mailerlite.php ➔ jetpack_mailerlite_subscriber_popup()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 9
rs 9.9666
c 0
b 0
f 0
1
<?php //phpcs:ignore WordPress.Files.FileName.InvalidClassFileName
2
3
use Automattic\Jetpack\Assets;
4
/**
5
 * Mailerlite Subscriber Popup Form shortcode
6
 *
7
 * Example:
8
 * [mailerlite_subscriber_popup account="234532432" uuid="rat43ttatrs"]
9
 */
10
11
/**
12
 * Register [mailerlite_subscriber_popup] shortcode.
13
 */
14
function jetpack_mailerlite_subscriber_popup() {
15
	add_shortcode(
16
		'mailerlite_subscriber_popup',
17
		array(
18
			'Mailerlite_Subscriber_Popup',
19
			'shortcode',
20
		)
21
	);
22
}
23
24
if ( defined( 'IS_WPCOM' ) && IS_WPCOM ) {
25
	add_action( 'init', 'jetpack_mailerlite_subscriber_popup' );
26
} else {
27
	jetpack_mailerlite_subscriber_popup();
28
}
29
30
/**
31
 * Class Mailerlite_Subscriber_Popup
32
 *
33
 * @since 4.5.0
34
 */
35
class Mailerlite_Subscriber_Popup {
36
	/**
37
	 * Parses the shortcode back out to embedded information.
38
	 *
39
	 * @param array $attrs shortcode attributes.
40
	 *
41
	 * @return string
42
	 */
43
	public static function shortcode( $attrs ) {
44
		if ( wp_script_is( 'mailerlite-subscriber-popup', 'enqueued' ) ) {
45
			return '';
46
		}
47
48
		$attrs = shortcode_atts(
49
			array(
50
				'account' => '',
51
				'uuid'    => '',
52
			),
53
			$attrs,
54
			'mailerlite_subscriber_popup'
55
		);
56
		wp_register_script( 'mailerlite-universal', 'https://static.mailerlite.com/js/universal.js', array(), '20200521', true );
57
		wp_enqueue_script(
58
			'mailerlite-subscriber-popup',
59
			Assets::get_file_url_for_environment( '_inc/build/shortcodes/js/mailerlite-subscriber-popup.min.js', 'modules/shortcodes/js/mailerlite-subscriber-popup.js' ),
60
			array( 'mailerlite-universal' ),
61
			'20200521',
62
			true
63
		);
64
		wp_localize_script( 'mailerlite-subscriber-popup', 'jetpackMailerliteSettings', $attrs );
65
		return '';
66
	}
67
}
68