NEXT craftinamerica.org. Base setup for headless wordpress https://www.craftinamerica.org
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. <?php
  2. class P2P_Autoload {
  3. protected function __construct( $prefix, $basedir ) {
  4. $this->prefix = $prefix;
  5. $this->basedir = $basedir;
  6. }
  7. static function register( $prefix, $basedir ) {
  8. $loader = new self( $prefix, $basedir );
  9. spl_autoload_register( array( $loader, 'autoload' ) );
  10. }
  11. function autoload( $class ) {
  12. if ( $class[0] === '\\' ) {
  13. $class = substr( $class, 1 );
  14. }
  15. if ( strpos( $class, $this->prefix ) !== 0 ) {
  16. return;
  17. }
  18. $path = str_replace( $this->prefix, '', $class );
  19. $path = str_replace( '_', '-', strtolower( $path ) );
  20. $file = sprintf( '%s/%s.php', $this->basedir, $path );
  21. if ( is_file( $file ) ) {
  22. require $file;
  23. }
  24. }
  25. }
  26. P2P_Autoload::register( 'P2P_', dirname( __FILE__ ) );
  27. require_once dirname( __FILE__ ) . '/util.php';
  28. require_once dirname( __FILE__ ) . '/api.php';