Make WordPress Core

Changeset 56671

Timestamp:
09/24/2023 11:58:42 PM (14 months ago)
Author:
joedolson
Message:

Widgets: Add missing no JS notice in Widgets screen.

Add an H1 heading and an admin notice to display on the Widgets screen when JS is not available. Invite the user to either install or activate the Classic Widgets plugin, as that plugin provides basic functionality without JS.

Props afercia, nihar007, huzaifaalmesbah, joedolson, matthewfarlymn, bvreeman22, bosskhj, devmuhib, shailu25, joedolson.
Fixes #58738.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/widgets-form-blocks.php

    r53094 r56671  
    7474?>
    7575
    76 <div id="widgets-editor" class="blocks-widgets-container"></div>
     76<div id="widgets-editor" class="blocks-widgets-container">
     77    <?php // JavaScript is disabled. ?>
     78    <div class="wrap hide-if-js widgets-editor-no-js">
     79        <h1 class="wp-heading-inline"><?php echo esc_html( $title ); ?></h1>
     80        <?php
     81        if ( file_exists( WP_PLUGIN_DIR . '/classic-widgets/classic-widgets.php' ) ) {
     82            // If Classic Widgets is already installed, provide a link to activate the plugin.
     83            $installed           = true;
     84            $plugin_activate_url = wp_nonce_url( 'plugins.php?action=activate&amp;plugin=classic-widgets/classic-widgets.php', 'activate-plugin_classic-widgets/classic-widgets.php' );
     85            $message             = sprintf(
     86                /* translators: %s: Link to activate the Classic Widgets plugin. */
     87                __( 'The block widgets require JavaScript. Please enable JavaScript in your browser settings, or activate the <a href="%s">Classic Widgets plugin</a>.' ),
     88                esc_url( $plugin_activate_url )
     89            );
     90        } else {
     91            // If Classic Widgets is not installed, provide a link to install it.
     92            $installed          = false;
     93            $plugin_install_url = wp_nonce_url( self_admin_url( 'update.php?action=install-plugin&plugin=classic-widgets' ), 'install-plugin_classic-widgets' );
     94            $message            = sprintf(
     95                /* translators: %s: A link to install the Classic Widgets plugin. */
     96                __( 'The block widgets require JavaScript. Please enable JavaScript in your browser settings, or install the <a href="%s">Classic Widgets plugin</a>.' ),
     97                esc_url( $plugin_install_url )
     98            );
     99        }
     100        /**
     101         * Filters the message displayed in the block widget interface when JavaScript is
     102         * not enabled in the browser.
     103         *
     104         * @since 6.4.0
     105         *
     106         * @param string $message The message being displayed.
     107         * @param bool   $installed Whether the Classic Widget plugin is installed.
     108         */
     109        $message = apply_filters( 'block_widgets_no_javascript_message', $message, $installed );
     110        wp_admin_notice(
     111            $message,
     112            array(
     113                'type'               => 'error',
     114                'additional_classes' => array( 'hide-if-js' ),
     115            )
     116        );
     117        ?>
     118    </div>
     119</div>
    77120
    78121<?php
Note: See TracChangeset for help on using the changeset viewer.