PageRenderTime 46ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-content/themes/hero/functions.php

https://github.com/Bochet/festival_lgbt
PHP | 401 lines | 271 code | 80 blank | 50 comment | 37 complexity | 8ba2a3201c904e378a8141f6b1bda8e4 MD5 | raw file
Possible License(s): GPL-2.0, AGPL-1.0, LGPL-2.1
  1. <?php
  2. /** Tell WordPress to run Hero_setup() when the 'after_setup_theme' hook is run. */
  3. add_action( 'after_setup_theme', 'Hero_setup' );
  4. if ( ! function_exists( 'Hero_setup' ) ):
  5. function Hero_setup() {
  6. global $content_width;
  7. if (!isset($content_width))
  8. $content_width = 620;
  9. // This theme uses post thumbnails
  10. add_theme_support( 'post-thumbnails' );
  11. // Add default posts and comments RSS feed links to head
  12. add_theme_support( 'automatic-feed-links' );
  13. // Add support for custom backgrounds
  14. $args = array(
  15. 'default-color' => '000000',
  16. 'wp-head-callback' => '_custom_background_cb'
  17. );
  18. add_theme_support( 'custom-background', $args );
  19. // Make theme available for translation
  20. // Translations can be filed in the /languages/ directory
  21. load_theme_textdomain( 'Hero', get_template_directory() . '/languages' );
  22. $locale = get_locale();
  23. $locale_file = get_template_directory() . "/languages/$locale.php";
  24. if ( is_readable( $locale_file ) )
  25. require_once( $locale_file );
  26. // This theme uses wp_nav_menu() in one location.
  27. register_nav_menus( array(
  28. 'primary' => __( 'Primary Navigation', 'Hero' ),
  29. ) );
  30. }
  31. endif;
  32. ?>
  33. <?php
  34. function Hero_list_pings($comment, $args, $depth) {
  35. $GLOBALS['comment'] = $comment; ?>
  36. <li id="comment-<?php comment_ID(); ?>"><?php comment_author_link(); ?>
  37. <?php } ?>
  38. <?php
  39. add_filter('get_comments_number', 'Hero_comment_count', 0);
  40. function Hero_comment_count( $count ) {
  41. if ( ! is_admin() ) {
  42. global $id;
  43. $comments_by_type = &separate_comments(get_comments('status=approve&post_id=' . $id));
  44. return count($comments_by_type['comment']);
  45. } else {
  46. return $count;
  47. }
  48. }
  49. ?>
  50. <?php
  51. if ( ! function_exists( 'Hero_comment' ) ) :
  52. function Hero_comment( $comment, $args, $depth ) {
  53. $GLOBALS['comment'] = $comment;
  54. switch ( $comment->comment_type ) :
  55. case '' :
  56. ?>
  57. <li <?php comment_class(); ?> id="li-comment-<?php comment_ID(); ?>">
  58. <div id="comment-<?php comment_ID(); ?>">
  59. <div class="comment-author vcard">
  60. <?php echo get_avatar( $comment, 40 ); ?>
  61. <?php printf( __( '%s', 'Hero' ), sprintf( '<cite class="fn">%s</cite>', get_comment_author_link() ) ); ?>
  62. </div><!-- .comment-author .vcard -->
  63. <?php if ( $comment->comment_approved == '0' ) : ?>
  64. <em><?php _e( 'Your comment is awaiting moderation.', 'Hero' ); ?></em>
  65. <br />
  66. <?php endif; ?>
  67. <div class="comment-meta commentmetadata"><a href="<?php echo esc_url( get_comment_link( $comment->comment_ID ) ); ?>">
  68. <?php
  69. /* translators: 1: date, 2: time */
  70. printf( __( '%1$s at %2$s', 'Hero' ), get_comment_date(), get_comment_time() ); ?></a><?php edit_comment_link( __( '(Edit)', 'Hero' ), ' ' );
  71. ?>
  72. </div><!-- .comment-meta .commentmetadata -->
  73. <div class="comment-body"><?php comment_text(); ?></div>
  74. <div class="reply">
  75. <?php comment_reply_link( array_merge( $args, array( 'depth' => $depth, 'max_depth' => $args['max_depth'] ) ) ); ?>
  76. </div><!-- .reply -->
  77. </div><!-- #comment-## -->
  78. <?php
  79. break;
  80. case 'pingback' :
  81. case 'trackback' :
  82. ?>
  83. <li class="post pingback">
  84. <p><?php _e( 'Pingback:', 'Hero' ); ?> <?php comment_author_link(); ?><?php edit_comment_link( __('(Edit)', 'Hero'), ' ' ); ?></p>
  85. <?php
  86. break;
  87. endswitch;
  88. }
  89. endif;
  90. /**
  91. * Register widgetized areas, including two sidebars and four widget-ready columns in the footer.
  92. *
  93. * To override Hero_widgets_init() in a child theme, remove the action hook and add your own
  94. * function tied to the init hook.
  95. */
  96. function Hero_widgets_init() {
  97. // Area 1, located at the top of the sidebar.
  98. register_sidebar( array(
  99. 'name' => __( 'Primary Widget Area', 'Hero' ),
  100. 'id' => 'primary-widget-area',
  101. 'description' => __( 'The primary widget area', 'Hero' ),
  102. 'before_widget' => '<li id="%1$s" class="widget-container %2$s">',
  103. 'after_widget' => '</li>',
  104. 'before_title' => '<h3 class="widget-title">',
  105. 'after_title' => '</h3>',
  106. ) );
  107. // Area 3, located in the footer. Empty by default.
  108. register_sidebar( array(
  109. 'name' => __( 'First Footer Widget Area', 'Hero' ),
  110. 'id' => 'first-footer-widget-area',
  111. 'description' => __( 'The first footer widget area', 'Hero' ),
  112. 'before_widget' => '<li id="%1$s" class="widget-container %2$s">',
  113. 'after_widget' => '</li>',
  114. 'before_title' => '<h3 class="widget-title">',
  115. 'after_title' => '</h3>',
  116. ) );
  117. // Area 4, located in the footer. Empty by default.
  118. register_sidebar( array(
  119. 'name' => __( 'Second Footer Widget Area', 'Hero' ),
  120. 'id' => 'second-footer-widget-area',
  121. 'description' => __( 'The second footer widget area', 'Hero' ),
  122. 'before_widget' => '<li id="%1$s" class="widget-container %2$s">',
  123. 'after_widget' => '</li>',
  124. 'before_title' => '<h3 class="widget-title">',
  125. 'after_title' => '</h3>',
  126. ) );
  127. // Area 5, located in the footer. Empty by default.
  128. register_sidebar( array(
  129. 'name' => __( 'Third Footer Widget Area', 'Hero' ),
  130. 'id' => 'third-footer-widget-area',
  131. 'description' => __( 'The third footer widget area', 'Hero' ),
  132. 'before_widget' => '<li id="%1$s" class="widget-container %2$s">',
  133. 'after_widget' => '</li>',
  134. 'before_title' => '<h3 class="widget-title">',
  135. 'after_title' => '</h3>',
  136. ) );
  137. // Area 6, located in the footer. Empty by default.
  138. register_sidebar( array(
  139. 'name' => __( 'Fourth Footer Widget Area', 'Hero' ),
  140. 'id' => 'fourth-footer-widget-area',
  141. 'description' => __( 'The fourth footer widget area', 'Hero' ),
  142. 'before_widget' => '<li id="%1$s" class="widget-container %2$s">',
  143. 'after_widget' => '</li>',
  144. 'before_title' => '<h3 class="widget-title">',
  145. 'after_title' => '</h3>',
  146. ) );
  147. }
  148. if ( ! function_exists( 'Hero_posted_on' ) ) :
  149. /**
  150. * Prints HTML with meta information for the current post—date/time and author.
  151. */
  152. function Hero_posted_on() {
  153. printf( __( '%2$s <span class="meta-sep">by</span> %3$s', 'Hero' ),
  154. 'meta-prep meta-prep-author',
  155. sprintf( '<a href="%1$s" title="%2$s" rel="bookmark"><span class="entry-date">%3$s</span></a>',
  156. get_permalink(),
  157. esc_attr( get_the_time() ),
  158. get_the_date()
  159. ),
  160. sprintf( '<span class="author vcard"><a class="url fn n" href="%1$s" title="%2$s">%3$s</a></span>',
  161. get_author_posts_url( get_the_author_meta( 'ID' ) ),
  162. sprintf( esc_attr__( 'View all posts by %s', 'Hero' ), get_the_author() ),
  163. get_the_author()
  164. )
  165. );
  166. }
  167. endif;
  168. /** Register sidebars by running Hero_widgets_init() on the widgets_init hook. */
  169. add_action( 'widgets_init', 'Hero_widgets_init' );
  170. /** Excerpt */
  171. function Hero_excerpt_length( $length ) {
  172. return 30;
  173. }
  174. add_filter( 'excerpt_length', 'Hero_excerpt_length' );
  175. function Hero_auto_excerpt_more( $more ) {
  176. return ' &hellip;' ;
  177. }
  178. add_filter( 'excerpt_more', 'Hero_auto_excerpt_more' );
  179. /** filter function for wp_title */
  180. function Hero_filter_wp_title( $old_title, $sep, $sep_location ){
  181. // add padding to the sep
  182. $ssep = ' ' . $sep . ' ';
  183. // find the type of index page this is
  184. if( is_category() ) $insert = $ssep . 'Category';
  185. elseif( is_tag() ) $insert = $ssep . 'Tag';
  186. elseif( is_author() ) $insert = $ssep . 'Author';
  187. elseif( is_year() || is_month() || is_day() ) $insert = $ssep . 'Archives';
  188. else $insert = NULL;
  189. // get the page number we're on (index)
  190. if( get_query_var( 'paged' ) )
  191. $num = $ssep . 'page ' . get_query_var( 'paged' );
  192. // get the page number we're on (multipage post)
  193. elseif( get_query_var( 'page' ) )
  194. $num = $ssep . 'page ' . get_query_var( 'page' );
  195. // else
  196. else $num = NULL;
  197. // concoct and return new title
  198. return get_bloginfo( 'name' ) . $insert . $old_title . $num;
  199. }
  200. // call our custom wp_title filter, with normal (10) priority, and 3 args
  201. add_filter( 'wp_title', 'Hero_filter_wp_title', 10, 3 );
  202. /*-----------------------------------------------------------------------------------*/
  203. /* Exclude categories from displaying on the "Blog" page template.
  204. /*-----------------------------------------------------------------------------------*/
  205. // Exclude categories on the "Blog" page template.
  206. add_filter( 'Hero_blog_template_query_args', 'Hero_exclude_categories_blogtemplate' );
  207. function Hero_exclude_categories_blogtemplate ( $args ) {
  208. if ( ! function_exists( 'Hero_prepare_category_ids_from_option' ) ) { return $args; }
  209. $excluded_cats = array();
  210. // Process the category data and convert all categories to IDs.
  211. $excluded_cats = Hero_prepare_category_ids_from_option( 'exclude_cat' );
  212. if ( count( $excluded_cats ) > 0 ) {
  213. // Setup the categories as a string, because "category__not_in" doesn't seem to work
  214. // when using query_posts().
  215. foreach ( $excluded_cats as $k => $v ) { $excluded_cats[$k] = '-' . $v; }
  216. $cats = join( ',', $excluded_cats );
  217. $args['cat'] = $cats;
  218. }
  219. return $args;
  220. }
  221. /*-----------------------------------------------------------------------------------*/
  222. /* Hero_prepare_category_ids_from_option()
  223. /*-----------------------------------------------------------------------------------*/
  224. if ( ! function_exists( 'Hero_prepare_category_ids_from_option' ) ) {
  225. function Hero_prepare_category_ids_from_option ( $option ) {
  226. $cats = array();
  227. $stored_cats = of_get_option( $option );
  228. $cats_raw = explode( ',', $stored_cats );
  229. if ( is_array( $cats_raw ) && ( count( $cats_raw ) > 0 ) ) {
  230. foreach ( $cats_raw as $k => $v ) {
  231. $value = trim( $v );
  232. if ( is_numeric( $value ) ) {
  233. $cats_raw[$k] = $value;
  234. } else {
  235. $cat_obj = get_category_by_slug( $value );
  236. if ( isset( $cat_obj->term_id ) ) {
  237. $cats_raw[$k] = $cat_obj->term_id;
  238. }
  239. }
  240. $cats = $cats_raw;
  241. }
  242. }
  243. return $cats;
  244. }
  245. }
  246. // custom function
  247. function Hero_head_css() {
  248. $output = '';
  249. $custom_css = of_get_option('custom_css');
  250. if ($custom_css <> '') {
  251. $output .= $custom_css . "\n";
  252. }
  253. // Output styles
  254. if ($output <> '') {
  255. $output = "<!-- Custom Styling -->\n<style type=\"text/css\">\n" . $output . "</style>\n";
  256. echo $output;
  257. }
  258. }
  259. add_action('wp_head', 'Hero_head_css');
  260. function Hero_of_analytics(){
  261. $googleanalytics= of_get_option('go_code');
  262. echo stripslashes($googleanalytics);
  263. }
  264. add_action( 'wp_footer', 'Hero_of_analytics' );
  265. function Hero_favicon() {
  266. if (of_get_option('favicon_image') != '') {
  267. echo '<link rel="shortcut icon" href="'. of_get_option('favicon_image') .'"/>'."\n";
  268. }
  269. }
  270. add_action('wp_head', 'Hero_favicon');
  271. function Hero_date_on() {
  272. printf( __( '<span class="%1$s">Posted on</span> %2$s', 'Hero' ),
  273. 'meta-prep meta-prep-author',
  274. sprintf( '<a href="%1$s" title="%2$s" rel="bookmark"><span class="entry-date">%3$s</span></a>',
  275. get_permalink(),
  276. esc_attr( get_the_time() ),
  277. get_the_date()
  278. )
  279. );
  280. }
  281. function Hero_of_register_js() {
  282. if (!is_admin()) {
  283. wp_register_script('superfish', get_template_directory_uri() . '/js/superfish.js', 'jquery', '1.0', TRUE);
  284. wp_register_script('custom', get_template_directory_uri() . '/js/jquery.custom.js', 'jquery', '1.0', TRUE);
  285. wp_register_script('nivo', get_template_directory_uri() . '/js/jquery.nivo.slider.js', 'jquery', '3.0.1', TRUE);
  286. wp_enqueue_script('jquery');
  287. wp_enqueue_script('superfish');
  288. wp_enqueue_script('custom');
  289. wp_enqueue_script('nivo');
  290. }
  291. }
  292. add_action('init', 'Hero_of_register_js');
  293. function of_single_scripts() {
  294. if(is_singular()) wp_enqueue_script( 'comment-reply' ); // loads the javascript required for threaded comments
  295. }
  296. add_action('wp_print_scripts', 'of_single_scripts');
  297. function Hero_of_styles() {
  298. wp_register_style( 'superfish', get_template_directory_uri() . '/css/superfish.css' );
  299. wp_register_style( 'nivo', get_template_directory_uri() . '/css/nivo-slider.css' );
  300. wp_enqueue_style( 'superfish' );
  301. wp_enqueue_style( 'nivo' );
  302. }
  303. add_action('wp_print_styles', 'Hero_of_styles');
  304. /** redirect */
  305. if ( is_admin() && isset($_GET['activated'] ) && $pagenow == "themes.php" )
  306. wp_redirect( 'themes.php?page=options-framework');
  307. // include panel file.
  308. if ( !function_exists( 'optionsframework_init' ) ) {
  309. /*-----------------------------------------------------------------------------------*/
  310. /* Options Framework Theme
  311. /*-----------------------------------------------------------------------------------*/
  312. /* Set the file path based on whether the Options Framework Theme is a parent theme or child theme */
  313. if ( get_stylesheet_directory() == get_template_directory_uri() ) {
  314. define('OPTIONS_FRAMEWORK_URL', get_template_directory() . '/admin/');
  315. define('OPTIONS_FRAMEWORK_DIRECTORY', get_template_directory_uri() . '/admin/');
  316. } else {
  317. define('OPTIONS_FRAMEWORK_URL', get_template_directory() . '/admin/');
  318. define('OPTIONS_FRAMEWORK_DIRECTORY', get_template_directory_uri() . '/admin/');
  319. }
  320. require_once (OPTIONS_FRAMEWORK_URL . 'options-framework.php');
  321. }