Skip to content

Instantly share code, notes, and snippets.

View codearachnid's full-sized avatar
🎯
Focusing

Timothy Wood codearachnid

🎯
Focusing
View GitHub Profile
@codearachnid
codearachnid / acf_field_gravity_forms_list.php
Last active March 21, 2024 18:12
Populate ACF field with list of active Gravity Forms
<?php
/***
* Populate ACF field (list_gravity_forms) with list of active Gravity Forms
***/
add_filter( 'acf/load_field/name=list_gravity_forms', function( $field ) {
$forms = GFFormsModel::get_forms();
// Filter active forms
$forms = array_filter( $forms, function( $form ) {
@codearachnid
codearachnid / gform_entry_page_replay_webhooks.php
Created February 14, 2024 21:56
Gravity Forms: Webhooks Entry Caller
<?php
// add meta boxes on entry detail
add_filter('gform_entry_detail_meta_boxes', function( $meta_boxes ){
// check that Webhooks class is available
if( class_exists('GF_Webhooks') ){
$meta_boxes['webhooks'] = [
'title' => 'Webhooks',
@codearachnid
codearachnid / gppa-explode-commas-as-selected-choices.php
Last active January 26, 2024 17:45
This is the rework of the explode commas into selected choices as there are changes in how gravitywiz populate anything now behaves. https://github.com/gravitywiz/snippet-library/blob/master/gp-populate-anything/gppa-explode-commas-as-selected-choices.php
/**
* Gravity Perks // Populate Anything // Explode Commas into Selected Choices
* https://gravitywiz.com/documentation/gravity-forms-populate-anything/
*
* Plugin Name: GPPA Explode Commas into Selected Choices
* Plugin URI: https://gravitywiz.com/documentation/gravity-forms-populate-anything/
* Description: Convert comma-delimited values into selected choices when populated into a choice-based field.
* Author: Gravity Wiz
* Version: 0.1
* Author URI: https://gravitywiz.com
@codearachnid
codearachnid / filter_gf_select_optgroup.php
Last active November 10, 2023 10:46
Add the optgroup ability to Gravity Forms default select field.
/**
* Filter Gravity Forms select field display to wrap optgroups where defined
* USE:
* set the value of the select option to `optgroup` within the form editor. The
* filter will then automagically wrap the options following until the start of
* the next option group
*/
add_filter( 'gform_field_content', 'filter_gf_select_optgroup', 10, 2 );
function filter_gf_select_optgroup( $input, $field ) {
@codearachnid
codearachnid / ping.php
Created January 28, 2015 18:04
Simple PHP ping request
<?php
function ping($host){
if(exec('echo EXEC') == 'EXEC'){
exec(sprintf('ping -c 1 -W 5 %s', escapeshellarg($host)), $res, $rval);
} elseif( function_exists('fsocketopen') ){
$port = 80;
$timeout= 6;
$fsock = fsockopen($host, $port, $errno, $errstr, $timeout);
if ( ! $fsock ){
@codearachnid
codearachnid / wp_convert_to_timezone.php
Last active September 19, 2023 17:21
Recently was working on importing dates into WordPress and needed to convert the date to the current site timezone. Because WordPress may not give you the timezone string if an UTC offset is set I modify the datetime vs change the timezone.
<?php
/**
* wp_convert_to_timezone useful for adjusting an imported DateTime to your site GMT/UTC offset
*
* @link http://www.php.net/manual/en/timezones.php Accepted $timezone strings
* @link http://www.cs.tut.fi/~jkorpela/iso8601.html Reason for default return as ISO 8601
*
* @param string $datetime
* @param string $timezone default GMT
@codearachnid
codearachnid / wp-db-cleanup.sql
Last active August 23, 2023 19:19
Safely delete orphan postmeta, attachment, gravity form entries in WordPress database *** ALWAYS BACKUP YOUR DATA FIRST ***
-- List all orphan rows from wp_postmeta
SELECT * FROM wp_postmeta
LEFT JOIN wp_posts ON wp_posts.ID = wp_postmeta.post_id
WHERE wp_posts.ID IS NULL;
-- Delete orphan postmeta
DELETE pm
FROM wp_postmeta pm
LEFT JOIN wp_posts p ON pm.post_id = p.ID
WHERE p.ID IS NULL;
<?php
// The field accepts a value with this structure
$value = [
'address' => '123 Example St, Townsville XYZ 1234, Country',
'lat' => - 38.1486228,
'lng' => 144.360414,
'zoom' => 14,
'place_id' => 'Ei0xMjMgTW9vcmFib29sIFN0LCBHZWVsb25nIFZJQyAzMjIwLCBBdXN0cmFsaWEiMBIuChQKEgmX0JaIHBTUahFyH_LC9sYD8hB7KhQKEglDz-DYDxTUahECZY8QisCjzg',
'street_number' => 123,
<?php
// The field accepts a value with this structure
$value = [
'address' => '123 Example St, Townsville XYZ 1234, Country',
'lat' => - 38.1486228,
'lng' => 144.360414,
'zoom' => 14,
'place_id' => 'Ei0xMjMgTW9vcmFib29sIFN0LCBHZWVsb25nIFZJQyAzMjIwLCBBdXN0cmFsaWEiMBIuChQKEgmX0JaIHBTUahFyH_LC9sYD8hB7KhQKEglDz-DYDxTUahECZY8QisCjzg',
'street_number' => 123,
@codearachnid
codearachnid / vuejs-actions-filters.md
Last active May 5, 2023 18:33
A recommendation on building actions/filters management similar to WordPress within a Vuejs (3) app.

VueJS (3) Action + Filters

This is a proposal to extend a compiled Vuejs application at runtime by adding actions and filters. This would allow for permitting functional extension to the data models/patterns or runtime executions of the application with discrete injection points by the development team. The purpose is to allow extensibility of functionality or filtering of data that the original application may not have considered or leveraged due to constraints. This concept is a potential benefit/risk because it gives discrete exposure to aspects of the application during runtime. By exposing controlled points during runtime for global access into the vuejs application this allows other UI frameworks within the same global space an opportunity to hook into application based api with promise driven callbacks.

[Sequence diagram for reference](https://viewer.diagrams.net/?tags=%7B%7D&amp;highlight=0000ff&amp;edit=_blank&amp;layers=1&amp;nav=1&amp;title=vuejs-actions-filters.drawio#R%3Cmxfile%3E%3Cdiagram%20name%3D%22Overvi