3 (load library theme-scripts.js) (ok)

// Lionel Load file js && css
define( 'PFCOREELEMENTSURLPUBLIC', get_template_directory_uri().'/public/' );
require get_parent_theme_file_path( '/coreelements-public.php' );
require get_parent_theme_file_path( '/coreelements-loader.php' );
require get_parent_theme_file_path( '/coreelements.php' );
<?php
class Coreelements_Public {
  public function enqueue_styles_scripts() {
    wp_register_script('theme-scriptspf', PFCOREELEMENTSURLPUBLIC . 'js/theme-scripts.js', ['jquery', 'jquery-ui-autocomplete'], '2.0', true);
    wp_enqueue_script('theme-scriptspf');
  }
}
?>
<?php
class Coreelements_Loader {
  protected $actions;
  public function __construct() {
    $this->actions = array();
  }
  public function add_action($hook, $component, $callback, $priority = 10, $accepted_args = 1) {
    $this->actions = $this->add($this->actions, $hook, $component, $callback, $priority, $accepted_args);
  }
  private function add($hooks, $hook, $component, $callback, $priority, $accepted_args) {
    $hooks[] = array(
      'hook'          => $hook,
      'component'     => $component,
      'callback'      => $callback,
      'priority'      => $priority,
      'accepted_args' => $accepted_args,
    );
    return $hooks;
  }
  public function run() {
    foreach ($this->actions as $hook) {
      add_action($hook['hook'], array($hook['component'], $hook['callback']), $hook['priority'], $hook['accepted_args']);
    }
  }
}
?>
<?php
class Coreelements {
  protected $loader;
  public function __construct() {
  	$this->load_dependencies();
  	$this->define_public_hooks();
  }
  private function load_dependencies() {
  	$this->loader = new Coreelements_Loader();
  }
  private function define_public_hooks() {
  	$plugin_public = new Coreelements_Public();
  	$this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'enqueue_styles_scripts' );
  }
  public function run() {
		$this->loader->run();
	}
}
$plugin = new Coreelements();
$plugin->run();
?>

Last updated