PageRenderTime 44ms CodeModel.GetById 15ms RepoModel.GetById 1ms app.codeStats 0ms

/wp-content/themes/catch-box/functions.php

https://github.com/ActivateNY/activateny.org
PHP | 919 lines | 505 code | 121 blank | 293 comment | 89 complexity | f4b3a2d718aa830f6a185cfcc5ca5b3a MD5 | raw file
Possible License(s): GPL-2.0, AGPL-1.0, LGPL-2.1
  1. <?php
  2. /**
  3. * Catch Box functions and definitions
  4. *
  5. * Sets up the theme and provides some helper functions. Some helper functions
  6. * are used in the theme as custom template tags. Others are attached to action and
  7. * filter hooks in WordPress to change core functionality.
  8. *
  9. * The first function, catchbox_setup(), sets up the theme by registering support
  10. * for various features in WordPress, such as post thumbnails, navigation menus, and the like.
  11. *
  12. * When using a child theme (see http://codex.wordpress.org/Theme_Development and
  13. * http://codex.wordpress.org/Child_Themes), you can override certain functions
  14. * (those wrapped in a function_exists() call) by defining them first in your child theme's
  15. * functions.php file. The child theme's functions.php file is included before the parent
  16. * theme's file, so the child theme functions would be used.
  17. *
  18. * Functions that are not pluggable (not wrapped in function_exists()) are instead attached
  19. * to a filter or action hook. The hook can be removed by using remove_action() or
  20. * remove_filter() and you can attach your own function to the hook.
  21. *
  22. * We can remove the parent theme's hook only after it is attached, which means we need to
  23. * wait until setting up the child theme:
  24. *
  25. * <code>
  26. * add_action( 'after_setup_theme', 'my_child_theme_setup' );
  27. * function my_child_theme_setup() {
  28. * // We are providing our own filter for excerpt_length (or using the unfiltered value)
  29. * remove_filter( 'excerpt_length', 'catchbox_excerpt_length' );
  30. * ...
  31. * }
  32. * </code>
  33. *
  34. * For more information on hooks, actions, and filters, see http://codex.wordpress.org/Plugin_API.
  35. *
  36. * @package Catch Themes
  37. * @subpackage Catch_Box
  38. * @since Catch Box 1.0
  39. */
  40. /**
  41. * Tell WordPress to run catchbox_setup() when the 'after_setup_theme' hook is run.
  42. */
  43. add_action( 'after_setup_theme', 'catchbox_setup' );
  44. if ( ! function_exists( 'catchbox_setup' ) ):
  45. /**
  46. * Sets up theme defaults and registers support for various WordPress features.
  47. *
  48. * Note that this function is hooked into the after_setup_theme hook, which runs
  49. * before the init hook. The init hook is too late for some features, such as indicating
  50. * support post thumbnails.
  51. *
  52. * To override catchbox_setup() in a child theme, add your own catchbox_setup to your child theme's
  53. * functions.php file.
  54. *
  55. * @uses load_theme_textdomain() For translation/localization support.
  56. * @uses add_editor_style() To style the visual editor.
  57. * @uses add_theme_support() To add support for post thumbnails, automatic feed links,custom headers and backgrounds.
  58. * @uses register_nav_menus() To add support for navigation menus.
  59. * @uses register_default_headers() To register the default custom header images provided with the theme.
  60. * @uses set_post_thumbnail_size() To set a custom post thumbnail size.
  61. *
  62. * @since Catch Box 1.0
  63. */
  64. function catchbox_setup() {
  65. /**
  66. * Global content width.
  67. *
  68. * Set the content width based on the theme's design and stylesheet.
  69. * making it large as we have template without sidebar which is large
  70. */
  71. if ( ! isset( $content_width ) )
  72. $content_width = 818;
  73. /* Catch Box is now available for translation.
  74. * Add your files into /languages/ directory.
  75. * @see http://codex.wordpress.org/Function_Reference/load_theme_textdomain
  76. */
  77. load_theme_textdomain( 'catchbox', get_template_directory() . '/languages' );
  78. $locale = get_locale();
  79. $locale_file = get_template_directory().'/languages/$locale.php';
  80. if (is_readable( $locale_file))
  81. require_once( $locale_file);
  82. /**
  83. * Add callback for custom TinyMCE editor stylesheets. (editor-style.css)
  84. * @see http://codex.wordpress.org/Function_Reference/add_editor_style
  85. */
  86. add_editor_style();
  87. // Load up our theme options page and related code.
  88. require( get_template_directory() . '/inc/theme-options.php' );
  89. // Grab Catch Box's Adspace Widget.
  90. require( get_template_directory() . '/inc/widgets.php' );
  91. // Add default posts and comments RSS feed links to <head>.
  92. add_theme_support( 'automatic-feed-links' );
  93. /**
  94. * This feature enables custom-menus support for a theme.
  95. * @see http://codex.wordpress.org/Function_Reference/register_nav_menus
  96. */
  97. register_nav_menus(array(
  98. 'primary' => __( 'Primary Menu', 'catchbox' ),
  99. 'secondary' => __( 'Secondary Menu', 'catchbox' ),
  100. 'footer' => __( 'Footer Menu', 'catchbox' )
  101. ) );
  102. // Add support for custom backgrounds
  103. // WordPress 3.4+
  104. if ( function_exists( 'get_custom_header') ) {
  105. add_theme_support( 'custom-background' );
  106. } else {
  107. // Backward Compatibility for WordPress Version 3.3
  108. add_custom_background();
  109. }
  110. /**
  111. * This feature enables post-thumbnail support for a theme.
  112. * @see http://codex.wordpress.org/Function_Reference/add_theme_support#Post_Thumbnails
  113. */
  114. add_theme_support( 'post-thumbnails' );
  115. // The next four constants set how Catch Boxsupports custom headers.
  116. // The default header text color
  117. define( 'HEADER_TEXTCOLOR', '000' );
  118. // By leaving empty, we allow for random image rotation.
  119. define( 'HEADER_IMAGE', '' );
  120. // The height and width of your custom header used for site logo.
  121. // Add a filter to catchbox_header_image_width and catchbox_header_image_height to change these values.
  122. define( 'HEADER_IMAGE_WIDTH', apply_filters( 'catchbox_header_image_width', 300 ) );
  123. define( 'HEADER_IMAGE_HEIGHT', apply_filters( 'catchbox_header_image_height', 125 ) );
  124. // We'll be using post thumbnails for custom header images for logos.
  125. // We want them to be the size of the header image that we just defined
  126. // Larger images will be auto-cropped to fit, smaller ones will be ignored. See header.php.
  127. set_post_thumbnail_size( HEADER_IMAGE_WIDTH, HEADER_IMAGE_HEIGHT, true );
  128. // Add Catch Box's custom image sizes
  129. add_image_size( 'featured-header', HEADER_IMAGE_WIDTH, HEADER_IMAGE_HEIGHT, true ); // Used for logo (header) images
  130. //disable old image size for featued posts add_image_size( 'featured-slider', 560, 270, true );
  131. add_image_size( 'featured-slider', 644, 320, true ); // Used for featured posts if a large-feature doesn't exist
  132. // Add support for custom backgrounds
  133. // WordPress 3.4+
  134. if ( function_exists( 'get_custom_header') ) {
  135. add_theme_support( 'custom-header', array(
  136. // Header image random rotation default
  137. 'random-default' => false,
  138. // Header image flex width
  139. 'flex-width' => true,
  140. // Header image flex height
  141. 'flex-height' => true,
  142. // Template header style callback
  143. 'wp-head-callback' => 'catchbox_header_style',
  144. // Admin header style callback
  145. 'admin-head-callback' => 'catchbox_admin_header_style',
  146. // Admin preview style callback
  147. 'admin-preview-callback' => 'catchbox_admin_header_image'
  148. ) );
  149. } else {
  150. // Backward Compatibility for WordPress Version 3.3
  151. // Add a way for the custom header to be styled in the admin panel that controls
  152. // custom headers. See catchbox_admin_header_style(), below.
  153. add_custom_image_header( 'catchbox_header_style', 'catchbox_admin_header_style', 'catchbox_admin_header_image' );
  154. }
  155. // ... and thus ends the changeable header business.
  156. // Default custom headers packaged with the theme. %s is a placeholder for the theme template directory URI.
  157. register_default_headers( array(
  158. 'wheel' => array(
  159. 'url' => '%s/images/headers/garden.jpg',
  160. 'thumbnail_url' => '%s/images/headers/garden-thumbnail.jpg',
  161. /* translators: header image description */
  162. 'description' => __( 'Garden', 'catchbox' )
  163. ),
  164. 'shore' => array(
  165. 'url' => '%s/images/headers/flower.jpg',
  166. 'thumbnail_url' => '%s/images/headers/flower-thumbnail.jpg',
  167. /* translators: header image description */
  168. 'description' => __( 'Flower', 'catchbox' )
  169. ),
  170. 'trolley' => array(
  171. 'url' => '%s/images/headers/mountain.jpg',
  172. 'thumbnail_url' => '%s/images/headers/mountain-thumbnail.jpg',
  173. /* translators: header image description */
  174. 'description' => __( 'Mountain', 'catchbox' )
  175. ),
  176. ) );
  177. }
  178. endif; // catchbox_setup
  179. if ( ! function_exists( 'catchbox_header_style' ) ) :
  180. /**
  181. * Styles the header image and text displayed on the blog
  182. *
  183. * @since Catch Box 1.0
  184. */
  185. function catchbox_header_style() {
  186. $text_color = get_header_textcolor();
  187. // If no custom options for text are set, let's bail.
  188. if ( $text_color == HEADER_TEXTCOLOR )
  189. return;
  190. // If we get this far, we have custom styles. Let's do this.
  191. ?>
  192. <style type="text/css">
  193. <?php
  194. // Has the text been hidden?
  195. if ( 'blank' == $text_color ) :
  196. ?>
  197. #site-title,
  198. #site-description {
  199. position: absolute !important;
  200. clip: rect(1px 1px 1px 1px); /* IE6, IE7 */
  201. clip: rect(1px, 1px, 1px, 1px);
  202. }
  203. <?php
  204. // If the user has set a custom color for the text use that
  205. else :
  206. ?>
  207. #site-title a,
  208. #site-description {
  209. color: #<?php echo get_header_textcolor(); ?> !important;
  210. }
  211. <?php endif; ?>
  212. </style>
  213. <?php
  214. }
  215. endif; // catchbox_header_style
  216. if ( ! function_exists( 'catchbox_admin_header_style' ) ) :
  217. /**
  218. * Styles the header image displayed on the Appearance > Header admin panel.
  219. *
  220. * @since Catch Box 1.0
  221. */
  222. function catchbox_admin_header_style() {
  223. ?>
  224. <style type="text/css">
  225. .appearance_page_custom-header #headimg {
  226. border: none;
  227. }
  228. #headimg h1,
  229. #desc {
  230. font-family: "Helvetica Neue", Arial, Helvetica, "Nimbus Sans L", sans-serif;
  231. }
  232. #headimg h1 {
  233. margin: 0;
  234. }
  235. #headimg h1 a {
  236. font-size: 32px;
  237. line-height: 36px;
  238. text-decoration: none;
  239. }
  240. #desc {
  241. font-size: 14px;
  242. line-height: 23px;
  243. padding: 0 0 3em;
  244. }
  245. <?php
  246. // If the user has set a custom color for the text use that
  247. if ( get_header_textcolor() != HEADER_TEXTCOLOR ) :
  248. ?>
  249. #site-title a,
  250. #site-description {
  251. color: #<?php echo get_header_textcolor(); ?>;
  252. }
  253. <?php endif; ?>
  254. #headimg img {
  255. height: auto;
  256. max-width: 100%;
  257. }
  258. </style>
  259. <?php
  260. }
  261. endif; // catchbox_admin_header_style
  262. if ( ! function_exists( 'catchbox_admin_header_image' ) ) :
  263. /**
  264. * Custom header image markup displayed on the Appearance > Header admin panel.
  265. *
  266. * @since Catch Box 1.0
  267. */
  268. function catchbox_admin_header_image() { ?>
  269. <div id="headimg">
  270. <?php
  271. $color = get_header_textcolor();
  272. $image = get_header_image();
  273. if ( $color && $color != 'blank' )
  274. $style = ' style="color:#' . $color . '"';
  275. else
  276. $style = ' style="display:none"';
  277. ?>
  278. <h1><a id="name"<?php echo $style; ?> onclick="return false;" href="<?php echo esc_url( home_url( '/' ) ); ?>"><?php bloginfo( 'name' ); ?></a></h1>
  279. <div id="desc"<?php echo $style; ?>><?php bloginfo( 'description' ); ?></div>
  280. <?php if ( $image ) : ?>
  281. <img src="<?php echo esc_url( $image ); ?>" alt="" />
  282. <?php endif; ?>
  283. </div>
  284. <?php }
  285. endif; // catchbox_admin_header_image
  286. /**
  287. * Creates a nicely formatted and more specific title element text
  288. * for output in head of document, based on current view.
  289. *
  290. * @param string $title Default title text for current view.
  291. * @param string $sep Optional separator.
  292. * @return string Filtered title.
  293. */
  294. function catchbox_filter_wp_title( $title, $sep ) {
  295. global $page, $paged;
  296. if ( is_feed() )
  297. return $title;
  298. // Add the site name.
  299. $title .= get_bloginfo( 'name' );
  300. // Add the site description for the home/front page.
  301. $site_description = get_bloginfo( 'description', 'display' );
  302. if ( $site_description && ( is_home() || is_front_page() ) )
  303. $title = "$title $sep $site_description";
  304. // Add a page number if necessary.
  305. if ( $paged >= 2 || $page >= 2 )
  306. $title = "$title $sep " . sprintf( __( 'Page %s', 'catchbox' ), max( $paged, $page ) );
  307. return $title;
  308. }
  309. add_filter( 'wp_title', 'catchbox_filter_wp_title', 10, 2 );
  310. /**
  311. * Sets the post excerpt length.
  312. *
  313. * To override this length in a child theme, remove the filter and add your own
  314. * function tied to the excerpt_length filter hook.
  315. */
  316. function catchbox_excerpt_length( $length ) {
  317. $options = catchbox_get_theme_options();
  318. if( empty( $options['excerpt_length'] ) )
  319. $options = catchbox_get_default_theme_options();
  320. $length = $options['excerpt_length'];
  321. return $length;
  322. }
  323. add_filter( 'excerpt_length', 'catchbox_excerpt_length' );
  324. /**
  325. * Returns a "Continue Reading" link for excerpts
  326. */
  327. function catchbox_continue_reading_link() {
  328. return ' <a class="more-link" href="'. esc_url( get_permalink() ) . '">' . __( 'Continue reading <span class="meta-nav">&rarr;</span>', 'catchbox' ) . '</a>';
  329. }
  330. /**
  331. * Replaces "[...]" (appended to automatically generated excerpts) with an ellipsis and catchbox_continue_reading_link().
  332. *
  333. * To override this in a child theme, remove the filter and add your own
  334. * function tied to the excerpt_more filter hook.
  335. */
  336. function catchbox_auto_excerpt_more( $more ) {
  337. return catchbox_continue_reading_link();
  338. }
  339. add_filter( 'excerpt_more', 'catchbox_auto_excerpt_more' );
  340. /**
  341. * Adds a pretty "Continue Reading" link to custom post excerpts.
  342. *
  343. * To override this link in a child theme, remove the filter and add your own
  344. * function tied to the get_the_excerpt filter hook.
  345. */
  346. function catchbox_custom_excerpt_more( $output ) {
  347. if ( has_excerpt() && ! is_attachment() ) {
  348. $output .= catchbox_continue_reading_link();
  349. }
  350. return $output;
  351. }
  352. add_filter( 'get_the_excerpt', 'catchbox_custom_excerpt_more' );
  353. /**
  354. * Get our wp_nav_menu() fallback, wp_page_menu(), to show a home link.
  355. */
  356. function catchbox_page_menu_args( $args ) {
  357. $args['show_home'] = true;
  358. return $args;
  359. }
  360. add_filter( 'wp_page_menu_args', 'catchbox_page_menu_args' );
  361. /**
  362. * Replacing classes in default wp_page_menu
  363. *
  364. * REPLACE "current_page_item" WITH CLASS "current-menu-item"
  365. * REPLACE "current_page_ancestor" WITH CLASS "current-menu-ancestor"
  366. */
  367. function catchbox_page_menu_active($text){
  368. $replace = array(
  369. // List of classes to replace with "active"
  370. 'current_page_item' => 'current-menu-item',
  371. 'current_page_ancestor' => 'current-menu-ancestor',
  372. );
  373. $text = str_replace(array_keys($replace), $replace, $text);
  374. return $text;
  375. }
  376. add_filter ( 'wp_page_menu', 'catchbox_page_menu_active' );
  377. /**
  378. * Register our sidebars and widgetized areas. Also register the default Epherma widget.
  379. *
  380. * @since Catch Box 1.0
  381. */
  382. function catchbox_widgets_init() {
  383. register_widget( 'catchbox_adwidget' );
  384. register_sidebar( array(
  385. 'name' => __( 'Main Sidebar', 'catchbox' ),
  386. 'id' => 'sidebar-1',
  387. 'before_widget' => '<aside id="%1$s" class="widget %2$s">',
  388. 'after_widget' => "</aside>",
  389. 'before_title' => '<h3 class="widget-title">',
  390. 'after_title' => '</h3>',
  391. ) );
  392. register_sidebar( array(
  393. 'name' => __( 'Footer Area One', 'catchbox' ),
  394. 'id' => 'sidebar-2',
  395. 'description' => __( 'An optional widget area for your site footer', 'catchbox' ),
  396. 'before_widget' => '<aside id="%1$s" class="widget %2$s">',
  397. 'after_widget' => "</aside>",
  398. 'before_title' => '<h3 class="widget-title">',
  399. 'after_title' => '</h3>',
  400. ) );
  401. register_sidebar( array(
  402. 'name' => __( 'Footer Area Two', 'catchbox' ),
  403. 'id' => 'sidebar-3',
  404. 'description' => __( 'An optional widget area for your site footer', 'catchbox' ),
  405. 'before_widget' => '<aside id="%1$s" class="widget %2$s">',
  406. 'after_widget' => "</aside>",
  407. 'before_title' => '<h3 class="widget-title">',
  408. 'after_title' => '</h3>',
  409. ) );
  410. register_sidebar( array(
  411. 'name' => __( 'Footer Area Three', 'catchbox' ),
  412. 'id' => 'sidebar-4',
  413. 'description' => __( 'An optional widget area for your site footer', 'catchbox' ),
  414. 'before_widget' => '<aside id="%1$s" class="widget %2$s">',
  415. 'after_widget' => "</aside>",
  416. 'before_title' => '<h3 class="widget-title">',
  417. 'after_title' => '</h3>',
  418. ) );
  419. }
  420. add_action( 'widgets_init', 'catchbox_widgets_init' );
  421. if ( ! function_exists( 'catchbox_content_nav' ) ) :
  422. /**
  423. * Display navigation to next/previous pages when applicable
  424. */
  425. function catchbox_content_nav( $nav_id ) {
  426. global $wp_query;
  427. if ( $wp_query->max_num_pages > 1 ) { ?>
  428. <nav id="<?php echo $nav_id; ?>">
  429. <h3 class="assistive-text"><?php _e( 'Post navigation', 'catchbox' ); ?></h3>
  430. <?php if ( function_exists('wp_pagenavi' ) ) {
  431. wp_pagenavi();
  432. }
  433. elseif ( function_exists('wp_page_numbers' ) ) {
  434. wp_page_numbers();
  435. }
  436. else { ?>
  437. <div class="nav-previous"><?php next_posts_link( __( '<span class="meta-nav">&larr;</span> Older posts', 'catchbox' ) ); ?></div>
  438. <div class="nav-next"><?php previous_posts_link( __( 'Newer posts <span class="meta-nav">&rarr;</span>', 'catchbox' ) ); ?></div>
  439. <?php
  440. } ?>
  441. </nav><!-- #nav -->
  442. <?php
  443. }
  444. }
  445. endif; // catchbox_content_nav
  446. /**
  447. * Return the URL for the first link found in the post content.
  448. *
  449. * @since Catch Box 1.0
  450. * @return string|bool URL or false when no link is present.
  451. */
  452. function catchbox_url_grabber() {
  453. if ( ! preg_match( '/<a\s[^>]*?href=[\'"](.+?)[\'"]/is', get_the_content(), $matches ) )
  454. return false;
  455. return esc_url_raw( $matches[1] );
  456. }
  457. /**
  458. * Count the number of footer sidebars to enable dynamic classes for the footer
  459. */
  460. function catchbox_footer_sidebar_class() {
  461. $count = 0;
  462. if ( is_active_sidebar( 'sidebar-2' ) )
  463. $count++;
  464. if ( is_active_sidebar( 'sidebar-3' ) )
  465. $count++;
  466. if ( is_active_sidebar( 'sidebar-4' ) )
  467. $count++;
  468. $class = '';
  469. switch ( $count ) {
  470. case '1':
  471. $class = 'one';
  472. break;
  473. case '2':
  474. $class = 'two';
  475. break;
  476. case '3':
  477. $class = 'three';
  478. break;
  479. }
  480. if ( $class )
  481. echo 'class="' . $class . '"';
  482. }
  483. if ( ! function_exists( 'catchbox_comment' ) ) :
  484. /**
  485. * Template for comments and pingbacks.
  486. *
  487. * To override this walker in a child theme without modifying the comments template
  488. * simply create your own catchbox_comment(), and that function will be used instead.
  489. *
  490. * Used as a callback by wp_list_comments() for displaying the comments.
  491. *
  492. * @since Catch Box 1.0
  493. */
  494. function catchbox_comment( $comment, $args, $depth ) {
  495. $GLOBALS['comment'] = $comment;
  496. switch ( $comment->comment_type ) :
  497. case 'pingback' :
  498. case 'trackback' :
  499. ?>
  500. <li class="post pingback">
  501. <p><?php _e( 'Pingback:', 'catchbox' ); ?> <?php comment_author_link(); ?><?php edit_comment_link( __( 'Edit', 'catchbox' ), '<span class="edit-link">', '</span>' ); ?></p>
  502. <?php
  503. break;
  504. default :
  505. ?>
  506. <li <?php comment_class(); ?> id="li-comment-<?php comment_ID(); ?>">
  507. <article id="comment-<?php comment_ID(); ?>" class="comment">
  508. <footer class="comment-meta">
  509. <div class="comment-author vcard">
  510. <?php
  511. $avatar_size = 68;
  512. if ( '0' != $comment->comment_parent )
  513. $avatar_size = 39;
  514. echo get_avatar( $comment, $avatar_size );
  515. /* translators: 1: comment author, 2: date and time */
  516. printf( __( '%1$s on %2$s <span class="says">said:</span>', 'catchbox' ),
  517. sprintf( '<span class="fn">%s</span>', get_comment_author_link() ),
  518. sprintf( '<a href="%1$s"><time pubdate datetime="%2$s">%3$s</time></a>',
  519. esc_url( get_comment_link( $comment->comment_ID ) ),
  520. get_comment_time( 'c' ),
  521. /* translators: 1: date, 2: time */
  522. sprintf( __( '%1$s at %2$s', 'catchbox' ), get_comment_date(), get_comment_time() )
  523. )
  524. );
  525. ?>
  526. <?php edit_comment_link( __( 'Edit', 'catchbox' ), '<span class="edit-link">', '</span>' ); ?>
  527. </div><!-- .comment-author .vcard -->
  528. <?php if ( $comment->comment_approved == '0' ) : ?>
  529. <em class="comment-awaiting-moderation"><?php _e( 'Your comment is awaiting moderation.', 'catchbox' ); ?></em>
  530. <br />
  531. <?php endif; ?>
  532. </footer>
  533. <div class="comment-content"><?php comment_text(); ?></div>
  534. <div class="reply">
  535. <?php comment_reply_link( array_merge( $args, array( 'reply_text' => __( 'Reply <span>&darr;</span>', 'catchbox' ), 'depth' => $depth, 'max_depth' => $args['max_depth'] ) ) ); ?>
  536. </div><!-- .reply -->
  537. </article><!-- #comment-## -->
  538. <?php
  539. break;
  540. endswitch;
  541. }
  542. endif; // ends check for catchbox_comment()
  543. if ( ! function_exists( 'catchbox_posted_on' ) ) :
  544. /**
  545. * Prints HTML with meta information for the current post-date/time and author.
  546. * Create your own catchbox_posted_on to override in a child theme
  547. *
  548. * @since Catch Box 1.0
  549. */
  550. function catchbox_posted_on() {
  551. printf( __( '<span class="sep">Posted on </span><a href="%1$s" title="%2$s" rel="bookmark"><time class="entry-date updated" datetime="%3$s" pubdate>%4$s</time></a><span class="by-author"> <span class="sep"> by </span> <span class="author vcard"><a class="url fn n" href="%5$s" title="%6$s" rel="author">%7$s</a></span></span>', 'catchbox' ),
  552. esc_url( get_permalink() ),
  553. esc_attr( get_the_time() ),
  554. esc_attr( get_the_date( 'c' ) ),
  555. esc_html( get_the_date() ),
  556. esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ),
  557. esc_attr( sprintf( __( 'View all posts by %s', 'catchbox' ), get_the_author() ) ),
  558. get_the_author()
  559. );
  560. }
  561. endif;
  562. /**
  563. * Adds two classes to the array of body classes.
  564. * The first is if the site has only had one author with published posts.
  565. * The second is if a singular post being displayed
  566. *
  567. * @since Catch Box 1.0
  568. */
  569. function catchbox_body_classes( $classes ) {
  570. $options = catchbox_get_theme_options();
  571. $layout = $options['theme_layout'];
  572. if ( function_exists( 'is_multi_author' ) && !is_multi_author() ) {
  573. $classes[] = 'single-author';
  574. }
  575. if ( $layout == 'content-sidebar' && !is_page_template( 'page-disable-sidebar.php' ) && !is_page_template( 'page-fullwidth.php' ) && !is_page_template( 'page-onecolumn.php' ) ) {
  576. $classes[] = 'content-sidebar';
  577. }
  578. elseif ( $layout == 'sidebar-content' && !is_page_template( 'page-disable-sidebar.php' ) && !is_page_template( 'page-fullwidth.php' ) && !is_page_template( 'page-onecolumn.php' ) ) {
  579. $classes[] = 'sidebar-content';
  580. }
  581. elseif ( $layout == 'content-onecolumn' || is_page_template( 'page-onecolumn.php' ) && !is_page_template( 'page-disable-sidebar.php' ) && !is_page_template( 'page-fullwidth.php' ) ) {
  582. $classes[] = 'content-onecolumn';
  583. }
  584. elseif ( is_page_template( 'page-disable-sidebar.php' ) || is_attachment() ) {
  585. $classes[] = 'singular';
  586. }
  587. elseif ( is_page_template( 'page-fullwidth.php' ) || is_attachment() ) {
  588. $classes[] = 'fullwidth';
  589. }
  590. return $classes;
  591. }
  592. add_filter( 'body_class', 'catchbox_body_classes' );
  593. /**
  594. * Adds in post ID when viewing lists of posts
  595. * This will help the admin to add the post ID in featured slider
  596. *
  597. * @param mixed $post_columns
  598. * @return post columns
  599. */
  600. function catchbox_post_id_column( $post_columns ) {
  601. $beginning = array_slice( $post_columns, 0 ,1 );
  602. $beginning[ 'postid' ] = __( 'ID', 'catchbox' );
  603. $ending = array_slice( $post_columns, 1 );
  604. $post_columns = array_merge( $beginning, $ending );
  605. return $post_columns;
  606. }
  607. add_filter( 'manage_posts_columns', 'catchbox_post_id_column' );
  608. function catchbox_posts_id_column( $col, $val ) {
  609. if( $col == 'postid' ) echo $val;
  610. }
  611. add_action( 'manage_posts_custom_column', 'catchbox_posts_id_column', 10, 2 );
  612. function catchbox_posts_id_column_css() {
  613. echo '<style type="text/css">#postid { width: 50px; }</style>';
  614. }
  615. add_action( 'admin_head-edit.php', 'catchbox_posts_id_column_css' );
  616. /**
  617. * Function to pass the variables for php to js file.
  618. * This funcition passes the slider effect variables.
  619. */
  620. function catchbox_pass_slider_value() {
  621. $options = get_option( 'catchbox_options_slider' );
  622. if( !isset( $options[ 'transition_effect' ] ) ) {
  623. $options[ 'transition_effect' ] = "fade";
  624. }
  625. if( !isset( $options[ 'transition_delay' ] ) ) {
  626. $options[ 'transition_delay' ] = 4;
  627. }
  628. if( !isset( $options[ 'transition_duration' ] ) ) {
  629. $options[ 'transition_duration' ] = 1;
  630. }
  631. $transition_effect = $options[ 'transition_effect' ];
  632. $transition_delay = $options[ 'transition_delay' ] * 1000;
  633. $transition_duration = $options[ 'transition_duration' ] * 1000;
  634. wp_localize_script(
  635. 'catchbox_slider',
  636. 'js_value',
  637. array(
  638. 'transition_effect' => $transition_effect,
  639. 'transition_delay' => $transition_delay,
  640. 'transition_duration' => $transition_duration
  641. )
  642. );
  643. }//catchbox_pass_slider_value
  644. /**
  645. * This function to display featured posts on index.php
  646. *
  647. * @get the data value from theme options
  648. * @displays on the index
  649. *
  650. * @useage Featured Image, Title and Content of Post
  651. *
  652. * @uses set_transient and delete_transient
  653. */
  654. function catchbox_sliders() {
  655. global $post;
  656. //delete_transient( 'catchbox_sliders' );
  657. // get data value from catchbox_options_slider through theme options
  658. $options = get_option( 'catchbox_options_slider' );
  659. // get slider_qty from theme options
  660. $postperpage = $options[ 'slider_qty' ];
  661. if( ( !$catchbox_sliders = get_transient( 'catchbox_sliders' ) ) && !empty( $options[ 'featured_slider' ] ) ) {
  662. echo '<!-- refreshing cache -->';
  663. $catchbox_sliders = '
  664. <div id="slider">
  665. <section id="slider-wrap">';
  666. $get_featured_posts = new WP_Query( array(
  667. 'posts_per_page' => $postperpage,
  668. 'post__in' => $options[ 'featured_slider' ],
  669. 'orderby' => 'post__in',
  670. 'ignore_sticky_posts' => 1 // ignore sticky posts
  671. ));
  672. $i=0; while ( $get_featured_posts->have_posts()) : $get_featured_posts->the_post(); $i++;
  673. $title_attribute = esc_attr( apply_filters( 'the_title', get_the_title( $post->ID ) ) );
  674. if ( $i == 1 ) { $classes = "slides displayblock"; } else { $classes = "slides displaynone"; }
  675. $catchbox_sliders .= '
  676. <div class="'.$classes.'">
  677. <a href="'.get_permalink().'" title="'.sprintf( esc_attr__( 'Permalink to %s', 'catchbox' ), the_title_attribute( 'echo=0' ) ).'" rel="bookmark">
  678. '.get_the_post_thumbnail( $post->ID, 'featured-slider', array( 'title' => $title_attribute, 'alt' => $title_attribute, 'class' => 'pngfix' ) ).'
  679. </a>
  680. <div class="featured-text">'
  681. .the_title( '<span>','</span>', false ).' :
  682. '.get_the_excerpt().'
  683. </div><!-- .featured-text -->
  684. </div> <!-- .slides -->';
  685. endwhile; wp_reset_query();
  686. $catchbox_sliders .= '
  687. </section> <!-- .slider-wrap -->
  688. <nav id="nav-slider">
  689. <div class="nav-previous"><img class="pngfix" src="'.get_template_directory_uri().'/images/previous.png" alt="next slide"></div>
  690. <div class="nav-next"><img class="pngfix" src="'.get_template_directory_uri().'/images/next.png" alt="next slide"></div>
  691. </nav>
  692. </div> <!-- #featured-slider -->';
  693. set_transient( 'catchbox_sliders', $catchbox_sliders, 86940 );
  694. }
  695. echo $catchbox_sliders;
  696. } // catchbox_sliders
  697. /**
  698. * Register jquery scripts
  699. *
  700. * @register jquery cycle and custom-script
  701. * hooks action wp_enqueue_scripts
  702. */
  703. function catchbox_scripts_method() {
  704. //Register JQuery circle all and JQuery set up as dependent on Jquery-cycle
  705. wp_register_script( 'jquery-cycle', get_template_directory_uri() . '/js/jquery.cycle.all.min.js', array( 'jquery' ), '2.9999.5', true );
  706. //Enqueue Slider Script only in Front Page
  707. if(is_home() || is_front_page()) {
  708. wp_enqueue_script( 'catchbox_slider', get_template_directory_uri() . '/js/catchbox_slider.js', array( 'jquery-cycle' ), '1.0', true );
  709. }
  710. wp_enqueue_script('catchbox-menu', get_template_directory_uri() . '/js/catchbox-menu.min.js', array('jquery'), '1.1.0', true);
  711. //Browser Specific Enqueue Script i.e. for IE 1-6
  712. $catchbox_ua = strtolower($_SERVER['HTTP_USER_AGENT']);
  713. if(preg_match('/(?i)msie [1-6]/',$catchbox_ua)) {
  714. wp_enqueue_script( 'catchbox-pngfix', get_template_directory_uri() . '/js/pngfix.min.js' );
  715. }
  716. //browser specific queuing i.e. for IE 1-8
  717. if(preg_match('/(?i)msie [1-8]/',$catchbox_ua)) {
  718. wp_enqueue_script( 'catchbox-html5', get_template_directory_uri() . '/js/html5.js' );
  719. }
  720. } // catchbox_scripts_method
  721. add_action( 'wp_enqueue_scripts', 'catchbox_scripts_method' );
  722. /**
  723. * Enqueue Comment Reply Script
  724. *
  725. * @used wp_enqueue_script
  726. * hooks action comment_form_before
  727. */
  728. function catchbox_enqueue_comment_reply_script() {
  729. if ( comments_open() && get_option( 'thread_comments' ) ) {
  730. wp_enqueue_script( 'comment-reply' );
  731. }
  732. }
  733. add_action( 'comment_form_before', 'catchbox_enqueue_comment_reply_script' );
  734. /**
  735. * Alter the query for the main loop in home page
  736. * @uses pre_get_posts hook
  737. */
  738. function catchbox_alter_home( $query ) {
  739. $options = get_option( 'catchbox_options_slider' );
  740. if( !isset( $options[ 'exclude_slider_post' ] ) ) {
  741. $options[ 'exclude_slider_post' ] = "0";
  742. }
  743. if ( $options[ 'exclude_slider_post'] != "0" && !empty( $options[ 'featured_slider' ] ) ) {
  744. if( $query->is_main_query() && $query->is_home() ) {
  745. $query->query_vars['post__not_in'] = $options[ 'featured_slider' ];
  746. }
  747. }
  748. }
  749. add_action( 'pre_get_posts','catchbox_alter_home' );
  750. /**
  751. * Remove div from wp_page_menu() and replace with ul.
  752. * @uses wp_page_menu filter
  753. */
  754. function catchbox_wp_page_menu( $page_markup ) {
  755. preg_match('/^<div class=\"([a-z0-9-_]+)\">/i', $page_markup, $matches);
  756. $divclass = $matches[1];
  757. $replace = array('<div class="'.$divclass.'">', '</div>');
  758. $new_markup = str_replace($replace, '', $page_markup);
  759. $new_markup = preg_replace('/^<ul>/i', '<ul class="'.$divclass.'">', $new_markup);
  760. return $new_markup; }
  761. add_filter( 'wp_page_menu', 'catchbox_wp_page_menu' );
  762. /**
  763. * Altering Comment Form Fields
  764. * @uses comment_form_default_fields filter
  765. */
  766. function catchbox_comment_form_fields( $fields ) {
  767. $req = get_option( 'require_name_email' );
  768. $aria_req = ( $req ? " aria-required='true'" : '' );
  769. $commenter = wp_get_current_commenter();
  770. $fields['author'] = '<p class="comment-form-author"><label for="author">' . esc_attr__( 'Name', 'catchbox' ) . '</label> ' . ( $req ? '<span class="required">*</span>' : '' ) .
  771. '<input id="author" name="author" type="text" value="' . esc_attr( $commenter['comment_author'] ) . '" size="30"' . $aria_req . ' /></p>';
  772. $fields['email'] = '<p class="comment-form-email"><label for="email">' . esc_attr__( 'Email', 'catchbox' ) . '</label> ' . ( $req ? '<span class="required">*</span>' : '' ) .
  773. '<input id="email" name="email" type="text" value="' . esc_attr( $commenter['comment_author_email'] ) . '" size="30"' . $aria_req . ' /></p>';
  774. return $fields;
  775. }
  776. add_filter( 'comment_form_default_fields', 'catchbox_comment_form_fields' );
  777. /**
  778. * Get the Web Click Icon from theme options
  779. *
  780. * @uses web clip
  781. * @get the data value of image from theme options
  782. * @display web clip
  783. *
  784. * @uses set_transient and delete_transient
  785. */
  786. function catchbox_webclip() {
  787. //delete_transient( 'catchbox_webclip' );
  788. if ( !$catchbox_webclip = get_transient( 'catchbox_webclip' ) ) {
  789. $options = catchbox_get_theme_options();
  790. if ( !empty( $options['fav_icon'] ) ) {
  791. $catchbox_webclip = '<link rel="apple-touch-icon-precomposed" href="'.esc_url( $options[ 'web_clip' ] ).'" />';
  792. }
  793. set_transient( 'catchbox_webclip', $catchbox_webclip, 86940 );
  794. }
  795. echo $catchbox_webclip ;
  796. }
  797. //Load webclip in Header Section
  798. add_action('wp_head', 'catchbox_webclip');