1 | <?php |
---|
2 | |
---|
3 | function trailingslashit( $path ) { |
---|
4 | return ( substr( $path, -1, 1 ) === '/' ) ? $path : $path . '/'; |
---|
5 | } |
---|
6 | |
---|
7 | interface WP_Autoload_Handler { |
---|
8 | /** |
---|
9 | * @return string|null |
---|
10 | */ |
---|
11 | public function get_path( $class ); |
---|
12 | } |
---|
13 | class WP_Autoload_Prefixed implements WP_Autoload_Handler { |
---|
14 | protected $prefix; |
---|
15 | protected $path; |
---|
16 | public function __construct( $prefix, $path ) { |
---|
17 | $this->prefix = strtolower( $prefix ); |
---|
18 | $this->path = trailingslashit( $path ); |
---|
19 | } |
---|
20 | public function get_path( $class ) { |
---|
21 | $class = strtolower( $class ); |
---|
22 | if ( strpos( $class, $this->prefix ) !== 0 ) { |
---|
23 | return null; |
---|
24 | } |
---|
25 | |
---|
26 | $filename = 'class-' . str_replace( '_', '-', $class ) . '.php'; |
---|
27 | return $this->path . $filename; |
---|
28 | } |
---|
29 | } |
---|
30 | class WP_Autoload_PSR0 implements WP_Autoload_Handler { |
---|
31 | protected $prefix; |
---|
32 | protected $path; |
---|
33 | public function __construct( $prefix, $path ) { |
---|
34 | $this->prefix = $prefix; |
---|
35 | $this->path = trailingslashit( $path ); |
---|
36 | } |
---|
37 | public function get_path( $class ) { |
---|
38 | if ( strpos( $class, $this->prefix ) !== 0 ) { |
---|
39 | return null; |
---|
40 | } |
---|
41 | |
---|
42 | $parts = explode( '_', substr( $class, strlen( $this->prefix ) ) ); |
---|
43 | $filename = implode( '/', $parts ) . '.php'; |
---|
44 | return $this->path . $filename; |
---|
45 | } |
---|
46 | } |
---|
47 | class WP_Autoload_ClassMap implements WP_Autoload_Handler { |
---|
48 | protected $map; |
---|
49 | public function __construct( $map ) { |
---|
50 | $this->map = $map; |
---|
51 | } |
---|
52 | public function get_path( $class ) { |
---|
53 | if ( ! isset( $this->map[ $class ] ) ) { |
---|
54 | return null; |
---|
55 | } |
---|
56 | |
---|
57 | return $this->map[ $class ]; |
---|
58 | } |
---|
59 | } |
---|
60 | |
---|
61 | $wp_autoloaders = []; |
---|
62 | function register_autoloader( WP_Autoload_Handler $handler ) { |
---|
63 | global $wp_autoloaders; |
---|
64 | $wp_autoloaders[] = $handler; |
---|
65 | } |
---|
66 | function file_for_class( $class ) { |
---|
67 | global $wp_autoloaders; |
---|
68 | foreach ( $wp_autoloaders as $autoloader ) { |
---|
69 | if ( $path = $autoloader->get_path( $class ) ) { |
---|
70 | return $path; |
---|
71 | } |
---|
72 | } |
---|
73 | |
---|
74 | return null; |
---|
75 | } |
---|
76 | |
---|
77 | // Legacy |
---|
78 | register_autoloader( new WP_Autoload_ClassMap([ |
---|
79 | 'WP' => 'wp-includes/class-wp.php', |
---|
80 | 'wpdb' => 'wp-includes/wp-db.php', |
---|
81 | 'WP_Date_Query' => 'wp-includes/date.php', |
---|
82 | 'WP_Locale' => 'wp-includes/locale.php', |
---|
83 | 'WP_oEmbed' => 'wp-includes/class-oembed.php', |
---|
84 | 'WP_Query' => 'wp-includes/query.php', |
---|
85 | 'WP_User_Meta_Session_Tokens' => 'wp-includes/session.php', |
---|
86 | |
---|
87 | // Back-compat |
---|
88 | 'WP_HTTP_Fsockopen' => 'wp-includes/class-wp-http-streams.php', |
---|
89 | |
---|
90 | // Old Customizer |
---|
91 | 'WP_Customize_Control' => 'wp-includes/class-wp-customize-control.php', |
---|
92 | 'WP_Customize_Panel' => 'wp-includes/class-wp-customize-panel.php', |
---|
93 | 'WP_Customize_Section' => 'wp-includes/class-wp-customize-section.php', |
---|
94 | 'WP_Customize_Setting' => 'wp-includes/class-wp-customize-setting.php', |
---|
95 | |
---|
96 | // Dependencies (uses dot instead of dash) |
---|
97 | 'WP_Dependencies' => 'wp-includes/class.wp-dependencies.php', |
---|
98 | '_WP_Dependency' => 'wp-includes/class.wp-dependencies.php', |
---|
99 | 'WP_Scripts' => 'wp-includes/class.wp-scripts.php', |
---|
100 | 'WP_Styles' => 'wp-includes/class.wp-styles.php', |
---|
101 | |
---|
102 | // Widgets |
---|
103 | 'WP_Widget_Factory' => 'wp-includes/class-wp-widget-factory.php', |
---|
104 | |
---|
105 | // Walkers |
---|
106 | 'Walker' => 'wp-includes/class-wp-walker.php', |
---|
107 | 'Walker_CategoryDropdown' => 'wp-includes/class-walker-category-dropdown.php', |
---|
108 | 'Walker_PageDropdown' => 'wp-includes/class-walker-page-dropdown.php', |
---|
109 | |
---|
110 | // Diff |
---|
111 | 'WP_Text_Diff_Renderer_Table' => 'wp-includes/wp-diff.php', |
---|
112 | 'WP_Text_Diff_Renderer_inline' => 'wp-includes/wp-diff.php', |
---|
113 | ])); |
---|
114 | |
---|
115 | // Admin-only |
---|
116 | register_autoloader( new WP_Autoload_ClassMap([ |
---|
117 | // List tables |
---|
118 | 'WP_Comments_List_Table' => 'wp-admin/includes/class-wp-comments-list-table.php', |
---|
119 | 'WP_Links_List_Table' => 'wp-admin/includes/class-wp-links-list-table.php', |
---|
120 | 'WP_List_Table' => 'wp-admin/includes/class-wp-list-table.php', |
---|
121 | 'WP_Media_List_Table' => 'wp-admin/includes/class-wp-media-list-table.php', |
---|
122 | 'WP_MS_Sites_List_Table' => 'wp-admin/includes/class-wp-ms-sites-list-table.php', |
---|
123 | 'WP_MS_Themes_List_Table' => 'wp-admin/includes/class-wp-ms-themes-list-table.php', |
---|
124 | 'WP_MS_Users_List_Table' => 'wp-admin/includes/class-wp-ms-users-list-table.php', |
---|
125 | 'WP_Plugin_Install_List_Table' => 'wp-admin/includes/class-wp-plugin-install-list-table.php', |
---|
126 | 'WP_Plugins_List_Table' => 'wp-admin/includes/class-wp-plugins-list-table.php', |
---|
127 | 'WP_Post_Comments_List_Table' => 'wp-admin/includes/class-wp-post-comments-list-table.php', |
---|
128 | 'WP_Posts_List_Table' => 'wp-admin/includes/class-wp-posts-list-table.php', |
---|
129 | 'WP_Terms_List_Table' => 'wp-admin/includes/class-wp-terms-list-table.php', |
---|
130 | 'WP_Theme_Install_List_Table' => 'wp-admin/includes/class-wp-theme-install-list-table.php', |
---|
131 | 'WP_Themes_List_Table' => 'wp-admin/includes/class-wp-themes-list-table.php', |
---|
132 | 'WP_Users_List_Table' => 'wp-admin/includes/class-wp-users-list-table.php', |
---|
133 | '_WP_List_Table' => 'wp-admin/includes/list-table.php', |
---|
134 | '_WP_List_Table_Compat' => 'wp-admin/includes/list-table.php', |
---|
135 | |
---|
136 | // Skins |
---|
137 | 'WP_Upgrader_Skin' => 'wp-admin/includes/class-wp-upgrader-skins.php', |
---|
138 | 'Plugin_Upgrader_Skin' => 'wp-admin/includes/class-wp-upgrader-skins.php', |
---|
139 | 'Bulk_Upgrader_Skin' => 'wp-admin/includes/class-wp-upgrader-skins.php', |
---|
140 | 'Bulk_Plugin_Upgrader_Skin' => 'wp-admin/includes/class-wp-upgrader-skins.php', |
---|
141 | 'Bulk_Theme_Upgrader_Skin' => 'wp-admin/includes/class-wp-upgrader-skins.php', |
---|
142 | 'Plugin_Installer_Skin' => 'wp-admin/includes/class-wp-upgrader-skins.php', |
---|
143 | 'Theme_Installer_Skin' => 'wp-admin/includes/class-wp-upgrader-skins.php', |
---|
144 | 'Theme_Upgrader_Skin' => 'wp-admin/includes/class-wp-upgrader-skins.php', |
---|
145 | 'Language_Pack_Upgrader_Skin' => 'wp-admin/includes/class-wp-upgrader-skins.php', |
---|
146 | 'Automatic_Upgrader_Skin' => 'wp-admin/includes/class-wp-upgrader-skins.php', |
---|
147 | |
---|
148 | // Upgraders |
---|
149 | 'WP_Upgrader' => 'wp-admin/includes/class-wp-upgrader.php', |
---|
150 | 'Plugin_Upgrader' => 'wp-admin/includes/class-wp-upgrader.php', |
---|
151 | 'Theme_Upgrader' => 'wp-admin/includes/class-wp-upgrader.php', |
---|
152 | 'Language_Pack_Upgrader' => 'wp-admin/includes/class-wp-upgrader.php', |
---|
153 | 'Core_Upgrader' => 'wp-admin/includes/class-wp-upgrader.php', |
---|
154 | 'File_Upload_Upgrader' => 'wp-admin/includes/class-wp-upgrader.php', |
---|
155 | 'WP_Automatic_Updater' => 'wp-admin/includes/class-wp-upgrader.php', |
---|
156 | |
---|
157 | // Admin walkers |
---|
158 | 'Walker_Category_Checklist' => 'wp-admin/includes/class-walker-category-checklist.php', |
---|
159 | 'Walker_Nav_Menu_Checklist' => 'wp-admin/includes/class-walker-nav-menu-checklist.php', |
---|
160 | 'Walker_Nav_Menu_Edit' => 'wp-admin/includes/class-walker-nav-menu-edit.php', |
---|
161 | |
---|
162 | // Others! |
---|
163 | 'Custom_Background' => 'wp-admin/custom-background.php', |
---|
164 | 'Custom_Image_Header' => 'wp-admin/custom-header.php', |
---|
165 | 'WP_Importer' => 'wp-admin/includes/class-wp-importer.php', |
---|
166 | 'WP_Press_This' => 'wp-admin/includes/class-wp-press-this.php', |
---|
167 | 'WP_Site_Icon' => 'wp-admin/includes/class-wp-site-icon.php', |
---|
168 | ])); |
---|
169 | |
---|
170 | |
---|
171 | // Externals |
---|
172 | register_autoloader( new WP_Autoload_ClassMap([ |
---|
173 | // AtomLib |
---|
174 | 'AtomFeed' => 'wp-includes/atomlib.php', |
---|
175 | 'AtomEntry' => 'wp-includes/atomlib.php', |
---|
176 | 'AtomParser' => 'wp-includes/atomlib.php', |
---|
177 | |
---|
178 | // FTP handling |
---|
179 | 'ftp' => 'wp-admin/includes/class-ftp.php', |
---|
180 | 'ftp_base' => 'wp-admin/includes/class-ftp.php', |
---|
181 | |
---|
182 | // IXR |
---|
183 | 'IXR_Value' => 'wp-includes/class-IXR.php', |
---|
184 | 'IXR_Date' => 'wp-includes/class-IXR.php', |
---|
185 | |
---|
186 | // Magpie |
---|
187 | 'MagpieRSS' => 'wp-includes/rss.php', |
---|
188 | 'RSSCache' => 'wp-includes/rss.php', |
---|
189 | |
---|
190 | // ID3 |
---|
191 | 'getid3_asf' => 'wp-includes/ID3/module.audio-video.asf.php', |
---|
192 | 'getid3_flv' => 'wp-includes/ID3/module.audio-video.flv.php', |
---|
193 | 'AMFStream' => 'wp-includes/ID3/module.audio-video.flv.php', |
---|
194 | 'AMFReader' => 'wp-includes/ID3/module.audio-video.flv.php', |
---|
195 | 'AVCSequenceParameterSetReader' => 'wp-includes/ID3/module.audio-video.flv.php', |
---|
196 | 'getid3_riff' => 'wp-includes/ID3/module.audio-video.riff.php', |
---|
197 | |
---|
198 | // phpass |
---|
199 | 'PasswordHash' => 'wp-includes/class-phpass.php', |
---|
200 | |
---|
201 | // POMO |
---|
202 | 'Translation_Entry' => 'wp-includes/pomo/entry.php', |
---|
203 | 'MO' => 'wp-includes/pomo/mo.php', |
---|
204 | 'PO' => 'wp-includes/pomo/po.php', |
---|
205 | 'POMO_Reader' => 'wp-includes/pomo/streams.php', |
---|
206 | 'POMO_FileReader' => 'wp-includes/pomo/streams.php', |
---|
207 | 'POMO_StringReader' => 'wp-includes/pomo/streams.php', |
---|
208 | 'POMO_CachedFileReader' => 'wp-includes/pomo/streams.php', |
---|
209 | 'POMO_CachedIntFileReader' => 'wp-includes/pomo/streams.php', |
---|
210 | 'Translations' => 'wp-includes/pomo/translations.php', |
---|
211 | 'Gettext_Translations' => 'wp-includes/pomo/translations.php', |
---|
212 | 'NOOP_Translations' => 'wp-includes/pomo/translations.php', |
---|
213 | |
---|
214 | // POP3 |
---|
215 | 'POP3' => 'wp-includes/class-pop3.php', |
---|
216 | |
---|
217 | // Text_Diff |
---|
218 | 'Text_Diff' => 'wp-includes/Text/Diff.php', |
---|
219 | 'Text_MappedDiff' => 'wp-includes/Text/Diff.php', |
---|
220 | 'Text_Diff_Op' => 'wp-includes/Text/Diff.php', |
---|
221 | 'Text_Diff_Op_copy' => 'wp-includes/Text/Diff.php', |
---|
222 | 'Text_Diff_Op_change' => 'wp-includes/Text/Diff.php', |
---|
223 | 'Text_Diff_Op_delete' => 'wp-includes/Text/Diff.php', |
---|
224 | 'Text_Diff_Op_add' => 'wp-includes/Text/Diff.php', |
---|
225 | ])); |
---|
226 | register_autoloader( new WP_Autoload_PSR0( 'Text_Diff_', 'wp-includes/Text/Diff/' ) ); |
---|
227 | |
---|
228 | $prefixed = [ |
---|
229 | // Subdirs of includes |
---|
230 | 'wp_customize_' => 'wp-includes/customize/', |
---|
231 | 'wp_rest_' => 'wp-includes/rest-api/', |
---|
232 | 'wp_widget_' => 'wp-includes/widgets/', |
---|
233 | |
---|
234 | // Admin-specific |
---|
235 | 'wp_filesystem_' => 'wp-admin/includes/', |
---|
236 | |
---|
237 | // Catch-all |
---|
238 | 'wp_' => 'wp-includes/', |
---|
239 | 'walker_' => 'wp-includes/', |
---|
240 | ]; |
---|
241 | foreach ( $prefixed as $prefix => $path ) { |
---|
242 | register_autoloader( new WP_Autoload_Prefixed( $prefix, $path ) ); |
---|
243 | } |
---|
244 | |
---|
245 | $file = fopen( 'classes.csv', 'r' ); |
---|
246 | |
---|
247 | $classes = []; |
---|
248 | while ( ( $fields = fgetcsv( $file ) ) !== false ) { |
---|
249 | $classes[] = [ 'file' => $fields[0], 'class' => $fields[1] ]; |
---|
250 | } |
---|
251 | fclose( $file ); |
---|
252 | |
---|
253 | ?> |
---|
254 | <style> |
---|
255 | html, body { |
---|
256 | font-family: sans-serif; |
---|
257 | color: #333; |
---|
258 | } |
---|
259 | table { |
---|
260 | width: 100%; |
---|
261 | } |
---|
262 | .match { |
---|
263 | /*background: rgba( 0, 255, 0, 0.08 );*/ |
---|
264 | } |
---|
265 | .no-match { |
---|
266 | background: rgba( 255, 0, 0, 0.08 ); |
---|
267 | } |
---|
268 | </style> |
---|
269 | |
---|
270 | <table> |
---|
271 | <thead> |
---|
272 | <tr> |
---|
273 | <th>Class</th> |
---|
274 | <th>File</th> |
---|
275 | <th>Expected</th> |
---|
276 | </tr> |
---|
277 | </thead> |
---|
278 | <tbody> |
---|
279 | <?php foreach ( $classes as $data ): ?> |
---|
280 | <?php $expected = file_for_class( $data['class'] ) ?> |
---|
281 | |
---|
282 | <tr> |
---|
283 | |
---|
284 | <td><?php echo $data['class'] ?></td> |
---|
285 | <td><?php echo $data['file'] ?></td> |
---|
286 | <td class="<?php echo ( $expected === $data['file'] ? 'match' : 'no-match' ) ?>"> |
---|
287 | <?php echo $expected ?> |
---|
288 | </td> |
---|
289 | |
---|
290 | </tr> |
---|
291 | |
---|
292 | <?php endforeach ?> |
---|
293 | </tbody> |
---|
294 | </table> |
---|