- Timestamp:
- 06/16/2014 11:56:42 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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.