summaryrefslogtreecommitdiffstats
path: root/wp-admin/includes/plugin-install.php
diff options
context:
space:
mode:
Diffstat (limited to 'wp-admin/includes/plugin-install.php')
-rw-r--r--wp-admin/includes/plugin-install.php175
1 files changed, 154 insertions, 21 deletions
diff --git a/wp-admin/includes/plugin-install.php b/wp-admin/includes/plugin-install.php
index 7662076..a3afbcb 100644
--- a/wp-admin/includes/plugin-install.php
+++ b/wp-admin/includes/plugin-install.php
@@ -361,7 +361,7 @@ function install_plugins_upload() {
?>
</label>
<input type="file" id="pluginzip" name="pluginzip" accept=".zip" />
- <?php submit_button( __( 'Install Now' ), '', 'install-plugin-submit', false ); ?>
+ <?php submit_button( _x( 'Install Now', 'plugin' ), '', 'install-plugin-submit', false ); ?>
</form>
</div>
<?php
@@ -884,43 +884,176 @@ function install_plugin_information() {
echo "</div>\n"; // #plugin-information-scrollable
echo "<div id='$tab-footer'>\n";
if ( ! empty( $api->download_link ) && ( current_user_can( 'install_plugins' ) || current_user_can( 'update_plugins' ) ) ) {
- $status = install_plugin_install_status( $api );
+ $button = wp_get_plugin_action_button( $api->name, $api, $compatible_php, $compatible_wp );
+ $button = str_replace( 'class="', 'class="right ', $button );
+
+ if ( ! str_contains( $button, _x( 'Activate', 'plugin' ) ) ) {
+ $button = str_replace( 'class="', 'id="plugin_install_from_iframe" class="', $button );
+ }
+
+ echo wp_kses_post( $button );
+ }
+ echo "</div>\n";
+
+ wp_print_request_filesystem_credentials_modal();
+ wp_print_admin_notice_templates();
+
+ iframe_footer();
+ exit;
+}
+
+/**
+ * Gets the markup for the plugin install action button.
+ *
+ * @since 6.5.0
+ *
+ * @param string $name Plugin name.
+ * @param array|object $data {
+ * An array or object of plugin data. Can be retrieved from the API.
+ *
+ * @type string $slug The plugin slug.
+ * @type string[] $requires_plugins An array of plugin dependency slugs.
+ * @type string $version The plugin's version string. Used when getting the install status.
+ * }
+ * @param bool $compatible_php The result of a PHP compatibility check.
+ * @param bool $compatible_wp The result of a WP compatibility check.
+ * @return string $button The markup for the dependency row button.
+ */
+function wp_get_plugin_action_button( $name, $data, $compatible_php, $compatible_wp ) {
+ $button = '';
+ $data = (object) $data;
+ $status = install_plugin_install_status( $data );
+ $requires_plugins = $data->requires_plugins ?? array();
+
+ // Determine the status of plugin dependencies.
+ $installed_plugins = get_plugins();
+ $active_plugins = get_option( 'active_plugins', array() );
+ $plugin_dependencies_count = count( $requires_plugins );
+ $installed_plugin_dependencies_count = 0;
+ $active_plugin_dependencies_count = 0;
+ foreach ( $requires_plugins as $dependency ) {
+ foreach ( array_keys( $installed_plugins ) as $installed_plugin_file ) {
+ if ( str_contains( $installed_plugin_file, '/' ) && explode( '/', $installed_plugin_file )[0] === $dependency ) {
+ ++$installed_plugin_dependencies_count;
+ }
+ }
+
+ foreach ( $active_plugins as $active_plugin_file ) {
+ if ( str_contains( $active_plugin_file, '/' ) && explode( '/', $active_plugin_file )[0] === $dependency ) {
+ ++$active_plugin_dependencies_count;
+ }
+ }
+ }
+ $all_plugin_dependencies_installed = $installed_plugin_dependencies_count === $plugin_dependencies_count;
+ $all_plugin_dependencies_active = $active_plugin_dependencies_count === $plugin_dependencies_count;
+
+ sprintf(
+ '<a class="install-now button" data-slug="%s" href="%s" aria-label="%s" data-name="%s">%s</a>',
+ esc_attr( $data->slug ),
+ esc_url( $status['url'] ),
+ /* translators: %s: Plugin name and version. */
+ esc_attr( sprintf( _x( 'Install %s now', 'plugin' ), $name ) ),
+ esc_attr( $name ),
+ _x( 'Install Now', 'plugin' )
+ );
+
+ if ( current_user_can( 'install_plugins' ) || current_user_can( 'update_plugins' ) ) {
switch ( $status['status'] ) {
case 'install':
if ( $status['url'] ) {
- if ( $compatible_php && $compatible_wp ) {
- echo '<a data-slug="' . esc_attr( $api->slug ) . '" id="plugin_install_from_iframe" class="button button-primary right" href="' . $status['url'] . '" target="_parent">' . __( 'Install Now' ) . '</a>';
+ if ( $compatible_php && $compatible_wp && $all_plugin_dependencies_installed && ! empty( $data->download_link ) ) {
+ $button = sprintf(
+ '<a class="install-now button" data-slug="%s" href="%s" aria-label="%s" data-name="%s">%s</a>',
+ esc_attr( $data->slug ),
+ esc_url( $status['url'] ),
+ /* translators: %s: Plugin name and version. */
+ esc_attr( sprintf( _x( 'Install %s now', 'plugin' ), $name ) ),
+ esc_attr( $name ),
+ _x( 'Install Now', 'plugin' )
+ );
} else {
- printf(
- '<button type="button" class="button button-primary button-disabled right" disabled="disabled">%s</button>',
- _x( 'Cannot Install', 'plugin' )
+ $button = sprintf(
+ '<button type="button" class="install-now button button-disabled" disabled="disabled">%s</button>',
+ _x( 'Install Now', 'plugin' )
);
}
}
break;
+
case 'update_available':
if ( $status['url'] ) {
- if ( $compatible_php ) {
- echo '<a data-slug="' . esc_attr( $api->slug ) . '" data-plugin="' . esc_attr( $status['file'] ) . '" id="plugin_update_from_iframe" class="button button-primary right" href="' . $status['url'] . '" target="_parent">' . __( 'Install Update Now' ) . '</a>';
+ if ( $compatible_php && $compatible_wp ) {
+ $button = sprintf(
+ '<a class="update-now button aria-button-if-js" data-plugin="%s" data-slug="%s" href="%s" aria-label="%s" data-name="%s">%s</a>',
+ esc_attr( $status['file'] ),
+ esc_attr( $data->slug ),
+ esc_url( $status['url'] ),
+ /* translators: %s: Plugin name and version. */
+ esc_attr( sprintf( _x( 'Update %s now', 'plugin' ), $name ) ),
+ esc_attr( $name ),
+ _x( 'Update Now', 'plugin' )
+ );
} else {
- printf(
- '<button type="button" class="button button-primary button-disabled right" disabled="disabled">%s</button>',
- _x( 'Cannot Update', 'plugin' )
+ $button = sprintf(
+ '<button type="button" class="button button-disabled" disabled="disabled">%s</button>',
+ _x( 'Update Now', 'plugin' )
);
}
}
break;
- case 'newer_installed':
- /* translators: %s: Plugin version. */
- echo '<a class="button button-primary right disabled">' . sprintf( __( 'Newer Version (%s) Installed' ), esc_html( $status['version'] ) ) . '</a>';
- break;
+
case 'latest_installed':
- echo '<a class="button button-primary right disabled">' . __( 'Latest Version Installed' ) . '</a>';
+ case 'newer_installed':
+ if ( is_plugin_active( $status['file'] ) ) {
+ $button = sprintf(
+ '<button type="button" class="button button-disabled" disabled="disabled">%s</button>',
+ _x( 'Active', 'plugin' )
+ );
+ } elseif ( current_user_can( 'activate_plugin', $status['file'] ) ) {
+ if ( $compatible_php && $compatible_wp && $all_plugin_dependencies_active ) {
+ $button_text = _x( 'Activate', 'plugin' );
+ /* translators: %s: Plugin name. */
+ $button_label = _x( 'Activate %s', 'plugin' );
+ $activate_url = add_query_arg(
+ array(
+ '_wpnonce' => wp_create_nonce( 'activate-plugin_' . $status['file'] ),
+ 'action' => 'activate',
+ 'plugin' => $status['file'],
+ ),
+ network_admin_url( 'plugins.php' )
+ );
+
+ if ( is_network_admin() ) {
+ $button_text = _x( 'Network Activate', 'plugin' );
+ /* translators: %s: Plugin name. */
+ $button_label = _x( 'Network Activate %s', 'plugin' );
+ $activate_url = add_query_arg( array( 'networkwide' => 1 ), $activate_url );
+ }
+
+ $button = sprintf(
+ '<a href="%1$s" data-name="%2$s" data-slug="%3$s" data-plugin="%4$s" class="button button-primary activate-now" aria-label="%5$s">%6$s</a>',
+ esc_url( $activate_url ),
+ esc_attr( $name ),
+ esc_attr( $data->slug ),
+ esc_attr( $status['file'] ),
+ esc_attr( sprintf( $button_label, $name ) ),
+ $button_text
+ );
+ } else {
+ $button = sprintf(
+ '<button type="button" class="button button-disabled" disabled="disabled">%s</button>',
+ is_network_admin() ? _x( 'Network Activate', 'plugin' ) : _x( 'Activate', 'plugin' )
+ );
+ }
+ } else {
+ $button = sprintf(
+ '<button type="button" class="button button-disabled" disabled="disabled">%s</button>',
+ _x( 'Installed', 'plugin' )
+ );
+ }
break;
}
- }
- echo "</div>\n";
- iframe_footer();
- exit;
+ return $button;
+ }
}