Skip to content

Instantly share code, notes, and snippets.

View jacobwise's full-sized avatar

Jacob Wise jacobwise

View GitHub Profile
// Debouncer
(function($,sr){
// debouncing function from John Hann
// http://unscriptable.com/index.php/2009/03/20/debouncing-javascript-methods/
var debounce = function (func, threshold, execAsap) {
var timeout;
return function debounced () {
var obj = this, args = arguments;
@jacobwise
jacobwise / Time since last custom post type
Last active August 29, 2015 14:14
Using c.bavota and from the WordPress Codex for human_time_diff() these function return a readable time since last post for custom post types
/**
* Display time since post was published
*
* @uses human_time_diff() Return time difference in easy to read format
* @uses get_the_time() Get the time the post was published
* @uses current_time() Get the current time
*
* @return string Timestamp since post was published
*
* @author c.bavota
/**
* Add and extra class to the entry-content div
*
*/
function jw_entry_content_class( $attributes ) {
if ( is_tax( $taxonomy ) )
$attributes['class'] .= $class_to_add;
return $attributes;
@jacobwise
jacobwise / .gitignore
Created April 17, 2015 13:40
Starter .gitignore
*~
.DS_Store
.svn
.cvs
*.bak
*.swp
Thumbs.db
# wordpress specific
wp-config.php
@jacobwise
jacobwise / remove-entry-header-genesis
Created April 30, 2015 15:15
Remove Entry Header Genesis on front page
<?php
add_action( 'genesis_before', 'prefix_remove_entry_header' );
/**
* Remove Entry Header
*/
function prefix_remove_entry_header()
{
if ( ! is_front_page() ) { return; }
@jacobwise
jacobwise / MemberMapper.php
Last active August 29, 2015 14:26
Class to retrieve JSON and add posts to WordPress Database
<?php namespace Plugin\Models;
use Plugin\Helper;
class MemberMapper
{
public function sync_members( $post_id )
{
$admins = get_users( array( 'role' => 'administrator', 'fields' => 'ID' ) );
@jacobwise
jacobwise / get_recent_posts.php
Last active August 29, 2015 14:27
Gets the 4 most recent WordPress posts on the forum.
<?php
$url = 'https://luminous-landscape.com/wp-json/posts?filter[posts_per_page]=4';
get_recent_posts( $url );
function get_recent_posts( $url ) {
$json = file_get_contents($url);
@jacobwise
jacobwise / override_user_login.php
Last active November 12, 2015 19:16
Override user_login in WordPress
// Check if user_login already exists before we force update
if ( ! username_exists( $username ) ) {
// Force update user_login and user_nicename
$tablename = $wpdb->prefix . "users";
$wpdb->update( $tablename, // Table to Update ( prefix_users )
array(
'user_login' => $username, // Data to Update ( user_login )
'user_nicename' => $username // Data to Update ( user_nicename )
),
@jacobwise
jacobwise / check-originial-username.js
Created November 12, 2015 19:53
Checks if input has illegal characters. I was using it to see if the user already had a valid username.
hasOriginalUsername: function() {
var illegalChars = new RegExp(/\W/); // allow letters, numbers, and underscores
if ( illegalChars.test( this.originalUsername ) ) {
return true;
} else{
@jacobwise
jacobwise / sample-controller.php
Created October 16, 2017 17:55
A sample controller for a WP_Query
<?php
function prefix_get_post_type () {
$args = array(
'post_type' => 'post_type',
'posts_per_page' => 10
);
// The Query
$the_query = new WP_Query( $args );
// Create empty posts array
$posts = array();