assets
2 weeks ago
classes
2 weeks ago
dist
2 weeks ago
nps-survey-plugin-loader.php
2 weeks ago
nps-survey.php
2 weeks ago
version.json
2 weeks ago
nps-survey-plugin-loader.php
111 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Plugin Loader. |
| 4 | * |
| 5 | * @package NPS_Survey |
| 6 | * @since 1.0.0 |
| 7 | */ |
| 8 | |
| 9 | namespace NPS_Survey; |
| 10 | |
| 11 | if ( ! defined( 'ABSPATH' ) ) { |
| 12 | exit; |
| 13 | } |
| 14 | |
| 15 | if ( ! class_exists( 'NPS_Survey_Plugin_Loader' ) ) { |
| 16 | |
| 17 | /** |
| 18 | * Plugin_Loader |
| 19 | * |
| 20 | * @since 1.0.0 |
| 21 | */ |
| 22 | class NPS_Survey_Plugin_Loader { |
| 23 | /** |
| 24 | * Instance |
| 25 | * |
| 26 | * @access private |
| 27 | * @var object Class Instance. |
| 28 | * @since 1.0.0 |
| 29 | */ |
| 30 | private static $instance; |
| 31 | |
| 32 | /** |
| 33 | * Constructor |
| 34 | * |
| 35 | * @since 1.0.0 |
| 36 | */ |
| 37 | public function __construct() { |
| 38 | |
| 39 | spl_autoload_register( [ $this, 'autoload' ] ); |
| 40 | |
| 41 | if ( did_action( 'wp_loaded' ) ) { |
| 42 | $this->load_files(); |
| 43 | } else { |
| 44 | add_action( 'wp_loaded', [ $this, 'load_files' ] ); |
| 45 | } |
| 46 | } |
| 47 | |
| 48 | /** |
| 49 | * Initiator |
| 50 | * |
| 51 | * @since 1.0.0 |
| 52 | * @return object initialized object of class. |
| 53 | */ |
| 54 | public static function get_instance() { |
| 55 | if ( null === self::$instance ) { |
| 56 | self::$instance = new self(); |
| 57 | } |
| 58 | return self::$instance; |
| 59 | } |
| 60 | |
| 61 | /** |
| 62 | * Autoload classes. |
| 63 | * |
| 64 | * @param string $class class name. |
| 65 | * @return void |
| 66 | */ |
| 67 | public function autoload( $class ): void { |
| 68 | if ( 0 !== strpos( $class, __NAMESPACE__ ) ) { |
| 69 | return; |
| 70 | } |
| 71 | |
| 72 | $class_to_load = $class; |
| 73 | |
| 74 | $filename = strtolower( |
| 75 | strval( |
| 76 | preg_replace( |
| 77 | [ '/^' . __NAMESPACE__ . '\\\/', '/([a-z])([A-Z])/', '/_/', '/\\\/' ], |
| 78 | [ '', '$1-$2', '-', DIRECTORY_SEPARATOR ], |
| 79 | $class_to_load |
| 80 | ) |
| 81 | ) |
| 82 | ); |
| 83 | |
| 84 | $file = NPS_SURVEY_DIR . $filename . '.php'; |
| 85 | |
| 86 | // if the file redable, include it. |
| 87 | if ( is_readable( $file ) ) { |
| 88 | // nosemgrep audit.php.lang.security.file.inclusion-arg - To allow the theme or plugin on WooCommerce Marketplace. |
| 89 | require_once $file; |
| 90 | } |
| 91 | } |
| 92 | |
| 93 | /** |
| 94 | * Load Files |
| 95 | * |
| 96 | * @since 1.0.0 |
| 97 | * |
| 98 | * @return void |
| 99 | */ |
| 100 | public function load_files(): void { |
| 101 | require_once NPS_SURVEY_DIR . 'classes/nps-survey-script.php'; |
| 102 | } |
| 103 | } |
| 104 | |
| 105 | /** |
| 106 | * Kicking this off by calling 'get_instance()' method |
| 107 | */ |
| 108 | NPS_Survey_Plugin_Loader::get_instance(); |
| 109 | |
| 110 | } |
| 111 |