PageRenderTime 62ms CodeModel.GetById 34ms RepoModel.GetById 1ms app.codeStats 0ms

/functions.php

https://github.com/maddisondesigns/Quark
PHP | 971 lines | 549 code | 142 blank | 280 comment | 54 complexity | a63642130f2ecfb36fe8d0435e2e8c4c MD5 | raw file
  1. <?php
  2. /**
  3. * Quark functions and definitions
  4. *
  5. * @package Quark
  6. * @since Quark 1.0
  7. */
  8. /**
  9. * Set the content width based on the theme's design and stylesheet.
  10. *
  11. * @since Quark 1.0
  12. */
  13. if ( ! isset( $content_width ) )
  14. $content_width = 790; /* Default the embedded content width to 790px */
  15. /**
  16. * Sets up theme defaults and registers support for various WordPress features.
  17. *
  18. * Note that this function is hooked into the after_setup_theme hook, which runs
  19. * before the init hook. The init hook is too late for some features, such as indicating
  20. * support post thumbnails.
  21. *
  22. * @since Quark 1.0
  23. *
  24. * @return void
  25. */
  26. if ( ! function_exists( 'quark_setup' ) ) {
  27. function quark_setup() {
  28. global $content_width;
  29. /**
  30. * Make theme available for translation
  31. * Translations can be filed in the /languages/ directory
  32. * If you're building a theme based on Quark, use a find and replace
  33. * to change 'quark' to the name of your theme in all the template files
  34. */
  35. load_theme_textdomain( 'quark', trailingslashit( get_template_directory() ) . 'languages' );
  36. // This theme styles the visual editor with editor-style.css to match the theme style.
  37. add_editor_style();
  38. // Add default posts and comments RSS feed links to head
  39. add_theme_support( 'automatic-feed-links' );
  40. // Enable support for Post Thumbnails
  41. add_theme_support( 'post-thumbnails' );
  42. // Create an extra image size for the Post featured image
  43. add_image_size( 'post_feature_full_width', 792, 300, true );
  44. // This theme uses wp_nav_menu() in one location
  45. register_nav_menus( array(
  46. 'primary' => esc_html__( 'Primary Menu', 'quark' )
  47. ) );
  48. // This theme supports a variety of post formats
  49. add_theme_support( 'post-formats', array( 'aside', 'audio', 'chat', 'gallery', 'image', 'link', 'quote', 'status', 'video' ) );
  50. // Enable support for Custom Backgrounds
  51. add_theme_support( 'custom-background', array(
  52. // Background color default
  53. 'default-color' => 'fff',
  54. // Background image default
  55. 'default-image' => trailingslashit( get_template_directory_uri() ) . 'images/faint-squares.jpg'
  56. ) );
  57. // Enable support for Custom Headers (or in our case, a custom logo)
  58. add_theme_support( 'custom-header', array(
  59. // Header image default
  60. 'default-image' => trailingslashit( get_template_directory_uri() ) . 'images/logo.png',
  61. // Header text display default
  62. 'header-text' => false,
  63. // Header text color default
  64. 'default-text-color' => '000',
  65. // Flexible width
  66. 'flex-width' => true,
  67. // Header image width (in pixels)
  68. 'width' => 300,
  69. // Flexible height
  70. 'flex-height' => true,
  71. // Header image height (in pixels)
  72. 'height' => 80
  73. ) );
  74. // Enable support for Theme Options.
  75. // Rather than reinvent the wheel, we're using the Options Framework by Devin Price, so huge props to him!
  76. // http://wptheming.com/options-framework-theme/
  77. if ( !function_exists( 'optionsframework_init' ) ) {
  78. define( 'OPTIONS_FRAMEWORK_DIRECTORY', trailingslashit( get_template_directory_uri() ) . 'inc/' );
  79. require_once trailingslashit( dirname( __FILE__ ) ) . 'inc/options-framework.php';
  80. }
  81. }
  82. }
  83. add_action( 'after_setup_theme', 'quark_setup' );
  84. /**
  85. * Returns the Google font stylesheet URL, if available.
  86. *
  87. * The use of PT Sans and Arvo by default is localized. For languages that use characters not supported by the fonts, the fonts can be disabled.
  88. *
  89. * @since Quark 1.2.5
  90. *
  91. * @return string Font stylesheet or empty string if disabled.
  92. */
  93. function quark_fonts_url() {
  94. $fonts_url = '';
  95. $subsets = 'latin';
  96. /* translators: If there are characters in your language that are not supported by PT Sans, translate this to 'off'.
  97. * Do not translate into your own language.
  98. */
  99. $pt_sans = _x( 'on', 'PT Sans font: on or off', 'quark' );
  100. /* translators: To add an additional PT Sans character subset specific to your language, translate this to 'greek', 'cyrillic' or 'vietnamese'.
  101. * Do not translate into your own language.
  102. */
  103. $subset = _x( 'no-subset', 'PT Sans font: add new subset (cyrillic)', 'quark' );
  104. if ( 'cyrillic' == $subset )
  105. $subsets .= ',cyrillic';
  106. /* translators: If there are characters in your language that are not supported by Arvo, translate this to 'off'.
  107. * Do not translate into your own language.
  108. */
  109. $arvo = _x( 'on', 'Arvo font: on or off', 'quark' );
  110. if ( 'off' !== $pt_sans || 'off' !== $arvo ) {
  111. $font_families = array();
  112. if ( 'off' !== $pt_sans )
  113. $font_families[] = 'PT+Sans:400,400italic,700,700italic';
  114. if ( 'off' !== $arvo )
  115. $font_families[] = 'Arvo:400';
  116. $protocol = is_ssl() ? 'https' : 'http';
  117. $query_args = array(
  118. 'family' => implode( '|', $font_families ),
  119. 'subset' => $subsets,
  120. );
  121. $fonts_url = add_query_arg( $query_args, "$protocol://fonts.googleapis.com/css" );
  122. }
  123. return $fonts_url;
  124. }
  125. /**
  126. * Adds additional stylesheets to the TinyMCE editor if needed.
  127. *
  128. * @since Quark 1.2.5
  129. *
  130. * @param string $mce_css CSS path to load in TinyMCE.
  131. * @return string The filtered CSS paths list.
  132. */
  133. function quark_mce_css( $mce_css ) {
  134. $fonts_url = quark_fonts_url();
  135. if ( empty( $fonts_url ) ) {
  136. return $mce_css;
  137. }
  138. if ( !empty( $mce_css ) ) {
  139. $mce_css .= ',';
  140. }
  141. $mce_css .= esc_url_raw( str_replace( ',', '%2C', $fonts_url ) );
  142. return $mce_css;
  143. }
  144. add_filter( 'mce_css', 'quark_mce_css' );
  145. /**
  146. * Register widgetized areas
  147. *
  148. * @since Quark 1.0
  149. *
  150. * @return void
  151. */
  152. function quark_widgets_init() {
  153. register_sidebar( array(
  154. 'name' => esc_html__( 'Main Sidebar', 'quark' ),
  155. 'id' => 'sidebar-main',
  156. 'description' => esc_html__( 'Appears in the sidebar on posts and pages except the optional Front Page template, which has its own widgets', 'quark' ),
  157. 'before_widget' => '<aside id="%1$s" class="widget %2$s">',
  158. 'after_widget' => '</aside>',
  159. 'before_title' => '<h3 class="widget-title">',
  160. 'after_title' => '</h3>'
  161. ) );
  162. register_sidebar( array(
  163. 'name' => esc_html__( 'Blog Sidebar', 'quark' ),
  164. 'id' => 'sidebar-blog',
  165. 'description' => esc_html__( 'Appears in the sidebar on the blog and archive pages only', 'quark' ),
  166. 'before_widget' => '<aside id="%1$s" class="widget %2$s">',
  167. 'after_widget' => '</aside>',
  168. 'before_title' => '<h3 class="widget-title">',
  169. 'after_title' => '</h3>'
  170. ) );
  171. register_sidebar( array(
  172. 'name' => esc_html__( 'Single Post Sidebar', 'quark' ),
  173. 'id' => 'sidebar-single',
  174. 'description' => esc_html__( 'Appears in the sidebar on single posts only', 'quark' ),
  175. 'before_widget' => '<aside id="%1$s" class="widget %2$s">',
  176. 'after_widget' => '</aside>',
  177. 'before_title' => '<h3 class="widget-title">',
  178. 'after_title' => '</h3>'
  179. ) );
  180. register_sidebar( array(
  181. 'name' => esc_html__( 'Page Sidebar', 'quark' ),
  182. 'id' => 'sidebar-page',
  183. 'description' => esc_html__( 'Appears in the sidebar on pages only', 'quark' ),
  184. 'before_widget' => '<aside id="%1$s" class="widget %2$s">',
  185. 'after_widget' => '</aside>',
  186. 'before_title' => '<h3 class="widget-title">',
  187. 'after_title' => '</h3>'
  188. ) );
  189. register_sidebar( array(
  190. 'name' => esc_html__( 'First Front Page Banner Widget', 'quark' ),
  191. 'id' => 'frontpage-banner1',
  192. 'description' => esc_html__( 'Appears in the banner area on the Front Page', 'quark' ),
  193. 'before_widget' => '<div id="%1$s" class="widget %2$s">',
  194. 'after_widget' => '</div>',
  195. 'before_title' => '<h1 class="widget-title">',
  196. 'after_title' => '</h1>'
  197. ) );
  198. register_sidebar( array(
  199. 'name' => esc_html__( 'Second Front Page Banner Widget', 'quark' ),
  200. 'id' => 'frontpage-banner2',
  201. 'description' => esc_html__( 'Appears in the banner area on the Front Page', 'quark' ),
  202. 'before_widget' => '<div id="%1$s" class="widget %2$s">',
  203. 'after_widget' => '</div>',
  204. 'before_title' => '<h1 class="widget-title">',
  205. 'after_title' => '</h1>'
  206. ) );
  207. register_sidebar( array(
  208. 'name' => esc_html__( 'First Front Page Widget Area', 'quark' ),
  209. 'id' => 'sidebar-homepage1',
  210. 'description' => esc_html__( 'Appears when using the optional Front Page template with a page set as Static Front Page', 'quark' ),
  211. 'before_widget' => '<aside id="%1$s" class="widget %2$s">',
  212. 'after_widget' => '</aside>',
  213. 'before_title' => '<h3 class="widget-title">',
  214. 'after_title' => '</h3>'
  215. ) );
  216. register_sidebar( array(
  217. 'name' => esc_html__( 'Second Front Page Widget Area', 'quark' ),
  218. 'id' => 'sidebar-homepage2',
  219. 'description' => esc_html__( 'Appears when using the optional Front Page template with a page set as Static Front Page', 'quark' ),
  220. 'before_widget' => '<aside id="%1$s" class="widget %2$s">',
  221. 'after_widget' => '</aside>',
  222. 'before_title' => '<h3 class="widget-title">',
  223. 'after_title' => '</h3>'
  224. ) );
  225. register_sidebar( array(
  226. 'name' => esc_html__( 'Third Front Page Widget Area', 'quark' ),
  227. 'id' => 'sidebar-homepage3',
  228. 'description' => esc_html__( 'Appears when using the optional Front Page template with a page set as Static Front Page', 'quark' ),
  229. 'before_widget' => '<aside id="%1$s" class="widget %2$s">',
  230. 'after_widget' => '</aside>',
  231. 'before_title' => '<h3 class="widget-title">',
  232. 'after_title' => '</h3>'
  233. ) );
  234. register_sidebar( array(
  235. 'name' => esc_html__( 'Fourth Front Page Widget Area', 'quark' ),
  236. 'id' => 'sidebar-homepage4',
  237. 'description' => esc_html__( 'Appears when using the optional Front Page template with a page set as Static Front Page', 'quark' ),
  238. 'before_widget' => '<aside id="%1$s" class="widget %2$s">',
  239. 'after_widget' => '</aside>',
  240. 'before_title' => '<h3 class="widget-title">',
  241. 'after_title' => '</h3>'
  242. ) );
  243. register_sidebar( array(
  244. 'name' => esc_html__( 'First Footer Widget Area', 'quark' ),
  245. 'id' => 'sidebar-footer1',
  246. 'description' => esc_html__( 'Appears in the footer sidebar', 'quark' ),
  247. 'before_widget' => '<aside id="%1$s" class="widget %2$s">',
  248. 'after_widget' => '</aside>',
  249. 'before_title' => '<h3 class="widget-title">',
  250. 'after_title' => '</h3>'
  251. ) );
  252. register_sidebar( array(
  253. 'name' => esc_html__( 'Second Footer Widget Area', 'quark' ),
  254. 'id' => 'sidebar-footer2',
  255. 'description' => esc_html__( 'Appears in the footer sidebar', 'quark' ),
  256. 'before_widget' => '<aside id="%1$s" class="widget %2$s">',
  257. 'after_widget' => '</aside>',
  258. 'before_title' => '<h3 class="widget-title">',
  259. 'after_title' => '</h3>'
  260. ) );
  261. register_sidebar( array(
  262. 'name' => esc_html__( 'Third Footer Widget Area', 'quark' ),
  263. 'id' => 'sidebar-footer3',
  264. 'description' => esc_html__( 'Appears in the footer sidebar', 'quark' ),
  265. 'before_widget' => '<aside id="%1$s" class="widget %2$s">',
  266. 'after_widget' => '</aside>',
  267. 'before_title' => '<h3 class="widget-title">',
  268. 'after_title' => '</h3>'
  269. ) );
  270. register_sidebar( array(
  271. 'name' => esc_html__( 'Fourth Footer Widget Area', 'quark' ),
  272. 'id' => 'sidebar-footer4',
  273. 'description' => esc_html__( 'Appears in the footer sidebar', 'quark' ),
  274. 'before_widget' => '<aside id="%1$s" class="widget %2$s">',
  275. 'after_widget' => '</aside>',
  276. 'before_title' => '<h3 class="widget-title">',
  277. 'after_title' => '</h3>'
  278. ) );
  279. }
  280. add_action( 'widgets_init', 'quark_widgets_init' );
  281. /**
  282. * Enqueue scripts and styles
  283. *
  284. * @since Quark 1.0
  285. *
  286. * @return void
  287. */
  288. function quark_scripts_styles() {
  289. /**
  290. * Register and enqueue our stylesheets
  291. */
  292. // Start off with a clean base by using normalise. If you prefer to use a reset stylesheet or something else, simply replace this
  293. wp_register_style( 'normalize', trailingslashit( get_template_directory_uri() ) . 'css/normalize.css' , array(), '3.0.1', 'all' );
  294. wp_enqueue_style( 'normalize' );
  295. // Register and enqueue our icon font
  296. // We're using the awesome Font Awesome icon font. http://fortawesome.github.io/Font-Awesome
  297. wp_register_style( 'fontawesome', trailingslashit( get_template_directory_uri() ) . 'css/font-awesome.min.css' , array(), '4.1.0', 'all' );
  298. wp_enqueue_style( 'fontawesome' );
  299. // Our styles for setting up the grid.
  300. // If you prefer to use a different grid system, simply replace this and perform a find/replace in the php for the relevant styles. I'm nice like that!
  301. wp_register_style( 'gridsystem', trailingslashit( get_template_directory_uri() ) . 'css/grid.css' , array(), '1.0.0', 'all' );
  302. wp_enqueue_style( 'gridsystem' );
  303. /*
  304. * Load our Google Fonts.
  305. *
  306. * To disable in a child theme, use wp_dequeue_style()
  307. * function mytheme_dequeue_fonts() {
  308. * wp_dequeue_style( 'quark-fonts' );
  309. * }
  310. * add_action( 'wp_enqueue_scripts', 'mytheme_dequeue_fonts', 11 );
  311. */
  312. $fonts_url = quark_fonts_url();
  313. if ( !empty( $fonts_url ) ) {
  314. wp_enqueue_style( 'quark-fonts', esc_url_raw( $fonts_url ), array(), null );
  315. }
  316. // Enqueue the default WordPress stylesheet
  317. wp_enqueue_style( 'style', get_stylesheet_uri(), array(), '1.2.3', 'all' );
  318. /**
  319. * Register and enqueue our scripts
  320. */
  321. // Load Modernizr at the top of the document, which enables HTML5 elements and feature detects
  322. wp_register_script( 'modernizr', trailingslashit( get_template_directory_uri() ) . 'js/modernizr-2.8.2-min.js', array(), '2.8.2', false );
  323. wp_enqueue_script( 'modernizr' );
  324. // Adds JavaScript to pages with the comment form to support sites with threaded comments (when in use)
  325. if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
  326. wp_enqueue_script( 'comment-reply' );
  327. }
  328. // Load jQuery Validation as well as the initialiser to provide client side comment form validation
  329. // Using the 1.11.0pre version as it fixes an error that causes the email validation to fire immediately when text is entered in the field
  330. // You can change the validation error messages below
  331. if ( is_singular() && comments_open() ) {
  332. wp_register_script( 'validate', trailingslashit( get_template_directory_uri() ) . 'js/jquery.validate.min.1.11.0pre.js', array( 'jquery' ), '1.11.0', true );
  333. wp_register_script( 'commentvalidate', trailingslashit( get_template_directory_uri() ) . 'js/comment-form-validation.js', array( 'jquery', 'validate' ), '1.11.0', true );
  334. wp_enqueue_script( 'commentvalidate' );
  335. wp_localize_script( 'commentvalidate', 'comments_object', array(
  336. 'req' => get_option( 'require_name_email' ),
  337. 'author' => esc_html__( 'Please enter your name', 'quark' ),
  338. 'email' => esc_html__( 'Please enter a valid email address', 'quark' ),
  339. 'comment' => esc_html__( 'Please add a comment', 'quark' ) )
  340. );
  341. }
  342. // Include this script to envoke a button toggle for the main navigation menu on small screens
  343. //wp_register_script( 'small-menu', trailingslashit( get_template_directory_uri() ) . 'js/small-menu.js', array( 'jquery' ), '20130130', true );
  344. //wp_enqueue_script( 'small-menu' );
  345. }
  346. add_action( 'wp_enqueue_scripts', 'quark_scripts_styles' );
  347. /**
  348. * Creates a nicely formatted and more specific title element text
  349. * for output in head of document, based on current view.
  350. *
  351. * @since Quark 1.0
  352. *
  353. * @param string $title Default title text for current view.
  354. * @param string $sep Optional separator.
  355. * @return string The filtered title.
  356. */
  357. function quark_wp_title( $title, $sep ) {
  358. global $paged, $page;
  359. if ( is_feed() ) {
  360. return $title;
  361. }
  362. // Add the blog name.
  363. $title .= get_bloginfo( 'name' );
  364. // Add the blog description for the home/front page.
  365. $site_description = get_bloginfo( 'description', 'display' );
  366. if ( $site_description && ( is_home() || is_front_page() ) ) {
  367. $title = "$title $sep $site_description";
  368. }
  369. // Add a page number if necessary.
  370. if ( $paged >= 2 || $page >= 2 ) {
  371. $title = "$title $sep " . sprintf( esc_html__( 'Page %s', 'quark' ), max( $paged, $page ) );
  372. }
  373. return $title;
  374. }
  375. add_filter( 'wp_title', 'quark_wp_title', 10, 2 );
  376. /**
  377. * Displays navigation to next/previous pages when applicable.
  378. *
  379. * @since Quark 1.0
  380. *
  381. * @param string html ID
  382. * @return void
  383. */
  384. if ( ! function_exists( 'quark_content_nav' ) ) {
  385. function quark_content_nav( $nav_id ) {
  386. global $wp_query;
  387. $big = 999999999; // need an unlikely integer
  388. $nav_class = 'site-navigation paging-navigation';
  389. if ( is_single() ) {
  390. $nav_class = 'site-navigation post-navigation nav-single';
  391. }
  392. ?>
  393. <nav role="navigation" id="<?php echo $nav_id; ?>" class="<?php echo $nav_class; ?>">
  394. <h3 class="assistive-text"><?php esc_html_e( 'Post navigation', 'quark' ); ?></h3>
  395. <?php if ( is_single() ) { // navigation links for single posts ?>
  396. <?php previous_post_link( '<div class="nav-previous">%link</div>', '<span class="meta-nav">' . _x( '<i class="fa fa-angle-left"></i>', 'Previous post link', 'quark' ) . '</span> %title' ); ?>
  397. <?php next_post_link( '<div class="nav-next">%link</div>', '%title <span class="meta-nav">' . _x( '<i class="fa fa-angle-right"></i>', 'Next post link', 'quark' ) . '</span>' ); ?>
  398. <?php }
  399. elseif ( $wp_query->max_num_pages > 1 && ( is_home() || is_archive() || is_search() ) ) { // navigation links for home, archive, and search pages ?>
  400. <?php echo paginate_links( array(
  401. 'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
  402. 'format' => '?paged=%#%',
  403. 'current' => max( 1, get_query_var( 'paged' ) ),
  404. 'total' => $wp_query->max_num_pages,
  405. 'type' => 'list',
  406. 'prev_text' => wp_kses( __( '<i class="fa fa-angle-left"></i> Previous', 'quark' ), array( 'i' => array(
  407. 'class' => array() ) ) ),
  408. 'next_text' => wp_kses( __( 'Next <i class="fa fa-angle-right"></i>', 'quark' ), array( 'i' => array(
  409. 'class' => array() ) ) )
  410. ) ); ?>
  411. <?php } ?>
  412. </nav><!-- #<?php echo $nav_id; ?> -->
  413. <?php
  414. }
  415. }
  416. /**
  417. * Template for comments and pingbacks.
  418. *
  419. * To override this walker in a child theme without modifying the comments template
  420. * simply create your own quark_comment(), and that function will be used instead.
  421. *
  422. * Used as a callback by wp_list_comments() for displaying the comments.
  423. * (Note the lack of a trailing </li>. WordPress will add it itself once it's done listing any children and whatnot)
  424. *
  425. * @since Quark 1.0
  426. *
  427. * @param array Comment
  428. * @param array Arguments
  429. * @param integer Comment depth
  430. * @return void
  431. */
  432. if ( ! function_exists( 'quark_comment' ) ) {
  433. function quark_comment( $comment, $args, $depth ) {
  434. $GLOBALS['comment'] = $comment;
  435. switch ( $comment->comment_type ) {
  436. case 'pingback' :
  437. case 'trackback' :
  438. // Display trackbacks differently than normal comments ?>
  439. <li <?php comment_class(); ?> id="comment-<?php comment_ID(); ?>">
  440. <article id="comment-<?php comment_ID(); ?>" class="pingback">
  441. <p><?php esc_html_e( 'Pingback:', 'quark' ); ?> <?php comment_author_link(); ?> <?php edit_comment_link( esc_html__( '(Edit)', 'quark' ), '<span class="edit-link">', '</span>' ); ?></p>
  442. </article> <!-- #comment-##.pingback -->
  443. <?php
  444. break;
  445. default :
  446. // Proceed with normal comments.
  447. global $post; ?>
  448. <li <?php comment_class(); ?> id="li-comment-<?php comment_ID(); ?>">
  449. <article id="comment-<?php comment_ID(); ?>" class="comment">
  450. <header class="comment-meta comment-author vcard">
  451. <?php
  452. echo get_avatar( $comment, 44 );
  453. printf( '<cite class="fn">%1$s %2$s</cite>',
  454. get_comment_author_link(),
  455. // If current post author is also comment author, make it known visually.
  456. ( $comment->user_id === $post->post_author ) ? '<span> ' . esc_html__( 'Post author', 'quark' ) . '</span>' : '' );
  457. printf( '<a href="%1$s" title="Posted %2$s"><time itemprop="datePublished" datetime="%3$s">%4$s</time></a>',
  458. esc_url( get_comment_link( $comment->comment_ID ) ),
  459. sprintf( esc_html__( '%1$s @ %2$s', 'quark' ), esc_html( get_comment_date() ), esc_attr( get_comment_time() ) ),
  460. get_comment_time( 'c' ),
  461. /* Translators: 1: date, 2: time */
  462. sprintf( esc_html__( '%1$s at %2$s', 'quark' ), get_comment_date(), get_comment_time() )
  463. );
  464. ?>
  465. </header> <!-- .comment-meta -->
  466. <?php if ( '0' == $comment->comment_approved ) { ?>
  467. <p class="comment-awaiting-moderation"><?php esc_html_e( 'Your comment is awaiting moderation.', 'quark' ); ?></p>
  468. <?php } ?>
  469. <section class="comment-content comment">
  470. <?php comment_text(); ?>
  471. <?php edit_comment_link( esc_html__( 'Edit', 'quark' ), '<p class="edit-link">', '</p>' ); ?>
  472. </section> <!-- .comment-content -->
  473. <div class="reply">
  474. <?php comment_reply_link( array_merge( $args, array( 'reply_text' => wp_kses( __( 'Reply <span>&darr;</span>', 'quark' ), array( 'span' => array() ) ), 'depth' => $depth, 'max_depth' => $args['max_depth'] ) ) ); ?>
  475. </div> <!-- .reply -->
  476. </article> <!-- #comment-## -->
  477. <?php
  478. break;
  479. } // end comment_type check
  480. }
  481. }
  482. /**
  483. * Update the Comments form so that the 'required' span is contained within the form label.
  484. *
  485. * @since Quark 1.0
  486. *
  487. * @param string Comment form fields html
  488. * @return string The updated comment form fields html
  489. */
  490. function quark_comment_form_default_fields( $fields ) {
  491. $commenter = wp_get_current_commenter();
  492. $req = get_option( 'require_name_email' );
  493. $aria_req = ( $req ? ' aria-required="true"' : "" );
  494. $fields[ 'author' ] = '<p class="comment-form-author">' . '<label for="author">' . esc_html__( 'Name', 'quark' ) . ( $req ? ' <span class="required">*</span>' : '' ) . '</label> ' . '<input id="author" name="author" type="text" value="' . esc_attr( $commenter['comment_author'] ) . '" size="30"' . $aria_req . ' /></p>';
  495. $fields[ 'email' ] = '<p class="comment-form-email"><label for="email">' . esc_html__( 'Email', 'quark' ) . ( $req ? ' <span class="required">*</span>' : '' ) . '</label> ' . '<input id="email" name="email" type="text" value="' . esc_attr( $commenter['comment_author_email'] ) . '" size="30"' . $aria_req . ' /></p>';
  496. $fields[ 'url' ] = '<p class="comment-form-url"><label for="url">' . esc_html__( 'Website', 'quark' ) . '</label>' . '<input id="url" name="url" type="text" value="' . esc_attr( $commenter['comment_author_url'] ) . '" size="30" /></p>';
  497. return $fields;
  498. }
  499. add_action( 'comment_form_default_fields', 'quark_comment_form_default_fields' );
  500. /**
  501. * Update the Comments form to add a 'required' span to the Comment textarea within the form label, because it's pointless
  502. * submitting a comment that doesn't actually have any text in the comment field!
  503. *
  504. * @since Quark 1.0
  505. *
  506. * @param string Comment form textarea html
  507. * @return string The updated comment form textarea html
  508. */
  509. function quark_comment_form_field_comment( $field ) {
  510. $field = '<p class="comment-form-comment"><label for="comment">' . _x( 'Comment', 'noun', 'quark' ) . ' <span class="required">*</span></label><textarea id="comment" name="comment" cols="45" rows="8" aria-required="true"></textarea></p>';
  511. return $field;
  512. }
  513. add_action( 'comment_form_field_comment', 'quark_comment_form_field_comment' );
  514. /**
  515. * Prints HTML with meta information for current post: author and date
  516. *
  517. * @since Quark 1.0
  518. *
  519. * @return void
  520. */
  521. if ( ! function_exists( 'quark_posted_on' ) ) {
  522. function quark_posted_on() {
  523. $post_icon = '';
  524. switch ( get_post_format() ) {
  525. case 'aside':
  526. $post_icon = 'fa-file-o';
  527. break;
  528. case 'audio':
  529. $post_icon = 'fa-volume-up';
  530. break;
  531. case 'chat':
  532. $post_icon = 'fa-comment';
  533. break;
  534. case 'gallery':
  535. $post_icon = 'fa-camera';
  536. break;
  537. case 'image':
  538. $post_icon = 'fa-picture-o';
  539. break;
  540. case 'link':
  541. $post_icon = 'fa-link';
  542. break;
  543. case 'quote':
  544. $post_icon = 'fa-quote-left';
  545. break;
  546. case 'status':
  547. $post_icon = 'fa-user';
  548. break;
  549. case 'video':
  550. $post_icon = 'fa-video-camera';
  551. break;
  552. default:
  553. $post_icon = 'fa-calendar';
  554. break;
  555. }
  556. // Translators: 1: Icon 2: Permalink 3: Post date and time 4: Publish date in ISO format 5: Post date
  557. $date = sprintf( '<i class="fa %1$s"></i> <a href="%2$s" title="Posted %3$s" rel="bookmark"><time class="entry-date" datetime="%4$s" itemprop="datePublished">%5$s</time></a>',
  558. $post_icon,
  559. esc_url( get_permalink() ),
  560. sprintf( esc_html__( '%1$s @ %2$s', 'quark' ), esc_html( get_the_date() ), esc_attr( get_the_time() ) ),
  561. esc_attr( get_the_date( 'c' ) ),
  562. esc_html( get_the_date() )
  563. );
  564. // Translators: 1: Date link 2: Author link 3: Categories 4: No. of Comments
  565. $author = sprintf( '<i class="fa fa-pencil"></i> <address class="author vcard"><a class="url fn n" href="%1$s" title="%2$s" rel="author">%3$s</a></address>',
  566. esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ),
  567. esc_attr( sprintf( esc_html__( 'View all posts by %s', 'quark' ), get_the_author() ) ),
  568. get_the_author()
  569. );
  570. // Return the Categories as a list
  571. $categories_list = get_the_category_list( esc_html__( ' ', 'quark' ) );
  572. // Translators: 1: Permalink 2: Title 3: No. of Comments
  573. $comments = sprintf( '<span class="comments-link"><i class="fa fa-comment"></i> <a href="%1$s" title="%2$s">%3$s</a></span>',
  574. esc_url( get_comments_link() ),
  575. esc_attr( esc_html__( 'Comment on ' . the_title_attribute( 'echo=0' ) ) ),
  576. ( get_comments_number() > 0 ? sprintf( _n( '%1$s Comment', '%1$s Comments', get_comments_number(), 'quark' ), get_comments_number() ) : esc_html__( 'No Comments', 'quark' ) )
  577. );
  578. // Translators: 1: Date 2: Author 3: Categories 4: Comments
  579. printf( wp_kses( __( '<div class="header-meta">%1$s%2$s<span class="post-categories">%3$s</span>%4$s</div>', 'quark' ), array(
  580. 'div' => array (
  581. 'class' => array() ),
  582. 'span' => array(
  583. 'class' => array() ) ) ),
  584. $date,
  585. $author,
  586. $categories_list,
  587. ( is_search() ? '' : $comments )
  588. );
  589. }
  590. }
  591. /**
  592. * Prints HTML with meta information for current post: categories, tags, permalink
  593. *
  594. * @since Quark 1.0
  595. *
  596. * @return void
  597. */
  598. if ( ! function_exists( 'quark_entry_meta' ) ) {
  599. function quark_entry_meta() {
  600. // Return the Tags as a list
  601. $tag_list = "";
  602. if ( get_the_tag_list() ) {
  603. $tag_list = get_the_tag_list( '<span class="post-tags">', esc_html__( ' ', 'quark' ), '</span>' );
  604. }
  605. // Translators: 1 is tag
  606. if ( $tag_list ) {
  607. printf( wp_kses( __( '<i class="fa fa-tag"></i> %1$s', 'quark' ), array( 'i' => array( 'class' => array() ) ) ), $tag_list );
  608. }
  609. }
  610. }
  611. /**
  612. * Adjusts content_width value for full-width templates and attachments
  613. *
  614. * @since Quark 1.0
  615. *
  616. * @return void
  617. */
  618. function quark_content_width() {
  619. if ( is_page_template( 'page-templates/full-width.php' ) || is_attachment() ) {
  620. global $content_width;
  621. $content_width = 1200;
  622. }
  623. }
  624. add_action( 'template_redirect', 'quark_content_width' );
  625. /**
  626. * Change the "read more..." link so it links to the top of the page rather than part way down
  627. *
  628. * @since Quark 1.0
  629. *
  630. * @param string The 'Read more' link
  631. * @return string The link to the post url without the more tag appended on the end
  632. */
  633. function quark_remove_more_jump_link( $link ) {
  634. $offset = strpos( $link, '#more-' );
  635. if ( $offset ) {
  636. $end = strpos( $link, '"', $offset );
  637. }
  638. if ( $end ) {
  639. $link = substr_replace( $link, '', $offset, $end-$offset );
  640. }
  641. return $link;
  642. }
  643. add_filter( 'the_content_more_link', 'quark_remove_more_jump_link' );
  644. /**
  645. * Returns a "Continue Reading" link for excerpts
  646. *
  647. * @since Quark 1.0
  648. *
  649. * @return string The 'Continue reading' link
  650. */
  651. function quark_continue_reading_link() {
  652. return '&hellip;<p><a class="more-link" href="'. esc_url( get_permalink() ) . '" title="' . esc_html__( 'Continue reading', 'quark' ) . ' &lsquo;' . get_the_title() . '&rsquo;">' . wp_kses( __( 'Continue reading <span class="meta-nav">&rarr;</span>', 'quark' ), array( 'span' => array(
  653. 'class' => array() ) ) ) . '</a></p>';
  654. }
  655. /**
  656. * Replaces "[...]" (appended to automatically generated excerpts) with the quark_continue_reading_link().
  657. *
  658. * @since Quark 1.0
  659. *
  660. * @param string Auto generated excerpt
  661. * @return string The filtered excerpt
  662. */
  663. function quark_auto_excerpt_more( $more ) {
  664. return quark_continue_reading_link();
  665. }
  666. add_filter( 'excerpt_more', 'quark_auto_excerpt_more' );
  667. /**
  668. * Extend the user contact methods to include Twitter, Facebook and Google+
  669. *
  670. * @since Quark 1.0
  671. *
  672. * @param array List of user contact methods
  673. * @return array The filtered list of updated user contact methods
  674. */
  675. function quark_new_contactmethods( $contactmethods ) {
  676. // Add Twitter
  677. $contactmethods['twitter'] = 'Twitter';
  678. //add Facebook
  679. $contactmethods['facebook'] = 'Facebook';
  680. //add Google Plus
  681. $contactmethods['googleplus'] = 'Google+';
  682. return $contactmethods;
  683. }
  684. add_filter( 'user_contactmethods', 'quark_new_contactmethods', 10, 1 );
  685. /**
  686. * Add a filter for wp_nav_menu to add an extra class for menu items that have children (ie. sub menus)
  687. * This allows us to perform some nicer styling on our menu items that have multiple levels (eg. dropdown menu arrows)
  688. *
  689. * @since Quark 1.0
  690. *
  691. * @param Menu items
  692. * @return array An extra css class is on menu items with children
  693. */
  694. function quark_add_menu_parent_class( $items ) {
  695. $parents = array();
  696. foreach ( $items as $item ) {
  697. if ( $item->menu_item_parent && $item->menu_item_parent > 0 ) {
  698. $parents[] = $item->menu_item_parent;
  699. }
  700. }
  701. foreach ( $items as $item ) {
  702. if ( in_array( $item->ID, $parents ) ) {
  703. $item->classes[] = 'menu-parent-item';
  704. }
  705. }
  706. return $items;
  707. }
  708. add_filter( 'wp_nav_menu_objects', 'quark_add_menu_parent_class' );
  709. /**
  710. * Add Filter to allow Shortcodes to work in the Sidebar
  711. *
  712. * @since Quark 1.0
  713. */
  714. add_filter( 'widget_text', 'do_shortcode' );
  715. /**
  716. * Return an unordered list of linked social media icons, based on the urls provided in the Theme Options
  717. *
  718. * @since Quark 1.0
  719. *
  720. * @return string Unordered list of linked social media icons
  721. */
  722. if ( ! function_exists( 'quark_get_social_media' ) ) {
  723. function quark_get_social_media() {
  724. $output = '';
  725. $icons = array(
  726. array( 'url' => of_get_option( 'social_twitter', '' ), 'icon' => 'fa-twitter', 'title' => esc_html__( 'Follow me on Twitter', 'quark' ) ),
  727. array( 'url' => of_get_option( 'social_facebook', '' ), 'icon' => 'fa-facebook', 'title' => esc_html__( 'Friend me on Facebook', 'quark' ) ),
  728. array( 'url' => of_get_option( 'social_googleplus', '' ), 'icon' => 'fa-google-plus', 'title' => esc_html__( 'Connect with me on Google+', 'quark' ) ),
  729. array( 'url' => of_get_option( 'social_linkedin', '' ), 'icon' => 'fa-linkedin', 'title' => esc_html__( 'Connect with me on LinkedIn', 'quark' ) ),
  730. array( 'url' => of_get_option( 'social_dribbble', '' ), 'icon' => 'fa-dribbble', 'title' => esc_html__( 'Follow me on Dribbble', 'quark' ) ),
  731. array( 'url' => of_get_option( 'social_tumblr', '' ), 'icon' => 'fa-tumblr', 'title' => esc_html__( 'Follow me on Tumblr', 'quark' ) ),
  732. array( 'url' => of_get_option( 'social_github', '' ), 'icon' => 'fa-github', 'title' => esc_html__( 'Fork me on GitHub', 'quark' ) ),
  733. array( 'url' => of_get_option( 'social_bitbucket', '' ), 'icon' => 'fa-bitbucket', 'title' => esc_html__( 'Fork me on Bitbucket', 'quark' ) ),
  734. array( 'url' => of_get_option( 'social_foursquare', '' ), 'icon' => 'fa-foursquare', 'title' => esc_html__( 'Follow me on Foursquare', 'quark' ) ),
  735. array( 'url' => of_get_option( 'social_youtube', '' ), 'icon' => 'fa-youtube', 'title' => esc_html__( 'Subscribe to me on YouTube', 'quark' ) ),
  736. array( 'url' => of_get_option( 'social_instagram', '' ), 'icon' => 'fa-instagram', 'title' => esc_html__( 'Follow me on Instagram', 'quark' ) ),
  737. array( 'url' => of_get_option( 'social_flickr', '' ), 'icon' => 'fa-flickr', 'title' => esc_html__( 'Connect with me on Flickr', 'quark' ) ),
  738. array( 'url' => of_get_option( 'social_pinterest', '' ), 'icon' => 'fa-pinterest', 'title' => esc_html__( 'Follow me on Pinterest', 'quark' ) ),
  739. array( 'url' => of_get_option( 'social_rss', '' ), 'icon' => 'fa-rss', 'title' => esc_html__( 'Subscribe to my RSS Feed', 'quark' ) )
  740. );
  741. foreach ( $icons as $key ) {
  742. $value = $key['url'];
  743. if ( !empty( $value ) ) {
  744. $output .= sprintf( '<li><a href="%1$s" title="%2$s"%3$s><span class="fa-stack fa-lg"><i class="fa fa-square fa-stack-2x"></i><i class="fa %4$s fa-stack-1x fa-inverse"></i></span></a></li>',
  745. esc_url( $value ),
  746. $key['title'],
  747. ( !of_get_option( 'social_newtab' ) ? '' : ' target="_blank"' ),
  748. $key['icon']
  749. );
  750. }
  751. }
  752. if ( !empty( $output ) ) {
  753. $output = '<ul>' . $output . '</ul>';
  754. }
  755. return $output;
  756. }
  757. }
  758. /**
  759. * Return a string containing the footer credits & link
  760. *
  761. * @since Quark 1.0
  762. *
  763. * @return string Footer credits & link
  764. */
  765. if ( ! function_exists( 'quark_get_credits' ) ) {
  766. function quark_get_credits() {
  767. $output = '';
  768. $output = sprintf( '%1$s <a href="%2$s" title="%3$s">%4$s</a>',
  769. esc_html__( 'Proudly powered by', 'quark' ),
  770. esc_url( esc_html__( 'http://wordpress.org/', 'quark' ) ),
  771. esc_attr( esc_html__( 'Semantic Personal Publishing Platform', 'quark' ) ),
  772. esc_html__( 'WordPress', 'quark' )
  773. );
  774. return $output;
  775. }
  776. }
  777. /**
  778. * Outputs the selected Theme Options inline into the <head>
  779. *
  780. * @since Quark 1.0
  781. *
  782. * @return void
  783. */
  784. function quark_theme_options_styles() {
  785. $output = '';
  786. $imagepath = trailingslashit( get_template_directory_uri() ) . 'images/';
  787. $background_defaults = array(
  788. 'color' => '#222222',
  789. 'image' => $imagepath . 'dark-noise.jpg',
  790. 'repeat' => 'repeat',
  791. 'position' => 'top left',
  792. 'attachment'=>'scroll' );
  793. $background = of_get_option( 'banner_background', $background_defaults );
  794. if ( $background ) {
  795. $bkgrnd_color = apply_filters( 'of_sanitize_color', $background['color'] );
  796. $output .= "#bannercontainer { ";
  797. $output .= "background: " . $bkgrnd_color . " url('" . esc_url( $background['image'] ) . "') " . $background['repeat'] . " " . $background['attachment'] . " " . $background['position'] . ";";
  798. $output .= " }";
  799. }
  800. $footerColour = apply_filters( 'of_sanitize_color', of_get_option( 'footer_color', '#222222' ) );
  801. if ( !empty( $footerColour ) ) {
  802. $output .= "\n#footercontainer { ";
  803. $output .= "background-color: " . $footerColour . ";";
  804. $output .= " }";
  805. }
  806. if ( of_get_option( 'footer_position', 'center' ) ) {
  807. $output .= "\n.smallprint { ";
  808. $output .= "text-align: " . sanitize_text_field( of_get_option( 'footer_position', 'center' ) ) . ";";
  809. $output .= " }";
  810. }
  811. if ( $output != '' ) {
  812. $output = "\n<style>\n" . $output . "\n</style>\n";
  813. echo $output;
  814. }
  815. }
  816. add_action( 'wp_head', 'quark_theme_options_styles' );
  817. /**
  818. * Recreate the default filters on the_content
  819. * This will make it much easier to output the Theme Options Editor content with proper/expected formatting.
  820. * We don't include an add_filter for 'prepend_attachment' as it causes an image to appear in the content, on attachment pages.
  821. * Also, since the Theme Options editor doesn't allow you to add images anyway, no big deal.
  822. *
  823. * @since Quark 1.0
  824. */
  825. add_filter( 'meta_content', 'wptexturize' );
  826. add_filter( 'meta_content', 'convert_smilies' );
  827. add_filter( 'meta_content', 'convert_chars' );
  828. add_filter( 'meta_content', 'wpautop' );
  829. add_filter( 'meta_content', 'shortcode_unautop' );