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 `<html>` element when JavaScript is detected. * * @since Apple 1.0 */ function javascript_detection() { echo "<script>(function(html){html.className = html.className.replace(/\bno-js\b/,'js')})(document.documentElement);</script>\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' => '<section id="%1$s" class="widget %2$s">', 'after_widget' => '</section>', 'before_title' => '<h2 class="widget-title">', 'after_title' => '</h2>', ) ); } /** * 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() { ?> <div class="notice notice-warning is-dismissible"> <p> <?php printf( __( '<p><h3>Apple needs companion plugin "Apple Theme Pack" to work properly. Please install and activate it.</h3></p> <p>Apple also recommends you to use following optional plugins.</p> <p><a href="%s">WooCommerce</a> to show your products.</p> <p><a href="%s">Contact Form 7</a> to show quick quote and contact forms.</p> <p><a href="%s">Breadcrumb NavXT</a> to show breadcrumbs.</p>', 'tm-apple' ), esc_url_raw( 'https://wordpress.org/plugins/woocommerce/' ), esc_url_raw( 'https://wordpress.org/plugins/contact-form-7/' ), esc_url_raw( 'https://wordpress.org/plugins/breadcrumb-navxt/' ) ); ?> </p> </div> <?php } ); } } public function add_page_meta_boxes( $current_post_type ) { add_meta_box( esc_attr( 'tm-apple-page-meta' ), // Unique ID __( 'Page Settings', 'tm-apple' ),// Box title array( $this, 'render_page_meta_box'), 'page', 'normal' //context ); } public function render_page_meta_box( $post ) { $img = get_post_meta( $post->ID, 'apple_header_image_uri', true ); $header_image = empty( $img ) ? apple_get_theme_mod( 'apple_default_header_image_uri' ) : $img; $disable_header_image = get_post_meta( $post->ID, 'apple_disable_header_image', true ); ?> <p><label><?php esc_html_e( 'Disable Header Image', 'tm-apple' ); ?></label></p> <p> <input type="checkbox" name="apple_disable_header_image" <?php checked( 'yes', $disable_header_image ); ?>/> <?php esc_html_e( 'Disable Image', 'tm-apple' ); ?> </p> <p><label><?php esc_html_e( 'Header Image', 'tm-apple' ); ?></label></p> <div class = "widget" id="header-image"> <p> <input class="widefat image_id" type="hidden" name="apple_header_image_attachment_id" value="<?php echo esc_url_raw( get_post_meta( $post->ID, 'apple_header_image_attchment_id', true ) ); ?>"/> <input class="widefat apple_image_uri" type="text" name="apple_header_image_uri" value="<?php echo esc_url_raw( $header_image ); ?>"/> </p> <p> <img class="apple_image" style="max-width:100%" src="<?php echo esc_url_raw( $header_image ); ?>"/> </p> <a class="button apple_image_button"><?php _e( 'Add/Update header image', 'tm-apple' ); ?></a> </div> <input type="hidden" name="tm-apple-metabox-nonce" value="<?php echo wp_create_nonce( 'tm-apple-metabox-nonce' ); ?>"/> <?php } public function save_meta_box( $post_id ) { if( empty( $_POST ) ) { return $post_id; } $post_type = get_post_type($post_id); // If this isn't a 'book' post, don't update it. if ( "page" != $post_type ) { return $post_id; } // If this is auto save lets return the post id and do nothing if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE ){ return $post_id; } // If this is revision, lets do nothing but return if ( isset( $_POST['post_type'] ) && 'revision' === $_POST['post_type'] ){ return $post_id; } if( isset( $_POST['save'] ) ) { $nonce = $_POST[ 'tm-apple-metabox-nonce' ]; // check to see if the submitted nonce matches with the // generated nonce we created earlier if ( ! wp_verify_nonce( $nonce, 'tm-apple-metabox-nonce' ) ) { die ( __( 'You do not have permissions!','tm-apple' ) ); } //check user permissions if( ! current_user_can( 'edit_posts' ) ) { die ( __( 'You do not have permissions!', 'tm-apple' ) ); } } // do validation here if( isset( $_POST['apple_header_image_uri'] ) ){ update_post_meta( $post_id, 'apple_header_image_uri', esc_url_raw( $_POST['apple_header_image_uri'] ) ); } if( isset( $_POST['apple_disable_header_image'] ) ){ update_post_meta( $post_id, 'apple_disable_header_image', sanitize_text_field( 'yes' ) ); } } } $app = new AppleThemeApplication(); $GLOBALS['apple'] = $app; if( ! function_exists( 'apple_embed_gmap' ) ) : function apple_embed_gmap() { $embed = false; $google_map_enabled = $GLOBALS['apple']->theme_mods[ 'apple_google_map_enabled' ]; if( ! empty( $google_map_enabled ) && $google_map_enabled === true ) { $api_key = esc_html( $GLOBALS['apple']->theme_mods[ 'apple_google_map_api_key' ] ); if( empty( $api_key ) ) { return; } $map_visibility = esc_html( $GLOBALS['apple']->theme_mods[ 'apple_google_map_visibility' ] ); if( ! empty( $map_visibility ) && $map_visibility === 'all_pages' ) { $embed = true; } if( ! empty( $map_visibility ) && $map_visibility === 'front_page' ) { if( is_front_page() ) { $embed = true; } } } return apply_filters( 'apple_embed_gmap', $embed ); } endif; if( ! function_exists( 'apple_do_page_header' ) ) { function apple_do_page_header() { do_action( 'apple_before_page_header' ); global $post; $show_header_image = apple_show_header_image(); if( $show_header_image ) { apple_insert_page_header_image_breadcrumbs_title(); }else{ apple_insert_breadcrumbs(); } do_action( 'apple_after_page_header' ); } } if( ! function_exists( 'apple_insert_breadcrumbs' ) ) { function apple_insert_breadcrumbs() { if( function_exists( 'bcn_display' ) ) : ?> <?php if( function_exists( 'bcn_display' ) ) { ?> <div class="breadcrumbs" typeof="BreadcrumbList" vocab="http://schema.org/"> <div class="container"> <?php bcn_display(); ?> </div> </div> <?php } endif; } } if( ! function_exists( 'apple_insert_page_header_image_breadcrumbs_title' ) ) { function apple_insert_page_header_image_breadcrumbs_title() { global $post; $header_image = get_post_meta( $post->ID, 'apple_header_image_uri', true ); ?> <div class="page-img-header"> <img src="<?php echo esc_url_raw( $header_image ); ?>"> <div class="container"> <header class="entry-header"> <?php the_title( '<h1 class="entry-title page-img-header-title">', '</h1>' ); ?> </header> <?php if( function_exists( 'bcn_display' ) ) { ?> <div class="page-header-breadcrumbs" typeof="BreadcrumbList" vocab="http://schema.org/"> <?php bcn_display(); ?> </div> <?php } ?> </div> </div> <?php } } if( ! function_exists( 'apple_show_header_image' ) ) : function apple_show_header_image() { global $post; $disable_header_image = get_post_meta( $post->ID, 'apple_disable_header_image', true ); if( ! empty( $disable_header_image ) && $disable_header_image === 'yes' ) { return false; } else { return true; } } endif; if( ! function_exists( 'apple_get_theme_mod' ) ) : function apple_get_theme_mod( $key ) { if( array_key_exists( $key, $GLOBALS[ 'apple_theme_mods' ] ) ) { return get_theme_mod( $key, $GLOBALS[ 'apple_theme_mods' ][ $key ] ); } else { return get_theme_mod( $key ); } } endif; if( ! function_exists( 'apple_array_insert_before' ) ) : /** * @param array $array * @param int|string $position * @param mixed $insert */ function apple_array_insert_before( &$array, $position, $insert ) { if ( is_int( $position ) ) { array_splice( $array, $position, 0, $insert ); } else { $pos = array_search( $position, array_keys( $array ) ); $array = array_merge( array_slice( $array, 0, $pos ), $insert, array_slice( $array, $pos ) ); } } endif; if( ! function_exists( 'apple_get_sections_ordered' ) ) : /** * returns theme mods with default values * @return array */ function apple_get_sections_ordered() { $sections = array(); $sections[ apple_get_theme_mod( 'apple_services_order' ) ] = 'services'; $sections[ apple_get_theme_mod( 'apple_skills_order' ) ] = 'skills'; $sections[ apple_get_theme_mod( 'apple_about_order' ) ] = 'about_us'; $sections[ apple_get_theme_mod( 'apple_stats_order' ) ] = 'stats'; $sections[ apple_get_theme_mod( 'apple_projects_order' ) ] = 'projects'; $sections[ apple_get_theme_mod( 'apple_bb_cta_order' ) ] = 'bb_cta'; $sections[ apple_get_theme_mod( 'apple_pricing_order' ) ] = 'pricing'; $sections[ apple_get_theme_mod( 'apple_testimonials_order' ) ] = 'testimonials'; $sections[ apple_get_theme_mod( 'apple_subscribe_order' ) ] = 'subscribe'; $sections[ apple_get_theme_mod( 'apple_clients_order' ) ] = 'clients'; $sections[ apple_get_theme_mod( 'apple_team_order' ) ] = 'team'; $sections[ apple_get_theme_mod( 'apple_features_order' ) ] = 'features'; $sections[ apple_get_theme_mod( 'apple_rb_cta_order' ) ] = 'rb_cta'; $sections[ apple_get_theme_mod( 'apple_faqs_order' ) ] = 'faqs'; $sections[ apple_get_theme_mod( 'apple_qoute_order' ) ] = 'quote'; $sections[ apple_get_theme_mod( 'apple_news_order' ) ] = 'news'; $sections[ apple_get_theme_mod( 'apple_products_order' ) ] = 'products'; ksort( $sections ); return $sections; } endif; if( ! function_exists( 'apple_add_theme_pages' ) ) : /** * Adds theme pages */ function apple_add_theme_pages() { add_theme_page( __('Apple Theme', 'tm-apple' ) , __( 'Apple Theme', 'tm-apple' ) , 'edit_theme_options' , 'tm-apple-theme' , 'apple_print_theme_page' ); } endif; add_action( 'admin_menu', 'apple_add_theme_pages' ); if( ! function_exists( 'apple_print_theme_page' ) ) : /** * Prints theme pages */ function apple_print_theme_page() { get_template_part( 'theme-page-parts/theme-page', 'main' ); } endif; if( ! function_exists( 'apple_is_active_tab' ) ) : /** * Prints theme pages */ function apple_is_active_tab( $tab, $active_tab ) { return $tab === $active_tab; } endif; if( ! function_exists( 'apple_site_credit' ) ) : function apple_site_credit() { $date = DateTime::createFromFormat("Y-m-d", date( "Y-m-d" ) ); $str = sprintf( __( "© %s %s. All rights reserved.", "tm-apple" ), $date->format("Y"), get_bloginfo( 'name' ) ); return $str; } endif; remove_action('wp_head', 'print_emoji_detection_script', 7); remove_action('wp_print_styles', 'print_emoji_styles'); remove_action( 'admin_print_scripts', 'print_emoji_detection_script' ); remove_action( 'admin_print_styles', 'print_emoji_styles' );