Skip to content

Instantly share code, notes, and snippets.

View matzeeable's full-sized avatar
💭
Looking for improvements!

Matthias Günter matzeeable

💭
Looking for improvements!
View GitHub Profile
@matzeeable
matzeeable / index.js
Last active November 18, 2022 22:34
Find object path within nested object with a given key
function findObjectWithKey(object, key, multiple = false, _recursiveData) {
var value, path = _recursiveData?.path || [];
Object.keys(object).some(function(k) {
if (k === key) {
value = object;
path.push("|");
if (!multiple) {
return true;
}
@matzeeable
matzeeable / index.js
Last active June 1, 2022 06:28
Restore function from overriden polyfill (ES5)
function restoreNativeFunctionFromPolyfillOverride(callback) {
var d = document;
var dE = d.documentElement;
var e = d.createElement("iframe");
e.style.display = "none";
dE.appendChild(e);
callback(window, e.contentWindow);
dE.removeChild(e);
}
@matzeeable
matzeeable / is_rest.php
Last active February 22, 2024 20:20
Checks if the current request is a WP REST API request.
<?php
if ( !function_exists( 'is_rest' ) ) {
/**
* Checks if the current request is a WP REST API request.
*
* Case #1: After WP_REST_Request initialisation
* Case #2: Support "plain" permalink settings and check if `rest_route` starts with `/`
* Case #3: It can happen that WP_Rewrite is not yet initialized,
* so do this (wp-settings.php)