Making WordPress.org

Changeset 2816


Ignore:
Timestamp:
03/25/2016 06:28:58 PM (10 years ago)
Author:
coffee2code
Message:

developer.wordpress.org: Improve deprecation notice banner text generation.

  • Add '()' to functions and methods on display, if dropped by parser.
  • Fall back to @deprecated message if no @see is present.
  • Append 'instead.' to string taken from @deprecated if not already present.

Fixes #1647.

File:
1 edited

Legend:

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

    r2766 r2816  
    742742
    743743        /**
    744          * Retrieve deprecated flag
     744         * Retrieve deprecated notice.
    745745         *
    746746         * @param int $post_id
     
    749749         */
    750750        function get_deprecated( $post_id = null ) {
    751                 if ( empty( $post_id ) ) {
     751                if ( ! $post_id ) {
    752752                        $post_id = get_the_ID();
    753753                }
     
    757757                $tags           = get_post_meta( $post_id, '_wp-parser_tags', true );
    758758                $deprecated = wp_filter_object_list( $tags, array( 'name' => 'deprecated' ) );
    759 
    760                 if ( empty( $deprecated ) ) {
     759                $deprecated = array_shift( $deprecated );
     760
     761                if ( ! $deprecated ) {
    761762                        return '';
    762763                }
     764
     765                $deprecation_info = '';
    763766
    764767                $referral = wp_filter_object_list( $tags, array( 'name' => 'see' ) );
    765768                $referral = array_shift( $referral );
    766769
     770                // Construct message pointing visitor to preferred alternative, as provided
     771                // via @see, if present.
    767772                if ( ! empty( $referral['refers'] ) ) {
    768773                        $refers = sanitize_text_field( $referral['refers'] );
    769774
    770                         if ( ! empty( $refers ) ) {
    771                                 /* translators: 1: Linked internal element name */
    772                                 $alternative_string = sprintf( __( ' Use %s instead.', 'wporg' ), \DevHub_Formatting::link_internal_element( $refers ) );
    773                         }
    774                 } else {
    775                         $alternative_string = '';
    776                 }
    777 
    778                 /* translators: 1: String for alternative function (if one exists) */
     775                        if ( $refers ) {
     776                                // For some reason, the parser may have dropped the parentheses, so add them.
     777                                if ( in_array( $type, array( 'function', 'method' ) ) && false === strpos( $refers, '()' ) ) {
     778                                        $refers .= '()';
     779                                }
     780                                /* translators: %s: Linked internal element name */
     781                                $deprecation_info = ' ' . sprintf( __( 'Use %s instead.', 'wporg' ), \DevHub_Formatting::link_internal_element( $refers ) );
     782                        }
     783                }
     784
     785                // If no alternative resource was referenced, use the deprecation string, if
     786                // present.
     787                if ( ! $deprecation_info && ! empty( $deprecated['content'] ) ) {
     788                        $deprecation_info = ' ' . sanitize_text_field ( $deprecated['content'] );
     789                        // Many deprecation strings use the syntax "Use function()" instead of the
     790                        // preferred "Use function() instead." Add it in if missing.
     791                        if ( false === strpos( $deprecation_info, 'instead' ) ) {
     792                                $deprecation_info .= ' instead.'; // Not making translatable since rest of string is not translatable.
     793                        }
     794                }
     795
     796                /* translators: 1: parsed post post, 2: String for alternative function (if one exists) */
    779797                $contents = sprintf( __( 'This %1$s has been deprecated.%2$s', 'wporg' ),
    780798                        $type,
    781                         $alternative_string
     799                        $deprecation_info
    782800                );
    783801
Note: See TracChangeset for help on using the changeset viewer.