Skip to content

Instantly share code, notes, and snippets.

View Langmans's full-sized avatar

Langmans Langmans

  • Netherlands
  • 18:09 (UTC +02:00)
View GitHub Profile
@Langmans
Langmans / functions.php
Created December 9, 2020 12:07
Advanced custom fields: make option pages with a custom post_id translatable.
<?php
add_filter('acf/pre_load_post_id',
/**
* Fix all ACF option pages. acf-pro translates the default "options" page, but not option pages with a custom post_id
*
* @param string|null $return
* @param string|int $post_id
*
* @return null|string
<?php
// Template Name: Advanced Custom Fields Export
$groups = acf_get_local_field_groups();
$json = [];
foreach ($groups as $group) {
// Fetch the fields for the given group key
$fields = acf_get_local_fields($group['key']);
// Remove unecessary key value pair with key "ID"
@Langmans
Langmans / wp-config.php
Last active May 29, 2019 07:02
turn off jquery, autoptimize and supercache for specific user agent
<?php
// at the top of wp-config.php
if ( isset( $_SERVER, $_SERVER['HTTP_USER_AGENT'] )
&& false !== stripos( $_SERVER['HTTP_USER_AGENT'], 'some-ua' )
) {
define( 'DISABLE_SUPERCACHE', true );
define( 'DONOTMINIFY', true );
define( 'NO_JQUERY', true );
} else {
define( 'NO_JQUERY', false );
{% if js is not defined or not js %}
<script>
document.cookie = "js=1";
location.reload(true); //Refreshes the page
</script>
{% endif %}
{% if js is not defined or js %}
<noscript>
<meta http-equiv="Set-Cookie" content="js=0">
<meta http-equiv="Refresh" content="0">
/**
* @param {int} y year
* @param {int} w ISO week (1-52)
* @param {int} d ISO weekday (1-7)
* @returns {Date}
*/
function getDateByISOYearWeek(y, w, d) {
d = d || 1;
var simple = new Date(Date.UTC(y, 0, 1 + (w - 1) * 7));
var dow = simple.getDay();
@Langmans
Langmans / iso_day.sql
Created April 3, 2019 15:01
mysql isoday
/*
year - weeknr - day of week (1-7)
*/
SELECT
CONCAT_WS("-",
LEFT(YEARWEEK(FROM_UNIXTIME(`daystamp`), 1), 4),
RIGHT(YEARWEEK(FROM_UNIXTIME(`daystamp`), 1), 2),
WEEKDAY(FROM_UNIXTIME(`daystamp`)) + 1
) as iso_day,
DATE(FROM_UNIXTIME(`daystamp`)) as date,
if (typeof assert !== 'function') {
function assert(expr, message) {
if (!Boolean(expr)) {
throw new Error(message || 'unknown assertion error');
}
}
}
function elementScreenQuadrant(element) {
@Langmans
Langmans / 404_images.php
Created March 19, 2019 10:38
fix wordpress missing image urls
<?php
add_filter( 'template_redirect', function () {
global $wp_query;
if ( $wp_query instanceof WP_Query &&
isset( $wp_query->query['pagename'] ) &&
$wp_query->is_404()
) {
$uploads_dir = wp_get_upload_dir();
@Langmans
Langmans / HttpCache.php
Created March 12, 2019 08:59
easy mode php last-modified/etag headers
<?php
class HttpCache {
/**
* @param int $lastModifiedTimestamp
* @param int $maxAge
*
* @return void
*/
public static function Init( $lastModifiedTimestamp, $maxAge = null ) {
@Langmans
Langmans / cache.htaccess
Last active February 26, 2019 09:45 — forked from jcanfield/cache.htaccess
.htaccess caching rules
<IfModule mod_mime.c>
# Text
AddType text/css .css
AddType application/x-javascript .js
AddType text/html .html .htm
AddType text/richtext .rtf .rtx
AddType text/plain .txt
AddType text/xml .xml