Open liton139 opened 1 year ago
class cannot work properly
Code is here ...
Function.php
<?php
/***
*/
if (! defined('MEDICALTHEME_DIR_PATH')){ define('MEDICALTHEME_DIR_PATH', untrailingslashit( get_template_directory())); }
function medical_get_theme_instance(){ \MEDICALTHEME\Inc\MEDICAL_THEME::get_instance(); }
medical_get_theme_instance();
require_once MEDICALTHEME_DIR_PATH . '/inc/helpers/autoloader.php';
function Medical_enqueue_scripts() {
// Register Styles wp_register_style('style-css', get_stylesheet_uri(), [], filemtime(get_template_directory() . '/style.css'),'all'); wp_register_style('bootstrap-css', get_template_directory_uri() . '/assets/src/library/css/bootstrap.min.css', [], false,'all'); // Register Scripts wp_register_script('main-js', get_template_directory_uri() . '/assets/main.js',[], filemtime(get_template_directory() .'/assets/main.js'), true ); wp_register_script('bootstrap-js', get_template_directory_uri() . '/assets/src/library/js/bootstrap.min.js',['jquery'], false, true ); // enqueue style wp_enqueue_style('style-css'); wp_enqueue_style('bootstrap-css'); // enqueue scripts wp_enqueue_script('main-js'); wp_enqueue_script('bootstrap-js');
} add_action('wp_enqueue_scripts', 'Medical_enqueue_scripts');
?>
traits-singleton.php
<?php /**
namespace MEDICALTHEME\Inc\Traits;
trait Singleton{ public function __construct(){
} public function __clone(){
} final public static function get_instance(){ static $instance =[];
$called_class = get_called_class(); if (!isset($instance[ $called_class ])){ $instance[$called_class] = new $called_class(); do_action( sprintf('MEDICAL_THEME_singletion_init%s', $called_class )); } return $instance[ $called_class ];
} }
class-medicaltheme.php
namespace MEDICALTHEME\Inc;
use MEDICALTHEME\Inc\Traits\Singleton;
class MEDICAL_THEME{ use Singleton;
protected function __construct(){ wp_die('hello'); //load class. $this->set_hooks(); } protected function set_hooks(){ //actions and filters }
}
class cannot work properly
Code is here ...
Function.php
<?php
/***
*/
if (! defined('MEDICALTHEME_DIR_PATH')){ define('MEDICALTHEME_DIR_PATH', untrailingslashit( get_template_directory())); }
function medical_get_theme_instance(){ \MEDICALTHEME\Inc\MEDICAL_THEME::get_instance(); }
medical_get_theme_instance();
require_once MEDICALTHEME_DIR_PATH . '/inc/helpers/autoloader.php';
function Medical_enqueue_scripts() {
} add_action('wp_enqueue_scripts', 'Medical_enqueue_scripts');
?>
traits-singleton.php
<?php /**
*/
namespace MEDICALTHEME\Inc\Traits;
trait Singleton{ public function __construct(){
} public function __clone(){
} final public static function get_instance(){ static $instance =[];
} }
class-medicaltheme.php
<?php /**
namespace MEDICALTHEME\Inc;
use MEDICALTHEME\Inc\Traits\Singleton;
class MEDICAL_THEME{ use Singleton;
}