Skip to content

Instantly share code, notes, and snippets.

View justingreerbbi's full-sized avatar

Justin Greer justingreerbbi

View GitHub Profile
@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';
}
add_action( 'rest_api_init', function () {
register_rest_route( 'myplugin/v1', '/author/(?P<id>\d+)', array(
'methods' => 'GET',
'callback' => 'my_awesome_func',
'args' => array(
'id' => array(
'validate_callback' => 'is_numeric'
),
),
'permission_callback' => function () {
@justingreerbbi
justingreerbbi / gist:97bd91186f84578ac08ee20ee6667ed6
Created February 1, 2018 19:53
WP OAuth Server - WooCommerce Custom Login URL Redirect Filter
function wo_woocommerce_login_redirect_example( $redirect ) {
if ( ! empty( $_REQUEST['redirect_to'] ) ) {
wp_redirect( $_REQUEST['redirect_to'] );
exit;
}
return $redirect;
}
@justingreerbbi
justingreerbbi / gist:a2c7c831c3d22a0ae7727f449917b6b9
Created January 23, 2018 16:43
Create a product dynamically in WooCommerce
$pName = $params["name"];
$pDescription = 'Wallet Deposit';
$pPrice = $params["tc_price"];
$post_title = 'Fund Deposit ' . rand( 1000, 9999 ) . ' - ' . floatval( $params["tc_price"] ) . ' Credits';
$post = array(
'post_author' => $pName, // User ID
'post_content' => $pDescription,
'post_status' => "public",
'post_title' => $post_title,
@justingreerbbi
justingreerbbi / gist:fd08b7397701428146c105a2f12da953
Created December 28, 2017 02:17
Never expire token filter. This filter will take an expired token and adds 99 years to it. * Use this filter wisley *
add_filter( 'wo_get_access_token_expires_return', 'wo_modify_expires_token' );
function wo_modify_expires_token( $expires ) {
return strtotime( '+99 years', $expires );
}
@justingreerbbi
justingreerbbi / gist:8fc763cca2a718144b07945c69c3c395
Created December 27, 2017 01:11
Custom template for User Wallet Credit System. Use this snippet with Pro to override and create your own template for the custom load feature.
add_filter( 'uwcs_dynamic_deposit_template', 'custom_form_override', 99 );
function custom_form_override( $template ) {
$return = '
<style>
#uwcs-pro-custom-template {
text-align: center;
background-color: #FFF;
border: 1px solid #ccc;
padding: 1.5em;
@justingreerbbi
justingreerbbi / gist:0d6327585f3b605fb8c414753b336ee9
Created November 12, 2017 15:07
Extend the user data method
add_filter( 'wo_me_resource_return', '234kdfe2_extend_me' );
function example_extend_me_method( $data ) {
// Add new information to the user data
$roles = get_userdata( $data['ID'] );
$data['roles'] = $roles;
// Grab a custom user meta field
$customer_user_meta = get_user_meta( $data['ID'], '_inc_user_type', true );
$data['inc_user_type'] = $customer_user_meta;
@justingreerbbi
justingreerbbi / gist:768f1effcca69b4098c9d0f7731deba0
Last active June 11, 2024 11:40
Logout user using WP REST API WordPress Custom Endpoint
/**
* Head to https://wp-oauth.com for more info on user authentication and custom login and out solutions
* for WordPress
*/
add_action( 'rest_api_init', function () {
register_rest_route( 'wpoauthserver/v1', '/logout/', array(
'methods' => 'GET',
'callback' => 'wp_oauth_server_logout'
) );
} );
@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: *' );
}