PluginProbe
User Profile Builder – Beautiful User Registration Forms, User Profiles & User Role Editor / 3.15.9
User Profile Builder – Beautiful User Registration Forms, User Profiles & User Role Editor v3.15.9
4.0.3 4.0.2 4.0.1 4.0.0 3.16.6 3.16.5 3.16.4 3.16.3 3.16.2 3.16.1 3.16.0 3.15.9 3.9.9 3.9.5 3.9.6 3.9.7 3.9.8 1.1.7 1.1.8 1.1.9 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 All 341 releases
profile-builder / features / content-restriction / content-restriction-meta-box.php

content-restriction-meta-box.php in User Profile Builder – Beautiful User Registration Forms, User Profiles & User Role Editor 3.15.9, at features/content-restriction/content-restriction-meta-box.php

549 lines 34.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
3
4 function wppb_content_restriction_initialize_meta_box() {
5
6 add_action( 'add_meta_boxes', 'wppb_content_restriction_add_meta_box' );
7
8 }
9 add_action( 'init', 'wppb_content_restriction_initialize_meta_box', 999 );
10
11 function wppb_content_restriction_add_meta_box() {
12
13 $post_types = get_post_types( array( 'public' => true ) );
14
15 if( ! empty( $post_types ) ) {
16 foreach( $post_types as $post_type ) {
17
18 if( apply_filters( 'wppb_content_restriction_enabled_for_post_type', true, $post_type ) ){
19 add_meta_box(
20 'wppb_post_content_restriction',
21 __( 'Profile Builder Content Restriction', 'profile-builder' ),
22 'wppb_content_restriction_meta_box_output',
23 $post_type,
24 'normal'
25 );
26 }
27
28 }
29 }
30
31 }
32
33 function wppb_content_restriction_get_supported_taxonomies() {
34
35 $taxonomies = get_taxonomies( array( 'public' => true ), 'objects' );
36
37 if ( empty( $taxonomies ) ) {
38 return array();
39 }
40
41 $disabled_taxonomies = array(
42 'nav_menu',
43 'link_category',
44 'post_format',
45 'product_visibility',
46 'product_shipping_class',
47 'action-group',
48 'product_type',
49 'wp_theme',
50 'wp_template_part_area',
51 );
52
53 foreach ( $taxonomies as $taxonomy => $taxonomy_object ) {
54 if ( in_array( $taxonomy, $disabled_taxonomies, true ) ) {
55 unset( $taxonomies[ $taxonomy ] );
56 continue;
57 }
58
59 if ( ! apply_filters( 'wppb_content_restriction_enabled_for_taxonomy', true, $taxonomy, $taxonomy_object ) ) {
60 unset( $taxonomies[ $taxonomy ] );
61 }
62 }
63
64 return $taxonomies;
65 }
66
67 function wppb_content_restriction_initialize_taxonomy_fields() {
68
69 $taxonomies = wppb_content_restriction_get_supported_taxonomies();
70
71 foreach ( $taxonomies as $taxonomy => $taxonomy_object ) {
72 add_action( $taxonomy . '_add_form_fields', 'wppb_content_restriction_taxonomy_add_form_fields' );
73 add_action( $taxonomy . '_edit_form_fields', 'wppb_content_restriction_taxonomy_edit_form_fields', 10, 2 );
74 }
75
76 add_action( 'create_term', 'wppb_content_restriction_save_term_data', 10, 3 );
77 add_action( 'edit_term', 'wppb_content_restriction_save_term_data', 10, 3 );
78 }
79 add_action( 'init', 'wppb_content_restriction_initialize_taxonomy_fields', 1000 );
80
81 function wppb_content_restriction_taxonomy_add_form_fields( $taxonomy ) {
82 wppb_content_restriction_taxonomy_fields_output( null, $taxonomy );
83 }
84
85 function wppb_content_restriction_taxonomy_edit_form_fields( $term, $taxonomy ) {
86 wppb_content_restriction_taxonomy_fields_output( $term, $taxonomy );
87 }
88
89 function wppb_content_restriction_taxonomy_fields_output( $term = null, $taxonomy = '' ) {
90
91 $term_id = ! empty( $term->term_id ) ? (int) $term->term_id : 0;
92 $wppb_content_restrict_types = apply_filters( 'wppb_single_post_content_restrict_types', array( 'message' => __( 'Message', 'profile-builder' ), 'redirect' => __( 'Redirect', 'profile-builder' ) ) );
93 $wppb_content_restrict_type = $term_id ? get_term_meta( $term_id, 'wppb-content-restrict-type', true ) : '';
94 $wppb_user_status = $term_id ? get_term_meta( $term_id, 'wppb-content-restrict-user-status', true ) : '';
95 $wppb_selected_roles = $term_id ? get_term_meta( $term_id, 'wppb-content-restrict-user-role' ) : array();
96 $wppb_custom_redirect_url_enabled = $term_id ? get_term_meta( $term_id, 'wppb-content-restrict-custom-redirect-url-enabled', true ) : '';
97 $wppb_custom_redirect_url = $term_id ? get_term_meta( $term_id, 'wppb-content-restrict-custom-redirect-url', true ) : '';
98 $wppb_custom_messages_enabled = $term_id ? get_term_meta( $term_id, 'wppb-content-restrict-messages-enabled', true ) : '';
99 $wppb_roles = get_editable_roles();
100 $object = get_taxonomy( $taxonomy );
101 $description_label = ! empty( $object->labels->singular_name ) ? $object->labels->singular_name : __( 'term', 'profile-builder' );
102
103 if ( empty( $wppb_selected_roles ) || ! is_array( $wppb_selected_roles ) ) {
104 $wppb_selected_roles = array();
105 }
106
107 ob_start();
108 ?>
109 <div class="wppb-meta-box-fields-wrapper wppb-taxonomy-content-restriction cozmoslabs-form-subsection-wrapper">
110 <h4 class="cozmoslabs-subsection-title"><?php esc_html_e( 'Profile Builder Content Restriction', 'profile-builder' ); ?></h4>
111
112 <div class="wppb-meta-box-field-wrapper cozmoslabs-form-field-wrapper">
113 <label class="wppb-meta-box-field-label cozmoslabs-form-field-label"><?php esc_html_e( 'Type of Restriction', 'profile-builder' ); ?></label>
114
115 <div class="cozmoslabs-radio-inputs-row">
116 <label class="wppb-meta-box-checkbox-label" for="wppb-content-restrict-type-default">
117 <input type="radio" id="wppb-content-restrict-type-default" value="default" <?php checked( empty( $wppb_content_restrict_type ) || $wppb_content_restrict_type === 'default' ); ?> name="wppb-content-restrict-type">
118 <?php esc_html_e( 'Settings Default', 'profile-builder' ); ?>
119 </label>
120
121 <?php foreach ( $wppb_content_restrict_types as $type_slug => $type_label ) : ?>
122 <label class="wppb-meta-box-checkbox-label" for="wppb-content-restrict-type-<?php echo esc_attr( $type_slug ); ?>">
123 <input type="radio" id="wppb-content-restrict-type-<?php echo esc_attr( $type_slug ); ?>" value="<?php echo esc_attr( $type_slug ); ?>" <?php checked( $wppb_content_restrict_type, $type_slug ); ?> name="wppb-content-restrict-type">
124 <?php echo esc_html( $type_label ); ?>
125 </label>
126 <?php endforeach; ?>
127 </div>
128 </div>
129
130 <div class="wppb-meta-box-field-wrapper cozmoslabs-form-field-wrapper cozmoslabs-checkbox-list-wrapper">
131 <label class="wppb-meta-box-field-label cozmoslabs-form-field-label"><?php esc_html_e( 'Display For', 'profile-builder' ); ?></label>
132
133 <div class="cozmoslabs-checkbox-list cozmoslabs-checkbox-multi-col-list">
134 <div class="cozmoslabs-chckbox-container">
135 <input type="checkbox" value="loggedin" <?php checked( $wppb_user_status, 'loggedin' ); ?> name="wppb-content-restrict-user-status" id="wppb-content-restrict-user-status">
136 <label class="wppb-meta-box-checkbox-label" for="wppb-content-restrict-user-status">
137 <?php esc_html_e( 'Logged In Users', 'profile-builder' ); ?>
138 </label>
139 </div>
140
141 <?php foreach ( $wppb_roles as $wppb_role => $wppb_role_details ) : ?>
142 <div class="cozmoslabs-chckbox-container">
143 <input type="checkbox" value="<?php echo esc_attr( $wppb_role ); ?>" <?php checked( in_array( $wppb_role, $wppb_selected_roles, true ) ); ?> name="wppb-content-restrict-user-role[]" id="wppb-content-restrict-user-role-<?php echo esc_attr( $wppb_role ); ?>">
144 <label class="wppb-meta-box-checkbox-label" for="wppb-content-restrict-user-role-<?php echo esc_attr( $wppb_role ); ?>">
145 <?php echo ! empty( $wppb_role_details['name'] ) ? esc_html( $wppb_role_details['name'] ) : esc_html( $wppb_role ); ?>
146 </label>
147 </div>
148 <?php endforeach; ?>
149
150 <p class="cozmoslabs-description">
151 <?php echo esc_html( sprintf( __( 'Checking only "Logged In Users" will show this %s to all logged in users, regardless of user role.', 'profile-builder' ), $description_label ) ); ?>
152 </p>
153
154 <p class="cozmoslabs-description">
155 <?php echo esc_html( sprintf( __( 'Checking any user role will show this %s only to users that have one of those user roles assigned.', 'profile-builder' ), $description_label ) ); ?>
156 </p>
157 </div>
158 </div>
159 </div>
160
161 <div id="wppb-meta-box-fields-wrapper-restriction-redirect-url" class="wppb-meta-box-fields-wrapper wppb-taxonomy-content-restriction cozmoslabs-form-subsection-wrapper <?php echo ( $wppb_content_restrict_type === 'redirect' ? 'wppb-content-restriction-enabled' : '' ); ?>">
162 <h4 class="cozmoslabs-subsection-title"><?php esc_html_e( 'Restriction Redirect URL', 'profile-builder' ); ?></h4>
163
164 <div class="wppb-meta-box-field-wrapper cozmoslabs-form-field-wrapper cozmoslabs-toggle-switch">
165 <label class="wppb-meta-box-field-label cozmoslabs-form-field-label" for="wppb-content-restrict-custom-redirect-url-enabled"><?php esc_html_e( 'Enable Custom Redirect URL', 'profile-builder' ); ?></label>
166
167 <div class="cozmoslabs-toggle-container">
168 <input type="checkbox" value="yes" <?php checked( ! empty( $wppb_custom_redirect_url_enabled ) ); ?> name="wppb-content-restrict-custom-redirect-url-enabled" id="wppb-content-restrict-custom-redirect-url-enabled">
169 <label class="cozmoslabs-toggle-track" for="wppb-content-restrict-custom-redirect-url-enabled"></label>
170 </div>
171 <div class="cozmoslabs-toggle-description">
172 <label for="wppb-content-restrict-custom-redirect-url-enabled" class="cozmoslabs-description"><?php echo esc_html( sprintf( __( 'Enable if you wish to add a custom redirect URL for this %s.', 'profile-builder' ), $description_label ) ); ?></label>
173 </div>
174 </div>
175
176 <div class="wppb-meta-box-field-wrapper cozmoslabs-form-field-wrapper wppb-meta-box-field-wrapper-custom-redirect-url <?php echo ( ! empty( $wppb_custom_redirect_url_enabled ) ? 'wppb-content-restriction-enabled' : '' ); ?>">
177 <label class="wppb-meta-box-field-label cozmoslabs-form-field-label" for="wppb-content-restrict-custom-redirect-url"><?php esc_html_e( 'Custom Redirect URL', 'profile-builder' ); ?></label>
178 <input type="text" value="<?php echo esc_attr( $wppb_custom_redirect_url ); ?>" name="wppb-content-restrict-custom-redirect-url" id="wppb-content-restrict-custom-redirect-url" class="widefat">
179 <p class="cozmoslabs-description cozmoslabs-description-space-left"><?php echo esc_html( sprintf( __( 'Add a URL where you wish to redirect users that do not have access to this %s and try to access it directly.', 'profile-builder' ), $description_label ) ); ?></p>
180 </div>
181 </div>
182
183 <div id="wppb-meta-box-fields-wrapper-restriction-custom-messages" class="wppb-meta-box-fields-wrapper wppb-taxonomy-content-restriction cozmoslabs-form-subsection-wrapper">
184 <h4 class="cozmoslabs-subsection-title"><?php esc_html_e( 'Restriction Messages', 'profile-builder' ); ?></h4>
185
186 <div class="wppb-meta-box-field-wrapper cozmoslabs-form-field-wrapper cozmoslabs-toggle-switch">
187 <label class="wppb-meta-box-field-label cozmoslabs-form-field-label" for="wppb-content-restrict-messages-enabled"><?php esc_html_e( 'Enable Custom Messages', 'profile-builder' ); ?></label>
188
189 <div class="cozmoslabs-toggle-container">
190 <input type="checkbox" value="yes" <?php checked( ! empty( $wppb_custom_messages_enabled ) ); ?> name="wppb-content-restrict-messages-enabled" id="wppb-content-restrict-messages-enabled">
191 <label class="cozmoslabs-toggle-track" for="wppb-content-restrict-messages-enabled"></label>
192 </div>
193 <div class="cozmoslabs-toggle-description">
194 <label for="wppb-content-restrict-messages-enabled" class="cozmoslabs-description"><?php echo esc_html( sprintf( __( 'Enable if you wish to add custom messages for this %s.', 'profile-builder' ), $description_label ) ); ?></label>
195 </div>
196 </div>
197
198 <div class="wppb-meta-box-field-wrapper-custom-messages <?php echo ( ! empty( $wppb_custom_messages_enabled ) ? 'wppb-content-restriction-enabled' : '' ); ?>">
199 <div class="cozmoslabs-form-field-wrapper cozmoslabs-wysiwyg-wrapper cozmoslabs-wysiwyg-indented">
200 <label class="cozmoslabs-form-field-label"><?php esc_html_e( 'Messages for logged-out users', 'profile-builder' ); ?></label>
201 <?php wp_editor( get_term_meta( $term_id, 'wppb-content-restrict-message-logged_out', true ), 'wppb-content-restrict-message-logged_out', array( 'textarea_name' => 'wppb-content-restrict-message-logged_out', 'editor_height' => 180 ) ); ?>
202 </div>
203
204 <div class="cozmoslabs-form-field-wrapper cozmoslabs-wysiwyg-wrapper cozmoslabs-wysiwyg-indented">
205 <label class="cozmoslabs-form-field-label"><?php esc_html_e( 'Messages for logged-in users', 'profile-builder' ); ?></label>
206 <?php wp_editor( get_term_meta( $term_id, 'wppb-content-restrict-message-logged_in', true ), 'wppb-content-restrict-message-logged_in', array( 'textarea_name' => 'wppb-content-restrict-message-logged_in', 'editor_height' => 180 ) ); ?>
207 </div>
208 </div>
209 </div>
210
211 <?php wp_nonce_field( 'wppb_meta_box_single_content_restriction_nonce', 'wppb_content_restriction_token', false ); ?>
212 <?php
213
214 $content = ob_get_clean();
215
216 if ( empty( $term_id ) ) {
217 echo $content; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
218 return;
219 }
220 ?>
221 <tr class="form-field wppb-taxonomy-content-restriction-row">
222 <th scope="row"><?php esc_html_e( 'Content Restriction', 'profile-builder' ); ?></th>
223 <td class="wppb-taxonomy-content-restriction-cell"><?php echo $content; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?></td>
224 </tr>
225 <?php
226 }
227
228 function wppb_content_restriction_meta_box_output( $post ) {
229
230 ?>
231 <div class="wppb-meta-box-fields-wrapper cozmoslabs-form-subsection-wrapper">
232 <h4 class="cozmoslabs-subsection-title"><?php echo esc_html__( 'Display Options', 'profile-builder' ); ?></h4>
233
234 <div class="wppb-meta-box-field-wrapper cozmoslabs-form-field-wrapper">
235 <?php
236 $wppb_content_restrict_types = apply_filters( 'wppb_single_post_content_restrict_types', array( 'message' => __( 'Message', 'profile-builder' ), 'redirect' => __( 'Redirect', 'profile-builder' ) ) );
237
238 $wppb_content_restrict_type = get_post_meta( $post->ID, 'wppb-content-restrict-type', true );
239 ?>
240
241 <label class="wppb-meta-box-field-label cozmoslabs-form-field-label"><?php esc_html_e( 'Type of Restriction', 'profile-builder' ); ?></label>
242
243 <div class="cozmoslabs-radio-inputs-row">
244 <label class="wppb-meta-box-checkbox-label" for="wppb-content-restrict-type-default">
245 <input type="radio" id="wppb-content-restrict-type-default" value="default" <?php if( empty( $wppb_content_restrict_type ) || $wppb_content_restrict_type == 'default' ) echo 'checked="checked"'; ?> name="wppb-content-restrict-type">
246 <?php echo esc_html__( 'Settings Default', 'profile-builder' ); ?>
247 </label>
248
249 <?php foreach( $wppb_content_restrict_types as $type_slug => $type_label ) { ?>
250 <label class="wppb-meta-box-checkbox-label" for="wppb-content-restrict-type-<?php echo esc_attr( $type_slug ); ?>">
251 <input type="radio" id="wppb-content-restrict-type-<?php echo esc_attr( $type_slug ); ?>" value="<?php echo esc_attr( $type_slug ); ?>" <?php if( $wppb_content_restrict_type == $type_slug ) echo 'checked="checked"'; ?> name="wppb-content-restrict-type">
252 <?php echo esc_html( $type_label ); ?>
253 </label>
254 <?php } ?>
255 </div>
256
257 </div>
258
259 <div class="wppb-meta-box-field-wrapper cozmoslabs-form-field-wrapper cozmoslabs-checkbox-list-wrapper">
260 <label class="wppb-meta-box-field-label cozmoslabs-form-field-label"><?php esc_html_e( 'Display For', 'profile-builder' ); ?></label>
261
262 <?php
263 $wppb_roles = get_editable_roles();
264 $wppb_user_status = get_post_meta( $post->ID, 'wppb-content-restrict-user-status', true );
265 $wppb_selected_roles = get_post_meta( $post->ID, 'wppb-content-restrict-user-role' );
266 ?>
267
268 <div class="cozmoslabs-checkbox-list cozmoslabs-checkbox-multi-col-list">
269
270 <div class="cozmoslabs-chckbox-container">
271 <input type="checkbox" value="loggedin" <?php if( ! empty( $wppb_user_status ) && $wppb_user_status == 'loggedin' ) echo 'checked="checked"'; ?> name="wppb-content-restrict-user-status" id="wppb-content-restrict-user-status">
272 <label class="wppb-meta-box-checkbox-label" for="wppb-content-restrict-user-status">
273 <?php echo esc_html__( 'Logged In Users', 'profile-builder' ); ?>
274 </label>
275 </div>
276
277 <?php
278 if( ! empty( $wppb_roles ) ) {
279 foreach( $wppb_roles as $wppb_role => $wppb_role_details ) {
280 ?>
281 <div class="cozmoslabs-chckbox-container">
282 <input type="checkbox" value="<?php echo esc_attr( $wppb_role ); ?>" <?php if( in_array( $wppb_role, $wppb_selected_roles ) ) echo 'checked="checked"'; ?> name="wppb-content-restrict-user-role[]" id="wppb-content-restrict-user-role-<?php echo esc_attr( $wppb_role ) ?>">
283 <label class="wppb-meta-box-checkbox-label" for="wppb-content-restrict-user-role-<?php echo esc_attr( $wppb_role ) ?>">
284 <?php echo !empty( $wppb_role_details['name'] ) ? esc_html( $wppb_role_details['name'] ) : esc_html( $wppb_role ); ?>
285 </label>
286 </div>
287 <?php } ?>
288
289 <p class="cozmoslabs-description">
290 <?php echo esc_html( sprintf( __( 'Checking only "Logged In Users" will show this %s to all logged in users, regardless of user role.', 'profile-builder' ), apply_filters( 'wppb_content_restrict_settings_description_cpt', $post->post_type ) ) ); ?>
291 </p>
292
293 <p class="cozmoslabs-description">
294 <?php echo esc_html( sprintf( __( 'Checking any user role will show this %s only to users that have one of those user roles assigned.', 'profile-builder' ), apply_filters( 'wppb_content_restrict_settings_description_cpt', $post->post_type ) ) ); ?>
295 </p>
296 <?php } ?>
297
298 </div>
299 </div>
300 </div>
301
302 <?php if( isset( $post->post_type ) && $post->post_type == 'product' ) : ?>
303 <div class="wppb-meta-box-fields-wrapper cozmoslabs-form-subsection-wrapper">
304 <h4 class="cozmoslabs-subsection-title"><?php esc_html_e( 'Purchase Options', 'profile-builder' ); ?></h4>
305
306 <?php
307 $wppb_purchase_user_status = get_post_meta( $post->ID, 'wppb-purchase-restrict-user-status', true );
308 $wppb_selected_purchase_roles = get_post_meta( $post->ID, 'wppb-purchase-restrict-user-role' );
309 ?>
310
311 <!-- Who Can Purchase? options -->
312 <div class="wppb-meta-box-field-wrapper cozmoslabs-form-field-wrapper cozmoslabs-checkbox-list-wrapper">
313 <label class="wppb-meta-box-field-label cozmoslabs-form-field-label"><?php esc_html_e( 'Who can purchase?', 'profile-builder' ); ?></label>
314
315 <div class="cozmoslabs-checkbox-list cozmoslabs-checkbox-multi-col-list">
316
317 <div class="cozmoslabs-chckbox-container">
318 <input type="checkbox" value="loggedin" <?php if( ! empty( $wppb_purchase_user_status ) ) checked($wppb_purchase_user_status, 'loggedin' ); ?> name="wppb-purchase-restrict-user-status" id="wppb-purchase-restrict-user-status">
319 <label class="wppb-meta-box-checkbox-label" for="wppb-purchase-restrict-user-status">
320 <?php esc_html_e( 'Logged In Users', 'profile-builder' ); ?>
321 </label>
322 </div>
323
324 <?php if( !empty( $wppb_roles ) ): foreach( $wppb_roles as $wppb_role => $wppb_role_details ): ?>
325
326 <div class="cozmoslabs-chckbox-container">
327 <input type="checkbox" value="<?php echo esc_attr( $wppb_role ); ?>" <?php if( in_array( $wppb_role, $wppb_selected_purchase_roles ) ) echo 'checked="checked"'; ?> name="wppb-purchase-restrict-user-role[]" id="wppb-purchase-restrict-user-role-<?php echo esc_attr( $wppb_role ) ?>">
328 <label class="wppb-meta-box-checkbox-label" for="wppb-purchase-restrict-user-role-<?php echo esc_attr( $wppb_role ) ?>">
329 <?php echo !empty( $wppb_role_details['name'] ) ? esc_html( $wppb_role_details['name'] ) : esc_html( $wppb_role ); ?>
330 </label>
331 </div>
332
333 <?php endforeach; ?>
334
335 <p class="cozmoslabs-description" style="margin-top: 10px;">
336 <?php esc_html_e( 'Select who can purchase this product.', 'profile-builder' ); ?>
337 </p>
338
339 <?php endif; ?>
340 </div>
341
342 </div>
343 </div>
344 <?php endif; ?>
345
346 <div id="wppb-meta-box-fields-wrapper-restriction-redirect-url" class="wppb-meta-box-fields-wrapper cozmoslabs-form-subsection-wrapper <?php echo ( $wppb_content_restrict_type == 'redirect' ? 'wppb-content-restriction-enabled' : '' ); ?>">
347 <h4 class="cozmoslabs-subsection-title"><?php echo esc_html__( 'Restriction Redirect URL', 'profile-builder' ); ?></h4>
348
349 <div class="wppb-meta-box-field-wrapper cozmoslabs-form-field-wrapper cozmoslabs-toggle-switch">
350
351 <?php $wppb_custom_redirect_url_enabled = get_post_meta( $post->ID, 'wppb-content-restrict-custom-redirect-url-enabled', true ); ?>
352
353 <label class="wppb-meta-box-field-label cozmoslabs-form-field-label" for="wppb-content-restrict-custom-redirect-url-enabled"><?php esc_html_e( 'Enable Custom Redirect URL', 'profile-builder' ); ?></label>
354
355 <div class="cozmoslabs-toggle-container">
356 <input type="checkbox" value="yes" <?php echo ( ! empty( $wppb_custom_redirect_url_enabled ) ? 'checked="checked"' : '' ); ?> name="wppb-content-restrict-custom-redirect-url-enabled" id="wppb-content-restrict-custom-redirect-url-enabled">
357 <label class="cozmoslabs-toggle-track" for="wppb-content-restrict-custom-redirect-url-enabled"></label>
358 </div>
359 <div class="cozmoslabs-toggle-description">
360 <label for="wppb-content-restrict-custom-redirect-url-enabled" class="cozmoslabs-description"><?php echo esc_html( sprintf( __( 'Enable if you wish to add a custom redirect URL for this %s.', 'profile-builder' ), apply_filters( 'wppb_content_restrict_settings_description_cpt', $post->post_type ) ) ); ?></label>
361 </div>
362 </div>
363
364 <div class="wppb-meta-box-field-wrapper cozmoslabs-form-field-wrapper wppb-meta-box-field-wrapper-custom-redirect-url <?php echo ( ! empty( $wppb_custom_redirect_url_enabled ) ? 'wppb-content-restriction-enabled' : '' ); ?>">
365 <?php $wppb_custom_redirect_url = get_post_meta( $post->ID, 'wppb-content-restrict-custom-redirect-url', true ); ?>
366
367 <label class="wppb-meta-box-field-label cozmoslabs-form-field-label" for="wppb-content-restrict-custom-redirect-url"><?php esc_html_e( 'Custom Redirect URL', 'profile-builder' ); ?></label>
368 <input type="text" value="<?php echo ( ! empty( $wppb_custom_redirect_url ) ? esc_url( $wppb_custom_redirect_url ) : '' ); ?>" name="wppb-content-restrict-custom-redirect-url" id="wppb-content-restrict-custom-redirect-url" class="widefat">
369 <p class="cozmoslabs-description cozmoslabs-description-space-left"><?php echo esc_html( sprintf( __( 'Add a URL where you wish to redirect users that do not have access to this %s and try to access it directly.', 'profile-builder' ), apply_filters( 'wppb_content_restrict_settings_description_cpt', $post->post_type ) ) ); ?></p>
370 </div>
371 </div>
372
373 <div id="wppb-meta-box-fields-wrapper-restriction-custom-messages" class="wppb-meta-box-fields-wrapper cozmoslabs-form-subsection-wrapper">
374 <h4 class="cozmoslabs-subsection-title"><?php echo esc_html__( 'Restriction Messages', 'profile-builder' ); ?></h4>
375
376 <div class="wppb-meta-box-field-wrapper cozmoslabs-form-field-wrapper cozmoslabs-toggle-switch">
377 <?php
378 $wppb_custom_messages_enabled = get_post_meta( $post->ID, 'wppb-content-restrict-messages-enabled', true );
379 ?>
380 <label class="wppb-meta-box-field-label cozmoslabs-form-field-label" for="wppb-content-restrict-messages-enabled"><?php esc_html_e( 'Enable Custom Messages', 'profile-builder' ); ?></label>
381
382 <div class="cozmoslabs-toggle-container">
383 <input type="checkbox" value="yes" <?php echo ( ! empty( $wppb_custom_messages_enabled ) ? 'checked="checked"' : '' ); ?> name="wppb-content-restrict-messages-enabled" id="wppb-content-restrict-messages-enabled">
384 <label class="cozmoslabs-toggle-track" for="wppb-content-restrict-messages-enabled"></label>
385 </div>
386 <div class="cozmoslabs-toggle-description">
387 <label for="wppb-content-restrict-messages-enabled" class="cozmoslabs-description"><?php echo esc_html( sprintf( __( 'Enable if you wish to add custom messages for this %s.', 'profile-builder' ), apply_filters( 'wppb_content_restrict_settings_description_cpt', $post->post_type ) ) ); ?></label>
388 </div>
389 </div>
390
391 <div class="wppb-meta-box-field-wrapper-custom-messages <?php echo ( ! empty( $wppb_custom_messages_enabled ) ? 'wppb-content-restriction-enabled' : '' ); ?>">
392 <?php do_action( 'wppb_view_meta_box_content_restrict_restriction_messages_top', $post->ID ); ?>
393
394 <div class="cozmoslabs-form-field-wrapper cozmoslabs-wysiwyg-wrapper cozmoslabs-wysiwyg-indented">
395 <label class="cozmoslabs-form-field-label"><?php esc_html_e( 'Messages for logged-out users', 'profile-builder' ); ?></label>
396 <?php wp_editor( get_post_meta( $post->ID, 'wppb-content-restrict-message-logged_out', true ), 'wppb-content-restrict-message-logged_out', array( 'textarea_name' => 'wppb-content-restrict-message-logged_out', 'editor_height' => 180 ) ); ?>
397 </div>
398
399 <div class="cozmoslabs-form-field-wrapper cozmoslabs-wysiwyg-wrapper cozmoslabs-wysiwyg-indented">
400 <label class="cozmoslabs-form-field-label"><?php esc_html_e( 'Messages for logged-in users', 'profile-builder' ); ?></label>
401 <?php wp_editor( get_post_meta( $post->ID, 'wppb-content-restrict-message-logged_in', true ), 'wppb-content-restrict-message-logged_in', array( 'textarea_name' => 'wppb-content-restrict-message-logged_in', 'editor_height' => 180 ) ); ?>
402 </div>
403
404 <?php if( isset( $post->post_type ) && $post->post_type == 'product' ) : ?>
405
406 <div class="cozmoslabs-form-field-wrapper cozmoslabs-wysiwyg-wrapper cozmoslabs-wysiwyg-indented">
407 <label class="cozmoslabs-form-field-label"><?php esc_html_e( 'Messages for restricted product purchase', 'profile-builder' ); ?></label>
408 <?php wp_editor( wp_kses_post( get_post_meta( $post->ID, 'wppb-content-restrict-message-purchasing_restricted', true ) ), 'wppb-content-restrict-message-purchasing_restricted', array( 'textarea_name' => 'wppb-content-restrict-message-purchasing_restricted', 'editor_height' => 180 ) ); ?>
409 </div>
410
411 <?php endif; ?>
412 </div>
413 </div>
414
415 <?php if ( ! defined( 'WPPB_PAID_PLUGIN_DIR' ) || ( defined( 'PROFILE_BUILDER_PAID_VERSION' ) && PROFILE_BUILDER_PAID_VERSION === 'dev' ) ) : ?>
416
417 <div class="cozmoslabs-form-field-wrapper">
418 <p class="cozmoslabs-description">
419 <?php echo wp_kses_post( sprintf( __( 'Have a question? %1$sOpen a support ticket.%2$s', 'profile-builder' ), '<a href="' . esc_url( 'https://wordpress.org/support/plugin/profile-builder/#new-topic-0' ) . '" target="_blank" rel="noopener">', '</a>' ) ); ?>
420 </p>
421 </div>
422
423 <?php endif; ?>
424
425 <?php
426 wp_nonce_field( 'wppb_meta_box_single_content_restriction_nonce', 'wppb_content_restriction_token', false );
427
428 }
429
430 function wppb_content_restriction_save_data( $post_id ) {
431
432 if( empty( $_POST['wppb_content_restriction_token'] ) || ! wp_verify_nonce( sanitize_text_field( $_POST['wppb_content_restriction_token'] ), 'wppb_meta_box_single_content_restriction_nonce' ) ) {
433 return;
434 }
435
436 // Handle restriction rules
437 delete_post_meta( $post_id, 'wppb-content-restrict-type' );
438
439 if( ! empty( $_POST['wppb-content-restrict-type'] ) ) {
440 update_post_meta( $post_id, 'wppb-content-restrict-type', sanitize_text_field( $_POST['wppb-content-restrict-type'] ) );
441 }
442
443 delete_post_meta( $post_id, 'wppb-content-restrict-user-role' );
444 if( isset( $_POST['wppb-content-restrict-user-role'] ) && is_array( $_POST['wppb-content-restrict-user-role'] ) ) {
445 $user_role_ids = array_map( 'sanitize_text_field', $_POST['wppb-content-restrict-user-role'] );
446 foreach( $user_role_ids as $user_role_id ) {
447 if( ! empty( $user_role_id ) ) {
448 add_post_meta( $post_id, 'wppb-content-restrict-user-role', $user_role_id );
449 }
450 }
451 }
452
453 if( isset( $_POST['wppb-content-restrict-user-status'] ) && $_POST['wppb-content-restrict-user-status'] == 'loggedin' ) {
454 update_post_meta( $post_id, 'wppb-content-restrict-user-status', 'loggedin' );
455 } else {
456 delete_post_meta( $post_id, 'wppb-content-restrict-user-status' );
457 }
458
459 // Handle custom redirect URL
460 delete_post_meta( $post_id, 'wppb-content-restrict-custom-redirect-url-enabled' );
461
462 if( isset( $_POST['wppb-content-restrict-custom-redirect-url-enabled'] ) ) {
463 update_post_meta( $post_id, 'wppb-content-restrict-custom-redirect-url-enabled', 'yes' );
464 }
465
466 update_post_meta( $post_id, 'wppb-content-restrict-custom-redirect-url', ( ! empty( $_POST['wppb-content-restrict-custom-redirect-url'] ) ? esc_url_raw( $_POST['wppb-content-restrict-custom-redirect-url'] ) : '' ) );
467
468 // Handle custom messages
469 delete_post_meta( $post_id, 'wppb-content-restrict-messages-enabled' );
470
471 if( isset( $_POST['wppb-content-restrict-messages-enabled'] ) ) {
472 update_post_meta( $post_id, 'wppb-content-restrict-messages-enabled', 'yes' );
473 }
474
475 update_post_meta( $post_id, 'wppb-content-restrict-message-logged_out', ( ! empty( $_POST['wppb-content-restrict-message-logged_out'] ) ? wp_kses_post( $_POST['wppb-content-restrict-message-logged_out'] ) : '' ) );
476 update_post_meta( $post_id, 'wppb-content-restrict-message-logged_in', ( ! empty( $_POST['wppb-content-restrict-message-logged_in'] ) ? wp_kses_post( $_POST['wppb-content-restrict-message-logged_in'] ) : '' ) );
477
478 // Handle WooCommerce purchase settings
479 delete_post_meta( $post_id, 'wppb-purchase-restrict-user-role' );
480 if( isset( $_POST['wppb-purchase-restrict-user-role'] ) && is_array( $_POST['wppb-purchase-restrict-user-role'] ) ) {
481 $restrict_roles = array_map( 'sanitize_text_field', $_POST['wppb-purchase-restrict-user-role'] );
482 foreach ( $restrict_roles as $role ) {
483 if( !empty( $role ) )
484 add_post_meta($post_id, 'wppb-purchase-restrict-user-role', sanitize_text_field( $role ) );
485 }
486
487 }
488
489 if( isset( $_POST['wppb-purchase-restrict-user-status'] ) && $_POST['wppb-purchase-restrict-user-status'] === 'loggedin' )
490 update_post_meta( $post_id, 'wppb-purchase-restrict-user-status', 'loggedin' );
491 else
492 delete_post_meta( $post_id, 'wppb-purchase-restrict-user-status' );
493
494 // save custom "product purchase restricted" message
495 update_post_meta( $post_id, 'wppb-content-restrict-message-purchasing_restricted', ( ! empty( $_POST['wppb-content-restrict-message-purchasing_restricted'] ) ? wp_kses_post($_POST['wppb-content-restrict-message-purchasing_restricted']) : '' ) );
496
497 }
498 add_action( 'save_post', 'wppb_content_restriction_save_data' );
499 add_action( 'edit_attachment', 'wppb_content_restriction_save_data' );
500
501 function wppb_content_restriction_save_term_data( $term_id, $tt_id = 0, $taxonomy = '' ) {
502
503 if ( empty( $_POST['wppb_content_restriction_token'] ) || ! wp_verify_nonce( sanitize_text_field( $_POST['wppb_content_restriction_token'] ), 'wppb_meta_box_single_content_restriction_nonce' ) ) {
504 return;
505 }
506
507 $supported_taxonomies = wppb_content_restriction_get_supported_taxonomies();
508
509 if ( ! empty( $taxonomy ) && ! isset( $supported_taxonomies[ $taxonomy ] ) ) {
510 return;
511 }
512
513 delete_term_meta( $term_id, 'wppb-content-restrict-type' );
514 if ( ! empty( $_POST['wppb-content-restrict-type'] ) ) {
515 update_term_meta( $term_id, 'wppb-content-restrict-type', sanitize_text_field( $_POST['wppb-content-restrict-type'] ) );
516 }
517
518 delete_term_meta( $term_id, 'wppb-content-restrict-user-role' );
519 if ( isset( $_POST['wppb-content-restrict-user-role'] ) && is_array( $_POST['wppb-content-restrict-user-role'] ) ) {
520 $user_role_ids = array_map( 'sanitize_text_field', $_POST['wppb-content-restrict-user-role'] );
521 foreach ( $user_role_ids as $user_role_id ) {
522 if ( ! empty( $user_role_id ) ) {
523 add_term_meta( $term_id, 'wppb-content-restrict-user-role', $user_role_id );
524 }
525 }
526 }
527
528 if ( isset( $_POST['wppb-content-restrict-user-status'] ) && $_POST['wppb-content-restrict-user-status'] === 'loggedin' ) {
529 update_term_meta( $term_id, 'wppb-content-restrict-user-status', 'loggedin' );
530 } else {
531 delete_term_meta( $term_id, 'wppb-content-restrict-user-status' );
532 }
533
534 delete_term_meta( $term_id, 'wppb-content-restrict-custom-redirect-url-enabled' );
535 if ( isset( $_POST['wppb-content-restrict-custom-redirect-url-enabled'] ) ) {
536 update_term_meta( $term_id, 'wppb-content-restrict-custom-redirect-url-enabled', 'yes' );
537 }
538
539 update_term_meta( $term_id, 'wppb-content-restrict-custom-redirect-url', ( ! empty( $_POST['wppb-content-restrict-custom-redirect-url'] ) ? esc_url_raw( $_POST['wppb-content-restrict-custom-redirect-url'] ) : '' ) );
540
541 delete_term_meta( $term_id, 'wppb-content-restrict-messages-enabled' );
542 if ( isset( $_POST['wppb-content-restrict-messages-enabled'] ) ) {
543 update_term_meta( $term_id, 'wppb-content-restrict-messages-enabled', 'yes' );
544 }
545
546 update_term_meta( $term_id, 'wppb-content-restrict-message-logged_out', ( ! empty( $_POST['wppb-content-restrict-message-logged_out'] ) ? wp_kses_post( $_POST['wppb-content-restrict-message-logged_out'] ) : '' ) );
547 update_term_meta( $term_id, 'wppb-content-restrict-message-logged_in', ( ! empty( $_POST['wppb-content-restrict-message-logged_in'] ) ? wp_kses_post( $_POST['wppb-content-restrict-message-logged_in'] ) : '' ) );
548 }
549