Make WordPress Core


Ignore:
Timestamp:
11/18/2015 08:50:53 PM (9 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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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}
Note: See TracChangeset for help on using the changeset viewer.