| 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-settings-container"> |
| 87 |
|
| 88 |
<div class="cozmoslabs-settings"> |
| 89 |
|
| 90 |
<div class="cozmoslabs-form-subsection-wrapper cozmoslabs-no-title-section" id="wppb-content-restriction-settings"> |
| 91 |
|
| 92 |
<?php |
| 93 |
$wppb_generalSettings = get_option( 'wppb_general_settings' ); |
| 94 |
$content_restriction_activated = 'no'; |
| 95 |
if( !empty( $wppb_content_restriction_settings['contentRestriction'] ) ){ |
| 96 |
$content_restriction_activated = $wppb_content_restriction_settings['contentRestriction']; |
| 97 |
} |
| 98 |
elseif( !empty( $wppb_generalSettings['contentRestriction'] ) ){ |
| 99 |
$content_restriction_activated = $wppb_generalSettings['contentRestriction']; |
| 100 |
} |
| 101 |
?> |
| 102 |
|
| 103 |
<div class="cozmoslabs-form-field-wrapper cozmoslabs-toggle-switch"> |
| 104 |
<label class="cozmoslabs-form-field-label" for="contentRestrictionSelect"><?php esc_html_e( 'Content Restriction', 'profile-builder' ); ?></label> |
| 105 |
|
| 106 |
<div class="cozmoslabs-toggle-container"> |
| 107 |
<input type="checkbox" name="wppb_content_restriction_settings[contentRestriction]" id="contentRestrictionSelect" value="yes" <?php echo ( $content_restriction_activated == 'yes' ) ? 'checked' : ''; ?> > |
| 108 |
<label class="cozmoslabs-toggle-track" for="contentRestrictionSelect"></label> |
| 109 |
</div> |
| 110 |
|
| 111 |
<div class="cozmoslabs-toggle-description"> |
| 112 |
<label for="contentRestrictionSelect" class="cozmoslabs-description"><?php esc_html_e( 'Activate Content Restriction.', 'profile-builder' ); ?></label> |
| 113 |
</div> |
| 114 |
</div> |
| 115 |
|
| 116 |
<div class="cozmoslabs-form-field-wrapper"> |
| 117 |
<label class="cozmoslabs-form-field-label"><?php esc_html_e( 'Type of Restriction', 'profile-builder' ); ?></label> |
| 118 |
|
| 119 |
<div class="cozmoslabs-radio-inputs-row"> |
| 120 |
<label for="wppb-content-restrict-type-message"> |
| 121 |
<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]"> |
| 122 |
<?php esc_html_e( 'Message', 'profile-builder' ); ?> |
| 123 |
</label> |
| 124 |
|
| 125 |
<label for="wppb-content-restrict-type-redirect"> |
| 126 |
<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]"> |
| 127 |
<?php esc_html_e( 'Redirect', 'profile-builder' ); ?> |
| 128 |
</label> |
| 129 |
</div> |
| 130 |
|
| 131 |
<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> |
| 132 |
<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> |
| 133 |
</div> |
| 134 |
|
| 135 |
<div class="cozmoslabs-form-field-wrapper"> |
| 136 |
<label class="cozmoslabs-form-field-label" for="wppb-content-restrict-redirect-url"><?php esc_html_e( 'Redirect URL', 'profile-builder' ); ?></label> |
| 137 |
<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'] ) : '' ); ?>" /> |
| 138 |
|
| 139 |
<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> |
| 140 |
</div> |
| 141 |
|
| 142 |
<div class="cozmoslabs-form-field-wrapper cozmoslabs-column-radios-wrapper"> |
| 143 |
<label class="cozmoslabs-form-field-label"><?php esc_html_e( 'Restricted Posts Preview', 'profile-builder' ); ?></label> |
| 144 |
|
| 145 |
<div class="cozmoslabs-radio-inputs-column"> |
| 146 |
<label> |
| 147 |
<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' : '' ); ?> /> |
| 148 |
<?php esc_html_e( 'None', 'profile-builder' ); ?> |
| 149 |
</label> |
| 150 |
|
| 151 |
<label> |
| 152 |
<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' : '' ); ?> /> |
| 153 |
<?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 ?> |
| 154 |
</label> |
| 155 |
|
| 156 |
<label> |
| 157 |
<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' : '' ); ?> /> |
| 158 |
<?php echo esc_html__( 'Show the content before the "more" tag', 'profile-builder' ); ?> |
| 159 |
</label> |
| 160 |
</div> |
| 161 |
|
| 162 |
<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> |
| 163 |
</div> |
| 164 |
|
| 165 |
<div class="cozmoslabs-form-field-wrapper cozmoslabs-toggle-switch"> |
| 166 |
<label class="cozmoslabs-form-field-label" for="excludeRestrictedPosts"><?php esc_html_e( 'Exclude Restricted Posts from Queries', 'profile-builder' ); ?></label> |
| 167 |
|
| 168 |
<div class="cozmoslabs-toggle-container"> |
| 169 |
<input type="checkbox" name="wppb_content_restriction_settings[excludePosts]" id="excludeRestrictedPosts" value="yes" <?php echo ( isset( $wppb_content_restriction_settings['excludePosts'] ) && $wppb_content_restriction_settings['excludePosts'] == 'yes' ) ? 'checked' : ''; ?> > |
| 170 |
<label class="cozmoslabs-toggle-track" for="excludeRestrictedPosts"></label> |
| 171 |
</div> |
| 172 |
|
| 173 |
<div class="cozmoslabs-toggle-description"> |
| 174 |
<label for="excludeRestrictedPosts" class="cozmoslabs-description"><?php esc_html_e( 'Activate this option to exclude the restricted posts from default WordPress and WooCommerce queries.', 'profile-builder' ); ?></label> |
| 175 |
</div> |
| 176 |
</div> |
| 177 |
|
| 178 |
<?php do_action( 'wppb_extra_content_restriction_settings', $wppb_content_restriction_settings ); ?> |
| 179 |
|
| 180 |
</div> |
| 181 |
|
| 182 |
<div class="cozmoslabs-form-subsection-wrapper cozmoslabs-wysiwyg-container"> |
| 183 |
<h4 class="cozmoslabs-subsection-title"><?php esc_html_e( 'Message for logged-out users', 'profile-builder' ); ?></h4> |
| 184 |
|
| 185 |
<div class="cozmoslabs-form-field-wrapper cozmoslabs-wysiwyg-wrapper"> |
| 186 |
<?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 ) ); ?> |
| 187 |
</div> |
| 188 |
</div> |
| 189 |
|
| 190 |
<div class="cozmoslabs-form-subsection-wrapper cozmoslabs-wysiwyg-container"> |
| 191 |
<h4 class="cozmoslabs-subsection-title"><?php esc_html_e( 'Message for logged-in users', 'profile-builder' ); ?></h4> |
| 192 |
|
| 193 |
<div class="cozmoslabs-form-field-wrapper cozmoslabs-wysiwyg-wrapper"> |
| 194 |
<?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 ) ); ?> |
| 195 |
</div> |
| 196 |
</div> |
| 197 |
|
| 198 |
<?php if ( ( in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) || ( is_plugin_active_for_network('woocommerce/woocommerce.php') ) ) : ?> |
| 199 |
<div class="cozmoslabs-form-subsection-wrapper cozmoslabs-wysiwyg-container"> |
| 200 |
<h4 class="cozmoslabs-subsection-title"><?php esc_html_e( 'Message for WooCommerce Restricted Product Purchase', 'profile-builder' ); ?></h4> |
| 201 |
|
| 202 |
<div class="cozmoslabs-form-field-wrapper cozmoslabs-wysiwyg-wrapper"> |
| 203 |
<?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 ) ); ?> |
| 204 |
</div> |
| 205 |
</div> |
| 206 |
<?php endif; ?> |
| 207 |
|
| 208 |
</div> |
| 209 |
|
| 210 |
<div class="submit cozmoslabs-submit"> |
| 211 |
<h3 class="cozmoslabs-subsection-title"><?php esc_html_e( 'Update Settings', 'profile-builder' ) ?></h3> |
| 212 |
<div class="cozmoslabs-publish-button-group"> |
| 213 |
<?php submit_button( __( 'Save Changes', 'profile-builder' ) ); ?> |
| 214 |
</div> |
| 215 |
</div> |
| 216 |
|
| 217 |
</div> |
| 218 |
|
| 219 |
</form> |
| 220 |
</div> |
| 221 |
<?php |
| 222 |
|
| 223 |
} |
| 224 |
|
| 225 |
function wppb_content_restriction_scripts_styles($hook_suffix) { |
| 226 |
//Check if it's an editing or adding new post page |
| 227 |
if( $hook_suffix === 'post-new.php' || $hook_suffix === 'edit.php' || $hook_suffix === 'edit-tags.php' || $hook_suffix === 'term.php' || ( $hook_suffix === 'post.php' && isset( $_GET['action'] ) && $_GET['action'] === 'edit' ) || ( isset( $_GET['page'] ) && $_GET['page'] === 'profile-builder-content_restriction' ) ){ |
| 228 |
wp_enqueue_script( 'wppb_content_restriction_js', plugin_dir_url( __FILE__ ) .'assets/js/content-restriction.js', array( 'jquery' ), PROFILE_BUILDER_VERSION ); |
| 229 |
wp_enqueue_style( 'wppb_content_restriction_css', plugin_dir_url( __FILE__ ) .'assets/css/content-restriction.css', array(), PROFILE_BUILDER_VERSION ); |
| 230 |
|
| 231 |
wp_enqueue_style( 'wppb-back-end-style', WPPB_PLUGIN_URL . 'assets/css/style-back-end.css', array(), PROFILE_BUILDER_VERSION ); |
| 232 |
} |
| 233 |
} |
| 234 |
|
| 235 |
// Declare HPOS compatibility |
| 236 |
add_action( 'before_woocommerce_init', 'wppb_woo_declare_hpos_compatibility' ); |
| 237 |
function wppb_woo_declare_hpos_compatibility() { |
| 238 |
|
| 239 |
$plugin_slug = 'profile-builder/index.php'; |
| 240 |
|
| 241 |
if( defined( 'PROFILE_BUILDER_PAID_VERSION' ) && PROFILE_BUILDER_PAID_VERSION == 'dev' ) |
| 242 |
$plugin_slug = 'profile-builder-dev/index.php'; |
| 243 |
|
| 244 |
if ( class_exists( \Automattic\WooCommerce\Utilities\FeaturesUtil::class ) ) |
| 245 |
\Automattic\WooCommerce\Utilities\FeaturesUtil::declare_compatibility( 'custom_order_tables', $plugin_slug, true ); |
| 246 |
|
| 247 |
} |