Build, Test, and Deploy a Custom Calculator with RMC Pro

The core of Responsive Mortgage Calculator Pro is it’s ability to easily accept data, run complex calculations, and display the results to the user. The preset calculators provide that ability and using them as the basis for customization will keep your troubles to a minimum.

But what about creating something unique not already included in the presets? If you are modifying text, this will probably be straightforward and won’t cause any issues, but if you are building a custom calculator with a unique combination of processors, calculators, and sub-calculations, you may need to build and test in a development or staging environment before deploying to a live site.

Create a Calculator

Adding a calculator to RMC Pro is perhaps the simplest aspect of customization. From the RMC Pro page, locate the link titled Create a Calculator and click it. The form that is displayed allows you to choose an existing calculator as the basis for a new one, or to start with a blank with no interface elements or processor. Pick your poison, name your calculator, and click Create Calculator. You’re on your way.

Enable Debugging

RMC Pro includes a setting to display processing information when it is run. To enable debugging messages, go to RMC Pro > Settings > CSS & Development, check the box for Debugging, and click the Save button at the bottom of the page.

When you are testing your calculator, you can view log information from each processor as it is run. If JavaScript is enabled, then messages will be displayed in the console whenever you run a calculation. If JavaScript is disabled, or the page is reloading for some reason, log messages will be displayed directly on the page. Messages tell you which processor is being run, where a processor is interrupted due to a lack of data, and where failures occur.

Of note, Processors, added in the Processors section of the Edit Calculator screen, will run until there is one that is missing data. This is intended to happen if a Processor requires a value from a Calculator that hasn’t yet run. If that happens, the Calculators begin running until there is one that is missing data, causing a switch back to Processors. This continues until all Processors and Calculators have run, or a Processor and Calculator are both unable to finish processing. The latter constitutes a failure: a piece of data wasn’t properly supplied. Hence, the need to debug!

Deploy a Custom Calculator

Once you have a working calculator, you can pass the settings between websites by exporting the calculator, creating an add-on plugin to register the settings file as a new preset, and activating the new add-on plugin on any website alongside the main RMC Pro plugin.

Exporting Calculator Settings

You can enable exporting by going to RMC Pro > Settings > CSS & Development, check the box for Exporting, and click the Save button at the bottom of the page. This will trigger a new box to be displayed on the Edit Calculator screen.

Navigate to a calculator that you want to export by clicking RMC Pro, finding a custom calculator and clicking the edit link. On the Edit Calculator screen, at the bottom right of the screen, you will see a box titled Export. Click the Export Settings link to trigger the exporting process. Exporting creates a new file containing the settings for the calculator in JSON format, and the file will be automatically saved to the Downloads folder on your computer.

Creating a Preset Add-On Plugin

To get your custom calculator onto another website, you’ll need to use the downloaded file as a preset calculator. In order to do that, you will need to create a plugin to register the preset and load the settings file. You can do this yourself by adding an action on the rmcp_add_presets action hook, or you can download my example RMC Pro Preset plugin and make some minor tweaks. I recommend the latter. Even if you know what you’re doing, you can easily reuse the callback code from the example.

Get the RMC Pro Preset plugin on Github

The example plugin is fully functional. What you will need to do is open the file inc > json-preset.json, erase the contents of the file, and paste in the contents of the settings file you previously exported from your RMC Pro Calculator. That’s it.

What you should do is open the rmc-pro-preset.php file and edit some text. Changing the WordPress plugin information at the top of the file will help you recognize the plugin on the WordPress Plugins screen. Beyond that, you should also change the class name RMCP_Example_Preset and function name rmcp_example_preset to something more unique. This will help prevent code clash if you are using multiple presets deployed in this way.

Finally, locate the add_preset method that defines the calculator $id and $title variables. The id is the string that will be used to identify this calculator in code, such as inside the RMC Pro shortcode. This can contain only letters, numbers and the underscore(_) – no spaces. The title is the human readable name of the calculator that will be displayed in the WordPress Admin wherever this calculator is referenced.

Deploy Your New Preset

You should now have a working preset calculator packaged as an add-on plugin to RMC Pro. Upload it to your site and activate it just like you would any other WordPress plugin. When you navigate to the RMC Pro Calculators list, you should see your new calculator in the Preset Calculators section of the page. It will have it’s own shortcode and it will also appear in the list of base calculators in the Create a Calculator form.

Leave a Reply

Your email address will not be published. Required fields are marked *