Skip to content

Instantly share code, notes, and snippets.

View pattonwebz's full-sized avatar
🏠
Working from home

William Patton pattonwebz

🏠
Working from home
View GitHub Profile
@pattonwebz
pattonwebz / pwwp_debug_logger.php
Created October 9, 2017 16:20
Function to handle some basic php logging with some logic for handling wp_error and any object/arrays.
<?php
/**
* Puts messages into the error log
*
* Using php error_log put messages into the log depending on what kind of
* variable they are.
*
* @author William Patton - will@pattonwebz.com
*
* @param mixed $error this is the error we'll be outputting. Type is ambiguous.
@pattonwebz
pattonwebz / add-text-when-on-dev-or-staging.php
Last active October 9, 2017 17:37
Add a small banner of text to the header for dev/staging servers.
<?php
/**
* Adds a small banner of text when on specific domains.
*
* @return string of html or empty string
*/
function pwwp_output_text_on_dev_or_staging_server() {
$output = '';
if ($_SERVER['SERVER_NAME'] === "staging.domain.com") {
@pattonwebz
pattonwebz / filter-opengraph-image-per-posttype.php
Last active October 9, 2017 17:41
How to use the filter in yoast seo to redefine a default image for only certain CPT that is used in the open graph tags.
<?php
/**
* Filters the image used in social meta tags added by yoast seo plugin.
*
* This is used to set a default social share image for various post types.
*
* @param string $image string containing link to image that is used in tags.
* @return string string containing maybe updated url to image
*/
function pwwp_filter_yoast_opengraph_image( $image = '' ) {
@pattonwebz
pattonwebz / reset.sh
Last active November 12, 2017 18:35
called with: sh reset.sh {url to theme zip file}.
#!/bin/bash
# clear databse
wp db reset --yes
# Install WP with long title
wp core install --url=http://theme-review.loc --title="This is a really long long title to check if this theme design doesn't break with the long site title" --admin_user=admin --admin_password=admin --admin_email=example@example.com
# Update wp.
wp core update
@pattonwebz
pattonwebz / open-authors-reports.js
Created December 15, 2017 19:35
check child theme authors aren't uploading too frequently - opens submission reports of all authors currently in the queue viewed
function openInNewTab(url) {
var win = window;
win.open(url, '_blank');
win.blur;
window.focus();
}
function get_authors() {
var authors = [];
jQuery('td.reporter').each( function() {
authors.push( jQuery( this ).text().trim() );
@pattonwebz
pattonwebz / bs3-version.php
Created February 10, 2018 16:04
Code for bootstrap 3 responsive navbars in wordpress using wp-bootstrap-navwalker class
<?php
/**
* The register_nav_menus call should go inside your themes setup function
* (usually found inside functions.php).
*/
register_nav_menus(
array(
'footer_nav' => __( 'Footer Menu', 'mytheme' ), // example of adding a menu location
'top_menu' => __( 'Top Menu', 'mytheme' ), // we will be using this top_menu location
@pattonwebz
pattonwebz / repointImgs.js
Last active February 20, 2018 15:58
Update the src of images in the uploads directory of a site to point from a dev/staging domain to the live site. This prevents the need to move all of the images from a live site to a they images are unnecessary for the changes (but still nice to see them in some situations like when screenshots are being sent to the client).
// this is the pattern we match against
var regexPattern = "/wp-content/uploads/";
// turn the pattern into a regular expression
var regExp = new RegExp(regexPattern);
// get an array of the images
var images=document.querySelectorAll('img');
// loop through each array item
[].forEach.call(images,function(img){
// test if the src matches the pattern of containing '/wp-content/uploads/'
if(regExp.test(img.src)){
@pattonwebz
pattonwebz / functions.php
Created April 12, 2018 03:19
Halt theme activation if attempting to activate on unsupported older php versions.
<?php
/**
* Define the min version you support. Here I use 5.6 as example but change it to match your support version.
*/
define( 'PREFIX_MIN_PHP_VERSION', '5.6' );
/**
* Attach a function to check php version on the `after_theme_switch` hook.
*/
add_action( 'after_switch_theme', 'prefix_test_for_min_php' );
@pattonwebz
pattonwebz / grok-pattern.md
Created December 28, 2020 14:56 — forked from geraldvillorente/grok-pattern.md
Pantheon nginx-access.log Grok pattern
%{IPORHOST:remoteaddress} - - \[%{HTTPDATE:timelocal}\]  "%{WORD:httpmethod} %{URIPATHPARAM:request} HTTP/%{NUMBER:httpversion}" %{NUMBER:response} (?:%{NUMBER:bytes}|-) (?:"(?:%{URI:referrer}|-)"|%{QS:referrer}) %{QS:useragent} %{BASE10NUM:request_duration} %{QS:xforwardedfor}
<style>
.compare-table--wrapper {
background: #f5f5f5;
max-width: 740px;
border-radius: 24px;
margin: 0 auto;
}
.compare-table {
border-collapse: separate;