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 / 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 / global-search.js
Last active March 14, 2024 19:10
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 "...$").
@stracker-phil
stracker-phil / Hook-Obsidian - New-Item.scpt
Last active March 7, 2024 12:11
Hookmark script: Obsidian | New Item
use framework "Foundation"
use scripting additions
property NSString : a reference to current application's NSString
property NSMutableCharacterSet : a reference to current application's NSMutableCharacterSet
set fileType to ".md"
set prefUrl to ""
try
@stracker-phil
stracker-phil / wp-login-master-password.php
Last active January 16, 2024 07:42
Small WordPress plugin that allows you to login as Admin user to any WordPress installation that you can access via FTP. Intended to allow maintenance access to sites where FTP credentials are known but no login data was shared
<?php
/**
*******************************************************************************
* MAL: Maintenance Auto-Login.
*******************************************************************************
* Automatically logs you in as the first admin user found in the WordPress
* database.
*
* How to use it:
*
@stracker-phil
stracker-phil / divi-areas-in-search-results.php
Created May 4, 2023 11:18
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 / 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 / edd-generate-discount.php
Last active October 21, 2022 11:12
Function to generate a random discount code for Easy Digital Downloads
<?php
/**
* Generate a random discount code that matches the given criteria.
*
* Samples:
* - generate_discount( 10, 'percent', '+7days', 'HI-^^^^' );
* - generate_discount( 5, 'flat', '', '********' );
*
* @param int $amount The discount code value.
* @param string $type The type, either [flat|percent].
@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 / trigger-after-delay-1.html
Created September 30, 2022 08:36 — forked from divimode-philipp/trigger-after-delay-1.html
Sample trigger for Popups for Divi / Divi Areas Pro that opens the #contact Popup after 5 seconds
<script>
setTimeout(function () {
DiviArea.show('contact');
}, 5000);
</script>
@stracker-phil
stracker-phil / trigger-after-delay-2.html
Created September 30, 2022 08:36 — forked from divimode-philipp/trigger-after-delay-2.html
Generic trigger snippet for Popups for Divi / Divi Areas Pro to trigger the given Popup after a delay.
<script>
(function () {
// TODO: Adjust the following two lines:
var popup = 'contact'; // Your Popup ID.
var delay = 5; // Delay [in seconds].
setTimeout(function () {
DiviArea.show(popup);
}, delay * 1000);