From 54321f4c6e884828be6fe27943956ca266a1ed30 Mon Sep 17 00:00:00 2001 From: Scott Taylor Date: Thu, 15 May 2014 02:45:15 +0000 Subject: [PATCH] Eliminate use of `extract()` in `get_media_item()`. To test, fire open the old media in the console: `tb_show('Old Media is Weird', 'media-upload.php?type=image&TB_iframe=true&post_id=0');` See #22400. Built from https://develop.svn.wordpress.org/trunk@28407 git-svn-id: http://core.svn.wordpress.org/trunk@28234 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/includes/media.php | 37 +++++++++++++++++++------------ wp-includes/bookmark-template.php | 2 +- 2 files changed, 24 insertions(+), 15 deletions(-) diff --git a/wp-admin/includes/media.php b/wp-admin/includes/media.php index 28c311c738..cda0638a54 100644 --- a/wp-admin/includes/media.php +++ b/wp-admin/includes/media.php @@ -1285,7 +1285,13 @@ function get_media_item( $attachment_id, $args = null ) { $post = get_post( $attachment_id ); $current_post_id = !empty( $_GET['post_id'] ) ? (int) $_GET['post_id'] : 0; - $default_args = array( 'errors' => null, 'send' => $current_post_id ? post_type_supports( get_post_type( $current_post_id ), 'editor' ) : true, 'delete' => true, 'toggle' => true, 'show_title' => true ); + $default_args = array( + 'errors' => null, + 'send' => $current_post_id ? post_type_supports( get_post_type( $current_post_id ), 'editor' ) : true, + 'delete' => true, + 'toggle' => true, + 'show_title' => true + ); $args = wp_parse_args( $args, $default_args ); /** @@ -1297,8 +1303,7 @@ function get_media_item( $attachment_id, $args = null ) { * * @param array $args An array of arguments. */ - $args = apply_filters( 'get_media_item_args', $args ); - extract( $args, EXTR_SKIP ); + $r = apply_filters( 'get_media_item_args', $args ); $toggle_on = __( 'Show' ); $toggle_off = __( 'Hide' ); @@ -1311,10 +1316,10 @@ function get_media_item( $attachment_id, $args = null ) { $type = array_shift( $keys ); $type_html = ""; - $form_fields = get_attachment_fields_to_edit( $post, $errors ); + $form_fields = get_attachment_fields_to_edit( $post, $r['errors'] ); - if ( $toggle ) { - $class = empty( $errors ) ? 'startclosed' : 'startopen'; + if ( $r['toggle'] ) { + $class = empty( $r['errors'] ) ? 'startclosed' : 'startopen'; $toggle_links = " $toggle_on $toggle_off"; @@ -1324,7 +1329,7 @@ function get_media_item( $attachment_id, $args = null ) { } $display_title = ( !empty( $title ) ) ? $title : $filename; // $title shouldn't ever be empty, but just in case - $display_title = $show_title ? "
" . wp_html_excerpt( $display_title, 60, '…' ) . "
" : ''; + $display_title = $r['show_title'] ? "
" . wp_html_excerpt( $display_title, 60, '…' ) . "
" : ''; $gallery = ( ( isset( $_REQUEST['tab'] ) && 'gallery' == $_REQUEST['tab'] ) || ( isset( $redir_tab ) && 'gallery' == $redir_tab ) ); $order = ''; @@ -1398,8 +1403,11 @@ function get_media_item( $attachment_id, $args = null ) { 'extra_rows' => array(), ); - if ( $send ) - $send = get_submit_button( __( 'Insert into Post' ), 'button', "send[$attachment_id]", false ); + if ( $r['send'] ) { + $r['send'] = get_submit_button( __( 'Insert into Post' ), 'button', "send[$attachment_id]", false ); + } + + $delete = empty( $r['delete'] ) ? '' : $r['delete']; if ( $delete && current_user_can( 'delete_post', $attachment_id ) ) { if ( !EMPTY_TRASH_DAYS ) { $delete = "" . __( 'Delete Permanently' ) . ''; @@ -1419,19 +1427,20 @@ function get_media_item( $attachment_id, $args = null ) { $thumbnail = ''; $calling_post_id = 0; - if ( isset( $_GET['post_id'] ) ) + if ( isset( $_GET['post_id'] ) ) { $calling_post_id = absint( $_GET['post_id'] ); - elseif ( isset( $_POST ) && count( $_POST ) ) // Like for async-upload where $_GET['post_id'] isn't set + } elseif ( isset( $_POST ) && count( $_POST ) ) {// Like for async-upload where $_GET['post_id'] isn't set $calling_post_id = $post->post_parent; + } 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 ) { $ajax_nonce = wp_create_nonce( "set_post_thumbnail-$calling_post_id" ); $thumbnail = "" . esc_html__( "Use as featured image" ) . ""; } - if ( ( $send || $thumbnail || $delete ) && !isset( $form_fields['buttons'] ) ) - $form_fields['buttons'] = array( 'tr' => "\t\t$send $thumbnail $delete\n" ); - + if ( ( $r['send'] || $thumbnail || $delete ) && !isset( $form_fields['buttons'] ) ) { + $form_fields['buttons'] = array( 'tr' => "\t\t" . $r['send'] . " $thumbnail $delete\n" ); + } $hidden_fields = array(); foreach ( $form_fields as $id => $field ) { diff --git a/wp-includes/bookmark-template.php b/wp-includes/bookmark-template.php index adbe9611fa..e791e704ae 100644 --- a/wp-includes/bookmark-template.php +++ b/wp-includes/bookmark-template.php @@ -241,7 +241,7 @@ function wp_list_bookmarks( $args = '' ) { } } - if ( $categorize ) { + if ( $r['categorize'] ) { // Split the bookmarks into ul's for each category foreach ( (array) $cats as $cat ) { $params = array_merge( $r, array( 'category' => $cat->term_id ) );