Changeset 47574 for trunk/src/wp-admin/includes/plugin.php
- Timestamp:
- 04/13/2020 03:29:17 PM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-admin/includes/plugin.php
r47557 r47574 1101 1101 1102 1102 /** 1103 * Validate the plugin requirements for WP version and PHP version. 1103 * Validates the plugin requirements for WordPress version and PHP version. 1104 * 1105 * Uses the information from `Requires at least` and `Requires PHP` headers 1106 * defined in the plugin's main PHP file. 1107 * 1108 * If the headers are not present in the plugin's main PHP file, 1109 * `readme.txt` is also checked as a fallback. 1104 1110 * 1105 1111 * @since 5.2.0 1112 * @since 5.3.0 Added support for reading the headers from the plugin's 1113 * main PHP file, with `readme.txt` as a fallback. 1106 1114 * 1107 1115 * @param string $plugin Path to the plugin file relative to the plugins directory. … … 1109 1117 */ 1110 1118 function validate_plugin_requirements( $plugin ) { 1119 $plugin_headers = get_plugin_data( WP_PLUGIN_DIR . '/' . $plugin ); 1120 1121 $requirements = array( 1122 'requires' => ! empty( $plugin_headers['RequiresWP'] ) ? $plugin_headers['RequiresWP'] : '', 1123 'requires_php' => ! empty( $plugin_headers['RequiresPHP'] ) ? $plugin_headers['RequiresPHP'] : '', 1124 ); 1125 1111 1126 $readme_file = WP_PLUGIN_DIR . '/' . dirname( $plugin ) . '/readme.txt'; 1112 $plugin_data = array(1113 'requires' => '',1114 'requires_php' => '',1115 );1116 1127 1117 1128 if ( file_exists( $readme_file ) ) { 1118 $ plugin_data= get_file_data(1129 $readme_headers = get_file_data( 1119 1130 $readme_file, 1120 1131 array( … … 1124 1135 'plugin' 1125 1136 ); 1126 } 1127 1128 $plugin_data = array_merge( $plugin_data, get_plugin_data( WP_PLUGIN_DIR . '/' . $plugin ) ); 1129 1130 // Check for headers in the plugin's PHP file, give precedence to the plugin headers. 1131 $plugin_data['requires'] = ! empty( $plugin_data['RequiresWP'] ) ? $plugin_data['RequiresWP'] : $plugin_data['requires']; 1132 $plugin_data['requires_php'] = ! empty( $plugin_data['RequiresPHP'] ) ? $plugin_data['RequiresPHP'] : $plugin_data['requires_php']; 1133 1134 $plugin_data['wp_compatible'] = is_wp_version_compatible( $plugin_data['requires'] ); 1135 $plugin_data['php_compatible'] = is_php_version_compatible( $plugin_data['requires_php'] ); 1136 1137 if ( ! $plugin_data['wp_compatible'] && ! $plugin_data['php_compatible'] ) { 1137 1138 $requirements = array_merge( $readme_headers, $requirements ); 1139 } 1140 1141 $compatible_wp = is_wp_version_compatible( $requirements['requires'] ); 1142 $compatible_php = is_php_version_compatible( $requirements['requires_php'] ); 1143 1144 if ( ! $compatible_wp && ! $compatible_php ) { 1138 1145 return new WP_Error( 1139 1146 'plugin_wp_php_incompatible', 1140 1147 sprintf( 1141 1148 /* translators: %s: Plugin name. */ 1142 _ _( '<strong>Error:</strong> Current WordPress and PHP versions do not meet minimum requirements for %s.' ),1143 $plugin_ data['Name']1149 _x( '<strong>Error:</strong> Current WordPress and PHP versions do not meet minimum requirements for %s.', 'plugin' ), 1150 $plugin_headers['Name'] 1144 1151 ) 1145 1152 ); 1146 } elseif ( ! $ plugin_data['php_compatible']) {1153 } elseif ( ! $compatible_php ) { 1147 1154 return new WP_Error( 1148 1155 'plugin_php_incompatible', 1149 1156 sprintf( 1150 1157 /* translators: %s: Plugin name. */ 1151 _ _( '<strong>Error:</strong> Current PHP version does not meet minimum requirements for %s.' ),1152 $plugin_ data['Name']1158 _x( '<strong>Error:</strong> Current PHP version does not meet minimum requirements for %s.', 'plugin' ), 1159 $plugin_headers['Name'] 1153 1160 ) 1154 1161 ); 1155 } elseif ( ! $ plugin_data['wp_compatible']) {1162 } elseif ( ! $compatible_wp ) { 1156 1163 return new WP_Error( 1157 1164 'plugin_wp_incompatible', 1158 1165 sprintf( 1159 1166 /* translators: %s: Plugin name. */ 1160 _ _( '<strong>Error:</strong> Current WordPress version does not meet minimum requirements for %s.' ),1161 $plugin_ data['Name']1167 _x( '<strong>Error:</strong> Current WordPress version does not meet minimum requirements for %s.', 'plugin' ), 1168 $plugin_headers['Name'] 1162 1169 ) 1163 1170 );
Note: See TracChangeset
for help on using the changeset viewer.