RMC Pro Filters API

Below is a list of filters available for you to tap into to create add-ons and modify the behaviour of RMC Pro.

Front End Filters

Front end filters allow you to manually load calculators, read calculator settings, modify the HTML being displayed, and get at the JavaScript localization array.

Read, Add, or Modify Calculators Being Prepared for a Page

rmcp_calculator_ids

This allows you to manually load a calculator for a page, especially important if you are using the do_shortcode() template tag to load a calculator. The callback takes one argument, an array of calculator ids and sources. To add one, you’ll need to append an array with the id and source.

As of v1.0.7, you can also add an attributes array to set default values.

function [your_prefix]_register_calculator_id( $ids ) {
    // ... Add custom logic as required ... //
    // Add a calculator id and source to the ids array. Attributes are optional
    $ids[] = array(
        'source'     => 'database',
        'id'         => [your_custom_id],
        'attributes' => array( [your_input_tag] => [your_default_value] )
    );
    return $ids;
}
add_filter( 'rmcp_calculator_ids', '[your_prefix]_register_calculator_id', 10, 1 );
    

A simple implementation to load a custom calculator might look like this (be sure to change the calculator id).

function custom_register_calculator_id( $ids ) {

   $ids[] = array(
       'source' => 'database’,
       ‘id'     => ‘change_this_to_the_calculator_id’
   );

   return $ids;
}
add_filter( 'rmcp_calculator_ids', ‘custom_register_calculator_id', 10, 1 );
    

Use ‘source’ => ‘preset’ if using a preset calculator, and ‘source’ => ‘database’ for custom calculators. You can find the calculator id number in the shortcode for a custom calculator. For presets, use the shortcode’s preset attribute, either payment or loan for the included presets.

Read Calculator Settings Being Loaded

rmcp_calculators_set

A read only filter that returns an array of calculator definitions with additional data, submission values, etc.

function [your_prefix]_filter_calculators_set( $definitions ) {
    // ... Look at calculator definitions before they are built ... //
}
add_filter( 'rmcp_calculators_set', '[your_prefix] _filter_calculators_set', 10, 1 );
    

Read or Modify the HTML of a Specific Calculator

rmcp_calculator_built-[count]

Provides access to the HTML of a single calculator on a page loaded in order of the [count] value. Use this to modify the HTML to be displayed. This filter also includes full information about the current calculator including the definition array, count value, id, source, and a boolean value to indicate whether results are being displayed.

You will need to know the $count value in order to set the filter. This can be obtained ahead of time using the rcmp_calculator_ids filter.

// Set up filters for a known set of calculators
for ( $count = 0; $count < count( $calculator_ids ); $count++ ) {
    add_filter( 'rmcp_calculator_built-' . $count, '[your_prefix]_filter_localize_definitions', 10, 6 );
}

// The callback function to execute the filter
function [your_prefix]_filter_calculator_html( $html, $definition, $count, $id, $source, $show_results ) {
    // ... Modify calculator HTML ... //
    return $html;
}
    

Read or Modify Calculator Settings Passed to Script Localization

rmcp_localize_definitions

Gives editable access to the calculator definitions array that are being passed into wp_localize_script.

function [your_prefix]_filter_localize_definitions( $definitions ) {
    // ... Modify or add to calculator definitions array ... //
    return $definitions;
}
add_filter( 'rmcp_localize_definitions', '[your_prefix]_filter_localize_definitions', 10, 1 );