Skip to content

Instantly share code, notes, and snippets.

View rbk's full-sized avatar

Richard Keller rbk

View GitHub Profile
@rbk
rbk / sql-queries.sql
Last active April 16, 2016 03:52
Queries
DELETE pm
FROM wp_postmeta pm
LEFT JOIN wp_posts wp ON wp.ID = pm.post_id
WHERE wp.ID IS NULL
SELECT *
FROM wp_postmeta pm
LEFT JOIN wp_posts wp ON wp.ID = pm.post_ID
WHERE wp.post_type = 'review'
@rbk
rbk / functions.php
Last active May 19, 2016 01:54
This is an example on how to use wp_enqueue_scripts in WordPress.
<?php
// https://developer.wordpress.org/reference/functions/wp_enqueue_script/
function add_my_scripts( ) {
wp_enqueue_script( 'my-script-identifier', get_template_directory_uri() . '/js/my-script.js', 1.0, true );
}
add_action('wp_enqueue_scripts', 'add_my_scripts');
?>
@rbk
rbk / scroll.js
Created June 7, 2016 15:31
Cross browser scroll position
// Calculate scroll position in all IE9+ Firefox, Chrome, and Edge
var scrollTop = 0;
window.addEventListener('scroll', function(e){
scrollTop = document.documentElement.scrollTop || window.scrollY;
});
@rbk
rbk / functions.php
Created June 8, 2016 19:55
Query WordPress and add the metadata to the result.
<?php
/*
*
* Get posts with a standard query
* Include all the meta data in the result
*
*/
function get_posts_with_meta( $args ) {
$query = get_posts($args);
@rbk
rbk / general.js
Last active June 29, 2016 19:06
Super Console Log for Chrome
function superConsoleLog( arg ) {
console.time( arg );
console.profile( arg );
console.assert( arg );
console.count( arg );
console.debug( arg );
console.dir( arg );
console.dirxml( arg );
console.error( arg );
console.info( arg );
@rbk
rbk / functions.php
Last active June 29, 2016 20:16
WordPress - Get all post metadata as a nice object that is easier to work with
<?php
function get_post_meta_object( $id ) {
$object = new stdClass();
$meta = get_post_meta( $id );
foreach( $meta as $key => $value ) {
$object->{$key} = $value[0];
}
@rbk
rbk / backup.sh
Created July 12, 2016 15:27 — forked from bradt/backup.sh
Simple Remote Backups for WordPress
#!/bin/bash
BUCKET_NAME=${1-''}
# Get upload folder path using WP-CLI
# We use --url=http://blah.com in our WP-CLI commands so that we don't get the PHP warning about HTTP_HOSTS
UPLOADS_PATH=$(wp eval '$upload_dir = wp_upload_dir(); echo $upload_dir["basedir"];' --url=http://blah.com 2>&1)
if [[ $UPLOADS_PATH =~ Error ]]
then
@rbk
rbk / super-func.php
Created July 22, 2016 17:47
Get an excerpt if one doesn't exist
<?php
function generate_awesome_excerpt( $id, $character_limit, $ending ) {
if( gettype($character_limit) != 'integer' ) {
$character_limit = 100;
}
$post = get_post($id);
$content = $post->post_content;
@rbk
rbk / mailchimp.php
Last active August 31, 2016 20:58
Subscript to Mailchimp list via php
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>MC TEST</title>
</head>
<body>
<?php
define('CLIENT_ID', '');
function slugify( $str ) {
$new_str = $str;
$new_str = preg_replace('/ /', '-', $new_str);
$new_str = preg_replace('/[^A-Za-z0-9\-]/', '', $new_str);
$new_str = strtolower($new_str);
return $new_str;
}