Changeset 705
- Timestamp:
- 06/16/2014 11:56:42 PM (10 years ago)
- Location:
- sites/trunk/wordpress.org/public_html/wp-content/plugins/handbook
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/plugins/handbook/functionality-for-pages.php
r18 r705 9 9 require_once dirname( __FILE__ ) . '/inc/email-post-changes.php'; 10 10 11 class WPorg_Handbook_TOC_Pages extends WPorg_Handbook_TOC { 12 protected $post_type = 'page'; 13 } 14 new WPorg_Handbook_TOC_Pages; 11 new WPorg_Handbook_TOC( array( 'page' ) ); 15 12 16 13 add_action( 'widgets_init', 'wporg_handbook_functionality_for_pages_widget', 12 ); -
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; -
sites/trunk/wordpress.org/public_html/wp-content/plugins/handbook/inc/email-post-changes.php
r10 r705 15 15 16 16 function handbook_sidebar() { 17 if ( ! class_exists( 'P2' ) || ! class_exists( 'Email_Post_Changes' ) )18 return;19 17 20 18 require_once dirname( __FILE__ ) . '/widgets.php'; -
sites/trunk/wordpress.org/public_html/wp-content/plugins/handbook/inc/table-of-contents.php
r609 r705 6 6 */ 7 7 class WPorg_Handbook_TOC { 8 protected $post_type = 'handbook';8 protected $post_types = array(); 9 9 10 10 protected $styles = '<style> .toc-jump { text-align: right; font-size: 12px; } .page .toc-heading { margin-top: -50px; padding-top: 50px !important; }</style>'; 11 11 12 function __construct() { 12 function __construct( $post_types ) { 13 $this->post_types = $post_types; 13 14 add_action( 'template_redirect', array( $this, 'load_filters' ) ); 14 15 } 15 16 16 17 function load_filters() { 17 if ( is_singular( $this->post_type ) ) 18 $this->post_types = array_map( array( $this, 'append_suffix' ), $this->post_types ); 19 20 if ( is_singular( $this->post_types ) ) 18 21 add_filter( 'the_content', array( $this, 'add_toc' ) ); 22 } 23 24 function append_suffix( $t ) { 25 if ( 'handbook' == $t ) 26 return $t; 27 28 return $t . '-handbook'; 19 29 } 20 30 … … 32 42 $pages_header = 'h3'; 33 43 34 if ( $pages = wp_list_pages( array( 'child_of' => get_the_ID(), 'echo' => false, 'title_li' => false, 'post_type' => $this->post_type ) ) ) 35 $toc .= "<$pages_header>Pages</$pages_header><ul class=\"items\">$pages</ul>"; 44 if ( $pages = wp_list_pages( array( 'child_of' => get_the_ID(), 'echo' => false, 'title_li' => false, 'post_type' => $this->post_type ) ) ) 45 $toc .= "<$pages_header>Pages</$pages_header><ul class=\"items\">$pages</ul>"; 36 46 37 47 if ( $items ) { 38 48 $toc .= $this->styles; 39 49 $toc .= '<div class="table-of-contents">'; 40 $toc .= "<$contents_header> Topics</$contents_header><ul class=\"items\">";50 $toc .= "<$contents_header>Contents</$contents_header><ul class=\"items\">"; 41 51 $last_item = false; 42 52 foreach ( $items as $item ) { -
sites/trunk/wordpress.org/public_html/wp-content/plugins/handbook/inc/widgets.php
r540 r705 2 2 3 3 class WPorg_Handbook_Widget extends WP_Widget { 4 protected $post_type = 'handbook'; 4 5 protected $post_types = 'handbook'; 5 6 6 7 function __construct() { 8 $this->post_types = apply_filters( 'handbook_post_types', $this->post_types ); 9 if ( ! is_array( $this->post_types ) ) { 10 $this->post_types = (array) $this->post_types; 11 } 12 $this->post_types = array_map( array( $this, 'append_suffix' ), $this->post_types ); 7 13 parent::__construct( 'handbook', 'Handbook Tools', array( 'classname' => 'widget_wporg_handbook', 'description' => 'Shows watch/unwatch links for handbook pages.' ) ); 8 14 } … … 11 17 if ( ! is_user_logged_in() ) 12 18 return; 19 13 20 $post = get_post(); 14 15 switch ( $this->post_type ) { 16 case 'page' : 17 if ( $post->post_type !== 'page' ) 18 return; 19 break; 20 default : 21 if ( $post->post_type !== $this->post_type && ! is_post_type_archive( $this->post_type ) ) 22 return; 23 break; 21 if ( $post->post_type == 'page' || ( in_array( $post->post_type, $this->post_types ) && ! is_post_type_archive( $this->post_types ) ) ) { 22 $watchlist = get_post_meta( $post->ID, '_wporg_watchlist', true ); 23 if ( $watchlist && in_array( get_current_user_id(), $watchlist ) ) { 24 printf( '<p>You are watching this page. <a href="%s">Unwatch</a></p>', 25 wp_nonce_url( admin_url( 'admin-post.php?action=wporg_watchlist&post_id=' . $post->ID ), 'unwatch-' . $post->ID ) ); 26 } else { 27 printf( '<p><a href="%s">Watch this page</a></p>', 28 wp_nonce_url( admin_url( 'admin-post.php?action=wporg_watchlist&watch=1&post_id=' . $post->ID ), 'watch-' . $post->ID ) ); 29 } 30 } else { 31 return; 24 32 } 25 33 26 $watchlist = get_post_meta( $post->ID, '_wporg_watchlist', true );27 if ( $watchlist && in_array( get_current_user_id(), $watchlist ) ) 28 printf( '<p class="handbook-watch">You are watching this page. <a href="%s">Unwatch</a></p>',29 wp_nonce_url( admin_url( 'admin-post.php?action=wporg_watchlist&post_id=' . $post->ID ), 'unwatch-' . $post->ID ) );30 else31 printf( '<p class="handbook-watch"><a href="%s">Watch this page</a></p>', 32 wp_nonce_url( admin_url( 'admin-post.php?action=wporg_watchlist&watch=1&post_id=' . $post->ID ), 'watch-' . $post->ID ) );34 } 35 36 function append_suffix( $t ) { 37 if ( 'handbook' == $t ) 38 return $t; 39 40 return $t . '-handbook'; 33 41 } 34 42 } 35 43 36 44 class WPorg_Handbook_Widget_for_Pages extends WPorg_Handbook_Widget { 45 37 46 protected $post_type = 'page'; 38 47 … … 43 52 44 53 class WPorg_Handbook_Pages_Widget extends WP_Widget_Pages { 45 protected $post_type = 'handbook'; 54 55 protected $post_types = 'handbook'; 46 56 47 57 function __construct() { … … 57 67 58 68 function handbook_post_type( $args ) { 59 $args['post_type'] = $this->post_type; 69 $post = get_post(); 70 71 $this->post_types = apply_filters( 'handbook_post_types', $this->post_types ); 72 if ( ! is_array( $this->post_types ) ) { 73 $this->post_types = (array) $this->post_types; 74 } 75 $this->post_types = array_map( array( $this, 'append_suffix' ), $this->post_types ); 76 77 if ( in_array( $post->post_type, $this->post_types ) ) { 78 $args['post_type'] = $post->post_type; 79 } 60 80 return $args; 61 81 } 82 83 function append_suffix( $t ) { 84 if ( 'handbook' == $t ) 85 return $t; 86 87 return $t . '-handbook'; 88 } 62 89 } 63
Note: See TracChangeset
for help on using the changeset viewer.