Make WordPress Core

Changeset 35689


Ignore:
Timestamp:
11/18/2015 08:50:53 PM (8 years ago)
Author:
DrewAPicture
Message:

Embeds: Introduce print_embed_comments_button(), print_embed_sharing_button(), and print_embed_sharing_dialog(), which respectively output the comments button, sharing buttons, and sharing dialog elements in the embed template.

This change hooks these new output functions to existing hooks in the embed template, allowing for more straightforward display control of these elements.

Leaves the embed header and footer intact pending further modularization in a future release.

Props juliobox, swissspidy, DrewAPicture.
See #34561.

Location:
trunk/src/wp-includes
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/default-filters.php

    r35517 r35689  
    459459add_action( 'embed_head',             'locale_stylesheet'                     );
    460460
     461add_action( 'embed_content_meta',     'print_embed_comments_button'           );
     462add_action( 'embed_content_meta',     'print_embed_sharing_button'            );
     463
     464add_action( 'embed_footer',           'print_embed_sharing_dialog'            );
    461465add_action( 'embed_footer',           'print_embed_scripts'                   );
    462466add_action( 'embed_footer',           'wp_print_footer_scripts',        20    );
  • trunk/src/wp-includes/embed-functions.php

    r35654 r35689  
    955955    return str_replace( '<iframe class="wp-embedded-content" sandbox="allow-scripts" security="restricted" style="display:none;"', '<iframe class="wp-embedded-content" sandbox="allow-scripts" security="restricted"', $content );
    956956}
     957
     958/**
     959 * Prints the necessary markup for the embed comments button.
     960 *
     961 * @since 4.4.0
     962 */
     963function print_embed_comments_button() {
     964    if ( is_404() || ! ( get_comments_number() || comments_open() ) ) {
     965        return;
     966    }
     967    ?>
     968    <div class="wp-embed-comments">
     969        <a href="<?php comments_link(); ?>" target="_top">
     970            <span class="dashicons dashicons-admin-comments"></span>
     971            <?php
     972            printf(
     973                _n(
     974                    '%s <span class="screen-reader-text">Comment</span>',
     975                    '%s <span class="screen-reader-text">Comments</span>',
     976                    get_comments_number()
     977                ),
     978                number_format_i18n( get_comments_number() )
     979            );
     980            ?>
     981        </a>
     982    </div>
     983    <?php
     984}
     985
     986/**
     987 * Prints the necessary markup for the embed sharing button.
     988 *
     989 * @since 4.4.0
     990 */
     991function print_embed_sharing_button() {
     992    if ( is_404() ) {
     993        return;
     994    }
     995    ?>
     996    <div class="wp-embed-share">
     997        <button type="button" class="wp-embed-share-dialog-open" aria-label="<?php esc_attr_e( 'Open sharing dialog' ); ?>">
     998            <span class="dashicons dashicons-share"></span>
     999        </button>
     1000    </div>
     1001    <?php
     1002}
     1003
     1004/**
     1005 * Prints the necessary markup for the embed sharing dialog.
     1006 *
     1007 * @since 4.4.0
     1008 */
     1009function print_embed_sharing_dialog() {
     1010    if ( is_404() ) {
     1011        return;
     1012    }
     1013    ?>
     1014    <div class="wp-embed-share-dialog hidden" role="dialog" aria-label="<?php esc_attr_e( 'Sharing options' ); ?>">
     1015        <div class="wp-embed-share-dialog-content">
     1016            <div class="wp-embed-share-dialog-text">
     1017                <ul class="wp-embed-share-tabs" role="tablist">
     1018                    <li class="wp-embed-share-tab-button wp-embed-share-tab-button-wordpress" role="presentation">
     1019                        <button type="button" role="tab" aria-controls="wp-embed-share-tab-wordpress" aria-selected="true" tabindex="0"><?php esc_html_e( 'WordPress Embed' ); ?></button>
     1020                    </li>
     1021                    <li class="wp-embed-share-tab-button wp-embed-share-tab-button-html" role="presentation">
     1022                        <button type="button" role="tab" aria-controls="wp-embed-share-tab-html" aria-selected="false" tabindex="-1"><?php esc_html_e( 'HTML Embed' ); ?></button>
     1023                    </li>
     1024                </ul>
     1025                <div id="wp-embed-share-tab-wordpress" class="wp-embed-share-tab" role="tabpanel" aria-hidden="false">
     1026                    <input type="text" value="<?php the_permalink(); ?>" class="wp-embed-share-input" aria-describedby="wp-embed-share-description-wordpress" tabindex="0" readonly/>
     1027
     1028                    <p class="wp-embed-share-description" id="wp-embed-share-description-wordpress">
     1029                        <?php _e( 'Copy and paste this URL into your WordPress site to embed' ); ?>
     1030                    </p>
     1031                </div>
     1032                <div id="wp-embed-share-tab-html" class="wp-embed-share-tab" role="tabpanel" aria-hidden="true">
     1033                    <textarea class="wp-embed-share-input" aria-describedby="wp-embed-share-description-html" tabindex="0" readonly><?php echo esc_textarea( get_post_embed_html( 600, 400 ) ); ?></textarea>
     1034
     1035                    <p class="wp-embed-share-description" id="wp-embed-share-description-html">
     1036                        <?php _e( 'Copy and paste this code into your site to embed' ); ?>
     1037                    </p>
     1038                </div>
     1039            </div>
     1040
     1041            <button type="button" class="wp-embed-share-dialog-close" aria-label="<?php esc_attr_e( 'Close sharing dialog' ); ?>">
     1042                <span class="dashicons dashicons-no"></span>
     1043            </button>
     1044        </div>
     1045    </div>
     1046    <?php
     1047}
  • trunk/src/wp-includes/embed-template.php

    r35578 r35689  
    150150                    do_action( 'embed_content_meta');
    151151                    ?>
    152                     <?php if ( get_comments_number() || comments_open() ) : ?>
    153                         <div class="wp-embed-comments">
    154                             <a href="<?php comments_link(); ?>" target="_top">
    155                                 <span class="dashicons dashicons-admin-comments"></span>
    156                                 <?php
    157                                 printf(
    158                                     _n(
    159                                         '%s <span class="screen-reader-text">Comment</span>',
    160                                         '%s <span class="screen-reader-text">Comments</span>',
    161                                         get_comments_number()
    162                                     ),
    163                                     number_format_i18n( get_comments_number() )
    164                                 );
    165                                 ?>
    166                             </a>
    167                         </div>
    168                     <?php endif; ?>
    169                     <div class="wp-embed-share">
    170                         <button type="button" class="wp-embed-share-dialog-open" aria-label="<?php esc_attr_e( 'Open sharing dialog' ); ?>">
    171                             <span class="dashicons dashicons-share"></span>
    172                         </button>
    173                     </div>
    174                 </div>
    175             </div>
    176             <div class="wp-embed-share-dialog hidden" role="dialog" aria-label="<?php esc_attr_e( 'Sharing options' ); ?>">
    177                 <div class="wp-embed-share-dialog-content">
    178                     <div class="wp-embed-share-dialog-text">
    179                         <ul class="wp-embed-share-tabs" role="tablist">
    180                             <li class="wp-embed-share-tab-button wp-embed-share-tab-button-wordpress" role="presentation">
    181                                 <button type="button" role="tab" aria-controls="wp-embed-share-tab-wordpress" aria-selected="true" tabindex="0"><?php esc_html_e( 'WordPress Embed' ); ?></button>
    182                             </li>
    183                             <li class="wp-embed-share-tab-button wp-embed-share-tab-button-html" role="presentation">
    184                                 <button type="button" role="tab" aria-controls="wp-embed-share-tab-html" aria-selected="false" tabindex="-1"><?php esc_html_e( 'HTML Embed' ); ?></button>
    185                             </li>
    186                         </ul>
    187                         <div id="wp-embed-share-tab-wordpress" class="wp-embed-share-tab" role="tabpanel" aria-hidden="false">
    188                             <input type="text" value="<?php the_permalink(); ?>" class="wp-embed-share-input" aria-describedby="wp-embed-share-description-wordpress" tabindex="0" readonly />
    189 
    190                             <p class="wp-embed-share-description" id="wp-embed-share-description-wordpress">
    191                                 <?php _e( 'Copy and paste this URL into your WordPress site to embed' ); ?>
    192                             </p>
    193                         </div>
    194                         <div id="wp-embed-share-tab-html" class="wp-embed-share-tab" role="tabpanel" aria-hidden="true">
    195                             <textarea class="wp-embed-share-input" aria-describedby="wp-embed-share-description-html" tabindex="0" readonly><?php echo esc_textarea( get_post_embed_html( 600, 400 ) ); ?></textarea>
    196 
    197                             <p class="wp-embed-share-description" id="wp-embed-share-description-html">
    198                                 <?php _e( 'Copy and paste this code into your site to embed' ); ?>
    199                             </p>
    200                         </div>
    201                     </div>
    202 
    203                     <button type="button" class="wp-embed-share-dialog-close" aria-label="<?php esc_attr_e( 'Close sharing dialog' ); ?>">
    204                         <span class="dashicons dashicons-no"></span>
    205                     </button>
    206152                </div>
    207153            </div>
Note: See TracChangeset for help on using the changeset viewer.