Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 361 lines (295 sloc) 11.715 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. */
703728f @justintadlock Merge the "classes" and "functions" folders into a new folder called …
authored
50 require_once( trailingslashit( THEME_DIR ) . 'includes/shortcodes.php' );
217f7fd Importing the News theme files and folders.
greenshady authored
51
52 /* Load admin functions. */
53 if ( is_admin() )
703728f @justintadlock Merge the "classes" and "functions" folders into a new folder called …
authored
54 require_once( trailingslashit( THEME_DIR ) . 'includes/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' );
9faa84b @justintadlock User the newer-style 'hybrid-core-javascript' theme feature rather th…
authored
67 add_theme_support( 'hybrid-core-javascript', array( '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' );
891bd15 @justintadlock Add support for the Cleaner Gallery extension to prettify galleries.
authored
75 add_theme_support( 'cleaner-gallery' );
217f7fd Importing the News theme files and folders.
greenshady authored
76
77 /* Register shortcodes. */
78 add_action( 'init', 'news_register_shortcodes' );
79
80 /* Register new image sizes. */
81 add_action( 'init', 'news_register_image_sizes' );
82
83 /* Register additional widgets. */
84 add_action( 'widgets_init', 'news_register_widgets' );
85
86 /* Load JavaScript. */
87 add_action( 'wp_enqueue_scripts', 'news_enqueue_script' );
88
89 /* Site description. */
90 add_action( "{$prefix}_before_menu_secondary", 'hybrid_site_description' );
91
92 /* Hook additional items to the nav menus. */
93 add_filter( 'wp_nav_menu', 'news_nav_menu_add_items', 10, 2 );
94
95 /* Content. */
96 add_action( "{$prefix}_singular-post_after_loop", 'news_singular_post_tags' );
97
98 /* Tag cloud. */
99 add_filter( 'wp_tag_cloud', 'news_add_span_to_tag_cloud' );
100 add_filter( 'term_links-post_tag', 'news_add_span_to_tag_cloud' );
101
102 /* Embed width/height defaults. */
103 add_filter( 'embed_defaults', 'news_embed_defaults' );
104
105 /* Set content width. */
106 hybrid_set_content_width( 600 );
107
108 /* Allow all post types to have shortlinks. Do this early so plugins can still override. */
109 add_filter( 'get_shortlink', 'news_filter_shortlink', 1, 3 );
110
111 /* Add classes to the comments pagination. */
112 add_filter( 'previous_comments_link_attributes', 'news_previous_comments_link_attributes' );
113 add_filter( 'next_comments_link_attributes', 'news_next_comments_link_attributes' );
114
115 /* Add a wrapper class for singular videos. */
116 add_filter( 'the_content', 'news_video_embed_wrapper', 20 );
117
118 /* Shorter excerpt length. */
119 add_filter( 'excerpt_length', 'news_excerpt_length' );
120
121 /* Comment form arguments. */
122 add_filter( 'comment_form_defaults', 'news_comment_form_defaults', 11 );
123
124 /* Additional default theme settings. */
125 add_filter( "{$prefix}_default_theme_settings", 'news_theme_settings' );
126 }
127
128 /**
129 * Registers additional image sizes, in particular, the 'news-thumbnail' and 'news-slideshow' sizes.
130 *
131 * @since 0.1.0
132 */
133 function news_register_image_sizes() {
134 add_image_size( 'news-slideshow', 600, 400, true );
135 add_image_size( 'news-slideshow-large', 640, 430, true );
136 add_image_size( 'news-thumbnail', 100, 75, true );
137 }
138
139 /**
140 * Loads extra widget files and registers the widgets.
141 *
142 * @since 0.1.0
143 */
144 function news_register_widgets() {
145
146 /* Load the popular tabs widget. */
147 if ( current_theme_supports( 'entry-views' ) ) {
703728f @justintadlock Merge the "classes" and "functions" folders into a new folder called …
authored
148 require_once( trailingslashit( THEME_DIR ) . 'includes/widget-popular-tabs.php' );
217f7fd Importing the News theme files and folders.
greenshady authored
149 register_widget( 'News_Widget_Popular_Tabs' );
150 }
151
152 /* Load the image stream widget. */
703728f @justintadlock Merge the "classes" and "functions" folders into a new folder called …
authored
153 require_once( trailingslashit( THEME_DIR ) . 'includes/widget-image-stream.php' );
217f7fd Importing the News theme files and folders.
greenshady authored
154 register_widget( 'News_Widget_Image_Stream' );
155
156 /* Load the newsletter widget. */
703728f @justintadlock Merge the "classes" and "functions" folders into a new folder called …
authored
157 require_once( trailingslashit( THEME_DIR ) . 'includes/widget-newsletter.php' );
217f7fd Importing the News theme files and folders.
greenshady authored
158 register_widget( 'News_Widget_Newsletter' );
159 }
160
161 /**
162 * Loads the theme JavaScript files.
163 *
164 * @since 0.1.0
165 */
166 function news_enqueue_script() {
167 wp_enqueue_script( 'jquery-ui-tabs' );
061ce9f @justintadlock Use the Hybrid Core drop-downs instead of keeping this in the theme's…
authored
168 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
169 }
170
171 /**
172 * Adds a log in/out link to the secondary menu.
173 *
174 * @since 0.1.0
175 */
176 function news_nav_menu_add_items( $menu, $args ) {
177
178 if ( 'secondary' == $args->theme_location ) {
6b75b39 @justintadlock Use home_url() instead of site_url()
authored
179 $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
180 $menu = str_replace( '</ul></div>', $links . '</ul></div>', $menu );
181 }
182
183 return $menu;
184 }
185
186 /**
187 * Displays the post tags for singular posts.
188 *
189 * @since 0.1.0
190 */
191 function news_singular_post_tags() {
192 if ( has_tag() )
193 echo '<div class="entry-tags">' . do_shortcode( '[entry-terms type="post_tag" separator=""]' ) . '</div>';
194 }
195
196 /**
197 * Wraps tag cloud links with a span for easier background image styling.
198 *
199 * @todo If anyone can figure out a way to style this without the <span>, we can remove this.
200 *
201 * @since 0.1.0
202 */
203 function news_add_span_to_tag_cloud( $cloud ) {
204 $cloud = preg_replace( "/>(.*?)<\/a>/", "><span>$1</span></a>", $cloud );
205 return $cloud;
206 }
207
208 /**
209 * Adds 'class="prev" to the previous comments link.
210 *
211 * @since 0.1.0
212 */
213 function news_previous_comments_link_attributes( $attributes ) {
214 return $attributes . ' class="prev"';
215 }
216
217 /**
218 * Adds 'class="next" to the next comments link.
219 *
220 * @since 0.1.0
221 */
222 function news_next_comments_link_attributes( $attributes ) {
223 return $attributes . ' class="next"';
224 }
225
226 /**
227 * Returns the current comments page.
228 *
229 * @since 0.1.0
230 */
231 function news_get_current_comments_page() {
232 $cpage = get_query_var( 'cpage' );
233
234 return ( ( empty( $cpage ) ) ? 1 : absint( $cpage ) );
235 }
236
237 /**
238 * Custom comment form arguments.
239 *
240 * @since 0.2.0
241 * @param array $args The arguments for the comments form.
242 */
243 function news_comment_form_defaults( $args ) {
244
b67e8bf @justintadlock Change all instances of hybrid_get_textdomain() to 'news'.
authored
245 $args['label_submit'] = esc_attr__( 'Submit', 'news' );
217f7fd Importing the News theme files and folders.
greenshady authored
246
247 return $args;
248 }
249
250 /**
251 * Filters 'get_shortlink' because WordPress only creates shortlinks for the 'post' post type. We need
252 * a shortlink for pages and attachments. Note that this doesn't handle custom post types since we
253 * wouldn't really be making them "short" anyway. Most users looking for good shortlink solutions should
254 * use a shortlink plugin, especially when dealing with custom post types.
255 *
256 * @since 0.1.0
257 */
258 function news_filter_shortlink( $shortlink, $id, $context ) {
259
260 /* Get the post based on ID. */
261 $post = get_post( $id );
262
263 /* If not a post, just return the shortlink. */
264 if ( empty( $post ) )
265 return $shortlink;
266
267 /* Add a default shortlink for pages. */
268 if ( 'page' == $post->post_type )
269 $shortlink = home_url( "?page_id={$id}" );
270
271 /* Add a default shortlink for attachments. */
272 elseif ( 'attachment' == $post->post_type )
273 $shortlink = home_url( "?attachment_id={$id}" );
274
275 /* Return the shortlink. */
276 return $shortlink;
277 }
278
279 /**
280 * Adds "class='video-wrap'" to the opening <p> element around video embeds.
281 *
282 * @since 0.1.0
283 */
284 function news_video_embed_wrapper( $content ) {
285
286 if ( is_singular( 'video' ) && in_the_loop() )
287 $content = preg_replace( array( "/<p>(.*?)<object/", "/<p>(.*?)<iframe/" ), array( "<p class='video-wrap'>$1<object", "<p class='video-wrap'>$1<iframe" ), $content );
288
289 return $content;
290 }
291
292 /**
293 * Overwrites the default widths for embeds. This is especially useful for making sure videos properly
294 * expand the full width on video pages. This function overwrites what the $content_width variable handles
295 * with context-based widths.
296 *
297 * @since 0.1.0
298 */
299 function news_embed_defaults( $args ) {
300 if ( is_singular( 'video' ) || is_singular( 'slideshow' ) )
301 $args['width'] = 640;
302 else
303 $args['width'] = 560;
304
305 return $args;
306 }
307
308 /**
309 * Shortens the excerpt length so that auto-excerpts fit nicely into the design. This isn't bulletproof since
310 * the excerpt length is determined by words rather than characters. Child themes can also filter the
311 * 'excerpt_length' hook to make this longer or shorter.
312 *
313 * @since 0.1.0
314 */
315 function news_excerpt_length( $length ) {
316 return 40;
317 }
318
319 /**
320 * Add additional settings to the theme settings array.
321 *
322 * @since 0.1.0
323 */
324 function news_theme_settings( $settings ) {
325 $settings['home_template_categories'] = array();
326
327 return $settings;
328 }
329
330 /**
331 * Function for grabbing a post ID by meta key and meta value. We're using this in the sidebar-feature.php
332 * file to check if a page has been given the 'page-template-popular.php' page template.
333 *
334 * @since 0.1.0
335 */
336 function news_get_post_by_meta( $meta_key = '', $meta_value = '' ) {
337 global $wpdb;
338
339 $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 ) );
340
341 if ( !empty( $post_id ) )
342 return $post_id;
343
344 return false;
345 }
346
7bf89bb @justintadlock Remove functions associated with post types.
authored
347 /* == Functions removed in version 0.3 == */
348
349 function news_flush_rewrite_rules() {}
350
217f7fd Importing the News theme files and folders.
greenshady authored
351 /* == Functions removed in version 0.2 == */
352
353 function news_get_header_sidebar() {}
354 function news_get_secondary_menu() {}
355 function news_get_subsidiary_menu() {}
356 function news_breadcrumb_trail_args() {}
357 function news_unregister_sidebars() {}
358 function news_register_sidebars() {}
359 function news_register_menus() {}
360
361 ?>
Something went wrong with that request. Please try again.