Skip to content

Instantly share code, notes, and snippets.

View justingreerbbi's full-sized avatar

Justin Greer justingreerbbi

  • Justin Greer Interactive, LLC
  • Barberton, Ohio
  • X @uscommsnerd
View GitHub Profile
@justingreerbbi
justingreerbbi / gist:915f0446af20c954a30044869ab312dd
Created June 29, 2017 13:46
Fixing - Access Control Allow Origin issues with WordPress, WP OAuth Server or WP REST API.
add_action('init', 'set_allow_origins_header');
function set_allow_origins_header(){
// You can change the origin domain by removing * and replacing it with a valid domain.
header( 'Access-Control-Allow-Origin: *' );
}
@justingreerbbi
justingreerbbi / gist:0bc4ef57ca5ee60d2b7057a570fbf224
Created June 21, 2017 16:30 — forked from nghuuphuoc/gist:8282411
Install wkhtmltopdf on Centos 6 x64
$ wget http://wkhtmltopdf.googlecode.com/files/wkhtmltopdf-0.9.9-static-amd64.tar.bz2
$ tar xvjf wkhtmltopdf-0.9.9-static-amd64.tar.bz2
$ mv wkhtmltopdf-amd64 /usr/bin/wkhtmltopdf
// In case you got the issue
// wkhtmltopdf: error while loading shared libraries:
// libfontconfig.so.1: cannot open shared object file: No such file or directory
//
// run the command below:
$ yum install urw-fonts libXext libXrender fontconfig libfontconfig.so.1
@justingreerbbi
justingreerbbi / wp-oauth-server-PHP-OAuth2-wrapper-example.php
Created May 12, 2017 11:56
Use of https://github.com/adoy/PHP-OAuth2 for WP OAuth Server and WP REST API. Example to create a new post as well as retrieve user data.
<?php
require( 'Client.php' );
require( 'GrantType/IGrantType.php' );
require( 'GrantType/AuthorizationCode.php' );
const CLIENT_ID = 'o1456R0uz7yv7C48wAgHdNogBF48oL3MN8STZSnz0W47z8g5Iw';
const CLIENT_SECRET = 'MWjbcUQh2e361QeUJeN7NN3SVD0bIJHuF1FSVw9YLd5N3jHNyu';
const OAUTH_SERVER = 'http://wordpress.dev/';
const REDIRECT_URI = 'http://oauth.dev/oauth2-client/index.php';
<?php
class onx_childpage_widget extends WP_Widget {
function __construct() {
parent::__construct(
'onx_childpage_widget',
'Child List Widget',
array(
'description' => 'Presents a list of children and grandchildren pages on any given page that has children or is a child.'
)
add_action( 'init', 'update_wo_custom_type', 99 );
function update_wo_custom_type() {
global $wp_post_types;
if ( post_type_exists( 'wo_client' ) ) {
$wp_post_types['wo_client']->exclude_from_search = true;
}
}
@justingreerbbi
justingreerbbi / gist:065d27e25c73ce778698bbd163b1950d
Created April 10, 2017 11:45
WP OAuth Server - Public Insert Client
function wo_public_insert_client( $client_data = null ) {
do_action( 'wo_before_create_client', array( $client_data ) );
$client_id = wo_gen_key();
$client_secret = wo_gen_key();
$grant_types = isset( $client_data['grant_types'] ) ? $client_data['grant_types'] : array();
$user_id = isset( $client_data['user_id'] ) ? intval( $client_data['user_id'] ) : 0;
@justingreerbbi
justingreerbbi / modify_scopes
Created February 22, 2017 15:28
Modify WP OAuth Server Scopes
add_filter( 'wo_scopes', 'modify_wo_scopes' );
function modify_wo_scopes( $scopes ) {
// Unset a scope
if ( isset( $scopes['openid'] ) ) {
unset( $scopes['openid'] );
}
// Add a scope
add_filter( 'aioi_template_redirect_allow_bypass', 'aioi_test_function' );
function aioi_test_function( $allows ) {
$allows['oauth'] = 'token';
return $allows;
}
<?php
class core_all_in_one_intranet {
protected function __construct() {
$this->add_actions();
}
// PRIVATE SITE
@justingreerbbi
justingreerbbi / gist:03b96213c05fa782c865e19f169867a3
Created February 6, 2017 14:33
WP OAuth Server User Credentials - PHP cURL
$curl_post_data = array(
'grant_type' => 'password',
'username' => $_POST['username'],
'password' => $_POST['password'],
'client_id' => $client_id,
'client_secret' => $client_secret
);
$curl = curl_init($server_url.'/oauth/token');
//curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);