✨feature: Initial commit
This commit is contained in:
@@ -0,0 +1,128 @@
|
||||
<?php
|
||||
/**
|
||||
* The core plugin class.
|
||||
*
|
||||
* @package AA_Events
|
||||
*/
|
||||
|
||||
// If this file is called directly, abort.
|
||||
if ( ! defined( 'WPINC' ) ) {
|
||||
die;
|
||||
}
|
||||
|
||||
/**
|
||||
* The core plugin class.
|
||||
*/
|
||||
final class AA_Events {
|
||||
|
||||
/**
|
||||
* The single instance of the class.
|
||||
*
|
||||
* @var AA_Events
|
||||
*/
|
||||
protected static $instance = null;
|
||||
|
||||
/**
|
||||
* Main AA_Events Instance.
|
||||
*
|
||||
* Ensures only one instance of AA_Events is loaded or can be loaded.
|
||||
*
|
||||
* @static
|
||||
* @return AA_Events - Main instance.
|
||||
*/
|
||||
public static function instance() {
|
||||
if ( is_null( self::$instance ) ) {
|
||||
self::$instance = new self();
|
||||
}
|
||||
|
||||
return self::$instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* AA_Events Constructor.
|
||||
*/
|
||||
public function __construct() {
|
||||
$this->includes();
|
||||
$this->init_hooks();
|
||||
}
|
||||
|
||||
/**
|
||||
* Include required core files.
|
||||
*/
|
||||
public function includes() {
|
||||
include_once AA_EVENTS_PLUGIN_DIR . 'includes/post-types.php';
|
||||
include_once AA_EVENTS_PLUGIN_DIR . 'includes/acf-fields.php';
|
||||
include_once AA_EVENTS_PLUGIN_DIR . 'includes/template-loader.php';
|
||||
}
|
||||
|
||||
/**
|
||||
* Hook into actions and filters.
|
||||
*/
|
||||
private function init_hooks() {
|
||||
add_action( 'init', array( $this, 'load_plugin_textdomain' ) );
|
||||
add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_styles' ) );
|
||||
// Ensure the active theme supports thumbnails for the event post type.
|
||||
add_action( 'after_setup_theme', array( $this, 'ensure_post_thumbnails_support' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Enqueue styles.
|
||||
*/
|
||||
public function enqueue_styles() {
|
||||
$theme_stylesheet = get_stylesheet_directory() . '/aa-events/aa-events.css';
|
||||
|
||||
if ( file_exists( $theme_stylesheet ) ) {
|
||||
wp_enqueue_style(
|
||||
'aa-events-theme',
|
||||
get_stylesheet_directory_uri() . '/aa-events/aa-events.css',
|
||||
array(),
|
||||
filemtime( $theme_stylesheet )
|
||||
);
|
||||
} else {
|
||||
wp_enqueue_style(
|
||||
'aa-events',
|
||||
AA_EVENTS_PLUGIN_URL . 'assets/css/aa-events.css',
|
||||
array(),
|
||||
AA_EVENTS_VERSION
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Load Localisation files.
|
||||
*/
|
||||
public function load_plugin_textdomain() {
|
||||
load_plugin_textdomain(
|
||||
'aa-events',
|
||||
false,
|
||||
dirname( plugin_basename( __FILE__ ) ) . '/languages/'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensure the theme supports post thumbnails for events.
|
||||
*
|
||||
* Some themes do not declare `add_theme_support( 'post-thumbnails' )`,
|
||||
* which hides the Featured Image panel. This enables thumbnails at least
|
||||
* for the `event` post type without impacting other types.
|
||||
*/
|
||||
public function ensure_post_thumbnails_support() {
|
||||
$support = get_theme_support( 'post-thumbnails' );
|
||||
|
||||
// If theme has no support at all, enable it for events only.
|
||||
if ( false === $support ) {
|
||||
add_theme_support( 'post-thumbnails', array( 'event' ) );
|
||||
return;
|
||||
}
|
||||
|
||||
// If theme supports specific post types, ensure 'event' is included.
|
||||
if ( is_array( $support ) && isset( $support[0] ) && is_array( $support[0] ) ) {
|
||||
$post_types = $support[0];
|
||||
if ( ! in_array( 'event', $post_types, true ) ) {
|
||||
$post_types[] = 'event';
|
||||
add_theme_support( 'post-thumbnails', $post_types );
|
||||
}
|
||||
}
|
||||
// If theme support is boolean true (all types), nothing to do.
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user