| 1 |
<?php |
| 2 |
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly |
| 3 |
/** |
| 4 |
* Function that creates the "Private Website" submenu page |
| 5 |
* |
| 6 |
* @since v.2.0 |
| 7 |
* |
| 8 |
* @return void |
| 9 |
*/ |
| 10 |
function wppb_private_website_submenu_page() { |
| 11 |
add_submenu_page( null, __( 'Private Website', 'profile-builder' ), __( 'Private Website', 'profile-builder' ), 'manage_options', 'profile-builder-private-website', 'wppb_private_website_content' ); |
| 12 |
} |
| 13 |
add_action( 'admin_menu', 'wppb_private_website_submenu_page' ); |
| 14 |
|
| 15 |
|
| 16 |
/** |
| 17 |
* Function that generates the default settings for private page |
| 18 |
*/ |
| 19 |
function wppb_private_website_settings_defaults() { |
| 20 |
|
| 21 |
add_option( 'wppb_private_website_settings', |
| 22 |
array( |
| 23 |
'private_website' => 'no', |
| 24 |
'redirect_to' => '', |
| 25 |
'allowed_pages' => array(), |
| 26 |
'hide_menus' => 'no', |
| 27 |
'disable_rest_api' => 'yes', |
| 28 |
) |
| 29 |
); |
| 30 |
|
| 31 |
} |
| 32 |
|
| 33 |
/** |
| 34 |
* Function that generates the content for the settings page |
| 35 |
*/ |
| 36 |
function wppb_private_website_content() { |
| 37 |
|
| 38 |
wppb_private_website_settings_defaults(); |
| 39 |
|
| 40 |
$wppb_private_website_settings = get_option( 'wppb_private_website_settings', 'not_found' ); |
| 41 |
|
| 42 |
$args = array( |
| 43 |
'post_type' => 'page', |
| 44 |
'posts_per_page' => -1 |
| 45 |
); |
| 46 |
|
| 47 |
if( function_exists( 'wc_get_page_id' ) ) |
| 48 |
$args['exclude'] = wc_get_page_id( 'shop' ); |
| 49 |
|
| 50 |
$all_pages = get_posts( $args ); |
| 51 |
?> |
| 52 |
<div class="wrap wppb-wrap wppb-private-website"> |
| 53 |
<h2><?php esc_html_e( 'Private Website Settings', 'profile-builder' );?></h2> |
| 54 |
|
| 55 |
<?php settings_errors(); ?> |
| 56 |
|
| 57 |
<?php wppb_generate_settings_tabs() ?> |
| 58 |
|
| 59 |
<form method="post" action="options.php"> |
| 60 |
<?php settings_fields( 'wppb_private_website_settings' ); ?> |
| 61 |
|
| 62 |
<table class="form-table"> |
| 63 |
<tbody> |
| 64 |
|
| 65 |
<tr> |
| 66 |
<th><?php esc_html_e( 'Enable Private Website', 'profile-builder' ); ?></th> |
| 67 |
<td> |
| 68 |
<select id="private-website-enable" class="wppb-select" name="wppb_private_website_settings[private_website]"> |
| 69 |
<option value="no" <?php echo ( ( $wppb_private_website_settings != 'not_found' && $wppb_private_website_settings['private_website'] == 'no' ) ? 'selected' : '' ); ?>><?php esc_html_e( 'No', 'profile-builder' ); ?></option> |
| 70 |
<option value="yes" <?php echo ( ( $wppb_private_website_settings != 'not_found' && $wppb_private_website_settings['private_website'] == 'yes' ) ? 'selected' : '' ); ?>><?php esc_html_e( 'Yes', 'profile-builder' ); ?></option> |
| 71 |
</select> |
| 72 |
<ul> |
| 73 |
<li class="description"><?php esc_html_e( 'Activate Private Website. It will restrict the content, RSS and REST API for your website', 'profile-builder' ); ?></li> |
| 74 |
</ul> |
| 75 |
</td> |
| 76 |
</tr> |
| 77 |
|
| 78 |
<tr> |
| 79 |
<th><?php esc_html_e( 'Redirect to', 'profile-builder' ); ?></th> |
| 80 |
<td> |
| 81 |
<select id="private-website-redirect-to-login" class="wppb-select" name="wppb_private_website_settings[redirect_to]"> |
| 82 |
<option value=""><?php esc_html_e( 'Default WordPress login page', 'profile-builder' ); ?></option> |
| 83 |
<?php |
| 84 |
if( !empty( $all_pages ) ){ |
| 85 |
foreach ($all_pages as $page){ |
| 86 |
?> |
| 87 |
<option value="<?php echo esc_attr( $page->ID ) ?>" <?php echo ( ( $wppb_private_website_settings != 'not_found' && isset( $wppb_private_website_settings['redirect_to'] ) && $wppb_private_website_settings['redirect_to'] == $page->ID ) ? 'selected' : '' ); ?>><?php echo esc_html( $page->post_title ) ?></option> |
| 88 |
<?php |
| 89 |
} |
| 90 |
} |
| 91 |
?> |
| 92 |
|
| 93 |
</select> |
| 94 |
<ul> |
| 95 |
<li class="description"><?php esc_html_e( 'Redirects to this page if not logged in. We recommend this page contains the [wppb-login] shortcode.', 'profile-builder' ); ?></li> |
| 96 |
<li class="description"><?php esc_html_e( 'You can force access to wp-login.php so you don\'t get locked out of the site by accessing the link:', 'profile-builder' ); ?> <a href="<?php echo esc_url( wp_login_url() ).'?wppb_force_wp_login=true' ?>"><?php echo esc_url( wp_login_url() ).'?wppb_force_wp_login=true' ?></a></li> |
| 97 |
</ul> |
| 98 |
</td> |
| 99 |
</tr> |
| 100 |
|
| 101 |
<tr> |
| 102 |
<th><?php esc_html_e( 'Allowed Pages', 'profile-builder' ); ?></th> |
| 103 |
<td> |
| 104 |
<select id="private-website-allowed-pages" class="wppb-select" name="wppb_private_website_settings[allowed_pages][]" multiple="multiple"> |
| 105 |
<?php |
| 106 |
if( !empty( $all_pages ) ){ |
| 107 |
foreach ($all_pages as $page){ |
| 108 |
?> |
| 109 |
<option value="<?php echo esc_attr( $page->ID ) ?>" <?php echo ( ( $wppb_private_website_settings != 'not_found' && isset( $wppb_private_website_settings['allowed_pages'] ) && in_array( $page->ID, $wppb_private_website_settings['allowed_pages'] ) ) ? 'selected' : '' ); ?>><?php echo esc_html( $page->post_title ) ?></option> |
| 110 |
<?php |
| 111 |
} |
| 112 |
} |
| 113 |
?> |
| 114 |
|
| 115 |
</select> |
| 116 |
<ul> |
| 117 |
<li class="description"><?php esc_html_e( 'Allow these pages to be accessed even if you are not logged in', 'profile-builder' ); ?></li> |
| 118 |
</ul> |
| 119 |
</td> |
| 120 |
</tr> |
| 121 |
|
| 122 |
<tr> |
| 123 |
<th><?php esc_html_e( 'Allowed Paths', 'profile-builder' ); ?></th> |
| 124 |
<td> |
| 125 |
<textarea id="private-website-allowed-paths" class="wppb-textarea" name="wppb_private_website_settings[allowed_paths]"><?php echo ( ( $wppb_private_website_settings != 'not_found' && !empty($wppb_private_website_settings['allowed_paths']) ) ? esc_textarea( $wppb_private_website_settings['allowed_paths'] ) : '' ); ?></textarea> |
| 126 |
<ul> |
| 127 |
<li class="description"><?php esc_html_e( 'Allow these paths to be accessed even if you are not logged in (supports wildcard at the end of the path). For example to exclude https://example.com/some/path/ you can either use the rule /some/path/ or /some/* Enter each rule on it\'s own line', 'profile-builder' ); ?></li> |
| 128 |
</ul> |
| 129 |
</td> |
| 130 |
</tr> |
| 131 |
|
| 132 |
<tr> |
| 133 |
<th><?php esc_html_e( 'Hide all Menus', 'profile-builder' ); ?></th> |
| 134 |
<td> |
| 135 |
<select id="private-website-menu-hide" class="wppb-select" name="wppb_private_website_settings[hide_menus]"> |
| 136 |
<option value="no" <?php echo ( ( $wppb_private_website_settings != 'not_found' && !empty($wppb_private_website_settings['hide_menus']) && $wppb_private_website_settings['hide_menus'] == 'no' ) ? 'selected' : '' ); ?>><?php esc_html_e( 'No', 'profile-builder' ); ?></option> |
| 137 |
<option value="yes" <?php echo ( ( $wppb_private_website_settings != 'not_found' && !empty($wppb_private_website_settings['hide_menus']) && $wppb_private_website_settings['hide_menus'] == 'yes' ) ? 'selected' : '' ); ?>><?php esc_html_e( 'Yes', 'profile-builder' ); ?></option> |
| 138 |
</select> |
| 139 |
<ul> |
| 140 |
<li class="description"><?php esc_html_e( 'Hide all menu items if you are not logged in.', 'profile-builder' ); ?></li> |
| 141 |
<li class="description"><?php wp_kses_post( printf( __( 'We recommend "<a href="%s" target="_blank">Custom Profile Menus</a>" addon if you need different menu items for logged in / logged out users.', 'profile-builder' ), 'https://www.cozmoslabs.com/add-ons/custom-profile-menus/' ) ) //phpcs:ignore; ?></li> |
| 142 |
</ul> |
| 143 |
</td> |
| 144 |
</tr> |
| 145 |
|
| 146 |
<tr> |
| 147 |
<th><?php esc_html_e( 'Disable REST-API', 'profile-builder' ); ?></th> |
| 148 |
<td> |
| 149 |
<select id="private-website-disable-rest-api" class="wppb-select" name="wppb_private_website_settings[disable_rest_api]"> |
| 150 |
<option value="yes" <?php selected ( ( $wppb_private_website_settings != 'not_found' && ( !isset( $wppb_private_website_settings[ 'disable_rest_api' ] ) || ( isset( $wppb_private_website_settings[ 'disable_rest_api' ] ) && $wppb_private_website_settings[ 'disable_rest_api' ] == 'yes' ) ) ), true ); ?>><?php esc_html_e( 'Yes', 'profile-builder' ); ?></option> |
| 151 |
<option value="no" <?php selected ( ( $wppb_private_website_settings != 'not_found' && isset( $wppb_private_website_settings[ 'disable_rest_api' ] ) && $wppb_private_website_settings[ 'disable_rest_api' ] == 'no' ), true ); ?>><?php esc_html_e( 'No', 'profile-builder' ); ?></option> |
| 152 |
</select> |
| 153 |
<ul> |
| 154 |
<li class="description"><?php esc_html_e( 'Disable the WordPress REST-API for non-logged in users when Private Website is enabled', 'profile-builder' ); ?></li> |
| 155 |
</ul> |
| 156 |
</td> |
| 157 |
</tr> |
| 158 |
|
| 159 |
</tbody> |
| 160 |
</table> |
| 161 |
|
| 162 |
<?php submit_button( esc_html__( 'Save Changes', 'profile-builder' ) ); ?> |
| 163 |
</form> |
| 164 |
|
| 165 |
|
| 166 |
</div> |
| 167 |
<?php |
| 168 |
} |
| 169 |
|