PluginProbe
Authorizer / 3.14.2
Authorizer v3.14.2
3.15.3 3.15.2 3.15.1 3.15.0 3.14.3 3.14.4 3.14.2 3.14.1 2.8.1 2.8.2 2.8.3 2.8.4 2.8.5 2.8.6 2.8.7 2.8.8 2.9.0 2.9.1 2.9.10 2.9.11 2.9.12 2.9.13 2.9.2 2.9.3 2.9.6 All 126 releases
authorizer / src / authorizer / options / class-public-access.php

class-public-access.php in Authorizer 3.14.2, at src/authorizer/options/class-public-access.php

237 lines 9.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Authorizer
4 *
5 * @license GPL-2.0+
6 * @link https://github.com/uhm-coe/authorizer
7 * @package authorizer
8 */
9
10 namespace Authorizer\Options;
11
12 use Authorizer\Helper;
13 use Authorizer\Options;
14
15 /**
16 * Contains functions for rendering the Public Access tab in Authorizer Settings.
17 */
18 class Public_Access extends \Authorizer\Singleton {
19
20 /**
21 * Settings print callback.
22 *
23 * @param array $args Args (e.g., multisite admin mode).
24 * @return void
25 */
26 public function print_section_info_access_public( $args = '' ) {
27 ?>
28 <div id="section_info_access_public" class="section_info">
29 <p><?php esc_html_e( 'Choose your public access options here.', 'authorizer' ); ?></p>
30 </div>
31 <?php
32 }
33
34
35 /**
36 * Settings print callback.
37 *
38 * @param array $args Args (e.g., multisite admin mode).
39 * @return void
40 */
41 public function print_radio_auth_access_who_can_view( $args = '' ) {
42 // Get plugin option.
43 $options = Options::get_instance();
44 $option = 'access_who_can_view';
45 $admin_mode = Helper::get_context( $args );
46 $auth_settings_option = $options->get( $option, $admin_mode, 'allow override', 'print overlay' );
47
48 // If this site is configured independently of any multisite overrides (and
49 // is not prevented from doing so), make sure we are not grabbing the
50 // multisite value; otherwise, grab the multisite value to show behind the
51 // disabled overlay.
52 if ( is_multisite() && 1 === intval( $options->get( 'advanced_override_multisite' ) ) && empty( $options->get( 'prevent_override_multisite', Helper::NETWORK_CONTEXT ) ) ) {
53 $auth_settings_option = $options->get( $option );
54 } elseif ( is_multisite() && Helper::SINGLE_CONTEXT === $admin_mode && '1' === $options->get( 'multisite_override', Helper::NETWORK_CONTEXT ) ) {
55 // Workaround: javascript code hides/shows other settings based
56 // on the selection in this option. If this option is overridden
57 // by a multisite option, it should show that value in order to
58 // correctly display the other appropriate options.
59 // Side effect: this site option will be overwritten by the
60 // multisite option on save. Since this is a 2-item radio, we
61 // determined this was acceptable.
62 $auth_settings_option = $options->get( $option, Helper::NETWORK_CONTEXT );
63 }
64
65 // Print option elements.
66 ?>
67 <fieldset>
68 <label><input type="radio" id="radio_auth_settings_<?php echo esc_attr( $option ); ?>_everyone" name="auth_settings[<?php echo esc_attr( $option ); ?>]" value="everyone"<?php checked( 'everyone' === $auth_settings_option ); ?> /> <?php esc_html_e( 'Everyone can see the site', 'authorizer' ); ?></label>
69 <br>
70 <label><input type="radio" id="radio_auth_settings_<?php echo esc_attr( $option ); ?>_logged_in_users" name="auth_settings[<?php echo esc_attr( $option ); ?>]" value="logged_in_users"<?php checked( 'logged_in_users' === $auth_settings_option ); ?> /> <?php esc_html_e( 'Only logged in users can see the site', 'authorizer' ); ?></label>
71 </fieldset>
72 <?php
73 }
74
75
76 /**
77 * Settings print callback.
78 *
79 * @param array $args Args (e.g., multisite admin mode).
80 * @return void
81 */
82 public function print_radio_auth_access_redirect( $args = '' ) {
83 // Get plugin option.
84 $options = Options::get_instance();
85 $option = 'access_redirect';
86 $auth_settings_option = $options->get( $option );
87
88 // Print option elements.
89 ?>
90 <fieldset>
91 <label><input type="radio" id="radio_auth_settings_<?php echo esc_attr( $option ); ?>_to_login" name="auth_settings[<?php echo esc_attr( $option ); ?>]" value="login"<?php checked( 'login' === $auth_settings_option ); ?> /> <?php esc_html_e( 'Send them to the login screen', 'authorizer' ); ?></label>
92 <br>
93 <label><input type="radio" id="radio_auth_settings_<?php echo esc_attr( $option ); ?>_to_message" name="auth_settings[<?php echo esc_attr( $option ); ?>]" value="message"<?php checked( 'message' === $auth_settings_option ); ?> /> <?php esc_html_e( 'Show them the anonymous access message (below)', 'authorizer' ); ?></label>
94 </fieldset>
95 <?php
96 }
97
98
99 /**
100 * Settings print callback.
101 *
102 * @param array $args Args (e.g., multisite admin mode).
103 * @return void
104 */
105 public function print_radio_auth_access_public_warning( $args = '' ) {
106 // Get plugin option.
107 $options = Options::get_instance();
108 $option = 'access_public_warning';
109 $auth_settings_option = $options->get( $option );
110
111 // Print option elements.
112 ?>
113 <fieldset>
114 <label><input type="radio" id="radio_auth_settings_<?php echo esc_attr( $option ); ?>_no" name="auth_settings[<?php echo esc_attr( $option ); ?>]" value="no_warning"<?php checked( 'no_warning' === $auth_settings_option ); ?> /> <?php echo wp_kses( __( 'Show them the page <strong>without</strong> the anonymous access message', 'authorizer' ), Helper::$allowed_html ); ?></label>
115 <br>
116 <label><input type="radio" id="radio_auth_settings_<?php echo esc_attr( $option ); ?>" name="auth_settings[<?php echo esc_attr( $option ); ?>]" value="warning"<?php checked( 'warning' === $auth_settings_option ); ?> /> <?php echo wp_kses( __( 'Show them the page <strong>with</strong> the anonymous access message (marked up as a <a href="http://getbootstrap.com/components/#alerts-dismissible" target="_blank">Bootstrap Dismissible Alert</a>)', 'authorizer' ), Helper::$allowed_html ); ?></label>
117 </fieldset>
118 <?php
119 }
120
121
122 /**
123 * Settings print callback.
124 *
125 * @param array $args Args (e.g., multisite admin mode).
126 * @return void
127 */
128 public function print_wysiwyg_auth_access_redirect_to_message( $args = '' ) {
129 // Get plugin option.
130 $options = Options::get_instance();
131 $option = 'access_redirect_to_message';
132 $auth_settings_option = $options->get( $option );
133
134 // Print option elements. If setting is overriden by filter or constant,
135 // don't expose the value; just print an informational message.
136 if ( has_filter( 'authorizer_message_anonymous_users' ) ) {
137 ?>
138 <input type="hidden" id="auth_settings_<?php echo esc_attr( $option ); ?>" name="auth_settings[<?php echo esc_attr( $option ); ?>]" value="<?php echo esc_attr( $auth_settings_option ); ?>" />
139 <p class="description">
140 <?php
141 echo wp_kses_post(
142 sprintf(
143 /* TRANSLATORS: %s: filter name */
144 __( 'This setting is not editable since it has been defined in the %s filter.', 'authorizer' ),
145 '<code>authorizer_message_anonymous_users</code>'
146 )
147 );
148 ?>
149 </p>
150 <?php
151 return;
152 } elseif ( defined( 'AUTHORIZER_MESSAGE_ANONYMOUS_USERS' ) ) {
153 ?>
154 <input type="hidden" id="auth_settings_<?php echo esc_attr( $option ); ?>" name="auth_settings[<?php echo esc_attr( $option ); ?>]" value="<?php echo esc_attr( $auth_settings_option ); ?>" />
155 <p class="description">
156 <?php
157 echo wp_kses_post(
158 sprintf(
159 /* TRANSLATORS: %s: defined constant name */
160 __( 'This setting is not editable since it has been defined in wp-config.php via %s', 'authorizer' ),
161 "<code>define( 'AUTHORIZER_MESSAGE_ANONYMOUS_USERS', '...' );</code>"
162 )
163 );
164 ?>
165 </p>
166 <?php
167 return;
168 }
169 wp_editor(
170 wpautop( $auth_settings_option ),
171 "auth_settings_$option",
172 array(
173 'media_buttons' => false,
174 'textarea_name' => "auth_settings[$option]",
175 'textarea_rows' => 5,
176 'tinymce' => true,
177 'teeny' => true,
178 'quicktags' => false,
179 )
180 );
181 }
182
183
184 /**
185 * Settings print callback.
186 *
187 * @param array $args Args (e.g., multisite admin mode).
188 * @return void
189 */
190 public function print_multiselect_auth_access_public_pages( $args = '' ) {
191 // Get plugin option.
192 $options = Options::get_instance();
193 $option = 'access_public_pages';
194 $auth_settings_option = $options->get( $option );
195 $auth_settings_option = is_array( $auth_settings_option ) ? $auth_settings_option : array();
196
197 $post_types = array_merge( array( 'page', 'post' ), get_post_types( array( '_builtin' => false ), 'names' ) );
198 $post_types = is_array( $post_types ) ? $post_types : array();
199
200 // Print option elements.
201 ?>
202 <select id="auth_settings_<?php echo esc_attr( $option ); ?>" multiple="multiple" name="auth_settings[<?php echo esc_attr( $option ); ?>][]">
203 <optgroup label="<?php esc_attr_e( 'Home', 'authorizer' ); ?>">
204 <option value="home" <?php selected( in_array( 'home', $auth_settings_option, true ) ); ?>><?php esc_html_e( 'Home Page', 'authorizer' ); ?></option>
205 <option value="auth_public_404" <?php selected( in_array( 'auth_public_404', $auth_settings_option, true ) ); ?>><?php esc_html_e( 'Nonexistent (404) Pages', 'authorizer' ); ?></option>
206 </optgroup>
207 <?php foreach ( $post_types as $post_type ) : ?>
208 <optgroup label="<?php echo esc_attr( ucfirst( $post_type ) ); ?>">
209 <?php
210 $pages = get_posts(
211 array(
212 'post_type' => $post_type,
213 'posts_per_page' => 1000, // phpcs:ignore WordPress.WP.PostsPerPage.posts_per_page_posts_per_page
214 // Disable caches to minimize memory footprint.
215 'cache_results' => false,
216 'update_post_meta_cache' => false,
217 'update_post_term_cache' => false,
218 'update_menu_item_cache' => false,
219 )
220 );
221 $pages = is_array( $pages ) ? $pages : array();
222 foreach ( $pages as $page ) :
223 ?>
224 <option value="<?php echo esc_attr( $page->ID ); ?>" <?php selected( in_array( strval( $page->ID ), $auth_settings_option, true ) ); ?>><?php echo esc_html( $page->post_title ); ?></option>
225 <?php endforeach; ?>
226 </optgroup>
227 <?php endforeach; ?>
228 <optgroup label="<?php esc_attr_e( 'Categories', 'authorizer' ); ?>">
229 <?php foreach ( get_categories( array( 'hide_empty' => false ) ) as $category ) : ?>
230 <option value="<?php echo esc_attr( 'cat_' . $category->slug ); ?>" <?php selected( in_array( 'cat_' . $category->slug, $auth_settings_option, true ) ); ?>><?php echo esc_html( $category->name ); ?></option>
231 <?php endforeach; ?>
232 </optgroup>
233 </select>
234 <?php
235 }
236 }
237