'Ocean', 'dir' => get_template_directory_uri() .'/inc/', ); } // Core Constants define( 'OCEAN_THEME_DIR', get_template_directory() ); define( 'OCEAN_THEME_URI', get_template_directory_uri() ); // Auto update require_once( OCEAN_THEME_DIR .'/inc/wp-updates.php' ); new WPUpdatesThemeUpdater_1878( 'http://wp-updates.com/api/2/theme', basename( get_template_directory() ) ); class OCEAN_Theme_Class { /** * Main Theme Class Constructor * * @since 1.0.0 */ public function __construct() { // Define constants add_action( 'after_setup_theme', array( 'OCEAN_Theme_Class', 'constants' ), 0 ); // Load all core theme function files add_action( 'after_setup_theme', array( 'OCEAN_Theme_Class', 'include_functions' ), 1 ); // Load configuration classes add_action( 'after_setup_theme', array( 'OCEAN_Theme_Class', 'configs' ), 3 ); // Load framework classes add_action( 'after_setup_theme', array( 'OCEAN_Theme_Class', 'classes' ), 4 ); // Setup theme => add_theme_support, register_nav_menus, load_theme_textdomain, etc add_action( 'after_setup_theme', array( 'OCEAN_Theme_Class', 'theme_setup' ), 10 ); // Run after switch theme add_action( 'after_switch_theme', array( 'OCEAN_Theme_Class', 'after_switch_theme' ) ); // Load custom widgets add_action( 'after_setup_theme', array( 'OCEAN_Theme_Class', 'custom_widgets' ), 5 ); // register sidebar widget areas add_action( 'widgets_init', array( 'OCEAN_Theme_Class', 'register_sidebars' ) ); /** Admin only actions **/ if ( is_admin() ) { // Load scripts in the WP admin add_action( 'admin_enqueue_scripts', array( 'OCEAN_Theme_Class', 'admin_scripts' ) ); // Outputs custom CSS for the admin add_action( 'admin_head', array( 'OCEAN_Theme_Class', 'admin_inline_css' ) ); // Remove ocean_term_data when a term is removed add_action( 'delete_term', array( 'OCEAN_Theme_Class', 'delete_term' ), 5 ); /** Non Admin actions **/ } else { // Load theme CSS add_action( 'wp_enqueue_scripts', array( 'OCEAN_Theme_Class', 'theme_css' ) ); // Load responsive CSS - must be added last add_action( 'wp_enqueue_scripts', array( 'OCEAN_Theme_Class', 'responsive_css' ), 99 ); // Load theme js add_action( 'wp_enqueue_scripts', array( 'OCEAN_Theme_Class', 'theme_js' ) ); // Add meta viewport tag to header add_action( 'wp_head', array( 'OCEAN_Theme_Class', 'meta_viewport' ), 1 ); // Add theme meta generator add_action( 'wp_head', array( 'OCEAN_Theme_Class', 'theme_meta_generator' ), 1 ); // Add an X-UA-Compatible header add_filter( 'wp_headers', array( 'OCEAN_Theme_Class', 'x_ua_compatible_headers' ) ); // Browser dependent CSS add_action( 'wp_head', array( 'OCEAN_Theme_Class', 'browser_dependent_css' ) ); // Loads html5 shiv script add_action( 'wp_head', array( 'OCEAN_Theme_Class', 'html5_shiv' ) ); // Outputs custom CSS to the head add_action( 'wp_head', array( 'OCEAN_Theme_Class', 'custom_css' ), 9999 ); // Alter tagcloud widget to display all tags with 1em font size add_filter( 'widget_tag_cloud_args', array( 'OCEAN_Theme_Class', 'widget_tag_cloud_args' ) ); // Alter WP categories widget to display count inside a span add_filter( 'wp_list_categories', array( 'OCEAN_Theme_Class', 'wp_list_categories_args' ) ); // Add a responsive wrapper to the WordPress oembed output add_filter( 'embed_oembed_html', array( 'OCEAN_Theme_Class', 'add_responsive_wrap_to_oembeds' ), 99, 4 ); // Allow for the use of shortcodes in the WordPress excerpt add_filter( 'the_excerpt', 'shortcode_unautop' ); add_filter( 'the_excerpt', 'do_shortcode' ); // Adds classes the post class add_filter( 'post_class', array( 'OCEAN_Theme_Class', 'post_class' ) ); // Add schema markup to the authors post link add_filter( 'the_author_posts_link', array( 'OCEAN_Theme_Class', 'the_author_posts_link' ) ); } } /** * Define Constants * * @since 1.0.0 */ public static function constants() { $version = self::theme_version(); // Theme version define( 'OCEAN_THEME_VERSION', $version ); // Javascript and CSS Paths define( 'OCEAN_JS_DIR_URI', OCEAN_THEME_URI .'/assets/js/' ); define( 'OCEAN_CSS_DIR_URI', OCEAN_THEME_URI .'/assets/css/' ); // Include Paths define( 'OCEAN_INC_DIR', OCEAN_THEME_DIR .'/inc/' ); define( 'OCEAN_INC_DIR_URI', OCEAN_THEME_URI .'/inc/' ); // Classes directory define( 'OCEAN_CLASSES_DIR', OCEAN_INC_DIR .'/classes/' ); // Check if plugins are active define( 'OCEAN_WOOCOMMERCE_ACTIVE', class_exists( 'WooCommerce' ) ); } /** * Load all core theme function files * * @since 1.0.0 */ public static function include_functions() { $dir = OCEAN_INC_DIR; require_once ( $dir .'helpers.php' ); require_once ( $dir .'arrays.php' ); require_once ( $dir .'body-classes.php' ); require_once ( $dir .'fonts.php' ); require_once ( $dir .'page-header.php' ); require_once ( $dir .'walker/init.php' ); require_once ( $dir .'walker/menu-walker.php' ); require_once ( $dir .'post-classes.php' ); require_once ( $dir .'comments-callback.php' ); // Welcome page if ( ! defined( 'OCEAN_DISABLE_THEME_ABOUT_PAGE' ) ) { require_once( $dir .'welcome/welcome.php' ); } } /** * Configs for 3rd party plugins. * * @since 1.0.0 */ public static function configs() { $dir = OCEAN_INC_DIR; // WooCommerce if ( OCEAN_WOOCOMMERCE_ACTIVE ) { require_once ( $dir .'woocommerce/woocommerce-config.php' ); } } /** * Returns current theme version * * @since 1.0.0 */ public static function theme_version() { // Get theme data $theme = wp_get_theme(); // Return theme version return $theme->get( 'Version' ); } /** * Load theme classes * * @since 1.0.0 */ public static function classes() { // Classes Dir $dir = OCEAN_CLASSES_DIR; // Admin only classes if ( is_admin() ) { // Recommend plugins require_once( OCEAN_INC_DIR .'plugins/class-tgm-plugin-activation.php' ); require_once( OCEAN_INC_DIR .'plugins/tgm-plugin-activation.php' ); } // Front-end classes else { // Breadcrumbs class require_once( $dir .'breadcrumbs.php' ); } // Customizer class require_once( OCEAN_INC_DIR .'customizer/customizer.php' ); // Load the Updater class for ocean extensions require_once( OCEAN_INC_DIR .'classes/updater.php' ); } /** * Theme Setup * * @since 1.0.0 */ public static function theme_setup() { // Load text domain load_theme_textdomain( 'ocean', OCEAN_THEME_DIR .'/languages' ); // Get globals global $content_width; // Set content width based on theme's default design if ( ! isset( $content_width ) ) { $content_width = 1200; } // Register navigation menus register_nav_menus( array( 'topbar_menu' => esc_html__( 'Top Bar', 'ocean' ), 'main_menu' => esc_html__( 'Main', 'ocean' ), 'footer_menu' => esc_html__( 'Footer', 'ocean' ) ) ); // Enable support for Post Formats add_theme_support( 'post-formats', array( 'video', 'gallery', 'audio', 'quote', 'link' ) ); // Enable support for tag add_theme_support( 'title-tag' ); // Add default posts and comments RSS feed links to head add_theme_support( 'automatic-feed-links' ); // Enable support for Post Thumbnails on posts and pages add_theme_support( 'post-thumbnails' ); /** * Enable support for site logo */ add_theme_support( 'custom-logo', array( 'height' => 45, 'width' => 164, 'flex-height' => true, 'flex-width' => true, ) ); /* * Switch default core markup for search form, comment form, comments, galleries, captions and widgets * to output valid HTML5. */ add_theme_support( 'html5', array( 'search-form', 'comment-form', 'comment-list', 'gallery', 'caption', 'widgets', ) ); /** * Add support for the Site Logo plugin and the site logo functionality in JetPack * https://github.com/automattic/site-logo * http://jetpack.me/ */ add_theme_support( 'site-logo', array( 'size' => 'full' ) ); // Declare WooCommerce support. add_theme_support( 'woocommerce' ); // Enable excerpts for pages. add_post_type_support( 'page', 'excerpt' ); // Add editor style add_editor_style( 'editor-style.css' ); // Declare support for selective refreshing of widgets. add_theme_support( 'customize-selective-refresh-widgets' ); } /** * Functions called after theme switch * * @since 1.0.0 */ public static function after_switch_theme() { delete_metadata( 'user', null, 'tgmpa_dismissed_notice_ocean_theme', null, true ); } /** * Adds the meta tag to the site header * * @since 1.0.0 */ public static function meta_viewport() { $viewport = '<meta name="viewport" content="width=device-width, initial-scale=1">'; // Apply filters to the meta viewport for child theme tweaking echo apply_filters( 'ocean_meta_viewport', $viewport ); } /** * Adds meta generator for * * @since 1.0.0 */ public static function theme_meta_generator() { echo "\r\n"; echo '<meta name="generator" content="ocean WordPress Theme '. OCEAN_THEME_VERSION .'" />'; echo "\r\n"; } /** * Load scripts in the WP admin * * @since 1.0.0 */ public static function admin_scripts( $hook ) { if ( $hook == 'nav-menus.php' ) { wp_enqueue_style( 'ocean-nav-menus', OCEAN_INC_DIR_URI .'walker/assets/nav-menus.css' ); } } /** * Load front-end scripts * * @since 1.0.0 */ public static function theme_css() { // Define dir $dir = OCEAN_CSS_DIR_URI; $theme_version = OCEAN_THEME_VERSION; // Remove font awesome scripts from plugins wp_deregister_style( 'font-awesome' ); wp_deregister_style( 'fontawesome' ); // Load font awesome script wp_enqueue_style( 'font-awesome', $dir .'devs/font-awesome.min.css', false, '4.6.3' ); // Register simple line icons script wp_enqueue_style( 'simple-line-icons', $dir .'devs/simple-line-icons.min.css', false, '2.2.2' ); // Main Style.css File wp_enqueue_style( 'ocean-style', get_stylesheet_uri(), false, $theme_version ); } /** * Loads responsive css very last after all styles. * * @since 1.0.0 */ public static function responsive_css() { wp_enqueue_style( 'ocean-responsive', OCEAN_CSS_DIR_URI .'ocean-responsive.min.css', false, OCEAN_THEME_VERSION ); } /** * Returns all js needed for the front-end * * @since 1.0.0 */ public static function theme_js() { // Get js directory uri $dir = OCEAN_JS_DIR_URI; // Get current theme version $theme_version = OCEAN_THEME_VERSION; // Get localized array $localize_array = OCEAN_Theme_Class::localize_array(); // Comment reply if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) { wp_enqueue_script( 'comment-reply' ); } // WooCommerce quantity buttons if ( OCEAN_WOOCOMMERCE_ACTIVE ) { wp_enqueue_script( 'wc-quantity-increment', $dir .'dynamic/wc-quantity-increment.js', array( 'jquery' ), $theme_version, true ); } // Load minified js wp_enqueue_script( 'ocean-main', $dir .'main.min.js', array( 'jquery' ), $theme_version, true ); wp_localize_script( 'ocean-main', 'oceanLocalize', $localize_array ); } /** * Functions.js localize array * * @since 1.0.0 */ public static function localize_array() { // Create array $array = array( 'isRTL' => is_rtl(), 'menuSearchStyle' => ocean_menu_search_style(), 'sidrSource' => ocean_sidr_menu_source(), 'sidrDisplace' => get_theme_mod( 'ocean_mobile_menu_sidr_displace', true ) ? true : false, 'sidrSide' => get_theme_mod( 'ocean_mobile_menu_sidr_direction', 'left' ), 'sidrDropdownTarget' => 'arrow', 'customSelects' => '.woocommerce-ordering .orderby, .cart-collaterals .cart_totals table select, #dropdown_product_cat, .widget_categories select, .widget_archive select, .single-product .variations_form .variations select', ); // WooCart if ( OCEAN_WOOCOMMERCE_ACTIVE ) { $array['wooCartStyle'] = ocean_menu_cart_style(); } // Apply filters and return array return apply_filters( 'ocean_localize_array', $array ); } /** * Add headers for IE to override IE's Compatibility View Settings * * @since 1.0.0 */ public static function x_ua_compatible_headers( $headers ) { $headers['X-UA-Compatible'] = 'IE=edge'; return $headers; } /** * Adds CSS for ie8 * Applies the ocean_ie_8_url filter so you can alter your IE8 stylesheet URL * * @since 1.0.0 */ public static function browser_dependent_css() { $ie_8 = apply_filters( 'ocean_ie8_stylesheet', OCEAN_CSS_DIR_URI .'ie8.css' ); echo '<!--[if IE 8]><link rel="stylesheet" type="text/css" href="'. $ie_8 .'" media="screen"><![endif]-->'; $ie_9 = apply_filters( 'ocean_ie9_stylesheet', OCEAN_CSS_DIR_URI .'ie9.css' ); echo '<!--[if IE 9]><link rel="stylesheet" type="text/css" href="'. $ie_9 .'" media="screen"><![endif]-->'; } /** * Load HTML5 dependencies for IE8 * * @since 1.0.0 */ public static function html5_shiv() { echo '<!--[if lt IE 9]><script src="'. OCEAN_JS_DIR_URI .'html5.js"></script><![endif]-->'; } /** * Include all custom widget classes * * @since 1.0.0 */ public static function custom_widgets() { // Define directory for widgets $dir = OCEAN_CLASSES_DIR .'widgets/'; // Define array of custom widgets for the theme $widgets = apply_filters( 'ocean_custom_widgets', array( 'about-me', 'contact-info', 'custom-links', 'facebook', 'flickr', 'instagram', 'mailchimp', 'recent-posts', 'social', 'video', ) ); // Loop through widgets and load their files if ( $widgets && is_array( $widgets ) ) { foreach ( $widgets as $widget ) { if ( file_exists( $dir . $widget .'.php' ) ) { require_once( $dir . $widget .'.php' ); } } } } /** * Registers sidebars * * @since 1.0.0 */ public static function register_sidebars() { // Sidebar register_sidebar( array( 'name' => esc_html__( 'Sidebar', 'ocean' ), 'id' => 'sidebar', 'description' => esc_html__( 'Widgets in this area are used in the sidebar region.', 'ocean' ), 'before_widget' => '<div class="sidebar-box %2$s clr">', 'after_widget' => '</div>', 'before_title' => '<h5 class="widget-title">', 'after_title' => '</h5>', ) ); // Search Results Sidebar if ( get_theme_mod( 'ocean_search_custom_sidebar', true ) ) { register_sidebar( array( 'name' => esc_html__( 'Search Results Sidebar', 'ocean' ), 'id' => 'search_sidebar', 'description' => esc_html__( 'Widgets in this area are used in the search result page.', 'ocean' ), 'before_widget' => '<div class="sidebar-box %2$s clr">', 'after_widget' => '</div>', 'before_title' => '<h5 class="widget-title">', 'after_title' => '</h5>', ) ); } // Footer 1 register_sidebar( array( 'name' => esc_html__( 'Footer 1', 'ocean' ), 'id' => 'footer-one', 'description' => esc_html__( 'Widgets in this area are used in the first footer region.', 'ocean' ), 'before_widget' => '<div class="footer-widget %2$s clr">', 'after_widget' => '</div>', 'before_title' => '<h6 class="widget-title">', 'after_title' => '</h6>', ) ); // Footer 2 register_sidebar( array( 'name' => esc_html__( 'Footer 2', 'ocean' ), 'id' => 'footer-two', 'description' => esc_html__( 'Widgets in this area are used in the second footer region.', 'ocean' ), 'before_widget' => '<div class="footer-widget %2$s clr">', 'after_widget' => '</div>', 'before_title' => '<h6 class="widget-title">', 'after_title' => '</h6>', ) ); // Footer 3 register_sidebar( array( 'name' => esc_html__( 'Footer 3', 'ocean' ), 'id' => 'footer-three', 'description' => esc_html__( 'Widgets in this area are used in the third footer region.', 'ocean' ), 'before_widget' => '<div class="footer-widget %2$s clr">', 'after_widget' => '</div>', 'before_title' => '<h6 class="widget-title">', 'after_title' => '</h6>', ) ); // Footer 4 register_sidebar( array( 'name' => esc_html__( 'Footer 4', 'ocean' ), 'id' => 'footer-four', 'description' => esc_html__( 'Widgets in this area are used in the fourth footer region.', 'ocean' ), 'before_widget' => '<div class="footer-widget %2$s clr">', 'after_widget' => '</div>', 'before_title' => '<h6 class="widget-title">', 'after_title' => '</h6>', ) ); } /** * All theme functions hook into the ocean_head_css filter for this function. * * @since 1.0.0 */ public static function custom_css( $output = NULL ) { // Add filter for adding custom css via other functions $output = apply_filters( 'ocean_head_css', $output ); // Minify and output CSS in the wp_head if ( ! empty( $output ) ) { echo "<!-- Ocean CSS -->\n<style type=\"text/css\">\n" . wp_strip_all_tags( ocean_minify_css( $output ) ) . "\n</style>"; } } /** * Adds inline CSS for the admin * * @since 1.0.0 */ public static function admin_inline_css() { echo '<style>div#setting-error-tgmpa{display:block;}</style>'; } /** * When a term is deleted, delete its data. * * @since 1.0.0 */ public static function delete_term( $term_id ) { // If term id is defined if ( $term_id = absint( $term_id ) ) { // Get terms data $term_data = get_option( 'ocean_term_data' ); // Remove key with term data if ( $term_data && isset( $term_data[$term_id] ) ) { unset( $term_data[$term_id] ); update_option( 'ocean_term_data', $term_data ); } } } /** * Alters the default WordPress tag cloud widget arguments. * Makes sure all font sizes for the cloud widget are set to 1em. * * @since 1.0.0 */ public static function widget_tag_cloud_args( $args ) { $args['largest'] = '0.923em'; $args['smallest'] = '0.923em'; $args['unit'] = 'em'; return $args; } /** * Alter wp list categories arguments. * Adds a span around the counter for easier styling. * * @since 1.0.0 */ public static function wp_list_categories_args( $links ) { $links = str_replace( '</a> (', '</a> <span class="cat-count-span">(', $links ); $links = str_replace( ' )', ' )</span>', $links ); return $links; } /** * Alters the default oembed output. * Adds special classes for responsive oembeds via CSS. * * @since 1.0.0 */ public static function add_responsive_wrap_to_oembeds( $cache, $url, $attr, $post_ID ) { // Supported video embeds $hosts = apply_filters( 'ocean_oembed_responsive_hosts', array( 'vimeo.com', 'youtube.com', 'blip.tv', 'money.cnn.com', 'dailymotion.com', 'flickr.com', 'hulu.com', 'kickstarter.com', 'vine.co', 'soundcloud.com', '#http://((m|www)\.)?youtube\.com/watch.*#i', '#https://((m|www)\.)?youtube\.com/watch.*#i', '#http://((m|www)\.)?youtube\.com/playlist.*#i', '#https://((m|www)\.)?youtube\.com/playlist.*#i', '#http://youtu\.be/.*#i', '#https://youtu\.be/.*#i', '#https?://(.+\.)?vimeo\.com/.*#i', '#https?://(www\.)?dailymotion\.com/.*#i', '#https?://dai.ly/*#i', '#https?://(www\.)?hulu\.com/watch/.*#i', '#https?://wordpress.tv/.*#i', '#https?://(www\.)?funnyordie\.com/videos/.*#i', '#https?://vine.co/v/.*#i', '#https?://(www\.)?collegehumor\.com/video/.*#i', '#https?://(www\.|embed\.)?ted\.com/talks/.*#i' ) ); // Supports responsive $supports_responsive = false; // Check if responsive wrap should be added foreach( $hosts as $host ) { if ( strpos( $url, $host ) !== false ) { $supports_responsive = true; break; // no need to loop further } } // Output code if ( $supports_responsive ) { return '<p class="responsive-video-wrap clr">' . $cache . '</p>'; } else { return '<div class="ocean-oembed-wrap clr">' . $cache . '</div>'; } } /** * Adds extra classes to the post_class() output * * @since 1.0.0 */ public static function post_class( $classes ) { // Get post global $post; // Add entry class $classes[] = 'entry'; // Add has media class if ( has_post_thumbnail() || get_post_meta( $post->ID, 'ocean_post_oembed', true ) || get_post_meta( $post->ID, 'ocean_post_self_hosted_media', true ) || get_post_meta( $post->ID, 'ocean_post_video_embed', true ) ) { $classes[] = 'has-media'; } // Return classes return $classes; } /** * Add schema markup to the authors post link * * @since 1.0.0 */ public static function the_author_posts_link( $link ) { // Add schema markup $schema = 'itemprop="author" itemscope="itemscope" itemtype="http://schema.org/Person"'; if ( $schema ) { $link = str_replace( 'rel="author"', 'rel="author"'. $schema, $link ); } // Return link return $link; } } $ocean_theme_class = new OCEAN_Theme_Class;