From 30883c26bdceb9eaf32c8d4a1b0c1bce223b5226 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 17 Apr 2024 09:57:26 +0200 Subject: Adding upstream version 6.5+dfsg1. Signed-off-by: Daniel Baumann --- wp-admin/includes/plugin-install.php | 175 ++++++++++++++++++++++++++++++----- 1 file changed, 154 insertions(+), 21 deletions(-) (limited to 'wp-admin/includes/plugin-install.php') 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() { ?> - + \n"; // #plugin-information-scrollable echo "\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( + '%s', + 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 '' . __( 'Install Now' ) . ''; + if ( $compatible_php && $compatible_wp && $all_plugin_dependencies_installed && ! empty( $data->download_link ) ) { + $button = sprintf( + '%s', + 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( - '', - _x( 'Cannot Install', 'plugin' ) + $button = sprintf( + '', + _x( 'Install Now', 'plugin' ) ); } } break; + case 'update_available': if ( $status['url'] ) { - if ( $compatible_php ) { - echo '' . __( 'Install Update Now' ) . ''; + if ( $compatible_php && $compatible_wp ) { + $button = sprintf( + '%s', + 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( - '', - _x( 'Cannot Update', 'plugin' ) + $button = sprintf( + '', + _x( 'Update Now', 'plugin' ) ); } } break; - case 'newer_installed': - /* translators: %s: Plugin version. */ - echo '' . sprintf( __( 'Newer Version (%s) Installed' ), esc_html( $status['version'] ) ) . ''; - break; + case 'latest_installed': - echo '' . __( 'Latest Version Installed' ) . ''; + case 'newer_installed': + if ( is_plugin_active( $status['file'] ) ) { + $button = sprintf( + '', + _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( + '%6$s', + 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( + '', + is_network_admin() ? _x( 'Network Activate', 'plugin' ) : _x( 'Activate', 'plugin' ) + ); + } + } else { + $button = sprintf( + '', + _x( 'Installed', 'plugin' ) + ); + } break; } - } - echo "\n"; - iframe_footer(); - exit; + return $button; + } } -- cgit v1.2.3