functions.php 52 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459
  1. <?php
  2. /**
  3. * Framework Functions File
  4. *
  5. * Please do not edit this file. This file is part of the Cyber Chimps Framework and all modifications
  6. * should be made in a child theme.
  7. *
  8. * Text Domain: cyberchimps_core
  9. *
  10. * @category CyberChimps Framework
  11. * @package Framework
  12. * @since 1.0
  13. * @author CyberChimps
  14. * @license http://www.opensource.org/licenses/gpl-license.php GPL v3.0 (or later)
  15. * @link http://www.cyberchimps.com/
  16. */
  17. // include plugin.php to use is_plugin_active() condition
  18. include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
  19. if( !function_exists( 'cyberchimps_get_option' ) ) {
  20. /**
  21. * Get Option.
  22. *
  23. * Helper function to return the theme option value.
  24. * If no value has been saved, it returns $default.
  25. * Needed because options are saved as serialized strings.
  26. */
  27. function cyberchimps_get_option( $name, $default = false ) {
  28. $options = get_option( 'cyberchimps_options' );
  29. if( isset( $options[$name] ) ) {
  30. return $options[$name];
  31. }
  32. return $default;
  33. }
  34. }
  35. // Enqueue core scripts and core styles
  36. function cyberchimps_core_scripts() {
  37. global $post;
  38. // Define paths
  39. $directory_uri = get_template_directory_uri();
  40. $js_path = $directory_uri . '/cyberchimps/lib/js/';
  41. $bootstrap_path = $directory_uri . '/cyberchimps/lib/bootstrap/';
  42. // set up slimbox for gallery images
  43. if( cyberchimps_get_option( 'gallery_lightbox', 1 ) ) {
  44. wp_enqueue_script( 'gallery-lightbox', $js_path . 'gallery-lightbox.min.js', array( 'jquery' ), '1.0' );
  45. }
  46. // Load JS for slimbox
  47. wp_enqueue_script( 'slimbox', $js_path . 'jquery.slimbox.min.js', array( 'jquery' ), '1.0' );
  48. // Load library for jcarousel
  49. wp_enqueue_script( 'jcarousel', $js_path . 'jquery.jcarousel.min.js', array( 'jquery' ), '1.0' );
  50. //touch swipe gestures
  51. wp_enqueue_script( 'jquery-mobile-touch', $js_path . 'jquery.mobile.custom.min.js', array( 'jquery' ) );
  52. wp_enqueue_script( 'slider-call', $js_path . 'swipe-call.min.js', array( 'jquery', 'jquery-mobile-touch' ) );
  53. // Load Bootstrap Library Items
  54. wp_enqueue_style( 'bootstrap-style', $bootstrap_path . 'css/bootstrap.min.css', false, '2.0.4' );
  55. wp_enqueue_style( 'bootstrap-responsive-style', $bootstrap_path . 'css/bootstrap-responsive.min.css', array( 'bootstrap-style' ), '2.0.4' );
  56. wp_enqueue_script( 'bootstrap-js', $bootstrap_path . 'js/bootstrap.min.js', array( 'jquery' ), '2.0.4', true );
  57. //responsive design
  58. if( cyberchimps_get_option( 'responsive_design', 'checked' ) ) {
  59. wp_enqueue_style( 'cyberchimps_responsive', $directory_uri . '/cyberchimps/lib/bootstrap/css/cyberchimps-responsive.min.css', array( 'bootstrap-responsive-style', 'bootstrap-style' ), '1.0' );
  60. }
  61. else {
  62. wp_dequeue_style( 'cyberchimps_responsive' );
  63. }
  64. // Load core JS
  65. wp_enqueue_script( 'core-js', $js_path . 'core.min.js', array( 'jquery' ) );
  66. /**
  67. * With the use of @2x at the end of an image it will use that to display the retina image. Both images have to been in the same folder
  68. */
  69. wp_enqueue_script( 'retina-js', $js_path . 'retina-1.1.0.min.js', '', '1.1.0', true );
  70. // Load Core Stylesheet
  71. wp_enqueue_style( 'core-style', $directory_uri . '/cyberchimps/lib/css/core.css', array( 'bootstrap-responsive-style', 'bootstrap-style' ), '1.0' );
  72. // Load Theme Stylesheet
  73. wp_enqueue_style( 'style', get_stylesheet_uri(), array( 'core-style' ), '1.0' );
  74. // add javascript for comments
  75. if( is_singular() ) {
  76. wp_enqueue_script( 'comment-reply' );
  77. }
  78. if( cyberchimps_get_option( 'responsive_videos' ) == '1' ) {
  79. wp_enqueue_script( 'video', $js_path . 'video.min.js' );
  80. }
  81. }
  82. add_action( 'wp_enqueue_scripts', 'cyberchimps_core_scripts', 20 );
  83. /**
  84. * WooCommerce
  85. *
  86. * Unhook/Hook the WooCommerce Wrappers
  87. */
  88. remove_action( 'woocommerce_before_main_content', 'woocommerce_output_content_wrapper', 10 );
  89. remove_action( 'woocommerce_after_main_content', 'woocommerce_output_content_wrapper_end', 10 );
  90. remove_action( 'woocommerce_sidebar', 'woocommerce_get_sidebar', 10 );
  91. add_action( 'woocommerce_before_main_content', 'cyberchimps_wrapper_start', 10 );
  92. add_action( 'woocommerce_after_main_content', 'cyberchimps_wrapper_end', 10 );
  93. if( !function_exists( 'cyberchimps_wrapper_start' ) ) {
  94. function cyberchimps_wrapper_start() {
  95. ?>
  96. <div id="cc_woocommerce" class="container-full-width">
  97. <div class="container">
  98. <div class="container-fluid">
  99. <div id="container" <?php cyberchimps_filter_container_class(); ?>>
  100. <?php do_action( 'cyberchimps_before_content_container' ); ?>
  101. <div id="content" <?php cyberchimps_filter_content_class(); ?>>
  102. <?php do_action( 'cyberchimps_before_content' );
  103. }
  104. }
  105. if( !function_exists( 'cyberchimps_wrapper_end' ) ) {
  106. function cyberchimps_wrapper_end() {
  107. ?>
  108. <?php do_action( 'cyberchimps_after_content' ); ?>
  109. </div><!-- #content -->
  110. <?php do_action( 'cyberchimps_after_content_container' ); ?>
  111. </div><!-- #container .row-fluid-->
  112. </div><!-- container fluid -->
  113. </div><!-- conatiner -->
  114. </div><!-- container full width -->
  115. <?php
  116. }
  117. }
  118. //Enables woocommerce support for the theme.
  119. add_theme_support( 'woocommerce' );
  120. function cyberchimps_create_layout() {
  121. global $post;
  122. if( is_single() ) {
  123. $layout_type = cyberchimps_get_option( 'single_post_sidebar_options', 'right_sidebar' );
  124. }
  125. elseif( is_home() ) {
  126. $layout_type = cyberchimps_get_option( 'sidebar_images', 'right_sidebar' );
  127. }
  128. elseif( is_page() ) {
  129. $page_sidebar = get_post_meta( $post->ID, 'cyberchimps_page_sidebar' );
  130. $layout_type = ( isset( $page_sidebar[0] ) ) ? $page_sidebar[0] : 'right_sidebar';
  131. }
  132. elseif( is_plugin_active( 'woocommerce/woocommerce.php' ) && is_woocommerce() && is_shop() ) {
  133. $page_sidebar = get_post_meta( woocommerce_get_page_id( 'shop' ), 'cyberchimps_page_sidebar' );
  134. $layout_type = ( isset( $page_sidebar[0] ) ) ? $page_sidebar[0] : 'right_sidebar';
  135. }
  136. elseif( is_archive() ) {
  137. $layout_type = cyberchimps_get_option( 'archive_sidebar_options', 'right_sidebar' );
  138. }
  139. elseif( is_search() ) {
  140. $layout_type = cyberchimps_get_option( 'search_sidebar_options', 'right_sidebar' );
  141. }
  142. elseif( is_404() ) {
  143. $layout_type = cyberchimps_get_option( 'error_sidebar_options', 'right_sidebar' );
  144. }
  145. else {
  146. $layout_type = apply_filters( 'cyberchimps_default_layout', 'right_sidebar' );
  147. }
  148. cyberchimps_get_layout( $layout_type );
  149. }
  150. add_action( 'wp', 'cyberchimps_create_layout' );
  151. function cyberchimps_get_layout( $layout_type ) {
  152. $wide_sidebar = cyberchimps_get_option( 'wide_sidebar', 0 );
  153. $layout_type = ( $layout_type ) ? $layout_type : 'right_sidebar';
  154. $content_span = ( $wide_sidebar == 1 ) ? 'cyberchimps_class_span8' : 'cyberchimps_class_span9';
  155. $sidebar_span = ( $wide_sidebar == 1 ) ? 'cyberchimps_class_span4' : 'cyberchimps_class_span3';
  156. switch( $layout_type ) {
  157. case 'full_width' :
  158. add_filter( 'cyberchimps_content_class', 'cyberchimps_class_span12' );
  159. break;
  160. case 'right_sidebar' :
  161. add_action( 'cyberchimps_after_content_container', 'cyberchimps_add_sidebar_right' );
  162. add_filter( 'cyberchimps_content_class', $content_span );
  163. add_filter( 'cyberchimps_content_class', 'cyberchimps_content_sbr_class' );
  164. add_filter( 'cyberchimps_sidebar_right_class', $sidebar_span );
  165. break;
  166. case 'left_sidebar' :
  167. add_action( 'cyberchimps_before_content_container', 'cyberchimps_add_sidebar_left' );
  168. add_filter( 'cyberchimps_content_class', $content_span );
  169. add_filter( 'cyberchimps_content_class', 'cyberchimps_content_sbl_class' );
  170. add_filter( 'cyberchimps_sidebar_left_class', $sidebar_span );
  171. break;
  172. case 'content_middle' :
  173. add_action( 'cyberchimps_before_content_container', 'cyberchimps_add_sidebar_left' );
  174. add_action( 'cyberchimps_after_content_container', 'cyberchimps_add_sidebar_right' );
  175. add_filter( 'cyberchimps_content_class', 'cyberchimps_class_span6' );
  176. add_filter( 'cyberchimps_content_class', 'cyberchimps_content_sb2_class' );
  177. add_filter( 'cyberchimps_sidebar_left_class', 'cyberchimps_class_span3' );
  178. add_filter( 'cyberchimps_sidebar_right_class', 'cyberchimps_class_span3' );
  179. break;
  180. case 'left_right_sidebar' :
  181. add_action( 'cyberchimps_after_content_container', 'cyberchimps_add_sidebar_left' );
  182. add_action( 'cyberchimps_after_content_container', 'cyberchimps_add_sidebar_right' );
  183. add_filter( 'cyberchimps_content_class', 'cyberchimps_class_span6' );
  184. add_filter( 'cyberchimps_content_class', 'cyberchimps_content_sb2r_class' );
  185. add_filter( 'cyberchimps_sidebar_left_class', 'cyberchimps_class_span3' );
  186. add_filter( 'cyberchimps_sidebar_right_class', 'cyberchimps_class_span3' );
  187. break;
  188. }
  189. }
  190. class cyberchimps_Walker extends Walker_Nav_Menu {
  191. function start_lvl( &$output, $depth = 0, $args = array() ) {
  192. //In a child UL, add the 'dropdown-menu' class
  193. if( $depth == 0 ) {
  194. $indent = str_repeat( "\t", $depth );
  195. $output .= "\n$indent<ul class=\"dropdown-menu\">\n";
  196. }
  197. else {
  198. $indent = str_repeat( "\t", $depth );
  199. $output .= "\n$indent<ul>\n";
  200. }
  201. }
  202. function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 ) {
  203. $indent = ( $depth ) ? str_repeat( "\t", $depth ) : '';
  204. $li_attributes = '';
  205. $class_names = $value = '';
  206. $classes = empty( $item->classes ) ? array() : ( array )$item->classes;
  207. //Add class and attribute to LI element that contains a submenu UL.
  208. if( $args->has_children && $depth < 1 ) {
  209. $classes[] = 'dropdown';
  210. $li_attributes .= ' data-dropdown="dropdown"';
  211. }
  212. if( $args->has_children && $depth == 1 ) {
  213. $classes[] = 'grandchild';
  214. }
  215. $classes[] = 'menu-item-' . $item->ID;
  216. //If we are on the current page, add the active class to that menu item.
  217. $classes[] = ( $item->current ) ? 'active' : '';
  218. //Make sure you still add all of the WordPress classes.
  219. $class_names = join( ' ', apply_filters( 'nav_menu_css_class', array_filter( $classes ), $item, $args ) );
  220. $class_names = ' class="' . esc_attr( $class_names ) . '"';
  221. $id = apply_filters( 'nav_menu_item_id', 'menu-item-' . $item->ID, $item, $args );
  222. $id = strlen( $id ) ? ' id="' . esc_attr( $id ) . '"' : '';
  223. $output .= $indent . '<li' . $id . $value . $class_names . $li_attributes . '>';
  224. //Add attributes to link element.
  225. $attributes = !empty( $item->attr_title ) ? ' title="' . esc_attr( $item->attr_title ) . '"' : '';
  226. $attributes .= !empty( $item->target ) ? ' target="' . esc_attr( $item->target ) . '"' : '';
  227. $attributes .= !empty( $item->xfn ) ? ' rel="' . esc_attr( $item->xfn ) . '"' : '';
  228. $attributes .= !empty( $item->url ) ? ' href="' . esc_attr( $item->url ) . '"' : '';
  229. $attributes .= ( $args->has_children && $depth < 1 ) ? ' class="dropdown-toggle"' : '';
  230. $item_output = $args->before;
  231. $item_output .= '<a' . $attributes . '>';
  232. $item_output .= $args->link_before . apply_filters( 'the_title', $item->title, $item->ID ) . $args->link_after;
  233. $item_output .= ( $args->has_children && $depth < 1 ) ? ' <b class="caret"></b> ' : '';
  234. $item_output .= ( $args->has_children && $depth == 1 ) ? apply_filters( 'cyberchimps_menu_grandchild_caret', '' ) : '';
  235. $item_output .= '</a>';
  236. $item_output .= $args->after;
  237. $output .= apply_filters( 'walker_nav_menu_start_el', $item_output, $item, $depth, $args );
  238. }
  239. //Overwrite display_element function to add has_children attribute. Not needed in >= WordPress 3.4
  240. function display_element( $element, &$children_elements, $max_depth, $depth = 0, $args, &$output ) {
  241. if( !$element ) {
  242. return;
  243. }
  244. $id_field = $this->db_fields['id'];
  245. //display this element
  246. if( is_array( $args[0] ) ) {
  247. $args[0]['has_children'] = !empty( $children_elements[$element->$id_field] );
  248. }
  249. else {
  250. if( is_object( $args[0] ) ) {
  251. $args[0]->has_children = !empty( $children_elements[$element->$id_field] );
  252. }
  253. }
  254. $cb_args = array_merge( array( &$output, $element, $depth ), $args );
  255. call_user_func_array( array( &$this, 'start_el' ), $cb_args );
  256. $id = $element->$id_field;
  257. // descend only when the depth is right and there are childrens for this element
  258. if( ( $max_depth == 0 || $max_depth > $depth + 1 ) && isset( $children_elements[$id] ) ) {
  259. foreach( $children_elements[$id] as $child ) {
  260. if( !isset( $newlevel ) ) {
  261. $newlevel = true;
  262. //start the child delimiter
  263. $cb_args = array_merge( array( &$output, $depth ), $args );
  264. call_user_func_array( array( &$this, 'start_lvl' ), $cb_args );
  265. }
  266. $this->display_element( $child, $children_elements, $max_depth, $depth + 1, $args, $output );
  267. }
  268. unset( $children_elements[$id] );
  269. }
  270. if( isset( $newlevel ) && $newlevel ) {
  271. //end the child delimiter
  272. $cb_args = array_merge( array( &$output, $depth ), $args );
  273. call_user_func_array( array( &$this, 'end_lvl' ), $cb_args );
  274. }
  275. //end this element
  276. $cb_args = array_merge( array( &$output, $element, $depth ), $args );
  277. call_user_func_array( array( &$this, 'end_el' ), $cb_args );
  278. }
  279. }
  280. class Cyberchimps_Fallback_Walker extends Walker_Page {
  281. function start_lvl( &$output, $depth = 0, $args = array() ) {
  282. if( $depth == 0 ) {
  283. $indent = str_repeat( "\t", $depth );
  284. $output .= "\n$indent<ul class=\"dropdown-menu\">\n";
  285. }
  286. else {
  287. $indent = str_repeat( "\t", $depth );
  288. $output .= "\n$indent<ul>\n";
  289. }
  290. }
  291. function start_el( &$output, $page, $depth = 0, $args = array(), $current_page = 0 ) {
  292. if( $depth ) {
  293. $indent = str_repeat( "\t", $depth );
  294. }
  295. else {
  296. $indent = '';
  297. }
  298. extract( $args, EXTR_SKIP );
  299. $class_attr = '';
  300. $data = '';
  301. $link_class_attr = '';
  302. $caret = '';
  303. if( $depth == 0 && !empty( $args['has_children'] ) ) {
  304. $class_attr .= 'dropdown ';
  305. $data = 'data-dropdown="dropdown"';
  306. $link_class_attr = 'dropdown-toggle';
  307. $caret = '<b class="caret"></b>';
  308. }
  309. if( !empty( $current_page ) ) {
  310. $_current_page = get_page( $current_page );
  311. if( ( isset( $_current_page->ancestors ) && in_array( $page->ID, (array)$_current_page->ancestors ) ) || ( $page->ID == $current_page ) || ( $_current_page && $page->ID == $_current_page->post_parent ) ) {
  312. $class_attr .= 'current-menu-item current_page_item active';
  313. }
  314. }
  315. elseif( ( is_single() || is_archive() ) && ( $page->ID == get_option( 'page_for_posts' ) ) ) {
  316. $class_attr = '';
  317. }
  318. if( $class_attr != '' ) {
  319. $class_attr = ' class="' . $class_attr . '"';
  320. }
  321. $output .= $indent . '<li' . $class_attr . $data . '><a href="' . get_page_link( $page->ID ) . '"' . $link_class_attr . '>' . apply_filters( 'the_title', $page->post_title, $page->ID ) . $caret . '</a>';
  322. }
  323. }
  324. // Sets fallback menu for 1 level. Could use preg_split to have children displayed too
  325. function cyberchimps_fallback_menu() {
  326. $walker = new cyberchimps_fallback_walker();
  327. $args = array(
  328. 'depth' => 0,
  329. 'show_date' => '',
  330. 'date_format' => '',
  331. 'child_of' => 0,
  332. 'exclude' => '',
  333. 'include' => '',
  334. 'title_li' => '',
  335. 'echo' => 0,
  336. 'authors' => '',
  337. 'sort_column' => 'menu_order, post_title',
  338. 'link_before' => '',
  339. 'link_after' => '',
  340. 'walker' => $walker,
  341. 'post_type' => 'page',
  342. 'post_status' => 'publish'
  343. );
  344. $pages = wp_list_pages( $args );
  345. $prepend = '<ul id="menu-menu" class="nav">';
  346. $pages = apply_filters( 'cyberchimps_fallback_menu_filter', $pages, $args );
  347. $append = '</ul>';
  348. $output = $prepend . $pages . $append;
  349. echo $output;
  350. }
  351. //Prints HTML with meta information for the current post date/time.
  352. if( !function_exists( 'cyberchimps_posted_on' ) ) {
  353. function cyberchimps_posted_on() {
  354. // Get value of post byline date toggle option from theme option for different pages
  355. if( is_single() ) {
  356. $show_date = ( cyberchimps_get_option( 'single_post_byline_date', 1 ) ) ? cyberchimps_get_option( 'single_post_byline_date', 1 ) : false;
  357. }
  358. elseif( is_archive() ) {
  359. $show_date = ( cyberchimps_get_option( 'archive_post_byline_date', 1 ) ) ? cyberchimps_get_option( 'archive_post_byline_date', 1 ) : false;
  360. }
  361. else {
  362. $show_date = ( cyberchimps_get_option( 'post_byline_date', 1 ) ) ? cyberchimps_get_option( 'post_byline_date', 1 ) : false;
  363. }
  364. // Get all data related to date.
  365. $date_url = esc_url( get_permalink() );
  366. $date_title = esc_attr( get_the_time() );
  367. $date_time = esc_attr( get_the_time() );
  368. $date_time = esc_attr( get_the_date( 'c' ) );
  369. $date = esc_html( get_the_date() );
  370. // Set the HTML for date link.
  371. $posted_on = sprintf(
  372. __( 'Posted on %s', 'cyberchimps_core' ),
  373. '<a href="' . $date_url . '" title="' . $date_title . '" rel="bookmark">
  374. <time class="entry-date updated" datetime="' . $date_time . '">' . $date . '</time>
  375. </a>'
  376. );
  377. // If post byline date toggle is on then print HTML for date link.
  378. if( $show_date ) {
  379. apply_filters( 'cyberchimps_posted_on', $posted_on );
  380. echo $posted_on;
  381. }
  382. }
  383. }
  384. // Prints HTML for author link of the post.
  385. if( !function_exists( 'cyberchimps_posted_by' ) ) {
  386. function cyberchimps_posted_by() {
  387. // Get value of post byline author toggle option from theme option for different pages.
  388. if( is_single() ) {
  389. $show_author = ( cyberchimps_get_option( 'single_post_byline_author', 1 ) ) ? cyberchimps_get_option( 'single_post_byline_author', 1 ) : false;
  390. }
  391. elseif( is_archive() ) {
  392. $show_author = ( cyberchimps_get_option( 'archive_post_byline_author', 1 ) ) ? cyberchimps_get_option( 'archive_post_byline_author', 1 ) : false;
  393. }
  394. else {
  395. $show_author = ( cyberchimps_get_option( 'post_byline_author', 1 ) ) ? cyberchimps_get_option( 'post_byline_author', 1 ) : false;
  396. }
  397. // Get url of all author archive( the page will contain all posts by the author).
  398. $auther_posts_url = esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) );
  399. // Set author title text which will appear on hover over the author link.
  400. $auther_link_title = esc_attr( sprintf( __( 'View all posts by %s', 'cyberchimps_core' ), get_the_author() ) );
  401. // Set the HTML for author link.
  402. $posted_by = sprintf(
  403. '<span class="byline"> ' . __( 'by %s', 'cyberchimps_core' ),
  404. '<span class="author vcard">
  405. <a class="url fn n" href="' . $auther_posts_url . '" title="' . $auther_link_title . '" rel="author">' . esc_html( get_the_author() ) . '</a>
  406. </span>
  407. </span>'
  408. );
  409. // If post byline author toggle is on then print HTML for author link.
  410. if( $show_author ) {
  411. apply_filters( 'cyberchimps_posted_by', $posted_by );
  412. echo $posted_by;
  413. }
  414. }
  415. }
  416. if( !function_exists( 'cyberchimps_posted_in' ) ) {
  417. //add meta entry category to single post, archive and blog list if set in options
  418. function cyberchimps_posted_in() {
  419. global $post;
  420. if( is_single() ) {
  421. $show = ( cyberchimps_get_option( 'single_post_byline_categories', 1 ) ) ? cyberchimps_get_option( 'single_post_byline_categories', 1 ) : false;
  422. }
  423. elseif( is_archive() ) {
  424. $show = ( cyberchimps_get_option( 'archive_post_byline_categories', 1 ) ) ? cyberchimps_get_option( 'archive_post_byline_categories', 1 ) : false;
  425. }
  426. else {
  427. $show = ( cyberchimps_get_option( 'post_byline_categories', 1 ) ) ? cyberchimps_get_option( 'post_byline_categories', 1 ) : false;
  428. }
  429. if( $show ):
  430. $categories_list = get_the_category_list( ', ' );
  431. if( $categories_list ) :
  432. $cats = sprintf( __( 'Posted in %s', 'cyberchimps_core' ), $categories_list );
  433. ?>
  434. <span class="cat-links">
  435. <?php echo apply_filters( 'cyberchimps_post_categories', $cats ); ?>
  436. </span>
  437. <span class="sep"> <?php echo apply_filters( 'cyberchimps_entry_meta_sep', '|' ); ?> </span>
  438. <?php endif;
  439. endif;
  440. }
  441. }
  442. if( !function_exists( 'cyberchimps_post_tags' ) ) {
  443. //add meta entry tags to single post, archive and blog list if set in options
  444. function cyberchimps_post_tags() {
  445. global $post;
  446. if( is_single() ) {
  447. $show = ( cyberchimps_get_option( 'single_post_byline_tags', 1 ) ) ? cyberchimps_get_option( 'single_post_byline_tags', 1 ) : false;
  448. }
  449. elseif( is_archive() ) {
  450. $show = ( cyberchimps_get_option( 'archive_post_byline_tags', 1 ) ) ? cyberchimps_get_option( 'archive_post_byline_tags', 1 ) : false;
  451. }
  452. else {
  453. $show = ( cyberchimps_get_option( 'post_byline_tags', 1 ) ) ? cyberchimps_get_option( 'post_byline_tags', 1 ) : false;
  454. }
  455. if( $show ):
  456. $tags_list = get_the_tag_list( '', ', ' );
  457. if( $tags_list ) :
  458. $tags = sprintf( __( 'Tags: %s', 'cyberchimps_core' ), $tags_list );
  459. ?>
  460. <span class="taglinks">
  461. <?php echo apply_filters( 'cyberchimps_post_tags', $tags ); ?>
  462. </span>
  463. <span class="sep"> <?php echo apply_filters( 'cyberchimps_entry_meta_sep', '|' ); ?> </span>
  464. <?php endif; // End if $tags_list
  465. endif;
  466. }
  467. }
  468. if( !function_exists( 'cyberchimps_post_comments' ) ) {
  469. //add meta entry comments to single post, archive and blog list if set in options
  470. function cyberchimps_post_comments() {
  471. global $post;
  472. if( is_single() ) {
  473. $show = ( cyberchimps_get_option( 'single_post_byline_comments', 1 ) ) ? cyberchimps_get_option( 'single_post_byline_comments', 1 ) : false;
  474. }
  475. elseif( is_archive() ) {
  476. $show = ( cyberchimps_get_option( 'archive_post_byline_comments', 1 ) ) ? cyberchimps_get_option( 'archive_post_byline_comments', 1 ) : false;
  477. }
  478. else {
  479. $show = ( cyberchimps_get_option( 'post_byline_comments', 1 ) ) ? cyberchimps_get_option( 'post_byline_comments', 1 ) : false;
  480. }
  481. $leave_comment = ( is_single() || is_page() ) ? '' : __( 'Leave a comment', 'cyberchimps_core' );
  482. if( $show ):
  483. if( !post_password_required() && ( comments_open() || '0' != get_comments_number() ) ) : ?>
  484. <span class="comments-link"><?php comments_popup_link( $leave_comment, __( '1 Comment', 'cyberchimps_core' ), '% ' . __( 'Comments', 'cyberchimps_core' ) ); ?></span>
  485. <span class="sep"> <?php echo ( $leave_comment != '' ) ? apply_filters( 'cyberchimps_entry_meta_sep', '|' ) : ''; ?> </span>
  486. <?php endif;
  487. endif;
  488. }
  489. }
  490. // change default comments labels and form
  491. add_filter( 'comment_form_defaults', 'cyberchimps_comment_form_filter' );
  492. function cyberchimps_comment_form_filter( $defaults ) {
  493. $defaults['title_reply'] = __( 'Leave a comment', 'cyberchimps_core' );
  494. return $defaults;
  495. }
  496. // add featured image to single post, archive and blog page if set in options
  497. function cyberchimps_featured_image() {
  498. global $post;
  499. if( is_single() ) {
  500. $show = ( cyberchimps_get_option( 'single_post_featured_images', 1 ) ) ? cyberchimps_get_option( 'single_post_featured_images', 1 ) : false;
  501. }
  502. elseif( is_archive() ) {
  503. $show = ( cyberchimps_get_option( 'archive_featured_images', 1 ) ) ? cyberchimps_get_option( 'archive_featured_images', 1 ) : false;
  504. }
  505. else {
  506. $show = ( cyberchimps_get_option( 'post_featured_images', 1 ) ) ? cyberchimps_get_option( 'post_featured_images', 1 ) : false;
  507. }
  508. if( $show ):
  509. if( has_post_thumbnail() ): ?>
  510. <div class="featured-image">
  511. <a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( 'Permalink to %s', 'cyberchimps_core' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark">
  512. <?php the_post_thumbnail( apply_filters( 'cyberchimps_post_thumbnail_size', 'thumbnail' ) ); ?>
  513. </a>
  514. </div>
  515. <?php endif;
  516. endif;
  517. }
  518. function cyberchimps_post_format_icon() {
  519. global $post;
  520. $format = get_post_format( $post->ID );
  521. if( $format == '' ) {
  522. $format = 'default';
  523. }
  524. if( is_single() ) {
  525. $show = ( cyberchimps_get_option( 'single_post_format_icons', 1 ) ) ? cyberchimps_get_option( 'single_post_format_icons', 1 ) : false;
  526. }
  527. elseif( is_archive() ) {
  528. $show = ( cyberchimps_get_option( 'archive_format_icons', 1 ) ) ? cyberchimps_get_option( 'archive_format_icons', 1 ) : false;
  529. }
  530. else {
  531. $show = ( cyberchimps_get_option( 'post_format_icons', 1 ) ) ? cyberchimps_get_option( 'post_format_icons', 1 ) : false;
  532. }
  533. if( !is_page() && $show ):
  534. // array of post formats and the matching font icons
  535. $icons = array(
  536. 'aside' => '<span class="glyphicon glyphicon-list-alt"></span>',
  537. 'audio' => '<span class="glyphicon glyphicon-volume-up"></span>',
  538. 'chat' => '<span class="glyphicon glyphicon-comment"></span>',
  539. 'default' => '<span class="glyphicon glyphicon-file"></span>',
  540. 'gallery' => '<span class="glyphicon glyphicon-film"></span>',
  541. 'image' => '<span class="glyphicon glyphicon-picture"></span>',
  542. 'link' => '<span class="glyphicon glyphicon-link"></span>',
  543. 'quote' => '<span class="glyphicon glyphicon-share"></span>',
  544. 'status' => '<span class="glyphicon glyphicon-th"></span>',
  545. 'video' => '<span class="glyphicon glyphicon-facetime-video"></span>'
  546. );
  547. ?>
  548. <div class="postformats"><!--begin format icon-->
  549. <?php echo $icons[$format]; ?>
  550. </div><!--end format-icon-->
  551. <?php
  552. endif;
  553. }
  554. // Returns true if a blog has more than 1 category
  555. function cyberchimps_categorized_blog() {
  556. if( false === ( $cyberchimps_categorized_transient = get_transient( 'cyberchimps_categorized_transient' ) ) ) {
  557. // Create an array of all the categories that are attached to posts
  558. $cyberchimps_categorized_transient = get_categories( array(
  559. 'hide_empty' => 1,
  560. ) );
  561. // Count the number of categories that are attached to the posts
  562. $cyberchimps_categorized_transient = count( $cyberchimps_categorized_transient );
  563. set_transient( 'cyberchimps_categorized_transient', $cyberchimps_categorized_transient );
  564. }
  565. if( '1' != $cyberchimps_categorized_transient ) {
  566. // This blog has more than 1 category so cyberchimps_categorized_blog should return true
  567. return true;
  568. }
  569. else {
  570. // This blog has only 1 category so cyberchimps_categorized_blog should return false
  571. return false;
  572. }
  573. }
  574. // Flush out the transients used in cyberchimps_categorized_blog
  575. function cyberchimps_category_transient_flusher() {
  576. // Remove transient
  577. delete_transient( 'cyberchimps_categorized_transient' );
  578. }
  579. add_action( 'edit_category', 'cyberchimps_category_transient_flusher' );
  580. add_action( 'save_post', 'cyberchimps_category_transient_flusher' );
  581. // Prints out default title of the site.
  582. function cyberchimps_default_site_title() {
  583. global $page, $paged;
  584. // Add the blog name.
  585. if( !is_feed() ) {
  586. bloginfo( 'name' );
  587. }
  588. //Title for page/post
  589. if( is_page() || is_single() ) {
  590. echo ' | ' . get_the_title();
  591. }
  592. //Title for archives
  593. if( is_archive() ) {
  594. echo ' | ';
  595. if( is_category() ) {
  596. printf( __( 'Category Archives: %s', 'cyberchimps_core' ), single_cat_title( '', false ) );
  597. }
  598. elseif( is_tag() ) {
  599. printf( __( 'Tag Archives: %s', 'cyberchimps_core' ) , single_tag_title( '', false ) );
  600. }
  601. elseif( is_author() ) {
  602. _e( 'Author Archives', 'cyberchimps_core' );
  603. }
  604. elseif( is_day() ) {
  605. printf( __( 'Daily Archives: %s', 'cyberchimps_core' ), get_the_date() );
  606. }
  607. elseif( is_month() ) {
  608. printf( __( 'Monthly Archives: %s', 'cyberchimps_core' ), get_the_date( 'F Y' ) );
  609. }
  610. elseif( is_year() ) {
  611. printf( __( 'Yearly Archives: %s', 'cyberchimps_core' ), get_the_date( 'Y' ) );
  612. }
  613. elseif( is_plugin_active( 'woocommerce/woocommerce.php' ) && is_woocommerce() && is_shop() ) {
  614. _e( 'Shop', 'cyberchimps_core_scripts' );
  615. }
  616. else {
  617. _e( 'Archives', 'cyberchimps_core' );
  618. }
  619. }
  620. //Title for search
  621. if( is_search() ) {
  622. echo ' | ' . sprintf( __( 'Search for &quot; %s &quot;', 'cyberchimps_core' ), get_search_query() );
  623. }
  624. //Title for 404
  625. if( is_404() ) {
  626. echo ' | ' . __( 'Not Found', 'cyberchimps_core' ) . ' ';
  627. }
  628. // Add the blog description for the home/front page.
  629. $site_description = get_bloginfo( 'description', 'display' );
  630. if( $site_description && ( is_home() || is_front_page() ) ) {
  631. echo ' | ' . $site_description;
  632. }
  633. // Add a page number if necessary:
  634. if( $paged >= 2 || $page >= 2 ) {
  635. echo ' | ' . sprintf( __( 'Page %s', 'cyberchimps_core' ), max( $paged, $page ) );
  636. }
  637. }
  638. add_filter( 'wp_title', 'cyberchimps_default_site_title' );
  639. // Remove default site title if seo plugin is active
  640. function cyberchimps_seo_compatibility_check() {
  641. if( cyberchimps_detect_seo_plugins() ) {
  642. remove_filter( 'wp_title', 'cyberchimps_default_site_title', 10, 3 );
  643. }
  644. }
  645. add_action( 'after_setup_theme', 'cyberchimps_seo_compatibility_check', 5 );
  646. // Add thumbnail size
  647. function cyberchimps_add_thumbnail_size() {
  648. add_image_size( 'featured-thumb', 100, 80, true );
  649. add_image_size( 'headline-thumb', 200, 225, true );
  650. }
  651. add_action( 'after_setup_theme', 'cyberchimps_add_thumbnail_size', 5 );
  652. // Detect some SEO Plugin that add constants, classes or functions.
  653. function cyberchimps_detect_seo_plugins() {
  654. return cyberchimps_detect_plugin(
  655. // Use this filter to adjust plugin tests.
  656. apply_filters(
  657. 'cyberchimps_detect_seo_plugins',
  658. /** Add to this array to add new plugin checks. */
  659. array(
  660. // Classes to detect.
  661. 'classes' => array(
  662. 'wpSEO',
  663. 'All_in_One_SEO_Pack',
  664. 'HeadSpace_Plugin',
  665. 'Platinum_SEO_Pack',
  666. ),
  667. // Functions to detect.
  668. 'functions' => array(),
  669. // Constants to detect.
  670. 'constants' => array( 'WPSEO_VERSION', ),
  671. )
  672. )
  673. );
  674. }
  675. // Detect event plugins
  676. function cyberchimps_detect_event_plugins() {
  677. return cyberchimps_detect_plugin(
  678. // Use this filter to adjust plugin tests.
  679. apply_filters(
  680. 'cyberchimps_detect_event_plugins',
  681. /** Add to this array to add new plugin checks. */
  682. array(
  683. // Classes to detect.
  684. 'classes' => array( 'TribeEvents' ),
  685. // Functions to detect.
  686. 'functions' => array(),
  687. // Constants to detect.
  688. 'constants' => array(),
  689. )
  690. )
  691. );
  692. }
  693. // Detect plugin by constant, class or function existence.
  694. function cyberchimps_detect_plugin( $plugins ) {
  695. /** Check for classes */
  696. if( isset( $plugins['classes'] ) ) {
  697. foreach( $plugins['classes'] as $name ) {
  698. if( class_exists( $name ) ) {
  699. return true;
  700. }
  701. }
  702. }
  703. /** Check for functions */
  704. if( isset( $plugins['functions'] ) ) {
  705. foreach( $plugins['functions'] as $name ) {
  706. if( function_exists( $name ) ) {
  707. return true;
  708. }
  709. }
  710. }
  711. /** Check for constants */
  712. if( isset( $plugins['constants'] ) ) {
  713. foreach( $plugins['constants'] as $name ) {
  714. if( defined( $name ) ) {
  715. return true;
  716. }
  717. }
  718. }
  719. /** No class, function or constant found to exist */
  720. return false;
  721. }
  722. // Set read more link for recent post element
  723. function cyberchimps_recent_post_excerpt_more( $more ) {
  724. global $custom_excerpt, $post;
  725. return '&hellip;
  726. </p>
  727. <div class="more-link">
  728. <a href="' . get_permalink( $post->ID ) . '">' . cyberchimps_blog_read_more_text() . '</a>
  729. </div>';
  730. }
  731. // Set read more link for featured post element
  732. function cyberchimps_featured_post_excerpt_more( $more ) {
  733. global $post;
  734. return '&hellip;</p></span><a class="excerpt-more featured-post-excerpt" href="' . get_permalink( $post->ID ) . '">' . cyberchimps_blog_read_more_text() . '</a>';
  735. }
  736. // Set length of the excerpt
  737. function cyberchimps_featured_post_length( $length ) {
  738. return 70;
  739. }
  740. // Set read more link for magazine featured post element
  741. function cyberchimps_magazine_featured_post_excerpt_more( $more ) {
  742. global $post;
  743. return '&hellip;</p></span><a class="excerpt-more magazine-featured-post-excerpt" href="' . get_permalink( $post->ID ) . '">' . cyberchimps_blog_read_more_text() . '</a>';
  744. }
  745. // Set length of the magazine featured post excerpt
  746. function cyberchimps_magazine_featured_post_length( $length ) {
  747. $new_length = cyberchimps_get_option( 'blog_magazine_excerpt_length', 70 );
  748. return $new_length;
  749. }
  750. // For magazine wide post
  751. function cyberchimps_magazine_post_wide( $length ) {
  752. $new_length = cyberchimps_get_option( 'blog_magazine_wide_excerpt_length', 130 );
  753. return $new_length;
  754. }
  755. // more text for search results excerpt
  756. function cyberchimps_search_excerpt_more( $more ) {
  757. global $post;
  758. if( cyberchimps_get_option( 'search_post_read_more' ) != '' ) {
  759. $more = '<p><a href="' . get_permalink( $post->ID ) . '">' . cyberchimps_get_option( 'search_post_read_more' ) . '</a></p>';
  760. return $more;
  761. }
  762. else {
  763. $more = '<p><a class="excerpt-more search-excerpt" href="' . get_permalink( $post->ID ) . '">' . __( 'Read More...', 'cyberchimps_core' ) . '</a></p>';
  764. return $more;
  765. }
  766. }
  767. // excerpt length for search results
  768. function cyberchimps_search_excerpt_length( $length ) {
  769. global $post;
  770. if( cyberchimps_get_option( 'search_post_excerpt_length' ) != '' ) {
  771. $length = cyberchimps_get_option( 'search_post_excerpt_length' );
  772. return $length;
  773. }
  774. else {
  775. $length = 55;
  776. return $length;
  777. }
  778. }
  779. //For archive posts
  780. function cyberchimps_archive_excerpt_more( $more ) {
  781. global $post;
  782. return '<p><a class="excerpt-more archive-excerpt" href="' . get_permalink( $post->ID ) . '">' . cyberchimps_blog_read_more_text() . '</a></p>';
  783. }
  784. if( cyberchimps_get_option( 'archive_post_excerpts', 0 ) != 0 ) {
  785. add_filter( 'excerpt_more', 'cyberchimps_blog_excerpt_more', 999 );
  786. }
  787. // Set value for blog read more text option.
  788. function cyberchimps_blog_read_more_text() {
  789. // Get the value of blog read more text option.
  790. $read_more = cyberchimps_get_option( 'blog_read_more_text' );
  791. // Check whether any not null value supplied and set the value accordingly.
  792. if( '' != $read_more ) {
  793. return $read_more;
  794. }
  795. else {
  796. return __( 'Read More...', 'cyberchimps_core' );
  797. }
  798. }
  799. //For blog posts
  800. function cyberchimps_blog_excerpt_more( $more ) {
  801. global $post;
  802. return '<p><a class="excerpt-more blog-excerpt" href="' . get_permalink( $post->ID ) . '">' . cyberchimps_blog_read_more_text() . '</a></p>';
  803. }
  804. if( cyberchimps_get_option( 'post_excerpts', 0 ) != 0 ) {
  805. add_filter( 'excerpt_more', 'cyberchimps_blog_excerpt_more', 10 );
  806. }
  807. /**
  808. * Set custom post excerpt link if excerpt is supplied manually.
  809. */
  810. function manual_excerpt_read_more_link( $output ) {
  811. global $post;
  812. $linktext = cyberchimps_blog_read_more_text();
  813. if( !empty( $post->post_excerpt ) ) {
  814. return $output . '<p><a class="excerpt-more" href="' . get_permalink( $post->ID ) . '">' . $linktext . '</a></p>';
  815. }
  816. else {
  817. return $output;
  818. }
  819. }
  820. add_filter( 'the_excerpt', 'manual_excerpt_read_more_link' );
  821. function cyberchimps_blog_excerpt_length( $length ) {
  822. global $post;
  823. if( cyberchimps_get_option( 'blog_excerpt_length' ) != '' ) {
  824. $length = cyberchimps_get_option( 'blog_excerpt_length' );
  825. return $length;
  826. }
  827. else {
  828. $length = 55;
  829. return $length;
  830. }
  831. }
  832. if( cyberchimps_get_option( 'post_excerpts', 0 ) != 0 ) {
  833. add_filter( 'excerpt_length', 'cyberchimps_blog_excerpt_length', 999 );
  834. }
  835. /* gets post views */
  836. function cyberchimps_getPostViews( $postID ) {
  837. $count_key = 'post_views_count';
  838. $count = get_post_meta( $postID, $count_key, true );
  839. if( $count == '' ) {
  840. delete_post_meta( $postID, $count_key );
  841. add_post_meta( $postID, $count_key, '0' );
  842. return "0 View";
  843. }
  844. return $count . ' Views';
  845. }
  846. /* Sets post views */
  847. function cyberchimps_setPostViews( $postID ) {
  848. $count_key = 'post_views_count';
  849. $count = get_post_meta( $postID, $count_key, true );
  850. if( $count == '' ) {
  851. $count = 0;
  852. delete_post_meta( $postID, $count_key );
  853. add_post_meta( $postID, $count_key, '0' );
  854. }
  855. else {
  856. $count++;
  857. update_post_meta( $postID, $count_key, $count );
  858. }
  859. }
  860. /* To correct issue: adjacent_posts_rel_link_wp_head causes meta to be updated multiple times */
  861. remove_action( 'wp_head', 'adjacent_posts_rel_link_wp_head', 10, 0 );
  862. // Set up half slide for iFeature pro slider, adds it before post/page content
  863. function cyberchimps_half_slider() {
  864. global $post;
  865. if( is_page() ) {
  866. $page_section_order = get_post_meta( $post->ID, 'cyberchimps_page_section_order', true );
  867. //if page_section_order is empty sets page as default
  868. $page_section_order = ( $page_section_order == '' ) ? array( 'page_section' ) : $page_section_order;
  869. if( in_array( 'page_slider', $page_section_order, true ) ) {
  870. $slider_size = get_post_meta( $post->ID, 'cyberchimps_slider_size', true );
  871. if( $slider_size == 'half' ) {
  872. do_action( 'page_slider' );
  873. }
  874. }
  875. }
  876. else {
  877. $blog_section_order = cyberchimps_get_option( 'blog_section_order' );
  878. //select default in case options are empty
  879. $blog_section_order = ( $blog_section_order == '' ) ? array( 'blog_post_page' ) : $blog_section_order;
  880. if( in_array( 'page_slider', $blog_section_order, true ) ) {
  881. $slider_size = cyberchimps_get_option( 'blog_slider_size' );
  882. if( $slider_size == 'half' ) {
  883. do_action( 'page_slider' );
  884. }
  885. }
  886. }
  887. }
  888. // Hook action to after/before content hook depending upon slider order.
  889. function cyberchimps_add_half_slider_action( $slider_order ) {
  890. add_action( 'cyberchimps_' . $slider_order . '_content', 'cyberchimps_half_slider' );
  891. }
  892. // Help text
  893. function cyberchimps_options_help_text() {
  894. $text = '';
  895. $instruction_img = get_template_directory_uri() . '/cyberchimps/options/lib/images/document.png';
  896. $support_img = get_template_directory_uri() . '/cyberchimps/options/lib/images/questionsupport.png';
  897. $text .= '<div class="cc_help_section">
  898. <div class="row-fluid"><div class="span3">
  899. <a href="' . apply_filters( 'cyberchimps_documentation', 'http://cyberchimps.com' ) . '" title="CyberChimps Instructions">
  900. <img src="' . $instruction_img . '" alt="CyberChimps Instructions" />
  901. <div class="cc_help_caption"><p>' . __( 'Instructions', 'cyberchimps_core' ) . '</p></div>
  902. </a>
  903. </div>
  904. <div class="span3">
  905. <a href="' . apply_filters( 'cyberchimps_support_forum', 'http://cyberchimps.com' ) . '" title="CyberChimps Support">
  906. <img src="' . $support_img . '" alt="CyberChimps Help" />
  907. <div class="cc_help_caption"><p>' . __( 'Support', 'cyberchimps_core' ) . '</p></div>
  908. </a>
  909. </div>
  910. </div>';
  911. // Upgrade Button and text for free themes
  912. if( cyberchimps_theme_check() == 'free' ) {
  913. $upgrade_link = apply_filters( 'cyberchimps_upgrade_link', 'http://cyberchimps.com' );
  914. $pro_title = apply_filters( 'cyberchimps_upgrade_pro_title', 'CyberChimps Pro' );
  915. $text .= '<div class="row-fluid">
  916. <div class="span6">
  917. <a href="' . $upgrade_link . '" title="' . $pro_title . '">
  918. <div class="cc_help_upgrade_bar">' . sprintf( __( 'Upgrade to %1$s', 'cyberchimps_core' ), $pro_title ) . '</div>
  919. </a>
  920. </div>
  921. </div>
  922. </div>
  923. <div class="clear"></div>';
  924. $text .= sprintf(
  925. '<p>' . __( 'For even more amazing new features, upgrade to %1$s which includes a slider with customizable features, an image carousel, widgetized boxes, a callout section, expanded typography (including Google Fonts), additional color skins, and many more powerful new features. Visit %2$s to learn more!', 'cyberchimps_core' ) . '</p>',
  926. '<a href="' . $upgrade_link . ' title="' . $pro_title . '">' . $pro_title . '</a>',
  927. '<a href="cyberchimps.com" title="CyberChimps">CyberChimps.com</a>'
  928. );
  929. }
  930. //text for pro themes
  931. else {
  932. $text .= '</div><div class="clear"></div>';
  933. }
  934. return $text;
  935. }
  936. add_filter( 'cyberchimps_help_description', 'cyberchimps_options_help_text' );
  937. // upgrade bar for free themes
  938. function cyberchimps_upgrade_bar() {
  939. $current_theme_name = apply_filters( 'cyberchimps_current_theme_name', 'CyberChimps' );
  940. $upgrade_link = apply_filters( 'cyberchimps_upgrade_link', 'http://cyberchimps.com' );
  941. $pro_title = apply_filters( 'cyberchimps_upgrade_pro_title', 'CyberChimps Pro' );
  942. ?>
  943. <div class="upgrade-callout">
  944. <p><img src="<?php echo get_template_directory_uri(); ?>/cyberchimps/options/lib/images/chimp.png" alt="CyberChimps"/>
  945. <?php printf(
  946. __( 'Welcome to %1$s! Learn more now about upgrading to %2$s today.', 'cyberchimps_core' ),
  947. $current_theme_name,
  948. '<a href="' . $upgrade_link . '" target="_blank" title="' . $pro_title . '">' . $pro_title . '</a> '
  949. ); ?>
  950. </p>
  951. <div class="social-container">
  952. <div class="social">
  953. <a href="https://twitter.com/cyberchimps" class="twitter-follow-button" data-show-count="false" data-size="small">Follow @cyberchimps</a>
  954. <script>!function (d, s, id) {
  955. var js, fjs = d.getElementsByTagName(s)[0];
  956. if (!d.getElementById(id)) {
  957. js = d.createElement(s);
  958. js.id = id;
  959. js.src = "//platform.twitter.com/widgets.js";
  960. fjs.parentNode.insertBefore(js, fjs);
  961. }
  962. }(document, "script", "twitter-wjs");</script>
  963. </div>
  964. <div class="social">
  965. <iframe
  966. src="//www.facebook.com/plugins/like.php?href=http%3A%2F%2Fcyberchimps.com%2F&amp;send=false&amp;layout=button_count&amp;width=200&amp;show_faces=false&amp;action=like&amp;colorscheme=light&amp;font&amp;height=21"
  967. scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:200px; height:21px;" allowTransparency="true"></iframe>
  968. </div>
  969. </div>
  970. </div>
  971. <?php
  972. }
  973. if( cyberchimps_theme_check() == 'free' ) {
  974. add_action( 'cyberchimps_options_before_container', 'cyberchimps_upgrade_bar' );
  975. }
  976. // Hide preview and view on custom post types
  977. function cyberchimps_posttype_admin_css() {
  978. global $post_type;
  979. if( $post_type == 'custom_slides' || $post_type == 'boxes' || $post_type == 'featured_posts' || $post_type == 'portfolio_images' ) {
  980. echo '<style type="text/css">#view-post-btn,#post-preview{display: none;}</style>';
  981. }
  982. }
  983. add_action( 'admin_head', 'cyberchimps_posttype_admin_css' );
  984. /**
  985. * Add link to theme options in Admin bar.
  986. */
  987. function cyberchimps_admin_link() {
  988. global $wp_admin_bar;
  989. $wp_admin_bar->add_menu( array(
  990. 'id' => 'cyberchimps',
  991. 'title' => apply_filters( 'cyberchimps_current_theme_name', 'CyberChimps ' . __( 'Options', 'cyberchimps_core' ) ) . __( 'Options', 'cyberchimps_core' ),
  992. 'href' => admin_url( 'themes.php?page=cyberchimps-theme-options' )
  993. ) );
  994. }
  995. // Include link to theme option in the admin header bar in pro theme only, as it is ruled out in free themes by WPORG.
  996. if( 'free' != cyberchimps_theme_check() ) {
  997. add_action( 'admin_bar_menu', 'cyberchimps_admin_link', 113 );
  998. }
  999. function cyberchimps_google_analytics() {
  1000. $code = cyberchimps_get_option( 'google_analytics', '' );
  1001. if( $code != '' ) {
  1002. echo '<script type="text/javascript">' . $code . '</script>';
  1003. }
  1004. }
  1005. if( 'pro' == cyberchimps_theme_check() ) {
  1006. add_action( 'wp_head', 'cyberchimps_google_analytics', 9999 );
  1007. }
  1008. // Add an array to an existing array in a certain position, used by options
  1009. function cyberchimps_heading_filter( $orig, $new ) {
  1010. foreach( $new as $key => $value ) {
  1011. array_splice( $orig, $key, 0, $value );
  1012. }
  1013. return $orig;
  1014. }
  1015. // the following 2 functions help retrieve the starting key number of the whole array of sections. There by allowing you to select the position of the custom section within that heading. 2 array's are passed to cyberchimps_array_section_organizer(). The initial array and the array of new sections. The array of new sections should have the format: $new_section[][10] = array( field-data ). 10 being the position within that heading.
  1016. //this function finds the initial key number where the heading name exists in the original array. If it does not yet exist then this must be a new heading and it returns the last key number of the array.
  1017. function cyberchimps_section_start_no( $heading, $orig ) {
  1018. foreach( $orig as $key => $value ) {
  1019. if( $value['heading'] == $heading ) {
  1020. $first_key_value = $key;
  1021. break;
  1022. }
  1023. else {
  1024. end( $orig );
  1025. $first_key_value = key( $orig ) + 1; //this counter acts the minus 1 from the organizer so the last element doesn't get built in front of
  1026. }
  1027. }
  1028. return $first_key_value;
  1029. }
  1030. //this function takes the new and old array and combines them adding the new array elements in the position indicated by their key
  1031. function cyberchimps_array_section_organizer( $orig, $new ) {
  1032. foreach( $new as $value ) {
  1033. foreach( $value as $key => $val ) {
  1034. $section_start_no = cyberchimps_section_start_no( $val['heading'], $orig );
  1035. $position = $section_start_no + ( $key - 1 );
  1036. $position = intval( $position );
  1037. array_splice( $orig, $position, 0, $value );
  1038. }
  1039. }
  1040. return $orig;
  1041. }
  1042. // the following 2 functions help retrieve the starting key number of the whole array of fields. There by allowing you to select the position of the custom field within that section. 2 array's are passed to cyberchimps_array_field_organizer(). The initial array and the array of new fields. The array of new fields should have the format: $new_field[][10] = array( field-data ). 10 being the position within that section.
  1043. //this function finds the initial key number wherethe section name exists in the original array. If it does not yet exist then this must be a new section and it returns the last key number of the array.
  1044. function cyberchimps_field_start_no( $section, $orig ) {
  1045. foreach( $orig as $key => $value ) {
  1046. if( $value['section'] == $section ) {
  1047. $first_key_value = $key;
  1048. break;
  1049. }
  1050. else {
  1051. end( $orig );
  1052. $first_key_value = key( $orig ) + 1;
  1053. }
  1054. }
  1055. return $first_key_value;
  1056. }
  1057. //this function takes the new and old array and combines them adding the new array elements in the position indicated by their key
  1058. function cyberchimps_array_field_organizer( $orig, $new ) {
  1059. foreach( $new as $value ) {
  1060. foreach( $value as $key => $val ) {
  1061. $section_start_no = cyberchimps_field_start_no( $val['section'], $orig );
  1062. $position = $section_start_no + ( $key - 1 );
  1063. $position = intval( $position );
  1064. array_splice( $orig, $position, 0, $value );
  1065. }
  1066. }
  1067. return $orig;
  1068. }
  1069. /**** Remove sections/fields from core theme options *****/
  1070. function cyberchimps_remove_options( $orig, $removes ) {
  1071. foreach( $removes as $remove ) {
  1072. foreach( $orig as $key => $value ) {
  1073. if( $value['id'] == $remove ) {
  1074. unset( $orig[$key] );
  1075. }
  1076. }
  1077. }
  1078. return $orig;
  1079. }
  1080. /* Container width fix for IE8 */
  1081. function cyberchimps_ie8_responsive() {
  1082. echo '<style type="text/css">.ie8 .container {max-width: ' . cyberchimps_get_option( 'max_width' ) . 'px;width:auto;}</style>';
  1083. }
  1084. add_action( 'wp_head', 'cyberchimps_ie8_responsive' );
  1085. /* Removing the unused page option from the woocommerce shop edit page */
  1086. function cyberchimps_woocommerce_shop_style() {
  1087. if( is_plugin_active( 'woocommerce/woocommerce.php' ) ) {
  1088. global $pagenow;
  1089. if( $pagenow == 'post.php' && $_GET['post'] == woocommerce_get_page_id( 'shop' ) ) {
  1090. echo '<style type="text/css">.cyberchimps_page_title_toggle, .cyberchimps_page_section_order{display:none}</style>';
  1091. }
  1092. }
  1093. }
  1094. add_action( 'admin_head', 'cyberchimps_woocommerce_shop_style' );
  1095. /**
  1096. * The Events Calendar Add On
  1097. */
  1098. // Add Ons Heading for Theme Options
  1099. function cyberchimps_addons_headings( $headings_list ) {
  1100. $headings_list[] = array(
  1101. 'id' => 'cyberchimps_addons_heading',
  1102. 'title' => __( 'Add Ons', 'cyberchimps_core' ),
  1103. );
  1104. return $headings_list;
  1105. }
  1106. add_filter( 'cyberchimps_headings_filter', 'cyberchimps_addons_headings', 20, 1 );
  1107. // Addon Section
  1108. function cyberchimps_addon_sections( $sections_list ) {
  1109. $sections_list[] = array(
  1110. 'id' => 'cyberchimps_eventcal_options',
  1111. 'label' => __( 'The Events Calendar', 'cyberchimps_core' ),
  1112. 'heading' => 'cyberchimps_addons_heading'
  1113. );
  1114. $sections_list[] = array(
  1115. 'id' => 'cyberchimps_digital_downloads_options',
  1116. 'label' => __( 'Digital Downloads', 'cyberchimps_core' ),
  1117. 'heading' => 'cyberchimps_addons_heading'
  1118. );
  1119. return $sections_list;
  1120. }
  1121. add_filter( 'cyberchimps_section_list', 'cyberchimps_addon_sections', 20, 1 );
  1122. // Addon Fields
  1123. function cyberchimps_addon_fields( $fields_list ) {
  1124. $fields_list[] = array(
  1125. 'name' => __( 'Events', 'cyberchimps_core' ),
  1126. 'id' => 'events_info',
  1127. 'type' => 'info',
  1128. 'callback' => 'cyberchimps_custom_events_callback',
  1129. 'section' => 'cyberchimps_eventcal_options',
  1130. 'heading' => 'cyberchimps_addons_heading'
  1131. );
  1132. $fields_list[] = array(
  1133. 'name' => __( 'Digital Downloads', 'cyberchimps' ),
  1134. 'id' => 'digital_downloads',
  1135. 'type' => 'info',
  1136. 'callback' => 'cyberchimps_digital_downloads_callback',
  1137. 'section' => 'cyberchimps_digital_downloads_options',
  1138. 'heading' => 'cyberchimps_addons_heading'
  1139. );
  1140. return $fields_list;
  1141. }
  1142. add_filter( 'cyberchimps_field_list', 'cyberchimps_addon_fields', 20, 1 );
  1143. // The Events Calendar Text
  1144. function cyberchimps_custom_events_callback( $value ) {
  1145. $output = '';
  1146. $plugin = 'the-events-calendar/the-events-calendar.php';
  1147. $icon = '<img class="plugins-icon" src="' . get_template_directory_uri() . '/cyberchimps/options/lib/images/addons/events.png" />';
  1148. $icon_neg = '<img class="plugins-icon" src="' . get_template_directory_uri() . '/cyberchimps/options/lib/images/addons/events-neg.png" />';
  1149. $installed_plugins = get_plugins();
  1150. if( isset( $installed_plugins[$plugin] ) ) {
  1151. if( is_plugin_active( $plugin ) ) {
  1152. $output .= $icon . '<a href="' . admin_url( 'edit.php?post_type=tribe_events&page=tribe-events-calendar' ) . '">' . __( 'Events Plugin Options', 'cyberchimps_core' ) . '</a>';
  1153. }
  1154. else {
  1155. $output .= $icon_neg . '<a href="' . admin_url( 'plugins.php' ) . '">' . __( 'Please activate The Events Calendar plugin', 'cyberchimps_core' ) . '</a>';
  1156. }
  1157. }
  1158. else {
  1159. $output .= $icon_neg . '<a href="' . cyberchimps_eventcal_install_link() . '">' . __( 'Install Events Calendar Plugin', 'cyberchimps_core' ) . '</a>';
  1160. }
  1161. echo $output;
  1162. }
  1163. // return a nonced installation link for the plugin.
  1164. function cyberchimps_eventcal_install_link() {
  1165. include_once ABSPATH . 'wp-admin/includes/plugin-install.php';
  1166. $slug = 'the-events-calendar';
  1167. return wp_nonce_url( self_admin_url( 'update.php?action=install-plugin&plugin=' . $slug ), 'install-plugin_' . $slug );
  1168. }
  1169. // Digital Downloads Text
  1170. function cyberchimps_digital_downloads_callback( $value ) {
  1171. $output = '';
  1172. $plugin = 'easy-digital-downloads/easy-digital-downloads.php';
  1173. $icon = '<img class="plugins-icon" src="' . get_template_directory_uri() . '/cyberchimps/options/lib/images/addons/easy.png" />';
  1174. $icon_neg = '<img class="plugins-icon" src="' . get_template_directory_uri() . '/cyberchimps/options/lib/images/addons/easy-neg.png" />';
  1175. $installed_plugins = get_plugins();
  1176. if( isset( $installed_plugins[$plugin] ) ) {
  1177. if( is_plugin_active( $plugin ) ) {
  1178. $output .= $icon . '<a href="' . admin_url( 'edit.php?post_type=download&page=edd-settings' ) . '">' . __( 'Digital Downloads Settings', 'cyberchimps_core' ) . '</a>';
  1179. }
  1180. else {
  1181. $output .= $icon_neg . '<a href="' . admin_url( 'plugins.php' ) . '">' . __( 'Please activate Easy Digital Downloads plugin', 'cyberchimps_core' ) . '</a>';
  1182. }
  1183. }
  1184. else {
  1185. $output .= $icon_neg . '<a href="' . cyberchimps_digital_downloads_install_link() . '">' . __( 'Install Easy Digital Downloads Plugin', 'cyberchimps_core' ) . '</a>';
  1186. }
  1187. echo $output;
  1188. }
  1189. // return a nonced installation link for the plugin.
  1190. function cyberchimps_digital_downloads_install_link() {
  1191. include_once ABSPATH . 'wp-admin/includes/plugin-install.php';
  1192. $slug = 'easy-digital-downloads';
  1193. return wp_nonce_url( self_admin_url( 'update.php?action=install-plugin&plugin=' . $slug ), 'install-plugin_' . $slug );
  1194. }
  1195. // Add class cc-responsive if responisve design is on.
  1196. add_filter( 'body_class', 'cyberchimps_add_responsive_class' );
  1197. function cyberchimps_add_responsive_class( $classes ) {
  1198. // Check if responisve design is on.
  1199. if( cyberchimps_get_option( 'responsive_design', 'checked' ) ) {
  1200. $classes[] = 'cc-responsive';
  1201. }
  1202. return $classes;
  1203. }
  1204. if ( 'mp6' === get_user_option( 'admin_color' ) || version_compare( $GLOBALS['wp_version'], '3.8-alpha', '>' ) ) {
  1205. function cyberchimps_load_custom_admin_styles() {
  1206. wp_enqueue_style( 'cc-admin', get_template_directory_uri() . '/cyberchimps/options/lib/css/custom-post-icons.css', false, '1.0.0' );
  1207. }
  1208. add_action( 'admin_enqueue_scripts', 'cyberchimps_load_custom_admin_styles' );
  1209. }
  1210. // FOR IE compatiblilty mode.
  1211. add_action( 'send_headers', 'cyberchimps_add_header_xua' );
  1212. function cyberchimps_add_header_xua() {
  1213. header( 'X-UA-Compatible: IE=edge,chrome=1' );
  1214. }