Skip to content

Instantly share code, notes, and snippets.

View pingram3541's full-sized avatar

pingram3541 pingram3541

View GitHub Profile
@pingram3541
pingram3541 / elementor-conditions.php
Last active December 16, 2024 15:49
Elementor Element Display Condition by Post ID
<?php
/**
* Plugin Name: Elementor Conditions for Elements
* Description: A plugin to add custom display conditions
* Plugin URI: https://elementor.com/
* Version: 1.0.0
* Author: Phil Ingram
* Author URI: https://developers.elementor.com/
* Text Domain: elementor-conditions
*
@pingram3541
pingram3541 / functions.php
Created March 6, 2024 17:20
Elementor Form Validation - Block non-english bots
/**
* Checks form textarea content is english to reduce spam from non-english bots
**/
function elementor_form_message_field_validation( $field, $record, $ajax_handler ) {
// Let's check the message field only
if ( empty( $field ) || empty( $field['message'] ) ) {
return;
}
// Validate content format by language
$string = $field['message'];
@pingram3541
pingram3541 / functions.php
Created August 8, 2023 18:06
WooCommerce - How to check for Guest Orders
//set the email address
$email = 'your@ema.il';
//get orders using the customer email address
$query = new WC_Order_Query();
$query->set( 'customer', $email );
$query->set( 'limit', -1 );
$orders = $query->get_orders();
//check if not a WordPress user but orders do exist
@pingram3541
pingram3541 / is-section-template.php
Created June 30, 2023 22:30
Canvas (like) template when editing Elementor "Section" Templates
<?php
/**
* Removes header & footer when editing Elementor Section templates
*
* Action: adds inline css to hide elements
*
* see Elementor issue: https://github.com/elementor/elementor/issues/6297
*
* How to use: add this file to your child theme and include it in your functions.php adding:
* include_once( 'is-section-template.php' );
@pingram3541
pingram3541 / should_render.php
Created June 30, 2023 17:08
Add Render control to all Elementor elements
<?php
/**
* Adds Render control to all widgets
*
* Action: toggle
*
* (base for adding custom conditions, see Step 3)
*
**/
@pingram3541
pingram3541 / webpcheck.js
Created May 24, 2023 16:50
Detect Webp browser support
// check_webp_feature:
// 'feature' can be one of 'lossy', 'lossless', 'alpha' or 'animation'.
// 'callback(feature, isSupported)' will be passed back the detection result (in an asynchronous way!)
// see: https://stackoverflow.com/a/54631141/4845112
function check_webp_feature(feature, callback) {
var kTestImages = {
lossy: "UklGRiIAAABXRUJQVlA4IBYAAAAwAQCdASoBAAEADsD+JaQAA3AAAAAA",
lossless: "UklGRhoAAABXRUJQVlA4TA0AAAAvAAAAEAcQERGIiP4HAA==",
alpha: "UklGRkoAAABXRUJQVlA4WAoAAAAQAAAAAAAAAAAAQUxQSAwAAAARBxAR/Q9ERP8DAABWUDggGAAAABQBAJ0BKgEAAQAAAP4AAA3AAP7mtQAAAA==",
animation: "UklGRlIAAABXRUJQVlA4WAoAAAASAAAAAAAAAAAAQU5JTQYAAAD/////AABBTk1GJgAAAAAAAAAAAAAAAAAAAGQAAABWUDhMDQAAAC8AAAAQBxAREYiI/gcA"
@pingram3541
pingram3541 / elementor_loaded.js
Created November 26, 2022 19:27
Script on elementor init, elementor ready/all elements loaded and how much time it took until all elements loaded output in console
/**
* perf monitoring
* use:
* const end = Date.now();
* const elapsed = end - start; // elapsed time in milliseconds
********************/
const start = Date.now();
//do stuff when Elementor initializes
window.addEventListener('elementor/frontend/init', function() {
@pingram3541
pingram3541 / functions.php
Created May 12, 2022 16:42
Elementor Pro Forms Custom Action - Twilio
<?php
/**
* Twilio Elementor Pro form integration
* requirements:
* - php7.2 or greater
* - twilio php helper library - https://github.com/twilio/twilio-php/archive/main.zip
* - copy into theme folder /twilio and ref below on init
*/
@pingram3541
pingram3541 / functions.php
Last active April 4, 2023 12:42
Elementor - Add Anchor (link) to Column Element w/ Hidden Anchor Text + Title Tag
<?php
/**
* Modify Elementor Column to wrap an anchor tag around it without actually wrapping it (overlay method)
*
* 1) Add url controls to column for loading w/ a link
*
* 2) Use 'elementor/frontend/column/before_render' action hook to update the column's
* css class and output the anchor tag (link) on the front end
*
* 3) Load needed css to document header - conditionally, only if any column(s) has link(s)
@pingram3541
pingram3541 / functions.php
Created August 27, 2021 17:54
Elementor - Modify Spacer Widget to wrap an anchor tag around it (link)
/**
* Modify Spacer Widget to wrap an anchor tag around it
*
* 1) Add url control to spacer widget for loading w/ a link
*
* 2) Use 'elementor/widget/render_content' action hook to update the spacer widget's
* normal output on the front end
*
**/
//part 1. to add our url control