Skip to content

Commit

Permalink
Upgrade/Install: Introduce Plugin Dependencies.
Browse files Browse the repository at this point in the history
Introduces a new "Requires Plugins" plugin header so that plugin developers can list the slugs of the plugins theirs depends on.

This will inform users of the requirements, and provide links to the WordPress.org Plugins Repository that they can click to install and activate the dependencies first.

Plugins whose requirements are not met cannot be installed or activated, and they will be deactivated automatically if their requirements become unmet.
Plugins that others rely on cannot be deactivated or deleted until their dependent plugins are deactivated or deleted.

In memory of Alex Mills and Alex King.
WordPress Remembers.

Props ahoereth, afragen, alanfuller, alexkingorg, amykamala, anonymized_10690803, apeatling, ashfame, atimmer, audrasjb, aristath, azaozz, batmoo, beaulebens, blobaugh, bobbingwide, boonebgorges, brianhenryie, chanthaboune, chrisdavidmiles, coolmann, costdev, courane01, danielbachhuber, davidperez, dd32, Denis-de-Bernardy, dingo_d, DJPaul, dougal, DrewAPicture, ethitter, filosofo, georgestephanis, giuseppemazzapica-1, goldenapples, griffinjt, hellofromTonya, husobj, ideag, jarednova, jbobich, jbrinley, jltallon, joedolson, johnciacia, johnjamesjacoby, joppuyo, jsmoriss, karmatosed, kebbet, knutsp, kraftbj, kraftner, kurtpayne, lkraav, logikal16, luisherranz, man4toman, markjaquith, matt, mbijon, megphillips91, mikeschinkel, mordauk, morehawes, mrwweb, mte90, mukesh27, mzaweb, nacin, norcross, nvwd, nwjames, obliviousharmony, ocean90, oglekler, paaljoachim, pauldewouters, pbaylies, pbiron, peterwilsoncc, Philipp15b, poena, pogidude, retlehs, rmccue, ryan, sabreuse, sc0ttkclark, scribu, sereedmedia, SergeyBiryukov, ShaneF, shidouhikari, soean, spacedmonkey, stephenh1988, swissspidy, taylorde, tazotodua, threadi, TimothyBlynJacobs, TJNowell, tollmanz, toscho, tropicalista, Viper007Bond, westi, whiteshadow, williamsba1, wpsmith, ZaneMatthew.
Fixes #22316.

git-svn-id: https://develop.svn.wordpress.org/trunk@57545 602fd350-edb4-49c9-b593-d223f7449a82
  • Loading branch information
costdev committed Feb 6, 2024
1 parent 3eb7bd1 commit 2b08a77
Show file tree
Hide file tree
Showing 30 changed files with 4,154 additions and 338 deletions.
681 changes: 559 additions & 122 deletions src/js/_enqueues/wp/updates.js

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions src/wp-admin/admin-ajax.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@
'parse-media-shortcode',
'destroy-sessions',
'install-plugin',
'activate-plugin',
'update-plugin',
'crop-image',
'generate-password',
Expand Down Expand Up @@ -169,6 +170,9 @@

add_action( 'wp_ajax_nopriv_heartbeat', 'wp_ajax_nopriv_heartbeat', 1 );

// Register Plugin Dependencies Ajax calls.
add_action( 'wp_ajax_check_plugin_dependencies', array( 'WP_Plugin_Dependencies', 'check_plugin_dependencies_during_ajax' ) );

$action = $_REQUEST['action'];

if ( is_user_logged_in() ) {
Expand Down
54 changes: 47 additions & 7 deletions src/wp-admin/css/common.css
Original file line number Diff line number Diff line change
Expand Up @@ -1500,14 +1500,32 @@ div.error {
background-color: #f0f6fc;
}

#plugin-information-footer .update-now:not(.button-disabled):before {
color: #d63638;
content: "\f463";
display: inline-block;
font: normal 20px/1 dashicons;
margin: -3px 5px 0 -2px;
speak: never;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
vertical-align: middle;
}

