Skip to content

Instantly share code, notes, and snippets.

View smilingpeanut's full-sized avatar

Chris Lanphear smilingpeanut

View GitHub Profile
@kayue
kayue / get_the_relative_time.php
Created January 10, 2011 04:13
Get relative time in WordPress
<?php
// This function will return "now", "3 seconds ago", "1 month ago" etc ...
function get_the_relative_time($time = null)
{
if(is_null($time)) $time = get_the_time("U");
$time_diff = date("U") - $time; // difference in second
$second = 1;
$minute = 60;
@markrickert
markrickert / auth.php
Created April 4, 2012 19:03
Authenticate via HTTP against WordPress user database
<?php
//Force SSL so that passwords aren't sent in the clear.
if($_SERVER["HTTPS"] != "on") {
header("HTTP/1.1 301 Moved Permanently");
header("Location: https://" . $_SERVER["SERVER_NAME"] . $_SERVER["REQUEST_URI"]);
exit();
}
//Here's where the Wordpress magic happens.
.fc {
direction: ltr;
text-align: left; }
.fc table {
border-collapse: collapse;
border-spacing: 0; }
.fc .btn {
line-height: 1.2em; }
html .fc {
@hubgit
hubgit / fetch-enclosures.php
Created September 20, 2012 10:46
Download all the file enclosures from an RSS feed
<?php
$rss = simplexml_load_file($argv[1]);
foreach ($rss->channel->item as $item) {
exec('wget --continue --directory-prefix="enclosures" ' . escapeshellarg($item->enclosure['url']));
}
@georgybu
georgybu / content-single-product.php
Created December 14, 2012 12:09
WooCommerce - Show next\prev products from current product category (when viewing a single product) 1. If product is last -> Next product is first 2. If product is first -> Prev product is last forked from https://gist.github.com/2176823 (This question was in http://stackoverflow.com/questions/13597687/woocommerce-get-next-previous-product/13612387
<?php
// get next and prev products
// Author: Georgy Bunin ([email protected])
// forked from https://gist.github.com/2176823
function ShowLinkToProduct($post_id, $categories_as_array, $label) {
// get post according post id
$query_args = array( 'post__in' => array($post_id), 'posts_per_page' => 1, 'post_status' => 'publish', 'post_type' => 'product', 'tax_query' => array(
array(
'taxonomy' => 'product_cat',
@jonathantneal
jonathantneal / facebook.php
Last active December 8, 2020 12:07
Getting social media feeds as JSON in PHP
<?php
/* Getting a JSON Facebook Feed
==========================================================================
1. Sign in as a developer at https://developers.facebook.com/
2. Click "Create New App" at https://developers.facebook.com/apps
3. Under Apps Settings, find the App ID and App Secret
@lisamelton
lisamelton / encode.sh
Last active March 31, 2024 21:13
This is the shell script I use to drive HandBrakeCLI to re-encode video files in a format suitable for playback on Apple TV, Roku 3, iOS, OS X, etc.
#!/bin/bash
# encode.sh
#
# Copyright (c) 2013 Don Melton
#
# This version published on June 7, 2013.
#
# Re-encode video files in a format suitable for playback on Apple TV, Roku 3,
# iOS, OS X, etc.
@leg0ffant
leg0ffant / nginx.conf
Last active May 5, 2020 10:06
Nginx file configuration Wordpress full SSL HSTS
#read more here http://tautt.com/best-nginx-configuration-for-security/
#don't send the nginx version number in error pages and Server header
server_tokens off;
# config to don't allow the browser to render the page inside an frame or iframe
# and avoid clickjacking
add_header X-Frame-Options SAMEORIGIN;
# when serving user-supplied content, include a X-Content-Type-Options: nosniff header along with the Content-Type: header,
@BFTrick
BFTrick / woocommerce-settings-tab-demo.php
Last active March 26, 2024 10:48
A plugin demonstrating how to add a WooCommerce settings tab.
<?php
/**
* Plugin Name: WooCommerce Settings Tab Demo
* Plugin URI: https://gist.github.com/BFTrick/b5e3afa6f4f83ba2e54a
* Description: A plugin demonstrating how to add a WooCommerce settings tab.
* Author: Patrick Rauland
* Author URI: http://speakinginbytes.com/
* Version: 1.0
*
* This program is free software: you can redistribute it and/or modify
@retlehs
retlehs / header.php
Created April 29, 2015 04:55
Sage header template for Bootstrap top navbar component
<?php
// This file assumes that you have included the nav walker from https://github.com/twittem/wp-bootstrap-navwalker
// somewhere in your theme.
?>
<header class="banner navbar navbar-default navbar-static-top" role="banner">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target=".navbar-collapse">
<span class="sr-only"><?= __('Toggle navigation', 'sage'); ?></span>