Skip to:
Content

BuddyPress.org

Changeset 13523


Ignore:
Timestamp:
07/22/2023 07:22:41 AM (2 years ago)
Author:
imath
Message:

Completely remove bundled moment.js library

As explained in #8766, after deprecating this library in version 11.0.0,
we are now removing it from the plugin. We now use the moment.js library
already bundled into WordPress since version 5.0.

livestamp.js has been updated to v2.

Fixes #8942
Closes https://github.com/buddypress/buddypress/pull/135

Location:
trunk/src/bp-core
Files:
1 deleted
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-core/bp-core-cssjs.php

    r13485 r13523  
    1919    $min = bp_core_get_minified_asset_suffix();
    2020    $url = buddypress()->plugin_url . 'bp-core/js/';
    21 
    22     // Is WordPress' moment dist library registered?
    23     $is_moment_registered = wp_script_is( 'moment', 'registered' );
    24     $moment_locale_url    = '';
    25 
    26     /*
    27      * In 11.0.0 we are deprecating `bp-moment` in favor of WordPress' already bundled `moment`.
    28      * @todo completely remove `bp-moment` in 12.0.0.
    29      */
    30     if ( ! $is_moment_registered ) {
    31         /*
    32         * Moment.js locale.
    33         *
    34         * Try to map current WordPress locale to a moment.js locale file for loading.
    35         *
    36         * eg. French (France) locale for WP is fr_FR. Here, we try to find fr-fr.js
    37         *     (this file doesn't exist).
    38         */
    39         $wp_locale = sanitize_file_name( strtolower( get_locale() ) );
    40 
    41         // WP uses ISO 639-2 or -3 codes for some locales, which we must translate back to ISO 639-1.
    42         $iso_locales = array(
    43             'bel' => 'be',
    44             'bre' => 'br',
    45             'kir' => 'ky',
    46             'mri' => 'mi',
    47             'ssw' => 'ss',
    48         );
    49 
    50         if ( isset( $iso_locales[ $wp_locale ] ) ) {
    51             $locale = $iso_locales[ $wp_locale ];
    52         } else {
    53             $locale = $wp_locale;
    54         }
    55 
    56         $locale = str_replace( '_', '-', $locale );
    57         if ( file_exists( buddypress()->core->path . "bp-core/js/vendor/moment-js/locale/{$locale}{$min}.js" ) ) {
    58             $moment_locale_url = $url . "vendor/moment-js/locale/{$locale}{$min}.js";
    59 
    60         /*
    61         * Try to find the short-form locale.
    62         *
    63         * eg. French (France) locale for WP is fr_FR. Here, we try to find fr.js
    64         *     (this exists).
    65         */
    66         } else {
    67             $locale = substr( $locale, 0, strpos( $locale, '-' ) );
    68             if ( file_exists( buddypress()->core->path . "bp-core/js/vendor/moment-js/locale/{$locale}{$min}.js" ) ) {
    69                 $moment_locale_url = $url . "vendor/moment-js/locale/{$locale}{$min}.js";
    70             }
    71         }
    72     }
    7321
    7422    // Set up default scripts to register.
     
    9543        'bp-livestamp' => array( 'file' => "{$url}vendor/livestamp{$min}.js", 'dependencies' => array( 'jquery', 'moment' ), 'footer' => true ),
    9644    );
    97 
    98     /*
    99      * In 11.0.0 we are deprecating `bp-moment` in favor of WordPress' already bundled `moment`.
    100      * @todo completely remove `bp-moment` in 12.0.0.
    101      */
    102     if ( ! $is_moment_registered ) {
    103         $scripts['bp-moment']         = array( 'file' => "{$url}vendor/moment-js/moment{$min}.js", 'dependencies' => array(), 'footer' => true );
    104         $bp_livestamp                 = $scripts['bp-livestamp'];
    105         $bp_livestamp['dependencies'] = array( 'jquery', 'bp-moment' );
    106 
    107         // Reset 'bp-livestamp' after 'bp-moment'.
    108         unset( $scripts['bp-livestamp'] );
    109         $scripts['bp-livestamp'] = $bp_livestamp;
    110 
    111         // Version 2.7 - Add Moment.js locale to our $scripts array if we found one.
    112         if ( $moment_locale_url ) {
    113             $scripts['bp-moment-locale'] = array( 'file' => esc_url( $moment_locale_url ), 'dependencies' => array( 'bp-moment' ), 'footer' => true );
    114         }
    115     }
    11645
    11746    if ( bp_support_blocks() ) {
     
    586515    }
    587516
    588     /*
    589      * Only enqueue Moment.js locale if we registered it in
    590      * bp_core_register_common_scripts().
    591      */
    592     if ( wp_script_is( 'bp-moment-locale', 'registered' ) ) {
    593         wp_enqueue_script( 'bp-moment-locale' );
    594         wp_add_inline_script( 'bp-livestamp', bp_core_moment_js_config() );
    595     } else {
    596         wp_add_inline_script(
    597             'moment',
    598             sprintf(
    599                 "moment.updateLocale( '%s', %s );",
    600                 get_user_locale(),
    601                 wp_json_encode(
    602                     array(
    603                         'relativeTime' => array(
    604                             /* Translators: %s is the relative time (eg: in a few seconds). */
    605                             'future' => __( 'in %s', 'buddypress' ),
    606                             /* translators: %s: the human time diff. */
    607                             'past'   => __( '%s ago', 'buddypress' ),
    608                             's'      => __( 'a few seconds', 'buddypress' ),
    609                             'm'      => __( 'a minute', 'buddypress' ),
    610                             /* Translators: %d is the amount of minutes. */
    611                             'mm'     => __( '%d minutes', 'buddypress' ),
    612                             'h'      => __( 'an hour', 'buddypress' ),
    613                             /* Translators: %d is the amount of hours. */
    614                             'hh'     => __( '%d hours', 'buddypress' ),
    615                             'd'      => __( 'a day', 'buddypress' ),
    616                             /* Translators: %d is the amount of days. */
    617                             'dd'     => __( '%d days', 'buddypress' ),
    618                             'M'      => __( 'a month', 'buddypress' ),
    619                             /* Translators: %d is the amount of months. */
    620                             'MM'     => __( '%d months', 'buddypress' ),
    621                             'y'      => __( 'a year', 'buddypress' ),
    622                             /* Translators: %d is the amount of years. */
    623                             'yy'     => __( '%d years', 'buddypress' ),
    624                         ),
    625                     )
     517    wp_add_inline_script(
     518        'moment',
     519        sprintf(
     520            "moment.updateLocale( '%s', %s );",
     521            get_user_locale(),
     522            wp_json_encode(
     523                array(
     524                    'relativeTime' => array(
     525                        /* Translators: %s is the relative time (eg: in a few seconds). */
     526                        'future' => __( 'in %s', 'buddypress' ),
     527                        /* translators: %s: the human time diff. */
     528                        'past'   => __( '%s ago', 'buddypress' ),
     529                        's'      => __( 'a few seconds', 'buddypress' ),
     530                        'm'      => __( 'a minute', 'buddypress' ),
     531                        /* Translators: %d is the amount of minutes. */
     532                        'mm'     => __( '%d minutes', 'buddypress' ),
     533                        'h'      => __( 'an hour', 'buddypress' ),
     534                        /* Translators: %d is the amount of hours. */
     535                        'hh'     => __( '%d hours', 'buddypress' ),
     536                        'd'      => __( 'a day', 'buddypress' ),
     537                        /* Translators: %d is the amount of days. */
     538                        'dd'     => __( '%d days', 'buddypress' ),
     539                        'M'      => __( 'a month', 'buddypress' ),
     540                        /* Translators: %d is the amount of months. */
     541                        'MM'     => __( '%d months', 'buddypress' ),
     542                        'y'      => __( 'a year', 'buddypress' ),
     543                        /* Translators: %d is the amount of years. */
     544                        'yy'     => __( '%d years', 'buddypress' ),
     545                    ),
    626546                )
    627547            )
    628         );
    629     }
     548        )
     549    );
    630550
    631551    wp_enqueue_script( 'bp-livestamp' );
    632552}
    633 
    634 /**
    635  * Return moment.js config.
    636  *
    637  * @since 2.7.0
    638  * @deprecated 11.0.0 Soflty deprecated as we're keeping the function into this file
    639  *                    to avoid fatal errors if deprecated code is ignored.
    640  *
    641  * @return string
    642  */
    643 function bp_core_moment_js_config() {
    644     _deprecated_function( __FUNCTION__, '11.0.0' );
    645 
    646     // Grab the locale from the enqueued JS.
    647     $moment_locale = wp_scripts()->query( 'bp-moment-locale' );
    648     $moment_locale = substr( $moment_locale->src, strpos( $moment_locale->src, '/moment-js/locale/' ) + 18 );
    649     $moment_locale = str_replace( '.js', '', $moment_locale );
    650 
    651     $inline_js = <<<EOD
    652 jQuery(function() {
    653     moment.locale( '{$moment_locale}' );
    654 });
    655 EOD;
    656 
    657     return $inline_js;
    658 }
  • trunk/src/bp-core/deprecated/11.0.php

    r13371 r13523  
    9292    return bp_attachments_get_mime_type( $file );
    9393}
     94
     95/**
     96 * Return moment.js config.
     97 *
     98 * @since 2.7.0
     99 * @deprecated 11.0.0
     100 */
     101function bp_core_moment_js_config() {
     102    _deprecated_function( __FUNCTION__, '11.0.0' );
     103}
  • trunk/src/bp-core/js/vendor/livestamp.js

    r11009 r13523  
    1 // Livestamp.js / v1.1.2 / (c) 2012 Matt Bradley / MIT License
    2 (function($, moment) {
     1// Livestamp.js / v2.0.0 / (c) 2015 Matt Bradley / MIT License
     2(function (plugin) {
     3  if (typeof define === 'function' && define.amd) {
     4    // AMD. Register as an anonymous module.
     5    define(['jquery', 'moment'], plugin);
     6  } else {
     7    // Browser globals
     8    plugin(jQuery, moment);
     9  }
     10}(function($, moment) {
    311  var updateInterval = 1e3,
    412      paused = false,
     
    6169
    6270      $livestamps = $livestamps.not(toRemove);
     71      delete $livestamps.prevObject
    6372    },
    6473
     
    127136    return livestampLocal[method](this, options);
    128137  };
    129 })(jQuery, moment);
     138}));
Note: See TracChangeset for help on using the changeset viewer.