Skip to content

Instantly share code, notes, and snippets.

Avatar

Nathaniel nathanielks

View GitHub Profile
@nathanielks
nathanielks / wordpress.php
Created Feb 1, 2012 — forked from cogentParadigm/wordpress.php
Automated Wordpress Installer
View wordpress.php
#!/usr/bin/php
<?php
$usage = "Automated Wordpress installer\nby Ali Gangji\nUsage: wordpress install_dir -u dbuser -p dbpass -d dbname\nOptions:\n";
$usage .= " -u dbuser Database username\n";
$usage .= " -p dbpass Database password\n";
$usage .= " -d dbname Database name\n";
$usage .= " -h dbhost Database host\n";
$usage .= " --private Hide blog from search engines\n";
$usage .= " --prefix prefix Database prefix\n";
if ($argc < 2) {
@nathanielks
nathanielks / functions.php
Created Mar 14, 2012 — forked from johnmegahan/functions.php
Extended Walker class for use with the Twitter Bootstrap toolkit Dropdown menus in Wordpress.
View functions.php
<?php
add_action( 'after_setup_theme', 'bootstrap_setup' );
if ( ! function_exists( 'bootstrap_setup' ) ):
function bootstrap_setup(){
add_action( 'init', 'register_menu' );
@nathanielks
nathanielks / leaflet-init.js
Created Jul 27, 2012
Leaflet Focus Overlay
View leaflet-init.js
$(document).ready(function(){
var center = new L.LatLng(-18.9717, -3.53815); // geographical point (longitude and latitude)
var map = new L.Map('map', {
scrollWheelZoom: false,
}).setView(center, 3);
var watercolor = new L.StamenTileLayer("watercolor").addTo(map);
var overlayUrl = '/path/to/image.png',
@nathanielks
nathanielks / Readme
Created Sep 7, 2012
jQuery Element Inline Distributor
View Readme
Description:
I wrote this so that I could evenly distribute elements in a line. Here's an example that may explain better than words: http://cl.ly/JHnp, http://jsfiddle.net/nathanielks/pvGcz/4/. What it does it take the parent element and scans it for specific child elements. It then calculates the various widths and adds a left margin accordingly. The reason each element is given a display: block and float:left is because of a weird bug with display: inline. The script requires the elements to displayed inline initially, but because inline elements have a few extra pixels around them, the elements aren't all contained, even though the math is right. Really weird. Anyway, here's how you use it.
Usage:
$('#parent').distributeElements();
Here's the demo: http://jsfiddle.net/nathanielks/pvGcz/4/
@nathanielks
nathanielks / WooCommerce Sale Products up front
Last active Dec 11, 2015
This will force WooCommerce sale items to the front of the store listing, prices lowest to highest, then sorted by title A-Z.
View WooCommerce Sale Products up front
/**
* Sale Products Up Front
*/
add_action( 'woocommerce_product_query', 'cur_sale_products_up_front', 10, 2);
add_filter('posts_request', 'cur_modify_products_query', 10, 2);
add_filter('loop_start', 'cur_reorder_sale_items');
//Utility function
function cur_replace_text($startPoint, $endPoint, $newText, $source) {
@nathanielks
nathanielks / add-to-sidebar.php
Created Apr 26, 2013
These functions will programmatically add widgets to a specified sidebar. This can be useful when a theme is first installed to fill specific sidebars with widgets you're written for your theme. $add_to_sidebar takes the id of the sidebar you wish to add to. $widgets takes the id's of the widgets you wish to add.
View add-to-sidebar.php
<?php
function cur_add_widget_to_sidebar( $widget_name, $add_to_sidebar, &$sidebar_options ){
$widget = get_option('widget_'.$widget_name);
if(!is_array($widget))$widget = array();
$count = count($widget)+1;
$sidebar_options[$add_to_sidebar][] = $widget_name.'-'.$count;
$widget[$count] = array();
update_option('widget_'.$widget_name,$widget);
@nathanielks
nathanielks / wp_ultimate_csv_importer.php
Created Nov 18, 2013
Updated wp_ultimate_csv_importer.php. Works with WP installs that are in a separate directory now. Updated hard links to wp-content and wp-admin to use admin_url and plugins_url.
View wp_ultimate_csv_importer.php
<?php
/**
*Plugin Name: WP Ultimate CSV Importer
*Plugin URI: http://www.smackcoders.com/blog/how-to-guide-for-free-wordpress-ultimate-csv-importer-plugin.html
*Description: A plugin that helps to import the data's from a CSV file.
*Version: 3.2.3
*Author: smackcoders.com
*Author URI: http://www.smackcoders.com
*
* Copyright (C) 2013 Smackcoders (www.smackcoders.com)
@nathanielks
nathanielks / new.php
Created Nov 21, 2013
tribe_get_the_day_link bug. Line 16 in old.php was attributing $date_description to 'next day' as opposed to comparing that it was true. It also wasn't feeding date on line 19 a unix timestamp.
View new.php
<?php
/**
* Get the date for the day navigation link
*
* @param string $date_description
* @return string
* @since 3.1.1
* @throws OverflowException
*/
function tribe_get_the_day_link_date( $date_description ) {
@nathanielks
nathanielks / class-cur-abstract.php
Created Dec 30, 2013
Instead of having to add the get_instance function to every class you want to use, I wanted to be able to extend an abstract class with just that functionality. This is the fruit of my efforts. You can read up more on it here:http://us1.php.net/lsb and here:
View class-cur-abstract.php
<?php
abstract class Cur_Abstract {
public static $instance;
public static function get_instance() {
// Instead of doing is_object( static::$instance ), we check to see if
// static::$instance is an instance of static::$class. Because we're
// extending the class, static::$instance wants to be shared across any
// classes that extend Cur_Abstract, muddling up this check. If it were
View invitations.php
// Okie doke. Need to process how to handle reciprocal connections, as well
// as determining when to add a user to blog as a certain type. For
// example, lets talk about students adding family friends as students.
// A student will invite another student as a family friend. It'll check to
// see if that user exists, if so, record their user id and email an
// invitation to that user. The user will then accept the invitation. On
// invitation acceptance, when it goes to add the student to the journal
// hosts journal, it'll check to see if the current user ( journal guest )
// is a student. If so, it'll also add the journal host to the journal
// guests' journal as well.