Ticket #43992: 43992-9.diff
File 43992-9.diff, 5.7 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 c898fc5169..31f6ae2b7d 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 … … 63 65 * @type string $TextDomain Plugin textdomain. 64 66 * @type string $DomainPath Plugins relative directory path to .mo files. 65 67 * @type bool $Network Whether the plugin can only be activated network-wide. 68 * @type string $RequiresWP Minimum required version of WordPress. 69 * @type string $RequiresPHP Minimum required version of PHP. 66 70 * } 67 71 */ 68 72 function get_plugin_data( $plugin_file, $markup = true, $translate = true ) { … … function get_plugin_data( $plugin_file, $markup = true, $translate = true ) { 77 81 'TextDomain' => 'Text Domain', 78 82 'DomainPath' => 'Domain Path', 79 83 'Network' => 'Network', 84 'RequiresWP' => 'Requires WP', 85 'RequiresPHP' => 'Requires PHP', 80 86 // Site Wide Only is deprecated in favor of Network. 81 87 '_sitewide' => 'Site Wide Only', 82 88 ); … … function _get_plugin_data_markup_translate( $plugin_file, $plugin_data, $markup 189 195 return $plugin_data; 190 196 } 191 197 198 /** 199 * Get the and return plugin data used for validation. 200 * 201 * Initially use the Plugin API as there's no current method to parse the local plugin readme.txt file. 202 * Alternately see if a plugin header `Requires WP` or `Requires PHP` exists and use that. 203 * 204 * @since 5.1.0 205 * @see validate_plugin_requirements() 206 * 207 * @param string $plugin_file Path to the plugin file relative to the plugins directory. 208 * 209 * @return object $plugin_data Object of plugin data for validation. 210 */ 211 function get_plugin_validation_data( $plugin_file ) { 212 $plugin_data = new stdClass(); 213 $slug = dirname( $plugin_file ); 214 $url = 'https://api.wordpress.org/plugins/info/1.2/'; 215 $url = add_query_arg( 216 array( 217 'action' => 'plugin_information', 218 rawurlencode( 'request[slug]' ) => $slug, 219 ), 220 $url 221 ); 222 $response = wp_remote_get( $url ); 223 if ( ! is_wp_error( $response ) ) { 224 $plugin_data = json_decode( wp_remote_retrieve_body( $response ) ); 225 } 226 227 $invalid_check = isset( $plugin_data->error ) || is_wp_error( $response ) || $slug !== $plugin_data->slug; 228 229 /* 230 * Plugin is likley not in the WP Plugin Directory but if they have designated 231 * `Requires WP` and/or `Requires PHP` headers we can use those. 232 */ 233 if ( $invalid_check ) { 234 $plugin_data = new stdClass(); 235 $plugin_data->file = $plugin_file; 236 $plugin_headers = get_plugin_data( WP_PLUGIN_DIR . '/' . $plugin_file ); 237 $plugin_data->requires = $plugin_headers['RequiresWP']; 238 $plugin_data->requires_php = $plugin_headers['RequiresPHP']; 239 } 240 241 return $plugin_data; 242 } 243 192 244 /** 193 245 * Get a list of a plugin's files. 194 246 * … … function activate_plugin( $plugin, $redirect = '', $network_wide = false, $silen 589 641 return $valid; 590 642 } 591 643 644 if ( ! validate_plugin_requirements( $plugin ) ) { 645 return new WP_Error( 'plugin_activation_error', __( 'Plugin does not meet minimum WordPress and/or PHP requirements.' ) ); 646 } 647 592 648 if ( ( $network_wide && ! isset( $current[ $plugin ] ) ) || ( ! $network_wide && ! in_array( $plugin, $current ) ) ) { 593 649 if ( ! empty( $redirect ) ) { 594 650 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 ) { 1023 1079 return 0; 1024 1080 } 1025 1081 1082 /** 1083 * Validate the plugin requirements for WP version and PHP version. 1084 * 1085 * @since 5.1.0 1086 * @see activate_plugin() 1087 * 1088 * @param string $plugin Path to the plugin file relative to the plugins directory. 1089 * 1090 * @return bool Default to true and if requirements met, false if not. 1091 */ 1092 function validate_plugin_requirements( $plugin ) { 1093 $plugin_data = get_plugin_validation_data( $plugin ); 1094 $wp_requires = isset( $plugin_data->requires ) ? $plugin_data->requires : null; 1095 $php_requires = isset( $plugin_data->requires_php ) ? $plugin_data->requires_php : null; 1096 1097 return is_compatible_wp( $wp_requires ) && is_compatible_php( $php_requires ); 1098 } 1099 1026 1100 /** 1027 1101 * Whether the plugin can be uninstalled. 1028 1102 * -
src/wp-includes/functions.php
diff --git src/wp-includes/functions.php src/wp-includes/functions.php index b00a47c1d8..d4cd0582b2 100644
function wp_privacy_delete_old_export_files() { 6580 6580 } 6581 6581 } 6582 6582 } 6583 6584 /** 6585 * Check compatibility with current WordPress version. 6586 * 6587 * @since 5.1.0 6588 * 6589 * @param string $requires Minimum WordPress version from API. 6590 * 6591 * @return bool True if is compatible or empty, false if not. 6592 */ 6593 function is_compatible_wp( $requires ) { 6594 $wp_version = get_bloginfo( 'version' ); 6595 return empty( $requires ) || version_compare( $wp_version, $requires, '>=' ); 6596 } 6597 6598 /** 6599 * Check compatibility with current PHP version. 6600 * 6601 * @since 5.1.0 6602 * 6603 * @param string $requires Minimum PHP version from API. 6604 * 6605 * @return bool True if is compatible or empty, false if not. 6606 */ 6607 function is_compatible_php( $requires ) { 6608 return empty( $requires ) || version_compare( phpversion(), $requires, '>=' ); 6609 }