Changeset 57545 for trunk/src/wp-admin/includes/plugin-install.php
- Timestamp:
- 02/06/2024 11:44:09 PM (9 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-admin/includes/plugin-install.php
r56571 r57545 885 885 echo "<div id='$tab-footer'>\n"; 886 886 if ( ! empty( $api->download_link ) && ( current_user_can( 'install_plugins' ) || current_user_can( 'update_plugins' ) ) ) { 887 $status = install_plugin_install_status( $api ); 887 $button = wp_get_plugin_action_button( $api->name, $api, $compatible_php, $compatible_wp ); 888 $button = str_replace( 'class="', 'class="right ', $button ); 889 890 if ( ! str_contains( $button, __( 'Activate' ) ) ) { 891 $button = str_replace( 'class="', 'id="plugin_install_from_iframe" class="', $button ); 892 } 893 894 echo wp_kses_post( $button ); 895 } 896 echo "</div>\n"; 897 898 wp_print_request_filesystem_credentials_modal(); 899 wp_print_admin_notice_templates(); 900 901 iframe_footer(); 902 exit; 903 } 904 905 /** 906 * Gets the markup for the plugin install action button. 907 * 908 * @since 6.5.0 909 * 910 * @param string $name Plugin name. 911 * @param array|object $data { 912 * An array or object of plugin data. Can be retrieved from the API. 913 * 914 * @type string $slug The plugin slug. 915 * @type string[] $requires_plugins An array of plugin dependency slugs. 916 * @type string $version The plugin's version string. Used when getting the install status. 917 * } 918 * @param bool $compatible_php The result of a PHP compatibility check. 919 * @param bool $compatible_wp The result of a WP compatibility check. 920 * @return string $button The markup for the dependency row button. 921 */ 922 function wp_get_plugin_action_button( $name, $data, $compatible_php, $compatible_wp ) { 923 $button = ''; 924 $data = (object) $data; 925 $status = install_plugin_install_status( $data ); 926 $requires_plugins = $data->requires_plugins ?? array(); 927 928 // Determine the status of plugin dependencies. 929 $installed_plugins = get_plugins(); 930 $active_plugins = get_option( 'active_plugins' ); 931 $plugin_dependencies_count = count( $requires_plugins ); 932 $installed_plugin_dependencies_count = 0; 933 $active_plugin_dependencies_count = 0; 934 foreach ( $requires_plugins as $dependency ) { 935 foreach ( array_keys( $installed_plugins ) as $installed_plugin_file ) { 936 if ( str_contains( $installed_plugin_file, '/' ) && explode( '/', $installed_plugin_file )[0] === $dependency ) { 937 ++$installed_plugin_dependencies_count; 938 } 939 } 940 941 foreach ( $active_plugins as $active_plugin_file ) { 942 if ( str_contains( $active_plugin_file, '/' ) && explode( '/', $active_plugin_file )[0] === $dependency ) { 943 ++$active_plugin_dependencies_count; 944 } 945 } 946 } 947 $all_plugin_dependencies_installed = $installed_plugin_dependencies_count === $plugin_dependencies_count; 948 $all_plugin_dependencies_active = $active_plugin_dependencies_count === $plugin_dependencies_count; 949 950 sprintf( 951 '<a class="install-now button" data-slug="%s" href="%s" aria-label="%s" data-name="%s">%s</a>', 952 esc_attr( $data->slug ), 953 esc_url( $status['url'] ), 954 /* translators: %s: Plugin name and version. */ 955 esc_attr( sprintf( _x( 'Install %s now', 'plugin' ), $name ) ), 956 esc_attr( $name ), 957 __( 'Install Now' ) 958 ); 959 960 if ( current_user_can( 'install_plugins' ) || current_user_can( 'update_plugins' ) ) { 888 961 switch ( $status['status'] ) { 889 962 case 'install': 890 963 if ( $status['url'] ) { 891 if ( $compatible_php && $compatible_wp ) { 892 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>'; 964 if ( $compatible_php && $compatible_wp && $all_plugin_dependencies_installed && ! empty( $data->download_link ) ) { 965 $button = sprintf( 966 '<a class="install-now button" data-slug="%s" href="%s" aria-label="%s" data-name="%s">%s</a>', 967 esc_attr( $data->slug ), 968 esc_url( $status['url'] ), 969 /* translators: %s: Plugin name and version. */ 970 esc_attr( sprintf( _x( 'Install %s now', 'plugin' ), $name ) ), 971 esc_attr( $name ), 972 __( 'Install Now' ) 973 ); 893 974 } else { 894 printf(895 '<button type="button" class=" button button-primary button-disabled right" disabled="disabled">%s</button>',896 _x( ' Cannot Install', 'plugin' )975 $button = sprintf( 976 '<button type="button" class="install-now button button-disabled" disabled="disabled">%s</button>', 977 _x( 'Install Now', 'plugin' ) 897 978 ); 898 979 } 899 980 } 900 981 break; 982 901 983 case 'update_available': 902 984 if ( $status['url'] ) { 903 if ( $compatible_php ) { 904 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>'; 985 if ( $compatible_php && $compatible_wp ) { 986 $button = sprintf( 987 '<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>', 988 esc_attr( $status['file'] ), 989 esc_attr( $data->slug ), 990 esc_url( $status['url'] ), 991 /* translators: %s: Plugin name and version. */ 992 esc_attr( sprintf( _x( 'Update %s now', 'plugin' ), $name ) ), 993 esc_attr( $name ), 994 __( 'Update Now' ) 995 ); 905 996 } else { 906 printf(907 '<button type="button" class="button button- primary button-disabled right" disabled="disabled">%s</button>',908 _x( ' Cannot Update', 'plugin' )997 $button = sprintf( 998 '<button type="button" class="button button-disabled" disabled="disabled">%s</button>', 999 _x( 'Update Now', 'plugin' ) 909 1000 ); 910 1001 } 911 1002 } 912 1003 break; 1004 1005 case 'latest_installed': 913 1006 case 'newer_installed': 914 /* translators: %s: Plugin version. */ 915 echo '<a class="button button-primary right disabled">' . sprintf( __( 'Newer Version (%s) Installed' ), esc_html( $status['version'] ) ) . '</a>'; 1007 if ( is_plugin_active( $status['file'] ) ) { 1008 $button = sprintf( 1009 '<button type="button" class="button button-disabled" disabled="disabled">%s</button>', 1010 _x( 'Active', 'plugin' ) 1011 ); 1012 } elseif ( current_user_can( 'activate_plugin', $status['file'] ) ) { 1013 if ( $compatible_php && $compatible_wp && $all_plugin_dependencies_active ) { 1014 $button_text = __( 'Activate' ); 1015 /* translators: %s: Plugin name. */ 1016 $button_label = _x( 'Activate %s', 'plugin' ); 1017 $activate_url = add_query_arg( 1018 array( 1019 '_wpnonce' => wp_create_nonce( 'activate-plugin_' . $status['file'] ), 1020 'action' => 'activate', 1021 'plugin' => $status['file'], 1022 ), 1023 network_admin_url( 'plugins.php' ) 1024 ); 1025 1026 if ( is_network_admin() ) { 1027 $button_text = __( 'Network Activate' ); 1028 /* translators: %s: Plugin name. */ 1029 $button_label = _x( 'Network Activate %s', 'plugin' ); 1030 $activate_url = add_query_arg( array( 'networkwide' => 1 ), $activate_url ); 1031 } 1032 1033 $button = sprintf( 1034 '<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>', 1035 esc_url( $activate_url ), 1036 esc_attr( $name ), 1037 esc_attr( $data->slug ), 1038 esc_attr( $status['file'] ), 1039 esc_attr( sprintf( $button_label, $name ) ), 1040 $button_text 1041 ); 1042 } else { 1043 $button = sprintf( 1044 '<button type="button" class="button button-disabled" disabled="disabled">%s</button>', 1045 is_network_admin() ? _x( 'Network Activate %s', 'plugin' ) : _x( 'Activate', 'plugin' ) 1046 ); 1047 } 1048 } else { 1049 $button = sprintf( 1050 '<button type="button" class="button button-disabled" disabled="disabled">%s</button>', 1051 _x( 'Installed', 'plugin' ) 1052 ); 1053 } 916 1054 break; 917 case 'latest_installed': 918 echo '<a class="button button-primary right disabled">' . __( 'Latest Version Installed' ) . '</a>'; 919 break; 920 } 921 } 922 echo "</div>\n"; 923 924 iframe_footer(); 925 exit; 1055 } 1056 1057 return $button; 1058 } 926 1059 }
Note: See TracChangeset
for help on using the changeset viewer.