Skip to content

Commit fa21528

Browse files
committed
Administration: Use wp_admin_notice() in /wp-admin/includes.
Add usages of `wp_admin_notice()` and `wp_get_admin_notice()` on `.notice-[type]` in the root level of `/wp-admin/includes`. Ongoing task to implement new function across core. Props costdev, joedolson. See #57791. git-svn-id: https://develop.svn.wordpress.org/trunk@56571 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 3cefc7c commit fa21528

13 files changed

Lines changed: 185 additions & 116 deletions

src/wp-admin/includes/class-custom-background.php

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -239,21 +239,24 @@ public function admin_page() {
239239
<div class="wrap" id="custom-background">
240240
<h1><?php _e( 'Custom Background' ); ?></h1>
241241

242-
<?php if ( current_user_can( 'customize' ) ) { ?>
243-
<div class="notice notice-info hide-if-no-customize">
244-
<p>
245-
<?php
246-
printf(
242+
<?php
243+
if ( current_user_can( 'customize' ) ) {
244+
$message = sprintf(
247245
/* translators: %s: URL to background image configuration in Customizer. */
248246
__( 'You can now manage and live-preview Custom Backgrounds in the <a href="%s">Customizer</a>.' ),
249247
admin_url( 'customize.php?autofocus[control]=background_image' )
250248
);
251-
?>
252-
</p>
253-
</div>
254-
<?php } ?>
249+
wp_admin_notice(
250+
$message,
251+
array(
252+
'type' => 'info',
253+
'additional_classes' => array( 'hide-if-no-customize' ),
254+
)
255+
);
256+
}
255257

256-
<?php if ( ! empty( $this->updated ) ) { ?>
258+
if ( ! empty( $this->updated ) ) {
259+
?>
257260
<div id="message" class="updated">
258261
<p>
259262
<?php

src/wp-admin/includes/class-custom-image-header.php

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -509,19 +509,22 @@ public function step_1() {
509509
<div class="wrap">
510510
<h1><?php _e( 'Custom Header' ); ?></h1>
511511

512-
<?php if ( current_user_can( 'customize' ) ) { ?>
513-
<div class="notice notice-info hide-if-no-customize">
514-
<p>
515-
<?php
516-
printf(
512+
<?php
513+
if ( current_user_can( 'customize' ) ) {
514+
$message = sprintf(
517515
/* translators: %s: URL to header image configuration in Customizer. */
518516
__( 'You can now manage and live-preview Custom Header in the <a href="%s">Customizer</a>.' ),
519517
admin_url( 'customize.php?autofocus[control]=header_image' )
520518
);
521-
?>
522-
</p>
523-
</div>
524-
<?php } ?>
519+
wp_admin_notice(
520+
$message,
521+
array(
522+
'type' => 'info',
523+
'additional_classes' => array( 'hide-if-no-customize' ),
524+
)
525+
);
526+
}
527+
?>
525528

526529
<?php if ( ! empty( $this->updated ) ) { ?>
527530
<div id="message" class="updated">

src/wp-admin/includes/class-wp-plugin-install-list-table.php

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -686,52 +686,59 @@ public function display_rows() {
686686
<div class="plugin-card plugin-card-<?php echo sanitize_html_class( $plugin['slug'] ); ?>">
687687
<?php
688688
if ( ! $compatible_php || ! $compatible_wp ) {
689-
echo '<div class="notice inline notice-error notice-alt"><p>';
689+
$incompatible_notice_message = '';
690690
if ( ! $compatible_php && ! $compatible_wp ) {
691-
_e( 'This plugin does not work with your versions of WordPress and PHP.' );
691+
$incompatible_notice_message .= __( 'This plugin does not work with your versions of WordPress and PHP.' );
692692
if ( current_user_can( 'update_core' ) && current_user_can( 'update_php' ) ) {
693-
printf(
693+
$incompatible_notice_message .= sprintf(
694694
/* translators: 1: URL to WordPress Updates screen, 2: URL to Update PHP page. */
695695
' ' . __( '<a href="%1$s">Please update WordPress</a>, and then <a href="%2$s">learn more about updating PHP</a>.' ),
696696
self_admin_url( 'update-core.php' ),
697697
esc_url( wp_get_update_php_url() )
698698
);
699-
wp_update_php_annotation( '</p><p><em>', '</em>' );
699+
$incompatible_notice_message .= wp_update_php_annotation( '</p><p><em>', '</em>', false );
700700
} elseif ( current_user_can( 'update_core' ) ) {
701-
printf(
701+
$incompatible_notice_message .= sprintf(
702702
/* translators: %s: URL to WordPress Updates screen. */
703703
' ' . __( '<a href="%s">Please update WordPress</a>.' ),
704704
self_admin_url( 'update-core.php' )
705705
);
706706
} elseif ( current_user_can( 'update_php' ) ) {
707-
printf(
707+
$incompatible_notice_message .= sprintf(
708708
/* translators: %s: URL to Update PHP page. */
709709
' ' . __( '<a href="%s">Learn more about updating PHP</a>.' ),
710710
esc_url( wp_get_update_php_url() )
711711
);
712-
wp_update_php_annotation( '</p><p><em>', '</em>' );
712+
$incompatible_notice_message .= wp_update_php_annotation( '</p><p><em>', '</em>', false );
713713
}
714714
} elseif ( ! $compatible_wp ) {
715-
_e( 'This plugin does not work with your version of WordPress.' );
715+
$incompatible_notice_message .= __( 'This plugin does not work with your version of WordPress.' );
716716
if ( current_user_can( 'update_core' ) ) {
717-
printf(
717+
$incompatible_notice_message .= printf(
718718
/* translators: %s: URL to WordPress Updates screen. */
719719
' ' . __( '<a href="%s">Please update WordPress</a>.' ),
720720
self_admin_url( 'update-core.php' )
721721
);
722722
}
723723
} elseif ( ! $compatible_php ) {
724-
_e( 'This plugin does not work with your version of PHP.' );
724+
$incompatible_notice_message .= __( 'This plugin does not work with your version of PHP.' );
725725
if ( current_user_can( 'update_php' ) ) {
726-
printf(
726+
$incompatible_notice_message .= sprintf(
727727
/* translators: %s: URL to Update PHP page. */
728728
' ' . __( '<a href="%s">Learn more about updating PHP</a>.' ),
729729
esc_url( wp_get_update_php_url() )
730730
);
731-
wp_update_php_annotation( '</p><p><em>', '</em>' );
731+
$incompatible_notice_message .= wp_update_php_annotation( '</p><p><em>', '</em>', false );
732732
}
733733
}
734-
echo '</p></div>';
734+
735+
wp_admin_notice(
736+
$incompatible_notice_message,
737+
array(
738+
'type' => 'error',
739+
'additional_classes' => array( 'notice-alt', 'inline' ),
740+
)
741+
);
735742
}
736743
?>
737744
<div class="plugin-card-top">

src/wp-admin/includes/class-wp-plugins-list-table.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1243,7 +1243,14 @@ public function single_row( $item ) {
12431243
*/
12441244
echo apply_filters( 'plugin_auto_update_setting_html', $html, $plugin_file, $plugin_data );
12451245

1246-
echo '<div class="notice notice-error notice-alt inline hidden"><p></p></div>';
1246+
wp_admin_notice(
1247+
'',
1248+
array(
1249+
'type' => 'error',
1250+
'additional_classes' => array( 'notice-alt', 'inline', 'hidden' ),
1251+
)
1252+
);
1253+
12471254
echo '</td>';
12481255

12491256
break;

src/wp-admin/includes/class-wp-posts-list-table.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2076,9 +2076,16 @@ public function inline_edit() {
20762076
<input type="hidden" name="post_author" value="<?php echo esc_attr( $post->post_author ); ?>" />
20772077
<?php endif; ?>
20782078

2079-
<div class="notice notice-error notice-alt inline hidden">
2080-
<p class="error"></p>
2081-
</div>
2079+
<?php
2080+
wp_admin_notice(
2081+
'<p class="error"></p>',
2082+
array(
2083+
'type' => 'error',
2084+
'additional_classes' => array( 'notice-alt', 'inline', 'hidden' ),
2085+
'paragraph_wrap' => false,
2086+
)
2087+
);
2088+
?>
20822089
</div>
20832090
</div> <!-- end of .inline-edit-wrapper -->
20842091

src/wp-admin/includes/class-wp-privacy-policy-content.php

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -352,22 +352,20 @@ public static function notice( $post = null ) {
352352
'after'
353353
);
354354
} else {
355-
?>
356-
<div class="notice notice-warning inline wp-pp-notice">
357-
<p>
358-
<?php
359-
echo $message;
360-
printf(
361-
' <a href="%s" target="_blank">%s <span class="screen-reader-text">%s</span></a>',
362-
$url,
363-
$label,
364-
/* translators: Hidden accessibility text. */
365-
__( '(opens in a new tab)' )
366-
);
367-
?>
368-
</p>
369-
</div>
370-
<?php
355+
$message .= sprintf(
356+
' <a href="%s" target="_blank">%s <span class="screen-reader-text">%s</span></a>',
357+
$url,
358+
$label,
359+
/* translators: Hidden accessibility text. */
360+
__( '(opens in a new tab)' )
361+
);
362+
wp_admin_notice(
363+
$message,
364+
array(
365+
'type' => 'warning',
366+
'additional_classes' => array( 'inline', 'wp-pp-notice' ),
367+
)
368+
);
371369
}
372370
}
373371

@@ -394,8 +392,14 @@ public static function privacy_policy_guide() {
394392
$badge_title = sprintf( __( 'Removed %s.' ), $date );
395393

396394
/* translators: %s: Date of plugin deactivation. */
397-
$removed = __( 'You deactivated this plugin on %s and may no longer need this policy.' );
398-
$removed = '<div class="notice notice-info inline"><p>' . sprintf( $removed, $date ) . '</p></div>';
395+
$removed = sprintf( __( 'You deactivated this plugin on %s and may no longer need this policy.' ), $date );
396+
$removed = wp_get_admin_notice(
397+
$removed,
398+
array(
399+
'type' => 'info',
400+
'additional_classes' => array( 'inline' ),
401+
)
402+
);
399403
} elseif ( ! empty( $section['updated'] ) ) {
400404
$badge_class = ' blue';
401405
$date = date_i18n( $date_format, $section['updated'] );

src/wp-admin/includes/class-wp-terms-list-table.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -711,9 +711,16 @@ public function inline_edit() {
711711
<input type="hidden" name="taxonomy" value="<?php echo esc_attr( $this->screen->taxonomy ); ?>" />
712712
<input type="hidden" name="post_type" value="<?php echo esc_attr( $this->screen->post_type ); ?>" />
713713

714-
<div class="notice notice-error notice-alt inline hidden">
715-
<p class="error"></p>
716-
</div>
714+
<?php
715+
wp_admin_notice(
716+
'<p class="error"></p>',
717+
array(
718+
'type' => 'error',
719+
'additional_classes' => array( 'notice-alt', 'inline', 'hidden' ),
720+
'paragraph_wrap' => false,
721+
)
722+
);
723+
?>
717724
</div>
718725
</div>
719726

src/wp-admin/includes/meta-boxes.php

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -311,25 +311,24 @@ function post_submit_meta_box( $post, $args = array() ) {
311311
endif;
312312

313313
if ( 'draft' === $post->post_status && get_post_meta( $post_id, '_customize_changeset_uuid', true ) ) :
314-
?>
315-
<div class="notice notice-info notice-alt inline">
316-
<p>
317-
<?php
318-
printf(
319-
/* translators: %s: URL to the Customizer. */
320-
__( 'This draft comes from your <a href="%s">unpublished customization changes</a>. You can edit, but there is no need to publish now. It will be published automatically with those changes.' ),
321-
esc_url(
322-
add_query_arg(
323-
'changeset_uuid',
324-
rawurlencode( get_post_meta( $post_id, '_customize_changeset_uuid', true ) ),
325-
admin_url( 'customize.php' )
326-
)
327-
)
328-
);
329-
?>
330-
</p>
331-
</div>
332-
<?php
314+
$message = sprintf(
315+
/* translators: %s: URL to the Customizer. */
316+
__( 'This draft comes from your <a href="%s">unpublished customization changes</a>. You can edit, but there is no need to publish now. It will be published automatically with those changes.' ),
317+
esc_url(
318+
add_query_arg(
319+
'changeset_uuid',
320+
rawurlencode( get_post_meta( $post_id, '_customize_changeset_uuid', true ) ),
321+
admin_url( 'customize.php' )
322+
)
323+
)
324+
);
325+
wp_admin_notice(
326+
$message,
327+
array(
328+
'type' => 'info',
329+
'additional_classes' => array( 'notice-alt', 'inline' ),
330+
)
331+
);
333332
endif;
334333

335334
/**

src/wp-admin/includes/plugin-install.php

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -817,37 +817,54 @@ function install_plugin_information() {
817817
$tested_wp = ( empty( $api->tested ) || version_compare( get_bloginfo( 'version' ), $api->tested, '<=' ) );
818818

819819
if ( ! $compatible_php ) {
820-
echo '<div class="notice notice-error notice-alt"><p>';
821-
_e( '<strong>Error:</strong> This plugin <strong>requires a newer version of PHP</strong>.' );
820+
$compatible_php_notice_message = '<p>';
821+
$compatible_php_notice_message .= __( '<strong>Error:</strong> This plugin <strong>requires a newer version of PHP</strong>.' );
822+
822823
if ( current_user_can( 'update_php' ) ) {
823-
printf(
824+
$compatible_php_notice_message .= sprintf(
824825
/* translators: %s: URL to Update PHP page. */
825826
' ' . __( '<a href="%s" target="_blank">Click here to learn more about updating PHP</a>.' ),
826827
esc_url( wp_get_update_php_url() )
827-
);
828-
829-
wp_update_php_annotation( '</p><p><em>', '</em>' );
828+
) . wp_update_php_annotation( '</p><p><em>', '</em>', false );
830829
} else {
831-
echo '</p>';
830+
$compatible_php_notice_message .= '</p>';
832831
}
833-
echo '</div>';
832+
833+
wp_admin_notice(
834+
$compatible_php_notice_message,
835+
array(
836+
'type' => 'error',
837+
'additional_classes' => array( 'notice-alt' ),
838+
'paragraph_wrap' => false,
839+
)
840+
);
834841
}
835842

836843
if ( ! $tested_wp ) {
837-
echo '<div class="notice notice-warning notice-alt"><p>';
838-
_e( '<strong>Warning:</strong> This plugin <strong>has not been tested</strong> with your current version of WordPress.' );
839-
echo '</p></div>';
844+
wp_admin_notice(
845+
__( '<strong>Warning:</strong> This plugin <strong>has not been tested</strong> with your current version of WordPress.' ),
846+
array(
847+
'type' => 'warning',
848+
'additional_classes' => array( 'notice-alt' ),
849+
)
850+
);
840851
} elseif ( ! $compatible_wp ) {
841-
echo '<div class="notice notice-error notice-alt"><p>';
842-
_e( '<strong>Error:</strong> This plugin <strong>requires a newer version of WordPress</strong>.' );
852+
$compatible_wp_notice_message = __( '<strong>Error:</strong> This plugin <strong>requires a newer version of WordPress</strong>.' );
843853
if ( current_user_can( 'update_core' ) ) {
844-
printf(
854+
$compatible_wp_notice_message .= sprintf(
845855
/* translators: %s: URL to WordPress Updates screen. */
846856
' ' . __( '<a href="%s" target="_parent">Click here to update WordPress</a>.' ),
847857
esc_url( self_admin_url( 'update-core.php' ) )
848858
);
849859
}
850-
echo '</p></div>';
860+
861+
wp_admin_notice(
862+
$compatible_wp_notice_message,
863+
array(
864+
'type' => 'error',
865+
'additional_classes' => array( 'notice-alt' ),
866+
)
867+
);
851868
}
852869

853870
foreach ( (array) $api->sections as $section_name => $content ) {

0 commit comments

Comments
 (0)