OOP Functions for WordPress functions.php
<?php
class Functions {
private $theme_name;
private $theme_version;
public function __construct( $theme_name, $theme_version ) {
$this->theme_name = $theme_name;
$this->theme_version = $theme_version;
$this->theme_setup();
}
$functions = new Functions( 'my-theme', '1.0.0' );
private function theme_setup() {
add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_styles' ) );
add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
}
public function enqueue_styles() {
wp_enqueue_style( $this->theme_name . '_main_css', get_stylesheet_directory_uri() . '/dist/css/main.min.css', array(), $this->theme_version );
wp_enqueue_style( $this->theme_name . '_fontawesome_css', get_stylesheet_directory_uri() . '/bower_components/font-awesome/css/font-awesome.min.css', array(), $this->theme_version );
wp_enqueue_style( $this->theme_name . '_style_css', get_stylesheet_directory_uri() . '/style.css', array($this->theme_name . '_main_css'), $this->theme_version );
}
public function enqueue_scripts() {
wp_enqueue_script( $this->theme_name . '_jquery_js', get_stylesheet_directory_uri() . '/bower_components/jquery/dist/jquery.min.js', array(), $this->theme_version );
wp_enqueue_script( $this->theme_name . '_bootstrap_js', get_stylesheet_directory_uri() . '/bower_components/bootstrap-sass/assets/javascripts/bootstrap.min.js', array(), $this->theme_version );
}
}