Changeset 554 for sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/functions.php
- Timestamp:
- 04/24/2014 10:19:39 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/functions.php
r69 r554 1 1 <?php 2 2 3 4 add_action( 'wp_enqueue_scripts', 'theme_scripts_styles' ); 3 namespace DevHub; 4 5 /** 6 * Custom template tags for this theme. 7 */ 8 require __DIR__ . '/inc/template-tags.php'; 9 10 /** 11 * Custom functions that act independently of the theme templates. 12 */ 13 require __DIR__ . '/inc/extras.php'; 14 15 /** 16 * Customizer additions. 17 */ 18 require __DIR__ . '/inc/customizer.php'; 19 20 /** 21 * Load Jetpack compatibility file. 22 */ 23 require __DIR__ . '/inc/jetpack.php'; 24 25 if ( ! function_exists( 'loop_pagination' ) ) { 26 require __DIR__ . '/inc/loop-pagination.php'; 27 } 28 29 if ( ! function_exists( 'breadcrumb_trail' ) ) { 30 require __DIR__ . '/inc/breadcrumb-trail.php'; 31 } 32 33 /** 34 * Set the content width based on the theme's design and stylesheet. 35 */ 36 if ( ! isset( $content_width ) ) { 37 $content_width = 640; /* pixels */ 38 } 39 40 41 add_action( 'init', __NAMESPACE__ . '\\init' ); 42 43 44 function init() { 45 46 register_post_types(); 47 register_taxonomies(); 48 add_action( 'widgets_init', __NAMESPACE__ . '\\widgets_init' ); 49 add_action( 'pre_get_posts', __NAMESPACE__ . '\\pre_get_posts' ); 50 add_action( 'wp_enqueue_scripts', __NAMESPACE__ . '\\theme_scripts_styles' ); 51 add_filter( 'post_type_link', __NAMESPACE__ . '\\method_permalink', 10, 2 ); 52 add_theme_support( 'automatic-feed-links' ); 53 add_theme_support( 'post-thumbnails' ); 54 55 // Temporarily disable comments 56 add_filter( 'comments_open', '__return_false' ); 57 } 58 59 60 /** 61 * widgets_init function. 62 * 63 * @access public 64 * @return void 65 */ 66 function widgets_init() { 67 register_sidebar( array( 68 'name' => __( 'Sidebar', 'wporg' ), 69 'id' => 'sidebar-1', 70 'before_widget' => '<aside id="%1$s" class="box gray widget %2$s">', 71 'after_widget' => '</div></aside>', 72 'before_title' => '<h1 class="widget-title">', 73 'after_title' => '</h1><div class="widget-content">', 74 ) ); 75 } 76 77 /** 78 * @param \WP_Query $query 79 */ 80 function pre_get_posts( $query ) { 81 82 if ( $query->is_main_query() && $query->is_post_type_archive() ) { 83 $query->set( 'orderby', 'title' ); 84 $query->set( 'order', 'ASC' ); 85 } 86 } 87 88 /** 89 * Register the function and class post types 90 */ 91 function register_post_types() { 92 $supports = array( 93 'comments', 94 'custom-fields', 95 'editor', 96 'excerpt', 97 'revisions', 98 'title', 99 ); 100 101 // Functions 102 register_post_type( 'wp-parser-function', array( 103 'has_archive' => 'reference/functions', 104 'label' => __( 'Functions', 'wporg' ), 105 'labels' => array( 106 'name' => __( 'Functions', 'wporg' ), 107 'singular_name' => __( 'Function', 'wporg' ), 108 'all_items' => __( 'Functions', 'wporg' ), 109 'new_item' => __( 'New Function', 'wporg' ), 110 'add_new' => __( 'Add New', 'wporg' ), 111 'add_new_item' => __( 'Add New Function', 'wporg' ), 112 'edit_item' => __( 'Edit Function', 'wporg' ), 113 'view_item' => __( 'View Function', 'wporg' ), 114 'search_items' => __( 'Search Functions', 'wporg' ), 115 'not_found' => __( 'No Functions found', 'wporg' ), 116 'not_found_in_trash' => __( 'No Functions found in trash', 'wporg' ), 117 'parent_item_colon' => __( 'Parent Function', 'wporg' ), 118 'menu_name' => __( 'Functions', 'wporg' ), 119 ), 120 'public' => true, 121 'rewrite' => array( 122 'feeds' => false, 123 'slug' => 'reference/function', 124 'with_front' => false, 125 ), 126 'supports' => $supports, 127 ) ); 128 129 // Methods 130 add_rewrite_rule( 'method/([^/]+)/([^/]+)/?$', 'index.php?post_type=wp-parser-function&name=$matches[1]-$matches[2]', 'top' ); 131 132 // Classes 133 register_post_type( 'wp-parser-class', array( 134 'has_archive' => 'reference/classes', 135 'label' => __( 'Classes', 'wporg' ), 136 'labels' => array( 137 'name' => __( 'Classes', 'wporg' ), 138 'singular_name' => __( 'Class', 'wporg' ), 139 'all_items' => __( 'Classes', 'wporg' ), 140 'new_item' => __( 'New Class', 'wporg' ), 141 'add_new' => __( 'Add New', 'wporg' ), 142 'add_new_item' => __( 'Add New Class', 'wporg' ), 143 'edit_item' => __( 'Edit Class', 'wporg' ), 144 'view_item' => __( 'View Class', 'wporg' ), 145 'search_items' => __( 'Search Classes', 'wporg' ), 146 'not_found' => __( 'No Classes found', 'wporg' ), 147 'not_found_in_trash' => __( 'No Classes found in trash', 'wporg' ), 148 'parent_item_colon' => __( 'Parent Class', 'wporg' ), 149 'menu_name' => __( 'Classes', 'wporg' ), 150 ), 151 'public' => true, 152 'rewrite' => array( 153 'feeds' => false, 154 'slug' => 'reference/class', 155 'with_front' => false, 156 ), 157 'supports' => $supports, 158 ) ); 159 160 // Hooks 161 register_post_type( 'wp-parser-hook', array( 162 'has_archive' => 'reference/hooks', 163 'label' => __( 'Hooks', 'wporg' ), 164 'labels' => array( 165 'name' => __( 'Hooks', 'wporg' ), 166 'singular_name' => __( 'Hook', 'wporg' ), 167 'all_items' => __( 'Hooks', 'wporg' ), 168 'new_item' => __( 'New Hook', 'wporg' ), 169 'add_new' => __( 'Add New', 'wporg' ), 170 'add_new_item' => __( 'Add New Hook', 'wporg' ), 171 'edit_item' => __( 'Edit Hook', 'wporg' ), 172 'view_item' => __( 'View Hook', 'wporg' ), 173 'search_items' => __( 'Search Hooks', 'wporg' ), 174 'not_found' => __( 'No Hooks found', 'wporg' ), 175 'not_found_in_trash' => __( 'No Hooks found in trash', 'wporg' ), 176 'parent_item_colon' => __( 'Parent Hook', 'wporg' ), 177 'menu_name' => __( 'Hooks', 'wporg' ), 178 ), 179 'public' => true, 180 'rewrite' => array( 181 'feeds' => false, 182 'slug' => 'reference/hook', 183 'with_front' => false, 184 ), 185 'supports' => $supports, 186 ) ); 187 188 // Methods 189 register_post_type( 'wp-parser-method', array( 190 'has_archive' => 'reference/methods', 191 'label' => __( 'Methods', 'wporg' ), 192 'labels' => array( 193 'name' => __( 'Methods', 'wporg' ), 194 'singular_name' => __( 'Method', 'wporg' ), 195 'all_items' => __( 'Methods', 'wporg' ), 196 'new_item' => __( 'New Method', 'wporg' ), 197 'add_new' => __( 'Add New', 'wporg' ), 198 'add_new_item' => __( 'Add New Method', 'wporg' ), 199 'edit_item' => __( 'Edit Method', 'wporg' ), 200 'view_item' => __( 'View Method', 'wporg' ), 201 'search_items' => __( 'Search Methods', 'wporg' ), 202 'not_found' => __( 'No Methods found', 'wporg' ), 203 'not_found_in_trash' => __( 'No Methods found in trash', 'wporg' ), 204 'parent_item_colon' => __( 'Parent Method', 'wporg' ), 205 'menu_name' => __( 'Methods', 'wporg' ), 206 ), 207 'public' => true, 208 'rewrite' => array( 209 'feeds' => false, 210 'slug' => 'method', 211 'with_front' => false, 212 ), 213 'supports' => $supports, 214 ) ); 215 } 216 217 /** 218 * Register the file and @since taxonomies 219 */ 220 function register_taxonomies() { 221 // Files 222 register_taxonomy( 'wp-parser-source-file', array( 'wp-parser-class', 'wp-parser-function', 'wp-parser-hook', 'wp-parser-method' ), array( 223 'label' => __( 'Files', 'wporg' ), 224 'labels' => array( 225 'name' => __( 'Files', 'wporg' ), 226 'singular_name' => _x( 'File', 'taxonomy general name', 'wporg' ), 227 'search_items' => __( 'Search Files', 'wporg' ), 228 'popular_items' => null, 229 'all_items' => __( 'All Files', 'wporg' ), 230 'parent_item' => __( 'Parent File', 'wporg' ), 231 'parent_item_colon' => __( 'Parent File:', 'wporg' ), 232 'edit_item' => __( 'Edit File', 'wporg' ), 233 'update_item' => __( 'Update File', 'wporg' ), 234 'add_new_item' => __( 'New File', 'wporg' ), 235 'new_item_name' => __( 'New File', 'wporg' ), 236 'separate_items_with_commas' => __( 'Files separated by comma', 'wporg' ), 237 'add_or_remove_items' => __( 'Add or remove Files', 'wporg' ), 238 'choose_from_most_used' => __( 'Choose from the most used Files', 'wporg' ), 239 'menu_name' => __( 'Files', 'wporg' ), 240 ), 241 'public' => true, 242 'rewrite' => array( 'slug' => 'reference/files' ), 243 'sort' => false, 244 'update_count_callback' => '_update_post_term_count', 245 ) ); 246 247 // Package 248 register_taxonomy( 'wp-parser-package', array( 'wp-parser-class', 'wp-parser-function', 'wp-parser-hook', 'wp-parser-method' ), array( 249 'hierarchical' => true, 250 'label' => '@package', 251 'public' => true, 252 'rewrite' => array( 'slug' => 'reference/package' ), 253 'sort' => false, 254 'update_count_callback' => '_update_post_term_count', 255 ) ); 256 257 // @since 258 register_taxonomy( 'wp-parser-since', array( 'wp-parser-class', 'wp-parser-function', 'wp-parser-hook', 'wp-parser-method' ), array( 259 'hierarchical' => true, 260 'label' => __( '@since', 'wporg' ), 261 'public' => true, 262 'rewrite' => array( 'slug' => 'reference/since' ), 263 'sort' => false, 264 'update_count_callback' => '_update_post_term_count', 265 ) ); 266 } 267 268 function method_permalink( $link, $post ) { 269 if ( $post->post_type !== 'wp-parser-function' || $post->post_parent == 0 ) 270 return $link; 271 272 list( $class, $method ) = explode( '-', $post->post_name ); 273 $link = home_url( user_trailingslashit( "method/$class/$method" ) ); 274 return $link; 275 } 276 5 277 function theme_scripts_styles() { 6 wp_enqueue_style( 'wp-doc-style', get_stylesheet_uri() ); 7 wp_enqueue_style( 'droid-sans-mono', '//fonts.googleapis.com/css?family=Droid+Sans+Mono' ); 8 9 ## wp_enqueue_script( 'ace-editor', 'http://rawgithub.com/ajaxorg/ace-builds/master/src-noconflict/ace.js' ); 10 } 11 12 function wp_doc_comment( $comment, $args, $depth ) { 13 ?> 14 <li <?php comment_class(); ?> id="li-comment-<?php comment_ID(); ?>"> 15 <article id="comment-<?php comment_ID(); ?>" class="comment"> 16 17 <?php if ( $comment->comment_approved == '0' ) : ?> 18 <em class="comment-awaiting-moderation"><?php _e('Your example is awaiting moderation.'); ?></em> 19 <br /> 20 <?php endif; ?> 21 22 <pre class="example-content"><?php echo htmlentities( get_comment_text() ); ?></pre> 23 24 <footer class="comment-meta"> 25 <div class="comment-author vcard"> 26 <?php 27 echo get_avatar( $comment ); 28 29 /* translators: 1: comment author, 2: date and time */ 30 printf( __('Contributed by %1$s on %2$s'), 31 sprintf( '<span class="fn">%s</span>', get_comment_author_link() ), 32 sprintf( '<a href="%1$s"><time datetime="%2$s">%3$s</time></a>', 33 esc_url( get_comment_link( $comment->comment_ID ) ), 34 get_comment_time( 'c' ), 35 /* translators: 1: date, 2: time */ 36 sprintf( __('%1$s at %2$s'), get_comment_date(), get_comment_time() ) 37 ) 38 ); 39 ?> 40 41 <?php edit_comment_link( __('Edit'), '<span class="edit-link">', '</span>' ); ?> 42 </div><!-- .comment-author .vcard --> 43 44 </footer> 45 46 </article><!-- #comment-## --> 47 48 <?php 49 } 50 278 wp_enqueue_style( 'dashicons' ); 279 wp_enqueue_style( 'open-sans', '//fonts.googleapis.com/css?family=Open+Sans:300italic,400italic,600italic,400,300,600' ); 280 wp_enqueue_style( 'wporg-developer-style', get_stylesheet_uri() ); 281 wp_enqueue_style( 'wp-dev-sass-compiled', get_template_directory_uri() . '/main.css', array( 'wporg-developer-style' ), '20140424' ); 282 wp_enqueue_script( 'wporg-developer-navigation', get_template_directory_uri() . '/js/navigation.js', array(), '20120206', true ); 283 wp_enqueue_script( 'wporg-developer-skip-link-focus-fix', get_template_directory_uri() . '/js/skip-link-focus-fix.js', array(), '20130115', true ); 284 if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) { 285 wp_enqueue_script( 'comment-reply' ); 286 } 287 }
Note:
See TracChangeset
for help on using the changeset viewer.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)