From 02192cb53fe6c5e58a541737d5d549cb71ee69a4 Mon Sep 17 00:00:00 2001 From: John Blackbourn Date: Sun, 31 May 2015 16:54:27 +0000 Subject: [PATCH] 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. Built from https://develop.svn.wordpress.org/trunk@32673 git-svn-id: http://core.svn.wordpress.org/trunk@32643 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/edit-form-advanced.php | 5 +++-- wp-admin/includes/media.php | 16 ++++++++++++++-- wp-admin/includes/post.php | 21 +++++++++++++++------ wp-admin/js/set-post-thumbnail.js | 3 ++- wp-admin/js/set-post-thumbnail.min.js | 2 +- wp-includes/media.php | 7 +++++-- wp-includes/post.php | 11 ++++++++++- wp-includes/script-loader.php | 15 +++++++++++---- wp-includes/version.php | 2 +- 9 files changed, 62 insertions(+), 20 deletions(-) diff --git a/wp-admin/edit-form-advanced.php b/wp-admin/edit-form-advanced.php index 5b5abb0ccf..0724a88c71 100644 --- a/wp-admin/edit-form-advanced.php +++ b/wp-admin/edit-form-advanced.php @@ -213,7 +213,7 @@ if ( post_type_supports($post_type, 'page-attributes') ) add_meta_box('pageparentdiv', 'page' == $post_type ? __('Page Attributes') : __('Attributes'), 'page_attributes_meta_box', null, 'side', 'core'); if ( $thumbnail_support && current_user_can( 'upload_files' ) ) - add_meta_box('postimagediv', __('Featured Image'), 'post_thumbnail_meta_box', null, 'side', 'low'); + add_meta_box('postimagediv', esc_html( $post_type_object->labels->featured_image ), 'post_thumbnail_meta_box', null, 'side', 'low'); if ( post_type_supports($post_type, 'excerpt') ) add_meta_box('postexcerpt', __('Excerpt'), 'post_excerpt_meta_box', null, 'normal', 'core'); @@ -371,7 +371,8 @@ if ( 'post' == $post_type ) { } if ( current_theme_supports( 'post-thumbnails' ) && post_type_supports( 'post', 'thumbnail' ) ) { - $publish_box .= '
  • ' . __('Featured Image - 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.') . '
  • '; + /* translators: %s: Featured Image */ + $publish_box .= '
  • ' . sprintf( __( '%s - 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 ) ) . '
  • '; } $publish_box .= ''; diff --git a/wp-admin/includes/media.php b/wp-admin/includes/media.php index bb3b4a079c..cf1beb6d8d 100644 --- a/wp-admin/includes/media.php +++ b/wp-admin/includes/media.php @@ -1493,8 +1493,12 @@ function get_media_item( $attachment_id, $args = null ) { } if ( 'image' == $type && $calling_post_id && current_theme_supports( 'post-thumbnails', get_post_type( $calling_post_id ) ) && post_type_supports( get_post_type( $calling_post_id ), 'thumbnail' ) && get_post_thumbnail_id( $calling_post_id ) != $attachment_id ) { + + $calling_post = get_post( $calling_post_id ); + $calling_post_type_object = get_post_type_object( $calling_post->post_type ); + $ajax_nonce = wp_create_nonce( "set_post_thumbnail-$calling_post_id" ); - $thumbnail = "" . esc_html__( "Use as featured image" ) . ""; + $thumbnail = "" . esc_html( $calling_post_type_object->labels->use_featured_image ) . ""; } if ( ( $r['send'] || $thumbnail || $delete ) && !isset( $form_fields['buttons'] ) ) { @@ -1736,8 +1740,16 @@ function get_compat_media_markup( $attachment_id, $args = null ) { * @since 2.5.0 */ function media_upload_header() { + $post_id = isset( $_REQUEST['post_id'] ) ? intval( $_REQUEST['post_id'] ) : 0; - echo '\n"; + + if ( ! empty( $post_id ) ) { + $post_type = get_post_type( $post_id ); + } else { + $post_type = ''; + } + + echo ''; if ( empty( $_GET['chromeless'] ) ) { echo '
    '; the_media_upload_tabs(); diff --git a/wp-admin/includes/post.php b/wp-admin/includes/post.php index 5ef3ce88e8..4916d13998 100644 --- a/wp-admin/includes/post.php +++ b/wp-admin/includes/post.php @@ -1362,11 +1362,16 @@ function get_sample_permalink_html( $id, $new_title = null, $new_slug = null ) { function _wp_post_thumbnail_html( $thumbnail_id = null, $post = null ) { global $content_width, $_wp_additional_image_sizes; - $post = get_post( $post ); + $post = get_post( $post ); + $post_type_object = get_post_type_object( $post->post_type ); + $set_thumbnail_link = '

    %s

    '; + $upload_iframe_src = get_upload_iframe_src( 'image', $post->ID ); - $upload_iframe_src = esc_url( get_upload_iframe_src('image', $post->ID ) ); - $set_thumbnail_link = '

    %s

    '; - $content = sprintf( $set_thumbnail_link, $upload_iframe_src, esc_html__( 'Set featured image' ) ); + $content = sprintf( $set_thumbnail_link, + esc_attr( $post_type_object->labels->set_featured_image ), + esc_url( $upload_iframe_src ), + esc_html( $post_type_object->labels->set_featured_image ) + ); if ( $thumbnail_id && get_post( $thumbnail_id ) ) { $old_content_width = $content_width; @@ -1377,8 +1382,12 @@ function _wp_post_thumbnail_html( $thumbnail_id = null, $post = null ) { $thumbnail_html = wp_get_attachment_image( $thumbnail_id, 'post-thumbnail' ); if ( !empty( $thumbnail_html ) ) { $ajax_nonce = wp_create_nonce( 'set_post_thumbnail-' . $post->ID ); - $content = sprintf( $set_thumbnail_link, $upload_iframe_src, $thumbnail_html ); - $content .= '

    ' . esc_html__( 'Remove featured image' ) . '

    '; + $content = sprintf( $set_thumbnail_link, + esc_attr( $post_type_object->labels->set_featured_image ), + esc_url( $upload_iframe_src ), + $thumbnail_html + ); + $content .= '

    ' . esc_html( $post_type_object->labels->remove_featured_image ) . '

    '; } $content_width = $old_content_width; } diff --git a/wp-admin/js/set-post-thumbnail.js b/wp-admin/js/set-post-thumbnail.js index 68abbcc830..fb17351a25 100644 --- a/wp-admin/js/set-post-thumbnail.js +++ b/wp-admin/js/set-post-thumbnail.js @@ -9,7 +9,8 @@ function WPSetAsThumbnail( id, nonce ) { action: 'set-post-thumbnail', post_id: post_id, thumbnail_id: id, _ajax_nonce: nonce, cookie: encodeURIComponent( document.cookie ) }, function(str){ var win = window.dialogArguments || opener || parent || top; - $link.text( setPostThumbnailL10n.setThumbnail ); + setThumbnail = 'setThumbnail_' + post_type; + $link.text( setPostThumbnailL10n[ setThumbnail ] ); if ( str == '0' ) { alert( setPostThumbnailL10n.error ); } else { diff --git a/wp-admin/js/set-post-thumbnail.min.js b/wp-admin/js/set-post-thumbnail.min.js index dcea06a69e..a0cb8737a5 100644 --- a/wp-admin/js/set-post-thumbnail.min.js +++ b/wp-admin/js/set-post-thumbnail.min.js @@ -1 +1 @@ -function WPSetAsThumbnail(a,b){var c=jQuery("a#wp-post-thumbnail-"+a);c.text(setPostThumbnailL10n.saving),jQuery.post(ajaxurl,{action:"set-post-thumbnail",post_id:post_id,thumbnail_id:a,_ajax_nonce:b,cookie:encodeURIComponent(document.cookie)},function(b){var d=window.dialogArguments||opener||parent||top;c.text(setPostThumbnailL10n.setThumbnail),"0"==b?alert(setPostThumbnailL10n.error):(jQuery("a.wp-post-thumbnail").show(),c.text(setPostThumbnailL10n.done),c.fadeOut(2e3),d.WPSetThumbnailID(a),d.WPSetThumbnailHTML(b))})} \ No newline at end of file +function WPSetAsThumbnail(a,b){var c=jQuery("a#wp-post-thumbnail-"+a);c.text(setPostThumbnailL10n.saving),jQuery.post(ajaxurl,{action:"set-post-thumbnail",post_id:post_id,thumbnail_id:a,_ajax_nonce:b,cookie:encodeURIComponent(document.cookie)},function(b){var d=window.dialogArguments||opener||parent||top;setThumbnail="setThumbnail_"+post_type,c.text(setPostThumbnailL10n[setThumbnail]),"0"==b?alert(setPostThumbnailL10n.error):(jQuery("a.wp-post-thumbnail").show(),c.text(setPostThumbnailL10n.done),c.fadeOut(2e3),d.WPSetThumbnailID(a),d.WPSetThumbnailHTML(b))})} \ No newline at end of file diff --git a/wp-includes/media.php b/wp-includes/media.php index 352c7b2f6f..27a9e1d1f1 100644 --- a/wp-includes/media.php +++ b/wp-includes/media.php @@ -2313,6 +2313,7 @@ function wp_maybe_load_embeds() { } wp_embed_register_handler( 'youtube_embed_url', '#https?://(www.)?youtube\.com/embed/([^/]+)#i', 'wp_embed_handler_youtube' ); + wp_embed_register_handler( 'youtube_v_url', '#https?://(www.)?youtube\.com/v/([^/]+)#i', 'wp_embed_handler_youtube' ); wp_embed_register_handler( 'googlevideo', '#http://video\.google\.([A-Za-z.]{2,5})/videoplay\?docid=([\d-]+)(.*?)#i', 'wp_embed_handler_googlevideo' ); @@ -3008,6 +3009,8 @@ function wp_enqueue_media( $args = array() ) { $hier = $post && is_post_type_hierarchical( $post->post_type ); + $post_type_object = get_post_type_object( $post->post_type ); + $strings = array( // Generic 'url' => __( 'URL' ), @@ -3066,8 +3069,8 @@ function wp_enqueue_media( $args = array() ) { 'insertFromUrlTitle' => __( 'Insert from URL' ), // Featured Images - 'setFeaturedImageTitle' => __( 'Set Featured Image' ), - 'setFeaturedImage' => __( 'Set featured image' ), + 'setFeaturedImageTitle' => $post_type_object->labels->featured_image, + 'setFeaturedImage' => $post_type_object->labels->set_featured_image, // Gallery 'createGalleryTitle' => __( 'Create Gallery' ), diff --git a/wp-includes/post.php b/wp-includes/post.php index 180513f254..451e29f596 100644 --- a/wp-includes/post.php +++ b/wp-includes/post.php @@ -1624,12 +1624,17 @@ function _post_type_meta_capabilities( $capabilities = null ) { * - parent_item_colon - This string isn't used on non-hierarchical types. In hierarchical * ones the default is 'Parent Page:'. * - all_items - String for the submenu. Default is All Posts/All Pages. + * - featured_image - Default is Featured Image. + * - set_featured_image - Default is Set featured image. + * - remove_featured_image - Default is Remove featured image. + * - use_featured_image - Default is Use as featured image. * - menu_name - Default is the same as `name`. * * Above, the first default value is for non-hierarchical post types (like posts) * and the second one is for hierarchical post types (like pages). * * @since 3.0.0 + * @since 4.3.0 Added the `featured_image`, `set_featured_image`, `remove_featured_image`, and `use_featured_image` labels. * @access private * * @param object $post_type_object Post type object. @@ -1648,7 +1653,11 @@ function get_post_type_labels( $post_type_object ) { 'not_found' => array( __('No posts found.'), __('No pages found.') ), 'not_found_in_trash' => array( __('No posts found in Trash.'), __('No pages found in Trash.') ), 'parent_item_colon' => array( null, __('Parent Page:') ), - 'all_items' => array( __( 'All Posts' ), __( 'All Pages' ) ) + 'all_items' => array( __( 'All Posts' ), __( 'All Pages' ) ), + 'featured_image' => array( __( 'Featured Image' ), __( 'Featured Image' ) ), + 'set_featured_image' => array( __( 'Set featured image' ), __( 'Set featured image' ) ), + 'remove_featured_image' => array( __( 'Remove featured image' ), __( 'Remove featured image' ) ), + 'use_featured_image' => array( __( 'Use as featured image' ), __( 'Use as featured image' ) ), ); $nohier_vs_hier_defaults['menu_name'] = $nohier_vs_hier_defaults['name']; diff --git a/wp-includes/script-loader.php b/wp-includes/script-loader.php index 6cd361b5d3..991e78e13e 100644 --- a/wp-includes/script-loader.php +++ b/wp-includes/script-loader.php @@ -570,13 +570,20 @@ function wp_default_scripts( &$scripts ) { 'error' => __( 'Could not load the preview image. Please reload the page and try again.' ) )); - $scripts->add( 'set-post-thumbnail', "/wp-admin/js/set-post-thumbnail$suffix.js", array( 'jquery' ), false, 1 ); - did_action( 'init' ) && $scripts->localize( 'set-post-thumbnail', 'setPostThumbnailL10n', array( - 'setThumbnail' => __( 'Use as featured image' ), + $setPostThumbnailL10n = array( + 'setThumbnail' => __( 'Use as featured image' ), // Back compat 'saving' => __( 'Saving...' ), 'error' => __( 'Could not set that as the thumbnail image. Try a different attachment.' ), 'done' => __( 'Done' ) - ) ); + ); + + foreach ( get_post_types( null, 'objects' ) as $post_type_object ) { + if ( isset( $post_type_object->labels->use_featured_image ) ) { + $setPostThumbnailL10n[ "setThumbnail_{$post_type_object->name}" ] = $post_type_object->labels->use_featured_image; + } + } + $scripts->add( 'set-post-thumbnail', "/wp-admin/js/set-post-thumbnail$suffix.js", array( 'jquery' ), false, 1 ); + did_action( 'init' ) && $scripts->localize( 'set-post-thumbnail', 'setPostThumbnailL10n', $setPostThumbnailL10n ); // Navigation Menus $scripts->add( 'nav-menu', "/wp-admin/js/nav-menu$suffix.js", array( 'jquery-ui-sortable', 'jquery-ui-draggable', 'jquery-ui-droppable', 'wp-lists', 'postbox' ) ); diff --git a/wp-includes/version.php b/wp-includes/version.php index afb1e99b5a..e01978127b 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -4,7 +4,7 @@ * * @global string $wp_version */ -$wp_version = '4.3-alpha-32672'; +$wp_version = '4.3-alpha-32673'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.