holding the calculator iframe. The iframe is written here so it has * an accessible title and shows even when a caching plugin delays JavaScript. ActiveCalculator's embed.js * then takes over the existing iframe and resizes it to the calculator's height. * * @package activecalculator */ if ( ! defined( 'ABSPATH' ) ) { exit; // Exit if accessed directly. } /** * Starting height of the calculator iframe, in pixels, before embed.js resizes it. */ define( 'ACTIVECALCULATOR_INITIAL_HEIGHT', 600 ); /** * Pattern for calculator IDs: cuid/cuid2 (20–32 letters and digits) or a uuid. Hyphenated words such as a * custom link name must not match. Kept in sync with src/utils/parse-calculator-input.js. */ define( 'ACTIVECALCULATOR_ID_PATTERN', '/^(?:[a-z0-9]{20,32}|[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})$/i' ); /** * Turns a calculator ID, embed code or ActiveCalculator link into a calculator ID. * * Accepts a bare ID, the embed code from Share → Embed (
or the older *
', $wrapper_attributes, esc_attr( $id ), esc_url( ACTIVECALCULATOR_APP_URL . '/embed/' . rawurlencode( $id ) ), esc_attr__( 'Interactive calculator', 'activecalculator' ), ACTIVECALCULATOR_INITIAL_HEIGHT ); } /** * Whether the page is being rendered inside the Elementor editor. * * Calculators aren't loaded there, because every load counts as an impression on the ActiveCalculator plan. * * @return bool */ function activecalculator_is_elementor_editor() { if ( ! did_action( 'elementor/loaded' ) || ! class_exists( '\Elementor\Plugin' ) ) { return false; } $elementor = \Elementor\Plugin::$instance; return ( isset( $elementor->editor ) && $elementor->editor->is_edit_mode() ) || ( isset( $elementor->preview ) && $elementor->preview->is_preview_mode() ); } /** * Placeholder shown instead of a calculator inside a page builder's editor. * * @param string $id Calculator ID, or '' when none has been entered yet. * @return string Escaped HTML. */ function activecalculator_editor_placeholder( $id ) { if ( '' === $id ) { $message = esc_html__( 'Paste the calculator’s embed code, link or ID in the settings.', 'activecalculator' ); } else { // Monospace with ligatures off: fonts like Inter turn the "x" in "4x0" into "×". $id_html = '' . esc_html( $id ) . ''; $message = esc_html__( 'Your calculator appears here on the published page.', 'activecalculator' ) . '
' . esc_html__( 'It isn’t loaded while you edit, so editing doesn’t count toward your impressions.', 'activecalculator' ) . '
' /* translators: %s: calculator ID. */ . sprintf( esc_html__( 'Calculator ID: %s', 'activecalculator' ), $id_html ) . '
'; } return '
' . '' . esc_html__( 'ActiveCalculator', 'activecalculator' ) . '
' . $message . '
'; } /** * HTML allowed in embed output. Used with wp_kses() wherever embed markup is echoed. * * @return array */ function activecalculator_allowed_html() { return array( 'div' => array( 'id' => true, 'class' => true, 'style' => true, 'data-calc-id' => true, ), 'iframe' => array( 'src' => true, 'title' => true, 'loading' => true, 'width' => true, 'height' => true, 'style' => true, 'data-calculator-id' => true, ), ); }