Skip to content

Instantly share code, notes, and snippets.

View justingreerbbi's full-sized avatar

Justin Greer justingreerbbi

View GitHub Profile
<?php
/**
* Add a new endpoint and functionality to WordPress OAuth Server.
* This snippet would go in your functions file.
*
* Requires that WP OAuth Server installed and activated.
* It can access using a valide access_token.
*
* POST/GET - Return JSON
* /oauth/hello?access_token=1234
@justingreerbbi
justingreerbbi / modify_core_me_resource_endpoint
Created January 20, 2015 02:22
Replaces the default /oauth/me method for WordPress OAuth Server
add_filter('wo_endpoints','wo_extend_resource_api', 2);
function wo_extend_resource_api ($methods)
{
$methods['me'] = array('func'=>'_wo_me');
return $methods;
}
/**
* Replaces the default me enpoint
* @param [type] $token [description]
@justingreerbbi
justingreerbbi / Override redirect_uri validation
Last active August 29, 2015 14:13
Filter to override WordPress OAuth Server redirect validation or handle comparing redirect with custom logic
/**
* Create cutom redirect validation hook
*
* NOTE: Since this is a filter the return should be a true or false but as a string. If 'true' is return the redirect_uri
* validation has passed. This example completely overides the redirect_uri validation.
*
* NOTE: This filter only runs during is a redirect_uri is given in th request
*
* Prioarity: 10
* Number of Args: 2
//
// Simple NSDefaults Wrapper
//
// Created by Justin Greer on 2/27/15.
// Copyright (c) 2015 Justin Greer Interactive, LLC. All rights reserved.
//
import Foundation
class FCStorage {
@justingreerbbi
justingreerbbi / gist:af44a4e9fa3c97d5e073
Created March 20, 2015 18:04
Override Default Me method and replace it will BuddyPress into
<?php
add_filter('wo_endpoints','wo_extend_resource_api', 2);
function wo_extend_resource_api ($methods)
{
$methods['me'] = array('func'=>'_wo_me');
return $methods;
}
/**
* Replaces the default me enpoint
@justingreerbbi
justingreerbbi / Extend Resource API
Created October 2, 2015 00:51
Extend Resource API endpoints
add_filter('wo_endpoints','new_hello_endpoint', 2);
function new_hello_endpoint ($methods){
$methods['hello'] = array(
'func'=>'run_hello_method' // Function name to run
'public' => true|false // True to be public
);
return $methods;
}
function run_hello_method ($token){
@justingreerbbi
justingreerbbi / only one access_token session
Created October 24, 2015 21:53
Only allow 1 access token session per client
/**
* Only allow 1 acces_token at a time
* @param [type] $results [description]
* @return [type] [description]
*/
function test_only_allow_one_access_token ( $object ) {
if ( is_null( $object ) )
return;
// Define the user ID
@justingreerbbi
justingreerbbi / Custom login redirect
Created November 30, 2015 14:41
Custom login redirect is user is not logged in for WP OAuth Server
function wo_before_authorize_function_login_redirect( $request ){
// Check if the user is logged in or not
if(!is_user_logged_in()){
wp_redirect( 'http://your-custom-login.com/login' );
exit;
}
// Else do nothing and let the server handle the request
}
@justingreerbbi
justingreerbbi / Table
Created January 19, 2016 17:16
Table
<table width="100%" border="0" cellpadding="10" cellspacing="0">
<tbody>
<tr bgcolor="#666">
<th width="14%" valign="middle" bgcolor="#666" style="color: #FFF" scope="col">Header</th>
<th width="14%" valign="middle" bgcolor="#666" style="color: #FFF" scope="col">Header</th>
<th width="14%" valign="middle" bgcolor="#666" style="color: #FFF" scope="col">Header</th>
<th width="14%" valign="middle" bgcolor="#666" style="color: #FFF" scope="col">Header</th>
<th width="14%" valign="middle" bgcolor="#666" style="color: #FFF" scope="col">Header</th>
<th width="14%" valign="middle" bgcolor="#666" style="color: #FFF" scope="col">Header</th>
<th width="16%" valign="middle" bgcolor="#666" style="color: #FFF" scope="col">Header</th>
<form action="<?php echo $server_url; ?>/oauth/token" method="POST">
<input type="text" name="refresh_token" value="" />
<input type="hidden" name="grant_type" value="refresh_token" />
<input type="hidden" name="client_id" value="<?php echo $client_id; ?>" />
<input type="hidden" name="client_secret" value="<?php echo $client_secret; ?>" />
<button type="submit">Request New</button>
</form>