Skip to content

Instantly share code, notes, and snippets.

@arkadiusjonczek
Created February 16, 2015 23:47
Show Gist options
  • Save arkadiusjonczek/848eaab53fba674e34d9 to your computer and use it in GitHub Desktop.
Save arkadiusjonczek/848eaab53fba674e34d9 to your computer and use it in GitHub Desktop.
<?php
/*
Plugin Name: calc
Plugin URI:
Description: Calculates loans/how much can be borrowed
Version: 1.0
Author: Mikey
Author URI:
*/
// from http://stackoverflow.com/questions/23207577/php-custom-calculator-script-wordpress-integration
// Save as calc.php and drop into plugins folder
// Use Shortcode [bcalc] to show the calculator
//WordPress Hooks
add_shortcode('bcalc', 'run_bc');
function run_bc()
{
if (isset($_POST['bc_person1'])) $bc_person1 = $_POST['bc_person1'];
if (isset($_POST['bc_person2'])) $bc_person2 = $_POST['bc_person2'];
$bc_multivar = 4;
$bc_answer = ($bc_person1 + $bc_person2) * $bc_multivar;
?>
<form method='post' action='<?php echo get_permalink(); ?>'>
<table border='0' width='500px' cellpadding='3' cellspacing='1' class='table'>
<tr class='calcheading'><td colspan='2'><strong>How much can you borrow?</strong></td></tr>
<tr class='calcrow'><td>Person 1 income:</td>
<td align='center'><input type='text' name='bc_person1' value='<?php echo $bc_person1 ?>'/></td></tr>
<tr class='calcrow2'><td>Person 2 income</td><td align='center'><input type='text' name='bc_person2' value='<?php echo $bc_person2 ?>'/></td></tr>
<tr class='submit'><td colspan='2'><input type='submit' value='Calculate'/></td></tr>
<tr class='calcrow'>
<td><i>You can borrow up to:</td>
<td align='center'><input type='text' value='<?php echo round($bc_answer); ?>'></td></i>
</tr>
</table>
</form>
<?php
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment