theme_mods = $this->get_theme_mod_defaults();
add_action( 'after_switch_theme', array( $this, 'apple_save_default_thememods' ) );
add_action('switch_theme', array( $this, 'apple_theme_deactivation' ) );
add_action( 'after_setup_theme', array( $this, 'theme_setup' ) );
add_action( 'after_setup_theme', array( $this, 'content_width' ), 0 );
add_action( 'init', array( $this, 'add_excerpts_to_pages' ) );
add_action( 'wp_head', array( $this, 'javascript_detection' ), 0 );
add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_front_scripts' ) );
add_action( 'wp_enqueue_scripts', array( 'AppleThemeCustomizer', 'enqueue_inline_css' ) );
add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_admin_scripts' ) );
add_filter( 'body_class', array( $this, 'body_classes' ) );
add_action( 'widgets_init', array( $this, 'widgets_init' ) );
add_action( 'add_meta_boxes', array( $this, 'add_page_meta_boxes' ) );
add_action( 'save_post', array( $this, 'save_meta_box' ) );
add_action( 'init', array( $this, 'deps_check') );
}
/**
* Sets up theme defaults and registers support for various WordPress features.
*
* Note that this function is hooked into the after_setup_theme hook, which
* runs before the init hook. The init hook is too late for some features, such
* as indicating support for post thumbnails.
*
* Create your own apple_setup() function to override in a child theme.
*
* @since Apple 1.0
*/
public function theme_setup() {
/*
* Make theme available for translation.
* Translations can be filed in the /languages/ directory.
* If you're building a theme based on apple, use a find and replace
* to change 'tm-apple' to the name of your theme in all the template files
*/
load_theme_textdomain( 'tm-apple', get_template_directory() . '/languages' );
// Add default posts and comments RSS feed links to head.
add_theme_support( 'automatic-feed-links' );
/*
* Let WordPress manage the document title.
* By adding theme support, we declare that this theme does not use a
* hard-coded
tag in the document head, and expect WordPress to
* provide it for us.
*/
add_theme_support( 'title-tag' );
/**
* Enable support for custom logo.
*
* @since Apple 1.0
*/
add_theme_support( 'custom-logo', array(
'height' => 115,
'width' => 50,
'flex-height' => true,
) );
/**
* WooCommerce Support
*/
add_theme_support( 'woocommerce' );
/**
* Enable support for Post Thumbnails on posts and pages.
*
* @link http://codex.wordpress.org/Function_Reference/add_theme_support#Post_Thumbnails
*/
add_theme_support( 'post-thumbnails' );
set_post_thumbnail_size( 1200, 9999 );
// This theme uses wp_nav_menu() in two locations.
register_nav_menus( array(
'primary' => __( 'Primary Menu', 'tm-apple' ),
'social' => __( 'Social Links Menu', 'tm-apple' ),
) );
/*
* Switch default core markup for search form, comment form, and comments
* to output valid HTML5.
*/
add_theme_support( 'html5', array(
'search-form',
'comment-form',
'comment-list',
'gallery',
'caption',
) );
/*
* Enable support for Post Formats.
*
* See: https://codex.wordpress.org/Post_Formats
*/
add_theme_support( 'post-formats', array(
'aside',
'image',
'video',
'quote',
'link',
'gallery',
'status',
'audio',
'chat',
) );
/*
* This theme styles the visual editor to resemble the theme style,
* specifically font, colors, icons, and column width.
*/
add_editor_style( array( 'css/editor-style.css', call_user_func( array( __CLASS__ , 'fonts_url' ) ) ) );
// Indicate widget sidebars can use selective refresh in the Customizer.
add_theme_support( 'customize-selective-refresh-widgets' );
}
/**
* Sets the content width in pixels, based on the theme's design and stylesheet.
*
* Priority 0 to make it available to lower priority callbacks.
*
* @global int $content_width
*
* @since Apple 1.0
*/
public function content_width() {
$GLOBALS['content_width'] = apply_filters( 'apple_content_width', 840 );
}
public function add_excerpts_to_pages() {
add_post_type_support( 'page', 'excerpt' );
}
/**
* Register Google fonts for apple.
*
* Create your own fonts_url() function to override in a child theme.
*
* @since Apple 1.0
*
* @return string Google fonts URL for the theme.
*/
public static function fonts_url( $fonts = array() ) {
$fonts_url = '';
$subsets = 'latin,latin-ext';
//$theme_mods = $GLOBALS[ 'apple_theme_mods' ];
if( empty( $fonts ) ) {
$fonts[] = apple_get_theme_mod( 'apple_font_family_one' );
$fonts[] = apple_get_theme_mod( 'apple_font_family_two' );
$fonts[] = apple_get_theme_mod( 'apple_font_family_three' );
if ( $fonts ) {
$fonts_url = add_query_arg( array(
'family' => urlencode( implode( '|', $fonts ) ),
'subset' => urlencode( $subsets ),
), 'https://fonts.googleapis.com/css' );
}
}
return $fonts_url;
}
/**
* Handles JavaScript detection.
*
* Adds a `js` class to the root `` element when JavaScript is detected.
*
* @since Apple 1.0
*/
function javascript_detection() {
echo "\n";
}
/**
* Enqueues front scripts and styles.
* @since Apple 1.0
*/
function enqueue_front_scripts() {
// Add custom fonts, used in the main stylesheet.
wp_enqueue_style( 'apple-fonts', self::fonts_url(), array(), null );
//Bootstrap, Font-awesome, Mega menu
wp_enqueue_style( 'apple-vendor-styles', get_theme_file_uri( '/css/vendor-styles.min.css' ), array(), filemtime( get_theme_file_path( '/css/vendor-styles.min.css' ) ) );
// Theme stylesheet.
wp_enqueue_style( 'apple-style', get_stylesheet_uri() );
//Bootstrap rtl
//wp_enqueue_style( 'apple-bootstrap-rtl', get_template_directory_uri() . '/rtl.decompressed.css' );
if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
wp_enqueue_script( 'comment-reply' );
}
$theme_mods = $GLOBALS[ 'apple_theme_mods' ];
wp_enqueue_script( 'wp-mediaelement' );
wp_enqueue_style( 'wp-mediaelement' );
if( is_front_page() ) {
wp_enqueue_script( 'apple-custom',get_theme_file_uri( '/js/front-page-vendor-scripts.min.js' ),array( 'jquery' ),
filemtime( get_theme_file_path( '/js/front-page-vendor-scripts.min.js' ) ), true );
}else {
wp_enqueue_script( 'apple-custom', get_theme_file_uri( '/js/inner-page-vendor-scripts.min.js' ),array( 'jquery' ),
filemtime( get_theme_file_path( '/js/inner-page-vendor-scripts.min.js' ) ), true );
}
}
/**
* Enqueues admin scripts and styles.
* @since Apple 1.0
*/
function enqueue_admin_scripts() {
wp_enqueue_script( 'apple_media_upload', get_theme_file_uri( '/js/media-uploader.min.js' ), false,
filemtime( get_theme_file_path( '/js/media-uploader.min.js' ) ), true );
}
public function apple_save_default_thememods() {
set_theme_mod( 'apple_default_header_image_uri', esc_url_raw( get_theme_file_uri( '/images/header-image.jpg' ) ) );
}
/**
* Synchronizes free version and pro version of theme whenever theme is deactivated
* @return void
*/
public function apple_theme_deactivation() {
update_option( 'theme_mods_tm-apple-pro', get_option( 'theme_mods_tm-apple' ) );
}
/**
* returns theme mods with default values
* @return array
*/
public function get_theme_mod_defaults( $control = null, $force_update = false ) {
if( ! empty( $GLOBALS[ 'apple_theme_mods' ] ) && $force_update === false ) {
return $GLOBALS[ 'apple_theme_mods' ];
}
$theme_mod_defaults = array();
require get_theme_file_path( '/inc/defaults.php' );
$defaults = array_merge( $controls, $color_controls );
if( ! empty( $defaults ) ) {
foreach ( $defaults as $section => $default ) {
foreach ( $default as $key => $value ) {
$theme_mod_defaults[ $key ] = get_theme_mod( $key, $value[ 'default' ] );
}
}
}
$theme_mod_defaults[ 'apple_logo' ] = $apple_logo;
$GLOBALS[ 'apple_theme_mods' ] = $theme_mod_defaults;
return $theme_mod_defaults;
}
/**
* Adds custom classes to the array of body classes.
*
* @since Apple 1.0
*
* @param array $classes Classes for the body element.
* @return array (Maybe) filtered body classes.
*/
function body_classes( $classes ) {
// Adds a class of hfeed to non-singular pages.
if ( ! is_singular() ) {
$classes[] = 'hfeed';
}
return $classes;
}
/**
* Registers a widget area.
*
* @link https://developer.wordpress.org/reference/functions/register_sidebar/
*
* @since 1.0
*/
function widgets_init() {
register_sidebar( array(
'name' => __( 'Sidebar', 'tm-apple' ),
'id' => 'sidebar-1',
'description' => __( 'Add widgets here to appear in your sidebar.', 'tm-apple' ),
'before_widget' => '',
'after_widget' => '',
'before_title' => '
',
'after_title' => '
',
) );
}
/**
* Register the required plugins for this theme.
*
* This function is hooked into tgmpa_init, which is fired within the
* TGM_Plugin_Activation class constructor.
*/
public function deps_check()
{
include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
if( ! is_plugin_active( 'apple-theme-pack/main.php' ) ) {
add_action( 'admin_notices', function() {
?>
Apple needs companion plugin "Apple Theme Pack" to work properly. Please install and activate it.
Apple also recommends you to use following optional plugins.