Make WordPress Core

Changeset 48925 for branches/5.5


Ignore:
Timestamp:
08/31/2020 10:41:11 PM (6 years ago)
Author:
desrosj
Message:

Script Loader: Add backward compatibility for JavaScript i18n globals and properties deprecated in WordPress 5.5.

The recommended approach for any plugins using these globals or properties is to switch to the newer wp.i18n functions.

In the meantime, this ensures that accessing any of these globals does not break the rest of the code on the page, and an appropriate warning message is logged to the JavaScript console.

Follow-up to: https://core.trac.wordpress.org/query?summary=~wp.i18n&milestone=5.5

Props omarreiss, peterwilsoncc, kbjohnson90, johnbillion, TimothyBlynJacobs, joostdevalk, ocean90, desrosj, SergeyBiryukov.
Merges [48923] to the 5.5 branch.
Fixes #51123.

Location:
branches/5.5
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • branches/5.5

  • branches/5.5/src/js/_enqueues/admin/common.js

    r48650 r48925  
    1717                $window = $( window ),
    1818                $body = $( document.body ),
    19                 __ = wp.i18n.__;
     19                __ = wp.i18n.__,
     20                sprintf = wp.i18n.sprintf;
     21
     22/**
     23 * Throws an error for a deprecated property.
     24 *
     25 * @since 5.5.1
     26 *
     27 * @param {string} propName    The property that was used.
     28 * @param {string} version     The version of WordPress that deprecated the property.
     29 * @param {string} replacement The property that should have been used.
     30 */
     31function deprecatedProperty( propName, version, replacement ) {
     32        var message;
     33
     34        if ( 'undefined' !== typeof replacement ) {
     35                message = sprintf(
     36                        /* translators: 1: Deprecated property name, 2: Version number, 3: Alternative property name. */
     37                        __( '%1$s is deprecated since version %2$s! Use %3$s instead.' ),
     38                        propName,
     39                        version,
     40                        replacement
     41                );
     42        } else {
     43                message = sprintf(
     44                        /* translators: 1: Deprecated property name, 2: Version number. */
     45                        __( '%1$s is deprecated since version %2$s with no alternative available.' ),
     46                        propName,
     47                        version
     48                );
     49        }
     50
     51        window.console.warn( message );
     52}
     53
     54/**
     55 * Deprecate all properties on an object.
     56 *
     57 * @since 5.5.1
     58 *
     59 * @param {string} name       The name of the object, i.e. commonL10n.
     60 * @param {object} l10nObject The object to deprecate the properties on.
     61 *
     62 * @return {object} The object with all its properties deprecated.
     63 */
     64function deprecateL10nObject( name, l10nObject ) {
     65        var deprecatedObject = {};
     66
     67        Object.keys( l10nObject ).forEach( function( key ) {
     68                var prop = l10nObject[ key ];
     69                var propName = name + '.' + key;
     70
     71                if ( 'object' === typeof prop ) {
     72                        Object.defineProperty( deprecatedObject, key, { get: function() {
     73                                deprecatedProperty( propName, '5.5.0', prop.alternative );
     74                                return prop.func();
     75                        } } );
     76                } else {
     77                        Object.defineProperty( deprecatedObject, key, { get: function() {
     78                                deprecatedProperty( propName, '5.5.0', 'wp.i18n' );
     79                                return prop;
     80                        } } );
     81                }
     82        } );
     83
     84        return deprecatedObject;
     85}
     86
     87window.wp.deprecateL10nObject = deprecateL10nObject;
     88
     89/**
     90 * Removed in 5.5.0, needed for back-compatibility.
     91 *
     92 * @since 2.6.0
     93 * @deprecated 5.5.0
     94 */
     95window.commonL10n = window.commonL10n || {
     96        warnDelete: '',
     97        dismiss: '',
     98        collapseMenu: '',
     99        expandMenu: ''
     100};
     101
     102window.commonL10n = deprecateL10nObject( 'commonL10n', window.commonL10n );
     103
     104/**
     105 * Removed in 5.5.0, needed for back-compatibility.
     106 *
     107 * @since 3.3.0
     108 * @deprecated 5.5.0
     109 */
     110window.wpPointerL10n = window.wpPointerL10n || {
     111        dismiss: ''
     112};
     113
     114window.wpPointerL10n = deprecateL10nObject( 'wpPointerL10n', window.wpPointerL10n );
     115
     116/**
     117 * Removed in 5.5.0, needed for back-compatibility.
     118 *
     119 * @since 4.3.0
     120 * @deprecated 5.5.0
     121 */
     122window.userProfileL10n = window.userProfileL10n || {
     123        warn: '',
     124        warnWeak: '',
     125        show: '',
     126        hide: '',
     127        cancel: '',
     128        ariaShow: '',
     129        ariaHide: ''
     130};
     131
     132window.userProfileL10n = deprecateL10nObject( 'userProfileL10n', window.userProfileL10n );
     133
     134/**
     135 * Removed in 5.5.0, needed for back-compatibility.
     136 *
     137 * @since 4.9.6
     138 * @deprecated 5.5.0
     139 */
     140window.privacyToolsL10n = window.privacyToolsL10n || {
     141        noDataFound: '',
     142        foundAndRemoved: '',
     143        noneRemoved: '',
     144        someNotRemoved: '',
     145        removalError: '',
     146        emailSent: '',
     147        noExportFile: '',
     148        exportError: ''
     149};
     150
     151window.privacyToolsL10n = deprecateL10nObject( 'privacyToolsL10n', window.privacyToolsL10n );
     152
     153/**
     154 * Removed in 5.5.0, needed for back-compatibility.
     155 *
     156 * @since 3.6.0
     157 * @deprecated 5.5.0
     158 */
     159window.authcheckL10n = {
     160        beforeunload: ''
     161};
     162
     163window.authcheckL10n = window.authcheckL10n || deprecateL10nObject( 'authcheckL10n', window.authcheckL10n );
     164
     165/**
     166 * Removed in 5.5.0, needed for back-compatibility.
     167 *
     168 * @since 2.8.0
     169 * @deprecated 5.5.0
     170 */
     171window.tagsl10n = {
     172        noPerm: '',
     173        broken: ''
     174};
     175
     176window.tagsl10n = window.tagsl10n || deprecateL10nObject( 'tagsl10n', window.tagsl10n );
     177
     178/**
     179 * Removed in 5.5.0, needed for back-compatibility.
     180 *
     181 * @since 2.5.0
     182 * @deprecated 5.5.0
     183 */
     184window.adminCommentsL10n = window.adminCommentsL10n || {
     185        hotkeys_highlight_first: {
     186                alternative: 'window.adminCommentsSettings.hotkeys_highlight_first',
     187                func: function() { return window.adminCommentsSettings.hotkeys_highlight_first; }
     188        },
     189        hotkeys_highlight_last: {
     190                alternative: 'window.adminCommentsSettings.hotkeys_highlight_last',
     191                func: function() { return window.adminCommentsSettings.hotkeys_highlight_last; }
     192        },
     193        replyApprove: '',
     194        reply: '',
     195        warnQuickEdit: '',
     196        warnCommentChanges: '',
     197        docTitleComments: '',
     198        docTitleCommentsCount: ''
     199};
     200
     201window.adminCommentsL10n = deprecateL10nObject( 'adminCommentsL10n', window.adminCommentsL10n );
     202
     203/**
     204 * Removed in 5.5.0, needed for back-compatibility.
     205 *
     206 * @since 2.5.0
     207 * @deprecated 5.5.0
     208 */
     209window.tagsSuggestL10n = window.tagsSuggestL10n || {
     210        tagDelimiter: '',
     211        removeTerm: '',
     212        termSelected: '',
     213        termAdded: '',
     214        termRemoved: ''
     215};
     216
     217window.tagsSuggestL10n = deprecateL10nObject( 'tagsSuggestL10n', window.tagsSuggestL10n );
     218
     219/**
     220 * Removed in 5.5.0, needed for back-compatibility.
     221 *
     222 * @since 3.5.0
     223 * @deprecated 5.5.0
     224 */
     225window.wpColorPickerL10n = window.wpColorPickerL10n || {
     226        clear: '',
     227        clearAriaLabel: '',
     228        defaultString: '',
     229        defaultAriaLabel: '',
     230        pick: '',
     231        defaultLabel: ''
     232};
     233
     234window.wpColorPickerL10n = deprecateL10nObject( 'wpColorPickerL10n', window.wpColorPickerL10n );
     235
     236/**
     237 * Removed in 5.5.0, needed for back-compatibility.
     238 *
     239 * @since 2.7.0
     240 * @deprecated 5.5.0
     241 */
     242window.attachMediaBoxL10n = window.attachMediaBoxL10n || {
     243        error: ''
     244};
     245
     246window.attachMediaBoxL10n = deprecateL10nObject( 'attachMediaBoxL10n', window.attachMediaBoxL10n );
     247
     248/**
     249 * Removed in 5.5.0, needed for back-compatibility.
     250 *
     251 * @since 2.5.0
     252 * @deprecated 5.5.0
     253 */
     254window.postL10n = window.postL10n || {
     255        ok: '',
     256        cancel: '',
     257        publishOn: '',
     258        publishOnFuture: '',
     259        publishOnPast: '',
     260        dateFormat: '',
     261        showcomm: '',
     262        endcomm: '',
     263        publish: '',
     264        schedule: '',
     265        update: '',
     266        savePending: '',
     267        saveDraft: '',
     268        'private': '',
     269        'public': '',
     270        publicSticky: '',
     271        password: '',
     272        privatelyPublished: '',
     273        published: '',
     274        saveAlert: '',
     275        savingText: '',
     276        permalinkSaved: ''
     277};
     278
     279window.postL10n = deprecateL10nObject( 'postL10n', window.postL10n );
     280
     281/**
     282 * Removed in 5.5.0, needed for back-compatibility.
     283 *
     284 * @since 2.7.0
     285 * @deprecated 5.5.0
     286 */
     287window.inlineEditL10n = window.inlineEditL10n || {
     288        error: '',
     289        ntdeltitle: '',
     290        notitle: '',
     291        comma: '',
     292        saved: ''
     293};
     294
     295window.inlineEditL10n = deprecateL10nObject( 'inlineEditL10n', window.inlineEditL10n );
     296
     297/**
     298 * Removed in 5.5.0, needed for back-compatibility.
     299 *
     300 * @since 2.7.0
     301 * @deprecated 5.5.0
     302 */
     303window.plugininstallL10n = window.plugininstallL10n || {
     304        plugin_information: '',
     305        plugin_modal_label: '',
     306        ays: ''
     307};
     308
     309window.plugininstallL10n = deprecateL10nObject( 'plugininstallL10n', window.plugininstallL10n );
     310
     311/**
     312 * Removed in 5.5.0, needed for back-compatibility.
     313 *
     314 * @since 3.0.0
     315 * @deprecated 5.5.0
     316 */
     317window.navMenuL10n = window.navMenuL10n || {
     318        noResultsFound: '',
     319        warnDeleteMenu: '',
     320        saveAlert: '',
     321        untitled: ''
     322};
     323
     324window.navMenuL10n = deprecateL10nObject( 'navMenuL10n', window.navMenuL10n );
     325
     326/**
     327 * Removed in 5.5.0, needed for back-compatibility.
     328 *
     329 * @since 2.5.0
     330 * @deprecated 5.5.0
     331 */
     332window.commentL10n = window.commentL10n || {
     333        submittedOn: '',
     334        dateFormat: ''
     335};
     336
     337window.commentL10n = deprecateL10nObject( 'commentL10n', window.commentL10n );
     338
     339/**
     340 * Removed in 5.5.0, needed for back-compatibility.
     341 *
     342 * @since 2.9.0
     343 * @deprecated 5.5.0
     344 */
     345window.setPostThumbnailL10n = window.setPostThumbnailL10n || {
     346        setThumbnail: '',
     347        saving: '',
     348        error: '',
     349        done: ''
     350};
     351
     352window.setPostThumbnailL10n = deprecateL10nObject( 'setPostThumbnailL10n', window.setPostThumbnailL10n );
    20353
    21354/**
  • branches/5.5/src/js/_enqueues/admin/widgets.js

    r48650 r48925  
    745745
    746746})(jQuery);
     747
     748/**
     749 * Removed in 5.5.0, needed for back-compatibility.
     750 *
     751 * @since 4.9.0
     752 * @deprecated 5.5.0
     753 *
     754 * @type {object}
     755*/
     756wpWidgets.l10n = wpWidgets.l10n || {
     757        save: '',
     758        saved: '',
     759        saveAlert: '',
     760        widgetAdded: ''
     761};
     762
     763wpWidgets.l10n = window.wp.deprecateL10nObject( 'wpWidgets.l10n', wpWidgets.l10n );
  • branches/5.5/src/js/_enqueues/wp/theme-plugin-editor.js

    r48650 r48925  
    10011001        return component;
    10021002})( jQuery );
     1003
     1004/**
     1005 * Removed in 5.5.0, needed for back-compatibility.
     1006 *
     1007 * @since 4.9.0
     1008 * @deprecated 5.5.0
     1009 *
     1010 * @type {object}
     1011 */
     1012wp.themePluginEditor.l10n = wp.themePluginEditor.l10n || {
     1013        saveAlert: '',
     1014        saveError: '',
     1015        lintError: {
     1016                alternative: 'wp.i18n',
     1017                func: function() {
     1018                        return {
     1019                                singular: '',
     1020                                plural: ''
     1021                        };
     1022                }
     1023        }
     1024};
     1025
     1026wp.themePluginEditor.l10n = window.wp.deprecateL10nObject( 'wp.themePluginEditor.l10n', wp.themePluginEditor.l10n );
  • branches/5.5/src/js/_enqueues/wp/updates.js

    r48650 r48925  
    4242         */
    4343        wp.updates = {};
     44
     45        /**
     46         * Removed in 5.5.0, needed for back-compatibility.
     47         *
     48         * @since 4.2.0
     49         * @deprecated 5.5.0
     50         *
     51         * @type {object}
     52         */
     53        wp.updates.l10n = {
     54                searchResults: '',
     55                searchResultsLabel: '',
     56                noPlugins: '',
     57                noItemsSelected: '',
     58                updating: '',
     59                pluginUpdated: '',
     60                themeUpdated: '',
     61                update: '',
     62                updateNow: '',
     63                pluginUpdateNowLabel: '',
     64                updateFailedShort: '',
     65                updateFailed: '',
     66                pluginUpdatingLabel: '',
     67                pluginUpdatedLabel: '',
     68                pluginUpdateFailedLabel: '',
     69                updatingMsg: '',
     70                updatedMsg: '',
     71                updateCancel: '',
     72                beforeunload: '',
     73                installNow: '',
     74                pluginInstallNowLabel: '',
     75                installing: '',
     76                pluginInstalled: '',
     77                themeInstalled: '',
     78                installFailedShort: '',
     79                installFailed: '',
     80                pluginInstallingLabel: '',
     81                themeInstallingLabel: '',
     82                pluginInstalledLabel: '',
     83                themeInstalledLabel: '',
     84                pluginInstallFailedLabel: '',
     85                themeInstallFailedLabel: '',
     86                installingMsg: '',
     87                installedMsg: '',
     88                importerInstalledMsg: '',
     89                aysDelete: '',
     90                aysDeleteUninstall: '',
     91                aysBulkDelete: '',
     92                aysBulkDeleteThemes: '',
     93                deleting: '',
     94                deleteFailed: '',
     95                pluginDeleted: '',
     96                themeDeleted: '',
     97                livePreview: '',
     98                activatePlugin: '',
     99                activateTheme: '',
     100                activatePluginLabel: '',
     101                activateThemeLabel: '',
     102                activateImporter: '',
     103                activateImporterLabel: '',
     104                unknownError: '',
     105                connectionError: '',
     106                nonceError: '',
     107                pluginsFound: '',
     108                noPluginsFound: '',
     109                autoUpdatesEnable: '',
     110                autoUpdatesEnabling: '',
     111                autoUpdatesEnabled: '',
     112                autoUpdatesDisable: '',
     113                autoUpdatesDisabling: '',
     114                autoUpdatesDisabled: '',
     115                autoUpdatesError: ''
     116        };
     117
     118        wp.updates.l10n = window.wp.deprecateL10nObject( 'wp.updates.l10n', wp.updates.l10n );
    44119
    45120        /**
  • branches/5.5/src/wp-includes/script-loader.php

    r48891 r48925  
    10141014        $scripts->add( 'htmlhint-kses', '/wp-includes/js/codemirror/htmlhint-kses.js', array( 'htmlhint' ) );
    10151015        $scripts->add( 'code-editor', "/wp-admin/js/code-editor$suffix.js", array( 'jquery', 'wp-codemirror', 'underscore' ) );
    1016         $scripts->add( 'wp-theme-plugin-editor', "/wp-admin/js/theme-plugin-editor$suffix.js", array( 'wp-util', 'wp-sanitize', 'jquery', 'jquery-ui-core', 'wp-a11y', 'underscore' ) );
     1016        $scripts->add( 'wp-theme-plugin-editor', "/wp-admin/js/theme-plugin-editor$suffix.js", array( 'common', 'wp-util', 'wp-sanitize', 'jquery', 'jquery-ui-core', 'wp-a11y', 'underscore' ) );
    10171017        $scripts->set_translations( 'wp-theme-plugin-editor' );
    10181018
     
    12621262                $scripts->set_translations( 'privacy-tools' );
    12631263
    1264                 $scripts->add( 'updates', "/wp-admin/js/updates$suffix.js", array( 'jquery', 'wp-util', 'wp-a11y', 'wp-sanitize' ), false, 1 );
     1264                $scripts->add( 'updates', "/wp-admin/js/updates$suffix.js", array( 'common', 'jquery', 'wp-util', 'wp-a11y', 'wp-sanitize' ), false, 1 );
    12651265                $scripts->set_translations( 'updates' );
    12661266                did_action( 'init' ) && $scripts->localize(
Note: See TracChangeset for help on using the changeset viewer.