Skip to content

Instantly share code, notes, and snippets.

@phlbnks
phlbnks / phpcompatabilitychecker.sh
Last active February 9, 2023 14:52
Check directory for PHP version compatibility, no dependencies except bash, PHP, Wget and Tar
#!/bin/bash
# vars
default_workdir=~/phpcompatabilitytest
default_targetversion="8.1"
default_ignore="*/vendor/*,*/sites/*,*/tests/*"
default_testdir="/var/www"
phpcsconfigfile="CodeSniffer.conf"
# config
@phlbnks
phlbnks / gmail_oauth.sh
Created January 31, 2023 23:12
Script to generate OAuth token file for use with Google API, specifically with parsedmarc / dmarc-visualizer
#!/bin/bash
# Injest / setup vars // TODO: error handling needed
client_id=$( cat parsedmarc/credentials.json | jq -r '.installed.client_id' )
client_secret=$( cat parsedmarc/credentials.json | jq -r '.installed.client_secret' )
scope="https://www.googleapis.com/auth/gmail.modify"
echo
echo "This script will take your OAuth Desktop Application credentials.json and use it to get a token to interact with the API"
sleep 2
@phlbnks
phlbnks / conflict.sh
Created November 28, 2019 16:04
Git merge conflict test generator
#!/bin/bash
# No conflict, changes in branch time order.
mkdir merge-conflict1
cd merge-conflict1
git init
touch test1.sh
git add test1.sh
echo $'Start\nOne\n\n\n\nTwo\n\n\n\nThree\n\n\n\nFour\n\n\n\nEnd' > test1.sh
git commit -am 'initial commit on master test1.sh'
@phlbnks
phlbnks / social.php
Created August 2, 2019 11:19
Basic social OG tag generation for WordPress
<?php
/**
* Plugin Name: Social Test
*
* TODO: Output <meta name="twitter:site" content="@username" />? Needs custom option to read from.
* TODO: Custom option for social fallback image instead of core image?
*/
/**
* Adding the Open Graph schema definitions in the Language Attributes.
@phlbnks
phlbnks / remove_valet.sh
Last active December 12, 2018 11:01
Sledgehammer removal of valet(+)
#!/usr/bin/env bash
valet stop
composer global remove laravel/valet
composer global remove weprovide/valet-plus
brew services stop --all
brew uninstall dnsmasq
sudo rm -rf /usr/local/etc/dnsmasq.conf
sudo rm -rf /usr/local/Cellar/dnsmasq
@phlbnks
phlbnks / remove_post_type_breadcrumb.php
Created May 17, 2018 11:43
Remove post type from Breadcrumb NavXT breadcrumbs when viewing Tag archives.
<?php
/**
* Filter breadcrumbs to remove post archive when viewing Tag archives.
*/
add_action( 'bcn_after_fill', function( $bcn_breadcrumb_trail ){
// Bail early if not a tag archive.
if ( ! is_tag() ) {
return $bcn_breadcrumb_trail;
}
@phlbnks
phlbnks / exclude_posts_with_meta.php
Created January 31, 2018 15:58
Exclude posts with a custom meta value from search
<?php
/**
* Exclude posts with 'fruit' custom meta field value of 'bananas' from site Search
*/
function cc_search_filter( $query ) {
if ( ! is_admin() && $query->is_main_query() ) {
if ( $query->is_search ) {
$query->set( 'meta_query',
array(
'relation' => 'OR',
@phlbnks
phlbnks / exclude_posts_with_term.php
Last active January 31, 2018 15:59
Exclude posts with a term in a taxonomy from search
<?php
/**
* Exclude posts with term 'bananas' from Search.
*/
function cc_search_filter( $query ) {
if ( ! is_admin() && $query->is_main_query() ) {
if ( $query->is_search ) {
$query->set(
'tax_query',
array(
@phlbnks
phlbnks / products_with_category.sql
Last active December 18, 2020 23:11
Select Product name, SKU, price and category from WordPress / WooCommerce with MySQL query
SELECT
wp_posts.post_title AS Product,
wp_postmeta1.meta_value AS SKU,
wp_postmeta2.meta_value AS Price,
GROUP_CONCAT( wp_terms.name ORDER BY wp_terms.name SEPARATOR ', ' ) AS ProductCategories
FROM wp_posts
LEFT JOIN wp_postmeta wp_postmeta1
ON wp_postmeta1.post_id = wp_posts.ID
AND wp_postmeta1.meta_key = '_sku'
LEFT JOIN wp_postmeta wp_postmeta2
@phlbnks
phlbnks / update_htaccess.php
Last active July 26, 2017 13:45
Example snippet showing how to update the WordPress .htaccess file programatically
<?php
/**
* Update .htaccess to whitelist logo when modified in platform settings.
*/
function cc_logo_htaccess() {
// Fire only on Platform Settings options page.
$screen = get_current_screen();
if ( 'cc-configurator_page_cc-settings' === $screen->id && ( $_POST['acf']['field_576c2a5137029'] || $_POST['acf']['field_576c2a9e3702a'] ) ) {
// Store files in an array.