Making WordPress.org

Ticket #1498: 1498.diff

File 1498.diff, 6.5 KB (added by DrewAPicture, 8 years ago)
  • content-reference.php

     
    44
    55        <?php echo get_deprecated(); ?>
    66
     7        <?php echo get_private_access_message(); ?>
     8
    79        <h1><a href="<?php the_permalink() ?>"><?php echo get_signature(); ?></a></h1>
    810
    911        <section class="summary">
  • inc/formatting.php

     
    132132
    133133                                // Link to an internal resource.
    134134                                else {
    135 
    136                                         // Link to class variable: {@see WP_Rewrite::$index}
    137                                         if ( false !== strpos( $link, '::$' ) ) {
    138                                                 // Nothing to link to currently.
    139                                         }
    140 
    141                                         // Link to class method: {@see WP_Query::query()}
    142                                         elseif ( false !== strpos( $link, '::' ) ) {
    143                                                 $link = '<a href="' .
    144                                                         get_post_type_archive_link( 'wp-parser-class' ) .
    145                                                         str_replace( array( '::', '()' ), array( '/', '' ), $link ) .
    146                                                         '">' . esc_html( $link ) . '</a>';
    147                                         }
    148 
    149                                         // Link to hook: {@see 'pre_get_search_form'}
    150                                         elseif ( 1 === preg_match( '/^(&#8216;)\w+(&#8217;)$/', $link, $hook ) ) {
    151                                                 if ( ! empty( $hook[0] ) ) {
    152                                                         $link = '<a href="' .
    153                                                                 get_post_type_archive_link( 'wp-parser-hook' ) .
    154                                                                 str_replace( array( '&#8216;', '&#8217;' ), '', $link ) .
    155                                                                 '">' . esc_html( $link ) . '</a>';
    156                                                 }
    157                                         }
    158 
    159                                         // Link to function: {@see esc_attr()}
    160                                         else {
    161                                                 $link = '<a href="' .
    162                                                         get_post_type_archive_link( 'wp-parser-function' ) .
    163                                                         str_replace( '()', '', $link ) .
    164                                                         '">' . esc_html( $link ) . '</a>';
    165                                         }
    166 
     135                                        $link = self::get_internal_element_link( $link );
    167136                                }
    168137
    169138                                return $link;
     
    173142        }
    174143
    175144        /**
     145         * Parses and links an internal element if a valid element is found.
     146         *
     147         * @static
     148         * @access public
     149         *
     150         * @param string $link Element string.
     151         * @param string HTML link markup if a valid element was found.
     152         */
     153        public static function get_internal_element_link( $link ) {
     154                // Link to class variable: {@see WP_Rewrite::$index}
     155                if ( false !== strpos( $link, '::$' ) ) {
     156                        // Nothing to link to currently.
     157                }
     158
     159                // Link to class method: {@see WP_Query::query()}
     160                elseif ( false !== strpos( $link, '::' ) ) {
     161                        $link = '<a href="' .
     162                                get_post_type_archive_link( 'wp-parser-class' ) .
     163                                str_replace( array( '::', '()' ), array( '/', '' ), $link ) .
     164                                '">' . esc_html( $link ) . '</a>';
     165                }
     166
     167                // Link to hook: {@see 'pre_get_search_form'}
     168                elseif ( 1 === preg_match( '/^(&#8216;)\w+(&#8217;)$/', $link, $hook ) ) {
     169                        if ( ! empty( $hook[0] ) ) {
     170                                $link = '<a href="' .
     171                                        get_post_type_archive_link( 'wp-parser-hook' ) .
     172                                        str_replace( array( '&#8216;', '&#8217;' ), '', $link ) .
     173                                        '">' . esc_html( $link ) . '</a>';
     174                        }
     175                }
     176
     177                // Link to function: {@see esc_attr()}
     178                else {
     179                        $link = '<a href="' .
     180                                get_post_type_archive_link( 'wp-parser-function' ) .
     181                                str_replace( '()', '', $link ) .
     182                                '">' . esc_html( $link ) . '</a>';
     183                }
     184                return $link;
     185        }
     186
     187        /**
    176188         * Fixes unintended markup generated by Markdown during parsing.
    177189         *
    178190         * The parser interprets underscores surrounding text as Markdown indicating
  • inc/template-tags.php

     
    13491349                }
    13501350                return get_post_field( $field, $explanation, $context );
    13511351        }
     1352
     1353        /**
     1354         * Retrieves private access data for a given post.
     1355         *
     1356         * @param int|WP_Post $post Optional. Post object or ID. Default global `$post`.
     1357         * @return string Private access message if the given reference is considered "private".
     1358         */
     1359        function get_private_access_message( $post = null ) {
     1360                if ( ! $post = get_post( $post ) ) {
     1361                        return '';
     1362                }
     1363
     1364                // Currently only handling private access messages for functions and hooks.
     1365                if ( ! in_array( get_post_type( $post ), array( 'wp-parser-function', 'wp-parser-hook' ) ) ) {
     1366                        return '';
     1367                }
     1368
     1369                $tags        = get_post_meta( $post->ID, '_wp-parser_tags', true );
     1370                $access_tags = wp_filter_object_list( $tags, array(
     1371                        'name'    => 'access',
     1372                        'content' => 'private'
     1373                ) );
     1374
     1375                if ( ! empty( $access_tags ) ) {
     1376                        $referral = array_shift( wp_filter_object_list( $tags, array( 'name' => 'see' ) ) );
     1377
     1378                        if ( ! empty( $referral['refers'] ) ) {
     1379                                $refers = sanitize_text_field( $referral['refers'] );
     1380
     1381                                if ( ! empty( $refers ) ) {
     1382                                        /* translators: 1: Linked internal element name */
     1383                                        $altnerative_string = sprintf( __( ' Use %s instead.', 'wporg' ), \DevHub_Formatting::get_internal_element_link( $refers ) );
     1384                                }
     1385                        } else {
     1386                                $altnerative_string = '';
     1387                        }
     1388
     1389                        return
     1390                                '<p class="private-access">' .
     1391                               /* translators: 1: String for alternative function (if one exists) */
     1392                               sprintf( __( 'This function&#8217;s access is marked private. This means it is not intended for use by plugin or theme developers, only in other core functions. It is listed here for completeness.%s', 'wporg' ),
     1393                                       $altnerative_string
     1394                               ) .
     1395                       '</p>';
     1396                }
     1397        }
    13521398}
  • scss/main.scss

     
    10191019                        color: #be2423;
    10201020                        font-style: italic;
    10211021                }
     1022                .private-access {
     1023                        color: #be2423;
     1024                        font-weight: bold;
     1025                        padding: 20px;
     1026                }
    10221027        }
    10231028
    10241029        &.archive, &.search {
  • stylesheets/main.css

     
    12221222  color: #be2423;
    12231223  font-style: italic;
    12241224}
     1225.devhub-wrap .wp-parser-class .private-access, .devhub-wrap .wp-parser-function .private-access, .devhub-wrap .wp-parser-hook .private-access, .devhub-wrap .wp-parser-method .private-access {
     1226  color: #be2423;
     1227  font-weight: bold;
     1228  padding: 20px;
     1229}
    12251230.devhub-wrap.archive .wp-parser-class h1 a, .devhub-wrap.archive .wp-parser-function h1 a, .devhub-wrap.archive .wp-parser-hook h1 a, .devhub-wrap.archive .wp-parser-method h1 a, .devhub-wrap.search .wp-parser-class h1 a, .devhub-wrap.search .wp-parser-function h1 a, .devhub-wrap.search .wp-parser-hook h1 a, .devhub-wrap.search .wp-parser-method h1 a {
    12261231  font-family: "Open Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;
    12271232  color: #21759b;