← All changes
|
features/content-restriction/content-restriction-meta-box.php
+278
-23
3.9.9
→
4.0.3
View file →
| @@ -13,20 +13,219 @@ | ||
| 13 | 13 | $post_types = get_post_types( array( 'public' => true ) ); |
| 14 | 14 | |
| 15 | 15 | if( ! empty( $post_types ) ) { |
| 16 | 16 | foreach( $post_types as $post_type ) { |
| 17 | - add_meta_box( | |
| 18 | - 'wppb_post_content_restriction', | |
| 19 | - __( 'Profile Builder Content Restriction', 'profile-builder' ), | |
| 20 | - 'wppb_content_restriction_meta_box_output', | |
| 21 | - $post_type, | |
| 22 | - 'normal' | |
| 23 | - ); | |
| 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 | + | |
| 24 | 28 | } |
| 25 | 29 | } |
| 26 | 30 | |
| 27 | 31 | } |
| 28 | 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 | + | |
| 29 | 228 | function wppb_content_restriction_meta_box_output( $post ) { |
| 30 | 229 | |
| 31 | 230 | ?> |
| 32 | 231 | <div class="wppb-meta-box-fields-wrapper cozmoslabs-form-subsection-wrapper"> |
| @@ -65,9 +264,9 @@ | ||
| 65 | 264 | $wppb_user_status = get_post_meta( $post->ID, 'wppb-content-restrict-user-status', true ); |
| 66 | 265 | $wppb_selected_roles = get_post_meta( $post->ID, 'wppb-content-restrict-user-role' ); |
| 67 | 266 | ?> |
| 68 | 267 | |
| 69 | - <div class="cozmoslabs-checkbox-list cozmoslabs-checkbox-4-col-list"> | |
| 268 | + <div class="cozmoslabs-checkbox-list cozmoslabs-checkbox-multi-col-list"> | |
| 70 | 269 | |
| 71 | 270 | <div class="cozmoslabs-chckbox-container"> |
| 72 | 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"> |
| 73 | 272 | <label class="wppb-meta-box-checkbox-label" for="wppb-content-restrict-user-status"> |
| @@ -87,13 +286,13 @@ | ||
| 87 | 286 | </div> |
| 88 | 287 | <?php } ?> |
| 89 | 288 | |
| 90 | 289 | <p class="cozmoslabs-description"> |
| 91 | - <?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' ), $post->post_type) ); ?> | |
| 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 ) ) ); ?> | |
| 92 | 291 | </p> |
| 93 | 292 | |
| 94 | 293 | <p class="cozmoslabs-description"> |
| 95 | - <?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' ), $post->post_type) ); ?> | |
| 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 ) ) ); ?> | |
| 96 | 295 | </p> |
| 97 | 296 | <?php } ?> |
| 98 | 297 | |
| 99 | 298 | </div> |
| @@ -112,9 +311,9 @@ | ||
| 112 | 311 | <!-- Who Can Purchase? options --> |
| 113 | 312 | <div class="wppb-meta-box-field-wrapper cozmoslabs-form-field-wrapper cozmoslabs-checkbox-list-wrapper"> |
| 114 | 313 | <label class="wppb-meta-box-field-label cozmoslabs-form-field-label"><?php esc_html_e( 'Who can purchase?', 'profile-builder' ); ?></label> |
| 115 | 314 | |
| 116 | - <div class="cozmoslabs-checkbox-list cozmoslabs-checkbox-4-col-list"> | |
| 315 | + <div class="cozmoslabs-checkbox-list cozmoslabs-checkbox-multi-col-list"> | |
| 117 | 316 | |
| 118 | 317 | <div class="cozmoslabs-chckbox-container"> |
| 119 | 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"> |
| 120 | 319 | <label class="wppb-meta-box-checkbox-label" for="wppb-purchase-restrict-user-status"> |
| @@ -157,9 +356,9 @@ | ||
| 157 | 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"> |
| 158 | 357 | <label class="cozmoslabs-toggle-track" for="wppb-content-restrict-custom-redirect-url-enabled"></label> |
| 159 | 358 | </div> |
| 160 | 359 | <div class="cozmoslabs-toggle-description"> |
| 161 | - <p class="cozmoslabs-description"><?php echo esc_html( sprintf( __( 'Enable if you wish to add a custom redirect URL for this %s.', 'profile-builder' ), $post->post_type ) ); ?></p> | |
| 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> | |
| 162 | 361 | </div> |
| 163 | 362 | </div> |
| 164 | 363 | |
| 165 | 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' : '' ); ?>"> |
| @@ -166,9 +365,9 @@ | ||
| 166 | 365 | <?php $wppb_custom_redirect_url = get_post_meta( $post->ID, 'wppb-content-restrict-custom-redirect-url', true ); ?> |
| 167 | 366 | |
| 168 | 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> |
| 169 | 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"> |
| 170 | - <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' ), $post->post_type ) ); ?></p> | |
| 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> | |
| 171 | 370 | </div> |
| 172 | 371 | </div> |
| 173 | 372 | |
| 174 | 373 | <div id="wppb-meta-box-fields-wrapper-restriction-custom-messages" class="wppb-meta-box-fields-wrapper cozmoslabs-form-subsection-wrapper"> |
| @@ -184,9 +383,9 @@ | ||
| 184 | 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"> |
| 185 | 384 | <label class="cozmoslabs-toggle-track" for="wppb-content-restrict-messages-enabled"></label> |
| 186 | 385 | </div> |
| 187 | 386 | <div class="cozmoslabs-toggle-description"> |
| 188 | - <p class="cozmoslabs-description"><?php echo esc_html( sprintf( __( 'Enable if you wish to add custom messages for this %s.', 'profile-builder' ), $post->post_type ) ); ?></p> | |
| 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> | |
| 189 | 388 | </div> |
| 190 | 389 | </div> |
| 191 | 390 | |
| 192 | 391 | <div class="wppb-meta-box-field-wrapper-custom-messages <?php echo ( ! empty( $wppb_custom_messages_enabled ) ? 'wppb-content-restriction-enabled' : '' ); ?>"> |
| @@ -212,8 +411,18 @@ | ||
| 212 | 411 | <?php endif; ?> |
| 213 | 412 | </div> |
| 214 | 413 | </div> |
| 215 | 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 | + | |
| 216 | 425 | <?php |
| 217 | 426 | wp_nonce_field( 'wppb_meta_box_single_content_restriction_nonce', 'wppb_content_restriction_token', false ); |
| 218 | 427 | |
| 219 | 428 | } |
| @@ -230,17 +439,14 @@ | ||
| 230 | 439 | if( ! empty( $_POST['wppb-content-restrict-type'] ) ) { |
| 231 | 440 | update_post_meta( $post_id, 'wppb-content-restrict-type', sanitize_text_field( $_POST['wppb-content-restrict-type'] ) ); |
| 232 | 441 | } |
| 233 | 442 | |
| 234 | - if( isset( $_POST['wppb-content-restrict-user-status'] ) && $_POST['wppb-content-restrict-user-status'] === 'loggedin' ) { | |
| 235 | - delete_post_meta( $post_id, 'wppb-content-restrict-user-role' ); | |
| 236 | - | |
| 237 | - if( isset( $_POST['wppb-content-restrict-user-role'] ) && is_array( $_POST['wppb-content-restrict-user-role'] ) ) { | |
| 238 | - $user_role_ids = array_map( 'sanitize_text_field', $_POST['wppb-content-restrict-user-role'] ); | |
| 239 | - foreach( $user_role_ids as $user_role_id ) { | |
| 240 | - if( ! empty( $user_role_id ) ) { | |
| 241 | - add_post_meta( $post_id, 'wppb-content-restrict-user-role', $user_role_id ); | |
| 242 | - } | |
| 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 ); | |
| 243 | 449 | } |
| 244 | 450 | } |
| 245 | 451 | } |
| 246 | 452 | |
| @@ -290,4 +496,53 @@ | ||
| 290 | 496 | |
| 291 | 497 | } |
| 292 | 498 | add_action( 'save_post', 'wppb_content_restriction_save_data' ); |
| 293 | 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 | +} | |