| @@ -1,16 +1,48 @@ | ||
| 1 | -<?php | |
| 2 | -spl_autoload_register( 'forumax_autoloader' ); | |
| 3 | - | |
| 4 | -/** | |
| 5 | - * Autoload files for the plugin | |
| 6 | - * | |
| 7 | - * @param string $class | |
| 8 | - * @return void | |
| 9 | - */ | |
| 10 | -function forumax_autoloader( $class ) { | |
| 11 | - $path = __DIR__ . '/includes/' . str_replace( '\\', '/', $class ) . '.php'; | |
| 12 | - | |
| 13 | - if ( file_exists( $path ) ) { | |
| 14 | - include_once $path; | |
| 15 | - } | |
| 16 | -} | |
| 1 | +<?php | |
| 2 | +spl_autoload_register( 'forumax_autoloader' ); | |
| 3 | + | |
| 4 | +/** | |
| 5 | + * Autoload files for the Forumax plugin. | |
| 6 | + * | |
| 7 | + * SCOPED: Only handles classes that belong to Forumax. | |
| 8 | + * This prevents conflicts with other plugins' autoloaders and namespaces. | |
| 9 | + * | |
| 10 | + * @param string $class The fully-qualified class name. | |
| 11 | + * @return void | |
| 12 | + */ | |
| 13 | +function forumax_autoloader( $class ) { | |
| 14 | + // Define the namespace/class prefixes that belong to Forumax. | |
| 15 | + $forumax_prefixes = array( | |
| 16 | + 'admin\\', // admin\Menu, admin\Elementor\*, admin\Blocks\*, admin\menu\* | |
| 17 | + 'Admin\\', // Admin\Admin_Assets | |
| 18 | + 'Frontend\\', // Frontend\Frontend_Assets | |
| 19 | + 'features\\', // features\bbp_voting, features\bbp_attachments, etc. | |
| 20 | + ); | |
| 21 | + | |
| 22 | + // Check if this class belongs to Forumax. | |
| 23 | + $is_forumax_class = false; | |
| 24 | + | |
| 25 | + // Check for exact global class name (no namespace). | |
| 26 | + if ( 'Admin' === $class ) { | |
| 27 | + $is_forumax_class = true; | |
| 28 | + } else { | |
| 29 | + // Check for namespace prefixes. | |
| 30 | + foreach ( $forumax_prefixes as $prefix ) { | |
| 31 | + if ( strpos( $class, $prefix ) === 0 ) { | |
| 32 | + $is_forumax_class = true; | |
| 33 | + break; | |
| 34 | + } | |
| 35 | + } | |
| 36 | + } | |
| 37 | + | |
| 38 | + // Bail early if this class doesn't belong to Forumax. | |
| 39 | + if ( ! $is_forumax_class ) { | |
| 40 | + return; | |
| 41 | + } | |
| 42 | + | |
| 43 | + $path = __DIR__ . '/includes/' . str_replace( '\\', '/', $class ) . '.php'; | |
| 44 | + | |
| 45 | + if ( file_exists( $path ) ) { | |
| 46 | + include_once $path; | |
| 47 | + } | |
| 48 | +} | |