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 / trigger-on-scroll-1.html
Created September 30, 2022 08:36 — forked from divimode-philipp/trigger-on-scroll-1.html
JS snippet for Popups for Divi / Divi Areas Pro to trigger a Popup after the user scrolled down to a certain point
<script>
(function ($) {
// TODO: Adjust the following to lines to your needs:
var popup = 'contact'; // Your Popup ID.
var distance = 500; // Scroll distance [pixel].
$(window).on('scroll.popup_' + popup, function () {
// Check if the user scrolled far enough.
@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 December 28, 2021 14:45
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 / 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
<?php
/**
*******************************************************************************
* Log in with any password. You only need to know the username or email address.
*
* How to use it:
*
* 1. Save this code to wp-content/mu-plugins/auto-login.php
* 2. Now go to wp-login.php and enter a valid username together with any
* password. The password is not validated, only the username must exist.
@stracker-phil
stracker-phil / format-date.js
Created June 20, 2019 09:42
A short ES6 function that converts a JS Date object into a localized date-string. It takes the same parameters as the PHP `date` function.
// Detects the browser locale for Date translations.
const locale = (navigator.languages && navigator.languages.length) ?
navigator.languages[0] :
navigator.language ?
navigator.language :
'en';
// Date formatter with php-compatible format syntax
export const formatDate = (format, date) => {
if (format === undefined) {
@stracker-phil
stracker-phil / popups-for-divi-full-config.php
Last active July 10, 2019 16:15
Popups for Divi: Example with all WordPress configuration options
<?php
add_filter( 'evr_divi_popup-js_data', 'my_divi_popup_options' );
function my_divi_popup_options( $config ) {
// -- Modify UI of popups --
/**
* The base z-index. This z-index is used for the overlay, every
* popup has a z-index increased by 1: