Skip to content

Instantly share code, notes, and snippets.

View justingreerbbi's full-sized avatar

Justin Greer justingreerbbi

View GitHub Profile
@justingreerbbi
justingreerbbi / gist:9a97bb226fcd7e1390d50bdcc8ee4bc0
Created February 18, 2024 14:25
Return WordPress posts for today or the last day there was posts
global $wpdb;
/**
* Get todays date and the last post date to compare
*/
$query_date = date( 'Y-m-d' );
$last_date = $wpdb->get_var( "SELECT DATE(MAX(post_date)) FROM {$wpdb->posts} WHERE post_status = 'publish' AND post_type = 'post' LIMIT 1" );
// Check if the last post is from today or not
if ( $last_date != $query_date ) {
@justingreerbbi
justingreerbbi / SymmetricEncryption.php
Created January 11, 2024 21:07 — forked from joaomvfsantos/SymmetricEncryption.php
Symmetric Encryption in PHP
<?php
class SymmetricEncryption {
private $cipher;
public function __construct($cipher = 'aes-256-cbc') {
$this->cipher = $cipher;
}
@justingreerbbi
justingreerbbi / gist:c520d0a11090c25d86b5770f92e97046
Created October 9, 2023 17:12
Check user role before adding an access token
add_action('wo_set_access_token', 'check_user_before_auth');
function check_user_before_auth( $info ) {
if ( ! isset( $info['user_id'] ) ) {
return;
}
$user_id = $info['user_id'];
// Do query to checl the
@justingreerbbi
justingreerbbi / gist:5146f5c07e8f24d0e9f315e4b3eaf080
Created September 22, 2022 13:03
PHP M2M CSQ Command Convert to dB and Signal Status
/**
* Breakdown of the RSSI return for AT+CSQ command. The return from the command gives a value that needs to be
* converted in many instances.
*
* @link https://m2msupport.net/m2msupport/atcsq-signal-quality/
*/
$values = array(
'2' => array(
'dB' => '-109',
'condition' => 'Marginal'
@justingreerbbi
justingreerbbi / gist:e145be304facfc89205d47bdd20301f3
Created March 21, 2022 14:21
.well-known/openid-configuration wpoauth
{
"issuer": "https://wordpress.site",
"authorization_endpoint": "http://wordpress.site/oauth/authorize/",
"token_endpoint": "http://wordpress.site/oauth/token/",
"userinfo_endpoint": "http://wordpress.site/oauth/me/",
"end_session_endpoint": "http://wordpress.site/oauth/destroy/",
"jwks_uri": "http://wordpress.site/.well-known/keys/",
"revocation_endpoint": "http://wordpress.site/oauth/revoke/",
"introspection_endpoint": "http://wordpress.site/oauth/introspection/",
"registration_endpoint": null,
@justingreerbbi
justingreerbbi / autoexstendtoken.php
Created November 13, 2021 17:12
Increase access token after successful use but X minutes. This is for WordPress OAuth Server. Place this snippet into your themes functions.php file. It taps into the authenticated action WP OAuth Server uses when checking authorization of a call.
/**
* UPDATES AN ACCESS TOKEN'S EXPIRE TIME BY X AMOUNT OF TIME WHEN SUCCESSFULLY USED FOR AUTHENTICATION
*
* NOTE: This will override any token settings used within the plugin but does allow for active tokens to
* stay active instead of expiring. This is useful for auto deauthentication tht is traditionally handled on the
* client side.
*/
add_action( 'wo_endpoint_user_authenticated', 'wp_oauth_successful_authentication_action' );
function wp_oauth_successful_authentication_action( $token ) {
//$current_expires = $token[0]['expires'];
@justingreerbbi
justingreerbbi / cache.js
Created November 11, 2021 02:45
Titanium Module Cache CommonJS module - Plug n Play - Easy Cache
/***************************************************
Titanium Cache Module
Modified By: Justin Greer
https://justin-greer.com
Original Author: Joe Maffia
http://about.me/joemaffia
A cache module to be used for Titanium app. http://www.appcelerator.com/
@justingreerbbi
justingreerbbi / gist:720e47f0204d70fa6097e0d6f639df1b
Created September 8, 2021 15:59
Remove OAuth Access Tokens when a user logs out of WordPress
/**
* Remove all OAuth access tokens when a user logs out of the WordPress
* @param $user_id
*/
function wo_example_destroy_authorizations( $user_id ) {
global $wpdb;
$wpdb->delete( "{$wpdb->prefix}oauth_access_tokens", array( "user_id" => $user_id ) );
$wpdb->delete( "{$wpdb->prefix}oauth_refresh_tokens", array( "user_id" => $user_id ) );
}
@justingreerbbi
justingreerbbi / custom-redirect-trigger.php
Last active December 23, 2020 15:42
Simple custom redirect hook for WordPress with domain whitelisting. Simply download the file
<?php
/**
* Plugin Name: Custom Redirect Trigger
*
* This plugin allows all redirects to be processed. It can be dangerous if used incorrectly. This includes
* not adding a whitelist domain redirect. Having this wide open will all hackish redirects.
*/
class Custom_Redirect_Rewrites {
<p>Introspection Test</p>
<form action="your-site.com/oauth/introspection/" method="POST">
<input type="text" name="access_token" value=""/>
<button type="submit">Run Introspection Test</button>
</form>