Make WordPress Core

Changeset 32673


Ignore:
Timestamp:
05/31/2015 04:53:12 PM (9 years ago)
Author:
johnbillion
Message:

Introduce featured_image, set_featured_image, remove_featured_image, and use_featured_image post type labels when registering a post type in order to override the 'Featured Image' text and its related phrases.

Props johnbillion, mordauk, valendesigns.
Fixes #19257.

Location:
trunk/src
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/edit-form-advanced.php

    r32642 r32673  
    214214
    215215if ( $thumbnail_support && current_user_can( 'upload_files' ) )
    216     add_meta_box('postimagediv', __('Featured Image'), 'post_thumbnail_meta_box', null, 'side', 'low');
     216    add_meta_box('postimagediv', esc_html( $post_type_object->labels->featured_image ), 'post_thumbnail_meta_box', null, 'side', 'low');
    217217
    218218if ( post_type_supports($post_type, 'excerpt') )
     
    372372
    373373    if ( current_theme_supports( 'post-thumbnails' ) && post_type_supports( 'post', 'thumbnail' ) ) {
    374         $publish_box .= '<li>' . __('<strong>Featured Image</strong> - This allows you to associate an image with your post without inserting it. This is usually useful only if your theme makes use of the featured image as a post thumbnail on the home page, a custom header, etc.') . '</li>';
     374        /* translators: %s: Featured Image */
     375        $publish_box .= '<li>' . sprintf( __( '<strong>%s</strong> - This allows you to associate an image with your post without inserting it. This is usually useful only if your theme makes use of the image as a post thumbnail on the home page, a custom header, etc.' ), esc_html( $post_type_object->labels->featured_image ) ) . '</li>';
    375376    }
    376377
  • trunk/src/wp-admin/includes/media.php

    r32672 r32673  
    14941494    if ( 'image' == $type && $calling_post_id && current_theme_supports( 'post-thumbnails', get_post_type( $calling_post_id ) )
    14951495        && post_type_supports( get_post_type( $calling_post_id ), 'thumbnail' ) && get_post_thumbnail_id( $calling_post_id ) != $attachment_id ) {
     1496       
     1497        $calling_post = get_post( $calling_post_id );
     1498        $calling_post_type_object = get_post_type_object( $calling_post->post_type );
     1499
    14961500        $ajax_nonce = wp_create_nonce( "set_post_thumbnail-$calling_post_id" );
    1497         $thumbnail = "<a class='wp-post-thumbnail' id='wp-post-thumbnail-" . $attachment_id . "' href='#' onclick='WPSetAsThumbnail(\"$attachment_id\", \"$ajax_nonce\");return false;'>" . esc_html__( "Use as featured image" ) . "</a>";
     1501        $thumbnail = "<a class='wp-post-thumbnail' id='wp-post-thumbnail-" . $attachment_id . "' href='#' onclick='WPSetAsThumbnail(\"$attachment_id\", \"$ajax_nonce\");return false;'>" . esc_html( $calling_post_type_object->labels->use_featured_image ) . "</a>";
    14981502    }
    14991503
     
    17371741 */
    17381742function media_upload_header() {
     1743
    17391744    $post_id = isset( $_REQUEST['post_id'] ) ? intval( $_REQUEST['post_id'] ) : 0;
    1740     echo '<script type="text/javascript">post_id = ' . $post_id . ";</script>\n";
     1745
     1746    if ( ! empty( $post_id ) ) {
     1747        $post_type = get_post_type( $post_id );
     1748    } else {
     1749        $post_type = '';
     1750    }
     1751
     1752    echo '<script type="text/javascript">post_id = ' . $post_id . ';post_type = ' . $post_type . ';</script>';
    17411753    if ( empty( $_GET['chromeless'] ) ) {
    17421754        echo '<div id="media-upload-header">';
  • trunk/src/wp-admin/includes/post.php

    r32643 r32673  
    13631363    global $content_width, $_wp_additional_image_sizes;
    13641364
    1365     $post = get_post( $post );
    1366 
    1367     $upload_iframe_src = esc_url( get_upload_iframe_src('image', $post->ID ) );
    1368     $set_thumbnail_link = '<p class="hide-if-no-js"><a title="' . esc_attr__( 'Set featured image' ) . '" href="%s" id="set-post-thumbnail" class="thickbox">%s</a></p>';
    1369     $content = sprintf( $set_thumbnail_link, $upload_iframe_src, esc_html__( 'Set featured image' ) );
     1365    $post               = get_post( $post );
     1366    $post_type_object   = get_post_type_object( $post->post_type );
     1367    $set_thumbnail_link = '<p class="hide-if-no-js"><a title="%s" href="%s" id="set-post-thumbnail" class="thickbox">%s</a></p>';
     1368    $upload_iframe_src  = get_upload_iframe_src( 'image', $post->ID );
     1369
     1370    $content = sprintf( $set_thumbnail_link,
     1371        esc_attr( $post_type_object->labels->set_featured_image ),
     1372        esc_url( $upload_iframe_src ),
     1373        esc_html( $post_type_object->labels->set_featured_image )
     1374    );
    13701375
    13711376    if ( $thumbnail_id && get_post( $thumbnail_id ) ) {
     
    13781383        if ( !empty( $thumbnail_html ) ) {
    13791384            $ajax_nonce = wp_create_nonce( 'set_post_thumbnail-' . $post->ID );
    1380             $content = sprintf( $set_thumbnail_link, $upload_iframe_src, $thumbnail_html );
    1381             $content .= '<p class="hide-if-no-js"><a href="#" id="remove-post-thumbnail" onclick="WPRemoveThumbnail(\'' . $ajax_nonce . '\');return false;">' . esc_html__( 'Remove featured image' ) . '</a></p>';
     1385            $content = sprintf( $set_thumbnail_link,
     1386                esc_attr( $post_type_object->labels->set_featured_image ),
     1387                esc_url( $upload_iframe_src ),
     1388                $thumbnail_html
     1389            );
     1390            $content .= '<p class="hide-if-no-js"><a href="#" id="remove-post-thumbnail" onclick="WPRemoveThumbnail(\'' . $ajax_nonce . '\');return false;">' . esc_html( $post_type_object->labels->remove_featured_image ) . '</a></p>';
    13821391        }
    13831392        $content_width = $old_content_width;
  • trunk/src/wp-admin/js/set-post-thumbnail.js

    r26199 r32673  
    1010    }, function(str){
    1111        var win = window.dialogArguments || opener || parent || top;
    12         $link.text( setPostThumbnailL10n.setThumbnail );
     12        setThumbnail = 'setThumbnail_' + post_type;
     13        $link.text( setPostThumbnailL10n[ setThumbnail ] );
    1314        if ( str == '0' ) {
    1415            alert( setPostThumbnailL10n.error );
  • trunk/src/wp-includes/media.php

    r32609 r32673  
    23142314
    23152315    wp_embed_register_handler( 'youtube_embed_url', '#https?://(www.)?youtube\.com/embed/([^/]+)#i', 'wp_embed_handler_youtube' );
     2316    wp_embed_register_handler( 'youtube_v_url', '#https?://(www.)?youtube\.com/v/([^/]+)#i', 'wp_embed_handler_youtube' );
    23162317
    23172318    wp_embed_register_handler( 'googlevideo', '#http://video\.google\.([A-Za-z.]{2,5})/videoplay\?docid=([\d-]+)(.*?)#i', 'wp_embed_handler_googlevideo' );
     
    30093010    $hier = $post && is_post_type_hierarchical( $post->post_type );
    30103011
     3012    $post_type_object = get_post_type_object( $post->post_type );
     3013
    30113014    $strings = array(
    30123015        // Generic
     
    30673070
    30683071        // Featured Images
    3069         'setFeaturedImageTitle' => __( 'Set Featured Image' ),
    3070         'setFeaturedImage'    => __( 'Set featured image' ),
     3072        'setFeaturedImageTitle' => $post_type_object->labels->featured_image,
     3073        'setFeaturedImage'      => $post_type_object->labels->set_featured_image,
    30713074
    30723075        // Gallery
  • trunk/src/wp-includes/post.php

    r32647 r32673  
    16251625 *                       ones the default is 'Parent Page:'.
    16261626 * - all_items - String for the submenu. Default is All Posts/All Pages.
     1627 * - featured_image - Default is Featured Image.
     1628 * - set_featured_image - Default is Set featured image.
     1629 * - remove_featured_image - Default is Remove featured image.
     1630 * - use_featured_image - Default is Use as featured image.
    16271631 * - menu_name - Default is the same as `name`.
    16281632 *
     
    16311635 *
    16321636 * @since 3.0.0
     1637 * @since 4.3.0 Added the `featured_image`, `set_featured_image`, `remove_featured_image`, and `use_featured_image` labels.
    16331638 * @access private
    16341639 *
     
    16491654        'not_found_in_trash' => array( __('No posts found in Trash.'), __('No pages found in Trash.') ),
    16501655        'parent_item_colon' => array( null, __('Parent Page:') ),
    1651         'all_items' => array( __( 'All Posts' ), __( 'All Pages' ) )
     1656        'all_items' => array( __( 'All Posts' ), __( 'All Pages' ) ),
     1657        'featured_image' => array( __( 'Featured Image' ), __( 'Featured Image' ) ),
     1658        'set_featured_image' => array( __( 'Set featured image' ), __( 'Set featured image' ) ),
     1659        'remove_featured_image' => array( __( 'Remove featured image' ), __( 'Remove featured image' ) ),
     1660        'use_featured_image' => array( __( 'Use as featured image' ), __( 'Use as featured image' ) ),
    16521661    );
    16531662    $nohier_vs_hier_defaults['menu_name'] = $nohier_vs_hier_defaults['name'];
  • trunk/src/wp-includes/script-loader.php

    r32623 r32673  
    571571        ));
    572572
    573         $scripts->add( 'set-post-thumbnail', "/wp-admin/js/set-post-thumbnail$suffix.js", array( 'jquery' ), false, 1 );
    574         did_action( 'init' ) && $scripts->localize( 'set-post-thumbnail', 'setPostThumbnailL10n', array(
    575             'setThumbnail' => __( 'Use as featured image' ),
     573        $setPostThumbnailL10n = array(
     574            'setThumbnail' => __( 'Use as featured image' ), // Back compat
    576575            'saving' => __( 'Saving...' ),
    577576            'error' => __( 'Could not set that as the thumbnail image. Try a different attachment.' ),
    578577            'done' => __( 'Done' )
    579         ) );
     578        );
     579
     580        foreach ( get_post_types( null, 'objects' ) as $post_type_object ) {
     581            if ( isset( $post_type_object->labels->use_featured_image ) ) {
     582                $setPostThumbnailL10n[ "setThumbnail_{$post_type_object->name}" ] = $post_type_object->labels->use_featured_image;
     583            }
     584        }
     585        $scripts->add( 'set-post-thumbnail', "/wp-admin/js/set-post-thumbnail$suffix.js", array( 'jquery' ), false, 1 );
     586        did_action( 'init' ) && $scripts->localize( 'set-post-thumbnail', 'setPostThumbnailL10n', $setPostThumbnailL10n );
    580587
    581588        // Navigation Menus
Note: See TracChangeset for help on using the changeset viewer.