Skip to content

Instantly share code, notes, and snippets.

@arthur5005
Last active December 8, 2022 21:41
Show Gist options
  • Save arthur5005/1fcf025a277ef7c0b77ffbda5098ea18 to your computer and use it in GitHub Desktop.
Save arthur5005/1fcf025a277ef7c0b77ffbda5098ea18 to your computer and use it in GitHub Desktop.
Wordpress Plugin that adds ability to conditionally show/hide a block of text in an ApproveMe (WP E-Signature) contract from a shortcode enclosure
<?php
/*
Plugin Name: E-Signature (ApproveMe) Show-If Gravity Forms Shortcode Block
Description: Description: Adds ability to conditionally show/hide a block of text in an ApproveMe (WP E-Signature) contract from a shortcode enclosure [esiggravity_show_if value='foo' formid='1' field_id='1'] Some HTML content [/esiggravity_show_if]
Version: 1.0.0
Author: Arthur Goldsmith
*/
if ( file_exists( ABSPATH . '/wp-content/plugins/gravity-signature-forms-add-on/includes/esig-gf-generate-value.php' ) ) {
// Include the other plugin file
require_once( ABSPATH . '/wp-content/plugins/gravity-signature-forms-add-on/includes/esig-gf-generate-value.php' );
/**
*
* @package ESIG_GRAVITY_ShowIf
* @author Arthur Goldsmith
*/
if (!class_exists('ESIG_GRAVITY_ShowIf')) :
class ESIG_GRAVITY_ShowIf extends ESIG_GF_VALUE {
protected static $instance = null;
private function __construct() {
add_shortcode('esiggravity_show_if', array($this, 'render_esiggravity_show_if'));
}
public static function get_instance() {
// If the single instance hasn't been set, set it now.
if (null == self::$instance) {
self::$instance = new self;
}
return self::$instance;
}
// Define the shortcode handler function
public function render_esiggravity_show_if($atts, $content = '') {
extract(shortcode_atts(array(
'formid' => '',
'field_id' => '',
'value' => null,
'option' => 'default',
), $atts, 'esiggravity'));
if (!function_exists('WP_E_Sig'))
return;
// creating esignature api
$api = new WP_E_Api();
$csum = ESIG_GET('csum');
if (empty($csum)) {
$document_id = get_option('esig_global_document_id');
} else {
$document_id = $api->document->document_id_by_csum($csum);
}
// getting document meta for gravity form
$entry_id = ESIG_GF_SETTINGS::entryId($document_id); //$api->meta->get($document_id, 'esig_gravity_entry_id');
if (empty($entry_id)) {
return do_shortcode($content);
}
$field_value = self::generate_value(filter_var($formid, FILTER_SANITIZE_NUMBER_INT), filter_var($field_id, FILTER_SANITIZE_NUMBER_INT), $entry_id, $document_id, 'value', $option);
if(!is_null($value)) {
if($value == $field_value) {
return do_shortcode($content);
} else {
return '';
}
}
}
}
endif;
add_action( 'plugins_loaded', array( 'ESIG_GRAVITY_ShowIf', 'get_instance' ) );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment