WordPress.org

Making WordPress.org

Changeset 1022


Ignore:
Timestamp:
12/03/2014 12:04:09 AM (6 years ago)
Author:
coffee2code
Message:

developer.wordpress.org: don't make parameters without explicit defaults appear as though they are defaulted to null

In the output of method signatures, it is misleading for the lack of a default value for a parameter to be presented as if the parameter was assigned a default value of null. At first glance it gives the impression the parameter is optional (it isn't) or that if a null value is explicitly provided the function will behave in its default manner (it likely won't).

File:
1 edited

Legend:

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

    r1020 r1022  
    525525        if ( $args ) {
    526526            foreach ( $args as $arg ) {
     527                $arg = (array) $arg;
    527528                $arg_string = '';
    528529                if ( ! empty( $arg['name'] ) && ! empty( $types[ $arg['name'] ] ) ) {
     
    531532
    532533                if ( ! empty( $arg['name'] ) ) {
    533                     $arg_string .= '&nbsp;<span class="arg-name">' . $arg['name'] . '</span>&nbsp;';
    534                 }
    535 
    536                 if ( is_array( $arg ) && array_key_exists( 'default', $arg ) ) {
    537 
    538                     if ( is_null( $arg['default'] ) ) {
    539                         $arg['default'] = 'null';
    540                     }
    541 
    542                     $arg_string .= '=&nbsp;<span class="arg-default">' . htmlentities( $arg['default'] ) . "</span>";
     534                    $arg_string .= '&nbsp;<span class="arg-name">' . $arg['name'] . '</span>';
     535                }
     536
     537                if ( ! empty( $arg['default'] ) ) {
     538                    $arg_string .= '&nbsp;=&nbsp;<span class="arg-default">' . htmlentities( $arg['default'] ) . "</span>";
    543539                }
    544540
     
    610606                if ( ! empty( $arg['name'] ) && ! empty( $params[ $arg['name'] ] ) ) {
    611607                    $params[ $arg['name'] ]['default'] = $arg['default'];
     608
    612609                    // If a known default is stated in the parameter's description, try to remove it
    613610                    // since the actual default value is displayed immediately following description.
    614                     if ( $arg['default'] ) {
     611                    if ( ! empty( $arg['default'] ) ) {
    615612                        $default = htmlentities( $arg['default'] );
    616613                        $params[ $arg['name'] ]['content'] = str_replace( "default is {$default}.", '', $params[ $arg['name'] ]['content'] );
Note: See TracChangeset for help on using the changeset viewer.