include.view-sidebar.php
5 years ago
include.view.php
5 years ago
index.php
5 years ago
view.access-condition.php
5 years ago
view.contentbox.php
5 years ago
view.access-condition.php
223 lines
| 1 | <?php |
| 2 | |
| 3 | $postedData = ppress_var(@$_POST['ppress_cc_data'], 'access_condition', []); |
| 4 | |
| 5 | $who_can_access = ppressPOST_var('who_can_access', ppress_var($accessConditionData, 'who_can_access'), false, $postedData); |
| 6 | $access_roles = ppressPOST_var('access_roles', ppress_var($accessConditionData, 'access_roles', []), [], $postedData); |
| 7 | $noaccess_action = ppressPOST_var('noaccess_action', ppress_var($accessConditionData, 'noaccess_action'), false, $postedData); |
| 8 | $noaccess_action_message_type = ppressPOST_var('noaccess_action_message_type', ppress_var($accessConditionData, 'noaccess_action_message_type'), false, $postedData); |
| 9 | $noaccess_action_message_custom = ppressPOST_var('noaccess_action_message_custom', ppress_var($accessConditionData, 'noaccess_action_message_custom'), false, $postedData); |
| 10 | $noaccess_action_redirect_url = ppressPOST_var('noaccess_action_redirect_url', ppress_var($accessConditionData, 'noaccess_action_redirect_url'), false, $postedData); |
| 11 | $noaccess_action_redirect_custom_url = ppressPOST_var('noaccess_action_redirect_custom_url', ppress_var($accessConditionData, 'noaccess_action_redirect_custom_url'), false, $postedData); |
| 12 | ?> |
| 13 | |
| 14 | <div class="pp-content-protection-access-box"> |
| 15 | <table class="form-table"> |
| 16 | <tbody> |
| 17 | <tr id="pp-cc-accessible-row"> |
| 18 | <th> |
| 19 | <label for="pp-cc-accessible"><?= esc_html__('Who can access the content?', 'wp-user-avatar') ?></label> |
| 20 | </th> |
| 21 | <td> |
| 22 | <select id="pp-cc-accessible" name="ppress_cc_data[access_condition][who_can_access]"> |
| 23 | <option value="everyone" <?php selected($who_can_access, 'everyone'); ?>><?= esc_html__('Everyone', 'wp-user-avatar') ?></option> |
| 24 | <option value="login" <?php selected($who_can_access, 'login'); ?>><?= esc_html__('Logged in users', 'wp-user-avatar') ?></option> |
| 25 | <option value="logout" <?php selected($who_can_access, 'logout'); ?>><?= esc_html__('Logged out users', 'wp-user-avatar') ?></option> |
| 26 | </select> |
| 27 | </td> |
| 28 | </tr> |
| 29 | <tr id="pp-cc-access-role-row"> |
| 30 | <th> |
| 31 | <label for="pp-cc-access-role"><?= esc_html__('Select roles that can access content', 'wp-user-avatar') ?></label> |
| 32 | </th> |
| 33 | <td> |
| 34 | <span> |
| 35 | <?php foreach (ppress_wp_roles_key_value(false) as $key => $value) : ?> |
| 36 | <label style="display:block"> |
| 37 | <input type="checkbox" name="ppress_cc_data[access_condition][access_roles][]" value="<?= $key ?>" <?= in_array($key, $access_roles) ? 'checked=checked' : ''; ?>> |
| 38 | <span><?= $value ?></span> |
| 39 | </label> |
| 40 | <?php endforeach; ?> |
| 41 | </td> |
| 42 | </tr> |
| 43 | <tr id="pp-cc-access-noaccess-action-row"> |
| 44 | <th> |
| 45 | <label for="pp-cc-access-noaccess-action"> |
| 46 | <?= esc_html__('What happens when users without access tries to view content?', 'wp-user-avatar') ?> |
| 47 | </label> |
| 48 | </th> |
| 49 | <td> |
| 50 | <select id="pp-cc-access-noaccess-action" name="ppress_cc_data[access_condition][noaccess_action]"> |
| 51 | <option value="message" <?php selected($noaccess_action, 'message') ?>><?= esc_html__('Show access restricted message', 'wp-user-avatar') ?></option> |
| 52 | <option value="redirect" <?php selected($noaccess_action, 'redirect') ?>><?= esc_html__('Redirect user', 'wp-user-avatar') ?></option> |
| 53 | </select> |
| 54 | </td> |
| 55 | </tr> |
| 56 | <tr id="pp-cc-access-noaccess-action-message-row"> |
| 57 | <th> |
| 58 | <label for="pp-cc-access-noaccess-action-message"> |
| 59 | <?= esc_html__('Message to show to unauthorized users', 'wp-user-avatar') ?> |
| 60 | </label> |
| 61 | </th> |
| 62 | <td> |
| 63 | <select id="pp-cc-access-noaccess-action-message" name="ppress_cc_data[access_condition][noaccess_action_message_type]"> |
| 64 | <option value="global" <?php selected($noaccess_action_message_type, 'global') ?>><?= esc_html__('Global Restrict Access Message', 'wp-user-avatar') ?></option> |
| 65 | <option value="custom" <?php selected($noaccess_action_message_type, 'custom') ?>><?= esc_html__('Custom message', 'wp-user-avatar') ?></option> |
| 66 | <option value="post_excerpt" <?php selected($noaccess_action_message_type, 'post_excerpt') ?>><?= esc_html__('Post Excerpt', 'wp-user-avatar') ?></option> |
| 67 | <option value="post_excerpt_global" <?php selected($noaccess_action_message_type, 'post_excerpt_global') ?>><?= esc_html__('Post Excerpt + Global Restrict Access Message', 'wp-user-avatar') ?></option> |
| 68 | <option value="post_excerpt_custom" <?php selected($noaccess_action_message_type, 'post_excerpt_custom') ?>><?= esc_html__('Post Excerpt + Custom Message', 'wp-user-avatar') ?></option> |
| 69 | </select> |
| 70 | <p class="description"> |
| 71 | <?= sprintf( |
| 72 | esc_html__('Note that Global Restrict Access Message can be %scustomized here%s.'), |
| 73 | '<a href="' . PPRESS_SETTINGS_SETTING_PAGE . '#access_settings?global_restricted_access_message_row" target="_blank">', '</a>' |
| 74 | ); ?> |
| 75 | </p> |
| 76 | </td> |
| 77 | </tr> |
| 78 | <tr id="pp-cc-access-noaccess-action-message-custom-row"> |
| 79 | <th> |
| 80 | <label for="pp-cc-access-noaccess-action-message-custom"> |
| 81 | <?= esc_html__('Custom Restricted Message', 'wp-user-avatar') ?> |
| 82 | </label> |
| 83 | </th> |
| 84 | <td> |
| 85 | <?php |
| 86 | remove_all_actions('media_buttons'); |
| 87 | remove_all_filters('media_buttons_context'); |
| 88 | remove_all_filters('mce_buttons', 10); |
| 89 | remove_all_filters('mce_external_plugins', 10); |
| 90 | remove_all_actions('after_wp_tiny_mce'); |
| 91 | wp_editor($noaccess_action_message_custom, 'pp-cc-access-noaccess-action-message-custom', [ |
| 92 | 'textarea_name' => 'ppress_cc_data[access_condition][noaccess_action_message_custom]', |
| 93 | 'textarea_rows' => 20, |
| 94 | 'wpautop' => false, |
| 95 | 'media_buttons' => false, |
| 96 | ]); |
| 97 | ?> |
| 98 | </td> |
| 99 | </tr> |
| 100 | <tr id="pp-cc-access-noaccess-action-redirect-row"> |
| 101 | <th> |
| 102 | <label for="pp-cc-access-noaccess-action-redirect"> |
| 103 | <?= esc_html__('Where should users be redirected to?', 'wp-user-avatar') ?> |
| 104 | </label> |
| 105 | </th> |
| 106 | <td> |
| 107 | <select id="pp-cc-access-noaccess-action-redirect" name="ppress_cc_data[access_condition][noaccess_action_redirect_url]"> |
| 108 | <option value="login_page" <?php selected($noaccess_action_redirect_url, 'login_page') ?>><?= esc_html__('Login page', 'wp-user-avatar') ?></option> |
| 109 | <option value="custom_url" <?php selected($noaccess_action_redirect_url, 'custom_url') ?>><?= esc_html__('Custom URL', 'wp-user-avatar') ?></option> |
| 110 | </select> |
| 111 | </td> |
| 112 | </tr> |
| 113 | <tr id="pp-cc-access-noaccess-action-redirect-custom-url-row"> |
| 114 | <th> |
| 115 | <label for="pp-cc-access-noaccess-action-redirect-custom-url"> |
| 116 | <?= esc_html__('Redirect URL', 'wp-user-avatar') ?> |
| 117 | </label> |
| 118 | </th> |
| 119 | <td> |
| 120 | <input type="text" id="pp-cc-access-noaccess-action-redirect-custom-url" name="ppress_cc_data[access_condition][noaccess_action_redirect_custom_url]" value="<?= $noaccess_action_redirect_custom_url ?>"> |
| 121 | </td> |
| 122 | </tr> |
| 123 | </tbody> |
| 124 | </table> |
| 125 | </div> |
| 126 | |
| 127 | <script type="text/javascript"> |
| 128 | (function ($) { |
| 129 | $(function () { |
| 130 | $('#pp-cc-accessible').on('change', function () { |
| 131 | |
| 132 | var val = this.value; |
| 133 | |
| 134 | switch (val) { |
| 135 | case 'everyone': |
| 136 | $('#pp-cc-access-role-row').hide(); |
| 137 | $('#pp-cc-access-noaccess-action-row').hide(); |
| 138 | $('#pp-cc-access-noaccess-action-message-row').hide(); |
| 139 | $('#pp-cc-access-noaccess-action-message-custom-row').hide(); |
| 140 | $('#pp-cc-access-noaccess-action-redirect-row').hide(); |
| 141 | $('#pp-cc-access-noaccess-action-redirect-custom-url-row').hide(); |
| 142 | break; |
| 143 | case 'login': |
| 144 | $('#pp-cc-access-noaccess-action-message-custom-row').hide(); |
| 145 | $('#pp-cc-access-noaccess-action-redirect-row').hide(); |
| 146 | $('#pp-cc-access-noaccess-action-redirect-custom-url-row').hide(); |
| 147 | $('#pp-cc-access-noaccess-action-message-row').hide(); |
| 148 | // all show code must be after hide() |
| 149 | $('#pp-cc-access-role-row').show().find('select').change(); |
| 150 | $('#pp-cc-access-noaccess-action-row').show().find('select').change(); |
| 151 | break; |
| 152 | case 'logout': |
| 153 | $('#pp-cc-access-role-row').hide(); |
| 154 | $('#pp-cc-access-noaccess-action-message-custom-row').hide(); |
| 155 | $('#pp-cc-access-noaccess-action-redirect-row').hide(); |
| 156 | $('#pp-cc-access-noaccess-action-redirect-custom-url-row').hide(); |
| 157 | $('#pp-cc-access-noaccess-action-redirect-row').hide(); |
| 158 | // all show code must be after hide() |
| 159 | $('#pp-cc-access-noaccess-action-row').show().find('select').change(); |
| 160 | break; |
| 161 | } |
| 162 | }); |
| 163 | |
| 164 | $('#pp-cc-access-noaccess-action').on('change', function () { |
| 165 | |
| 166 | var val = this.value; |
| 167 | |
| 168 | switch (val) { |
| 169 | case 'message': |
| 170 | $('#pp-cc-access-noaccess-action-message-custom-row').hide(); |
| 171 | $('#pp-cc-access-noaccess-action-redirect-row').hide(); |
| 172 | $('#pp-cc-access-noaccess-action-redirect-custom-url-row').hide(); |
| 173 | // all show code must be after hide() |
| 174 | $('#pp-cc-access-noaccess-action-message-row').show().find('select').change(); |
| 175 | break; |
| 176 | case 'redirect': |
| 177 | $('#pp-cc-access-noaccess-action-message-row').hide(); |
| 178 | $('#pp-cc-access-noaccess-action-message-custom-row').hide(); |
| 179 | $('#pp-cc-access-noaccess-action-redirect-custom-url-row').hide(); |
| 180 | // all show code must be after hide() |
| 181 | $('#pp-cc-access-noaccess-action-redirect-row').show().find('select').change(); |
| 182 | break; |
| 183 | } |
| 184 | }); |
| 185 | |
| 186 | $('#pp-cc-access-noaccess-action-message').on('change', function () { |
| 187 | |
| 188 | var val = this.value; |
| 189 | |
| 190 | switch (val) { |
| 191 | case 'global': |
| 192 | case 'post_excerpt_global': |
| 193 | $('#pp-cc-access-noaccess-action-message-custom-row').hide(); |
| 194 | $('#pp-cc-access-noaccess-action-redirect-row').hide(); |
| 195 | $('#pp-cc-access-noaccess-action-redirect-custom-url-row').hide(); |
| 196 | break; |
| 197 | case 'custom': |
| 198 | case 'post_excerpt_custom': |
| 199 | $('#pp-cc-access-noaccess-action-redirect-row').hide(); |
| 200 | $('#pp-cc-access-noaccess-action-redirect-custom-url-row').hide(); |
| 201 | $('#pp-cc-access-noaccess-action-message-custom-row').show().find('select').change(); |
| 202 | break; |
| 203 | } |
| 204 | }); |
| 205 | |
| 206 | $('#pp-cc-access-noaccess-action-redirect').on('change', function () { |
| 207 | |
| 208 | var val = this.value; |
| 209 | |
| 210 | switch (val) { |
| 211 | case 'login_page': |
| 212 | $('#pp-cc-access-noaccess-action-redirect-custom-url-row').hide(); |
| 213 | break; |
| 214 | case 'custom_url': |
| 215 | $('#pp-cc-access-noaccess-action-redirect-custom-url-row').show().find('select').change(); |
| 216 | break; |
| 217 | } |
| 218 | }); |
| 219 | |
| 220 | $('#pp-cc-accessible').change(); |
| 221 | }); |
| 222 | })(jQuery) |
| 223 | </script> |