| 1 |
<?php |
| 2 |
/** |
| 3 |
* Created by Code Monkeys LLC |
| 4 |
* http://www.codemonkeysllc.com |
| 5 |
* User: Spencer |
| 6 |
* Date: 11/27/2017 |
| 7 |
* Time: 4:33 PM |
| 8 |
* |
| 9 |
* Plugin Name: HIPAA Forms |
| 10 |
* Plugin URI: https://www.hipaaforms.online |
| 11 |
* Description: HIPAA Compliant Forms |
| 12 |
* Version: 3.2.2 |
| 13 |
* Author: Code Monkeys LLC |
| 14 |
* Author URI: https://www.codemonkeysllc.com |
| 15 |
* License: GPL2 |
| 16 |
*/ |
| 17 |
|
| 18 |
//* REQUIRE ADMIN ENQUEUE FILE |
| 19 |
require(plugin_dir_path(__FILE__) . 'admin-enqueue.php'); |
| 20 |
|
| 21 |
if(esc_attr(get_option('form_builder')) == 'gravity' && esc_attr(get_option('load_css_js_conditionally')) == 'enabled') { |
| 22 |
//* CHECK IF GRAVITY FORM IS LOADED ON PAGE |
| 23 |
add_filter('wp', function () { |
| 24 |
if (!class_exists('GFCommon') || !is_singular()) { |
| 25 |
return; |
| 26 |
} |
| 27 |
|
| 28 |
require_once(GFCommon::get_base_path() . '/form_display.php'); |
| 29 |
GFFormDisplay::parse_forms(get_queried_object()->post_content, $forms, $blocks); |
| 30 |
|
| 31 |
$enabledFormsSettings = json_decode(get_option('enabled_forms_settings')); |
| 32 |
|
| 33 |
if (is_array($enabledFormsSettings) && is_array($forms)) { |
| 34 |
// GET HIPAA ENABLED GRAVITY FORM ID'S |
| 35 |
$enabledFormIds = array(); |
| 36 |
foreach ($enabledFormsSettings as $enabledFormSettings) { |
| 37 |
if($enabledFormSettings->enabled == 'yes') { |
| 38 |
array_push($enabledFormIds, $enabledFormSettings->id); |
| 39 |
} |
| 40 |
} |
| 41 |
|
| 42 |
// CHECK IF ANY FORMS LOADED ON CURRENT PAGE MATCH ENABLED HIPAA FORM ID |
| 43 |
foreach ($forms as $index => $form) { |
| 44 |
if (in_array($index, $enabledFormIds)) { |
| 45 |
//* REQUIRE FRONTEND ENQUEUE FILE TO LOAD CSS & JS IF GRAVITY FORM ON PAGE IS HIPAA ENABLED (PREVENTS LOADING ON EVERY PAGE IF NOT NEEDED) |
| 46 |
require(plugin_dir_path(__FILE__) . 'enqueue.php'); |
| 47 |
|
| 48 |
return; |
| 49 |
} |
| 50 |
} |
| 51 |
} |
| 52 |
}); |
| 53 |
} else { |
| 54 |
//* REQUIRE FRONTEND ENQUEUE FILE TO LOAD CSS & JS (WILL LOAD ON EVERY PAGE, NEEDED IF SOMEONE STILL USING DEPRECATED CALDERA) |
| 55 |
require(plugin_dir_path(__FILE__) . 'enqueue.php'); |
| 56 |
} |
| 57 |
|
| 58 |
//* REQUIRE HIPAA FORMS OPTIONS |
| 59 |
require(plugin_dir_path(__FILE__) . 'includes/options.php'); |
| 60 |
|
| 61 |
//* REQUIRE CLASS FILE |
| 62 |
require(plugin_dir_path(__FILE__) . 'includes/class-cm-hipaa.php'); |
| 63 |
|
| 64 |
//* REQUIRE AJAX FUNCTIONS |
| 65 |
require(plugin_dir_path(__FILE__) . 'ajax-functions.php'); |
| 66 |
|
| 67 |
//* REQUIRE USER ROLE |
| 68 |
require(plugin_dir_path(__FILE__) . 'user-role.php'); |
| 69 |
|
| 70 |
//* REQUIRE ADMIN PAGE |
| 71 |
require(plugin_dir_path(__FILE__) . 'admin-page.php'); |
| 72 |
|
| 73 |
//* GET PLUGIN VERSION |
| 74 |
$plugin_data = get_file_data(__FILE__, array('Version' => 'Version'), false); |
| 75 |
$plugin_version = $plugin_data['Version']; |
| 76 |
define ( 'HIPAAFORMS_CURRENT_VERSION', $plugin_version ); |
| 77 |
|
| 78 |
// GET ENABLED FORMS |
| 79 |
$calderaEnabledForms = json_encode(explode(',', esc_attr(get_option('caldera_enabled_form_ids')))); |
| 80 |
$gravityEnabledForms = json_encode(explode(',', esc_attr(get_option('gravity_enabled_form_ids')))); |
| 81 |
$enabledFormsSettings = get_option('enabled_forms_settings'); // NEW JSON VERSION WITH FORM SETTINGS |
| 82 |
|
| 83 |
$decodedSettings = json_decode($enabledFormsSettings); |
| 84 |
if(is_array($decodedSettings)) { |
| 85 |
foreach($decodedSettings as $decodedSetting) { |
| 86 |
if($decodedSetting->form_builder == 'gravity' && $decodedSetting->enabled == 'yes') { |
| 87 |
// REMOVE GRAVITY SUBMIT BUTTON FOR ENABLED FORMS |
| 88 |
add_filter( 'gform_submit_button_' . $decodedSetting->id, '__return_false', 9999 ); |
| 89 |
|
| 90 |
// CATCH ANY HIPAA FORM SUBMITTED TO GRAVITY VALIDATION (THIS IS A FALLBACK, AND SHOULD NEVER ACTUALLY RUN) |
| 91 |
add_filter( 'gform_validation_' . $decodedSetting->id, function($validation_result){ |
| 92 |
$form = $validation_result['form']; |
| 93 |
|
| 94 |
// a hipaa form is validated through the HIPAA Forms plugin and should never be validated by gravity |
| 95 |
$validation_result['is_valid'] = false; |
| 96 |
|
| 97 |
|
| 98 |
add_filter( 'gform_validation_message', function($message, $form){ |
| 99 |
|
| 100 |
$message = "<div class='validation_error'><p>This form submission is being overridden be the HIPAA Forms Plugin and could not be submitted!</p></div>"; |
| 101 |
return $message; |
| 102 |
|
| 103 |
},9999,2); |
| 104 |
|
| 105 |
//Assign modified $form object back to the validation result |
| 106 |
$validation_result['form'] = $form; |
| 107 |
|
| 108 |
return $validation_result; |
| 109 |
}, 9999 ); |
| 110 |
|
| 111 |
} |
| 112 |
} |
| 113 |
} |
| 114 |
|