<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[BuddyPress][13523] trunk/src/bp-core: Completely remove bundled `moment.js` library</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { white-space: pre-line; overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta" style="font-size: 105%">
<dt style="float: left; width: 6em; font-weight: bold">Revision</dt> <dd><a style="font-weight: bold" href="http://buddypress.trac.wordpress.org/changeset/13523">13523</a><script type="application/ld+json">{"@context":"http://schema.org","@type":"EmailMessage","description":"Review this Commit","action":{"@type":"ViewAction","url":"http://buddypress.trac.wordpress.org/changeset/13523","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>imath</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2023-07-22 07:22:41 +0000 (Sat, 22 Jul 2023)</dd>
</dl>
<pre style='padding-left: 1em; margin: 2em 0; border-left: 2px solid #ccc; line-height: 1.25; font-size: 105%; font-family: sans-serif'>Completely remove bundled `moment.js` library
As explained in <a href="http://buddypress.trac.wordpress.org/ticket/8766">#8766</a>, 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 <a href="http://buddypress.trac.wordpress.org/ticket/8942">#8942</a>
Closes https://github.com/buddypress/buddypress/pull/135</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunksrcbpcorebpcorecssjsphp">trunk/src/bp-core/bp-core-cssjs.php</a></li>
<li><a href="#trunksrcbpcoredeprecated110php">trunk/src/bp-core/deprecated/11.0.php</a></li>
<li><a href="#trunksrcbpcorejsvendorlivestampjs">trunk/src/bp-core/js/vendor/livestamp.js</a></li>
</ul>
<h3>Removed Paths</h3>
<ul>
<li>trunk/src/bp-core/js/vendor/moment-js/</li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunksrcbpcorebpcorecssjsphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/bp-core/bp-core-cssjs.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/bp-core/bp-core-cssjs.php 2023-07-20 03:07:17 UTC (rev 13522)
+++ trunk/src/bp-core/bp-core-cssjs.php 2023-07-22 07:22:41 UTC (rev 13523)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -19,58 +19,6 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $min = bp_core_get_minified_asset_suffix();
</span><span class="cx" style="display: block; padding: 0 10px"> $url = buddypress()->plugin_url . 'bp-core/js/';
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- // Is WordPress' moment dist library registered?
- $is_moment_registered = wp_script_is( 'moment', 'registered' );
- $moment_locale_url = '';
-
- /*
- * In 11.0.0 we are deprecating `bp-moment` in favor of WordPress' already bundled `moment`.
- * @todo completely remove `bp-moment` in 12.0.0.
- */
- if ( ! $is_moment_registered ) {
- /*
- * Moment.js locale.
- *
- * Try to map current WordPress locale to a moment.js locale file for loading.
- *
- * eg. French (France) locale for WP is fr_FR. Here, we try to find fr-fr.js
- * (this file doesn't exist).
- */
- $wp_locale = sanitize_file_name( strtolower( get_locale() ) );
-
- // WP uses ISO 639-2 or -3 codes for some locales, which we must translate back to ISO 639-1.
- $iso_locales = array(
- 'bel' => 'be',
- 'bre' => 'br',
- 'kir' => 'ky',
- 'mri' => 'mi',
- 'ssw' => 'ss',
- );
-
- if ( isset( $iso_locales[ $wp_locale ] ) ) {
- $locale = $iso_locales[ $wp_locale ];
- } else {
- $locale = $wp_locale;
- }
-
- $locale = str_replace( '_', '-', $locale );
- if ( file_exists( buddypress()->core->path . "bp-core/js/vendor/moment-js/locale/{$locale}{$min}.js" ) ) {
- $moment_locale_url = $url . "vendor/moment-js/locale/{$locale}{$min}.js";
-
- /*
- * Try to find the short-form locale.
- *
- * eg. French (France) locale for WP is fr_FR. Here, we try to find fr.js
- * (this exists).
- */
- } else {
- $locale = substr( $locale, 0, strpos( $locale, '-' ) );
- if ( file_exists( buddypress()->core->path . "bp-core/js/vendor/moment-js/locale/{$locale}{$min}.js" ) ) {
- $moment_locale_url = $url . "vendor/moment-js/locale/{$locale}{$min}.js";
- }
- }
- }
-
</del><span class="cx" style="display: block; padding: 0 10px"> // Set up default scripts to register.
</span><span class="cx" style="display: block; padding: 0 10px"> $scripts = array(
</span><span class="cx" style="display: block; padding: 0 10px"> // Legacy.
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -95,25 +43,6 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 'bp-livestamp' => array( 'file' => "{$url}vendor/livestamp{$min}.js", 'dependencies' => array( 'jquery', 'moment' ), 'footer' => true ),
</span><span class="cx" style="display: block; padding: 0 10px"> );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- /*
- * In 11.0.0 we are deprecating `bp-moment` in favor of WordPress' already bundled `moment`.
- * @todo completely remove `bp-moment` in 12.0.0.
- */
- if ( ! $is_moment_registered ) {
- $scripts['bp-moment'] = array( 'file' => "{$url}vendor/moment-js/moment{$min}.js", 'dependencies' => array(), 'footer' => true );
- $bp_livestamp = $scripts['bp-livestamp'];
- $bp_livestamp['dependencies'] = array( 'jquery', 'bp-moment' );
-
- // Reset 'bp-livestamp' after 'bp-moment'.
- unset( $scripts['bp-livestamp'] );
- $scripts['bp-livestamp'] = $bp_livestamp;
-
- // Version 2.7 - Add Moment.js locale to our $scripts array if we found one.
- if ( $moment_locale_url ) {
- $scripts['bp-moment-locale'] = array( 'file' => esc_url( $moment_locale_url ), 'dependencies' => array( 'bp-moment' ), 'footer' => true );
- }
- }
-
</del><span class="cx" style="display: block; padding: 0 10px"> if ( bp_support_blocks() ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $asset = array(
</span><span class="cx" style="display: block; padding: 0 10px"> 'dependencies' => array(),
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -585,74 +514,39 @@
</span><span class="cx" style="display: block; padding: 0 10px"> return;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- /*
- * Only enqueue Moment.js locale if we registered it in
- * bp_core_register_common_scripts().
- */
- if ( wp_script_is( 'bp-moment-locale', 'registered' ) ) {
- wp_enqueue_script( 'bp-moment-locale' );
- wp_add_inline_script( 'bp-livestamp', bp_core_moment_js_config() );
- } else {
- wp_add_inline_script(
- 'moment',
- sprintf(
- "moment.updateLocale( '%s', %s );",
- get_user_locale(),
- wp_json_encode(
- array(
- 'relativeTime' => array(
- /* Translators: %s is the relative time (eg: in a few seconds). */
- 'future' => __( 'in %s', 'buddypress' ),
- /* translators: %s: the human time diff. */
- 'past' => __( '%s ago', 'buddypress' ),
- 's' => __( 'a few seconds', 'buddypress' ),
- 'm' => __( 'a minute', 'buddypress' ),
- /* Translators: %d is the amount of minutes. */
- 'mm' => __( '%d minutes', 'buddypress' ),
- 'h' => __( 'an hour', 'buddypress' ),
- /* Translators: %d is the amount of hours. */
- 'hh' => __( '%d hours', 'buddypress' ),
- 'd' => __( 'a day', 'buddypress' ),
- /* Translators: %d is the amount of days. */
- 'dd' => __( '%d days', 'buddypress' ),
- 'M' => __( 'a month', 'buddypress' ),
- /* Translators: %d is the amount of months. */
- 'MM' => __( '%d months', 'buddypress' ),
- 'y' => __( 'a year', 'buddypress' ),
- /* Translators: %d is the amount of years. */
- 'yy' => __( '%d years', 'buddypress' ),
- ),
- )
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ wp_add_inline_script(
+ 'moment',
+ sprintf(
+ "moment.updateLocale( '%s', %s );",
+ get_user_locale(),
+ wp_json_encode(
+ array(
+ 'relativeTime' => array(
+ /* Translators: %s is the relative time (eg: in a few seconds). */
+ 'future' => __( 'in %s', 'buddypress' ),
+ /* translators: %s: the human time diff. */
+ 'past' => __( '%s ago', 'buddypress' ),
+ 's' => __( 'a few seconds', 'buddypress' ),
+ 'm' => __( 'a minute', 'buddypress' ),
+ /* Translators: %d is the amount of minutes. */
+ 'mm' => __( '%d minutes', 'buddypress' ),
+ 'h' => __( 'an hour', 'buddypress' ),
+ /* Translators: %d is the amount of hours. */
+ 'hh' => __( '%d hours', 'buddypress' ),
+ 'd' => __( 'a day', 'buddypress' ),
+ /* Translators: %d is the amount of days. */
+ 'dd' => __( '%d days', 'buddypress' ),
+ 'M' => __( 'a month', 'buddypress' ),
+ /* Translators: %d is the amount of months. */
+ 'MM' => __( '%d months', 'buddypress' ),
+ 'y' => __( 'a year', 'buddypress' ),
+ /* Translators: %d is the amount of years. */
+ 'yy' => __( '%d years', 'buddypress' ),
+ ),
</ins><span class="cx" style="display: block; padding: 0 10px"> )
</span><span class="cx" style="display: block; padding: 0 10px"> )
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- );
- }
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ )
+ );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> wp_enqueue_script( 'bp-livestamp' );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-
-/**
- * Return moment.js config.
- *
- * @since 2.7.0
- * @deprecated 11.0.0 Soflty deprecated as we're keeping the function into this file
- * to avoid fatal errors if deprecated code is ignored.
- *
- * @return string
- */
-function bp_core_moment_js_config() {
- _deprecated_function( __FUNCTION__, '11.0.0' );
-
- // Grab the locale from the enqueued JS.
- $moment_locale = wp_scripts()->query( 'bp-moment-locale' );
- $moment_locale = substr( $moment_locale->src, strpos( $moment_locale->src, '/moment-js/locale/' ) + 18 );
- $moment_locale = str_replace( '.js', '', $moment_locale );
-
- $inline_js = <<<EOD
-jQuery(function() {
- moment.locale( '{$moment_locale}' );
-});
-EOD;
-
- return $inline_js;
-}
</del></span></pre></div>
<a id="trunksrcbpcoredeprecated110php"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/bp-core/deprecated/11.0.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/bp-core/deprecated/11.0.php 2023-07-20 03:07:17 UTC (rev 13522)
+++ trunk/src/bp-core/deprecated/11.0.php 2023-07-22 07:22:41 UTC (rev 13523)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -91,3 +91,13 @@
</span><span class="cx" style="display: block; padding: 0 10px"> _deprecated_function( __FUNCTION__, '11.0.0', 'bp_attachments_get_mime_type()' );
</span><span class="cx" style="display: block; padding: 0 10px"> return bp_attachments_get_mime_type( $file );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+/**
+ * Return moment.js config.
+ *
+ * @since 2.7.0
+ * @deprecated 11.0.0
+ */
+function bp_core_moment_js_config() {
+ _deprecated_function( __FUNCTION__, '11.0.0' );
+}
</ins></span></pre></div>
<a id="trunksrcbpcorejsvendorlivestampjs"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/bp-core/js/vendor/livestamp.js</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/bp-core/js/vendor/livestamp.js 2023-07-20 03:07:17 UTC (rev 13522)
+++ trunk/src/bp-core/js/vendor/livestamp.js 2023-07-22 07:22:41 UTC (rev 13523)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1,5 +1,13 @@
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-// Livestamp.js / v1.1.2 / (c) 2012 Matt Bradley / MIT License
-(function($, moment) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+// Livestamp.js / v2.0.0 / (c) 2015 Matt Bradley / MIT License
+(function (plugin) {
+ if (typeof define === 'function' && define.amd) {
+ // AMD. Register as an anonymous module.
+ define(['jquery', 'moment'], plugin);
+ } else {
+ // Browser globals
+ plugin(jQuery, moment);
+ }
+}(function($, moment) {
</ins><span class="cx" style="display: block; padding: 0 10px"> var updateInterval = 1e3,
</span><span class="cx" style="display: block; padding: 0 10px"> paused = false,
</span><span class="cx" style="display: block; padding: 0 10px"> $livestamps = $([]),
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -60,6 +68,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> });
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $livestamps = $livestamps.not(toRemove);
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ delete $livestamps.prevObject
</ins><span class="cx" style="display: block; padding: 0 10px"> },
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> pause: function() {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -126,4 +135,4 @@
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> return livestampLocal[method](this, options);
</span><span class="cx" style="display: block; padding: 0 10px"> };
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-})(jQuery, moment);
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+}));
</ins></span></pre>
</div>
</div>
</body>
</html>