Skip to content

Instantly share code, notes, and snippets.

View stracker-phil's full-sized avatar

Philipp Stracker stracker-phil

View GitHub Profile
@stracker-phil
stracker-phil / divi-areas-in-search-results.php
Created September 30, 2022 08:35 — forked from divimode-philipp/divi-areas-in-search-results.php
Include Divi Areas in WordPress search results
<?php
/**
* How to use this snippet:
*
* 1. Click the "Download ZIP" button (top-right area)
* 2. Open wp-admin > Plugins > Add New
* 3. Click "Upload Plugin" and select the zip file
* 4. After uploading the zip file, activate the plugin
*
* ----------
@stracker-phil
stracker-phil / dynamic-popups-1.js
Created September 30, 2022 08:33 — forked from divimode-philipp/dynamic-popups-1.js
Two ways how to display dynamic contents inside a Divi Area. In this sample we only change the URL of an iframe inside the Area, but it's possible to literally change anything inside the Area (e.g. fill out form fields, insert a user-name into a <span>, show/hide a button, etc.)
/**
* Option 1:
* Open an existing Popup and change the URL of an iframe inside the Popup.
*
* Preparation:
* Create a Divi Area (or an On-Page Popup) which contains an iframe.
*
* @param {string} areaId - The ID of an existing Popup or Divi Area.
* @param {string} iframeUrl - The new URL of the iframe inside the Popup.
*/
@stracker-phil
stracker-phil / asset-cache.php
Created September 30, 2022 08:33 — forked from divimode-philipp/asset-cache.php
Proof of concept - Cache External WP Assets
<?php
/**
* Proof of concept for https://github.com/divimode/gdpr-cache-script-styles
*/
/**
* Filter all scripts and style URLs.
* When an external URL is detected, download the file
* and replace it in the page source.
@stracker-phil
stracker-phil / divi-areas-pro-local-gsap.php
Last active December 29, 2021 23:37
Use self-hosted GSAP libraries in Divi Areas Pro.
<?php
/**
* Plugin Name: Divi Areas Pro - Local GSAP library
* Plugin URI: https://gist.github.com/stracker-phil/00b9a53632b93574c10aec491bcde586
* Description: Embed the GSAP animation library on the local website to comply with GDPR/privacy rules.
*
* ---------
*
* How to use this gist:
* 1. Download the gist as ZIP file
@stracker-phil
stracker-phil / get-css-definition.js
Last active June 10, 2024 19:52
Highly optimised and accurate alternative to the deprecated `getMatchedCSSRules()` method. StackOverflow question: https://stackoverflow.com/questions/66078682/get-the-css-definition-of-an-element/
/**
* Scans all CSS rules in the current document to find the most
* specific definiton of a single CSS property for a given element.
*
* Usage: getStyleDef('#my-element', 'width');
* --> returns the most specific "width" defintiion, e.g. "27em".
*
* @param {HTMLElement} element - The HTML Element to inspect.
* @param {string} prop - The CSS property to inspect.
* @return {string} The most specific CSS definition,
@stracker-phil
stracker-phil / test_json_performance.php
Last active October 4, 2022 23:57
Performance comparison for various PHP functions that test, if a string is valid JSON.
<?php
// https://stackoverflow.com/a/6041773/313501#answer-6041773
function test1( $value ) {
if ( ! is_scalar( $value ) ) {
return null;
}
json_decode( $value );
return ( json_last_error() == JSON_ERROR_NONE );
@stracker-phil
stracker-phil / forminator-via-ajax-script.js
Last active April 18, 2024 18:12
Load Forminator Form via Ajax
// This JS file is loaded by the theme:
(function() {
// The button with the CSS class "get-support" loads the form.
jQuery('.get-support').on('click', load_support_form);
// The form is displayed in a div tag with the CSS class "support-form".
function load_support_form() {
jQuery.get('/wp-admin/admin-ajax.php?action=my_get_support')
.then(function(response) {
@stracker-phil
stracker-phil / wp-dev-login.php
Last active September 18, 2020 11:13
Small MU-Plugin that disables passwords on local development sites. Once installed, you can select a user from a dropdown list and log-in with a single click. ONLY FOR LOCAL DEV-SITES! NEVER USE THIS ON A PUBLIC SITE!
<?php
/**
* Passwordless login for development environments.
*
* Setup:
* 1. Make sure that the "wp-contents/mu-plugins" folder exists. Create it if needed.
* 2. Save this file as "wp-contents/mu-plugins/wp-dev-login.php"
* 3. Check the conditions in line 29 - 30 and adjust them to your requirements.
*
* Once installed, all default WP login forms will display a dropdown list of all
@stracker-phil
stracker-phil / class-mycode.php
Last active January 24, 2023 12:37
Sample Block for MailPoet feature request
<?php
/**
* Custom Block to output Code.
*/
namespace MailPoet\Newsletter\Renderer\Blocks;
// Exit if accessed directly.
defined( 'ABSPATH' ) || exit;
@stracker-phil
stracker-phil / global-search.js
Last active January 10, 2026 18:33
Recursively searches the entire object tree for a given value
/**
* Recursively searches the startObject for the given value.
*
* All matches are displayed in the browser console and stored in the global variable "gsResults"
* The function tries to simplify DOM element names by using their ID, when possible.
*
* Usage samples:
*
* globalSearch( document, 'someValue' ); // Search entire DOM document for the string value.
* globalSearch( document, '^start' ); // Simple regex search (function recognizes prefix/suffix patterns: "^..." or "...$").