. */ if(!defined('ABSPATH')) { exit('Not allowed to access pages directly.'); } define('AFFILICIOUS_THEME_ROOT_PATH', get_template_directory()); define('AFFILICIOUS_THEME_ROOT_URL', get_template_directory_uri()); if(!class_exists('Affc_Affilivice_Theme')) { final class Affc_Affilivice_Theme { const NAME = 'affilivice'; const VERSION = '0.7.2'; const MIN_PHP_VERSION = '5.6'; /** * Stores the singleton instance. * * @var \Affc_Affilivice_Theme */ private static $instance; /** * A reference to the main plugin. * * @see https://github.com/affilicious-theme/affilicious * @var Affilicious_Plugin */ private $affilicious; /** * Register all services and parameters for the pimple dependency injection. * This container is just a reference to the container of the _affilicious plugin. * * @see http://pimple.sensiolabs.org * @var Pimple\Container */ private $container; /** * Get the instance of the affilicious theme. * * @since 0.3 * @return Affc_Affilivice_Theme */ public static function get_instance() { if (self::$instance === null) { self::$instance = new \Affc_Affilivice_Theme(); } return self::$instance; } /** * Get the root path of the affilicious theme. * * @since 0.2 * @return string */ public static function get_root_path() { return AFFILICIOUS_THEME_ROOT_PATH; } /** * Get the root url of the affilicious theme. * * @since 0.2 * @return string */ public static function get_root_url() { return AFFILICIOUS_THEME_ROOT_URL; } /** * Prepare the plugin with for usage with Wordpress and namespaces. * * @since 0.2 */ public function __construct() { // Gracefully fail the theme, if the PHP Version is not sufficient. if(version_compare(phpversion(), self::MIN_PHP_VERSION, '<')) { return; } // Make namespaces and autoloading available if (file_exists(__DIR__ . '/vendor/autoload.php')) { require(__DIR__ . '/vendor/autoload.php'); } spl_autoload_register(array($this, 'autoload')); // Load the affilicious plugin and the dependency container on existence if(class_exists('\Affilicious_Plugin')) { $this->affilicious = \Affilicious_Plugin::get_instance(); $this->container = $this->affilicious->get_container(); } else { $this->container = new Pimple\Container(); } } /** * Make namespaces compatible with the source code of this theme. * * @since 0.2 * @param string $class */ public function autoload($class) { $prefix = 'Affilivice\\'; if (stripos($class, $prefix) === false) { return; } $file_path = str_ireplace('Affilivice\\', '', $class) . '.php'; $file_path = strtolower($file_path); $file_path = str_replace('_', '-', $file_path); $file_path = __DIR__ . '/src/' . $file_path; $file_path = str_replace('\\', DIRECTORY_SEPARATOR, $file_path); /** @noinspection PhpIncludeInspection */ include_once($file_path); } /** * Run all of the theme code. * * @since 0.2 */ public function run() { // Hook the theme activation and deactivation add_action('after_switch_theme', array($this, 'activate')); add_action('switch_theme', array($this, 'deactivate')); // Gracefully fail the theme, if the PHP Version is not sufficient. if(version_compare(phpversion(), self::MIN_PHP_VERSION, '<')) { return; } // Hook the theme support and textdomain add_action('after_setup_theme', array($this, 'load_support')); add_action('after_setup_theme', array($this, 'load_textdomain')); $this->load_includes(); $this->load_services(); $this->load_content_width(); $this->register_public_hooks(); $this->register_admin_hooks(); } /** * The code that runs during theme activation. * * @since 0.2 */ public function activate() { // Check the PHP version requirement if(!version_compare(phpversion(), self::MIN_PHP_VERSION, '>=')) { switch_theme(''); $this->load_textdomain(); wp_die(sprintf( __('Affilivice Theme requires at least the PHP version %s to reveal the full potential. Please switch the PHP version in your hosting provider.', 'affilivice'), self::MIN_PHP_VERSION )); } // Apply the backup styles if(isset($this->container['affilivice.design.service.customizer_mods_backup'])) { $customizer_mods_backup_service = $this->container['affilivice.design.service.customizer_mods_backup']; if($customizer_mods_backup_service !== null) { $customizer_mods_backup_service->activate(); } } } /** * The code that runs during theme deactivation. * * @since 0.2 */ public function deactivate() { } /** * Load the supported theme options. * * @since 0.2 */ public function load_support() { add_theme_support('post-thumbnails'); add_theme_support('title-tag'); add_theme_support('automatic-feed-links'); } /** * Load the static content width. * * @since 0.8 */ public function load_content_width() { global $content_width; if (!isset($content_width)) { $content_width = 900; } } /** * Load the theme textdomain for internationalization. * * @since 0.2 */ public function load_textdomain() { $dir = self::get_root_path() . '/languages'; load_theme_textdomain(self::NAME, $dir); } /** * Load the includes. * * @since 0.3.4 */ public function load_includes() { require_once('include/customizer-library/customizer-library.php'); } /** * Register the services for the dependency injection. * * @since 0.3.4 */ public function load_services() { $this->container['affilivice.design.setup.assets'] = function () { return new \Affilivice\Design\Setup\Assets_Setup(); }; $this->container['affilivice.design.setup.content'] = function () { return new \Affilivice\Design\Setup\Content_Setup(); }; $this->container['affilivice.design.setup.comment'] = function () { return new \Affilivice\Design\Setup\Comment_Setup(); }; $this->container['affilivice.design.setup.menu'] = function () { return new \Affilivice\Design\Setup\Menu_Setup(); }; $this->container['affilivice.design.setup.sidebar'] = function () { return new \Affilivice\Design\Setup\Sidebar_Setup(); }; $this->container['affilivice.design.setup.customizer'] = function () { return new \Affilivice\Design\Setup\Customizer_Setup(); }; $this->container['affilivice.design.setup.widget'] = function () { return new \Affilivice\Design\Setup\Widget_Setup(); }; $this->container['affilivice.design.service.customizer_mods_backup'] = function() { return new \Affilivice\Design\Service\Customizer_Mods_Backup_Service(); }; $this->container['affilivice.design.migration.options'] = function() { return new \Affilivice\Design\Migration\Options_Migration(); }; $this->container['affilivice.design.migration.mods_backup'] = function($c) { return new \Affilivice\Design\Migration\Mods_Backup_Migration( $c['affilivice.design.service.customizer_mods_backup'] ); }; $this->container['affilivice.design.filter.pagination'] = function() { return new \Affilivice\Design\Filter\Pagination_Filter(); }; $this->container['affilivice.design.filter.archive_title'] = function() { return new \Affilivice\Design\Filter\Archive_Title_Filter(); }; } /** * Register all of the hooks related to the public-facing functionality. * * @since 0.2 */ public function register_public_hooks() { // Hook the public styles and scripts $asset_setup = $this->container['affilivice.design.setup.assets']; add_action('wp_enqueue_scripts', array($asset_setup, 'add_public_styles')); add_action('wp_enqueue_scripts', array($asset_setup, 'add_public_scripts')); // Hook the sidebars $sidebar_setup = $this->container['affilivice.design.setup.sidebar']; add_action('widgets_init', array($sidebar_setup, 'init')); add_filter('dynamic_sidebar_params', array($sidebar_setup, 'modify_sidebar_params')); // Hook the widgets $widget_setup = $this->container['affilivice.design.setup.widget']; add_filter('widgets_init', array($widget_setup, 'register_widgets')); add_filter('widget_tag_cloud_args', array($widget_setup, 'modifiy_tag_cloud')); // Hook the menus $menu_setup = $this->container['affilivice.design.setup.menu']; add_action('after_setup_theme', array($menu_setup, 'init')); // Hook the content $content_setup = $this->container['affilivice.design.setup.content']; add_filter('the_content', array($content_setup, 'set_table_class')); add_filter('excerpt_length', array($content_setup, 'set_excerpt_length')); add_filter('post_thumbnail_html', array($content_setup, 'remove_img_dimensions')); add_filter('the_content', array($content_setup, 'remove_img_dimensions')); add_filter('get_avatar', array($content_setup, 'remove_img_dimensions')); add_filter('the_content', array($content_setup, 'wrap_fluid_media')); // Hook the comments $comment_setup = $this->container['affilivice.design.setup.comment']; add_filter('comment_form_default_fields', array($comment_setup, 'set_form_default_fields')); add_filter('comment_form_defaults', array($comment_setup, 'set_form_defaults')); add_filter('after_setup_theme', array($comment_setup, 'set_theme_support')); // Hook the theme customizer $customizer_setup = $this->container['affilivice.design.setup.customizer']; add_action('init', array($customizer_setup, 'init'), 100); add_action('init', array($customizer_setup, 'render'), 102); add_action('wp_enqueue_scripts', array($customizer_setup, 'enqueue_scripts')); add_action('wp_head', array($customizer_setup, 'head')); // Hook the options migration $options_migration = $this->container['affilivice.design.migration.options']; add_action('init', array($options_migration, 'migrate'), 1); // Hook the mods backup migration $mods_backup_migration = $this->container['affilivice.design.migration.mods_backup']; add_action('init', array($mods_backup_migration, 'migrate'), 1); // Hook the pagination filter $pagination_filter = $this->container['affilivice.design.filter.pagination']; add_action('navigation_markup_template', array($pagination_filter, 'filter')); // Hook the archive title filter $archive_title_filter = $this->container['affilivice.design.filter.archive_title']; add_action('get_the_archive_title', array($archive_title_filter, 'filter')); } /** * Register all of the hooks related to the admin area functionality. * * @since 0.2 */ public function register_admin_hooks() { // Hook the mods backup $customizer_mods_backup_service = $this->container['affilivice.design.service.customizer_mods_backup']; add_action('customize_save_after', array($customizer_mods_backup_service, 'store_backup'), 99); add_action('added_option', array($customizer_mods_backup_service, 'apply_backup'), 999, 1); add_action('updated_option', array($customizer_mods_backup_service, 'apply_backup'), 999, 1); // Hook the admin and theme customizer styles and scripts $asset_setup = $this->container['affilivice.design.setup.assets']; add_action('customize_preview_init', array($asset_setup, 'add_customizer_scripts')); } /** * Get the dependency injection container. * * @since 0.3.4 * @return Pimple\Container */ public function get_container() { return $this->container; } } $affc_affilivice_theme = \Affc_Affilivice_Theme::get_instance(); $affc_affilivice_theme->run(); }