PluginProbe
User Profile Builder – Beautiful User Registration Forms, User Profiles & User Role Editor / 3.9.6
User Profile Builder – Beautiful User Registration Forms, User Profiles & User Role Editor v3.9.6
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.6, at features/content-restriction/content-restriction.php

192 lines 12.4 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">
64 <h2>
65 <?php esc_html_e( 'Content Restriction Settings', 'profile-builder' ); ?>
66 <a href="https://www.cozmoslabs.com/docs/profile-builder-2/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>
67 </h2>
68
69 <?php settings_errors(); ?>
70
71 <?php wppb_generate_settings_tabs() ?>
72
73 <form method="post" action="options.php">
74 <?php settings_fields( 'wppb_content_restriction_settings' ); ?>
75
76 <div id="wppb-settings-content-restriction">
77
78 <?php
79 $wppb_generalSettings = get_option( 'wppb_general_settings' );
80 $content_restriction_activated = 'no';
81 if( !empty( $wppb_content_restriction_settings['contentRestriction'] ) ){
82 $content_restriction_activated = $wppb_content_restriction_settings['contentRestriction'];
83 }
84 elseif( !empty( $wppb_generalSettings['contentRestriction'] ) ){
85 $content_restriction_activated = $wppb_generalSettings['contentRestriction'];
86 }
87 ?>
88 <div class="wppb-restriction-fields-group">
89 <label class="wppb-restriction-label" for="contentRestrictionSelect"><?php esc_html_e( 'Enable Content Restriction', 'profile-builder' ); ?></label>
90 <div class="wppb-restriction-activated">
91 <select id="contentRestrictionSelect" name="wppb_content_restriction_settings[contentRestriction]">
92 <option value="no" <?php if( $content_restriction_activated == 'no' ) echo 'selected'; ?>><?php esc_html_e( 'No', 'profile-builder' ); ?></option>
93 <option value="yes" <?php if( $content_restriction_activated == 'yes' ) echo 'selected'; ?>><?php esc_html_e( 'Yes', 'profile-builder' ); ?></option>
94 </select>
95 <p class="description"><?php esc_html_e( 'Activate Content Restriction', 'profile-builder' ); ?></p>
96 </div>
97 </div>
98
99 <div class="wppb-restriction-fields-group">
100 <label class="wppb-restriction-label"><?php esc_html_e( 'Type of Restriction', 'profile-builder' ); ?></label>
101
102 <div class="wppb-restriction-type">
103 <label for="wppb-content-restrict-type-message">
104 <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]">
105 <?php esc_html_e( 'Message', 'profile-builder' ); ?>
106 </label>
107
108 <label for="wppb-content-restrict-type-redirect">
109 <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]">
110 <?php esc_html_e( 'Redirect', 'profile-builder' ); ?>
111 </label>
112
113 <p class="description" style="margin-top: 10px;"><?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>
114 <p class="description"><?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>
115 </div>
116 </div>
117
118 <div class="wppb-restriction-fields-group">
119 <label class="wppb-restriction-label"><?php esc_html_e( 'Redirect URL', 'profile-builder' ); ?></label>
120 <input type="text" 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'] ) : '' ); ?>" />
121 </div>
122
123 <div class="wppb-restriction-fields-group">
124 <label class="wppb-restriction-label"><?php esc_html_e( 'Message for logged-out users', 'profile-builder' ); ?></label>
125 <?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' => 250 ) ); ?>
126 </div>
127
128 <div class="wppb-restriction-fields-group">
129 <label class="wppb-restriction-label"><?php esc_html_e( 'Message for logged-in users', 'profile-builder' ); ?></label>
130 <?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' => 250 ) ); ?>
131 </div>
132
133 <?php if ( ( in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) || ( is_plugin_active_for_network('woocommerce/woocommerce.php') ) ) : ?>
134 <h4 class="pms-subsection-title"><?php esc_html_e( 'WooCommerce Restriction Messages', 'profile-builder' ); ?></h4>
135
136 <div class="wppb-restriction-fields-group">
137
138 <label class="wppb-restriction-label"><?php esc_html_e( 'Messages for restricted product purchase', 'profile-builder' ); ?></label>
139 <?php wp_editor( wppb_get_restriction_content_message( 'purchasing_restricted' ), 'messages_purchasing_restricted', array( 'textarea_name' => 'wppb_content_restriction_settings[purchasing_restricted]', 'editor_height' => 250 ) ); ?>
140
141 </div>
142 <?php endif; ?>
143
144 <div class="wppb-restriction-fields-group">
145 <label class="wppb-restriction-label" for="restricted-posts-preview"><?php esc_html_e( 'Restricted Posts Preview', 'profile-builder' ) ?></label>
146
147 <div class="wppb-restriction-post-preview">
148 <div>
149 <label>
150 <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' : '' ); ?> />
151 <span><?php esc_html_e( 'None', 'profile-builder' ); ?></span>
152 </label>
153 </div>
154
155 <div>
156 <label>
157 <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' : '' ); ?> />
158
159 <span>
160 <?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;" />' ); //phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
161 </span>
162 </label>
163 </div>
164
165 <div>
166 <label>
167 <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' : '' ); ?> />
168 <span><?php echo esc_html__( 'Show the content before the "more" tag', 'profile-builder' ); ?></span>
169 </label>
170 </div>
171
172 <p class="description"><?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>
173 </div>
174 </div>
175 </div>
176
177 <?php submit_button( __( 'Save Changes', 'profile-builder' ) ); ?>
178 </form>
179 </div>
180 <?php
181
182 }
183
184 function wppb_content_restriction_scripts_styles($hook_suffix) {
185 //Check if it's an editing or adding new post page
186 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' ) ){
187 wp_enqueue_script( 'wppb_content_restriction_js', plugin_dir_url( __FILE__ ) .'assets/js/content-restriction.js', array( 'jquery' ), PROFILE_BUILDER_VERSION );
188 wp_enqueue_style( 'wppb_content_restriction_css', plugin_dir_url( __FILE__ ) .'assets/css/content-restriction.css', array(), PROFILE_BUILDER_VERSION );
189 }
190 }
191
192