Skip to content

Instantly share code, notes, and snippets.

@patjun
patjun / fix-image-maps.js
Created January 31, 2022 13:50 — forked from guregu/fix-image-maps.js
Responsive image maps (vanilla JS)
function fixImageMaps(force) {
var imgs = document.querySelectorAll("img[usemap]");
[].forEach.call(imgs, function(img) {
if (!img.naturalHeight) { return; }
var h = img.height / img.naturalHeight;
var w = img.width / img.naturalWidth;
var map = document.getElementsByName(img.useMap.slice(1))[0];
if (!map) { return; }
for (var i = 0; i < map.children.length; i++) {
var area = map.children[i];
@patjun
patjun / functions.php
Created August 28, 2017 15:06 — forked from maddisondesigns/functions.php
Remove the WP REST API JSON Endpoints for everyone except Administrators
<?php
/*
* Only allow Admin users to view WP REST API JSON Endpoints
*/
function mytheme_only_allow_logged_in_rest_access( $access ) {
if( ! is_user_logged_in() || ! current_user_can( 'manage_options' ) ) {
return new WP_Error( 'rest_cannot_access', __( 'Only authenticated users can access the REST API.', 'disable-json-api' ), array( 'status' => rest_authorization_required_code() ) );
}
return $access;
}
@patjun
patjun / functions.php
Created August 28, 2017 15:06 — forked from maddisondesigns/functions.php
Remove the WP REST API JSON Endpoints for non-logged in users
<?php
/*
* Remove the WP REST API JSON Endpoints for logged out users
*/
function mytheme_only_allow_logged_in_rest_access( $access ) {
if( ! is_user_logged_in() ) {
return new WP_Error( 'rest_cannot_access', __( 'Only authenticated users can access the REST API.', 'disable-json-api' ), array( 'status' => rest_authorization_required_code() ) );
}
return $access;
}
@patjun
patjun / update.sql
Last active July 3, 2019 06:25 — forked from PhilETaylor/update.sql
Fix for corrupt JSON strings in Joomla database when updating from Joomla 3.6.2 to 3.6.3.
-- Phil Taylor <phil@phil-taylor.com>
-- @see https://github.com/joomla/joomla-cms/issues/12460
-- replace jos_ with your database prefix (left as jos and not #__ for syntax highlighting)
-- This is not a COMPLETE fix, this only fixes SOME of the core columns in tables that contain JSON.
-- BACKUP YOUR DATABASE BEFORE RUNNING THIS!!!!!!
UPDATE jos_modules SET params = "{}" WHERE params = "" OR params = '{\"\"}' OR params = '{\\\"\\\"}';
UPDATE jos_menu SET params = "{}" WHERE params = "" OR params = '{\"\"}' OR params = '{\\\"\\\"}';
UPDATE jos_extensions SET params = "{}" WHERE params = "" OR params = '{\"\"}' OR params = '{\\\"\\\"}';
UPDATE jos_assets SET rules = "{}" WHERE rules = "" OR rules = '{\"\"}' OR rules = '{\\\"\\\"}';
@patjun
patjun / gist:684f7c25f1ec939d7fd4d82800dd7b17
Created July 6, 2016 07:49 — forked from thegdshop/gist:3171026
WooCommerce - Add checkbox field to the checkout
<?php
/**
* Add checkbox field to the checkout
**/
add_action('woocommerce_after_order_notes', 'my_custom_checkout_field');
function my_custom_checkout_field( $checkout ) {
echo '<div id="my-new-field"><h3>'.__('My Checkbox: ').'</h3>';
@patjun
patjun / jfindfiles
Created June 16, 2016 05:42 — forked from renekreijveld/jfindfiles
Find unused and used content files in your Joomla website
#!/bin/sh
# jfindfiles -- Find used and unused content files in your Joomla website
#
# This scripts supports Joomla versions 1.0 - 3.3
#
# Copyright 2014 Rene Kreijveld - email@renekreijveld.nl
#
# This program is free software; you may redistribute it and/or modify it.
#
@patjun
patjun / functions.php
Last active August 29, 2015 14:07 — forked from cdils/functions.php
//* Hook site avatar before site title
add_action( 'genesis_header', 'sixteen_nine_site_gravatar', 5 );
function sixteen_nine_site_gravatar() {
$header_image = get_header_image() ? '<img alt="" src="' . get_header_image() . '" />' : get_avatar( get_option( 'admin_email' ), 224 );
printf( '<div class="site-avatar"><a href="%s">%s</a></div>', home_url( '/' ), $header_image );
}