Making WordPress.org

Changeset 5171


Ignore:
Timestamp:
03/27/2017 07:38:55 PM (7 years ago)
Author:
coffee2code
Message:

Support Forums: Honor i18n number formatting when displaying numbers.

Fixes #1882.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/support-forums/inc/class-hooks.php

    r5161 r5171  
    4444        add_action( 'bbp_new_reply',  array( $this, 'handle_extra_reply_actions' ), 10, 2 );
    4545        add_action( 'bbp_edit_reply', array( $this, 'handle_extra_reply_actions' ), 10, 2 );
     46
     47        // Honor i18n number formatting.
     48        add_filter( 'bbp_number_format', array( $this, 'number_format_i18n' ), 10, 5 );
    4649
    4750        // Store moderator's username on approve/unapprove actions.
     
    326329
    327330    /**
     331     * Override `bbp_number_format()` to behave like `bbp_number_format_i18n()` under default conditions.
     332     *
     333     * bbPress uses `bbp_number_format()` in lots of places for display.
     334     *
     335     * @param string $formatted_number Formatted number.
     336     * @param string $number           Number before formatting.
     337     * @param bool   $decimals         Display decimals?
     338     * @param int    $dec_point        Decimal point character.
     339     * @param int    $thousands_sep    Thousands separator character.
     340     * @return string
     341     */
     342    public function number_format_i18n( $formatted_number, $number, $decimals, $dec_point, $thousands_sep ) {
     343        // Format number for i18n unless non-default decimal point or thousands separator provided.
     344        if ( '.' === $dec_point && ',' === $thousands_sep ) {
     345            $formatted_number = bbp_number_format_i18n( $number, $decimals );
     346        }
     347
     348        return $formatted_number;
     349    }
     350   
     351    /**
    328352     * Store moderator's username on approve/unapprove actions.
    329353     *
Note: See TracChangeset for help on using the changeset viewer.