PluginProbe
Authorizer / 3.15.2
Authorizer v3.15.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.15.2, at src/authorizer/options/external/class-google.php

193 lines 8.1 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 // Prevent direct access.
16 defined( 'ABSPATH' ) || exit;
17
18 /**
19 * Contains functions for rendering the Google options in the External Service
20 * tab in Authorizer Settings.
21 */
22 class Google extends \Authorizer\Singleton {
23
24 /**
25 * Settings print callback.
26 *
27 * @param array $args Args (e.g., multisite admin mode).
28 * @return void
29 */
30 public function print_checkbox_auth_external_google( $args = '' ) {
31 // Get plugin option.
32 $options = Options::get_instance();
33 $option = 'google';
34 $auth_settings_option = $options->get( $option, Helper::get_context( $args ), 'allow override', 'print overlay' );
35
36 // Print option elements.
37 ?>
38 <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>
39 <?php
40 }
41
42
43 /**
44 * Settings print callback.
45 *
46 * @param array $args Args (e.g., multisite admin mode).
47 * @return void
48 */
49 public function print_text_google_clientid( $args = '' ) {
50 // Get plugin option.
51 $options = Options::get_instance();
52 $option = 'google_clientid';
53 $auth_settings_option = $options->get( $option, Helper::get_context( $args ), 'allow override', 'print overlay' );
54
55 // Print option elements.
56 $site_url_parts = wp_parse_url( get_site_url() );
57 $site_url_host = $site_url_parts['scheme'] . '://' . $site_url_parts['host'] . '/';
58
59 esc_html_e( "If you don't have a Google Client ID and Secret, generate them by following these instructions:", 'authorizer' );
60 ?>
61 <ol>
62 <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>
63 <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 ); ?>
64 <ul>
65 <li><?php echo wp_kses( __( 'Application Type: <strong>Web application</strong>', 'authorizer' ), Helper::$allowed_html ); ?></li>
66 <li><?php esc_html_e( 'Authorized Javascript Origins:', 'authorizer' ); ?> <strong><?php echo esc_html( rtrim( $site_url_host, '/' ) ); ?></strong></li>
67 <li><?php echo wp_kses( __( 'Authorized Redirect URI: <em>none</em>', 'authorizer' ), Helper::$allowed_html ); ?></li>
68 </ul>
69 </li>
70 <li><?php esc_html_e( 'Copy/paste your new Client ID/Secret pair into the fields below.', 'authorizer' ); ?></li>
71 <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>
72 <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>
73 </ol>
74 <?php
75 // If ID is overridden by filter or constant, don't expose the value;
76 // just print an informational message.
77 if ( has_filter( 'authorizer_google_client_id' ) ) {
78 ?>
79 <input type="hidden" id="auth_settings_<?php echo esc_attr( $option ); ?>" name="auth_settings[<?php echo esc_attr( $option ); ?>]" value="" />
80 <p class="description">
81 <?php
82 echo wp_kses_post(
83 sprintf(
84 /* TRANSLATORS: %s: filter name */
85 __( 'This setting is not editable since it has been defined in the %s filter.', 'authorizer' ),
86 '<code>authorizer_google_client_id</code>'
87 )
88 );
89 ?>
90 </p>
91 <?php
92 return;
93 } elseif ( defined( 'AUTHORIZER_GOOGLE_CLIENT_ID' ) ) {
94 ?>
95 <input type="hidden" id="auth_settings_<?php echo esc_attr( $option ); ?>" name="auth_settings[<?php echo esc_attr( $option ); ?>]" value="" />
96 <p class="description">
97 <?php
98 echo wp_kses_post(
99 sprintf(
100 /* TRANSLATORS: %s: defined constant name */
101 __( 'This setting is not editable since it has been defined in wp-config.php via %s', 'authorizer' ),
102 "<code>define( 'AUTHORIZER_GOOGLE_CLIENT_ID', '...' );</code>"
103 )
104 );
105 ?>
106 </p>
107 <?php
108 return;
109 }
110
111 ?>
112 <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="" />
113 <p class="description"><?php esc_html_e( 'Example: 1234567890123-kdjr85yt6vjr6d8g7dhr8g7d6durjf7g.apps.googleusercontent.com', 'authorizer' ); ?></p>
114 <?php
115 }
116
117
118 /**
119 * Settings print callback.
120 *
121 * @param array $args Args (e.g., multisite admin mode).
122 * @return void
123 */
124 public function print_text_google_clientsecret( $args = '' ) {
125 // Get plugin option.
126 $options = Options::get_instance();
127 $option = 'google_clientsecret';
128 $auth_settings_option = $options->get( $option, Helper::get_context( $args ), 'allow override', 'print overlay' );
129
130 // If secret is overridden by filter or constant, don't expose the value;
131 // just print an informational message.
132 if ( has_filter( 'authorizer_google_client_secret' ) ) {
133 ?>
134 <p class="description">
135 <?php
136 echo wp_kses_post(
137 sprintf(
138 /* TRANSLATORS: %s: filter name */
139 __( 'This setting is not editable since it has been defined in the %s filter.', 'authorizer' ),
140 '<code>authorizer_google_client_secret</code>'
141 )
142 );
143 ?>
144 </p>
145 <input type="hidden" id="auth_settings_<?php echo esc_attr( $option ); ?>" name="auth_settings[<?php echo esc_attr( $option ); ?>]" value="" />
146 <?php
147 return;
148 } elseif ( defined( 'AUTHORIZER_GOOGLE_CLIENT_SECRET' ) ) {
149 ?>
150 <p class="description">
151 <?php
152 echo wp_kses_post(
153 sprintf(
154 /* TRANSLATORS: %s: defined constant name */
155 __( 'This setting is not editable since it has been defined in wp-config.php via %s', 'authorizer' ),
156 "<code>define( 'AUTHORIZER_GOOGLE_CLIENT_SECRET', '...' );</code>"
157 )
158 );
159 ?>
160 </p>
161 <input type="hidden" id="auth_settings_<?php echo esc_attr( $option ); ?>" name="auth_settings[<?php echo esc_attr( $option ); ?>]" value="" />
162 <?php
163 return;
164 }
165
166 // Print option elements.
167 ?>
168 <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;" />
169 <p class="description"><?php esc_html_e( 'Example: sDNgX5_pr_5bly-frKmvp8jT', 'authorizer' ); ?></p>
170 <?php
171 }
172
173
174 /**
175 * Settings print callback.
176 *
177 * @param array $args Args (e.g., multisite admin mode).
178 * @return void
179 */
180 public function print_text_google_hosteddomain( $args = '' ) {
181 // Get plugin option.
182 $options = Options::get_instance();
183 $option = 'google_hosteddomain';
184 $auth_settings_option = $options->get( $option, Helper::get_context( $args ), 'allow override', 'print overlay' );
185
186 // Print option elements.
187 ?>
188 <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>
189 <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>
190 <?php
191 }
192 }
193