Changeset 4782
- Timestamp:
- 01/25/2017 02:36:41 PM (9 years ago)
- Location:
- sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-cli
- Files:
-
- 3 added
- 2 edited
-
assets (added)
-
assets/images (added)
-
assets/images/github-mark.svg (added)
-
inc/class-handbook.php (modified) (5 diffs)
-
wporg-cli.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-cli/inc/class-handbook.php
r4745 r4782 4 4 5 5 class Handbook { 6 7 /** 8 * Append a "Edit on GitHub" link to Handbook document titles 9 */ 10 public static function filter_the_title_edit_link( $title ) { 11 // Only apply to the main title for the document 12 if ( ! is_singular( 'handbook' ) 13 || ! is_main_query() 14 || ! in_the_loop() ) { 15 return $title; 16 } 17 18 $markdown_source = self::get_markdown_edit_link( get_the_ID() ); 19 if ( ! $markdown_source ) { 20 return $title; 21 } 22 23 return $title . ' <a class="github-edit" href="' . esc_url( $markdown_source ) . '"><img src="' . esc_url( plugins_url( 'assets/images/github-mark.svg', dirname( __FILE__ ) ) ) . '"> <span>Edit</span></a>'; 24 } 25 6 26 /** 7 27 * WP-CLI Handbook pages are maintained in the GitHub repo, so the edit … … 9 29 */ 10 30 public static function redirect_edit_link_to_github( $link, $post_id, $context ) { 31 if ( is_admin() ) { 32 return $link; 33 } 11 34 $post = get_post( $post_id ); 12 35 if ( ! $post ) { … … 18 41 } 19 42 20 $markdown_source = Markdown_Import::get_markdown_source( $post_id );21 if ( is_wp_error( $markdown_source )) {43 $markdown_source = self::get_markdown_edit_link( $post_id ); 44 if ( ! $markdown_source ) { 22 45 return $link; 23 46 } … … 47 70 } 48 71 49 $markdown_source = Markdown_Import::get_markdown_source( $post_id );50 if ( is_wp_error( $markdown_source )) {72 $markdown_source = self::get_markdown_edit_link( $post_id ); 73 if ( ! $markdown_source ) { 51 74 return $actions; 52 75 } … … 85 108 return $actions; 86 109 } 110 111 private static function get_markdown_edit_link( $post_id ) { 112 $markdown_source = Markdown_Import::get_markdown_source( $post_id ); 113 if ( is_wp_error( $markdown_source ) ) { 114 return ''; 115 } 116 if ( 'github.com' !== parse_url( $markdown_source, PHP_URL_HOST ) 117 || false !== stripos( $markdown_source, '/edit/master/' ) ) { 118 return $markdown_source; 119 } 120 $markdown_source = str_replace( '/blob/master/', '/edit/master/', $markdown_source ); 121 return $markdown_source; 122 } 87 123 } -
sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-cli/wporg-cli.php
r4754 r4782 18 18 add_action( 'edit_form_after_title', array( 'WPOrg_Cli\Markdown_Import', 'action_edit_form_after_title' ) ); 19 19 add_action( 'save_post', array( 'WPOrg_Cli\Markdown_Import', 'action_save_post' ) ); 20 20 add_filter( 'the_title', array( 'WPOrg_Cli\Handbook', 'filter_the_title_edit_link' ) ); 21 21 add_filter( 'get_edit_post_link', array( 'WPOrg_Cli\Handbook', 'redirect_edit_link_to_github' ), 10, 3 ); 22 22 add_filter( 'o2_filter_post_actions', array( 'WPOrg_Cli\Handbook', 'redirect_o2_edit_link_to_github' ), 11, 2 ); … … 26 26 <style> 27 27 pre code { 28 padding: 0;29 28 line-height: 16px; 29 } 30 a.github-edit { 31 margin-left: .5em; 32 font-size: .5em; 33 vertical-align: top; 34 display: inline-block; 35 border: 1px solid #eeeeee; 36 border-radius: 2px; 37 background: #eeeeee; 38 padding: .5em .6em .4em; 39 color: black; 40 margin-top: 0.1em; 41 } 42 a.github-edit > * { 43 opacity: 0.6; 44 } 45 a.github-edit:hover > * { 46 opacity: 1; 47 color: black; 48 } 49 a.github-edit img { 50 height: .8em; 30 51 } 31 52 </style>
Note: See TracChangeset
for help on using the changeset viewer.