PluginProbe
Passster – Password Protect Pages and Content / 3.5.4
Passster – Password Protect Pages and Content v3.5.4
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.4, at src/admin/class-ps-admin.php

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