Skip to content

Instantly share code, notes, and snippets.

@phlbnks
phlbnks / Pure CSS Offsets
Last active July 23, 2019 08:01
CSS to add offsets to Pure grids http://purecss.io/
/*
Offsets from https://raw.githubusercontent.com/tilomitra/pure/d7f85e37abec3fdab14a541305ad05783159655c/src/grids/css/grids-offsets.css
Media queries from Pure v0.5.0
Copyright 2014 Yahoo! Inc. All rights reserved.
Licensed under the BSD License.
https://github.com/yui/pure/blob/master/LICENSE.md
*/
@media screen and (min-width: 35.5em) {
.offset-sm-0 {
margin-left:0;
@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 / time_machine.php
Last active May 20, 2018 03:28
Filter the *displayed* time of posts in WordPress to move them into the past/future.
/**
* Filter the_time function to show posts as being from another date/time.
*
* @param string $formatted The formatted time.
* @param string $format The time format used.
* @return string Modified formatted time.
*/
function cc_time_machine( $formatted, $format ) {
$offset = get_option( 'cc_time_offset' ); // Offset in days, can be negative.
if ( $offset ) {
@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_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 / 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 / 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.
@phlbnks
phlbnks / update_htpasswd.sh
Created July 26, 2017 08:52
Bash script to help manage .htpasswd files
#!/bin/bash
#
# Manage .htpasswd files
# Store script name for use in output.
me=$( basename $0 )
# Utility function for exiting.
@phlbnks
phlbnks / functions.php
Last active February 1, 2017 07:38
Show WordPress "authors" only the comments on their posts
<?php
/**
* Clone of wp_count_comments from WP4.2.
*/
function myblogs_count_comments( $post_id = 0 ) {
global $wpdb;
$post_id = (int) $post_id;
/**
* Filter the comments count for a given post.