Ticket #43992: 43992.10.diff
File 43992.10.diff, 6.4 KB (added by , 4 years ago) |
---|
-
src/wp-admin/includes/plugin.php
diff --git src/wp-admin/includes/plugin.php src/wp-admin/includes/plugin.php index 419ba1659c..6e2371e1f0 100644
31 31 * Network: Optional. Specify "Network: true" to require that a plugin is activated 32 32 * across all sites in an installation. This will prevent a plugin from being 33 33 * activated on a single site when Multisite is enabled. 34 * Requires WP: Optional. Specify the minimum required WordPress version. 35 * Requires PHP: Optional. Specify the minimum required PHP version. 34 36 * * / # Remove the space to close comment 35 37 * 36 38 * Some users have issues with opening large files and manipulating the contents … … 46 48 * reading. 47 49 * 48 50 * @since 1.5.0 51 * @since 5.2.0 Added `RequiresWP` and `RequiresPHP`. 49 52 * 50 53 * @param string $plugin_file Absolute path to the main plugin file. 51 54 * @param bool $markup Optional. If the returned data should have HTML markup applied. … … 63 66 * @type string $TextDomain Plugin textdomain. 64 67 * @type string $DomainPath Plugins relative directory path to .mo files. 65 68 * @type bool $Network Whether the plugin can only be activated network-wide. 69 * @type string $RequiresWP Minimum required version of WordPress. 70 * @type string $RequiresPHP Minimum required version of PHP. 66 71 * } 67 72 */ 68 73 function get_plugin_data( $plugin_file, $markup = true, $translate = true ) { … … function get_plugin_data( $plugin_file, $markup = true, $translate = true ) { 77 82 'TextDomain' => 'Text Domain', 78 83 'DomainPath' => 'Domain Path', 79 84 'Network' => 'Network', 85 'RequiresWP' => 'Requires WP', 86 'RequiresPHP' => 'Requires PHP', 80 87 // Site Wide Only is deprecated in favor of Network. 81 88 '_sitewide' => 'Site Wide Only', 82 89 ); … … function _get_plugin_data_markup_translate( $plugin_file, $plugin_data, $markup 213 220 return $plugin_data; 214 221 } 215 222 223 /** 224 * Get and return plugin data used for validation. 225 * 226 * Initially use the Plugin API as there's no current method to parse the local plugin readme.txt file. 227 * Alternately see if a plugin header `Requires WP` or `Requires PHP` exists and use that. 228 * 229 * @since 5.2.0 230 * @see validate_plugin_requirements() 231 * 232 * @param string $plugin_file Path to the plugin file relative to the plugins directory. 233 * 234 * @return object $plugin_data Object of plugin data for validation. 235 */ 236 function get_plugin_validation_data( $plugin_file ) { 237 $plugin_data = new stdClass(); 238 $slug = dirname( $plugin_file ); 239 $url = 'https://api.wordpress.org/plugins/info/1.2/'; 240 $url = add_query_arg( 241 array( 242 'action' => 'plugin_information', 243 rawurlencode( 'request[slug]' ) => $slug, 244 ), 245 $url 246 ); 247 $response = wp_remote_get( $url ); 248 if ( ! is_wp_error( $response ) ) { 249 $plugin_data = json_decode( wp_remote_retrieve_body( $response ) ); 250 } 251 252 $invalid_check = isset( $plugin_data->error ) || is_wp_error( $response ) || $slug !== $plugin_data->slug; 253 254 /* 255 * Plugin is likley not in the WP Plugin Directory but if they have designated 256 * `Requires WP` and/or `Requires PHP` headers we can use those. 257 */ 258 if ( $invalid_check ) { 259 $plugin_data = new stdClass(); 260 $plugin_data->file = $plugin_file; 261 $plugin_headers = get_plugin_data( WP_PLUGIN_DIR . '/' . $plugin_file ); 262 $plugin_data->requires = $plugin_headers['RequiresWP']; 263 $plugin_data->requires_php = $plugin_headers['RequiresPHP']; 264 } 265 266 return $plugin_data; 267 } 268 216 269 /** 217 270 * Get a list of a plugin's files. 218 271 * … … function is_network_only_plugin( $plugin ) { 675 728 * ensure that the success redirection will update the error redirection. 676 729 * 677 730 * @since 2.5.0 731 * @since 5.2.0 Test for WordPress version and PHP version compatibility. 678 732 * 679 733 * @param string $plugin Path to the plugin file relative to the plugins directory. 680 734 * @param string $redirect Optional. URL to redirect to. … … function activate_plugin( $plugin, $redirect = '', $network_wide = false, $silen 699 753 return $valid; 700 754 } 701 755 756 if ( ! validate_plugin_requirements( $plugin ) ) { 757 return new WP_Error( 'plugin_activation_error', __( 'Plugin does not meet minimum WordPress and/or PHP requirements.' ) ); 758 } 759 702 760 if ( ( $network_wide && ! isset( $current[ $plugin ] ) ) || ( ! $network_wide && ! in_array( $plugin, $current ) ) ) { 703 761 if ( ! empty( $redirect ) ) { 704 762 wp_redirect( add_query_arg( '_error_nonce', wp_create_nonce( 'plugin-activation-error_' . $plugin ), $redirect ) ); // we'll override this later if the plugin can be included without fatal error … … function validate_plugin( $plugin ) { 1194 1252 return 0; 1195 1253 } 1196 1254 1255 /** 1256 * Validate the plugin requirements for WP version and PHP version. 1257 * 1258 * @since 5.2.0 1259 * @see activate_plugin() 1260 * 1261 * @param string $plugin Path to the plugin file relative to the plugins directory. 1262 * 1263 * @return bool Default to true and if requirements met, false if not. 1264 */ 1265 function validate_plugin_requirements( $plugin ) { 1266 $plugin_data = get_plugin_validation_data( $plugin ); 1267 $wp_requires = isset( $plugin_data->requires ) ? $plugin_data->requires : null; 1268 $php_requires = isset( $plugin_data->requires_php ) ? $plugin_data->requires_php : null; 1269 1270 return is_compatible_wp( $wp_requires ) && is_compatible_php( $php_requires ); 1271 } 1272 1197 1273 /** 1198 1274 * Whether the plugin can be uninstalled. 1199 1275 * -
src/wp-includes/functions.php
diff --git src/wp-includes/functions.php src/wp-includes/functions.php index 9552455d05..36b91c7523 100644
function wp_update_php_annotation() { 6741 6741 ); 6742 6742 echo'</p>'; 6743 6743 } 6744 6745 /** 6746 * Check compatibility with current WordPress version. 6747 * 6748 * @since 5.2.0 6749 * 6750 * @param string $requires Minimum WordPress version from API. 6751 * 6752 * @return bool True if is compatible or empty, false if not. 6753 */ 6754 function is_compatible_wp( $requires ) { 6755 $wp_version = get_bloginfo( 'version' ); 6756 return empty( $requires ) || version_compare( $wp_version, $requires, '>=' ); 6757 } 6758 6759 /** 6760 * Check compatibility with current PHP version. 6761 * 6762 * @since 5.2.0 6763 * 6764 * @param string $requires Minimum PHP version from API. 6765 * 6766 * @return bool True if is compatible or empty, false if not. 6767 */ 6768 function is_compatible_php( $requires ) { 6769 return empty( $requires ) || version_compare( phpversion(), $requires, '>=' ); 6770 }