Skip to content

Instantly share code, notes, and snippets.

@davidsword
davidsword / wp-privacy-link-in-themes.php
Last active March 11, 2019 13:59
WordPress - native privacy policy link for custom themes
@davidsword
davidsword / deploy.php
Last active May 11, 2018 22:22
Github deploy webhook location to pull any pushes from master
<?php
// just a pinch of authorization
$sig = hash_hmac('sha1', file_get_contents('php://input'), 'mywebhooksecrethere');
if (
$_POST['payload'] &&
$_SERVER['HTTP_X_GITHUB_EVENT'] == 'push' &&
$_SERVER['HTTP_X_HUB_SIGNATURE'] == 'sha1='.$sig
) {
$cmd = 'cd /var/www/path/to/repo && /usr/bin/git reset --hard HEAD 2>&1 && /usr/bin/git pull 2>&1';
$out = shell_exec( $cmd );
@davidsword
davidsword / pass-vars-into-hooks.php
Last active March 12, 2019 18:07
WP - pass variable into wp_footer and other actions hooks and filters
<?php
// Pass a value to a hook in an annonymous function
add_shortcode('show_weather',function(){
$a = shortcode_atts( array(
'location' => 'Vancouver, BC',
), $atts, 'show_weather' );
$city = $a['location'];
@davidsword
davidsword / .bash_aliases
Created April 20, 2018 01:54
Bash - rerun the last script as sudo with "$ please"
alias please="sudo !!"
@davidsword
davidsword / js-hash-url.js
Created April 19, 2018 16:07
JS - set and get hash query values from a URLs
// get the HASH values
function getHashParams() {
var hashParams = {};
var e,
a = /\+/g, // Regex for replacing addition symbol with a space
r = /([^&;=]+)=?([^&;]*)/g,
d = function (s) { return decodeURIComponent(s.replace(a, ' ')); },
q = window.location.hash.substring(1);
#!/bin/bash
S3DIR="s3://BUCKET_NAME"
BACKUPPATH=/tmp/backups
SITESTORE=/var/www
SITE=public_html
DATEFORM=$(date +"%Y-%m-%d")
DAYSKEEP=7
@davidsword
davidsword / native-font-stack.css
Created April 11, 2018 06:53
CSS native font stack for osx
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
}
@davidsword
davidsword / sword-toolkit.php
Last active March 18, 2019 16:16
WordPress - https://github.com/davidsword/sword-toolkit plugin sample configuration
<?php
/**
* Sword Toolkit configuration
*
* @see https://github.com/davidsword/sword-toolkit
*/
add_filter('sword_toolkit', function() {
return [
'remove_blog' => true,
@davidsword
davidsword / wordpress-convert-post-to-cpt.php
Last active March 13, 2019 15:01
WordPress convert post post_type to cpt based on post category
<?php
/**
* Implements `dsca` command.
*/
class DSCA_Helpers {
/**
* Change a custom post type.
*
@davidsword
davidsword / template-include.php
Last active March 15, 2019 15:30
WordPress - template include file for theme from a location. Allows things like custom post types single-posttype.php to be in /myplugin/.
<?php
/**
* Use a plugins template file, unless one exists in theme.
*
* Useful when creating custom post types, allowing themes to create
* their own template.
*/
add_filter('template_include', function ( $template ) {
if ( is_singular( 'location' ) ) { // `location` is a custom post type