Skip to content

Instantly share code, notes, and snippets.

Daniel Foust danfoust

Block or report user

Report or block danfoust

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@danfoust
danfoust / disable-comments.php
Last active Aug 15, 2019
Add to functions.php or better yet - add it as a mu-plugin. You can use wget "raw path" to copy the file through the command line.
View disable-comments.php
<?php
/**
* Plugin Name: Disable Comments
* Plugin URI: https://gist.github.com/danfoust/72742429a74d5a691cd1f2db064ce620
* Description: A must-use plugin that disables comments everywhere
* Version: 1.0.0
* Author: Daniel Foust
* Author URI: https://foustwebdesignllc.com
* License: MIT License
*/
View colors.sh
#!/bin/bash
# Borrowed from: https://stackoverflow.com/a/28938235/7903952
cprintf() {
# Reset
NC='\033[0m' # Text Reset
# Regular Colors
Black='\033[0;30m' # Black
Red='\033[0;31m' # Red
@danfoust
danfoust / certgen.sh
Created Jul 16, 2019
Create new SSL certs
View certgen.sh
#!/bin/bash
source /Users/dev/sh/variables/colors.sh
###########################################################
# Generate a new SSL
# @param string $1 domain
if [ -n "$1" ]; then
domain="$1"
@danfoust
danfoust / wp-prepared-like.php
Created Mar 1, 2019
An example of how to escape LIKE statements in Wordpress SQL (inside AJAX for context)
View wp-prepared-like.php
add_action( 'wp_ajax_product_search', 'product_search' );
function sku_search() {
global $wpdb;
$searchText = filter_var(trim($_POST['searchText']), FILTER_SANITIZE_STRING);
$sql = "SELECT * FROM wp_posts
WHERE post_title LIKE %s
AND post_type = 'product'";
$resp = $wpdb->get_results(
@danfoust
danfoust / copyToClipboard.js
Created Feb 28, 2019
Simple Vanilla js approach for copying text of data attribute on click
View copyToClipboard.js
document.querySelectorAll('.copy-text').forEach(function(elem) {
elem.addEventListener('click', function() {
var copyText = this.getAttribute('data-copyText');
copyToClipboard(copyText);
});
});
function copyToClipboard(text) {
var selected = false;
@danfoust
danfoust / api.php
Created Jan 5, 2019
Applies same REST data structure to post as default endpoint, with added filtering through plugins (ACF & better featured image REST)
View api.php
add_action( 'rest_api_init', function () {
register_rest_route( 'blank-theme/v2', '/frontpage', [
'methods' => 'GET',
'callback' => 'wp_api_route_frontpage',
]);
});
function wp_api_route_frontpage($request) {
$controller = new WP_REST_Posts_Controller('post');
$post = get_post(get_option( 'page_on_front' ));
@danfoust
danfoust / php-to-js-console.js
Created Dec 27, 2018
Convert PHP object/array to JSON to output in dev console. I always forget the order of parse/stringify, so i made this gist.
View php-to-js-console.js
$splash = [
'texture' => 'purple',
'title' => 'BUY NOW',
];
<script type="text/javascript">
console.log(JSON.parse( JSON.stringify({!! json_encode($splash) !!}) ));
</script>
@danfoust
danfoust / usort-w-dates.php
Created Dec 27, 2018
Custom sort function example in PHP
View usort-w-dates.php
function dateCMP( array $a, array $b ) {
if ( $a['timestamp'] < $b['timestamp'] ) {
return -1;
} else if ( $a['timestamp'] < $b['timestamp'] ) {
return 1;
} else {
return 0;
}
usort($posts, 'dateCMP');
@danfoust
danfoust / jquery-passive-listener.js
Created Dec 20, 2018
Improves scroll performance by making jQuery events passive. Run directly after jQuery script is loaded. Read more: https://stackoverflow.com/questions/46094912/added-non-passive-event-listener-to-a-scroll-blocking-touchstart-event
View jquery-passive-listener.js
jQuery.event.special.touchstart = {
setup: function( _, ns, handle ){
if ( ns.includes("noPreventDefault") ) {
this.addEventListener("touchstart", handle, { passive: false });
} else {
this.addEventListener("touchstart", handle, { passive: true });
}
}
};
View overflow-culprit.js
var all = document.getElementsByTagName("*"), i = 0, rect, docWidth = document.documentElement.offsetWidth;
for (; i < all.length; i++) {
rect = all[i].getBoundingClientRect();
if (rect.right > docWidth || rect.left < 0){
console.log(all[i]);
}
}
You can’t perform that action at this time.