This repository has been archived by the owner on Mar 29, 2021. It is now read-only.
/
functions.php
236 lines (204 loc) · 5.96 KB
/
functions.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
<?php
/**
* @package WordPress
* @subpackage Chunk
*/
/**
* Set the content width based on the theme's design and stylesheet.
*/
if ( ! isset( $content_width ) )
$content_width = 580;
/**
* Make theme available for translation
* Translations can be filed in the /languages/ directory
*/
load_theme_textdomain( 'chunk', get_template_directory_uri() . '/languages' );
$locale = get_locale();
$locale_file = get_template_directory_uri() . "/languages/$locale.php";
if ( is_readable( $locale_file ) )
require_once( $locale_file );
/**
* Add feed links to head
*/
add_theme_support( 'automatic-feed-links' );
/**
* This theme uses wp_nav_menu() in one location.
*/
register_nav_menus( array(
'primary' => __( 'Main Menu', 'chunk' ),
'social' => __( 'Social Menu', 'chunk' ),
) );
/**
* Enable Post Formats
*/
add_theme_support( 'post-formats', array( 'aside', 'gallery', 'image', 'quote', 'link', 'audio', 'chat', 'video' ) );
/**
* Add custom background support.
*/
add_custom_background();
/**
* Get our wp_nav_menu() fallback, wp_page_menu(), to show a home link.
*/
function chunk_page_menu_args( $args ) {
$args['show_home'] = true;
return $args;
}
add_filter( 'wp_page_menu_args', 'chunk_page_menu_args' );
/**
* Register our footer widget area
*/
function chunk_widgets_init() {
register_sidebar( array(
'name' => __( 'Footer', 'chunk' ),
'id' => 'sidebar-1',
'before_widget' => '<aside id="%1$s" class="widget %2$s">',
'after_widget' => "</aside>",
'before_title' => '<h3 class="widget-title">',
'after_title' => '</h3>',
) );
register_sidebar( array(
'name' => __( 'Social', 'chunk' ),
'id' => 'sidebar-social',
'before_widget' => '<div class="social-links">',
'after_widget' => "</div>",
'before_title' => '<h3 class="widget-title">',
'after_title' => '</h3>',
) );
}
add_action( 'widgets_init', 'chunk_widgets_init' );
/**
* Custom Header.
*/
define( 'HEADER_TEXTCOLOR', '000' );
// By leaving empty, we default to random image rotation.
define( 'HEADER_IMAGE', '' );
define( 'HEADER_IMAGE_WIDTH', 800 );
define( 'HEADER_IMAGE_HEIGHT', 140 );
add_custom_image_header( 'chunk_header_style', 'chunk_admin_header_style' );
/**
* Styles the header image displayed on the Appearance > Header admin panel.
*/
function chunk_admin_header_style() {
?>
<style type="text/css">
#headimg {
width: <?php echo HEADER_IMAGE_WIDTH; ?>px;
height: <?php echo HEADER_IMAGE_HEIGHT; ?>px;
}
#heading,
#headimg h1,
#headimg #desc {
display: none;
}
</style>
<?php
}
/**
* Styles the header image and text displayed on the blog.
*/
function chunk_header_style() {
// If no custom options for text are set, let's bail
// get_header_textcolor() options: HEADER_TEXTCOLOR is default, hide text (returns 'blank') or any hex value
if ( HEADER_TEXTCOLOR == get_header_textcolor() )
return;
// If we get this far, we have custom styles. Let's do this.
?>
<style type="text/css">
<?php
// Has the text been hidden?
if ( 'blank' == get_header_textcolor() ) :
?>
#site-title,
#site-description {
position: absolute !important;
clip: rect(1px 1px 1px 1px); /* IE6, IE7 */
clip: rect(1px, 1px, 1px, 1px);
}
#header {
min-height: 0;
}
<?php
// If the user has set a custom color for the text use that
else :
?>
#site-title a {
color: #<?php echo get_header_textcolor(); ?> !important;
}
<?php endif; ?>
</style>
<?php
}
/**
* Enqueue font styles.
*/
function chunk_fonts() {
wp_enqueue_style( 'oswald', 'http://fonts.googleapis.com/css?family=Oswald' );
}
add_action( 'wp_enqueue_scripts', 'chunk_fonts' );
/**
* Audio player.
*/
function chunk_scripts() {
wp_register_style( 'patricia-lutz-custom', get_template_directory_uri() . '/css/style.css' );
wp_register_script( 'patricia-lutz-custom', get_template_directory_uri() . '/js/scripts.js', array( 'jquery' ), '', true );
if ( ! is_singular() || ( is_singular() && 'audio' == get_post_format() ) ) {
wp_enqueue_script( 'audio-player', get_template_directory_uri() . '/js/audio-player.js', array( 'jquery' ), '20110823' );
wp_register_script( 'cdnjquery', '//cdnjs.cloudflare.com/ajax/libs/jquery/1.8.0/jquery.min.js');
wp_enqueue_script( 'cdnjquery' );
}
wp_enqueue_style( 'patricia-lutz-custom' );
wp_enqueue_script( 'patricia-lutz-custom' );
}
add_action( 'wp_enqueue_scripts', 'chunk_scripts' );
function chunk_add_audio_support() {
if ( ! is_singular() || ( is_singular() && 'audio' == get_post_format() ) ) {
?>
<script type="text/javascript">
AudioPlayer.setup( "<?php echo get_template_directory_uri(); ?>/swf/player.swf", {
bg: "e4e4e4",
leftbg: "e4e4e4",
rightbg: "e4e4e4",
track: "222222",
text: "555555",
lefticon: "eeeeee",
righticon: "eeeeee",
border: "e4e4e4",
tracker: "eb374b",
loader: "666666"
});
</script>
<?php }
}
add_action( 'wp_head', 'chunk_add_audio_support' );
/**
* Return the URL for the first link found in this post.
*
* @param string the_content Post content, falls back to current post content if empty.
* @return string|bool URL or false when no link is present.
*/
function chunk_url_grabber( $the_content = '' ) {
if ( empty( $the_content ) )
$the_content = get_the_content();
if ( ! preg_match( '/<a\s[^>]*?href=[\'"](.+?)[\'"]/is', $the_content, $matches ) )
return false;
return esc_url_raw( $matches[1] );
}
/**
* Return the first audio file found for a post.
*
* @param int post_id ID for parent post
* @return boolean|string Path to audio file
*/
function chunk_audio_grabber( $post_id ) {
global $wpdb;
$first_audio = $wpdb->get_var( $wpdb->prepare( "SELECT guid FROM $wpdb->posts WHERE post_parent = %d AND post_type = 'attachment' AND INSTR(post_mime_type, 'audio') ORDER BY menu_order ASC LIMIT 0,1", (int) $post_id ) );
if ( ! empty( $first_audio ) )
return $first_audio;
return false;
}
/* Return slug name */
function post_name() {
global $post;
$title = sanitize_title($post->post_title);
echo $title;
}