Advertisement
Guest User

Untitled

a guest
Mar 31st, 2016
252
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 15.53 KB | None | 0 0
  1. <?php
  2. /**
  3. * Astrid functions and definitions.
  4. *
  5. * @link https://developer.wordpress.org/themes/basics/theme-functions/
  6. *
  7. * @package Astrid
  8. */
  9.  
  10. if ( ! function_exists( 'astrid_setup' ) ) :
  11. /**
  12. * Sets up theme defaults and registers support for various WordPress features.
  13. *
  14. * Note that this function is hooked into the after_setup_theme hook, which
  15. * runs before the init hook. The init hook is too late for some features, such
  16. * as indicating support for post thumbnails.
  17. */
  18. function astrid_setup() {
  19. /*
  20. * Make theme available for translation.
  21. * Translations can be filed in the /languages/ directory.
  22. * If you're building a theme based on Astrid, use a find and replace
  23. * to change 'astrid' to the name of your theme in all the template files.
  24. */
  25. load_theme_textdomain( 'astrid', get_template_directory() . '/languages' );
  26.  
  27. // Add default posts and comments RSS feed links to head.
  28. add_theme_support( 'automatic-feed-links' );
  29.  
  30. /*
  31. * Let WordPress manage the document title.
  32. * By adding theme support, we declare that this theme does not use a
  33. * hard-coded <title> tag in the document head, and expect WordPress to
  34. * provide it for us.
  35. */
  36. add_theme_support( 'title-tag' );
  37.  
  38. /*
  39. * Enable support for Post Thumbnails on posts and pages.
  40. *
  41. * @link https://developer.wordpress.org/themes/functionality/featured-images-post-thumbnails/
  42. */
  43. add_theme_support( 'post-thumbnails' );
  44. add_image_size('astrid-large-thumb', 700);
  45. add_image_size('astrid-medium-thumb', 520);
  46. add_image_size('astrid-small-thumb', 360);
  47. add_image_size('astrid-project-thumb', 500, 310, true);
  48. add_image_size('astrid-client-thumb', 250);
  49. add_image_size('astrid-testimonial-thumb', 100);
  50.  
  51. // This theme uses wp_nav_menu() in one location.
  52. register_nav_menus( array(
  53. 'primary' => esc_html__( 'Primary', 'astrid' ),
  54. 'footer' => esc_html__( 'Footer', 'astrid' ),
  55. ) );
  56.  
  57. /*
  58. * Switch default core markup for search form, comment form, and comments
  59. * to output valid HTML5.
  60. */
  61. add_theme_support( 'html5', array(
  62. 'search-form',
  63. 'comment-form',
  64. 'comment-list',
  65. 'gallery',
  66. 'caption',
  67. ) );
  68.  
  69. /*
  70. * Enable support for Post Formats.
  71. * See https://developer.wordpress.org/themes/functionality/post-formats/
  72. */
  73. add_theme_support( 'post-formats', array(
  74. 'aside',
  75. 'image',
  76. 'video',
  77. 'quote',
  78. 'link',
  79. ) );
  80.  
  81. // Set up the WordPress core custom background feature.
  82. add_theme_support( 'custom-background', apply_filters( 'astrid_custom_background_args', array(
  83. 'default-color' => 'f5f9f8',
  84. 'default-image' => '',
  85. ) ) );
  86. }
  87. endif;
  88. add_action( 'after_setup_theme', 'astrid_setup' );
  89.  
  90. /**
  91. * Set the content width in pixels, based on the theme's design and stylesheet.
  92. *
  93. * Priority 0 to make it available to lower priority callbacks.
  94. *
  95. * @global int $content_width
  96. */
  97. function astrid_content_width() {
  98. $GLOBALS['content_width'] = apply_filters( 'astrid_content_width', 640 );
  99. }
  100. add_action( 'after_setup_theme', 'astrid_content_width', 0 );
  101.  
  102. /**
  103. * Register widget area.
  104. *
  105. * @link https://developer.wordpress.org/themes/functionality/sidebars/#registering-a-sidebar
  106. */
  107. function astrid_widgets_init() {
  108. register_sidebar( array(
  109. 'name' => esc_html__( 'Sidebar', 'astrid' ),
  110. 'id' => 'sidebar-1',
  111. 'description' => '',
  112. 'before_widget' => '<aside id="%1$s" class="widget %2$s">',
  113. 'after_widget' => '</aside>',
  114. 'before_title' => '<h4 class="widget-title">',
  115. 'after_title' => '</h4>',
  116. ) );
  117.  
  118. //Register widget areas for the Widgetized page template
  119. $pages = get_pages(array(
  120. 'meta_key' => '_wp_page_template',
  121. 'meta_value' => 'page-templates/page_widgetized.php',
  122. ));
  123.  
  124. foreach($pages as $page){
  125. register_sidebar( array(
  126. 'name' => esc_html__( 'Page - ', 'astrid' ) . $page->post_title,
  127. 'id' => 'widget-area-' . strtolower($page->post_name),
  128. 'description' => esc_html__( 'Use this widget area to build content for the page: ', 'astrid' ) . $page->post_title,
  129. 'before_widget' => '<section id="%1$s" class="widget %2$s"><div class="atblock container">',
  130. 'after_widget' => '</div></section>',
  131. 'before_title' => '<h2 class="widget-title"><span class="title-decoration"></span>',
  132. 'after_title' => '</h2>',
  133. ) );
  134. }
  135.  
  136. //Footer widget areas
  137. $widget_areas = get_theme_mod('footer_widget_areas', '3');
  138. for ($i=1; $i<=$widget_areas; $i++) {
  139. register_sidebar( array(
  140. 'name' => __( 'Footer ', 'astrid' ) . $i,
  141. 'id' => 'footer-' . $i,
  142. 'description' => '',
  143. 'before_widget' => '<aside id="%1$s" class="widget %2$s">',
  144. 'after_widget' => '</aside>',
  145. 'before_title' => '<h3 class="widget-title">',
  146. 'after_title' => '</h3>',
  147. ) );
  148. }
  149.  
  150. register_widget( 'Atframework_Services' );
  151. register_widget( 'Atframework_Skills' );
  152. register_widget( 'Atframework_Facts' );
  153. register_widget( 'Atframework_Employees' );
  154. register_widget( 'Atframework_Projects' );
  155. register_widget( 'Atframework_Testimonials' );
  156. register_widget( 'Atframework_Clients' );
  157. register_widget( 'Atframework_Posts' );
  158. register_widget( 'Atframework_Video' );
  159. register_widget( 'Atframework_Recent_Posts' );
  160. register_widget( 'Atframework_Social' );
  161.  
  162. }
  163. add_action( 'widgets_init', 'astrid_widgets_init' );
  164.  
  165. //Homepage widgets
  166. $astrid_widgets = array('services', 'skills', 'facts', 'employees', 'projects', 'testimonials', 'clients', 'posts');
  167. foreach ( $astrid_widgets as $astrid_widget) {
  168. locate_template( '/inc/framework/widgets/front-' . $astrid_widget . '.php', true, false );
  169. }
  170.  
  171. //Sidebar widgets
  172. require get_template_directory() . "/inc/framework/widgets/video-widget.php";
  173. require get_template_directory() . "/inc/framework/widgets/posts-widget.php";
  174. require get_template_directory() . "/inc/framework/widgets/social-widget.php";
  175.  
  176. /**
  177. * Enqueue scripts and styles.
  178. */
  179. function astrid_scripts() {
  180. wp_enqueue_style( 'astrid-style', get_stylesheet_uri() );
  181.  
  182. $body_font = get_theme_mod('body_font_name', '<link href=\'https://fonts.googleapis.com/css?family=Open+Sans:300,300italic,600,600italic\' rel=\'stylesheet\' type=\'text/css\'>');
  183. $headings_font = get_theme_mod('headings_font_name', '<link href=\'https://fonts.googleapis.com/css?family=Josefin+Sans:300italic,300\' rel=\'stylesheet\' type=\'text/css\'>');
  184. $remove = array("<link href='", "' rel='stylesheet' type='text/css'>", "https:", "http:");
  185. $body_url = str_replace($remove, '', $body_font);
  186. $headings_url = str_replace($remove, '', $headings_font);
  187.  
  188. wp_enqueue_style( 'astrid-body-fonts', esc_attr($body_url) );
  189.  
  190. wp_enqueue_style( 'astrid-headings-fonts', esc_attr($headings_url) );
  191.  
  192. wp_enqueue_style( 'fontawesome', get_template_directory_uri() . '/fonts/font-awesome.min.css' );
  193.  
  194. wp_enqueue_script( 'astrid-main', get_template_directory_uri() . '/js/main.js', array('jquery'), '', true );
  195.  
  196. wp_enqueue_script( 'astrid-scripts', get_template_directory_uri() . '/js/scripts.min.js', array('jquery'), '', true );
  197.  
  198. if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
  199. wp_enqueue_script( 'comment-reply' );
  200. }
  201.  
  202. if ( astrid_blog_layout() == 'masonry-layout' && (is_home() || is_archive()) ) {
  203. wp_enqueue_script( 'astrid-masonry-init', get_template_directory_uri() . '/js/masonry-init.js', array('jquery-masonry'), '', true );
  204. }
  205.  
  206. }
  207. add_action( 'wp_enqueue_scripts', 'astrid_scripts' );
  208.  
  209. /**
  210. * Enqueue Bootstrap
  211. */
  212. function astrid_enqueue_bootstrap() {
  213. wp_enqueue_style( 'astrid-bootstrap', get_template_directory_uri() . '/css/bootstrap/bootstrap.min.css', array(), true );
  214. }
  215. add_action( 'wp_enqueue_scripts', 'astrid_enqueue_bootstrap', 9 );
  216.  
  217.  
  218. /**
  219. * Customizer styles
  220. */
  221. function astrid_customizer_styles($hook) {
  222. if ( ( 'customize.php' != $hook ) && ( 'widgets.php' != $hook ) ) {
  223. return;
  224. }
  225. wp_enqueue_style( 'astrid-customizer-styles', get_template_directory_uri() . '/inc/framework/css/customizer.css' );
  226. }
  227. add_action( 'admin_enqueue_scripts', 'astrid_customizer_styles' );
  228.  
  229. /**
  230. * Blog layout
  231. */
  232. function astrid_blog_layout() {
  233. $layout = get_theme_mod('blog_layout','list');
  234. return $layout;
  235. }
  236.  
  237. /**
  238. * Remove archives labels
  239. */
  240. function astrid_category_label($title) {
  241. if ( is_category() ) {
  242. $title = '<i class="fa fa-folder-o"></i>' . single_cat_title( '', false );
  243. } elseif ( is_tag() ) {
  244. $title = '<i class="fa fa-tag"></i>' . single_tag_title( '', false );
  245. } elseif ( is_author() ) {
  246. $title = '<span class="vcard"><i class="fa fa-user"></i>' . get_the_author() . '</span>';
  247. }
  248. return $title;
  249. }
  250. add_filter('get_the_archive_title', 'astrid_category_label');
  251.  
  252. /**
  253. * Load html5shiv
  254. */
  255. function astrid_html5shiv() {
  256. echo '<!--[if lt IE 9]>' . "\n";
  257. echo '<script src="' . esc_url( get_template_directory_uri() . '/js/html5shiv.js' ) . '"></script>' . "\n";
  258. echo '<![endif]-->' . "\n";
  259. }
  260. add_action( 'wp_head', 'astrid_html5shiv' );
  261.  
  262. /**
  263. * Header image check
  264. */
  265. function astrid_has_header() {
  266. $front_header = get_theme_mod('front_header_type' ,'image');
  267. $site_header = get_theme_mod('site_header_type', 'nothing');
  268. global $post;
  269. if ( !is_404() ) {
  270. $single_toggle = get_post_meta( $post->ID, '_astrid_header_key', true );
  271. } else {
  272. $single_toggle = false;
  273. }
  274.  
  275. if ( get_header_image() && ( $front_header == 'image' && is_front_page() ) || ( $site_header == 'image' && !is_front_page() ) ) {
  276. if (!$single_toggle)
  277. return 'has-header';
  278. } elseif ( ($front_header == 'shortcode' && is_front_page()) || ($site_header == 'shortcode' && !is_front_page()) ) {
  279. if (!$single_toggle)
  280. return 'has-shortcode';
  281. }
  282. }
  283.  
  284. /**
  285. * Full width single posts
  286. */
  287. function astrid_fullwidth_singles($classes) {
  288. if ( function_exists('is_woocommerce') ) {
  289. $woocommerce = is_woocommerce();
  290. } else {
  291. $woocommerce = false;
  292. }
  293.  
  294. $single_layout = get_theme_mod('fullwidth_single', 0);
  295. if ( is_single() && !$woocommerce && $single_layout ) {
  296. $classes[] = 'fullwidth-single';
  297. }
  298. return $classes;
  299. }
  300. add_filter('body_class', 'astrid_fullwidth_singles');
  301.  
  302. /**
  303. * Polylang compatibility
  304. */
  305. if ( function_exists('pll_register_string') ) :
  306. function astrid_polylang() {
  307. pll_register_string('Header text', get_theme_mod('header_text'), 'Astrid');
  308. pll_register_string('Header subtext', get_theme_mod('header_subtext'), 'Astrid');
  309. pll_register_string('Header button', get_theme_mod('header_button'), 'Astrid');
  310. }
  311. add_action( 'admin_init', 'astrid_polylang' );
  312. endif;
  313.  
  314. /**
  315. * Header text
  316. */
  317. function astrid_header_text() {
  318.  
  319. if ( !function_exists('pll_register_string') ) {
  320. $header_text = get_theme_mod('header_text', '5 MINUTE SETUP');
  321. $header_subtext = get_theme_mod('header_subtext', 'Time to meet Astrid');
  322. $header_button = get_theme_mod('header_button', 'Explore');
  323. } else {
  324. $header_text = pll__(get_theme_mod('header_text', '5 MINUTE SETUP'));
  325. $header_subtext = pll__(get_theme_mod('header_subtext', 'Time to meet Astrid'));
  326. $header_button = pll__(get_theme_mod('header_button', 'Explore'));
  327. }
  328. $header_button_url = get_theme_mod('header_button_url', '#primary');
  329.  
  330. echo '<div class="header-info">
  331. <div class="container">
  332. <h4 class="header-subtext">' . wp_kses_post($header_subtext) . '</h4>
  333. <h3 class="header-text">' . wp_kses_post($header_text) . '</h3>';
  334. if ($header_button_url) {
  335. echo '<a class="button header-button" href="' . esc_url($header_button_url) . '">' . esc_html($header_button) . '</a>';
  336. }
  337. echo '</div>';
  338. echo '</div>';
  339. }
  340.  
  341. /**
  342. * Site branding
  343. */
  344. if ( ! function_exists( 'astrid_branding' ) ) :
  345. function astrid_branding() {
  346. $site_logo = get_theme_mod('site_logo');
  347. if ( $site_logo ) :
  348. echo '<a href="' . esc_url( home_url( '/' ) ) . '" title="' . esc_attr(get_bloginfo('name')) . '"><img class="site-logo" src="' . esc_url($site_logo) . '" alt="' . esc_attr(get_bloginfo('name')) . '" /></a>';
  349. else :
  350. echo '<h1 class="site-title"><a href="' . esc_url( home_url( '/' ) ) . '" rel="home">' . esc_html(get_bloginfo('name')) . '</a></h1>';
  351. echo '<p class="site-description">' . esc_html(get_bloginfo( 'description' )) . '</p>';
  352. endif;
  353. }
  354. endif;
  355.  
  356. /**
  357. * Footer site branding
  358. */
  359. if ( ! function_exists( 'astrid_footer_branding' ) ) :
  360. function astrid_footer_branding() {
  361. $footer_logo = get_theme_mod('footer_logo');
  362. echo '<div class="footer-branding">';
  363. if ( $footer_logo ) :
  364. echo '<a href="' . esc_url( home_url( '/' ) ) . '" title="' . esc_attr(get_bloginfo('name')) . '"><img class="footer-logo" src="' . esc_url($footer_logo) . '" alt="' . esc_attr(get_bloginfo('name')) . '" /></a>';
  365. else :
  366. echo '<h2 class="site-title-footer"><a href="' . esc_url( home_url( '/' ) ) . '" rel="home">' . esc_html(get_bloginfo('name')) . '</a></h1>';
  367. endif;
  368. echo '</div>';
  369. }
  370. endif;
  371.  
  372. /**
  373. * Footer contact
  374. */
  375. if ( ! function_exists( 'astrid_footer_contact' ) ) :
  376. function astrid_footer_contact() {
  377. $footer_contact_address = get_theme_mod('footer_contact_address', '29 Bedford St, London');
  378. $footer_contact_email = antispambot(get_theme_mod('footer_contact_email', 'office@site.com'));
  379. $footer_contact_phone = get_theme_mod('footer_contact_phone', '(020) 4513 3568');
  380.  
  381. echo '<div class="footer-contact">';
  382. if ($footer_contact_address) {
  383. echo '<div class="footer-contact-block">';
  384. echo '<i class="fa fa-home"></i>';
  385. echo '<span>' . esc_html($footer_contact_address) . '</span>';
  386. echo '</div>';
  387. }
  388. if ($footer_contact_email) {
  389. echo '<div class="footer-contact-block">';
  390. echo '<i class="fa fa-envelope"></i>';
  391. echo '<span><a href="mailto:' . esc_html($footer_contact_email) . '">' . esc_html($footer_contact_email) . '</a></span>';
  392. echo '</div>';
  393. }
  394. if ($footer_contact_phone) {
  395. echo '<div class="footer-contact-block">';
  396. echo '<i class="fa fa-phone"></i>';
  397. echo '<span>' . esc_html($footer_contact_phone) . '</span>';
  398. echo '</div>';
  399. }
  400. echo '</div>';
  401.  
  402. }
  403. endif;
  404.  
  405. /**
  406. * Clearfix posts
  407. */
  408. function astrid_clearfix_posts( $classes ) {
  409. $classes[] = 'clearfix';
  410. return $classes;
  411. }
  412. add_filter( 'post_class', 'astrid_clearfix_posts' );
  413.  
  414. /**
  415. * Excerpt length
  416. */
  417. function astrid_excerpt_length( $length ) {
  418. $excerpt = get_theme_mod('exc_length', '40');
  419. return $excerpt;
  420. }
  421. add_filter( 'excerpt_length', 'astrid_excerpt_length', 99 );
  422.  
  423. /**
  424. * Footer credits
  425. */
  426. function astrid_footer_credits() {
  427. echo '<a href="' . esc_url( __( 'https://wordpress.org/', 'astrid' ) ) . '">';
  428. printf( __( 'Powered by %s', 'astrid' ), 'WordPress' );
  429. echo '</a>';
  430. echo '<span class="sep"> | </span>';
  431. printf( __( 'Theme: %2$s by %1$s.', 'astrid' ), 'aThemes', '<a href="http://athemes.com/theme/astrid" rel="designer">Astrid</a>' );
  432. }
  433. add_action( 'astrid_footer', 'astrid_footer_credits' );
  434.  
  435. /**
  436. * Implement the Custom Header feature.
  437. */
  438. require get_template_directory() . '/inc/custom-header.php';
  439.  
  440. /**
  441. * Custom template tags for this theme.
  442. */
  443. require get_template_directory() . '/inc/template-tags.php';
  444.  
  445. /**
  446. * Custom functions that act independently of the theme templates.
  447. */
  448. require get_template_directory() . '/inc/extras.php';
  449.  
  450. /**
  451. * Customizer additions.
  452. */
  453. require get_template_directory() . '/inc/customizer.php';
  454.  
  455. /**
  456. * Load Jetpack compatibility file.
  457. */
  458. require get_template_directory() . '/inc/jetpack.php';
  459.  
  460. /**
  461. * Widget options
  462. */
  463. require get_template_directory() . '/inc/framework/widget-options.php';
  464.  
  465. /**
  466. * Styles
  467. */
  468. require get_template_directory() . '/inc/styles.php';
  469.  
  470. /**
  471. * Woocommerce
  472. */
  473. require get_template_directory() . '/woocommerce/woocommerce.php';
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement