/
functions.php
336 lines (275 loc) · 10.5 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
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
<?php
/**
* @package WordPress
* @subpackage Documentation
* @version 08/09/2012
*/
/**
* Post content often has specified width.
* Thus, images which has bigger size than content width can break up the layout of theme.
* To prevent this situation, WordPress provides one way to specify the maximum image size for themes.
* Define the maximum image size
*/
if ( ! isset( $content_width ) )
$content_width = 900;
if ( ! function_exists( 'documentation_setup' ) ) {
add_action( 'after_setup_theme', 'documentation_setup' );
/**
* Sets up theme defaults and registers support for various WordPress features.
*
* Note that this function is hooked into the after_setup_theme hook, which runs
* before the init hook. The init hook is too late for some features, such as indicating
* support post thumbnails.
*
* @since 1.0.0
* @return void
*/
function documentation_setup() {
/**
* Make Documentation available for translation.
* Translations can be added to the /languages/ directory.
* If you're building a theme based on Documentation, use a find and replace
* to change 'documentation' to the name of your theme in all the template files.
*/
load_theme_textdomain( 'documentation', get_template_directory() . '/languages' );
/**
* Login + Admin Bar Branding
*
* @see https://github.com/bueltge/WordPress-Basis-Theme/tree/namespace/inc/admin
*/
require_once( get_template_directory() . '/inc/class-branding.php' );
new Documentation_Admin_Branding( array() );
// params for options class
$args = array(
'theme_key' => strtolower( get_stylesheet() )
);
/**
* CURRENT DON'T LOAD WITHOUT CUSTOMIZER; BUT WITH MORE WORK FOR CODERS
// Load up our theme options page and related code.
require_once( get_template_directory() . '/inc/theme-options.php' );
$documentation_options = new Documentation_Options( $args );
*/
// Include the theme customizer for options of theme options
require_once( get_template_directory() . '/inc/theme-customize.php' );
$documentation_customize = new Documentation_Customize( $args );
// include to write the custom theme options in theme head
require_once( get_template_directory() . '/inc/head-style.php' );
$documentation_head_style = new Documentation_Head_Style( $args );
// Add default posts and comments RSS feed links to <head>.
add_theme_support( 'automatic-feed-links' );
// This theme uses wp_nav_menu() in one location.
register_nav_menu( 'primary', __( 'Primary Menu', 'documentation' ) );
// Add support for custom background.
$args = array(
'default-image' => '',
'default-color' => 'fff',
'wp-head-callback' => '_custom_background_cb',
'admin-head-callback' => '',
'admin-preview-callback' => ''
);
add_theme_support( 'custom-background', $args );
// define suffix for development on scripts and styles
$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '.dev' : '';
// This theme styles the visual editor with editor-style.css to match the theme style.
add_editor_style( 'css/editor-style' . $suffix . '.css' );
}
} // end if func exists
if ( ! function_exists( 'documentation_get_options' ) ) {
/**
* Return options value or array of all values
* Small wrapper for the class
*
* @since 08/09/2012
* @return String, Array Value of the options item
*/
function documentation_get_options( $value = '' ) {
// failed to load file for options, then return NULL
if ( ! class_exists( 'Documentation_Customize' ) )
return NULL;
$documentation_options = new Documentation_Customize();
$options = $documentation_options->get_theme_options();
if ( ! empty( $value ) )
$options = $options[$value];
return $options;
}
} // end if func exists
if ( ! function_exists( 'documentation_scripts_styles' ) ) {
add_action( 'wp_enqueue_scripts', 'documentation_scripts_styles' );
/**
* Enqueue scripts and styles for front-end.
*
* @since 2.0
*/
function documentation_scripts_styles() {
// set suffix for debug mode
$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '.dev' : '';
/**
* Add JavaScript to pages with the comment form to support
* sites with threaded comments (when in use).
*/
if ( is_singular() && comments_open() && get_option( 'thread_comments' ) )
wp_enqueue_script( 'comment-reply' );
// Register main and print CSS file
wp_register_style( 'documentation-style', get_stylesheet_directory_uri() . '/css/style' . $suffix . '.css' );
wp_register_style(
'documentation-print-style',
get_stylesheet_directory_uri() . '/css/print' . $suffix . '.css',
array(),
FALSE,
'print'
);
wp_enqueue_style( 'documentation-style' );
wp_enqueue_style( 'documentation-print-style' );
}
} // end if func exists
if ( ! function_exists( 'documentation_widgets_init' ) ) {
add_action( 'widgets_init', 'documentation_widgets_init' );
/**
* Register widgetized areas
*
* @return void
*/
function documentation_widgets_init() {
// Area 1
register_sidebar( array (
'name' => __( 'Primary Widget Area', 'documentation' ),
'id' => 'primary-widget-area',
'description' => __( 'The primary widget area is visible on all pages and posts.', 'documentation' ),
'before_widget' => '<li id="%1$s" class="widget-container %2$s">',
'after_widget' => "</li>",
'before_title' => '<h3 class="widget-title">',
'after_title' => '</h3>',
) );
// Area 2
register_sidebar( array (
'name' => __( 'Secondary Widget Area', 'documentation' ),
'id' => 'secondary-widget-area',
'description' => __( 'The secondary widget area down below Primary Widget Area only on pages and posts.' , 'documentation' ),
'before_widget' => '<li id="%1$s" class="widget-container %2$s">',
'after_widget' => "</li>",
'before_title' => '<h3 class="widget-title">',
'after_title' => '</h3>',
) );
} // end theme_widgets_init
} // end if func exists
if ( ! function_exists( 'documentation_comment' ) ) {
/**
* Template for comments and pingbacks.
*
* To override this walker in a child theme without modifying the comments template
* simply create your own documentation_comment(), and that function will be used instead.
*
* Used as a callback by wp_list_comments() for displaying the comments.
*
* @since 2.0.0
* @param $comment
* @param $args
* @param $depth
* @return void
*/
function documentation_comment( $comment, $args, $depth ) {
$GLOBALS['comment'] = $comment;
switch ( $comment->comment_type ) :
case 'pingback' :
case 'trackback' :
?>
<li class="post pingback">
<p><?php _e( 'Pingback:', 'documentation' ); ?> <?php comment_author_link(); ?><?php edit_comment_link( __( 'Edit', 'documentation' ), '<span class="edit-link">', '</span>' ); ?></p>
<?php
break;
default :
?>
<li <?php comment_class(); ?> id="li-comment-<?php comment_ID(); ?>">
<article id="comment-<?php comment_ID(); ?>" class="comment">
<footer class="comment-meta">
<div class="comment-author vcard">
<?php
$avatar_size = 68;
if ( '0' != $comment->comment_parent )
$avatar_size = 39;
echo get_avatar( $comment, $avatar_size );
/* translators: 1: comment author, 2: date and time */
printf( __( '%1$s on %2$s <span class="says">said:</span>', 'documentation' ),
sprintf( '<span class="fn">%s</span>', get_comment_author_link() ),
sprintf( '<a href="%1$s"><time pubdate datetime="%2$s">%3$s</time></a>',
esc_url( get_comment_link( $comment->comment_ID ) ),
get_comment_time( 'c' ),
/* translators: 1: date, 2: time */
sprintf( __( '%1$s at %2$s', 'documentation' ), get_comment_date(), get_comment_time() )
)
);
?>
<?php edit_comment_link( __( 'Edit', 'documentation' ), '<span class="edit-link">', '</span>' ); ?>
</div><!-- .comment-author .vcard -->
<?php if ( $comment->comment_approved == '0' ) : ?>
<em class="comment-awaiting-moderation"><?php _e( 'Your comment is awaiting moderation.', 'documentation' ); ?></em>
<br />
<?php endif; ?>
</footer>
<div class="comment-content"><?php comment_text(); ?></div>
<div class="reply">
<?php comment_reply_link( array_merge( $args, array( 'reply_text' => __( 'Reply <span>↓</span>', 'documentation' ), 'depth' => $depth, 'max_depth' => $args['max_depth'] ) ) ); ?>
</div><!-- .reply -->
</article><!-- #comment-## -->
<?php
break;
endswitch;
}
} // end if function exists
if ( ! function_exists( 'documentation_get_paginate_bar' ) ) {
/**
* Create a pagination bar
*
* @since 08/09/2012
* @param $args Array see default array inside fct.
* @return $pagination String
*/
function documentation_get_paginate_bar( $args = FALSE ) {
global $wp_rewrite, $wp_query;
$wp_query->query_vars['paged'] > 1 ? $current = $wp_query->query_vars['paged'] : $current = 1;
if ( empty($rules) )
$rulestouse = @add_query_arg( 'paged','%#%' );
else
$rulestouse = @add_query_arg( 'page','%#%' );
if ( ! $args ) {
// default arguments
$args = array(
'base' => $rulestouse,
'format' => '',
'total' => $wp_query->max_num_pages,
'current' => $current,
'show_all' => FALSE,
'prev_next' => TRUE,
'prev_text' => __( '« Previous', 'documentation' ),
'next_text' => __( 'Next »', 'documentation' ),
'end_size' => 3,
'mid_size' => 5,
'type' => 'plain',
'add_args' => FALSE, // array of query args to add
'add_fragment' => '',
'show_total' => FALSE,
'display' => TRUE,
'markup' => 'div'
);
}
if ( $wp_rewrite->using_permalinks() ) {
$args['base'] = user_trailingslashit(
trailingslashit( remove_query_arg( 's', get_pagenum_link(1) ) ) . 'page/%#%/', 'paged'
);
}
if ( ! empty( $wp_query->query_vars['s'] ) )
$args['add_args'] = array( 's' => get_query_var('s') );
$pagination = paginate_links( $args );
if ( $args['show_total'] )
$pagination .= sprintf( __( ' (%d)', 'documentation' ), $wp_query->max_num_pages );
if ( ! empty( $args['markup'] ) )
$pagination = apply_filters(
'documentation_paginate_bar',
'<' . $args['markup'] . ' class="paginate_bar">' . $pagination . '</' . $args['markup'] . '>'
);
if ( $args['display'] && 1 < $wp_query->max_num_pages )
echo $pagination;
else
return $pagination;
}
} // end if function exists