Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 3 additions & 39 deletions src/wp-admin/css/list-tables.css
Original file line number Diff line number Diff line change
Expand Up @@ -1600,45 +1600,9 @@ div.action-links,
display: none;
}

.plugin-card .notice.plugin-dependencies {
margin: auto 20px 20px;
padding: 15px;
}

.plugin-card .plugin-dependencies-explainer-text {
margin-block: 0;
}

.plugin-card .plugin-dependency {
align-items: center;
display: flex;
flex-wrap: wrap;
margin-top: 0.5em;
column-gap: 1%;
row-gap: 0.5em;
}

.plugin-card .plugin-dependency:nth-child(2),
.plugin-card .plugin-dependency:last-child {
margin-top: 1em;
}

.plugin-card .plugin-dependency-name {
flex-basis: 74%;
}

.plugin-card .plugin-dependency .more-details-link {
margin-left: auto;
}

.rtl .plugin-card .plugin-dependency .more-details-link {
margin-right: auto;
}

@media (max-width: 939px) {
.plugin-card .plugin-dependency-name {
flex-basis: 69%;
}
/* Sits in the card's text flow, directly below the authors line. */
.plugin-card .plugin-dependencies-inline {
margin-bottom: 0;
}

.plugins #the-list .required-by,
Expand Down
57 changes: 30 additions & 27 deletions src/wp-admin/includes/class-wp-plugin-install-list-table.php
Original file line number Diff line number Diff line change
Expand Up @@ -760,14 +760,14 @@ public function display_rows() {
<div class="desc column-description">
<p><?php echo $description; ?></p>
<p class="authors"><?php echo $author; ?></p>
<?php
$dependencies_notice = $this->get_dependencies_notice( $plugin );
if ( ! empty( $dependencies_notice ) ) {
echo $dependencies_notice;
}
?>
</div>
</div>
<?php
$dependencies_notice = $this->get_dependencies_notice( $plugin );
if ( ! empty( $dependencies_notice ) ) {
echo $dependencies_notice;
}
?>
<div class="plugin-card-bottom">
<div class="vers column-rating">
<?php
Expand Down Expand Up @@ -829,24 +829,22 @@ public function display_rows() {
}

/**
* Returns a notice containing a list of dependencies required by the plugin.
* Returns a line of text listing the dependencies required by the plugin.
*
* @since 6.5.0
* @since 7.3.0 The dependencies are listed in a line of text instead of a notice.
*
* @param array $plugin_data An array of plugin data. See {@see plugins_api()}
* for the list of possible values.
* @return string A notice containing a list of dependencies required by the plugin,
* @return string A line of text listing the dependencies required by the plugin,
* or an empty string if none is required.
*/
protected function get_dependencies_notice( $plugin_data ) {
if ( empty( $plugin_data['requires_plugins'] ) ) {
return '';
}

$no_name_markup = '<div class="plugin-dependency"><span class="plugin-dependency-name">%s</span></div>';
$has_name_markup = '<div class="plugin-dependency"><span class="plugin-dependency-name">%s</span> %s</div>';

$dependencies_list = '';
$dependencies = array();
foreach ( $plugin_data['requires_plugins'] as $dependency ) {
$dependency_data = WP_Plugin_Dependencies::get_dependency_data( $dependency );

Expand All @@ -856,41 +854,42 @@ protected function get_dependencies_notice( $plugin_data ) {
! empty( $dependency_data['slug'] ) &&
! empty( $dependency_data['version'] )
) {
$more_details_link = $this->get_more_details_link( $dependency_data['name'], $dependency_data['slug'] );
$dependencies_list .= sprintf( $has_name_markup, esc_html( $dependency_data['name'] ), $more_details_link );
$dependencies[] = $this->get_more_details_link( $dependency_data['name'], $dependency_data['slug'], $dependency_data['name'] );
continue;
}

$result = plugins_api( 'plugin_information', array( 'slug' => $dependency ) );

if ( ! empty( $result->name ) ) {
$more_details_link = $this->get_more_details_link( $result->name, $result->slug );
$dependencies_list .= sprintf( $has_name_markup, esc_html( $result->name ), $more_details_link );
$dependencies[] = $this->get_more_details_link( $result->name, $result->slug, $result->name );
continue;
}

$dependencies_list .= sprintf( $no_name_markup, esc_html( $dependency ) );
$dependencies[] = esc_html( $dependency );
}

$dependencies_notice = sprintf(
'<div class="plugin-dependencies notice notice-alt notice-info inline"><p class="plugin-dependencies-explainer-text">%s</p> %s</div>',
'<strong>' . __( 'Additional plugins are required' ) . '</strong>',
$dependencies_list
return sprintf(
'<p class="plugin-dependencies-inline">%s</p>',
sprintf(
/* translators: %s: List of dependency names. */
_n( 'Requires: %s', 'Requires: %s', count( $dependencies ) ),
implode( wp_get_list_item_separator(), $dependencies )
)
);

return $dependencies_notice;
}

/**
* Creates a 'More details' link for the plugin.
*
* @since 6.5.0
* @since 7.3.0 Added the `$link_text` parameter.
*
* @param string $name The plugin's name.
* @param string $slug The plugin's slug.
* @param string $name The plugin's name.
* @param string $slug The plugin's slug.
* @param string $link_text Optional. The link's text. Default 'More Details'.
* @return string The 'More details' link for the plugin.
*/
protected function get_more_details_link( $name, $slug ) {
protected function get_more_details_link( $name, $slug, $link_text = '' ) {
$url = add_query_arg(
array(
'tab' => 'plugin-information',
Expand All @@ -902,13 +901,17 @@ protected function get_more_details_link( $name, $slug ) {
network_admin_url( 'plugin-install.php' )
);

if ( '' === $link_text ) {
$link_text = __( 'More Details' );
}

$more_details_link = sprintf(
'<a href="%1$s" class="more-details-link thickbox open-plugin-details-modal" aria-label="%2$s" data-title="%3$s">%4$s</a>',
esc_url( $url ),
/* translators: %s: Plugin name. */
sprintf( __( 'More information about %s' ), esc_html( $name ) ),
esc_attr( $name ),
__( 'More Details' )
esc_html( $link_text )
);

return $more_details_link;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,18 @@
class Tests_Admin_wpPluginInstallListTableGetDependenciesNotice extends WP_UnitTestCase {

/**
* The notice before the list of dependencies.
* The start of the line listing the dependencies.
*
* @var string
*/
const NOTICE_START = '<div class="plugin-dependencies notice notice-alt notice-info inline"><p class="plugin-dependencies-explainer-text"><strong>Additional plugins are required</strong></p> ';
const NOTICE_START = '<p class="plugin-dependencies-inline">Requires: ';

/**
* The end of the line listing the dependencies.
*
* @var string
*/
const NOTICE_END = '</p>';

/**
* The list table.
Expand Down Expand Up @@ -88,7 +95,7 @@ public function tear_down() {
}

/**
* Tests that no notice is returned for a plugin without dependencies.
* Tests that nothing is returned for a plugin without dependencies.
*
* @ticket 65819
*
Expand Down Expand Up @@ -129,7 +136,7 @@ public function test_should_name_dependency_from_dependency_data() {
);

$this->assertSame(
self::NOTICE_START . $this->get_named_dependency( 'Dep &lt;b&gt;&amp;&lt;/b&gt; &quot;One&quot;', 'dep-one' ) . '</div>',
self::NOTICE_START . $this->get_named_dependency( 'Dep &lt;b&gt;&amp;&lt;/b&gt; &quot;One&quot;', 'dep-one' ) . self::NOTICE_END,
$this->get_dependencies_notice( array( 'requires_plugins' => array( 'dep-one' ) ) ),
'The dependency should be named from the stored data.'
);
Expand All @@ -153,7 +160,7 @@ public function test_should_use_slug_from_dependency_data() {
);

$this->assertSame(
self::NOTICE_START . $this->get_named_dependency( 'Dep One', 'dep-one-renamed' ) . '</div>',
self::NOTICE_START . $this->get_named_dependency( 'Dep One', 'dep-one-renamed' ) . self::NOTICE_END,
$this->get_dependencies_notice( array( 'requires_plugins' => array( 'dep-one' ) ) )
);
}
Expand All @@ -178,7 +185,7 @@ public function test_should_fall_back_to_plugins_api_for_incomplete_dependency_d
);

$this->assertSame(
self::NOTICE_START . $this->get_named_dependency( 'Dep One From API', 'dep-one' ) . '</div>',
self::NOTICE_START . $this->get_named_dependency( 'Dep One From API', 'dep-one' ) . self::NOTICE_END,
$this->get_dependencies_notice( array( 'requires_plugins' => array( 'dep-one' ) ) ),
'The dependency should be named from the plugins API.'
);
Expand Down Expand Up @@ -218,7 +225,7 @@ public function test_should_use_slug_from_plugins_api() {
);

$this->assertSame(
self::NOTICE_START . $this->get_named_dependency( 'Dep &lt;i&gt;One&lt;/i&gt;', 'renamed-dep' ) . '</div>',
self::NOTICE_START . $this->get_named_dependency( 'Dep &lt;i&gt;One&lt;/i&gt;', 'renamed-dep' ) . self::NOTICE_END,
$this->get_dependencies_notice( array( 'requires_plugins' => array( 'dep-one' ) ) )
);
}
Expand All @@ -241,7 +248,7 @@ public function test_should_list_dependency_by_slug_without_name( $response ) {
);

$this->assertSame(
self::NOTICE_START . '<div class="plugin-dependency"><span class="plugin-dependency-name">dep&lt;one&gt;</span></div></div>',
self::NOTICE_START . 'dep&lt;one&gt;' . self::NOTICE_END,
$this->get_dependencies_notice( array( 'requires_plugins' => array( 'dep<one>' ) ) )
);
}
Expand Down Expand Up @@ -283,9 +290,11 @@ public function test_should_list_all_dependencies_in_order() {
$this->assertSame(
self::NOTICE_START
. $this->get_named_dependency( 'Dep One', 'dep-one' )
. wp_get_list_item_separator()
. $this->get_named_dependency( 'Dep Two', 'dep-two' )
. '<div class="plugin-dependency"><span class="plugin-dependency-name">dep-three</span></div>'
. '</div>',
. wp_get_list_item_separator()
. 'dep-three'
. self::NOTICE_END,
$this->get_dependencies_notice( array( 'requires_plugins' => array( 'dep-one', 'dep-two', 'dep-three' ) ) ),
'Each dependency should be listed in order.'
);
Expand All @@ -303,9 +312,8 @@ private function get_named_dependency( $escaped_name, $slug ) {
$url = 'http://' . WP_TESTS_DOMAIN . '/wp-admin/' . ( is_multisite() ? 'network/' : '' )
. 'plugin-install.php?tab=plugin-information&#038;plugin=' . $slug . '&#038;TB_iframe=true&#038;width=600&#038;height=550';

return '<div class="plugin-dependency"><span class="plugin-dependency-name">' . $escaped_name . '</span> '
. '<a href="' . $url . '" class="more-details-link thickbox open-plugin-details-modal" aria-label="More information about ' . $escaped_name . '" data-title="' . $escaped_name . '">More Details</a>'
. '</div>';
return '<a href="' . $url . '" class="more-details-link thickbox open-plugin-details-modal" aria-label="More information about '
. $escaped_name . '" data-title="' . $escaped_name . '">' . $escaped_name . '</a>';
}

/**
Expand Down
Loading