Making WordPress.org

Ticket #1498: 1498.3.diff

File 1498.3.diff, 7.2 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::link_internal_element( $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 link_internal_element( $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         * Generates a private access message for a private element.
     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                // Bail if it isn't private.
     1376                if ( empty( $access_tags ) ) {
     1377                        return '';
     1378                }
     1379
     1380                $referral = array_shift( wp_filter_object_list( $tags, array( 'name' => 'see' ) ) );
     1381
     1382                if ( ! empty( $referral['refers'] ) ) {
     1383                        $refers = sanitize_text_field( $referral['refers'] );
     1384
     1385                        if ( ! empty( $refers ) ) {
     1386                                /* translators: 1: Linked internal element name */
     1387                                $alternative_string = sprintf( __( ' Use %s instead.', 'wporg' ), \DevHub_Formatting::link_internal_element( $refers ) );
     1388                        }
     1389                } else {
     1390                        $alternative_string = '';
     1391                }
     1392
     1393                /* translators: 1: String for alternative function (if one exists) */
     1394                $contents = 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' ),
     1395                                $alternative_string
     1396                );
     1397
     1398                // Use the 'alert' callout box if it's available. Otherwise, fall back to a theme-supported div class.
     1399                if ( class_exists( 'WPorg_Handbook_Callout_Boxes' ) ) {
     1400                        $callout = new \WPorg_Handbook_Callout_Boxes();
     1401                        $message = $callout->alert_shortcode( array(), $contents );
     1402                } else {
     1403                        $message  = '<div class="private-access">';
     1404                        $message .= apply_filters( 'the_content', $contents );
     1405                        $message .= '</div>';
     1406                }
     1407
     1408                return $message;
     1409        }
    13521410}
  • scss/main.scss

     
    10191019                        color: #be2423;
    10201020                        font-style: italic;
    10211021                }
     1022                .private-access {
     1023                        margin-top: 30px;
     1024                        padding: 20px 20px 10px;
     1025                        border: 1px solid #ffb900;
     1026                        background-color: #fff8e5;
     1027                }
     1028                .callout {
     1029                        margin-top: 30px;
     1030                }
    10221031        }
    10231032
    10241033        &.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  margin-top: 30px;
     1227  padding: 20px 20px 10px;
     1228  border: 1px solid #ffb900;
     1229  background-color: #fff8e5;
     1230}
     1231.devhub-wrap .wp-parser-class .callout, .devhub-wrap .wp-parser-function .callout, .devhub-wrap .wp-parser-hook .callout, .devhub-wrap .wp-parser-method .callout {
     1232  margin-top: 30px;
     1233}
    12251234.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 {
    12261235  font-family: "Open Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;
    12271236  color: #21759b;