Skip to content

Instantly share code, notes, and snippets.

😀
Happy

Micah Wood wpscholar

View GitHub Profile
@wpscholar
wpscholar / config.yml
Created Apr 22, 2019
CircleCI Rsync Deployment
View config.yml
version: 2
jobs:
build_and_deploy:
docker:
- image: circleci/php:7.1-node-browsers
steps:
- checkout
- run: sudo apt update
- run: sudo apt-get install rsync
- run: sudo docker-php-ext-install zip
View ajax.js
var url = "";
var params = {
name: 'John',
email: 'webmaster@mysite.com'
};
var xhr = new XMLHttpRequest();
xhr.open('POST', url + '?' + buildQueryString(params));
@wpscholar
wpscholar / webpack.config.js
Created Mar 14, 2019
Get started with WebPack in WordPress today!
View webpack.config.js
'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 / nav-login-logout.php
Last active Jan 31, 2019
Automatically append login and logout links to a specific menu location.
View nav-login-logout.php
<?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 Jan 31, 2019
Sample plugin for redirecting a WordPress site to a specific URL.
View wp-site-redirect.php
<?php
/*
* Plugin Name:
* Plugin URI:
* Description:
* Version: 1.0
* Author:
* Author URI:
* License: GPL2
@wpscholar
wpscholar / .htaccess
Last active Mar 4, 2019
Set up WordPress Multi Network
View .htaccess
# 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 Oct 26, 2018
Created a function that will return the first found match from a list of items.
View wp-list-find.php
<?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 Sep 28, 2018
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
View mm_get_client_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
Plugin for creating a post type with a custom API that reflects Schema.org data structures
View schema-api.php
<?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 Apr 26, 2018
A custom WebPack 4 plugin for removing generated JS files that aren't needed.
View nojs.webpack.js
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}` ) );
}
} );
You can’t perform that action at this time.