PageRenderTime 42ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/functions.php

https://github.com/MaTachi/sturdy-sector
PHP | 255 lines | 141 code | 32 blank | 82 comment | 13 complexity | e339d89d566cc96aedf3e0eabe13d898 MD5 | raw file
Possible License(s): GPL-3.0
  1. <?php
  2. if ( $_POST['update_themeoptions'] == 'true' )
  3. themeoptions_update();
  4. /**
  5. * Sets up the content width value based on the theme's design and stylesheet.
  6. */
  7. if ( ! isset( $content_width ) )
  8. $content_width = 700;
  9. /**
  10. * Sets up theme defaults and registers the various WordPress features that
  11. * Sturdy Sector supports.
  12. *
  13. * @uses load_theme_textdomain() For translation/localization support.
  14. * @uses add_editor_style() To add a Visual Editor stylesheet.
  15. * @uses add_theme_support() To add support for post thumbnails, automatic feed links,
  16. * custom background, and post formats.
  17. * @uses register_nav_menu() To add support for navigation menus.
  18. * @uses set_post_thumbnail_size() To set a custom post thumbnail size.
  19. *
  20. * @since Sturdy Sector 1.0
  21. */
  22. function sturdysector_setup() {
  23. /*
  24. * Makes Twenty Twelve available for translation.
  25. *
  26. * Translations can be added to the /languages/ directory.
  27. * If you're building a theme based on Twenty Twelve, use a find and replace
  28. * to change 'sturdysector' to the name of your theme in all the template files.
  29. */
  30. //load_theme_textdomain( 'sturdysector', get_template_directory() . '/languages' );
  31. // This theme styles the visual editor with editor-style.css to match the theme style.
  32. add_editor_style();
  33. // Adds RSS feed links to <head> for posts and comments.
  34. add_theme_support( 'automatic-feed-links' );
  35. // This theme supports a variety of post formats.
  36. //add_theme_support( 'post-formats', array( 'aside', 'image', 'link', 'quote', 'status' ) );
  37. // This theme uses wp_nav_menu() in one location.
  38. register_nav_menu( 'primary', __( 'Primary Menu', 'sturdysector' ) );
  39. // This theme uses a custom image size for featured images, displayed on "standard" posts.
  40. add_theme_support( 'post-thumbnails' );
  41. set_post_thumbnail_size( 699, 9999 ); // Unlimited height, soft crop
  42. }
  43. add_action( 'after_setup_theme', 'sturdysector_setup' );
  44. /**
  45. * Registers our main widget area and the front page widget areas.
  46. *
  47. * @since Sturdy Sector 1.0
  48. */
  49. function sturdysector_widgets_init() {
  50. register_sidebar( array(
  51. 'name' => __( 'Main Sidebar', 'sturdysector' ),
  52. 'id' => 'sidebar-1',
  53. 'description' => __( 'Appears on posts and pages except the optional Front Page template, which has its own widgets', 'sturdysector' ),
  54. 'before_widget' => '<aside id="%1$s" class="widget %2$s">',
  55. 'after_widget' => '</aside>',
  56. 'before_title' => '<h3 class="widget-title">',
  57. 'after_title' => '</h3>',
  58. ) );
  59. }
  60. add_action( 'widgets_init', 'sturdysector_widgets_init' );
  61. /**
  62. * Enqueues scripts and styles for front-end.
  63. *
  64. * @since Sturdy Sector 1.0
  65. */
  66. function sturdysector_scripts_styles() {
  67. /*
  68. * Fonts.
  69. */
  70. wp_enqueue_style( 'sturdysector-fonts', 'http://fonts.googleapis.com/css?family=Geo|Racing+Sans+One|Open+Sans' );
  71. /*
  72. * Loads our main stylesheet.
  73. */
  74. wp_enqueue_style( 'sturdysector-style', get_stylesheet_uri() );
  75. }
  76. add_action( 'wp_enqueue_scripts', 'sturdysector_scripts_styles' );
  77. if ( ! function_exists( 'sturdysector_entry_meta' ) ) :
  78. /**
  79. * Prints HTML with meta information for current post: categories, tags, permalink, author, and date.
  80. *
  81. * Create your own sturdysector_entry_meta() to override in a child theme.
  82. *
  83. * @since Twenty Twelve 1.0
  84. */
  85. function sturdysector_entry_meta() {
  86. // Translators: used between list items, there is a space after the comma.
  87. $categories_list = get_the_category_list( __( ', ', 'sturdysector' ) );
  88. // Translators: used between list items, there is a space after the comma.
  89. $tag_list = get_the_tag_list( '', __( ', ', 'sturdysector' ) );
  90. $date = sprintf( '<time class="entry-date" datetime="%1$s">%2$s</time>',
  91. esc_attr( get_the_date( 'c' ) ),
  92. esc_attr( get_the_date( 'F j, Y, H:i' ) )
  93. );
  94. $author = sprintf( '<span class="author vcard"><a class="url fn n" href="%1$s" title="%2$s" rel="author">%3$s</a></span>',
  95. esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ),
  96. esc_attr( sprintf( __( 'View all posts by %s', 'sturdysector' ), get_the_author() ) ),
  97. get_the_author()
  98. );
  99. // Translators: 1 is category, 2 is tag, 3 is the date and 4 is the author's name.
  100. if ( $tag_list ) {
  101. $utility_text = __( 'Posted on: %1$s by %2$s<br />Categories: %3$s<br />Tags: %4$s', 'sturdysector' );
  102. } elseif ( $categories_list ) {
  103. $utility_text = __( 'Posted on: %1$s by %2$s<br />Categories: %3$s', 'sturdysector' );
  104. } else {
  105. $utility_text = __( 'Posted on: %1$s by %2$s', 'sturdysector' );
  106. }
  107. printf(
  108. $utility_text,
  109. $date,
  110. $author,
  111. $categories_list,
  112. $tag_list
  113. );
  114. //printf(
  115. // $utility_text,
  116. // $categories_list,
  117. // $tag_list,
  118. // $date,
  119. // $author
  120. //);
  121. }
  122. endif;
  123. if ( ! function_exists( 'sturdysector_content_nav' ) ) :
  124. /**
  125. * Displays navigation to next/previous pages when applicable.
  126. *
  127. * @since Twenty Twelve 1.0
  128. */
  129. function sturdysector_content_nav( $html_id ) {
  130. global $wp_query;
  131. $html_id = esc_attr( $html_id );
  132. if ( $wp_query->max_num_pages > 1 ) : ?>
  133. <nav id="<?php echo $html_id; ?>" class="navigation" role="navigation">
  134. <h3 class="assistive-text"><?php _e( 'Post navigation', 'sturdysector' ); ?></h3>
  135. <div class="nav-previous alignleft"><?php next_posts_link( __( '<span class="meta-nav">&larr;</span> Older posts', 'sturdysector' ) ); ?></div>
  136. <div class="nav-next alignright"><?php previous_posts_link( __( 'Newer posts <span class="meta-nav">&rarr;</span>', 'sturdysector' ) ); ?></div>
  137. </nav><!-- #<?php echo $html_id; ?> .navigation -->
  138. <?php endif;
  139. }
  140. endif;
  141. if ( ! function_exists( 'sturdysector_comment' ) ) :
  142. /**
  143. * Template for comments and pingbacks.
  144. *
  145. * To override this walker in a child theme without modifying the comments template
  146. * simply create your own sturdysector_comment(), and that function will be used instead.
  147. *
  148. * Used as a callback by wp_list_comments() for displaying the comments.
  149. *
  150. * @since Twenty Twelve 1.0
  151. */
  152. function sturdysector_comment( $comment, $args, $depth ) {
  153. $GLOBALS['comment'] = $comment;
  154. switch ( $comment->comment_type ) :
  155. case 'pingback' :
  156. case 'trackback' :
  157. // Display trackbacks differently than normal comments.
  158. ?>
  159. <li <?php comment_class(); ?> id="comment-<?php comment_ID(); ?>">
  160. <p><?php _e( 'Pingback:', 'sturdysector' ); ?> <?php comment_author_link(); ?> <?php edit_comment_link( __( '(Edit)', 'sturdysector' ), '<span class="edit-link">', '</span>' ); ?></p>
  161. <?php
  162. break;
  163. default :
  164. // Proceed with normal comments.
  165. global $post;
  166. ?>
  167. <li <?php comment_class(); ?> id="li-comment-<?php comment_ID(); ?>">
  168. <article id="comment-<?php comment_ID(); ?>" class="comment">
  169. <header class="comment-meta comment-author vcard">
  170. <?php
  171. echo get_avatar( $comment, 44 );
  172. printf( '<cite class="fn">%1$s %2$s</cite>',
  173. get_comment_author_link(),
  174. // If current post author is also comment author, make it known visually.
  175. ( $comment->user_id === $post->post_author ) ? '<span> ' . __( 'Post author', 'sturdysector' ) . '</span>' : ''
  176. );
  177. printf( '<a href="%1$s"><time datetime="%2$s">%3$s</time></a>',
  178. esc_url( get_comment_link( $comment->comment_ID ) ),
  179. get_comment_time( 'c' ),
  180. /* translators: 1: date, 2: time */
  181. sprintf( __( '%1$s at %2$s', 'sturdysector' ), get_comment_date(), get_comment_time() )
  182. );
  183. ?>
  184. </header><!-- .comment-meta -->
  185. <?php if ( '0' == $comment->comment_approved ) : ?>
  186. <p class="comment-awaiting-moderation"><?php _e( 'Your comment is awaiting moderation.', 'sturdysector' ); ?></p>
  187. <?php endif; ?>
  188. <section class="comment-content comment">
  189. <?php comment_text(); ?>
  190. <?php edit_comment_link( __( 'Edit', 'sturdysector' ), '<p class="edit-link">', '</p>' ); ?>
  191. </section><!-- .comment-content -->
  192. <div class="reply">
  193. <?php comment_reply_link( array_merge( $args, array( 'reply_text' => __( 'Reply', 'sturdysector' ), 'after' => ' <span>&darr;</span>', 'depth' => $depth, 'max_depth' => $args['max_depth'] ) ) ); ?>
  194. </div><!-- .reply -->
  195. </article><!-- #comment-## -->
  196. <?php
  197. break;
  198. endswitch; // end comment_type check
  199. }
  200. endif;
  201. function themeoptions_admin_menu() {
  202. add_theme_page("Theme Options", "Theme Options", 'edit_themes', basename(__FILE__), 'themeoptions_page');
  203. }
  204. function themeoptions_page() {
  205. ?>
  206. <div class="wrap">
  207. <div id="icon-themes" class="icon32"><br /></div>
  208. <h2>Theme Options</h2>
  209. <form method="POST" action="">
  210. <input type="hidden" name="update_themeoptions" value="true" />
  211. <h4><input type="checkbox" name="display_twitter_icon" id="display_twitter_icon" value="true" <?php echo get_option( 'sturdysector_display_twitter_icon' ) == 'true' ? 'checked ' : ''; ?>/> Display Twitter icon</h4>
  212. <p><input type="text" name="twitter_username" id="twitter_username" size="32" value="<?php echo get_option( 'sturdysector_twitter_username' ); ?>" /> Twitter Username</p>
  213. <p><input type="submit" name="search" value="Update Options" class="button" /></p>
  214. </form>
  215. </div>
  216. <?php
  217. }
  218. add_action('admin_menu', 'themeoptions_admin_menu');
  219. function themeoptions_update() {
  220. update_option( 'sturdysector_display_twitter_icon', empty($_POST['display_twitter_icon']) ? 'false' : 'true' );
  221. update_option( 'sturdysector_twitter_username', $_POST['twitter_username'] );
  222. }
  223. ?>