Skip to content

Instantly share code, notes, and snippets.

View rohjay's full-sized avatar

Ryan Oeltjenbruns rohjay

View GitHub Profile
@rohjay
rohjay / wp-fix-search-typos.php
Created May 31, 2024 21:04
Example code that fixes common misspellings of words in seaches. Parameterize to taste 👍
<?php
add_action( 'pre_get_posts', function( $query ) {
if ( !$query->is_main_query() || !$query->is_search() ) {
return $query;
}
$common_misspellings = [
'lorem' => ['lorum', 'lorm', 'lormu', 'lormum', 'lormum'],
'ipsum' => ['ipusm', 'ipsums', 'ipsumz', 'ipsumz', 'ispum'],
@rohjay
rohjay / hostile-xmlrpc-responder.php
Last active November 15, 2023 18:17
Hostile XMLRPC Responder
<?php
/*
Plugin Name: Hostile XMLRPC Responder
Plugin URI: https://kneejerk.dev
Description: A MUST use plugin designed to respond to XMLRPC requests with a little hostility =]
Version: 2.8.1
Author: Ryan "Rohjay" Oeltjenbruns
Author URI: https://rohjay.one
Requires at least: 6.0
Requires PHP: 8.0
@rohjay
rohjay / func.compare_strings.php
Created May 11, 2023 15:37
PHP function to compare strings using the Ratcliff/Obershelp pattern-matching algorithm. Great for checking sameness of words / phrases.
<?php
// I PHP-ified Ben's work from here: https://github.com/ben-yocum/gestalt-pattern-matcher (thanks for sharing Ben!)
// made a few modifications and added comments to better understand how this works. Enjoy =]
function compare_strings(string $input1, string $input2, bool $case_insensitive = true): float {
if ( $input1 == '' || $input2 == '' ) {
return 0.0;
}
// Case insensitive is the preferred, but you do you
@rohjay
rohjay / .bash_aliases
Last active May 11, 2023 15:43
These are some aliases I've enjoyed over the years =]
# PS1 stuff...
reset=$(tput -Txterm sgr0)
color=$(tput -Txterm setaf 3)
altcolor=$(tput -Txterm setaf 2)
export PS1="\[$color\]\u\[$reset\]@\[$altcolor\]\h\[$reset\]::\w>"
## Quick nav
alias ..="cd ../"
alias ~="cd ~"
<?php
/**
This is a simple class to help you render values into templates, rather than echoing large strings of html/whatever.
Usage:
// Set the base directory of all of your template files and instantiate the Templater
$base_dir = __DIR__ . '/templates';
$templater = new Templater($base_dir);
@rohjay
rohjay / wordpress-plugin-svn-to-git.md
Created July 27, 2020 23:04 — forked from kasparsd/wordpress-plugin-svn-to-git.md
Using Git with Subversion Mirroring for WordPress Plugin Development
<?php
/*
Plugin Name: Unlimited WordPress Tags!
Description: Enables the default of unlimited tags in the tag cloud to actually be unlimited (docs say unlimited, code says 45 - this fixes that.)
Version: 0.1
Author: Ryan Oeltjenbruns
Author URI: https://rohjay.one
License: GPLv2 or later
Text Domain: Tags, Tag cloud, Unlimited tags, Woohoo!
*/
@rohjay
rohjay / var_dump_to_error_log.php
Created March 27, 2019 17:57
Var dump to the error log
<?php
function var_dump_to_error_log($data) {
ob_start();
var_dump($data);
$error_log_this = ob_get_contents();
ob_end_clean();
error_log($error_log_this);
}
@rohjay
rohjay / keybase.md
Created September 18, 2018 19:30
Proof that I'm me.

Keybase proof

I hereby claim:

  • I am rohjay on github.
  • I am rohjay (https://keybase.io/rohjay) on keybase.
  • I have a public key ASBJpJtc5SN3cMx5WuTvZ6AHD1SY3yr0hUGd-fqX0EMg2go

To claim this, I am signing this object:

@rohjay
rohjay / grouper.php
Last active March 13, 2016 21:11
php function to group a list of dictionaries by a common key.
<?php
// I find myself grouping a lot of data... heres a quick helper function to do just that =]
function grouper($data, $key_to_group_by, $key_to_group_unfound='unfound', $unset_key_from_data=false) {
$grouped_results = array();
foreach ( $data as $k => $value ) {
$value_key = isset($value[$key_to_group_by]) ? $value[$key_to_group_by] : $key_to_group_unfound;
if ( !isset($grouped_results[$value_key]) ) {
$grouped_results[$value_key] = array();