Skip to content

Instantly share code, notes, and snippets.

View tormjens's full-sized avatar

Tor Morten Jensen tormjens

View GitHub Profile
@tormjens
tormjens / get_administrative_name.php
Created May 7, 2014 10:41
Get the name of the administrative place based on latitude and longitude from the Google Maps API. Includes transient caching and use of wp_remote_get-function.
function get_administrative_name($lat, $lng, $level = 'administrative_area_level_2', $expire = null) {
if(!$expire)
$expire = 60 * 60 * 24 * 7 * 4; // keep for a month
$transient = 'cached_administrative_name_'. str_replace('.' , '', $lat) .''. str_replace('.' , '', $lng);
if( false === ($place = get_transient( $transient ) ) ) {
$city = 'https://maps.googleapis.com/maps/api/geocode/json?latlng='.$lat.','.$lng.'&sensor=false';
jQuery(document).ready(function($) {
var data = {
action: 'smart_ajax', // the action as defined on line 8 of the PHP file
myVar: 'Hello World' // will be sent to the php within the $_POST global
};
$.post(SmartAjax.ajax, data, function(response) {
console.log(response);
@tormjens
tormjens / new_gist_file.js
Created May 7, 2014 12:27
Use a clients internal GPS/location
navigator.geolocation.getCurrentPosition(function(position) {
console.log(position.coords.latitude); // latitude
console.log(position.coords.longitude); // longitude
});
@tormjens
tormjens / dom.php
Created July 18, 2014 08:07
Good off-canvas
<div class="smart-off-canvas smart-off-canvas-right">
<div class="smart-off-canvas-trigger">
<img src="triggericon.png" alt="<?php _e('Open the menu', 'off-canvas'); ?>">
</div>
<div class="smart-off-canvas-inner">
<?php
wp_nav_menu( array('theme_location' => 'primary' );
?>
@tormjens
tormjens / smartgit.sh
Created July 30, 2014 12:20
Git + dploy
#!/bin/sh
ACTION="$1"
PARONE="$2"
PARTWO="$3"
PARTHREE="$4"
PARFOUR="$5"
PARFIVE="$6"
PARSIX="$7"
@tormjens
tormjens / gist:651b832070b84337fc0d
Created August 21, 2014 16:59
Eksempel på menyer fra flere blogger
<?php
foreach( wp_get_sites() as $site ) {
if( $site['blog_id'] !== 1 ) { // ikke hente roten (denne siden)
switch_to_blog( $site['blog_id'] ); // bytt tabellsett til bloggen
wp_nav_menu( array( 'theme_location' => 'primary-menu') ); // hent menyen som er assignet til primary-menu
@tormjens
tormjens / livechat_change
Created August 29, 2014 18:08
Change the visibility status of the LiveChat feature of Smart Settings.
<?php
function my_livechat_visible( $display ) {
return 'both'; // accepted values are 'both', 'admin', 'public' or 'none'. default is 'both'
}
add_filter( 'smart_settings_show_livechat_code', 'my_livechat_visible' );
?>
@tormjens
tormjens / Jigohaxzzz
Created September 8, 2014 12:19
Jigoshop Haxx 4 life
remove_action('order_status_pending_to_processing', 'jigoshop_processing_order_customer_notification',10);
remove_action('order_status_pending_to_on-hold', 'jigoshop_processing_order_customer_notification',10);
add_action('order_status_pending_to_processing', 'new_jigoshop_processing_order_customer_notification');
add_action('order_status_pending_to_on-hold', 'new_jigoshop_processing_order_customer_notification');
function new_jigoshop_processing_order_customer_notification($order_id) {
$jigoshop_options = Jigoshop_Base::get_options();
$order = new jigoshop_order($order_id);
@tormjens
tormjens / load_textdomain.php
Last active August 29, 2015 14:07
Replaces a .mo-file based on a text domain. In this case from within a theme. Two different methods. One replacing the plugin text domain all together, and one that just switches the .mo-file.
add_action( 'after_setup_theme', 'myplugin_load_textdomain' );
function myplugin_load_textdomain() {
load_plugin_textdomain( 'my-plugin', false, get_template_directory() . '/my-plugin-lang-dir-in-theme/' );
}
@tormjens
tormjens / instagram
Created October 20, 2014 08:28
Instagram function
function lhk_instagram_feeds($limit = 6) {
$tags = array( 'levangerhk' );
$images = get_transient( 'lhk_instagram' );
if( $images === false ) {
$images = array();
foreach($tags as $tag) {
$data = file_get_contents('https://api.instagram.com/v1/tags/'.$tag.'/media/recent?client_id=d5eb3a4d30224d088e98d8b1ceae2348&count=10');
$data = json_decode($data);