Make WordPress Core


Ignore:
Timestamp:
02/06/2024 11:44:09 PM (6 months ago)
Author:
costdev
Message:

Upgrade/Install: Introduce Plugin Dependencies.

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/ajax-actions.php

    r57136 r57545  
    45804580
    45814581/**
     4582 * Handles activating a plugin via AJAX.
     4583 *
     4584 * @since 6.5.0
     4585 */
     4586function wp_ajax_activate_plugin() {
     4587    check_ajax_referer( 'updates' );
     4588
     4589    if ( empty( $_POST['name'] ) || empty( $_POST['slug'] ) || empty( $_POST['plugin'] ) ) {
     4590        wp_send_json_error(
     4591            array(
     4592                'slug'         => '',
     4593                'pluginName'   => '',
     4594                'plugin'       => '',
     4595                'errorCode'    => 'no_plugin_specified',
     4596                'errorMessage' => __( 'No plugin specified.' ),
     4597            )
     4598        );
     4599    }
     4600
     4601    $status = array(
     4602        'activate'   => 'plugin',
     4603        'slug'       => wp_unslash( $_POST['slug'] ),
     4604        'pluginName' => wp_unslash( $_POST['name'] ),
     4605        'plugin'     => wp_unslash( $_POST['plugin'] ),
     4606    );
     4607
     4608    if ( ! current_user_can( 'activate_plugin', $status['plugin'] ) ) {
     4609        $status['errorMessage'] = __( 'Sorry, you are not allowed to activate plugins on this site.' );
     4610        wp_send_json_error( $status );
     4611    }
     4612
     4613    if ( is_plugin_active( $status['plugin'] ) ) {
     4614        $status['errorMessage'] = sprintf(
     4615            /* translators: %s: Plugin name. */
     4616            __( '%s is already active.' ),
     4617            $status['pluginName']
     4618        );
     4619    }
     4620
     4621    $activated = activate_plugin( $status['plugin'] );
     4622
     4623    if ( is_wp_error( $activated ) ) {
     4624        $status['errorMessage'] = $activated->get_error_message();
     4625        wp_send_json_error( $status );
     4626    }
     4627
     4628    wp_send_json_success( $status );
     4629}
     4630
     4631/**
    45824632 * Handles updating a plugin via AJAX.
    45834633 *
Note: See TracChangeset for help on using the changeset viewer.