abstracts
4 years ago
admin
4 years ago
elementor
4 years ago
export
4 years ago
fields
4 years ago
interfaces
8 years ago
libraries
7 years ago
log-handlers
4 years ago
shortcodes
4 years ago
templates
5 years ago
class-everest-forms.php
4 years ago
class-evf-ajax.php
4 years ago
class-evf-autoloader.php
7 years ago
class-evf-background-updater.php
7 years ago
class-evf-cache-helper.php
6 years ago
class-evf-deprecated-action-hooks.php
6 years ago
class-evf-deprecated-filter-hooks.php
5 years ago
class-evf-emails.php
5 years ago
class-evf-fields.php
6 years ago
class-evf-form-block.php
4 years ago
class-evf-form-handler.php
4 years ago
class-evf-form-task.php
4 years ago
class-evf-forms-features.php
4 years ago
class-evf-frontend-scripts.php
4 years ago
class-evf-install.php
5 years ago
class-evf-integrations.php
7 years ago
class-evf-log-levels.php
8 years ago
class-evf-logger.php
5 years ago
class-evf-post-types.php
5 years ago
class-evf-privacy.php
6 years ago
class-evf-session-handler.php
7 years ago
class-evf-shortcodes.php
4 years ago
class-evf-smart-tags.php
4 years ago
class-evf-template-loader.php
4 years ago
class-evf-validation.php
6 years ago
evf-conditional-functions.php
6 years ago
evf-core-functions.php
4 years ago
evf-deprecated-functions.php
6 years ago
evf-entry-functions.php
4 years ago
evf-formatting-functions.php
4 years ago
evf-notice-functions.php
4 years ago
evf-template-functions.php
4 years ago
evf-template-hooks.php
7 years ago
evf-update-functions.php
5 years ago
class-evf-autoloader.php
92 lines
| 1 | <?php |
| 2 | /** |
| 3 | * EverestForms Autoloader. |
| 4 | * |
| 5 | * @package EverestForms\Classes |
| 6 | * @since 1.0.0 |
| 7 | */ |
| 8 | |
| 9 | defined( 'ABSPATH' ) || exit; |
| 10 | |
| 11 | /** |
| 12 | * Autoloader Class. |
| 13 | */ |
| 14 | class EVF_Autoloader { |
| 15 | |
| 16 | /** |
| 17 | * Path to the includes directory. |
| 18 | * |
| 19 | * @var string |
| 20 | */ |
| 21 | private $include_path = ''; |
| 22 | |
| 23 | /** |
| 24 | * Class Constructor Method. |
| 25 | */ |
| 26 | public function __construct() { |
| 27 | if ( function_exists( '__autoload' ) ) { |
| 28 | spl_autoload_register( '__autoload' ); |
| 29 | } |
| 30 | |
| 31 | spl_autoload_register( array( $this, 'autoload' ) ); |
| 32 | |
| 33 | $this->include_path = untrailingslashit( plugin_dir_path( EVF_PLUGIN_FILE ) ) . '/includes/'; |
| 34 | } |
| 35 | |
| 36 | /** |
| 37 | * Take a class name and turn it into a file name. |
| 38 | * |
| 39 | * @param string $class Class name. |
| 40 | * @return string |
| 41 | */ |
| 42 | private function get_file_name_from_class( $class ) { |
| 43 | return 'class-' . str_replace( '_', '-', $class ) . '.php'; |
| 44 | } |
| 45 | |
| 46 | /** |
| 47 | * Include a class file. |
| 48 | * |
| 49 | * @param string $path File path. |
| 50 | * @return bool Successful or not. |
| 51 | */ |
| 52 | private function load_file( $path ) { |
| 53 | if ( $path && is_readable( $path ) ) { |
| 54 | include_once $path; |
| 55 | return true; |
| 56 | } |
| 57 | return false; |
| 58 | } |
| 59 | |
| 60 | /** |
| 61 | * Auto-load EVF classes on demand to reduce memory consumption. |
| 62 | * |
| 63 | * @param string $class Class name. |
| 64 | */ |
| 65 | public function autoload( $class ) { |
| 66 | $class = strtolower( $class ); |
| 67 | |
| 68 | if ( 0 !== strpos( $class, 'evf_' ) ) { |
| 69 | return; |
| 70 | } |
| 71 | |
| 72 | $file = $this->get_file_name_from_class( $class ); |
| 73 | $path = ''; |
| 74 | |
| 75 | if ( 0 === strpos( $class, 'evf_field_' ) ) { |
| 76 | $path = $this->include_path . 'fields/'; |
| 77 | } elseif ( 0 === strpos( $class, 'evf_shortcode_' ) ) { |
| 78 | $path = $this->include_path . 'shortcodes/'; |
| 79 | } elseif ( 0 === strpos( $class, 'evf_admin' ) ) { |
| 80 | $path = $this->include_path . 'admin/'; |
| 81 | } elseif ( 0 === strpos( $class, 'evf_log_handler_' ) ) { |
| 82 | $path = $this->include_path . 'log-handlers/'; |
| 83 | } |
| 84 | |
| 85 | if ( empty( $path ) || ! $this->load_file( $path . $file ) ) { |
| 86 | $this->load_file( $this->include_path . $file ); |
| 87 | } |
| 88 | } |
| 89 | } |
| 90 | |
| 91 | new EVF_Autoloader(); |
| 92 |