Ticket #43992: 43992.18.diff
| File 43992.18.diff, 6.1 KB (added by , 7 years ago) |
|---|
-
wp-admin/includes/plugin.php
diff --git a/wp-admin/includes/plugin.php b/wp-admin/includes/plugin.php index 05e3861f17..e05eeaf62c 100644
a b 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 * Return plugin data for validation with WP version and PHP version. 225 * 226 * Uses get_file_data() to parse local readme.txt. 227 * Valid data in readme.txt takes priority. 228 * If valid data is not in readme.txt check if plugin header `Requires WP` or `Requires PHP` exists and use that. 229 * 230 * @since 5.2.0 231 * @see validate_plugin_requirements() 232 * 233 * @param string $plugin_file Path to the plugin file relative to the plugins directory. 234 * 235 * @return array $plugin_data Array of plugin data for validation. 236 */ 237 function get_plugin_validation_data( $plugin_file ) { 238 $validation_headers = array( 239 'requires' => 'requires at least', 240 'requires_php' => 'requires php', 241 ); 242 $plugin_data = null; 243 $readme_file = WP_PLUGIN_DIR . '/' . dirname( $plugin_file ) . '/readme.txt'; 244 if ( file_exists( $readme_file ) ) { 245 $plugin_data = get_file_data( $readme_file, $validation_headers ); 246 } 247 248 $plugin_data['file'] = $plugin_file; 249 250 // Plugin might have `Requires WP` and/or `Requires PHP` headers we can use. 251 $plugin_headers = get_plugin_data( WP_PLUGIN_DIR . '/' . $plugin_file, false, false ); 252 253 $plugin_data['requires'] = empty( $plugin_data['requires'] ) ? $plugin_headers['RequiresWP'] : $plugin_data['requires']; 254 $plugin_data['requires_php'] = empty( $plugin_data['requires_php'] ) ? $plugin_headers['RequiresPHP'] : $plugin_data['requires_php']; 255 256 return $plugin_data; 257 } 258 216 259 /** 217 260 * Get a list of a plugin's files. 218 261 * … … function is_network_only_plugin( $plugin ) { 675 718 * ensure that the success redirection will update the error redirection. 676 719 * 677 720 * @since 2.5.0 721 * @since 5.2.0 Test for WordPress version and PHP version compatibility. 678 722 * 679 723 * @param string $plugin Path to the plugin file relative to the plugins directory. 680 724 * @param string $redirect Optional. URL to redirect to. … … function activate_plugin( $plugin, $redirect = '', $network_wide = false, $silen 699 743 return $valid; 700 744 } 701 745 746 if ( ! validate_plugin_requirements( $plugin ) ) { 747 return new WP_Error( 'unmet_requirements', __( 'Plugin does not meet minimum WordPress and/or PHP requirements.' ) ); 748 } 749 702 750 if ( ( $network_wide && ! isset( $current[ $plugin ] ) ) || ( ! $network_wide && ! in_array( $plugin, $current ) ) ) { 703 751 if ( ! empty( $redirect ) ) { 704 752 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 ) { 1199 1247 return 0; 1200 1248 } 1201 1249 1250 /** 1251 * Validate the plugin requirements for WP version and PHP version. 1252 * 1253 * @since 5.2.0 1254 * @see activate_plugin() 1255 * 1256 * @param string $plugin Path to the plugin file relative to the plugins directory. 1257 * 1258 * @return bool Default to true and if requirements met, false if not. 1259 */ 1260 function validate_plugin_requirements( $plugin ) { 1261 $plugin_data = get_plugin_validation_data( $plugin ); 1262 $wp_requires = isset( $plugin_data['requires'] ) ? $plugin_data['requires'] : null; 1263 $php_requires = isset( $plugin_data['requires_php'] ) ? $plugin_data['requires_php'] : null; 1264 1265 return is_wp_compatible( $wp_requires ) && is_php_compatible( $php_requires ); 1266 } 1267 1202 1268 /** 1203 1269 * Whether the plugin can be uninstalled. 1204 1270 * -
wp-includes/functions.php
diff --git a/wp-includes/functions.php b/wp-includes/functions.php index 214c134d01..b25bc6e74a 100644
a b function wp_update_php_annotation() { 6830 6830 ); 6831 6831 echo'</p>'; 6832 6832 } 6833 6834 /** 6835 * Check compatibility with current WordPress version. 6836 * 6837 * @since 5.2.0 6838 * 6839 * @param string $requires Minimum WordPress version from API. 6840 * 6841 * @return bool True if is compatible or empty, false if not. 6842 */ 6843 function is_wp_compatible( $requires ) { 6844 $wp_version = get_bloginfo( 'version' ); 6845 return empty( $requires ) || version_compare( $wp_version, $requires, '>=' ); 6846 } 6847 6848 /** 6849 * Check compatibility with current PHP version. 6850 * 6851 * @since 5.2.0 6852 * 6853 * @param string $requires Minimum PHP version from API. 6854 * 6855 * @return bool True if is compatible or empty, false if not. 6856 */ 6857 function is_php_compatible( $requires ) { 6858 return empty( $requires ) || version_compare( phpversion(), $requires, '>=' ); 6859 }