Skip to content

Instantly share code, notes, and snippets.

View wpscholar's full-sized avatar
😀
Happy

Micah Wood wpscholar

😀
Happy
View GitHub Profile
var url = "";
var params = {
name: 'John',
email: '[email protected]'
};
var xhr = new XMLHttpRequest();
xhr.open('POST', url + '?' + buildQueryString(params));
@wpscholar
wpscholar / webpack.config.js
Last active March 15, 2022 01:06
Get started with WebPack in WordPress today!
'use strict';
const autoprefixer = require('autoprefixer');
const browsers = require('@wordpress/browserslist-config');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const path = require('path');
const webpack = require('webpack');
module.exports = function (env, options) {
@wpscholar
wpscholar / cloudSettings
Last active July 18, 2020 18:11
Visual Studio Code Settings
{"lastUpload":"2020-07-18T18:11:37.497Z","extensionVersion":"v3.4.3"}
@wpscholar
wpscholar / nav-login-logout.php
Last active March 15, 2022 01:18
Automatically append login and logout links to a specific menu location.
<?php
add_filter(
'wp_nav_menu_items',
function( $items, $args ) {
if ( 'primary_nav' === $args->theme_location ) {
if ( is_user_logged_in() ) {
$items .= '<li><a title="Log Out" href="' . esc_url( wp_logout_url() ) . '">' . __( 'Log Out', 'cobb-realtors' ) . '</a></li>';
} else {
$items .= '<li><a title="Login" href="' . esc_url( wp_login_url() ) . '">' . __( 'Login', 'cobb-realtors' ) . ' </a ></li >';
@wpscholar
wpscholar / wp-site-redirect.php
Created January 31, 2019 19:57
Sample plugin for redirecting a WordPress site to a specific URL.
<?php
/*
* Plugin Name:
* Plugin URI:
* Description:
* Version: 1.0
* Author:
* Author URI:
* License: GPL2
@wpscholar
wpscholar / .htaccess
Last active March 4, 2019 17:05
Set up WordPress Multi Network
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
# add a trailing slash to /wp-admin
RewriteRule ^([_0-9a-zA-Z-]+/)?wp-admin$ $1wp-admin/ [R=301,L]
RewriteCond %{REQUEST_FILENAME} -f [OR]
@wpscholar
wpscholar / wp-list-find.php
Created October 26, 2018 19:56
Created a function that will return the first found match from a list of items.
<?php
/**
* Find a single item in a list based on specific criteria.
*
* @uses wp_list_filter()
*
* @param array $list
* @param array $args
* @param string $operator
@wpscholar
wpscholar / mm_get_client_ip()
Last active September 28, 2018 15:43
What are the security implications of overwriting `REMOTE_ADDR`? Do we need to explicitly check for trusted IP addresses (e.g. https://www.cloudflare.com/ips/)? Should 'HTTP_X_FORWARDED_FOR' ever be used? See https://kb.sucuri.net/firewall/Troubleshooting/same-user-ip
/**
* Get the client IP address.
*
* @return string
*/
function mm_get_client_ip() {
// Default to REMOTE_ADDR
$ip = $_SERVER['REMOTE_ADDR'];
@wpscholar
wpscholar / schema-api.php
Created May 30, 2018 20:25
Plugin for creating a post type with a custom API that reflects Schema.org data structures
<?php
/*
* Plugin Name: Schema API
* Plugin URI:
* Description:
* Version: 0.1.0
* Author: Micah Wood
* Author URI: https://wpscholar.com
* License: GPL2
@wpscholar
wpscholar / nojs.webpack.js
Created April 26, 2018 12:14
A custom WebPack 4 plugin for removing generated JS files that aren't needed.
function() {
// Custom webpack plugin - remove generated JS files that aren't needed
this.hooks.done.tap( 'webpack', function( stats ) {
stats.compilation.chunks.forEach( chunk => {
if (!chunk.entryModule._identifier.includes( '.js' )) {
chunk.files.forEach( file => {
if (file.includes( '.js' )) {
fs.unlinkSync( path.join( __dirname, `/${file}` ) );
}
} );