upskill-event-manager/wordpress-dev/wordpress/wp-content/plugins/user-registration/includes/class-ur-autoloader.php
bengizmo d1509b3d60 feat(dev-env): implement backup-based development workflow
This commit introduces a more reliable and consistent approach to setting up
the development environment using backups:

- Add setup-from-backup.sh script for environment setup from existing backups
- Standardize script naming and organization
- Move obsolete scripts to bin/obsolete directory
- Update documentation with new workflow instructions
- Create migration guide for transitioning to new workflow
- Update Memory Bank with workflow improvements

The new workflow provides:
- More reliable environment setup
- Faster setup process
- Offline development capability
- Consistent development environments across team members

Breaking changes:
- setup-dev.sh is replaced by setup-from-backup.sh
- sync-and-setup.sh is replaced by separate scripts
- verify-with-wpcli.sh is no longer used

Migration path is documented in MIGRATION_GUIDE.md
2025-03-26 11:26:18 -03:00

99 lines
2.2 KiB
PHP

<?php
/**
* UserRegistration Autoloader.
*
* @class UR_Autoloader
* @version 1.0.0
* @package UserRegistration/Classes
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* UR_Autoloader Class
*/
class UR_Autoloader {
/**
* Path to the includes directory.
*
* @var string
*/
private $include_path = '';
/**
* Class Constructor Method.
*/
public function __construct() {
if ( function_exists( '__autoload' ) ) {
spl_autoload_register( '__autoload' );
}
spl_autoload_register( array( $this, 'autoload' ) );
$this->include_path = untrailingslashit( plugin_dir_path( UR_PLUGIN_FILE ) ) . '/includes/';
}
/**
* Take a class name and turn it into a file name.
*
* @param string $class Class.
*
* @return string
*/
private function get_file_name_from_class( $class ) {
return 'class-' . str_replace( '_', '-', $class ) . '.php';
}
/**
* Include a class file.
*
* @param string $path Path.
*
* @return bool successful or not
*/
private function load_file( $path ) {
if ( $path && is_readable( $path ) ) {
include_once $path;
return true;
}
return false;
}
/**
* Auto-load UR classes on demand to reduce memory consumption.
*
* @param string $class Class.
*/
public function autoload( $class ) {
$class = strtolower( $class );
$file = $this->get_file_name_from_class( $class );
$path = '';
if ( strpos( $class, 'ur_shortcode_' ) === 0 ) {
$path = $this->include_path . 'shortcodes/';
} elseif ( strpos( $class, 'ur_meta_box' ) === 0 ) {
$path = $this->include_path . 'admin/meta-boxes/';
} elseif ( strpos( $class, 'ur_admin' ) === 0 ) {
$path = $this->include_path . 'admin/';
} elseif ( strpos( $class, 'ur_settings' ) === 0 ) {
$path = $this->include_path . 'admin/settings/emails/';
} elseif ( strpos( $class, 'ur_form' ) === 0 ) {
$path = $this->include_path . 'form/';
} elseif ( strpos( $class, 'ur_log_handler_' ) === 0 ) {
$path = $this->include_path . 'log-handlers/';
} elseif ( strpos( $class, 'ur_form_field_' ) === 0 ) {
$path = $this->include_path . 'form/';
}
if ( empty( $path ) || ( ! $this->load_file( $path . $file ) && strpos( $class, 'ur_' ) === 0 ) ) {
$this->load_file( $this->include_path . $file );
}
}
}
new UR_Autoloader();