Skip to content

Instantly share code, notes, and snippets.

View justingreerbbi's full-sized avatar

Justin Greer justingreerbbi

View GitHub Profile
function wp_oauth_server_debug_backtrace() {
$friendly = array();
$backtrace = debug_backtrace();
foreach ( $backtrace as $file ) {
$friendly[] = array(
'file' => $file['file'],
'function' => $file['function'],
'line' => $file['line']
);
}
@justingreerbbi
justingreerbbi / gist:6b9badadd7024ee90db7879d4a4dad30
Created February 9, 2020 14:12
WordPress OAuth Server Set Access Token Action
do_action( 'wo_set_access_token', array(
'access_token' => $access_token,
'client_id' => $client_id,
'user_id' => $user_id
) );
@justingreerbbi
justingreerbbi / gist:8587d270cab2328bcd45f717b11336f6
Created November 15, 2019 00:55
Check Before Authorizing a User in WordPress OAuth after using Authorization Code Grant Type.
add_action( 'wo_authorization_code_authorize', 'before_authorization_test' );
function before_authorization_test( $user_id ) {
$user_id = $user_id[0];
$authorized = true;
// Do user check and authorize if allowed
// Present error is the user is not authorized
@justingreerbbi
justingreerbbi / gist:d1d7e6af47796a9ff2a647fcc3cc1108
Created November 14, 2019 23:07
User Redirect after login to WordPress REST API
/**
* This can be used in conjuction https://gist.github.com/justingreerbbi/768f1effcca69b4098c9d0f7731deba0
* This code would go on the WP side.
*/
add_action('clear_auth_cookie', 'wp_oaut_server_logout_user_rediect_to_client_rest_api_endpoint');
function wp_oaut_server_logout_user_rediect_to_client_rest_api_endpoint(){
wp_redirect('https://site.com/wp-json/wpoauthserver/v1/logout/');
}
@justingreerbbi
justingreerbbi / gist:4d68b9823b65ed81ca1e627c0c3c35b4
Created October 8, 2019 11:15
Auto SSO with WP OAuth Server and Single Sign On Simple Client
add_filter( 'template_redirect', 'auto_sso_init', 11 );
function auto_sso_init() {
if ( ! is_user_logged_in() ) {
wp_safe_redirect( site_url( '?auth=sso' ) );
exit;
}
}
@justingreerbbi
justingreerbbi / gist:c8281d110588ea63dd39a4c1556868c4
Created August 23, 2019 13:13
Proper Custom Login WordPress Redirect Snippet
function _proper_custom_login_redirect_intercept( $template ) {
if ( ! is_user_logged_in() ) {
wp_safe_redirect( site_url( '/member-login/' ) );
exit;
}
return $template;
}
@justingreerbbi
justingreerbbi / gist:3f60aab604c70d2fc688d642e5d5c704
Created August 22, 2019 11:31
Do Action Hook for WP OAuth Server Client for User Creation or Login.
Plugin: Simple Single Sign On
Plugin File: /includes/callback.php
/*
* Action runs directly after a default user is created
*/
do_action( 'wpoc_user_created', $user_info, 1 );
/*
* Action runs directly before a user is logged in
@justingreerbbi
justingreerbbi / gist:46fa199954a7d15f8072eab43d078112
Last active September 26, 2019 12:29
Custom WordPress OAuth Login Page for WP OAuth Server
/**
* CUSTOM LOGIN REDIRECT
*
* Redirect a user to a custom login page for authentication
*/
add_action( 'wo_before_authorize_method', 'custom_login_redirect' );
function custom_login_redirect() {
if ( ! is_user_logged_in() ) {
wp_redirect( site_url() . '/custom-login?redirect_to=' . urlencode( site_url() . $_SERVER['REQUEST_URI'] ) );
exit;
@justingreerbbi
justingreerbbi / custom login with wp-login block
Last active August 14, 2019 16:56
Block wp-login.php but allow oauth requests to passthrough.
add_action( 'login_init', 'secure_wp_admin' );
function secure_wp_admin() {
/**
* Check if there is an redirect_url parameter during the login page.
*
* If the script has made it this far for WP OAuth Server, there will be redirect URL exposed for the login redirect
* required by WP OAuth Server. We can use this redirect as a flag to check for the path. If "oauth" is present, we
* should assume that the request is an oauth request and should not be redirected.
*/
@justingreerbbi
justingreerbbi / example.php
Created October 8, 2018 14:18
User Wallet Credit System - Modify Order Status when the wallet is used
<?php
/**
* Modifies the order status for orders made with user wallet for WooCommerce
* Prioroty set HIGH for pro since plugin handles this filter and this is a bypass for statuses not yet supported
*/
add_filter('wpuw_update_status', 'v3zzq_example_modify', 1);
function v3zzq_example_modify(){
return 'processing';
}