Skip to content

Instantly share code, notes, and snippets.

View saifsultanc's full-sized avatar
🏠
Remote

Saif Sultan saifsultanc

🏠
Remote
View GitHub Profile
@saifsultanc
saifsultanc / gist:3dba57cfa83e1bd275d88fc4a378b6a0
Created May 29, 2023 14:53
gpnf-limit-entry-min-max-from-field.php: WIP upgrade
class GP_Nested_Forms_Dynamic_Entry_Min_Max {
public function __construct( $args = array() ) {
// set our default arguments, parse against the provided arguments, and store for use throughout the class
$this->_args = wp_parse_args( $args, array(
'parent_form_id' => false,
'nested_form_field_id' => false,
'default_max' => 0, // Max to fallback to if the dependent field isn't populated
'default_min' => 0, // Min to fallback to if the dependent field isn't populated
@saifsultanc
saifsultanc / GP_Nested_Forms_Dynamic_Entry_Min_Max.php
Last active December 12, 2023 13:53
GP_Nested_Forms_Dynamic_Entry_Min_Max
class GP_Nested_Forms_Dynamic_Entry_Min_Max {
public function __construct( $args = array() ) {
// set our default arguments, parse against the provided arguments, and store for use throughout the class
$this->_args = wp_parse_args( $args, array(
'parent_form_id' => false,
'nested_form_field_id' => false,
'default_max' => 0, // Max to fallback to if the dependent field isn't populated
'default_min' => 0, // Min to fallback to if the dependent field isn't populated
/**
* Gravity Wiz // Gravity Forms // "None of the Above" Checkbox
* https://gravitywiz.com/
*
* Instruction Video: https://www.loom.com/share/0f8de708790b4afd879bf0632efd7eae (Out of date)
*
* Use this snippet to enable a proper "None of the Above" option in your Checkbox fields. If any
* other option is checked, the "None of the Above" option will be disabled. If the "None of the Above"
* option is checked, all other options will be disabled.
*
@saifsultanc
saifsultanc / GPPA_Populate_Child_Entries and GP_Nested_Forms_Dynamic_Entry_Min_Max
Created October 6, 2023 12:11
55159: GPPA_Populate_Child_Entries and GP_Nested_Forms_Dynamic_Entry_Min_Max
class GPPA_Populate_Child_Entries {
public function __construct( $args = array() ) {
// do version check in the init to make sure if GF is going to be loaded, it is already loaded
add_action( 'init', array( $this, 'init' ) );
}
public function init() {
<?php
add_filter( 'gppa_has_empty_field_filter_value_85_7', '__return_false' );
add_filter( 'gppa_object_type_filter_after_processing', function ( $query_builder_args, $args ) {
$target_form_id = 85;
$target_field_id = 7;
/**
* @var $field
* @var $filter_value
@saifsultanc
saifsultanc / gppa-reselect-correct-checkboxes-of-gravity-forms-edit.php
Last active May 1, 2024 01:40
Reselect the correct checkboxes based on the values saved for a given checkbox field rather than based on the input IDs stored.
<?php
// Snippet in Action: https://www.loom.com/share/39512bb9fd7b477fb886d75a85ae0be1
// Helper Method to get all checkbox values from an entry and targetted checkbox field_id
// Credits : https://gist.github.com/RadGH/d08a7466b097dfb895ec6dede2e474f5
function rs_gf_get_checked_boxes( $entry, $field_id ) {
$items = array();
$field_keys = array_keys( $entry );
<?php
class GW_Disable_Submit {
public static $script_output = false;
public function __construct( $form_id ) {
add_action( "gform_pre_render", array( $this, 'maybe_output_script' ) );
add_action( "gform_register_init_scripts", array( $this, 'add_init_script' ) );
@saifsultanc
saifsultanc / gpnf-hide-total-column-for-non-logged-in-users.php
Last active May 14, 2024 11:48
gp-nested-forms /gpnf-hide-total-column-for-non-logged-in-users.php
<?php
/**
* Gravity Perks // Nested Forms // Hide Total Column for Non-Logged in Users
* https://gravitywiz.com/documentation/gravity-forms-nested-forms/
*/
add_filter( 'gp_template_output_nested-entries', function( $markup, $located_template, $load, $args ) {
ob_start();
/**
* @var array $nested_fields An array of GF_Field objects.
* @var array $nested_form The form object of the nested form.
@saifsultanc
saifsultanc / gp_template_output_nested_entries_with_uid.php
Last active May 16, 2024 11:30
gp_template_output_nested_entries_with_uid.php
<?php
// Loom Demo: https://www.loom.com/share/ace89d21cbd54f3983abfc1a99829686
// customize code line 34 and 65 to include the form_id of your main form which generates the Unique IDs.
add_filter( 'gp_template_output_nested-entries', function( $markup, $located_template, $load, $args ) {
ob_start();
/**
* @var array $nested_fields An array of GF_Field objects.
* @var array $nested_form The form object of the nested form.
* @var array $nested_field_ids An array of nested field IDs.
@saifsultanc
saifsultanc / gpeb-display-svg-star-icon-for-rating-fields.php
Created May 22, 2024 10:25
gpeb-display-svg-star-icon-for-rating-fields.php
<?php
add_filter( 'gpeb_entry', function( $entry, $form ) {
$svg_star_icon = '<svg xmlns="http://www.w3.org/2000/svg" width="12" height="12" fill="none"><g clip-path="url(#a)"><path fill="url(#b)" d="M11.358 4.08 8.12 3.607 6.675.675a.78.78 0 0 0-1.35 0L3.879 3.609l-3.237.47a.75.75 0 0 0-.417 1.28l2.342 2.284-.553 3.224a.75.75 0 0 0 1.088.791L6 10.135l2.895 1.521a.75.75 0 0 0 1.089-.79L9.43 7.641l2.344-2.282a.75.75 0 0 0-.416-1.279h-.001Z"/></g><defs><linearGradient id="b" x1="9.043" x2="8.9" y1="11.165" y2=".684" gradientUnits="userSpaceOnUse"><stop stop-color="#E1A905"/><stop offset="1" stop-color="#F8E193"/></linearGradient><clipPath id="a"><path fill="#fff" d="M0 0h12v12H0z"/></clipPath></defs></svg>';
foreach ( $form['fields'] as $field ) {
if ( $field->get_input_type() === 'rating' ) {
$selected_value = $entry[ $field->id ];
foreach ( $field->choices as $index => $choice ) {
if ( $choice['value'] === $selected_value ) {
$entry[ $field->id ] = str_repeat( $svg_star_icon, $index + 1 );