Changeset 9987
- Timestamp:
- 06/29/2020 05:30:15 AM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/plugins/handbook/inc/watchlist.php
r772 r9987 14 14 15 15 add_action( 'p2_action_links', array(__CLASS__, 'display_action_link'), 100 ); 16 add_filter( 'o2_filter_post_actions', array( __CLASS__, 'add_o2_action_link' ) ); 17 add_filter( 'o2_filter_post_action_html', array( __CLASS__, 'get_o2_action_link' ), 10, 2 ); 16 18 } 17 19 … … 28 30 29 31 return $t . '-handbook'; 32 } 33 34 /** 35 * Adds a 'Watch' action link to O2 36 */ 37 public static function add_o2_action_link( $actions ) { 38 if ( ! is_user_logged_in() ) { 39 return; 40 } 41 42 $post = get_post(); 43 44 if ( 'page' == $post->post_type || ( in_array( $post->post_type, self::$post_types ) && ! is_post_type_archive( self::$post_types ) ) ) { 45 $watchlist = get_post_meta( $post->ID, '_wporg_watchlist', true ); 46 47 if ( $watchlist && in_array( get_current_user_id(), $watchlist ) ) { 48 $actions[35] = [ 49 'action' => 'watch', 50 'text' => __( 'Unwatch', 'wporg' ), 51 'href' => wp_nonce_url( admin_url( 'admin-post.php?action=wporg_watchlist&post_id=' . $post->ID ), 'unwatch-' . $post->ID ), 52 'title' => __( 'Stop getting notified about changes to this page', 'wporg' ), 53 'classes' => [ 'genericon', 'genericon-unsubscribe' ], 54 ]; 55 } else { 56 $actions[35] = [ 57 'action' => 'watch', 58 'text' => __( 'Watch', 'wporg' ), 59 'href' => wp_nonce_url( admin_url( 'admin-post.php?action=wporg_watchlist&watch=1&post_id=' . $post->ID ), 'watch-' . $post->ID ), 60 'title' => __( 'Get notified about changes to this page', 'wporg' ), 61 'classes' => [ 'genericon', 'genericon-subscribe' ], 62 ]; 63 } 64 } 65 return $actions; 66 } 67 68 /** 69 * Create the HTML for the watch o2 post action. 70 */ 71 public static function get_o2_action_link( $html, $action ) { 72 if ( 'watch' === $action['action'] ) { 73 $html = sprintf( 74 '<a href="%s" title="%s" class="%s">%s</a>', 75 $action['href'], 76 $action['title'], 77 implode( ' ', $action['classes'] ), 78 $action['text'] 79 ); 80 } 81 82 return $html; 30 83 } 31 84
Note: See TracChangeset
for help on using the changeset viewer.