#plugin-information-footer .notice {
margin-top: -5px;
}

.update-message p:before,
.updating-message p:before,
.updated-message p:before,
.import-php .updating-message:before,
.button.updating-message:before,
.button.updated-message:before,
.button.installed:before,
.button.installing:before {
.button.installing:before,
.button.activating-message:before,
.button.activated-message:before {
display: inline-block;
font: normal 20px/1 'dashicons';
-webkit-font-smoothing: antialiased;
Expand Down Expand Up @@ -1544,7 +1562,8 @@ div.error {
.updating-message p:before,
.import-php .updating-message:before,
.button.updating-message:before,
.button.installing:before {
.button.installing:before,
.button.activating-message:before {
color: #d63638;
content: "\f463";
}
Expand All @@ -1554,6 +1573,7 @@ div.error {
.import-php .updating-message:before,
.button.updating-message:before,
.button.installing:before,
.button.activating-message:before,
.plugins .column-auto-updates .dashicons-update.spin,
.theme-overlay .theme-autoupdate .dashicons-update.spin {
animation: rotation 2s infinite linear;
Expand All @@ -1564,6 +1584,7 @@ div.error {
.import-php .updating-message:before,
.button.updating-message:before,
.button.installing:before,
.button.activating-message:before,
.plugins .column-auto-updates .dashicons-update.spin,
.theme-overlay .theme-autoupdate .dashicons-update.spin {
animation: none;
Expand All @@ -1577,7 +1598,8 @@ div.error {
/* Updated icon (check mark). */
.updated-message p:before,
.installed p:before,
.button.updated-message:before {
.button.updated-message:before,
.button.activated-message:before {
color: #68de7c;
content: "\f147";
}
Expand Down Expand Up @@ -1662,19 +1684,37 @@ p.auto-update-status {
.button.updating-message:before,
.button.updated-message:before,
.button.installed:before,
.button.installing:before {
.button.installing:before,
.button.activated-message:before,
.button.activating-message:before {
margin: 3px 5px 0 -2px;
}

.button-primary.updating-message:before {
#plugin-information-footer .button.installed:before,
#plugin-information-footer .button.installing:before,
#plugin-information-footer .button.updating-message:before,
#plugin-information-footer .button.updated-message:before,
#plugin-information-footer .button.activated-message:before,
#plugin-information-footer .button.activating-message:before {
margin: 9px 5px 0 -2px;
}

#plugin-information-footer .button.update-now.updating-message:before {
margin: -3px 5px 0 -2px;
}

.button-primary.updating-message:before,
.button-primary.activating-message:before {
color: #fff;
}

.button-primary.updated-message:before {
.button-primary.updated-message:before,
.button-primary.activated-message:before {
color: #9ec2e6;
}

.button.updated-message {
.button.updated-message,
.button.activated-message {
transition-property: border, background, color;
transition-duration: .05s;
transition-timing-function: ease-in-out;
Expand Down
95 changes: 90 additions & 5 deletions src/wp-admin/css/list-tables.css
Original file line number Diff line number Diff line change
Expand Up @@ -585,8 +585,7 @@ th.sorted.desc:hover .sorting-indicator.asc:before {
z-index: 1;
}

.check-column input:where(:not(:disabled)):hover,
.check-column:hover input:where(:not(:disabled)) {
.check-column .label-covers-full-cell:hover + input:not(:disabled) {
box-shadow: 0 0 0 1px #2271b1;
}

Expand Down Expand Up @@ -1548,10 +1547,96 @@ div.action-links,
line-height: 1.3;
}

.plugin-card .name,
.plugin-card .desc {
margin-left: 148px; /* icon + margin */
margin-right: 128px; /* action links + margin */
margin-inline: 0;
}

.plugin-card .name, .plugin-card .desc > p {
margin-left: 148px;
}

@media (min-width: 1101px) {
.plugin-card .name, .plugin-card .desc > p {
margin-right: 128px;
}
}

@media (min-width: 481px) and (max-width: 781px) {
.plugin-card .name, .plugin-card .desc > p {
margin-right: 128px;
}
}

.plugin-card .column-description {
display: flex;
flex-direction: column;
justify-content: flex-start;
}

.plugin-card .column-description > p {
margin-top: 0;
}

.plugin-card .column-description .authors {
order: 1;
}

.plugin-card .column-description .plugin-dependencies {
order: 2;
}

.plugin-card .column-description p:empty {
display: none;
}

.plugin-card .plugin-dependencies {
background-color: #e5f5fa;
border-left: 3px solid #72aee6;
margin-bottom: .5em;
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: .5em;
column-gap: 1%;
row-gap: .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%;
}
.plugin-card .plugin-dependency .more-details-link {
}
}

.plugins #the-list .required-by,
.plugins #the-list .requires {
margin-top: 1em;
}

.plugin-card .action-links {
Expand Down
50 changes: 50 additions & 0 deletions src/wp-admin/includes/ajax-actions.php
Original file line number Diff line number Diff line change
Expand Up @@ -4578,6 +4578,56 @@ function wp_ajax_install_plugin() {
wp_send_json_success( $status );
}

/**
* Handles activating a plugin via AJAX.
*
* @since 6.5.0
*/
function wp_ajax_activate_plugin() {
check_ajax_referer( 'updates' );

if ( empty( $_POST['name'] ) || empty( $_POST['slug'] ) || empty( $_POST['plugin'] ) ) {
wp_send_json_error(
array(
'slug' => '',
'pluginName' => '',
'plugin' => '',
'errorCode' => 'no_plugin_specified',
'errorMessage' => __( 'No plugin specified.' ),
)
);
}

$status = array(
'activate' => 'plugin',
'slug' => wp_unslash( $_POST['slug'] ),
'pluginName' => wp_unslash( $_POST['name'] ),
'plugin' => wp_unslash( $_POST['plugin'] ),
);

if ( ! current_user_can( 'activate_plugin', $status['plugin'] ) ) {
$status['errorMessage'] = __( 'Sorry, you are not allowed to activate plugins on this site.' );
wp_send_json_error( $status );
}

if ( is_plugin_active( $status['plugin'] ) ) {
$status['errorMessage'] = sprintf(
/* translators: %s: Plugin name. */
__( '%s is already active.' ),
$status['pluginName']
);
}

$activated = activate_plugin( $status['plugin'] );

if ( is_wp_error( $activated ) ) {
$status['errorMessage'] = $activated->get_error_message();
wp_send_json_error( $status );
}

wp_send_json_success( $status );
}

/**
* Handles updating a plugin via AJAX.
*
Expand Down
17 changes: 16 additions & 1 deletion src/wp-admin/includes/class-plugin-upgrader.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,12 @@ public function install( $package, $args = array() ) {
// Force refresh of plugin update information.
wp_clean_plugins_cache( $parsed_args['clear_update_cache'] );

$all_plugin_data = get_option( 'plugin_data', array() );
$plugin_file = $this->new_plugin_data['file'];
unset( $this->new_plugin_data['file'] );
$all_plugin_data[ $plugin_file ] = $this->new_plugin_data;
update_option( 'plugin_data', $all_plugin_data );

if ( $parsed_args['overwrite_package'] ) {
/**
* Fires when the upgrader has successfully overwritten a currently installed
Expand Down Expand Up @@ -482,7 +488,16 @@ public function check_package( $source ) {
foreach ( $files as $file ) {
$info = get_plugin_data( $file, false, false );
if ( ! empty( $info['Name'] ) ) {
$this->new_plugin_data = $info;
$basename = basename( $file );
$dirname = basename( dirname( $file ) );

if ( '.' === $dirname ) {
$plugin_file = $basename;
} else {
$plugin_file = "$dirname/$basename";
}
$this->new_plugin_data = ( $info );
$this->new_plugin_data['file'] = $plugin_file;
break;
}
}
Expand Down
Loading

0 comments on commit 2b08a77

Please sign in to comment.