PluginProbe
User Profile Builder – Beautiful User Registration Forms, User Profiles & User Role Editor / 3.9.9
User Profile Builder – Beautiful User Registration Forms, User Profiles & User Role Editor v3.9.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.php

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

206 lines 13.1 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 $wppb_generalSettings = get_option( 'wppb_general_settings', 'not_found' );
5 $wppb_content_restriction_settings = get_option( 'wppb_content_restriction_settings', 'not_found' );
6 if( $wppb_generalSettings != 'not_found' || $wppb_content_restriction_settings != 'not_found' ) {
7 global $content_restriction_activated;
8 $content_restriction_activated = 'no';
9 if( !empty( $wppb_content_restriction_settings['contentRestriction'] ) ){
10 $content_restriction_activated = $wppb_content_restriction_settings['contentRestriction'];
11 }
12 elseif( !empty( $wppb_generalSettings['contentRestriction'] ) ){
13 $content_restriction_activated = $wppb_generalSettings['contentRestriction'];
14 }
15 if( $content_restriction_activated == 'yes' ) {
16 include_once 'content-restriction-meta-box.php';
17 include_once 'content-restriction-filtering.php';
18 }
19 include_once 'content-restriction-functions.php';
20 }
21
22 add_action( 'admin_menu', 'wppb_content_restriction_submenu', 10 );
23 add_action( 'admin_enqueue_scripts', 'wppb_content_restriction_scripts_styles' );
24
25 function wppb_content_restriction_submenu() {
26
27 add_submenu_page( 'profile-builder', __( 'Content Restriction', 'profile-builder' ), __( 'Content Restriction', 'profile-builder' ), 'manage_options', 'profile-builder-content_restriction', 'wppb_content_restriction_content' );
28
29 }
30
31 /* hide the menu item for Content restriction if it is disabled...in v 2.8.9 or 2.9.0 we should remove all the unnecessary tab menus */
32 add_action( 'admin_head', 'wppb_hide_content_restriction_menu' );
33 function wppb_hide_content_restriction_menu(){
34 global $content_restriction_activated;
35 if( $content_restriction_activated == 'no' ){
36 echo '<style type="text/css">a[href="admin.php?page=profile-builder-content_restriction"]{display:none !important;}</style>';
37 }
38 }
39
40 function wppb_content_restriction_settings_defaults() {
41
42 add_option( 'wppb_content_restriction_settings',
43 array(
44 'restrict_type' => 'message',
45 'redirect_url' => '',
46 'message_logged_out' => '',
47 'message_logged_in' => '',
48 'purchasing_restricted' => '',
49 'post_preview' => 'none',
50 'post_preview_length' => '20',
51 )
52 );
53
54 }
55
56 function wppb_content_restriction_content() {
57
58 wppb_content_restriction_settings_defaults();
59
60 $wppb_content_restriction_settings = get_option( 'wppb_content_restriction_settings', 'not_found' );
61
62 ?>
63 <div class="wrap wppb-content-restriction-wrap cozmoslabs-wrap">
64
65 <h1></h1>
66 <!-- WordPress Notices are added after the h1 tag -->
67
68 <div class="cozmoslabs-page-header">
69 <div class="cozmoslabs-section-title">
70
71 <h2 class="cozmoslabs-page-title">
72 <?php esc_html_e( 'Content Restriction Settings', 'profile-builder' ); ?>
73 <a href="https://www.cozmoslabs.com/docs/profile-builder/general-settings/content-restriction/?utm_source=wpbackend&utm_medium=pb-documentation&utm_campaign=PBDocs" target="_blank" data-code="f223" class="wppb-docs-link dashicons dashicons-editor-help"></a>
74 </h2>
75
76 </div>
77 </div>
78
79 <?php settings_errors(); ?>
80
81 <?php wppb_generate_settings_tabs() ?>
82
83 <form method="post" action="options.php">
84 <?php settings_fields( 'wppb_content_restriction_settings' ); ?>
85
86 <div class="cozmoslabs-form-subsection-wrapper cozmoslabs-no-title-section" id="wppb-content-restriction-settings">
87
88 <?php
89 $wppb_generalSettings = get_option( 'wppb_general_settings' );
90 $content_restriction_activated = 'no';
91 if( !empty( $wppb_content_restriction_settings['contentRestriction'] ) ){
92 $content_restriction_activated = $wppb_content_restriction_settings['contentRestriction'];
93 }
94 elseif( !empty( $wppb_generalSettings['contentRestriction'] ) ){
95 $content_restriction_activated = $wppb_generalSettings['contentRestriction'];
96 }
97 ?>
98
99 <div class="cozmoslabs-form-field-wrapper cozmoslabs-toggle-switch">
100 <label class="cozmoslabs-form-field-label" for="contentRestrictionSelect"><?php esc_html_e( 'Content Restriction', 'profile-builder' ); ?></label>
101
102 <div class="cozmoslabs-toggle-container">
103 <input type="checkbox" name="wppb_content_restriction_settings[contentRestriction]" id="contentRestrictionSelect" value="yes" <?php echo ( $content_restriction_activated == 'yes' ) ? 'checked' : ''; ?> >
104 <label class="cozmoslabs-toggle-track" for="contentRestrictionSelect"></label>
105 </div>
106
107 <div class="cozmoslabs-toggle-description">
108 <p class="cozmoslabs-description"><?php esc_html_e( 'Activate Content Restriction.', 'profile-builder' ); ?></p>
109 </div>
110 </div>
111
112 <div class="cozmoslabs-form-field-wrapper">
113 <label class="cozmoslabs-form-field-label"><?php esc_html_e( 'Type of Restriction', 'profile-builder' ); ?></label>
114
115 <div class="cozmoslabs-radio-inputs-row">
116 <label for="wppb-content-restrict-type-message">
117 <input type="radio" id="wppb-content-restrict-type-message" value="message" <?php echo ( ( $wppb_content_restriction_settings != 'not_found' && $wppb_content_restriction_settings['restrict_type'] == 'message' ) ? 'checked="checked"' : '' ); ?> name="wppb_content_restriction_settings[restrict_type]">
118 <?php esc_html_e( 'Message', 'profile-builder' ); ?>
119 </label>
120
121 <label for="wppb-content-restrict-type-redirect">
122 <input type="radio" id="wppb-content-restrict-type-redirect" value="redirect" <?php echo ( ( $wppb_content_restriction_settings != 'not_found' && $wppb_content_restriction_settings['restrict_type'] == 'redirect' ) ? 'checked="checked"' : '' ); ?> name="wppb_content_restriction_settings[restrict_type]">
123 <?php esc_html_e( 'Redirect', 'profile-builder' ); ?>
124 </label>
125 </div>
126
127 <p class="cozmoslabs-description cozmoslabs-description-space-left"><?php echo esc_html__( 'If you select "Message", the post\'s content will be protected by being replaced with a custom message.', 'profile-builder' ); ?></p>
128 <p class="cozmoslabs-description cozmoslabs-description-space-left"><?php echo esc_html__( 'If you select "Redirect", the post\'s content will be protected by redirecting the user to the URL you specify. The redirect happens only when accessing a single post. On archive pages the restriction message will be displayed, instead of the content.', 'profile-builder' ); ?></p>
129 </div>
130
131 <div class="cozmoslabs-form-field-wrapper">
132 <label class="cozmoslabs-form-field-label" for="wppb-content-restrict-redirect-url"><?php esc_html_e( 'Redirect URL', 'profile-builder' ); ?></label>
133 <input type="text" id="wppb-content-restrict-redirect-url" class="widefat" name="wppb_content_restriction_settings[redirect_url]" value="<?php echo ( ( $wppb_content_restriction_settings != 'not_found' && ! empty( $wppb_content_restriction_settings['redirect_url'] ) ) ? esc_url( $wppb_content_restriction_settings['redirect_url'] ) : '' ); ?>" />
134
135 <p class="cozmoslabs-description cozmoslabs-description-space-left"><?php echo esc_html__( 'The URL where the user will be redirected if a redirect restriction is selected above.', 'profile-builder' ); ?></p>
136 </div>
137
138 <div class="cozmoslabs-form-field-wrapper cozmoslabs-column-radios-wrapper">
139 <label class="cozmoslabs-form-field-label"><?php esc_html_e( 'Restricted Posts Preview', 'profile-builder' ); ?></label>
140
141 <div class="cozmoslabs-radio-inputs-column">
142 <label>
143 <input type="radio" name="wppb_content_restriction_settings[post_preview]" value="none" <?php echo ( ( $wppb_content_restriction_settings != 'not_found' ) && $wppb_content_restriction_settings['post_preview'] == 'none' ? 'checked' : '' ); ?> />
144 <?php esc_html_e( 'None', 'profile-builder' ); ?>
145 </label>
146
147 <label>
148 <input type="radio" name="wppb_content_restriction_settings[post_preview]" value="trim-content" <?php echo ( ( $wppb_content_restriction_settings != 'not_found' ) && $wppb_content_restriction_settings['post_preview'] == 'trim-content' ? 'checked' : '' ); ?> />
149 <?php echo sprintf( __( 'Show the first %s words of the post\'s content', 'profile-builder' ), '<input name="wppb_content_restriction_settings[post_preview_length]" type="text" value="'. ( $wppb_content_restriction_settings != 'not_found' && ! empty( $wppb_content_restriction_settings['post_preview_length'] ) ? esc_attr( $wppb_content_restriction_settings['post_preview_length'] ) : 20 ) .'" style="width: 50px; height: 25px; min-height: 25px;" />' ); //phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
150 </label>
151
152 <label>
153 <input type="radio" name="wppb_content_restriction_settings[post_preview]" value="more-tag" <?php echo ( ( $wppb_content_restriction_settings != 'not_found' ) && $wppb_content_restriction_settings['post_preview'] == 'more-tag' ? 'checked' : '' ); ?> />
154 <?php echo esc_html__( 'Show the content before the "more" tag', 'profile-builder' ); ?>
155 </label>
156 </div>
157
158 <p class="cozmoslabs-description cozmoslabs-description-space-left"><?php echo esc_html__( 'Show a portion of the restricted post to logged-out users or users that are not allowed to see it.', 'profile-builder' ); ?></p>
159 </div>
160
161 </div>
162
163 <div class="cozmoslabs-form-subsection-wrapper cozmoslabs-wysiwyg-container">
164 <h4 class="cozmoslabs-subsection-title"><?php esc_html_e( 'Message for logged-out users', 'profile-builder' ); ?></h4>
165
166 <div class="cozmoslabs-form-field-wrapper cozmoslabs-wysiwyg-wrapper">
167 <?php wp_editor( wppb_get_restriction_content_message( 'logged_out' ), 'message_logged_out', array( 'textarea_name' => 'wppb_content_restriction_settings[message_logged_out]', 'editor_height' => 180 ) ); ?>
168 </div>
169 </div>
170
171 <div class="cozmoslabs-form-subsection-wrapper cozmoslabs-wysiwyg-container">
172 <h4 class="cozmoslabs-subsection-title"><?php esc_html_e( 'Message for logged-in users', 'profile-builder' ); ?></h4>
173
174 <div class="cozmoslabs-form-field-wrapper cozmoslabs-wysiwyg-wrapper">
175 <?php wp_editor( wppb_get_restriction_content_message( 'logged_in' ), 'message_logged_in', array( 'textarea_name' => 'wppb_content_restriction_settings[message_logged_in]', 'editor_height' => 180 ) ); ?>
176 </div>
177 </div>
178
179 <?php if ( ( in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) || ( is_plugin_active_for_network('woocommerce/woocommerce.php') ) ) : ?>
180 <div class="cozmoslabs-form-subsection-wrapper cozmoslabs-wysiwyg-container">
181 <h4 class="cozmoslabs-subsection-title"><?php esc_html_e( 'Message for WooCommerce Restricted Product Purchase', 'profile-builder' ); ?></h4>
182
183 <div class="cozmoslabs-form-field-wrapper cozmoslabs-wysiwyg-wrapper">
184 <?php wp_editor( wppb_get_restriction_content_message( 'purchasing_restricted' ), 'messages_purchasing_restricted', array( 'textarea_name' => 'wppb_content_restriction_settings[purchasing_restricted]', 'editor_height' => 180 ) ); ?>
185 </div>
186 </div>
187 <?php endif; ?>
188
189 <?php submit_button( __( 'Save Changes', 'profile-builder' ) ); ?>
190 </form>
191 </div>
192 <?php
193
194 }
195
196 function wppb_content_restriction_scripts_styles($hook_suffix) {
197 //Check if it's an editing or adding new post page
198 if( $hook_suffix === 'post-new.php' || $hook_suffix === 'edit.php' || ( $hook_suffix === 'post.php' && isset( $_GET['action'] ) && $_GET['action'] === 'edit' ) || ( isset( $_GET['page'] ) && $_GET['page'] === 'profile-builder-content_restriction' ) ){
199 wp_enqueue_script( 'wppb_content_restriction_js', plugin_dir_url( __FILE__ ) .'assets/js/content-restriction.js', array( 'jquery' ), PROFILE_BUILDER_VERSION );
200 wp_enqueue_style( 'wppb_content_restriction_css', plugin_dir_url( __FILE__ ) .'assets/css/content-restriction.css', array(), PROFILE_BUILDER_VERSION );
201
202 wp_enqueue_style( 'wppb-back-end-style', WPPB_PLUGIN_URL . 'assets/css/style-back-end.css', array(), PROFILE_BUILDER_VERSION );
203 }
204 }
205
206