PluginProbe
Passster – Password Protect Pages and Content / 3.5.5.2
Passster – Password Protect Pages and Content v3.5.5.2
4.3.15 4.3.14 4.3.12 4.3.13 4.3.11 4.3.10 4.3.9 4.3.8 4.3.7 4.3.6 4.3.5 trunk 3.5.4 3.5.5.2 3.5.5.8 3.5.5.9 4.0 4.1.4 4.2.10 4.2.11 4.2.12 4.2.13 4.2.14 4.2.15 4.2.16 All 47 releases
content-protector / src / admin / class-ps-admin.php

class-ps-admin.php in Passster – Password Protect Pages and Content 3.5.5.2, at src/admin/class-ps-admin.php

358 lines 13.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace passster;
4
5 class PS_Admin
6 {
7 /**
8 * Contains instance or null
9 *
10 * @var object|null
11 */
12 private static $instance = null ;
13 /**
14 * Returns instance of PS_Admin.
15 *
16 * @return object
17 */
18 public static function get_instance()
19 {
20 if ( null === self::$instance ) {
21 self::$instance = new self();
22 }
23 return self::$instance;
24 }
25
26 /**
27 * Setup the passster admin area
28 *
29 * @return void
30 */
31 public function __construct()
32 {
33 // Check permissions before include settings.
34 if ( !current_user_can( 'manage_options' ) ) {
35 return;
36 }
37 add_action( 'admin_enqueue_scripts', array( $this, 'add_admin_scripts' ) );
38 add_action( 'init', array( $this, 'register_password_areas' ) );
39 add_filter( 'manage_protected_areas_posts_columns', array( $this, 'set_area_columns' ) );
40 add_action(
41 'manage_protected_areas_posts_custom_column',
42 array( $this, 'set_area_columns_content' ),
43 10,
44 2
45 );
46 $settings = new PS_Settings();
47 $settings->add_section( array(
48 'id' => 'passster_general_settings',
49 'title' => __( 'Options', 'content-protector' ),
50 ) );
51 $settings->add_field( 'passster_general_settings', array(
52 'id' => 'passster_advanced_cookie_title',
53 'type' => 'title',
54 'name' => '<h3>' . __( 'Cookie', 'content-protector' ) . '</h3>',
55 ) );
56 $settings->add_field( 'passster_general_settings', array(
57 'id' => 'toggle_cookie',
58 'type' => 'toggle',
59 'default' => 'on',
60 'name' => __( 'Use Cookie', 'content-protector' ),
61 ) );
62 $settings->add_field( 'passster_general_settings', array(
63 'id' => 'passster_cookie_duration',
64 'type' => 'number',
65 'name' => __( 'Cookie Duration', 'content-protector' ),
66 'desc' => __( 'Duration (in days) for your cookie. Once a cookie expires, the user will have to enter the password again.', 'content-protector' ),
67 'default' => '2',
68 'min' => 1,
69 ) );
70 $settings->add_field( 'passster_general_settings', array(
71 'id' => 'passster_advanced_compatibility_mode',
72 'type' => 'title',
73 'name' => '<h3>' . __( 'Compatibility Mode', 'content-protector' ) . '</h3>',
74 ) );
75 $settings->add_field( 'passster_general_settings', array(
76 'id' => 'toggle_ajax',
77 'type' => 'toggle',
78 'default' => 'off',
79 'name' => __( 'Reload after successful validation', 'content-protector' ),
80 ) );
81 $settings->add_field( 'passster_general_settings', array(
82 'id' => 'passster_advanced_amp_title',
83 'type' => 'title',
84 'name' => '<h3>' . __( 'AMP', 'content-protector' ) . '</h3>',
85 ) );
86 $settings->add_field( 'passster_general_settings', array(
87 'id' => 'toggle_amp',
88 'type' => 'toggle',
89 'default' => 'off',
90 'name' => __( 'Activate AMP Support', 'content-protector' ),
91 ) );
92 $settings->add_field( 'passster_general_settings', array(
93 'id' => 'passster_advanced_third_party_title',
94 'type' => 'title',
95 'name' => '<h3>' . __( 'Third-Party Support', 'content-protector' ) . '</h3>',
96 ) );
97 $settings->add_field( 'passster_general_settings', array(
98 'id' => 'third_party_shortcodes',
99 'type' => 'textarea',
100 'name' => __( 'Third-Party Shortcodes', 'content-protector' ),
101 'desc' => __( 'Add a comma separated list of shortcodes you want to use inside of Passster. <br>You can also use <b>{post-id}</b> to add the ID of the current page/post dynamically. ', 'content-protector' ),
102 ) );
103 $settings->add_field( 'passster_general_settings', array(
104 'id' => 'passster_advanced_delete_title',
105 'type' => 'title',
106 'name' => '<h3>' . __( 'Uninstall', 'content-protector' ) . '</h3>',
107 ) );
108 $settings->add_field( 'passster_general_settings', array(
109 'id' => 'passster_advanced_delete_options',
110 'type' => 'checkbox',
111 'name' => __( 'Delete Plugin Options On Uninstall', 'content-protector' ),
112 'desc' => __( 'If checked, all plugin options will be deleted if the plugin is unstalled.', 'content-protector' ),
113 ) );
114 $settings->add_section( array(
115 'id' => 'passster_advanced_settings',
116 'title' => __( 'External Services', 'content-protector' ),
117 ) );
118 $settings->add_field( 'passster_advanced_settings', array(
119 'id' => 'passster_recaptcha_title',
120 'type' => 'title',
121 'name' => '<h3>' . __( 'Google Recaptcha', 'content-protector' ) . '</h3>',
122 ) );
123 $settings->add_field( 'passster_advanced_settings', array(
124 'id' => 'passster_recaptcha_type',
125 'type' => 'select',
126 'name' => __( 'Recaptcha Version', 'content-protector' ),
127 'options' => array(
128 'v3' => 'V3 (invisible Captcha)',
129 'v2' => 'V2 (Checkbox)',
130 ),
131 ) );
132 $settings->add_field( 'passster_advanced_settings', array(
133 'id' => 'passster_recaptcha_site_key',
134 'type' => 'text',
135 'name' => __( 'Site Key', 'content-protector' ),
136 'desc' => __( 'Add your Google ReCaptcha Site Key', 'content-protector' ),
137 'premium' => 'premium',
138 ) );
139 $settings->add_field( 'passster_advanced_settings', array(
140 'id' => 'passster_recaptcha_secret',
141 'type' => 'text',
142 'name' => __( 'Secret', 'content-protector' ),
143 'desc' => __( 'Add your Google ReCaptcha Secret', 'content-protector' ),
144 'premium' => 'premium',
145 ) );
146 $settings->add_field( 'passster_advanced_settings', array(
147 'id' => 'passster_recaptcha_language',
148 'type' => 'text',
149 'name' => __( 'Language', 'content-protector' ),
150 'desc' => __( 'Add your language shortcode. For example "en" for english or "de" for german. ', 'content-protector' ),
151 'default' => 'en',
152 'premium' => 'premium',
153 ) );
154 $settings->add_field( 'passster_advanced_settings', array(
155 'id' => 'passster_bitly_title',
156 'type' => 'title',
157 'name' => '<h3>' . __( 'Bitly', 'content-protector' ) . '</h3>',
158 ) );
159 $settings->add_field( 'passster_advanced_settings', array(
160 'id' => 'passster_bitly_access_key',
161 'type' => 'text',
162 'name' => __( 'Bitly Access Token', 'content-protector' ),
163 'desc' => __( 'Add your bitly access token. You can get one here: <a target="_blank" href="https://bitly.com/">bitly.com</a>', 'content-protector' ),
164 'premium' => 'premium',
165 ) );
166 }
167
168 /**
169 * Add admin assets
170 *
171 * @return void
172 */
173 public function add_admin_scripts()
174 {
175 $suffix = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min' );
176 wp_enqueue_style(
177 'passster-admin-css',
178 PASSSTER_URL . '/assets/admin/passster-admin.css',
179 '1.0',
180 'all'
181 );
182 wp_enqueue_script(
183 'passster-admin-js',
184 PASSSTER_URL . '/assets/admin/passster-admin' . $suffix . '.js',
185 array( 'jquery' ),
186 '1.0',
187 false
188 );
189 wp_localize_script( 'passster-admin-js', 'ps_admin_ajax', array(
190 'ajax_url' => admin_url( 'admin-ajax.php' ),
191 'nonce' => wp_create_nonce( 'passster-admin-nonce' ),
192 'reset_message' => __( 'Usage data resetted.', 'content-protector' ),
193 ) );
194 }
195
196 /**
197 * Register post type "password lists"
198 *
199 * @return void
200 */
201 public function register_password_lists()
202 {
203 }
204
205 /**
206 * Register post type "protected areas"
207 *
208 * @return void
209 */
210 public function register_password_areas()
211 {
212 $labels = array(
213 'name' => _x( 'Protected Areas', 'post type general name', 'content-protector' ),
214 'singular_name' => _x( 'Protected Area', 'post type singular name', 'content-protector' ),
215 'menu_name' => _x( 'Protected Areas', 'admin menu', 'content-protector' ),
216 'name_admin_bar' => _x( 'Protected Area', 'add new on admin bar', 'content-protector' ),
217 'add_new' => _x( 'Add New', 'content-protector' ),
218 'add_new_item' => __( 'Add New Protected Area', 'content-protector' ),
219 'new_item' => __( 'New Protected Area', 'content-protector' ),
220 'edit_item' => __( 'Edit Protected Area', 'content-protector' ),
221 'view_item' => __( 'View Protected Area', 'content-protector' ),
222 'all_items' => __( 'Protected Areas', 'content-protector' ),
223 'search_items' => __( 'Search Protected Areas', 'content-protector' ),
224 'parent_item_colon' => __( 'Parent Protected Area', 'content-protector' ),
225 'not_found' => __( 'No Protected Areas found.', 'content-protector' ),
226 'not_found_in_trash' => __( 'No Protected Areas found in Trash.', 'content-protector' ),
227 );
228 $args = array(
229 'labels' => $labels,
230 'description' => __( 'Manageable protected areas', 'content-protector' ),
231 'public' => false,
232 'publicly_queryable' => false,
233 'show_ui' => true,
234 'show_in_menu' => 'passster',
235 'query_var' => true,
236 'rewrite' => false,
237 'capability_type' => 'post',
238 'has_archive' => false,
239 'hierarchical' => false,
240 'menu_position' => null,
241 'supports' => array( 'title', 'editor' ),
242 'show_in_rest' => true,
243 );
244
245 if ( current_user_can( 'administrator' ) ) {
246 $args['public'] = true;
247 $args['publicly_queryable'] = true;
248 }
249
250 register_post_type( 'protected_areas', $args );
251 }
252
253 /**
254 * Set column headers password lists post type
255 *
256 * @param array $columns array of columns.
257 * @return array
258 */
259 public function set_columns( $columns )
260 {
261 }
262
263 /**
264 * Add content to registered columns for password list post type.
265 *
266 * @param string $column name of the column.
267 * @param int $post_id current id.
268 * @return void
269 */
270 public function set_columns_content( $column, $post_id )
271 {
272 }
273
274 /**
275 * Set column headers password lists post type
276 *
277 * @param array $columns array of columns.
278 * @return array
279 */
280 public function set_area_columns( $columns )
281 {
282 $columns['shortcode'] = __( 'Shortcode', 'content-protector' );
283 unset( $columns['date'] );
284 return $columns;
285 }
286
287 /**
288 * Add content to registered columns for password list post type.
289 *
290 * @param string $column name of the column.
291 * @param int $post_id current id.
292 * @return void
293 */
294 public function set_area_columns_content( $column, $post_id )
295 {
296 switch ( $column ) {
297 case 'shortcode':
298 $shortcode = get_post_meta( $post_id, 'passster_area_shortcode', true );
299 echo esc_html( $shortcode ) ;
300 break;
301 }
302 }
303
304 /**
305 * Return default based on option name.
306 *
307 * @param string $option_name name of the option.
308 * @return array
309 */
310 public static function get_defaults( $option_name )
311 {
312 switch ( $option_name ) {
313 case 'passster_general_settings':
314 $settings = array(
315 'toggle_cookie' => 'on',
316 'toggle_ajax' => 'off',
317 'passster_cookie_duration' => 2,
318 'toggle_amp' => 'off',
319 'passster_advanced_delete_options' => 'off',
320 );
321 return $settings;
322 break;
323 case 'passster_advanced_settings':
324 $settings = array(
325 'passster_recaptcha_site_key' => '',
326 'passster_recaptcha_type' => 'v3',
327 'passster_recaptcha_secret' => '',
328 'passster_recaptcha_language' => '',
329 'passster_bitly_access_key' => '',
330 );
331 return $settings;
332 break;
333 }
334 }
335
336 /**
337 * Decrease remaining downloads in post meta.
338 */
339 public function reset_usage_data()
340 {
341 }
342
343 /**
344 * Add Gutenberg support for editing areas.
345 *
346 * @param bool $can_edit bool indicates if editable or not.
347 * @param string $post_type given post type.
348 * @return bool
349 */
350 public function activate_areas_block_editor( $can_edit, $post_type )
351 {
352 if ( 'protected_areas' == $post_type ) {
353 $can_edit = true;
354 }
355 return $can_edit;
356 }
357
358 }