- Timestamp:
- 06/16/2014 11:56:42 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/plugins/handbook/handbook.php
r474 r705 10 10 require_once dirname( __FILE__ ) . '/inc/email-post-changes.php'; 11 11 12 WPorg_Handbook_Glossary::init(); 13 new WPorg_Handbook_TOC; 12 //WPorg_Handbook_Glossary::init(); 13 14 /** 15 * Initialize our handbooks 16 * 17 */ 18 class WPorg_Handbook_Init { 19 20 static function init() { 21 22 $post_types = 'handbook'; 23 24 $post_types = apply_filters( 'handbook_post_types', $post_types ); 25 26 if ( ! is_array( $post_types ) ) { 27 $post_types = (array) $post_types; 28 } 29 30 new WPorg_Handbook_TOC( $post_types ); 31 32 foreach ( $post_types as $type ) { 33 new WPorg_Handbook( $type ); 34 35 } 36 } 37 } 38 add_action( 'after_setup_theme', array( 'WPorg_Handbook_Init', 'init' ) ); 14 39 15 40 class WPorg_Handbook { 41 42 public $post_type = ''; 43 44 protected $label = ''; 16 45 17 46 static function caps() { … … 31 60 } 32 61 33 function __construct() { 62 function __construct( $type ) { 63 if ( 'handbook' != $type ) 64 $this->post_type = $type . '-handbook'; 65 66 $this->label = ucwords( str_replace( array( '-', '_' ), ' ', $this->post_type ) ); 34 67 add_filter( 'user_has_cap', array( $this, 'grant_handbook_caps' ) ); 35 68 add_filter( 'init', array( $this, 'register_post_type' ) ); … … 56 89 57 90 function register_post_type() { 58 register_post_type( 'handbook', array( 91 if ( 'handbook' != $this->post_type ) { 92 $slug = 'handbook/' . substr( $this->post_type, 0, -9 ); 93 } else { 94 $slug = 'handbook'; 95 } 96 register_post_type( $this->post_type, array( 59 97 'labels' => array( 60 'name' => 'Handbook Pages', 61 'singular_name' => 'Handbook Page', 62 'menu_name' => 'Handbook', 98 'name' => "{$this->label} Pages", 99 'singular_name' => "{$this->label} Page", 100 'menu_name' => "{$this->label}", 101 'all_items' => "{$this->label} Pages", 63 102 ), 64 103 'public' => true, … … 69 108 'hierarchical' => true, 70 109 'menu_position' => 11, 71 'rewrite' => true, 110 'rewrite' => array( 111 'feeds' => false, 112 'slug' => $slug, 113 'with_front' => false, 114 ), 72 115 'delete_with_user' => false, 73 116 'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'page-attributes', 'custom-fields', 'comments', 'revisions' ), … … 77 120 function admin_page_access_denied() { 78 121 if ( ! current_user_can( 'read' ) ) { 79 wp_redirect( admin_url( 'edit.php?post_type=handbook') );122 wp_redirect( admin_url( "edit.php?post_type={$this->post_type}" ) ); 80 123 exit; 81 124 } … … 83 126 84 127 function post_type_link( $link, $post ) { 85 if ( $post->post_type === 'handbook' && $post->post_name === 'handbook')86 return get_post_type_archive_link( 'handbook');128 if ( $post->post_type === $this->post_type && $post->post_name === $this->post_type ) 129 return get_post_type_archive_link( $this->post_type ); 87 130 return $link; 88 131 } 89 132 90 133 function pre_get_posts( $query ) { 91 if ( $query->is_main_query() && ! $query->is_admin && $query->is_post_type_archive( 'handbook') ) {92 $query->set( 'handbook', 'handbook');134 if ( $query->is_main_query() && ! $query->is_admin && $query->is_post_type_archive( $this->post_type ) ) { 135 $query->set( 'handbook', $this->post_type ); 93 136 } 94 137 } 95 138 96 139 function handbook_sidebar() { 97 if ( ! class_exists( 'P2' ) ) 98 return; 99 100 register_sidebar( array( 'id' => 'handbook', 'name' => 'Handbook', 'description' => 'Used on handbook pages' ) ); 101 140 register_sidebar( array( 'id' => $this->post_type, 'name' => $this->label, 'description' => "Used on {$this->label} pages" ) ); 102 141 require_once dirname( __FILE__ ) . '/inc/widgets.php'; 103 142 register_widget( 'WPorg_Handbook_Pages_Widget' ); … … 105 144 106 145 function wporg_email_changes_for_post_types( $post_types ) { 107 if ( ! in_array( 'handbook', $post_types ) )108 $post_types[] = 'handbook';146 if ( ! in_array( $this->post_type, $post_types ) ) 147 $post_types[] = $this->post_type; 109 148 return $post_types; 110 149 } 111 150 } 112 113 new WPorg_Handbook;
Note: See TracChangeset
for help on using the changeset viewer.