Skip to content

Instantly share code, notes, and snippets.

@asifpix
Created September 26, 2019 07:55
Show Gist options
  • Save asifpix/1c251251c013d747ee5cb9221fd85d89 to your computer and use it in GitHub Desktop.
Save asifpix/1c251251c013d747ee5cb9221fd85d89 to your computer and use it in GitHub Desktop.
Autoloader also looking for theme's class file.
<?php
/**
* Plugin Name: Travelux Core
* Plugin URI: http://ithemeslab.com/
* Description: Extends the functionality of Travelux Theme.
* Version: 1.0.0
* Author: iThemesLab
* Author URI: https://ithemeslab.com/
* Text Domain: travelux-core
* Domain Path: /languages
*/
?>
<?php
namespace TraveluxCore;
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
}
final class Travelux_Core {
private static $_instance = null;
public static function instance() {
if ( is_null( self::$_instance ) ) {
self::$_instance = new self();
}
return self::$_instance;
}
public function __construct() {
add_action( 'init', [ $this, 'i18n' ] );
add_action( 'plugins_loaded', [ $this, 'init' ] );
add_action( 'admin_enqueue_scripts', [ $this, 'admin_assets' ] );
$this->run();
$this->travelux_class_instantiate();
}
public function i18n() {
load_plugin_textdomain( 'travelux-core', false, plugin_dir_url( __FILE__ ) . '/languages' );
}
public function autoload( $classname ){
$dirpath = plugin_dir_path( __FILE__ ) .'inc/class/';
$filename = $classname . '.php';
require_once ( $dirpath . $filename );
}
public function run(){
spl_autoload_register( [ $this, 'autoload' ], true );
}
public function travelux_class_instantiate(){
$tl_tour_post_type = new \TraveluxCore\Travelux_Tour_Post_Type();
}
}
Travelux_Core::instance();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment