Skip to content

Instantly share code, notes, and snippets.

View vfontjr's full-sized avatar

Victor M. Font Jr. vfontjr

View GitHub Profile
jQuery(document).ready(function ($) {
"use strict";
/**
* Particles and connectors that are commonly lowercase in surnames and multi-part names
* (EXCEPT when they are the first word in the full string).
*
* Examples:
* - "Font de Lahara" -> "de" stays lowercase
* - "Juan de la Cruz" -> "de" and "la" stay lowercase
<?php
/**
* Email OTP for Formidable Forms
* - Generates and emails a 6-digit OTP tied to the submitted email.
* - Stores OTP in a transient for 10 minutes.
* - Validates on submit; blocks entry if code is wrong/expired.
*
* Replace FORM_ID, EMAIL_FIELD_ID, CODE_FIELD_ID with your actual IDs.
*/
import { dispatch } from '@wordpress/data';
const saveCustomData = (data) => {
return ( { select, dispatch } ) => {
const store = dispatch('my-plugin/store');
store.setSaving(true);
fetch('/wp-json/my-plugin/v1/save', {
method: 'POST',
body: JSON.stringify(data),
@vfontjr
vfontjr / save_post_url_to_hidden_field.php
Created July 17, 2025 20:20
Response to Mohit Manderna on Formidable Community Forum
<?php
add_action( 'frm_after_create_entry', 'save_post_url_to_hidden_field', 30, 2 );
function save_post_url_to_hidden_field( $entry_id, $form_id ) {
// Replace with your actual form ID
if ( $form_id != 42 ) {
return;
}
// Get the entry object, with meta
@vfontjr
vfontjr / wp_die_handler.php
Created July 11, 2025 21:30
Kim Clark Community Forum Response
<?php
add_filter( 'wp_die_handler', 'my_custom_wp_die_handler' );
function my_custom_wp_die_handler( $handler ) {
return 'my_override_wp_die';
}
function my_override_wp_die( $message, $title = '', $args = array() ) {
if ( trim( $message ) === 'Oops! This file is protected.' ) {
@vfontjr
vfontjr / getLastFridayOfMonth.php
Created October 30, 2024 01:23
getLastFridayOfMonth for Query
<?php
function getLastFridayOfMonth($year, $month) {
// Start with the last day of the month
$lastDay = new DateTime("$year-$month-01");
$lastDay->modify('last day of this month');
// Find the last Friday before or on the last day of the month
if ($lastDay->format('N') < 5) {
// If the last day is before Friday, subtract days to reach the last Friday
$lastDay->modify('last Friday');
@vfontjr
vfontjr / frm_entry_meta_example.php
Last active October 21, 2024 12:28
Updating From Entry Meta
<?php
function add_or_update_entry_meta( $entry_id, $field_key, $value ){
/* convert field_key to field_id for software portability */
$field_id = FrmField::get_id_by_key($field_key);
/* check for existing value */
$field_val_exists = FrmProEntriesController::get_field_value_shortcode(array('field_id' => $field_id, 'entry' => $entry_id));
/* add or update as appropriate */
<?php
function create_init_field_vars_array( $form_key ) {
global $wpdb;
/* initialize the variables for the formidable tables */
$wpdb_prefix = $wpdb->prefix;
$frm_fields = $wpdb_prefix . 'frm_fields';
$form_id = FrmForm::get_id_by_key( $form_key );
$new_key = str_replace('-', '_', $form_key);
@vfontjr
vfontjr / splitCSV.php
Created July 20, 2024 22:53
Split CSV Files into smaller chunks
<?php
/*
This function was created by ChatGPT and does the following:
1. Checks if the input file exists.
2. Opens the input CSV file for reading.
3. Ensures the output directory exists, creating it if necessary.
4. Reads the header row of the CSV.
5. Loops through each row of the input CSV file.
6. Creates a new output file every 400 rows, including the header row.
<script>
/* install this script in the after fields section on the
* form's CustomizeHTML page.
*/
jQuery(document).ready(function($) {
"use strict";
/**
* original code found on StackExchange
* addmonths: function used to calculate renewal date
* date {dateStr}