-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathclass.php
198 lines (150 loc) · 5.96 KB
/
class.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
<?php
/**
* Registers zeen101's Leaky Paywall class
*
* @package zeen101's Leaky Paywall - Article Countdown Nag
* @since 1.0.0
*/
/**
* This class registers the main issuem functionality
*
* @since 1.0.0
*/
class Leaky_Paywall_Article_Countdown_Nag {
/**
* Class constructor, puts things in motion
*
* @since 1.0.0
*/
public function __construct() {
add_action( 'wp_enqueue_scripts', array( $this, 'frontend_scripts' ) );
add_filter( 'leaky_paywall_settings_tab_sections', array( $this, 'add_setting_section' ) );
add_action( 'leaky_paywall_output_settings_fields', array( $this, 'display_settings_fields' ), 10, 2 );
add_action( 'leaky_paywall_update_settings', array( $this, 'save_settings_fields' ), 20, 3 );
}
public function frontend_scripts() {
if ( is_home() || is_front_page() || is_archive() ) {
return;
}
$settings = $this->get_settings();
wp_enqueue_script( 'leaky-paywall-article-countdown-nag', LP_ACN_URL . 'js/article-countdown-nag.js', array( 'jquery' ), LP_ACN_VERSION );
$protocol = isset( $_SERVER['HTTPS'] ) ? 'https://' : 'http://';
$params = array(
'ajaxurl' => admin_url( 'admin-ajax.php', $protocol )
);
wp_localize_script( 'leaky-paywall-article-countdown-nag', 'lp_acn', $params );
if ( $settings['nag_theme'] == 'slim' ) {
wp_enqueue_style( 'leaky-paywall-article-countdown-nag', LP_ACN_URL . 'css/article-countdown-nag-slim.css', '', LP_ACN_VERSION );
} else {
wp_enqueue_style( 'leaky-paywall-article-countdown-nag', LP_ACN_URL . 'css/article-countdown-nag.css', '', LP_ACN_VERSION );
}
}
/**
* Get zeen101's Leaky Paywall - Article Countdown Nag options
*
* @since 1.0.0
*/
public function get_settings() {
$defaults = array(
'nag_after_countdown' => '0',
'nag_theme' => 'default',
'zero_remaining_popup' => 'yes'
);
$defaults = apply_filters( 'leaky_paywall_article_countdown_nag_default_settings', $defaults );
$settings = get_option( 'issuem-leaky-paywall-article-countdown-nag' );
return wp_parse_args( $settings, $defaults );
}
/**
* Add Leaky Paywall - Article Countdown Nag section to general settings
*
* @since 1.0.0
*/
public function add_setting_section( $sections )
{
$sections['general'][] = 'article_countdown_nag';
return $sections;
}
/**
* Display Leaky Paywall - Registration Redirect options
*
* @since 1.0.0
*/
public function display_settings_fields( $current_tab, $current_section )
{
if ( $current_tab != 'general' ) {
return;
}
if ( $current_section != 'article_countdown_nag' ) {
return;
}
$settings = $this->get_settings();
?>
<h3><span><?php _e( 'Article Countdown Nag', 'lp-acn' ); ?></span></h3>
<table id="leaky_paywall_article_countdown_nag" class="form-table">
<tr>
<th><?php _e( 'Show Nag After Reading', 'lp-acn' ); ?></th>
<td>
<input class="small-text" type="number" value="<?php echo $settings['nag_after_countdown']; ?>" name="nag_after_countdown" /> <?php _e( 'restricted content items', 'lp-acn' ); ?>
<p class="description"><?php _e( 'Display the article countdown nag popup after the user has read the given number of restricted content items. <br>Set to 0 to show the nag the first time restricted content is viewed.' ); ?></p>
</td>
</tr>
<tr>
<th><?php _e( 'Nag Theme', 'lp-acn' ); ?></th>
<td>
<select id="nag_theme" name="nag_theme">
<option value="default" <?php selected( 'default' === $settings['nag_theme'] ); ?>><?php _e( 'Default', 'lp-acn' ); ?></option>
<option value="slim" <?php selected( 'slim' === $settings['nag_theme'] ); ?>><?php _e( 'Slim', 'lp-acn' ); ?></option>
</select>
<p class="description"><?php _e( 'Choose theme for article countdown nag popup.', 'lp-acn' ); ?></p>
</td>
</tr>
<tr>
<th><?php _e( 'Zero Remaining Popup', 'lp-acn' ); ?></th>
<td>
<select id="zero_remaining_popup" name="zero_remaining_popup">
<option value="yes" <?php selected( 'yes' === $settings['zero_remaining_popup'] ); ?>><?php _e( 'Yes', 'lp-acn' ); ?></option>
<option value="no" <?php selected( 'no' === $settings['zero_remaining_popup'] ); ?>><?php _e( 'No', 'lp-acn' ); ?></option>
</select>
<p class="description"><?php _e( 'Display the zero remaining popup over the top of the page when the content limit is reached. If set to "No", the user will instead see the default Leaky Paywall subscribe nag in the content.', 'lp-acn' ); ?></p>
</td>
</tr>
</table>
<?php
}
/**
* Save Leaky Paywall - Article Countdown Nag options
*
* @since 1.0.0
*/
public function save_settings_fields( $settings, $current_tab, $current_section )
{
if ( $current_tab != 'general' ) {
return;
}
if ( $current_section != 'article_countdown_nag' ) {
return;
}
// Get the user options
$settings = $this->get_settings();
if ( !empty( $_POST['nag_after_countdown'] ) ) {
$settings['nag_after_countdown'] = absint( trim( $_POST['nag_after_countdown'] ) );
} else {
$settings['nag_after_countdown'] = '0';
}
if ( isset( $_POST['nag_theme'] ) ) {
$settings['nag_theme'] = sanitize_text_field( $_POST['nag_theme'] );
}
if ( isset( $_POST['zero_remaining_popup'] ) ) {
$settings['zero_remaining_popup'] = sanitize_text_field( $_POST['zero_remaining_popup'] );
}
$this->update_settings( $settings );
}
/**
* Update Leaky Paywall - Article Countdown Nag options
*
* @since 1.0.0
*/
public function update_settings( $settings ) {
update_option( 'issuem-leaky-paywall-article-countdown-nag', $settings );
}
}