<!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][13373] trunk/src/bp-core: Deprecate `bp-moment` JS dependency in favor of WP's `moment` one</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/13373">13373</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/13373","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>2022-11-24 23:14:42 +0000 (Thu, 24 Nov 2022)</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'>Deprecate `bp-moment` JS dependency in favor of WP's `moment` one
Doing so is taking care of using a fresher version of moment.js (v2.29.4).
Props thomaslhotta, dcavins
Closes https://github.com/buddypress/buddypress/pull/39
Fixes <a href="http://buddypress.trac.wordpress.org/ticket/8766">#8766</a></pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunksrcbpcorebpcorecssjsphp">trunk/src/bp-core/bp-core-cssjs.php</a></li>
<li><a href="#trunksrcbpcoreclassesclassbpadminphp">trunk/src/bp-core/classes/class-bp-admin.php</a></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 2022-11-24 21:33:11 UTC (rev 13372)
+++ trunk/src/bp-core/bp-core-cssjs.php 2022-11-24 23:14:42 UTC (rev 13373)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -19,45 +19,55 @@
</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><ins style="background-color: #dfd; 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 = '';
+
</ins><span class="cx" style="display: block; padding: 0 10px"> /*
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * 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).
</del><ins style="background-color: #dfd; 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.
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $wp_locale = sanitize_file_name( strtolower( get_locale() ) );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 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() ) );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- // 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',
- );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ // 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',
+ );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( isset( $iso_locales[ $wp_locale ] ) ) {
- $locale = $iso_locales[ $wp_locale ];
- } else {
- $locale = $wp_locale;
- }
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( isset( $iso_locales[ $wp_locale ] ) ) {
+ $locale = $iso_locales[ $wp_locale ];
+ } else {
+ $locale = $wp_locale;
+ }
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $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, '-' ) );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $locale = str_replace( '_', '-', $locale );
</ins><span class="cx" style="display: block; padding: 0 10px"> if ( file_exists( buddypress()->core->path . "bp-core/js/vendor/moment-js/locale/{$locale}{$min}.js" ) ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $moment_locale_url = $url . "vendor/moment-js/locale/{$locale}{$min}.js";
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+ /*
+ * 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";
+ }
</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">
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -83,16 +93,29 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 'bp-cover-image' => array( 'file' => "{$url}cover-image{$min}.js", 'dependencies' => array(), 'footer' => true ),
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // Version 2.7.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'bp-moment' => array( 'file' => "{$url}vendor/moment-js/moment{$min}.js", 'dependencies' => array(), 'footer' => true ),
- 'bp-livestamp' => array( 'file' => "{$url}vendor/livestamp{$min}.js", 'dependencies' => array( 'jquery', 'bp-moment' ), 'footer' => true ),
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'bp-livestamp' => array( 'file' => "{$url}vendor/livestamp{$min}.js", 'dependencies' => array( 'jquery', 'moment' ), 'footer' => true ),
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // Version 9.0.
</span><span class="cx" style="display: block; padding: 0 10px"> 'bp-dynamic-widget-block-script' => array( 'file' => "{$url}dynamic-widget-block.js", 'dependencies' => array( 'lodash', 'wp-url' ), '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">- // Version 2.7 - Add Moment.js locale to our $scripts array if we found one.
- if ( isset( $moment_locale_url ) ) {
- $scripts['bp-moment-locale'] = array( 'file' => esc_url( $moment_locale_url ), 'dependencies' => array( 'bp-moment' ), 'footer' => true );
</del><ins style="background-color: #dfd; 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 );
+ }
</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"> /**
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -555,7 +578,41 @@
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> if ( wp_script_is( 'bp-moment-locale', 'registered' ) ) {
</span><span class="cx" style="display: block; padding: 0 10px"> wp_enqueue_script( 'bp-moment-locale' );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- wp_add_inline_script ( 'bp-livestamp', bp_core_moment_js_config() );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 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 is the relative time (eg: 10 minutes ago). */
+ '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><span class="cx" style="display: block; padding: 0 10px"> wp_enqueue_script( 'bp-livestamp' );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -565,10 +622,14 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * Return moment.js config.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @since 2.7.0
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @deprecated 11.0.0 Soflty deprecated as we're keeping the function into this file
+ * to avoid fatal errors if deprecated code is ignored.
</ins><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @return string
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> function bp_core_moment_js_config() {
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ _deprecated_function( __FUNCTION__, '11.0.0' );
+
</ins><span class="cx" style="display: block; padding: 0 10px"> // Grab the locale from the enqueued JS.
</span><span class="cx" style="display: block; padding: 0 10px"> $moment_locale = wp_scripts()->query( 'bp-moment-locale' );
</span><span class="cx" style="display: block; padding: 0 10px"> $moment_locale = substr( $moment_locale->src, strpos( $moment_locale->src, '/moment-js/locale/' ) + 18 );
</span></span></pre></div>
<a id="trunksrcbpcoreclassesclassbpadminphp"></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/classes/class-bp-admin.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/bp-core/classes/class-bp-admin.php 2022-11-24 21:33:11 UTC (rev 13372)
+++ trunk/src/bp-core/classes/class-bp-admin.php 2022-11-24 23:14:42 UTC (rev 13373)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1138,7 +1138,6 @@
</span><span class="cx" style="display: block; padding: 0 10px"> <a href="https://github.com/carhartl/jquery-cookie">jquery.cookie</a>,
</span><span class="cx" style="display: block; padding: 0 10px"> <a href="https://mattbradley.github.io/livestampjs/">Livestamp.js</a>,
</span><span class="cx" style="display: block; padding: 0 10px"> <a href="https://www.mediawiki.org/wiki/MediaWiki">MediaWiki</a>,
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- <a href="https://momentjs.com/">Moment.js</a>,
</del><span class="cx" style="display: block; padding: 0 10px"> <a href="https://wordpress.org">WordPress</a>.
</span><span class="cx" style="display: block; padding: 0 10px"> </p>
</span><span class="cx" style="display: block; padding: 0 10px">
</span></span></pre>
</div>
</div>
</body>
</html>