Skip to main content

GravityMath_Shortcode

Source: includes/class-gravitymath-shortcode.php:6

Details

  • Kind: class
  • Namespace: (global)

Properties

PropertyTypeDescription
$reporterGravityMath_Report
$instanceGravityMath_Shortcode

Methods

MethodDescription
get_instance()Get the instance of this class.
add_hooks()Register the shortcode.
sanitize_formula()Strip tags, remove thousands separators, and convert dashes to minus.
do_shortcode()Process the shortcode.
format_number()Intelligently format a number.
is_valid_default_value()Validates shortcode supplied default value.

Method Reference

get_instance()

public static function get_instance( $calculator, $reporter )

Get the instance of this class.

Parameters

NameTypeDefaultDescription
$calculatorGravityMath_EngineThe calculator engine.
$reporterGravityMath_ReportThe reporter.

Returns

Since: 1.0

Source: includes/class-gravitymath-shortcode.php:82

add_hooks()

public function add_hooks()

Register the shortcode.

Since: 1.0

Source: includes/class-gravitymath-shortcode.php:118

sanitize_formula()

public static function sanitize_formula( $original_formula )

Strip tags, remove thousands separators, and convert dashes to minus.

Parameters

NameTypeDefaultDescription
$original_formulastringThe original formula.

Returns

  • string

Since: 1.0

Source: includes/class-gravitymath-shortcode.php:133

do_shortcode()

public function do_shortcode( $atts=[], $passed_content='', $shortcode='gravitymath' )

Process the shortcode.

Parameters

NameTypeDefaultDescription
$attsarray[]Attributes for the shortcode.
$passed_content''
$shortcodestring'gravitymath'Shortcode used (default: gv_math).
$contentstringContent passed to the shortcode.

Returns

  • mixed | string | void

See Also

  • GravityMath_Shortcode::$default_atts

Since: 1.0

Source: includes/class-gravitymath-shortcode.php:267

format_number()

public static function format_number( $number, $decimals=null )

Intelligently format a number.

If you don't define the number of decimal places, then it will use the existing number of decimal places. This is done in a way that respects the localization of the site.

If you do define decimals, it uses number_format_i18n().

Parameters

NameTypeDefaultDescription
$numberint | float | stringA number to format.
$decimalsint | nullnullOptional. Precision of the number of decimal places. Default '' (use existing number of decimals).

Returns

  • string — Converted number in string format.

See Also

Since: 1.0

Source: includes/class-gravitymath-shortcode.php:405

is_valid_default_value()

public static function is_valid_default_value( $value )

Validates shortcode supplied default value.

Parameters

NameTypeDefaultDescription
$valuemixedDefault value setting.

Returns

  • bool — True: valid default value; False: invalid.

See Also

  • GravityMath_Shortcode::do_shortcode

Since: 1.0

Source: includes/class-gravitymath-shortcode.php:440