Skip to content

Commit

Permalink
More complex notices
Browse files Browse the repository at this point in the history
  • Loading branch information
joedolson committed Oct 8, 2023
1 parent 191191d commit f2524a8
Show file tree
Hide file tree
Showing 3 changed files with 117 additions and 88 deletions.
16 changes: 14 additions & 2 deletions src/wp-admin/includes/image-edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,21 @@ function wp_image_editor( $post_id, $msg = false ) {

if ( $msg ) {
if ( isset( $msg->error ) ) {
$note = "<div class='notice notice-error' role='alert'><p>$msg->error</p></div>";
$note = wp_get_admin_notice(
$msg->error,
array(
'type' => 'error',
'attributes' => array( 'role' => 'alert' ),
)
);
} elseif ( isset( $msg->msg ) ) {
$note = "<div class='notice notice-success' role='alert'><p>$msg->msg</p></div>";
$note = wp_get_admin_notice(
$msg->msg,
array(
'type' => 'success',
'attributes' => array( 'role' => 'alert' ),
)
);
}
}

Expand Down
167 changes: 88 additions & 79 deletions src/wp-admin/includes/update.php
Original file line number Diff line number Diff line change
Expand Up @@ -508,22 +508,20 @@ function wp_plugin_update_row( $file, $plugin_data ) {

$requires_php = isset( $response->requires_php ) ? $response->requires_php : null;
$compatible_php = is_php_version_compatible( $requires_php );
$notice_type = $compatible_php ? 'notice-warning' : 'notice-error';
$notice_type = $compatible_php ? 'warning' : 'error';

printf(
'<tr class="plugin-update-tr%s" id="%s" data-slug="%s" data-plugin="%s">' .
'<td colspan="%s" class="plugin-update colspanchange">' .
'<div class="update-message notice inline %s notice-alt"><p>',
'<td colspan="%s" class="plugin-update colspanchange">',
$active_class,
esc_attr( $plugin_slug . '-update' ),
esc_attr( $plugin_slug ),
esc_attr( $file ),
esc_attr( $wp_list_table->get_column_count() ),
$notice_type
esc_attr( $wp_list_table->get_column_count() )
);

if ( ! current_user_can( 'update_plugins' ) ) {
printf(
$compatibility_notice .= sprintf(
/* translators: 1: Plugin name, 2: Details URL, 3: Additional link attributes, 4: Version number. */
__( 'There is a new version of %1$s available. <a href="%2$s" %3$s>View version %4$s details</a>.' ),
$plugin_name,
Expand All @@ -536,7 +534,7 @@ function wp_plugin_update_row( $file, $plugin_data ) {
esc_attr( $response->new_version )
);
} elseif ( empty( $response->package ) ) {
printf(
$compatibility_notice .= sprintf(
/* translators: 1: Plugin name, 2: Details URL, 3: Additional link attributes, 4: Version number. */
__( 'There is a new version of %1$s available. <a href="%2$s" %3$s>View version %4$s details</a>. <em>Automatic update is unavailable for this plugin.</em>' ),
$plugin_name,
Expand All @@ -550,7 +548,7 @@ function wp_plugin_update_row( $file, $plugin_data ) {
);
} else {
if ( $compatible_php ) {
printf(
$compatibility_notice .= sprintf(
/* translators: 1: Plugin name, 2: Details URL, 3: Additional link attributes, 4: Version number, 5: Update URL, 6: Additional link attributes. */
__( 'There is a new version of %1$s available. <a href="%2$s" %3$s>View version %4$s details</a> or <a href="%5$s" %6$s>update now</a>.' ),
$plugin_name,
Expand All @@ -569,7 +567,7 @@ function wp_plugin_update_row( $file, $plugin_data ) {
)
);
} else {
printf(
$compatibility_notice .= sprintf(
/* translators: 1: Plugin name, 2: Details URL, 3: Additional link attributes, 4: Version number 5: URL to Update PHP page. */
__( 'There is a new version of %1$s available, but it does not work with your version of PHP. <a href="%2$s" %3$s>View version %4$s details</a> or <a href="%5$s">learn more about updating PHP</a>.' ),
$plugin_name,
Expand All @@ -582,42 +580,48 @@ function wp_plugin_update_row( $file, $plugin_data ) {
esc_attr( $response->new_version ),
esc_url( wp_get_update_php_url() )
);
wp_update_php_annotation( '<br><em>', '</em>' );
$compatibility_notice .= wp_update_php_annotation( '<br><em>', '</em>', false );
}
}

/**
* Fires at the end of the update message container in each
* row of the plugins list table.
*
* The dynamic portion of the hook name, `$file`, refers to the path
* of the plugin's primary file relative to the plugins directory.
*
* @since 2.8.0
*
* @param array $plugin_data An array of plugin metadata. See get_plugin_data()
* and the {@see 'plugin_row_meta'} filter for the list
* of possible values.
* @param object $response {
* An object of metadata about the available plugin update.
*
* @type string $id Plugin ID, e.g. `w.org/plugins/[plugin-name]`.
* @type string $slug Plugin slug.
* @type string $plugin Plugin basename.
* @type string $new_version New plugin version.
* @type string $url Plugin URL.
* @type string $package Plugin update package URL.
* @type string[] $icons An array of plugin icon URLs.
* @type string[] $banners An array of plugin banner URLs.
* @type string[] $banners_rtl An array of plugin RTL banner URLs.
* @type string $requires The version of WordPress which the plugin requires.
* @type string $tested The version of WordPress the plugin is tested against.
* @type string $requires_php The version of PHP which the plugin requires.
* }
*/
do_action( "in_plugin_update_message-{$file}", $plugin_data, $response ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores

echo '</p></div></td></tr>';
wp_admin_notice(
/**
* Fires at the end of the update message container in each
* row of the plugins list table.
*
* The dynamic portion of the hook name, `$file`, refers to the path
* of the plugin's primary file relative to the plugins directory.
*
* @since 2.8.0
*
* @param array $plugin_data An array of plugin metadata. See get_plugin_data()
* and the {@see 'plugin_row_meta'} filter for the list
* of possible values.
* @param object $response {
* An object of metadata about the available plugin update.
*
* @type string $id Plugin ID, e.g. `w.org/plugins/[plugin-name]`.
* @type string $slug Plugin slug.
* @type string $plugin Plugin basename.
* @type string $new_version New plugin version.
* @type string $url Plugin URL.
* @type string $package Plugin update package URL.
* @type string[] $icons An array of plugin icon URLs.
* @type string[] $banners An array of plugin banner URLs.
* @type string[] $banners_rtl An array of plugin RTL banner URLs.
* @type string $requires The version of WordPress which the plugin requires.
* @type string $tested The version of WordPress the plugin is tested against.
* @type string $requires_php The version of PHP which the plugin requires.
* }
*/
$compatibility_notice . do_action( "in_plugin_update_message-{$file}", $plugin_data, $response ), // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores,
array(
'type' => $notice_type,
'additional_classes' => array( 'update-message', 'inline', 'notice-alt' ),
'paragraph_wrap' => false,
)
);
echo '</td></tr>';
}
}

Expand Down Expand Up @@ -706,8 +710,7 @@ function wp_theme_update_row( $theme_key, $theme ) {

printf(
'<tr class="plugin-update-tr%s" id="%s" data-slug="%s">' .
'<td colspan="%s" class="plugin-update colspanchange">' .
'<div class="update-message notice inline notice-warning notice-alt"><p>',
'<td colspan="%s" class="plugin-update colspanchange">',
$active,
esc_attr( $theme->get_stylesheet() . '-update' ),
esc_attr( $theme->get_stylesheet() ),
Expand All @@ -716,7 +719,7 @@ function wp_theme_update_row( $theme_key, $theme ) {

if ( $compatible_wp && $compatible_php ) {
if ( ! current_user_can( 'update_themes' ) ) {
printf(
$compatibility_notice .= sprintf(
/* translators: 1: Theme name, 2: Details URL, 3: Additional link attributes, 4: Version number. */
__( 'There is a new version of %1$s available. <a href="%2$s" %3$s>View version %4$s details</a>.' ),
$theme['Name'],
Expand All @@ -729,7 +732,7 @@ function wp_theme_update_row( $theme_key, $theme ) {
$response['new_version']
);
} elseif ( empty( $response['package'] ) ) {
printf(
$compatibility_notice .= sprintf(
/* translators: 1: Theme name, 2: Details URL, 3: Additional link attributes, 4: Version number. */
__( 'There is a new version of %1$s available. <a href="%2$s" %3$s>View version %4$s details</a>. <em>Automatic update is unavailable for this theme.</em>' ),
$theme['Name'],
Expand All @@ -742,7 +745,7 @@ function wp_theme_update_row( $theme_key, $theme ) {
$response['new_version']
);
} else {
printf(
$compatibility_notice .= sprintf(
/* translators: 1: Theme name, 2: Details URL, 3: Additional link attributes, 4: Version number, 5: Update URL, 6: Additional link attributes. */
__( 'There is a new version of %1$s available. <a href="%2$s" %3$s>View version %4$s details</a> or <a href="%5$s" %6$s>update now</a>.' ),
$theme['Name'],
Expand All @@ -763,84 +766,90 @@ function wp_theme_update_row( $theme_key, $theme ) {
}
} else {
if ( ! $compatible_wp && ! $compatible_php ) {
printf(
$compatibility_notice .= sprintf(
/* translators: %s: Theme name. */
__( 'There is a new version of %s available, but it does not work with your versions of WordPress and PHP.' ),
$theme['Name']
);
if ( current_user_can( 'update_core' ) && current_user_can( 'update_php' ) ) {
printf(
$compatibility_notice .= sprintf(
/* translators: 1: URL to WordPress Updates screen, 2: URL to Update PHP page. */
' ' . __( '<a href="%1$s">Please update WordPress</a>, and then <a href="%2$s">learn more about updating PHP</a>.' ),
self_admin_url( 'update-core.php' ),
esc_url( wp_get_update_php_url() )
);
wp_update_php_annotation( '</p><p><em>', '</em>' );
$compatibility_notice .= wp_update_php_annotation( '</p><p><em>', '</em>', false );
} elseif ( current_user_can( 'update_core' ) ) {
printf(
$compatibility_notice .= sprintf(
/* translators: %s: URL to WordPress Updates screen. */
' ' . __( '<a href="%s">Please update WordPress</a>.' ),
self_admin_url( 'update-core.php' )
);
} elseif ( current_user_can( 'update_php' ) ) {
printf(
$compatibility_notice .= sprintf(
/* translators: %s: URL to Update PHP page. */
' ' . __( '<a href="%s">Learn more about updating PHP</a>.' ),
esc_url( wp_get_update_php_url() )
);
wp_update_php_annotation( '</p><p><em>', '</em>' );
$compatibility_notice .= wp_update_php_annotation( '</p><p><em>', '</em>', false );
}
} elseif ( ! $compatible_wp ) {
printf(
$compatibility_notice .= sprintf(
/* translators: %s: Theme name. */
__( 'There is a new version of %s available, but it does not work with your version of WordPress.' ),
$theme['Name']
);
if ( current_user_can( 'update_core' ) ) {
printf(
$compatibility_notice .= sprintf(
/* translators: %s: URL to WordPress Updates screen. */
' ' . __( '<a href="%s">Please update WordPress</a>.' ),
self_admin_url( 'update-core.php' )
);
}
} elseif ( ! $compatible_php ) {
printf(
$compatibility_notice .= sprintf(
/* translators: %s: Theme name. */
__( 'There is a new version of %s available, but it does not work with your version of PHP.' ),
$theme['Name']
);
if ( current_user_can( 'update_php' ) ) {
printf(
$compatibility_notice .= sprintf(
/* translators: %s: URL to Update PHP page. */
' ' . __( '<a href="%s">Learn more about updating PHP</a>.' ),
esc_url( wp_get_update_php_url() )
);
wp_update_php_annotation( '</p><p><em>', '</em>' );
$compatibility_notice .= wp_update_php_annotation( '</p><p><em>', '</em>', false );
}
}
}

/**
* Fires at the end of the update message container in each
* row of the themes list table.
*
* The dynamic portion of the hook name, `$theme_key`, refers to
* the theme slug as found in the WordPress.org themes repository.
*
* @since 3.1.0
*
* @param WP_Theme $theme The WP_Theme object.
* @param array $response {
* An array of metadata about the available theme update.
*
* @type string $new_version New theme version.
* @type string $url Theme URL.
* @type string $package Theme update package URL.
* }
*/
do_action( "in_theme_update_message-{$theme_key}", $theme, $response ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores

echo '</p></div></td></tr>';
wp_admin_notice(
/**
* Fires at the end of the update message container in each
* row of the themes list table.
*
* The dynamic portion of the hook name, `$theme_key`, refers to
* the theme slug as found in the WordPress.org themes repository.
*
* @since 3.1.0
*
* @param WP_Theme $theme The WP_Theme object.
* @param array $response {
* An array of metadata about the available theme update.
*
* @type string $new_version New theme version.
* @type string $url Theme URL.
* @type string $package Theme update package URL.
* }
*/
$compatibility_notice . do_action( "in_theme_update_message-{$theme_key}", $theme, $response ), // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
array(
'type' => 'warning',
'additional_classes' => array( 'update-message', 'inline', 'notice-alt' ),
'paragraph_wrap' => false,
)
);
echo '</td></tr>';
}

/**
Expand Down
22 changes: 15 additions & 7 deletions src/wp-admin/themes.php
Original file line number Diff line number Diff line change
Expand Up @@ -821,13 +821,21 @@ function wp_theme_auto_update_setting_template() {

<# if ( data.hasUpdate ) { #>
<# if ( data.updateResponse.compatibleWP && data.updateResponse.compatiblePHP ) { #>
<div class="update-message notice inline notice-warning notice-alt"><p>
<# if ( data.hasPackage ) { #>
<?php _e( 'New version available. <button class="button-link" type="button">Update now</button>' ); ?>
<# } else { #>
<?php _e( 'New version available.' ); ?>
<# } #>
</p></div>
<?php
$update_available = '<# if ( data.hasPackage ) { #>';
$update_available .= __( 'New version available. <button class="button-link" type="button">Update now</button>' );
$update_available .= '<# } else { #>';
$update_available .= __( 'New version available.' );
$update_available .= '<# } #>';

wp_admin_notice(
$update_available,
array(
'type' => 'warning',
'additional_classes' => array( 'update-message', 'inline', 'notice-alt' ),
)
);
?>
<# } else { #>
<div class="update-message notice inline notice-error notice-alt"><p>
<# if ( ! data.updateResponse.compatibleWP && ! data.updateResponse.compatiblePHP ) { #>
Expand Down

0 comments on commit f2524a8

Please sign in to comment.