is_jetpack_lazy_images_active()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
nc 3
nop 0
dl 0
loc 7
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * Auto Load Next Post Settings - Events
4
 *
5
 * @since    1.5.0
6
 * @version  1.6.0
7
 * @author   Sébastien Dumont
8
 * @category Admin
9
 * @package  Auto Load Next Post/Admin/Settings
10
 * @license  GPL-2.0+
11
 */
12
13
// Exit if accessed directly.
14
if ( ! defined( 'ABSPATH' ) ) {
15
	exit;
16
}
17
18
if ( ! class_exists( 'ALNP_Settings_Events' ) ) {
19
20
	class ALNP_Settings_Events extends ALNP_Settings_Page {
21
22
		/**
23
		 * Constructor.
24
		 *
25
		 * @access public
26
		 */
27
		public function __construct() {
28
			$this->id    = 'events';
29
			$this->label = esc_html__( 'Events', 'auto-load-next-post' );
30
31
			parent::__construct();
32
33
			add_action( 'auto_load_next_post_settings_events', array( __CLASS__, 'is_jetpack_lazy_images_active' ), 0 );
34
		} // END __construct()
35
36
		/**
37
		 * Displays a notification if JetPack is active and
38
		 * JetPack's Lazy Images module is enabled.
39
		 *
40
		 * @access public
41
		 * @static
42
		 */
43
		public static function is_jetpack_lazy_images_active() {
44
			if ( alnp_check_jetpack() == 'yes' ) {
45
				if ( Jetpack::is_module_active( 'lazy-images' ) ) {
46
					include( dirname( AUTO_LOAD_NEXT_POST_FILE ) . '/includes/admin/views/html-notice-jetpack-lazy-images-module.php' );
47
				}
48
			}
49
		} // END is_jetpack_lazy_images_active()
50
51
		/**
52
		 * Get settings array.
53
		 *
54
		 * @access public
55
		 * @return array
56
		 */
57
		public function get_settings() {
58
			return apply_filters(
59
				'alnp_event_settings', array(
60
61
					array(
62
						'title' => $this->label,
63
						'type'  => 'title',
64
						'desc'  => sprintf( __( 'Below you can enter external JavaScript events to be triggered alongside %1$s native events. Separate each event like so: %2$s', 'auto-load-next-post' ), esc_html__( 'Auto Load Next Post', 'auto-load-next-post' ), '<code>event1, event2,</code>' ),
65
						'id'    => 'events_options'
66
					),
67
68
					array(
69
						'title'    => esc_html__( 'Post loaded', 'auto-load-next-post' ),
70
						'desc'     => esc_html__( 'Events listed here will be triggered after a new post has loaded.', 'auto-load-next-post' ),
71
						'id'       => 'auto_load_next_post_on_load_event',
72
						'default'  => '',
73
						'type'     => 'textarea',
74
						'css'      => 'min-width: 50%; height: 75px;',
75
						'autoload' => false
76
					),
77
78
					array(
79
						'title'    => esc_html__( 'Entering a Post', 'auto-load-next-post' ),
80
						'desc'     => esc_html__( 'Events listed here will be triggered when entering a post.', 'auto-load-next-post' ),
81
						'id'       => 'auto_load_next_post_on_entering_event',
82
						'default'  => '',
83
						'type'     => 'textarea',
84
						'css'      => 'min-width: 50%; height: 75px;',
85
						'autoload' => false
86
					),
87
88
					array(
89
						'type' => 'sectionend',
90
						'id'   => 'events_options'
91
					),
92
			) ); // End event settings
93
		} // END get_settings()
94
95
		/**
96
		 * Output the settings.
97
		 *
98
		 * @access public
99
		 */
100
		public function output() {
101
			$settings = $this->get_settings();
102
103
			ALNP_Admin_Settings::output_fields( $settings );
104
		} // END output()
105
106
		/**
107
		 * Save settings.
108
		 *
109
		 * @access public
110
		 */
111
		public function save() {
112
			$settings = $this->get_settings();
113
114
			ALNP_Admin_Settings::save_fields( $settings );
115
		} // END save()
116
117
	} // END class
118
119
} // END if class exists
120
121
return new ALNP_Settings_Events();
122