Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 360 lines (294 sloc) 11.649 kB
217f7fd Importing the News theme files and folders.
greenshady authored
1 <?php
2 /**
3 * The functions file is used to initialize everything in the theme. It controls how the theme is loaded and
4 * sets up the supported features, default actions, and default filters. If making customizations, users
5 * should create a child theme and make changes to its functions.php file (not this one). Friends don't let
6 * friends modify parent theme files. ;)
7 *
8 * Child themes should do their setup on the 'after_setup_theme' hook with a priority of 11 if they want to
9 * override parent theme features. Use a priority of 9 if wanting to run before the parent theme.
10 *
11 * This program is free software; you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License version 2, as published by the Free Software Foundation. You may NOT assume
13 * that you can use any other version of the GPL.
14 *
15 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
16 * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
17 *
18 * You should have received a copy of the GNU General Public License along with this program; if not, write
19 * to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 *
21 * @package News
22 * @subpackage Functions
b778d40 @justintadlock Version bump to 0.3 beta.
authored
23 * @version 0.3.0
302fb93 @justintadlock Update copyright information.
authored
24 * @author Justin Tadlock <justin@justintadlock.com>
e9a7a90 @justintadlock More copyright updates.
authored
25 * @author Tung Do <ttsondo@gmail.com>
26 * @copyright Copyright (c) 2010 - 2012
302fb93 @justintadlock Update copyright information.
authored
27 * @link http://themehybrid.com/themes/news
217f7fd Importing the News theme files and folders.
greenshady authored
28 * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
29 */
30
31 /* Load the core theme framework. */
87b5704 @justintadlock Update call to Hybrid Core.
authored
32 require_once( trailingslashit( get_template_directory() ) . 'library/hybrid.php' );
33 new Hybrid();
217f7fd Importing the News theme files and folders.
greenshady authored
34
35 /* Do theme setup on the 'after_setup_theme' hook. */
36 add_action( 'after_setup_theme', 'news_theme_setup' );
37
38 /**
39 * Theme setup function. This function adds support for theme features and defines the default theme
40 * actions and filters.
41 *
42 * @since 0.1.0
43 */
44 function news_theme_setup() {
45
46 /* Get action/filter hook prefix. */
47 $prefix = hybrid_get_prefix();
48
49 /* Load shortcodes file. */
178b520 @justintadlock Never assume there's a trailing slash. Use trailingslashit().
authored
50 require_once( trailingslashit( THEME_DIR ) . 'functions/shortcodes.php' );
217f7fd Importing the News theme files and folders.
greenshady authored
51
52 /* Load admin functions. */
53 if ( is_admin() )
178b520 @justintadlock Never assume there's a trailing slash. Use trailingslashit().
authored
54 require_once( trailingslashit( THEME_DIR ) . 'functions/admin.php' );
217f7fd Importing the News theme files and folders.
greenshady authored
55
56 /* Add theme support for WordPress features. */
57 add_theme_support( 'automatic-feed-links' );
58
59 /* Add theme support for core framework features. */
60 add_theme_support( 'hybrid-core-menus', array( 'primary', 'secondary', 'subsidiary' ) );
61 add_theme_support( 'hybrid-core-sidebars', array( 'primary', 'secondary', 'header', 'after-singular' ) );
62 add_theme_support( 'hybrid-core-widgets' );
63 add_theme_support( 'hybrid-core-shortcodes' );
64 add_theme_support( 'hybrid-core-theme-settings', array( 'about', 'footer' ) );
65 add_theme_support( 'hybrid-core-seo' );
66 add_theme_support( 'hybrid-core-template-hierarchy' );
061ce9f @justintadlock Use the Hybrid Core drop-downs instead of keeping this in the theme's…
authored
67 add_theme_support( 'hybrid-core-drop-downs' );
217f7fd Importing the News theme files and folders.
greenshady authored
68
69 /* Add theme support for extensions. */
70 add_theme_support( 'dev-stylesheet' );
71 add_theme_support( 'loop-pagination' );
72 add_theme_support( 'get-the-image' );
73 add_theme_support( 'entry-views' );
74 add_theme_support( 'breadcrumb-trail' );
75
76 /* Register shortcodes. */
77 add_action( 'init', 'news_register_shortcodes' );
78
79 /* Register new image sizes. */
80 add_action( 'init', 'news_register_image_sizes' );
81
82 /* Register additional widgets. */
83 add_action( 'widgets_init', 'news_register_widgets' );
84
85 /* Load JavaScript. */
86 add_action( 'wp_enqueue_scripts', 'news_enqueue_script' );
87
88 /* Site description. */
89 add_action( "{$prefix}_before_menu_secondary", 'hybrid_site_description' );
90
91 /* Hook additional items to the nav menus. */
92 add_filter( 'wp_nav_menu', 'news_nav_menu_add_items', 10, 2 );
93
94 /* Content. */
95 add_action( "{$prefix}_singular-post_after_loop", 'news_singular_post_tags' );
96
97 /* Tag cloud. */
98 add_filter( 'wp_tag_cloud', 'news_add_span_to_tag_cloud' );
99 add_filter( 'term_links-post_tag', 'news_add_span_to_tag_cloud' );
100
101 /* Embed width/height defaults. */
102 add_filter( 'embed_defaults', 'news_embed_defaults' );
103
104 /* Set content width. */
105 hybrid_set_content_width( 600 );
106
107 /* Allow all post types to have shortlinks. Do this early so plugins can still override. */
108 add_filter( 'get_shortlink', 'news_filter_shortlink', 1, 3 );
109
110 /* Add classes to the comments pagination. */
111 add_filter( 'previous_comments_link_attributes', 'news_previous_comments_link_attributes' );
112 add_filter( 'next_comments_link_attributes', 'news_next_comments_link_attributes' );
113
114 /* Add a wrapper class for singular videos. */
115 add_filter( 'the_content', 'news_video_embed_wrapper', 20 );
116
117 /* Shorter excerpt length. */
118 add_filter( 'excerpt_length', 'news_excerpt_length' );
119
120 /* Comment form arguments. */
121 add_filter( 'comment_form_defaults', 'news_comment_form_defaults', 11 );
122
123 /* Additional default theme settings. */
124 add_filter( "{$prefix}_default_theme_settings", 'news_theme_settings' );
125 }
126
127 /**
128 * Registers additional image sizes, in particular, the 'news-thumbnail' and 'news-slideshow' sizes.
129 *
130 * @since 0.1.0
131 */
132 function news_register_image_sizes() {
133 add_image_size( 'news-slideshow', 600, 400, true );
134 add_image_size( 'news-slideshow-large', 640, 430, true );
135 add_image_size( 'news-thumbnail', 100, 75, true );
136 }
137
138 /**
139 * Loads extra widget files and registers the widgets.
140 *
141 * @since 0.1.0
142 */
143 function news_register_widgets() {
144
145 /* Load the popular tabs widget. */
146 if ( current_theme_supports( 'entry-views' ) ) {
178b520 @justintadlock Never assume there's a trailing slash. Use trailingslashit().
authored
147 require_once( trailingslashit( THEME_DIR ) . 'classes/widget-popular-tabs.php' );
217f7fd Importing the News theme files and folders.
greenshady authored
148 register_widget( 'News_Widget_Popular_Tabs' );
149 }
150
151 /* Load the image stream widget. */
178b520 @justintadlock Never assume there's a trailing slash. Use trailingslashit().
authored
152 require_once( trailingslashit( THEME_DIR ) . 'classes/widget-image-stream.php' );
217f7fd Importing the News theme files and folders.
greenshady authored
153 register_widget( 'News_Widget_Image_Stream' );
154
155 /* Load the newsletter widget. */
178b520 @justintadlock Never assume there's a trailing slash. Use trailingslashit().
authored
156 require_once( trailingslashit( THEME_DIR ) . 'classes/widget-newsletter.php' );
217f7fd Importing the News theme files and folders.
greenshady authored
157 register_widget( 'News_Widget_Newsletter' );
158 }
159
160 /**
161 * Loads the theme JavaScript files.
162 *
163 * @since 0.1.0
164 */
165 function news_enqueue_script() {
166 wp_enqueue_script( 'jquery-ui-tabs' );
061ce9f @justintadlock Use the Hybrid Core drop-downs instead of keeping this in the theme's…
authored
167 wp_enqueue_script( 'news-theme', trailingslashit( THEME_URI ) . 'js/news-theme.js', array( 'jquery' ), '20120825', true );
217f7fd Importing the News theme files and folders.
greenshady authored
168 }
169
170 /**
171 * Adds a log in/out link to the secondary menu.
172 *
173 * @since 0.1.0
174 */
175 function news_nav_menu_add_items( $menu, $args ) {
176
177 if ( 'secondary' == $args->theme_location ) {
6b75b39 @justintadlock Use home_url() instead of site_url()
authored
178 $links = '<li class="loginout">' . wp_loginout( home_url( esc_url( $_SERVER['REQUEST_URI'] ) ), false ) . '</li>';
217f7fd Importing the News theme files and folders.
greenshady authored
179 $menu = str_replace( '</ul></div>', $links . '</ul></div>', $menu );
180 }
181
182 return $menu;
183 }
184
185 /**
186 * Displays the post tags for singular posts.
187 *
188 * @since 0.1.0
189 */
190 function news_singular_post_tags() {
191 if ( has_tag() )
192 echo '<div class="entry-tags">' . do_shortcode( '[entry-terms type="post_tag" separator=""]' ) . '</div>';
193 }
194
195 /**
196 * Wraps tag cloud links with a span for easier background image styling.
197 *
198 * @todo If anyone can figure out a way to style this without the <span>, we can remove this.
199 *
200 * @since 0.1.0
201 */
202 function news_add_span_to_tag_cloud( $cloud ) {
203 $cloud = preg_replace( "/>(.*?)<\/a>/", "><span>$1</span></a>", $cloud );
204 return $cloud;
205 }
206
207 /**
208 * Adds 'class="prev" to the previous comments link.
209 *
210 * @since 0.1.0
211 */
212 function news_previous_comments_link_attributes( $attributes ) {
213 return $attributes . ' class="prev"';
214 }
215
216 /**
217 * Adds 'class="next" to the next comments link.
218 *
219 * @since 0.1.0
220 */
221 function news_next_comments_link_attributes( $attributes ) {
222 return $attributes . ' class="next"';
223 }
224
225 /**
226 * Returns the current comments page.
227 *
228 * @since 0.1.0
229 */
230 function news_get_current_comments_page() {
231 $cpage = get_query_var( 'cpage' );
232
233 return ( ( empty( $cpage ) ) ? 1 : absint( $cpage ) );
234 }
235
236 /**
237 * Custom comment form arguments.
238 *
239 * @since 0.2.0
240 * @param array $args The arguments for the comments form.
241 */
242 function news_comment_form_defaults( $args ) {
243
b67e8bf @justintadlock Change all instances of hybrid_get_textdomain() to 'news'.
authored
244 $args['label_submit'] = esc_attr__( 'Submit', 'news' );
217f7fd Importing the News theme files and folders.
greenshady authored
245
246 return $args;
247 }
248
249 /**
250 * Filters 'get_shortlink' because WordPress only creates shortlinks for the 'post' post type. We need
251 * a shortlink for pages and attachments. Note that this doesn't handle custom post types since we
252 * wouldn't really be making them "short" anyway. Most users looking for good shortlink solutions should
253 * use a shortlink plugin, especially when dealing with custom post types.
254 *
255 * @since 0.1.0
256 */
257 function news_filter_shortlink( $shortlink, $id, $context ) {
258
259 /* Get the post based on ID. */
260 $post = get_post( $id );
261
262 /* If not a post, just return the shortlink. */
263 if ( empty( $post ) )
264 return $shortlink;
265
266 /* Add a default shortlink for pages. */
267 if ( 'page' == $post->post_type )
268 $shortlink = home_url( "?page_id={$id}" );
269
270 /* Add a default shortlink for attachments. */
271 elseif ( 'attachment' == $post->post_type )
272 $shortlink = home_url( "?attachment_id={$id}" );
273
274 /* Return the shortlink. */
275 return $shortlink;
276 }
277
278 /**
279 * Adds "class='video-wrap'" to the opening <p> element around video embeds.
280 *
281 * @since 0.1.0
282 */
283 function news_video_embed_wrapper( $content ) {
284
285 if ( is_singular( 'video' ) && in_the_loop() )
286 $content = preg_replace( array( "/<p>(.*?)<object/", "/<p>(.*?)<iframe/" ), array( "<p class='video-wrap'>$1<object", "<p class='video-wrap'>$1<iframe" ), $content );
287
288 return $content;
289 }
290
291 /**
292 * Overwrites the default widths for embeds. This is especially useful for making sure videos properly
293 * expand the full width on video pages. This function overwrites what the $content_width variable handles
294 * with context-based widths.
295 *
296 * @since 0.1.0
297 */
298 function news_embed_defaults( $args ) {
299 if ( is_singular( 'video' ) || is_singular( 'slideshow' ) )
300 $args['width'] = 640;
301 else
302 $args['width'] = 560;
303
304 return $args;
305 }
306
307 /**
308 * Shortens the excerpt length so that auto-excerpts fit nicely into the design. This isn't bulletproof since
309 * the excerpt length is determined by words rather than characters. Child themes can also filter the
310 * 'excerpt_length' hook to make this longer or shorter.
311 *
312 * @since 0.1.0
313 */
314 function news_excerpt_length( $length ) {
315 return 40;
316 }
317
318 /**
319 * Add additional settings to the theme settings array.
320 *
321 * @since 0.1.0
322 */
323 function news_theme_settings( $settings ) {
324 $settings['home_template_categories'] = array();
325
326 return $settings;
327 }
328
329 /**
330 * Function for grabbing a post ID by meta key and meta value. We're using this in the sidebar-feature.php
331 * file to check if a page has been given the 'page-template-popular.php' page template.
332 *
333 * @since 0.1.0
334 */
335 function news_get_post_by_meta( $meta_key = '', $meta_value = '' ) {
336 global $wpdb;
337
338 $post_id = $wpdb->get_var( $wpdb->prepare( "SELECT post_id FROM $wpdb->postmeta WHERE meta_key = %s AND meta_value = %s LIMIT 1", $meta_key, $meta_value ) );
339
340 if ( !empty( $post_id ) )
341 return $post_id;
342
343 return false;
344 }
345
7bf89bb @justintadlock Remove functions associated with post types.
authored
346 /* == Functions removed in version 0.3 == */
347
348 function news_flush_rewrite_rules() {}
349
217f7fd Importing the News theme files and folders.
greenshady authored
350 /* == Functions removed in version 0.2 == */
351
352 function news_get_header_sidebar() {}
353 function news_get_secondary_menu() {}
354 function news_get_subsidiary_menu() {}
355 function news_breadcrumb_trail_args() {}
356 function news_unregister_sidebars() {}
357 function news_register_sidebars() {}
358 function news_register_menus() {}
359
360 ?>
Something went wrong with that request. Please try again.