removing trailing whitespace

isekai
Jonathan Daggerhart 5 years ago
parent a0dfa7723d
commit bf2e517a89

@ -1,12 +1,12 @@
<?php <?php
class OpenID_Connect_Generic_Client_Wrapper { class OpenID_Connect_Generic_Client_Wrapper {
private $client; private $client;
// settings object // settings object
private $settings; private $settings;
// logger object // logger object
private $logger; private $logger;
@ -19,10 +19,9 @@ class OpenID_Connect_Generic_Client_Wrapper {
// WP_Error if there was a problem, or false if no error // WP_Error if there was a problem, or false if no error
private $error = false; private $error = false;
/** /**
* Inject necessary objects and services into the client * Inject necessary objects and services into the client
* *
* @param \OpenID_Connect_Generic_Client $client * @param \OpenID_Connect_Generic_Client $client
* @param \OpenID_Connect_Generic_Option_Settings $settings * @param \OpenID_Connect_Generic_Option_Settings $settings
* @param \OpenID_Connect_Generic_Option_Logger $logger * @param \OpenID_Connect_Generic_Option_Logger $logger
@ -44,7 +43,7 @@ class OpenID_Connect_Generic_Client_Wrapper {
*/ */
static public function register( OpenID_Connect_Generic_Client $client, OpenID_Connect_Generic_Option_Settings $settings, OpenID_Connect_Generic_Option_Logger $logger ){ static public function register( OpenID_Connect_Generic_Client $client, OpenID_Connect_Generic_Option_Settings $settings, OpenID_Connect_Generic_Option_Logger $logger ){
$client_wrapper = new self( $client, $settings, $logger ); $client_wrapper = new self( $client, $settings, $logger );
// integrated logout // integrated logout
if ( $settings->endpoint_end_session ) { if ( $settings->endpoint_end_session ) {
add_filter( 'allowed_redirect_hosts', array( $client_wrapper, 'update_allowed_redirect_hosts' ), 99, 1 ); add_filter( 'allowed_redirect_hosts', array( $client_wrapper, 'update_allowed_redirect_hosts' ), 99, 1 );
@ -72,13 +71,13 @@ class OpenID_Connect_Generic_Client_Wrapper {
if ( is_user_logged_in() ) { if ( is_user_logged_in() ) {
add_action( 'wp_loaded', array($client_wrapper, 'ensure_tokens_still_fresh')); add_action( 'wp_loaded', array($client_wrapper, 'ensure_tokens_still_fresh'));
} }
return $client_wrapper; return $client_wrapper;
} }
/** /**
* Implements WP action - parse_request * Implements WP action - parse_request
* *
* @param $query * @param $query
* *
* @return mixed * @return mixed
@ -96,7 +95,7 @@ class OpenID_Connect_Generic_Client_Wrapper {
/** /**
* Get the authentication url from the client * Get the authentication url from the client
* *
* @return string * @return string
*/ */
function get_authentication_url(){ function get_authentication_url(){
@ -144,7 +143,7 @@ class OpenID_Connect_Generic_Client_Wrapper {
} }
$token_result = $this->client->request_new_tokens( $refresh_token ); $token_result = $this->client->request_new_tokens( $refresh_token );
if ( is_wp_error( $token_result ) ) { if ( is_wp_error( $token_result ) ) {
wp_logout(); wp_logout();
$this->error_redirect( $token_result ); $this->error_redirect( $token_result );
@ -168,10 +167,10 @@ class OpenID_Connect_Generic_Client_Wrapper {
*/ */
function error_redirect( $error ) { function error_redirect( $error ) {
$this->logger->log( $error ); $this->logger->log( $error );
// redirect user back to login page // redirect user back to login page
wp_redirect( wp_redirect(
wp_login_url() . wp_login_url() .
'?login-error=' . $error->get_error_code() . '?login-error=' . $error->get_error_code() .
'&message=' . urlencode( $error->get_error_message() ) '&message=' . urlencode( $error->get_error_message() )
); );
@ -186,7 +185,7 @@ class OpenID_Connect_Generic_Client_Wrapper {
function get_error(){ function get_error(){
return $this->error; return $this->error;
} }
/** /**
* Add the end_session endpoint to WP core's whitelist of redirect hosts * Add the end_session endpoint to WP core's whitelist of redirect hosts
* *
@ -266,31 +265,31 @@ class OpenID_Connect_Generic_Client_Wrapper {
return $request; return $request;
} }
/** /**
* Control the authentication and subsequent authorization of the user when * Control the authentication and subsequent authorization of the user when
* returning from the IDP. * returning from the IDP.
*/ */
function authentication_request_callback() { function authentication_request_callback() {
$client = $this->client; $client = $this->client;
// start the authentication flow // start the authentication flow
$authentication_request = $client->validate_authentication_request( $_GET ); $authentication_request = $client->validate_authentication_request( $_GET );
if ( is_wp_error( $authentication_request ) ){ if ( is_wp_error( $authentication_request ) ){
$this->error_redirect( $authentication_request ); $this->error_redirect( $authentication_request );
} }
// retrieve the authentication code from the authentication request // retrieve the authentication code from the authentication request
$code = $client->get_authentication_code( $authentication_request ); $code = $client->get_authentication_code( $authentication_request );
if ( is_wp_error( $code ) ){ if ( is_wp_error( $code ) ){
$this->error_redirect( $code ); $this->error_redirect( $code );
} }
// attempting to exchange an authorization code for an authentication token // attempting to exchange an authorization code for an authentication token
$token_result = $client->request_authentication_token( $code ); $token_result = $client->request_authentication_token( $code );
if ( is_wp_error( $token_result ) ) { if ( is_wp_error( $token_result ) ) {
$this->error_redirect( $token_result ); $this->error_redirect( $token_result );
} }
@ -307,7 +306,7 @@ class OpenID_Connect_Generic_Client_Wrapper {
// ensure the that response contains required information // ensure the that response contains required information
$valid = $client->validate_token_response( $token_response ); $valid = $client->validate_token_response( $token_response );
if ( is_wp_error( $valid ) ) { if ( is_wp_error( $valid ) ) {
$this->error_redirect( $valid ); $this->error_redirect( $valid );
} }
@ -328,28 +327,28 @@ class OpenID_Connect_Generic_Client_Wrapper {
if ( is_wp_error( $id_token_claim ) ){ if ( is_wp_error( $id_token_claim ) ){
$this->error_redirect( $id_token_claim ); $this->error_redirect( $id_token_claim );
} }
// validate our id_token has required values // validate our id_token has required values
$valid = $client->validate_id_token_claim( $id_token_claim ); $valid = $client->validate_id_token_claim( $id_token_claim );
if ( is_wp_error( $valid ) ){ if ( is_wp_error( $valid ) ){
$this->error_redirect( $valid ); $this->error_redirect( $valid );
} }
// if userinfo endpoint is set, exchange the token_response for a user_claim // if userinfo endpoint is set, exchange the token_response for a user_claim
if ( !empty( $this->settings->endpoint_userinfo ) && isset( $token_response['access_token'] )) { if ( !empty( $this->settings->endpoint_userinfo ) && isset( $token_response['access_token'] )) {
$user_claim = $client->get_user_claim( $token_response ); $user_claim = $client->get_user_claim( $token_response );
} else { } else {
$user_claim = $id_token_claim; $user_claim = $id_token_claim;
} }
if ( is_wp_error( $user_claim ) ){ if ( is_wp_error( $user_claim ) ){
$this->error_redirect( $user_claim ); $this->error_redirect( $user_claim );
} }
// validate our user_claim has required values // validate our user_claim has required values
$valid = $client->validate_user_claim( $user_claim, $id_token_claim ); $valid = $client->validate_user_claim( $user_claim, $id_token_claim );
if ( is_wp_error( $valid ) ){ if ( is_wp_error( $valid ) ){
$this->error_redirect( $valid ); $this->error_redirect( $valid );
} }
@ -380,7 +379,7 @@ class OpenID_Connect_Generic_Client_Wrapper {
// validate the found / created user // validate the found / created user
$valid = $this->validate_user( $user ); $valid = $this->validate_user( $user );
if ( is_wp_error( $valid ) ){ if ( is_wp_error( $valid ) ){
$this->error_redirect( $valid ); $this->error_redirect( $valid );
} }
@ -405,13 +404,13 @@ class OpenID_Connect_Generic_Client_Wrapper {
else { else {
wp_redirect( home_url() ); wp_redirect( home_url() );
} }
exit; exit;
} }
/** /**
* Validate the potential WP_User * Validate the potential WP_User
* *
* @param $user * @param $user
* *
* @return true|\WP_Error * @return true|\WP_Error
@ -421,13 +420,13 @@ class OpenID_Connect_Generic_Client_Wrapper {
if ( ! is_a( $user, 'WP_User' ) || ! $user->exists() ) { if ( ! is_a( $user, 'WP_User' ) || ! $user->exists() ) {
return new WP_Error( 'invalid-user', __( 'Invalid user' ), $user ); return new WP_Error( 'invalid-user', __( 'Invalid user' ), $user );
} }
return true; return true;
} }
/** /**
* Record user meta data, and provide an authorization cookie * Record user meta data, and provide an authorization cookie
* *
* @param $user * @param $user
*/ */
function login_user( $user, $token_response, $id_token_claim, $user_claim, $subject_identity ){ function login_user( $user, $token_response, $id_token_claim, $user_claim, $subject_identity ){
@ -478,8 +477,8 @@ class OpenID_Connect_Generic_Client_Wrapper {
} }
/** /**
* Get the user that has meta data matching a * Get the user that has meta data matching a
* *
* @param $subject_identity * @param $subject_identity
* *
* @return false|\WP_User * @return false|\WP_User
@ -500,7 +499,7 @@ class OpenID_Connect_Generic_Client_Wrapper {
$users = $user_query->get_results(); $users = $user_query->get_results();
return $users[0]; return $users[0];
} }
return false; return false;
} }
@ -592,7 +591,7 @@ class OpenID_Connect_Generic_Client_Wrapper {
$string .= substr( $format, $i, $match[ 1 ] - $i ); $string .= substr( $format, $i, $match[ 1 ] - $i );
if ( ! isset( $user_claim[ $key ] ) ) { if ( ! isset( $user_claim[ $key ] ) ) {
if ( $error_on_missing_key ) { if ( $error_on_missing_key ) {
return new WP_Error( 'incomplete-user-claim', __( 'User claim incomplete' ), return new WP_Error( 'incomplete-user-claim', __( 'User claim incomplete' ),
array('message'=>'Unable to find key: '.$key.' in user_claim', array('message'=>'Unable to find key: '.$key.' in user_claim',
'hint'=>'Verify OpenID Scope includes a scope with the attributes you need', 'hint'=>'Verify OpenID Scope includes a scope with the attributes you need',
'user_claim'=>$user_claim, 'user_claim'=>$user_claim,
@ -638,7 +637,7 @@ class OpenID_Connect_Generic_Client_Wrapper {
/** /**
* Create a new user from details in a user_claim * Create a new user from details in a user_claim
* *
* @param $subject_identity * @param $subject_identity
* @param $user_claim * @param $user_claim
* *
@ -738,14 +737,14 @@ class OpenID_Connect_Generic_Client_Wrapper {
} }
} }
// allow other plugins / themes to determine authorization // allow other plugins / themes to determine authorization
// of new accounts based on the returned user claim // of new accounts based on the returned user claim
$create_user = apply_filters( 'openid-connect-generic-user-creation-test', true, $user_claim ); $create_user = apply_filters( 'openid-connect-generic-user-creation-test', true, $user_claim );
if ( ! $create_user ) { if ( ! $create_user ) {
return new WP_Error( 'cannot-authorize', __( 'Can not authorize.' ), $create_user ); return new WP_Error( 'cannot-authorize', __( 'Can not authorize.' ), $create_user );
} }
$user_data = array( $user_data = array(
'user_login' => $username, 'user_login' => $username,
'user_pass' => wp_generate_password( 32, true, true ), 'user_pass' => wp_generate_password( 32, true, true ),
@ -776,26 +775,25 @@ class OpenID_Connect_Generic_Client_Wrapper {
// allow plugins / themes to take action on new user creation // allow plugins / themes to take action on new user creation
do_action( 'openid-connect-generic-user-create', $user, $user_claim ); do_action( 'openid-connect-generic-user-create', $user, $user_claim );
return $user; return $user;
} }
/** /**
* Update an existing user with OpenID Connect meta data * Update an existing user with OpenID Connect meta data
* *
* @param $uid * @param $uid
* @param $subject_identity * @param $subject_identity
* *
* @return \WP_Error | \WP_User * @return \WP_Error | \WP_User
*/ */
function update_existing_user( $uid, $subject_identity ) { function update_existing_user( $uid, $subject_identity ) {
// add the OpenID Connect meta data // add the OpenID Connect meta data
update_user_meta( $uid, 'openid-connect-generic-subject-identity', (string) $subject_identity ); update_user_meta( $uid, 'openid-connect-generic-subject-identity', (string) $subject_identity );
// allow plugins / themes to take action on user update // allow plugins / themes to take action on user update
do_action( 'openid-connect-generic-user-update', $uid ); do_action( 'openid-connect-generic-user-update', $uid );
// return our updated user // return our updated user
return get_user_by( 'id', $uid ); return get_user_by( 'id', $uid );
} }

@ -67,9 +67,9 @@ class OpenID_Connect_Generic_Client {
/** /**
* Validate the request for login authentication * Validate the request for login authentication
* *
* @param $request * @param $request
* *
* @return array|\WP_Error * @return array|\WP_Error
*/ */
function validate_authentication_request( $request ){ function validate_authentication_request( $request ){
@ -111,7 +111,7 @@ class OpenID_Connect_Generic_Client {
* Using the authorization_code, request an authentication token from the idp * Using the authorization_code, request an authentication token from the idp
* *
* @param $code - authorization_code * @param $code - authorization_code
* *
* @return array|\WP_Error * @return array|\WP_Error
*/ */
function request_authentication_token( $code ) { function request_authentication_token( $code ) {
@ -142,7 +142,7 @@ class OpenID_Connect_Generic_Client {
if ( is_wp_error( $response ) ){ if ( is_wp_error( $response ) ){
$response->add( 'request_authentication_token' , __( 'Request for authentication token failed.' ) ); $response->add( 'request_authentication_token' , __( 'Request for authentication token failed.' ) );
} }
return $response; return $response;
} }
@ -203,12 +203,12 @@ class OpenID_Connect_Generic_Client {
return $token_response; return $token_response;
} }
/** /**
* Exchange an access_token for a user_claim from the userinfo endpoint * Exchange an access_token for a user_claim from the userinfo endpoint
* *
* @param $access_token * @param $access_token
* *
* @return array|\WP_Error * @return array|\WP_Error
*/ */
function request_userinfo( $access_token ) { function request_userinfo( $access_token ) {
@ -240,7 +240,7 @@ class OpenID_Connect_Generic_Client {
if ( is_wp_error( $response ) ){ if ( is_wp_error( $response ) ){
$response->add( 'request_userinfo' , __( 'Request for userinfo failed.' ) ); $response->add( 'request_userinfo' , __( 'Request for userinfo failed.' ) );
} }
return $response; return $response;
} }
@ -293,18 +293,18 @@ class OpenID_Connect_Generic_Client {
function validate_token_response( $token_response ){ function validate_token_response( $token_response ){
// we need to ensure 2 specific items exist with the token response in order // we need to ensure 2 specific items exist with the token response in order
// to proceed with confidence: id_token and token_type == 'Bearer' // to proceed with confidence: id_token and token_type == 'Bearer'
if ( ! isset( $token_response['id_token'] ) || if ( ! isset( $token_response['id_token'] ) ||
! isset( $token_response['token_type'] ) || strcasecmp( $token_response['token_type'], 'Bearer' ) ! isset( $token_response['token_type'] ) || strcasecmp( $token_response['token_type'], 'Bearer' )
) { ) {
return new WP_Error( 'invalid-token-response', 'Invalid token response', $token_response ); return new WP_Error( 'invalid-token-response', 'Invalid token response', $token_response );
} }
return true; return true;
} }
/** /**
* Extract the id_token_claim from the token_response * Extract the id_token_claim from the token_response
* *
* @param $token_response * @param $token_response
* *
* @return array|\WP_Error * @return array|\WP_Error
@ -333,13 +333,13 @@ class OpenID_Connect_Generic_Client {
) )
, true , true
); );
return $id_token_claim; return $id_token_claim;
} }
/** /**
* Ensure the id_token_claim contains the required values * Ensure the id_token_claim contains the required values
* *
* @param $id_token_claim * @param $id_token_claim
* *
* @return bool|\WP_Error * @return bool|\WP_Error
@ -348,20 +348,20 @@ class OpenID_Connect_Generic_Client {
if ( ! is_array( $id_token_claim ) ) { if ( ! is_array( $id_token_claim ) ) {
return new WP_Error( 'bad-id-token-claim', __( 'Bad ID token claim' ), $id_token_claim ); return new WP_Error( 'bad-id-token-claim', __( 'Bad ID token claim' ), $id_token_claim );
} }
// make sure we can find our identification data and that it has a value // make sure we can find our identification data and that it has a value
if ( ! isset( $id_token_claim['sub'] ) || empty( $id_token_claim['sub'] ) ) { if ( ! isset( $id_token_claim['sub'] ) || empty( $id_token_claim['sub'] ) ) {
return new WP_Error( 'no-subject-identity', __( 'No subject identity' ), $id_token_claim ); return new WP_Error( 'no-subject-identity', __( 'No subject identity' ), $id_token_claim );
} }
return true; return true;
} }
/** /**
* Attempt to exchange the access_token for a user_claim * Attempt to exchange the access_token for a user_claim
* *
* @param $token_response * @param $token_response
* *
* @return array|mixed|object|\WP_Error * @return array|mixed|object|\WP_Error
*/ */
function get_user_claim( $token_response ){ function get_user_claim( $token_response ){
@ -377,11 +377,11 @@ class OpenID_Connect_Generic_Client {
return $user_claim; return $user_claim;
} }
/** /**
* Make sure the user_claim has all required values, and that the subject * Make sure the user_claim has all required values, and that the subject
* identity matches of the id_token matches that of the user_claim. * identity matches of the id_token matches that of the user_claim.
* *
* @param $user_claim * @param $user_claim
* @param $id_token_claim * @param $id_token_claim
* *
@ -409,17 +409,17 @@ class OpenID_Connect_Generic_Client {
// allow for other plugins to alter the login success // allow for other plugins to alter the login success
$login_user = apply_filters( 'openid-connect-generic-user-login-test', true, $user_claim ); $login_user = apply_filters( 'openid-connect-generic-user-login-test', true, $user_claim );
if ( ! $login_user ) { if ( ! $login_user ) {
return new WP_Error( 'unauthorized', __( 'Unauthorized access' ), $login_user ); return new WP_Error( 'unauthorized', __( 'Unauthorized access' ), $login_user );
} }
return true; return true;
} }
/** /**
* Retrieve the subject identity from the id_token * Retrieve the subject identity from the id_token
* *
* @param $id_token_claim array * @param $id_token_claim array
* *
* @return mixed * @return mixed

@ -3,25 +3,25 @@
* Simple class for logging messages to the options table * Simple class for logging messages to the options table
*/ */
class OpenID_Connect_Generic_Option_Logger { class OpenID_Connect_Generic_Option_Logger {
// wp option name/key // wp option name/key
private $option_name; private $option_name;
// default message type // default message type
private $default_message_type; private $default_message_type;
// the number of items to keep in the log // the number of items to keep in the log
private $log_limit; private $log_limit;
// whether or not the // whether or not the
private $logging_enabled; private $logging_enabled;
// internal cache of logs // internal cache of logs
private $logs; private $logs;
/** /**
* Setup the logger according to the needs of the instance * Setup the logger according to the needs of the instance
* *
* @param string $option_name * @param string $option_name
* @param string $default_message_type * @param string $default_message_type
* @param bool|TRUE $logging_enabled * @param bool|TRUE $logging_enabled
@ -36,7 +36,7 @@ class OpenID_Connect_Generic_Option_Logger {
/** /**
* Subscribe logger to a set of filters * Subscribe logger to a set of filters
* *
* @param $filter_names * @param $filter_names
* @param int $priority * @param int $priority
*/ */
@ -44,7 +44,7 @@ class OpenID_Connect_Generic_Option_Logger {
if ( ! is_array( $filter_names ) ) { if ( ! is_array( $filter_names ) ) {
$filter_names = array( $filter_names ); $filter_names = array( $filter_names );
} }
foreach ( $filter_names as $filter ){ foreach ( $filter_names as $filter ){
add_filter( $filter, array( $this, 'log_hook' ), $priority ); add_filter( $filter, array( $this, 'log_hook' ), $priority );
} }
@ -52,7 +52,7 @@ class OpenID_Connect_Generic_Option_Logger {
/** /**
* Subscribe logger to a set of actions * Subscribe logger to a set of actions
* *
* @param $action_names * @param $action_names
* @param $priority * @param $priority
*/ */
@ -67,8 +67,8 @@ class OpenID_Connect_Generic_Option_Logger {
} }
/** /**
* Log the data * Log the data
* *
* @param null $arg1 * @param null $arg1
* @return null * @return null
*/ */
@ -76,10 +76,10 @@ class OpenID_Connect_Generic_Option_Logger {
$this->log( func_get_args(), current_filter() ); $this->log( func_get_args(), current_filter() );
return $arg1; return $arg1;
} }
/** /**
* Save an array of data to the logs * Save an array of data to the logs
* *
* @param $data mixed * @param $data mixed
* @return bool * @return bool
*/ */
@ -90,13 +90,13 @@ class OpenID_Connect_Generic_Option_Logger {
$logs = $this->upkeep_logs( $logs ); $logs = $this->upkeep_logs( $logs );
return $this->save_logs( $logs ); return $this->save_logs( $logs );
} }
return false; return false;
} }
/** /**
* Retrieve all log messages * Retrieve all log messages
* *
* @return array * @return array
*/ */
public function get_logs() { public function get_logs() {
@ -109,7 +109,7 @@ class OpenID_Connect_Generic_Option_Logger {
/** /**
* Get the name of the option where this log is stored * Get the name of the option where this log is stored
* *
* @return string * @return string
*/ */
public function get_option_name(){ public function get_option_name(){
@ -128,7 +128,7 @@ class OpenID_Connect_Generic_Option_Logger {
// determine the type of message // determine the type of message
if ( empty( $type ) ) { if ( empty( $type ) ) {
$this->default_message_type; $this->default_message_type;
if ( is_array( $data ) && isset( $data['type'] ) ){ if ( is_array( $data ) && isset( $data['type'] ) ){
$type = $data['type']; $type = $data['type'];
} }
@ -148,7 +148,7 @@ class OpenID_Connect_Generic_Option_Logger {
return $message; return $message;
} }
/** /**
* Keep our log count under the limit * Keep our log count under the limit
* *
@ -161,14 +161,14 @@ class OpenID_Connect_Generic_Option_Logger {
if ( $items_to_remove > 0 ){ if ( $items_to_remove > 0 ){
// keep only the last $log_limit messages from the end // keep only the last $log_limit messages from the end
$logs = array_slice( $logs, ( $items_to_remove * -1) ); $logs = array_slice( $logs, ( $items_to_remove * -1) );
} }
return $logs; return $logs;
} }
/** /**
* Save the log messages * Save the log messages
* *
* @param $logs * @param $logs
* @return bool * @return bool
*/ */
@ -187,7 +187,7 @@ class OpenID_Connect_Generic_Option_Logger {
/** /**
* Get a simple html table of all the logs * Get a simple html table of all the logs
* *
* @param array $logs * @param array $logs
* @return string * @return string
*/ */
@ -196,9 +196,9 @@ class OpenID_Connect_Generic_Option_Logger {
$logs = $this->get_logs(); $logs = $this->get_logs();
} }
$logs = array_reverse( $logs ); $logs = array_reverse( $logs );
ini_set( 'xdebug.var_display_max_depth', -1 ); ini_set( 'xdebug.var_display_max_depth', -1 );
ob_start(); ob_start();
?> ?>
<style type="text/css"> <style type="text/css">
@ -232,7 +232,7 @@ class OpenID_Connect_Generic_Option_Logger {
<?php print $log['uri']; ?> <?php print $log['uri']; ?>
</div> </div>
</td> </td>
<td class="col-data"><pre><?php var_dump( $log['data'] ); ?></pre></td> <td class="col-data"><pre><?php var_dump( $log['data'] ); ?></pre></td>
</tr> </tr>
<?php } ?> <?php } ?>
@ -240,7 +240,7 @@ class OpenID_Connect_Generic_Option_Logger {
</table> </table>
<?php <?php
$output = ob_get_clean(); $output = ob_get_clean();
return $output; return $output;
} }
} }

@ -3,13 +3,13 @@
* Class OpenId_Connect_Generic_Option_Settings * Class OpenId_Connect_Generic_Option_Settings
*/ */
class OpenID_Connect_Generic_Option_Settings { class OpenID_Connect_Generic_Option_Settings {
// wp option name/key // wp option name/key
private $option_name; private $option_name;
// stored option values array // stored option values array
private $values; private $values;
// default plugin settings values // default plugin settings values
private $default_settings; private $default_settings;
@ -22,38 +22,38 @@ class OpenID_Connect_Generic_Option_Settings {
$this->option_name = $option_name; $this->option_name = $option_name;
$this->default_settings = $default_settings; $this->default_settings = $default_settings;
$this->values = get_option( $this->option_name, $this->default_settings ); $this->values = get_option( $this->option_name, $this->default_settings );
if ( $granular_defaults ) { if ( $granular_defaults ) {
$this->values = array_replace_recursive( $this->default_settings, $this->values ); $this->values = array_replace_recursive( $this->default_settings, $this->values );
} }
} }
function __get( $key ){ function __get( $key ){
if ( isset( $this->values[ $key ] ) ) { if ( isset( $this->values[ $key ] ) ) {
return $this->values[ $key ]; return $this->values[ $key ];
} }
} }
function __set( $key, $value ){ function __set( $key, $value ){
$this->values[ $key ] = $value; $this->values[ $key ] = $value;
} }
function __isset( $key ){ function __isset( $key ){
return isset( $this->values[ $key ] ); return isset( $this->values[ $key ] );
} }
function __unset( $key ){ function __unset( $key ){
unset( $this->values[ $key ]); unset( $this->values[ $key ]);
} }
function get_values(){ function get_values(){
return $this->values; return $this->values;
} }
function get_option_name() { function get_option_name() {
return $this->option_name; return $this->option_name;
} }
function save(){ function save(){
update_option( $this->option_name, $this->values ); update_option( $this->option_name, $this->values );
} }

@ -27,10 +27,10 @@ class OpenID_Connect_Generic_Settings_Page {
$this->settings = $settings; $this->settings = $settings;
$this->logger = $logger; $this->logger = $logger;
$this->settings_field_group = $this->settings->get_option_name() . '-group'; $this->settings_field_group = $this->settings->get_option_name() . '-group';
/* /*
* Simple settings fields simply have: * Simple settings fields simply have:
* *
* - title * - title
* - description * - description
* - type ( checkbox | text | select ) * - type ( checkbox | text | select )
@ -225,7 +225,7 @@ class OpenID_Connect_Generic_Settings_Page {
// register our settings // register our settings
add_action( 'admin_init', array( $settings_page, 'admin_init' ) ); add_action( 'admin_init', array( $settings_page, 'admin_init' ) );
return $settings_page; return $settings_page;
} }
@ -262,7 +262,7 @@ class OpenID_Connect_Generic_Settings_Page {
array( $this, 'user_settings_description' ), array( $this, 'user_settings_description' ),
$this->options_page_name $this->options_page_name
); );
add_settings_section( 'authorization_settings', add_settings_section( 'authorization_settings',
__( 'Authorization Settings' ), __( 'Authorization Settings' ),
array( $this, 'authorization_settings_description' ), array( $this, 'authorization_settings_description' ),
@ -322,7 +322,7 @@ class OpenID_Connect_Generic_Settings_Page {
foreach ( $this->settings_fields as $key => $field ) { foreach ( $this->settings_fields as $key => $field ) {
if ( isset( $input[ $key ] ) ) { if ( isset( $input[ $key ] ) ) {
$options[ $key ] = sanitize_text_field( trim( $input[ $key ] ) ); $options[ $key ] = sanitize_text_field( trim( $input[ $key ] ) );
} }
else { else {
$options[ $key ] = ''; $options[ $key ] = '';
} }
@ -349,7 +349,7 @@ class OpenID_Connect_Generic_Settings_Page {
settings_fields( $this->settings_field_group ); settings_fields( $this->settings_field_group );
do_settings_sections( $this->options_page_name ); do_settings_sections( $this->options_page_name );
submit_button(); submit_button();
// simple debug to view settings array // simple debug to view settings array
if ( isset( $_GET['debug'] ) ) { if ( isset( $_GET['debug'] ) ) {
var_dump( $this->settings->get_values() ); var_dump( $this->settings->get_values() );
@ -452,11 +452,11 @@ class OpenID_Connect_Generic_Settings_Page {
public function client_settings_description() { public function client_settings_description() {
_e( 'Enter your OpenID Connect identity provider settings' ); _e( 'Enter your OpenID Connect identity provider settings' );
} }
public function user_settings_description() { public function user_settings_description() {
_e( 'Modify the interaction between OpenID Connect and WordPress users' ); _e( 'Modify the interaction between OpenID Connect and WordPress users' );
} }
public function authorization_settings_description() { public function authorization_settings_description() {
_e( 'Control the authorization mechanics of the site' ); _e( 'Control the authorization mechanics of the site' );
} }

Loading…
Cancel
Save