Changeset 7769
- Timestamp:
- 10/24/2018 09:41:00 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/inc/formatting.php
r6448 r7769 134 134 // Link without linked text: {@link http://en.wikipedia.org/wiki/ISO_8601} 135 135 if ( 1 === count( $parts ) ) { 136 $ link = '<a href="' . esc_url( $link ) . '">' . esc_html( $link ) . '</a>';136 $url = $text = $link; 137 137 } 138 138 139 139 // Link with linked text: {@link http://codex.wordpress.org/The_Loop Use new WordPress Loop} 140 140 else { 141 $link = '<a href="' . esc_url( $parts[0] ) . '">' . esc_html( $parts[1] ) . '</a>'; 141 $url = $parts[0]; 142 $text = $parts[1]; 142 143 } 143 144 145 $link = self::generate_link( $url, $text ); 144 146 } 145 147 … … 165 167 */ 166 168 public static function link_internal_element( $link ) { 169 $url = ''; 170 167 171 // Link to class variable: {@see WP_Rewrite::$index} 168 172 if ( false !== strpos( $link, '::$' ) ) { … … 172 176 // Link to class method: {@see WP_Query::query()} 173 177 elseif ( false !== strpos( $link, '::' ) ) { 174 $link = '<a href="' . 175 get_post_type_archive_link( 'wp-parser-class' ) . 176 str_replace( array( '::', '()' ), array( '/', '' ), $link ) . 177 '">' . esc_html( $link ) . '</a>'; 178 $url = get_post_type_archive_link( 'wp-parser-class' ) . 179 str_replace( array( '::', '()' ), array( '/', '' ), $link ); 178 180 } 179 181 … … 181 183 elseif ( 1 === preg_match( '/^(?:\'|(?:‘))([\$\w-&;]+)(?:\'|(?:’))$/', $link, $hook ) ) { 182 184 if ( ! empty( $hook[1] ) ) { 183 $link = '<a href="' . 184 get_post_type_archive_link( 'wp-parser-hook' ) . 185 sanitize_title_with_dashes( html_entity_decode( $hook[1] ) ) . '/' . 186 '">' . esc_html( $link ) . '</a>'; 185 $url = get_post_type_archive_link( 'wp-parser-hook' ) . 186 sanitize_title_with_dashes( html_entity_decode( $hook[1] ) ) . '/'; 187 187 } 188 188 } … … 197 197 ( 1 === preg_match ( '/^_?[A-Z][a-zA-Z]+_\w+/', $link ) ) // Otherwise, class names start with (optional underscore, then) uppercase and have underscore 198 198 ) { 199 $link = sprintf( 200 '<a href="%s">%s</a>', 201 esc_url( get_post_type_archive_link( 'wp-parser-class' ) . sanitize_key( $link ) ), 202 esc_html( $link ) 203 ); 199 $url = get_post_type_archive_link( 'wp-parser-class' ) . sanitize_key( $link ); 204 200 } 205 201 206 202 // Link to function: {@see esc_attr()} 207 203 else { 208 $link = '<a href="' . 209 get_post_type_archive_link( 'wp-parser-function' ) . 210 sanitize_title_with_dashes( html_entity_decode( $link ) ) . 211 '">' . esc_html( $link ) . '</a>'; 204 $url = get_post_type_archive_link( 'wp-parser-function' ) . 205 sanitize_title_with_dashes( html_entity_decode( $link ) ); 206 } 207 208 if ( $url ) { 209 $link = self::generate_link( $url, $link ); 212 210 } 213 211 return $link; 214 212 } 215 213 214 /** 215 * Generates a link given a URL and text. 216 * 217 * @param string $url The URL, for the link's href attribute. 218 * @param string $text The text content of the link. 219 * @return string The HTML for the link. 220 */ 221 public static function generate_link( $url, $text ) { 222 /** 223 * Filters the HTML attributes applied to a link's anchor element. 224 * 225 * @param array $attrs The HTML attributes applied to the link's anchor element. 226 * @param string $url The URL for the link. 227 */ 228 $attrs = (array) apply_filters( 'devhub-format-link-attributes', array( 'href' => $url ), $url ); 229 230 // Make sure the filter didn't completely remove the href attribute. 231 if ( empty( $attrs['href'] ) ) { 232 $attrs['href'] = $url; 233 } 234 235 $attributes = ''; 236 foreach ( $attrs as $name => $value ) { 237 $value = 'href' === $name ? esc_url( $value ) : esc_attr( $value ); 238 $attributes .= sprintf( ' %s="%s"', esc_attr( $name ), $value ); 239 } 240 241 return sprintf( '<a%s>%s</a>', $attributes, esc_html( $text ) ); 242 } 243 216 244 /** 217 245 * Fixes unintended markup generated by Markdown during parsing.
Note: See TracChangeset
for help on using the changeset viewer.