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 / external / class-google.php

class-google.php in Authorizer 3.14.2, at src/authorizer/options/external/class-google.php

190 lines 8.0 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\External;
11
12 use Authorizer\Helper;
13 use Authorizer\Options;
14
15 /**
16 * Contains functions for rendering the Google options in the External Service
17 * tab in Authorizer Settings.
18 */
19 class Google extends \Authorizer\Singleton {
20
21 /**
22 * Settings print callback.
23 *
24 * @param array $args Args (e.g., multisite admin mode).
25 * @return void
26 */
27 public function print_checkbox_auth_external_google( $args = '' ) {
28 // Get plugin option.
29 $options = Options::get_instance();
30 $option = 'google';
31 $auth_settings_option = $options->get( $option, Helper::get_context( $args ), 'allow override', 'print overlay' );
32
33 // Print option elements.
34 ?>
35 <input type="checkbox" id="auth_settings_<?php echo esc_attr( $option ); ?>" name="auth_settings[<?php echo esc_attr( $option ); ?>]" value="1"<?php checked( 1 === intval( $auth_settings_option ) ); ?> /><label for="auth_settings_<?php echo esc_attr( $option ); ?>"><?php esc_html_e( 'Enable Google Logins', 'authorizer' ); ?></label>
36 <?php
37 }
38
39
40 /**
41 * Settings print callback.
42 *
43 * @param array $args Args (e.g., multisite admin mode).
44 * @return void
45 */
46 public function print_text_google_clientid( $args = '' ) {
47 // Get plugin option.
48 $options = Options::get_instance();
49 $option = 'google_clientid';
50 $auth_settings_option = $options->get( $option, Helper::get_context( $args ), 'allow override', 'print overlay' );
51
52 // Print option elements.
53 $site_url_parts = wp_parse_url( get_site_url() );
54 $site_url_host = $site_url_parts['scheme'] . '://' . $site_url_parts['host'] . '/';
55
56 esc_html_e( "If you don't have a Google Client ID and Secret, generate them by following these instructions:", 'authorizer' );
57 ?>
58 <ol>
59 <li><?php echo wp_kses( __( 'Click <strong>Create a Project</strong> on the <a href="https://cloud.google.com/console" target="_blank">Google Cloud Console</a>. You can name it whatever you want.', 'authorizer' ), Helper::$allowed_html ); ?></li>
60 <li><?php echo wp_kses( __( 'Within the project, navigate to <em>APIs and Services</em> &gt; <em>Credentials</em>, then click <strong>+ Create Credentials &gt; OAuth client ID</strong>. Use these settings:', 'authorizer' ), Helper::$allowed_html ); ?>
61 <ul>
62 <li><?php echo wp_kses( __( 'Application Type: <strong>Web application</strong>', 'authorizer' ), Helper::$allowed_html ); ?></li>
63 <li><?php esc_html_e( 'Authorized Javascript Origins:', 'authorizer' ); ?> <strong><?php echo esc_html( rtrim( $site_url_host, '/' ) ); ?></strong></li>
64 <li><?php echo wp_kses( __( 'Authorized Redirect URI: <em>none</em>', 'authorizer' ), Helper::$allowed_html ); ?></li>
65 </ul>
66 </li>
67 <li><?php esc_html_e( 'Copy/paste your new Client ID/Secret pair into the fields below.', 'authorizer' ); ?></li>
68 <li><?php echo wp_kses( __( '<strong>Note</strong>: Navigate to <em>APIs and Services</em> &gt; <em>OAuth consent screen</em> to change the way the Google consent screen appears after a user has successfully entered their password, but before they are redirected back to WordPress.', 'authorizer' ), Helper::$allowed_html ); ?></li>
69 <li><?php echo wp_kses( __( 'Note: Google may have a more recent version of these instructions in their <a href="https://developers.google.com/identity/gsi/web" target="_blank">developer documentation</a>.', 'authorizer' ), Helper::$allowed_html ); ?></li>
70 </ol>
71 <?php
72 // If ID is overridden by filter or constant, don't expose the value;
73 // just print an informational message.
74 if ( has_filter( 'authorizer_google_client_id' ) ) {
75 ?>
76 <input type="hidden" id="auth_settings_<?php echo esc_attr( $option ); ?>" name="auth_settings[<?php echo esc_attr( $option ); ?>]" value="" />
77 <p class="description">
78 <?php
79 echo wp_kses_post(
80 sprintf(
81 /* TRANSLATORS: %s: filter name */
82 __( 'This setting is not editable since it has been defined in the %s filter.', 'authorizer' ),
83 '<code>authorizer_google_client_id</code>'
84 )
85 );
86 ?>
87 </p>
88 <?php
89 return;
90 } elseif ( defined( 'AUTHORIZER_GOOGLE_CLIENT_ID' ) ) {
91 ?>
92 <input type="hidden" id="auth_settings_<?php echo esc_attr( $option ); ?>" name="auth_settings[<?php echo esc_attr( $option ); ?>]" value="" />
93 <p class="description">
94 <?php
95 echo wp_kses_post(
96 sprintf(
97 /* TRANSLATORS: %s: defined constant name */
98 __( 'This setting is not editable since it has been defined in wp-config.php via %s', 'authorizer' ),
99 "<code>define( 'AUTHORIZER_GOOGLE_CLIENT_ID', '...' );</code>"
100 )
101 );
102 ?>
103 </p>
104 <?php
105 return;
106 }
107
108 ?>
109 <input type="text" id="auth_settings_<?php echo esc_attr( $option ); ?>" name="auth_settings[<?php echo esc_attr( $option ); ?>]" value="<?php echo esc_attr( $auth_settings_option ); ?>" placeholder="" />
110 <p class="description"><?php esc_html_e( 'Example: 1234567890123-kdjr85yt6vjr6d8g7dhr8g7d6durjf7g.apps.googleusercontent.com', 'authorizer' ); ?></p>
111 <?php
112 }
113
114
115 /**
116 * Settings print callback.
117 *
118 * @param array $args Args (e.g., multisite admin mode).
119 * @return void
120 */
121 public function print_text_google_clientsecret( $args = '' ) {
122 // Get plugin option.
123 $options = Options::get_instance();
124 $option = 'google_clientsecret';
125 $auth_settings_option = $options->get( $option, Helper::get_context( $args ), 'allow override', 'print overlay' );
126
127 // If secret is overridden by filter or constant, don't expose the value;
128 // just print an informational message.
129 if ( has_filter( 'authorizer_google_client_secret' ) ) {
130 ?>
131 <p class="description">
132 <?php
133 echo wp_kses_post(
134 sprintf(
135 /* TRANSLATORS: %s: filter name */
136 __( 'This setting is not editable since it has been defined in the %s filter.', 'authorizer' ),
137 '<code>authorizer_google_client_secret</code>'
138 )
139 );
140 ?>
141 </p>
142 <input type="hidden" id="auth_settings_<?php echo esc_attr( $option ); ?>" name="auth_settings[<?php echo esc_attr( $option ); ?>]" value="" />
143 <?php
144 return;
145 } elseif ( defined( 'AUTHORIZER_GOOGLE_CLIENT_SECRET' ) ) {
146 ?>
147 <p class="description">
148 <?php
149 echo wp_kses_post(
150 sprintf(
151 /* TRANSLATORS: %s: defined constant name */
152 __( 'This setting is not editable since it has been defined in wp-config.php via %s', 'authorizer' ),
153 "<code>define( 'AUTHORIZER_GOOGLE_CLIENT_SECRET', '...' );</code>"
154 )
155 );
156 ?>
157 </p>
158 <input type="hidden" id="auth_settings_<?php echo esc_attr( $option ); ?>" name="auth_settings[<?php echo esc_attr( $option ); ?>]" value="" />
159 <?php
160 return;
161 }
162
163 // Print option elements.
164 ?>
165 <input type="text" id="auth_settings_<?php echo esc_attr( $option ); ?>" name="auth_settings[<?php echo esc_attr( $option ); ?>]" value="<?php echo esc_attr( $auth_settings_option ); ?>" placeholder="" style="width:220px;" />
166 <p class="description"><?php esc_html_e( 'Example: sDNgX5_pr_5bly-frKmvp8jT', 'authorizer' ); ?></p>
167 <?php
168 }
169
170
171 /**
172 * Settings print callback.
173 *
174 * @param array $args Args (e.g., multisite admin mode).
175 * @return void
176 */
177 public function print_text_google_hosteddomain( $args = '' ) {
178 // Get plugin option.
179 $options = Options::get_instance();
180 $option = 'google_hosteddomain';
181 $auth_settings_option = $options->get( $option, Helper::get_context( $args ), 'allow override', 'print overlay' );
182
183 // Print option elements.
184 ?>
185 <textarea id="auth_settings_<?php echo esc_attr( $option ); ?>" name="auth_settings[<?php echo esc_attr( $option ); ?>]" placeholder="" style="width:220px;"><?php echo esc_html( $auth_settings_option ); ?></textarea>
186 <p class="description"><?php esc_html_e( 'Restrict Google logins to a specific Google Apps hosted domain (for example, mycollege.edu). Leave blank to allow all Google sign-ins.', 'authorizer' ); ?> <?php esc_html_e( 'If restricting to multiple domains, add one domain per line.', 'authorizer' ); ?></p>
187 <?php
188 }
189 }
190