-
Notifications
You must be signed in to change notification settings - Fork 15
/
functions.php
194 lines (166 loc) · 5.27 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
<?php
namespace DevHub;
/**
* Custom template tags for this theme.
*/
require __DIR__ . '/inc/template-tags.php';
/**
* Custom functions that act independently of the theme templates.
*/
require __DIR__ . '/inc/extras.php';
/**
* Customizer additions.
*/
require __DIR__ . '/inc/customizer.php';
/**
* Load Jetpack compatibility file.
*/
require __DIR__ . '/inc/jetpack.php';
if ( ! function_exists( 'loop_pagination' ) ) {
require __DIR__ . '/php/loop-pagination.php';
}
if ( ! function_exists( 'breadcrumb_trail' ) ) {
require __DIR__ . '/php/breadcrumb-trail.php';
}
/**
* Set the content width based on the theme's design and stylesheet.
*/
if ( ! isset( $content_width ) ) {
$content_width = 640; /* pixels */
}
add_action( 'init', __NAMESPACE__ . '\\init' );
function init() {
register_post_types();
register_taxonomies();
add_action( 'widgets_init', __NAMESPACE__ . '\\widgets_init' );
add_action( 'pre_get_posts', __NAMESPACE__ . '\\pre_get_posts' );
add_action( 'wp_enqueue_scripts', __NAMESPACE__ . '\\theme_scripts_styles' );
add_filter( 'post_type_link', __NAMESPACE__ . '\\method_permalink', 10, 2 );
add_theme_support( 'automatic-feed-links' );
add_theme_support( 'post-thumbnails' );
}
/**
* widgets_init function.
*
* @access public
* @return void
*/
function widgets_init() {
register_sidebar( array(
'name' => __( 'Sidebar', 'wporg-developer' ),
'id' => 'sidebar-1',
'before_widget' => '<aside id="%1$s" class="box gray widget %2$s">',
'after_widget' => '</div></aside>',
'before_title' => '<h1 class="widget-title">',
'after_title' => '</h1><div class="widget-content">',
) );
}
/**
* @param \WP_Query $query
*/
function pre_get_posts( $query ) {
if ( $query->is_main_query() && $query->is_post_type_archive() ) {
$query->set( 'orderby', 'title' );
$query->set( 'order', 'ASC' );
}
}
/**
* Register the function and class post types
*/
function register_post_types() {
$supports = array(
'comments',
'custom-fields',
'editor',
'excerpt',
'revisions',
'title',
);
// Functions
register_post_type( 'wpapi-function', array(
'has_archive' => 'functions',
'label' => __( 'Functions', 'wporg' ),
'public' => true,
'rewrite' => array(
'feeds' => false,
'slug' => 'reference/function',
'with_front' => false,
),
'supports' => $supports,
) );
// Methods
add_rewrite_rule( 'method/([^/]+)/([^/]+)/?$', 'index.php?post_type=wpapi-function&name=$matches[1]-$matches[2]', 'top' );
// Classes
register_post_type( 'wpapi-class', array(
'has_archive' => 'classes',
'label' => __( 'Classes', 'wporg' ),
'public' => true,
'rewrite' => array(
'feeds' => false,
'slug' => 'reference/class',
'with_front' => false,
),
'supports' => $supports,
) );
// Hooks
register_post_type( 'wpapi-hook', array(
'has_archive' => 'hooks',
'label' => __( 'Hooks', 'wporg' ),
'public' => true,
'rewrite' => array(
'feeds' => false,
'slug' => 'reference/hook',
'with_front' => false,
),
'supports' => $supports,
) );
}
/**
* Register the file and @since taxonomies
*/
function register_taxonomies() {
// Files
register_taxonomy( 'wpapi-source-file', array( 'wpapi-class', 'wpapi-function', 'wpapi-hook' ), array(
'label' => __( 'Files', 'wporg' ),
'public' => true,
'rewrite' => array( 'slug' => 'reference/files' ),
'sort' => false,
'update_count_callback' => '_update_post_term_count',
) );
// Package
register_taxonomy( 'wpapi-package', array( 'wpapi-class', 'wpapi-function', 'wpapi-hook' ), array(
'hierarchical' => true,
'label' => '@package',
'public' => true,
'rewrite' => array( 'slug' => 'reference/package' ),
'sort' => false,
'update_count_callback' => '_update_post_term_count',
) );
// @since
register_taxonomy( 'wpapi-since', array( 'wpapi-class', 'wpapi-function', 'wpapi-hook' ), array(
'hierarchical' => true,
'label' => __( '@since', 'wporg' ),
'public' => true,
'rewrite' => array( 'slug' => 'reference/since' ),
'sort' => false,
'update_count_callback' => '_update_post_term_count',
) );
}
function method_permalink( $link, $post ) {
if ( $post->post_type !== 'wpapi-function' || $post->post_parent == 0 )
return $link;
list( $class, $method ) = explode( '-', $post->post_name );
$link = home_url( user_trailingslashit( "method/$class/$method" ) );
return $link;
}
function theme_scripts_styles() {
wp_enqueue_style( 'dashicons' );
wp_enqueue_style( 'open-sans', '//fonts.googleapis.com/css?family=Open+Sans:300italic,400italic,600italic,400,300,600' );
wp_enqueue_style( 'wporg-developer-style', get_stylesheet_uri() );
wp_enqueue_style( 'wp-dev-sass-compiled', get_template_directory_uri() . '/main.css', array( 'wporg-developer-style' ) );
wp_enqueue_script( 'wporg-developer-navigation', get_template_directory_uri() . '/js/navigation.js', array(), '20120206', true );
wp_enqueue_script( 'wporg-developer-skip-link-focus-fix', get_template_directory_uri() . '/js/skip-link-focus-fix.js', array(), '20130115', true );
if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
wp_enqueue_script( 'comment-reply' );
}
}