Making WordPress.org


Ignore:
Timestamp:
04/19/2016 08:15:57 PM (8 years ago)
Author:
coffee2code
Message:

developer.wordpress.org: Prevent overzealous auto-linking of hash parameter text.

Currently, hash params are part of the description text of a single parameter and are not true sub-parameters, so auto-linking the entire hash notation text blob can affect non-description aspects of hash elements (namely when a class is the expected datatype for a hash element) and mess up hash formatting.

  • Move param_formatting_fixup() to inc/formatting.php.
  • Rename param_formatting_fixup() to fix_param_hash_formatting()`.
  • In autolink_references(), don't autolink hash notation text blobs.
  • Filter param description text with fix_param_hash_formatting() via filter rather than direct call in content-reference template.
  • Call autolink_references() within fix_param_hash_formatting() for hash param item descriptions.

See https://wordpress.slack.com/archives/meta/p1460967552000043
See https://developer.wordpress.org/reference/classes/wp_customize_control/__construct/

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/inc/template-tags.php

    r2966 r2984  
    11911191
    11921192    /**
    1193      * Formats the output of params defined using hash notation.
    1194      *
    1195      * This is a temporary measure until the parser parses the hash notation
    1196      * into component elements that the theme could then handle and style
    1197      * properly.
    1198      *
    1199      * Also, as a stopgap this is going to begin as a barebones hack to simply
    1200      * keep the text looking like one big jumble.
    1201      *
    1202      * @param  string $text The content for the param.
    1203      * @return string
    1204      */
    1205     function param_formatting_fixup( $text ) {
    1206         // Don't do anything if this isn't a hash notation string.
    1207         if ( '{' != $text[0] ) {
    1208             return $text;
    1209         }
    1210 
    1211         $new_text = '';
    1212         $text     = trim( substr( $text, 1, -1 ) );
    1213         $text     = str_replace( '@type', "\n@type", $text );
    1214 
    1215         $in_list = false;
    1216         $parts = explode( "\n", $text );
    1217         foreach ( $parts as $part ) {
    1218             $part = preg_replace( '/\s+/', ' ', $part );
    1219             list( $wordtype, $type, $name, $description ) = explode( ' ', $part, 4 );
    1220             $description = trim( $description );
    1221 
    1222             $skip_closing_li = false;
    1223 
    1224             // Handle nested hashes.
    1225             if ( '{' === $description[0] || '{' === $name ) {
    1226                 $description = ltrim( $description, '{' ) . '<ul class="param-hash">';
    1227                 $skip_closing_li = true;
    1228             } elseif ( '}' === substr( $description, -1 ) ) {
    1229                 $description = substr( $description, 0, -1 ) . "</li></ul>\n";
    1230             }
    1231 
    1232             if ( '@type' != $wordtype ) {
    1233                 if ( $in_list ) {
    1234                     $in_list = false;
    1235                     $new_text .= "</li></ul>\n";
    1236                 }
    1237 
    1238                 $new_text .= $part;
    1239             } else {
    1240                 if ( $in_list ) {
    1241                     $new_text .= '<li>';
    1242                 } else {
    1243                     $new_text .= '<ul class="param-hash"><li>';
    1244                     $in_list = true;
    1245                 }
    1246 
    1247                 // Normalize argument name.
    1248                 if ( $name === '{' ) {
    1249                     // No name is specified, generally indicating an array of arrays.
    1250                     $name = '';
    1251                 } else {
    1252                     // The name is defined as a variable, so remove the leading '$'.
    1253                     $name = ltrim( $name, '$' );
    1254                 }
    1255                 if ( $name ) {
    1256                     $new_text .= "<b>'{$name}'</b><br />";
    1257                 }
    1258                 $new_text .= "<i><span class='type'>({$type})</span></i> {$description}";
    1259                 if ( ! $skip_closing_li ) {
    1260                     $new_text .= '</li>';
    1261                 }
    1262                 $new_text .= "\n";
    1263             }
    1264         }
    1265 
    1266         if ( $in_list ) {
    1267             $new_text .= "</li></ul>\n";
    1268         }
    1269 
    1270         return $new_text;
    1271     }
    1272 
    1273     /**
    12741193     * Should the search bar be shown?
    12751194     *
Note: See TracChangeset for help on using the changeset viewer.