Make WordPress Core


Ignore:
Timestamp:
09/14/2023 02:13:42 AM (9 months ago)
Author:
joedolson
Message:

Administration: Use wp_admin_notice() for .updated.

Add usages of wp_admin_notice() and wp_get_admin_notice() on .updated in the root level of /wp-admin/. Ongoing task to implement new function across core.

Props costdev, joedolson.
See #57791.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/plugins.php

    r56515 r56573  
    619619}
    620620
    621 if ( isset( $_GET['error'] ) ) :
     621if ( isset( $_GET['error'] ) ) {
    622622
    623623    if ( isset( $_GET['main'] ) ) {
     
    640640    }
    641641
    642     ?>
    643     <div id="message" class="error"><p><?php echo $errmsg; ?></p>
    644     <?php
    645 
    646642    if ( ! isset( $_GET['main'] ) && ! isset( $_GET['charsout'] )
    647643        && isset( $_GET['_error_nonce'] ) && wp_verify_nonce( $_GET['_error_nonce'], 'plugin-activation-error_' . $plugin )
     
    656652        );
    657653
    658         ?>
    659         <iframe style="border:0" width="100%" height="70px" src="<?php echo esc_url( $iframe_url ); ?>"></iframe>
    660         <?php
     654        $errmsg .= '<iframe style="border:0" width="100%" height="70px" src="' . esc_url( $iframe_url ) . '"></iframe>';
    661655    }
    662656
    663     ?>
    664     </div>
    665     <?php
    666 elseif ( isset( $_GET['deleted'] ) ) :
     657    wp_admin_notice(
     658        $errmsg,
     659        array(
     660            'id'                 => 'message',
     661            'additional_classes' => array( 'error' ),
     662        )
     663    );
     664
     665} elseif ( isset( $_GET['deleted'] ) ) {
    667666    $delete_result = get_transient( 'plugins_delete_result_' . $user_ID );
    668667    // Delete it once we're done.
    669668    delete_transient( 'plugins_delete_result_' . $user_ID );
    670669
    671     if ( is_wp_error( $delete_result ) ) :
    672         ?>
    673         <div id="message" class="error notice is-dismissible">
    674             <p>
    675                 <?php
    676                 printf(
    677                     /* translators: %s: Error message. */
    678                     __( 'Plugin could not be deleted due to an error: %s' ),
    679                     esc_html( $delete_result->get_error_message() )
    680                 );
    681                 ?>
    682             </p>
    683         </div>
    684         <?php else : ?>
    685         <div id="message" class="updated notice is-dismissible">
    686             <p>
    687                 <?php
    688                 if ( 1 === (int) $_GET['deleted'] ) {
    689                     _e( 'The selected plugin has been deleted.' );
    690                 } else {
    691                     _e( 'The selected plugins have been deleted.' );
    692                 }
    693                 ?>
    694             </p>
    695         </div>
    696     <?php endif; ?>
    697 <?php elseif ( isset( $_GET['activate'] ) ) : ?>
    698     <div id="message" class="updated notice is-dismissible"><p><?php _e( 'Plugin activated.' ); ?></p></div>
    699 <?php elseif ( isset( $_GET['activate-multi'] ) ) : ?>
    700     <div id="message" class="updated notice is-dismissible"><p><?php _e( 'Selected plugins activated.' ); ?></p></div>
    701 <?php elseif ( isset( $_GET['deactivate'] ) ) : ?>
    702     <div id="message" class="updated notice is-dismissible"><p><?php _e( 'Plugin deactivated.' ); ?></p></div>
    703 <?php elseif ( isset( $_GET['deactivate-multi'] ) ) : ?>
    704     <div id="message" class="updated notice is-dismissible"><p><?php _e( 'Selected plugins deactivated.' ); ?></p></div>
    705 <?php elseif ( 'update-selected' === $action ) : ?>
    706     <div id="message" class="updated notice is-dismissible"><p><?php _e( 'All selected plugins are up to date.' ); ?></p></div>
    707 <?php elseif ( isset( $_GET['resume'] ) ) : ?>
    708     <div id="message" class="updated notice is-dismissible"><p><?php _e( 'Plugin resumed.' ); ?></p></div>
    709 <?php elseif ( isset( $_GET['enabled-auto-update'] ) ) : ?>
    710     <div id="message" class="updated notice is-dismissible"><p><?php _e( 'Plugin will be auto-updated.' ); ?></p></div>
    711 <?php elseif ( isset( $_GET['disabled-auto-update'] ) ) : ?>
    712     <div id="message" class="updated notice is-dismissible"><p><?php _e( 'Plugin will no longer be auto-updated.' ); ?></p></div>
    713 <?php elseif ( isset( $_GET['enabled-auto-update-multi'] ) ) : ?>
    714     <div id="message" class="updated notice is-dismissible"><p><?php _e( 'Selected plugins will be auto-updated.' ); ?></p></div>
    715 <?php elseif ( isset( $_GET['disabled-auto-update-multi'] ) ) : ?>
    716     <div id="message" class="updated notice is-dismissible"><p><?php _e( 'Selected plugins will no longer be auto-updated.' ); ?></p></div>
    717 <?php endif; ?>
     670    if ( is_wp_error( $delete_result ) ) {
     671        $plugin_not_deleted_message = sprintf(
     672            /* translators: %s: Error message. */
     673            __( 'Plugin could not be deleted due to an error: %s' ),
     674            esc_html( $delete_result->get_error_message() )
     675        );
     676        wp_admin_notice(
     677            $plugin_not_deleted_message,
     678            array(
     679                'id'                 => 'message',
     680                'additional_classes' => array( 'error' ),
     681                'dismissible'        => true,
     682            )
     683        );
     684    } else {
     685        $updated_args = array(
     686            'id'                 => 'message',
     687            'additional_classes' => array( 'updated' ),
     688            'dismissible'        => true,
     689        );
     690        if ( 1 === (int) $_GET['deleted'] ) {
     691            $plugins_deleted_message = __( 'The selected plugin has been deleted.' );
     692        } else {
     693            $plugins_deleted_message = __( 'The selected plugins have been deleted.' );
     694        }
     695        wp_admin_notice( $plugins_deleted_message, $updated_args );
     696    }
     697} elseif ( isset( $_GET['activate'] ) ) {
     698    wp_admin_notice( __( 'Plugin activated.' ), $updated_args );
     699} elseif ( isset( $_GET['activate-multi'] ) ) {
     700    wp_admin_notice( __( 'Selected plugins activated.' ), $updated_args );
     701} elseif ( isset( $_GET['deactivate'] ) ) {
     702    wp_admin_notice( __( 'Plugin deactivated.' ), $updated_args );
     703} elseif ( isset( $_GET['deactivate-multi'] ) ) {
     704    wp_admin_notice( __( 'Selected plugins deactivated.' ), $updated_args );
     705} elseif ( 'update-selected' === $action ) {
     706    wp_admin_notice( __( 'All selected plugins are up to date.' ), $updated_args );
     707} elseif ( isset( $_GET['resume'] ) ) {
     708    wp_admin_notice( __( 'Plugin resumed.' ), $updated_args );
     709} elseif ( isset( $_GET['enabled-auto-update'] ) ) {
     710    wp_admin_notice( __( 'Plugin will be auto-updated.' ), $updated_args );
     711} elseif ( isset( $_GET['disabled-auto-update'] ) ) {
     712    wp_admin_notice( __( 'Plugin will no longer be auto-updated.' ), $updated_args );
     713} elseif ( isset( $_GET['enabled-auto-update-multi'] ) ) {
     714    wp_admin_notice( __( 'Selected plugins will be auto-updated.' ), $updated_args );
     715} elseif ( isset( $_GET['disabled-auto-update-multi'] ) ) {
     716    wp_admin_notice( __( 'Selected plugins will no longer be auto-updated.' ), $updated_args );
     717}
     718?>
    718719
    719720<div class="wrap">
Note: See TracChangeset for help on using the changeset viewer.