Changeset 10794
- Timestamp:
- 03/07/2021 08:41:31 PM (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/plugins/handbook/inc/watchlist.php
r10793 r10794 28 28 self::$post_types = WPorg_Handbook_Init::get_post_types(); 29 29 30 self::o2_register_default_post_action_states(); 31 30 32 add_action( 'p2_action_links', [ __CLASS__, 'display_action_link' ], 100 ); 31 33 add_filter( 'o2_filter_post_actions', [ __CLASS__, 'add_o2_action_link' ] ); 32 34 add_filter( 'o2_filter_post_action_html', [ __CLASS__, 'get_o2_action_link' ], 10, 2 ); 35 } 36 37 /** 38 * Returns default post action info. 39 * 40 * @param string $type The post action type. Either 'watch' or 'unwatch'. 41 * @return array 42 */ 43 protected static function get_default_post_action_info( $type ) { 44 $info = []; 45 46 if ( ! in_array( $type, [ 'unwatch', 'watch' ] ) ) { 47 return $info; 48 } 49 50 if ( 'watch' === $type ) { 51 $info = [ 52 'shortText' => __( 'Watch', 'wporg' ), 53 'title' => __( 'Get notified about changes to this page', 'wporg' ), 54 'genericon' => 'genericon-subscribe', 55 'classes' => [ 'genericon', 'genericon-subscribe' ], 56 'rel' => false, 57 ]; 58 } else { 59 $info = [ 60 'shortText' => __( 'Unwatch', 'wporg' ), 61 'title' => __( 'Stop getting notified about changes to this page', 'wporg' ), 62 'genericon' => 'genericon-unsubscribe', 63 'classes' => [ 'genericon', 'genericon-unsubscribe' ], 64 'rel' => false, 65 ]; 66 } 67 68 return $info; 69 } 70 71 /** 72 * Registers default post action states. 73 */ 74 public static function o2_register_default_post_action_states() { 75 if( ! function_exists( 'o2_register_post_action_states' ) ) { 76 return; 77 } 78 79 o2_register_post_action_states( 'watch', [ 80 'unwatch' => self::get_default_post_action_info( 'unwatch' ), 81 'watch' => self::get_default_post_action_info( 'watch' ), 82 ] ); 33 83 } 34 84 … … 53 103 54 104 if ( $watchlist && in_array( get_current_user_id(), $watchlist ) ) { 55 $actions[35] = [105 $actions[35] = wp_parse_args( [ 56 106 'action' => 'watch', 57 'text' => __( 'Unwatch', 'wporg' ),58 107 'href' => wp_nonce_url( admin_url( 'admin-post.php?action=wporg_watchlist&post_id=' . $post->ID ), 'unwatch-' . $post->ID ), 59 'title' => __( 'Stop getting notified about changes to this page', 'wporg' ), 60 'classes' => [ 'genericon', 'genericon-unsubscribe' ], 61 ]; 108 'initialState' => 'unwatch', 109 ], self::get_default_post_action_info( 'unwatch' ) ); 62 110 } else { 63 $actions[35] = [111 $actions[35] = wp_parse_args( [ 64 112 'action' => 'watch', 65 'text' => __( 'Watch', 'wporg' ),66 113 'href' => wp_nonce_url( admin_url( 'admin-post.php?action=wporg_watchlist&watch=1&post_id=' . $post->ID ), 'watch-' . $post->ID ), 67 'title' => __( 'Get notified about changes to this page', 'wporg' ), 68 'classes' => [ 'genericon', 'genericon-subscribe' ], 69 ]; 114 'initialState' => 'watch', 115 ], self::get_default_post_action_info( 'watch' ) ); 70 116 } 71 117 } … … 88 134 $action['title'], 89 135 implode( ' ', $action['classes'] ), 90 $action[' text']136 $action['shortText'] 91 137 ); 92 138 }
Note: See TracChangeset
for help on using the changeset viewer.