diff --git a/wp-admin/admin-ajax.php b/wp-admin/admin-ajax.php index 6be4a87a13..7d9266d80f 100644 --- a/wp-admin/admin-ajax.php +++ b/wp-admin/admin-ajax.php @@ -105,6 +105,7 @@ $core_actions_post = array( 'send-link-to-editor', 'send-attachment-to-editor', 'save-attachment-order', + 'media-create-image-subsizes', 'heartbeat', 'get-revision-diffs', 'save-user-color-scheme', diff --git a/wp-admin/includes/ajax-actions.php b/wp-admin/includes/ajax-actions.php index 28db878ef5..d9b688851e 100644 --- a/wp-admin/includes/ajax-actions.php +++ b/wp-admin/includes/ajax-actions.php @@ -111,6 +111,7 @@ function wp_ajax_ajax_tag_search() { $taxonomy = sanitize_key( $_GET['tax'] ); $tax = get_taxonomy( $taxonomy ); + if ( ! $tax ) { wp_die( 0 ); } @@ -125,10 +126,12 @@ function wp_ajax_ajax_tag_search() { if ( ',' !== $comma ) { $s = str_replace( $comma, ',', $s ); } + if ( false !== strpos( $s, ',' ) ) { $s = explode( ',', $s ); $s = $s[ count( $s ) - 1 ]; } + $s = trim( $s ); /** @@ -193,6 +196,7 @@ function wp_ajax_wp_compression_test() { if ( ! isset( $_SERVER['HTTP_ACCEPT_ENCODING'] ) ) { wp_die( -1 ); } + if ( false !== stripos( $_SERVER['HTTP_ACCEPT_ENCODING'], 'deflate' ) && function_exists( 'gzdeflate' ) && ! $force_gzip ) { header( 'Content-Encoding: deflate' ); $out = gzdeflate( $test_str, 1 ); @@ -202,6 +206,7 @@ function wp_ajax_wp_compression_test() { } else { wp_die( -1 ); } + echo $out; wp_die(); } elseif ( 'no' == $_GET['test'] ) { @@ -230,6 +235,7 @@ function wp_ajax_imgedit_preview() { check_ajax_referer( "image_editor-$post_id" ); include_once( ABSPATH . 'wp-admin/includes/image-edit.php' ); + if ( ! stream_preview_image( $post_id ) ) { wp_die( -1 ); } @@ -295,6 +301,7 @@ function wp_ajax_autocomplete_user() { 'fields' => 'ID', ) ) : array() ); + $exclude_blog_users = ( $type == 'add' ? get_users( array( 'blog_id' => $id, @@ -481,14 +488,18 @@ function _wp_ajax_delete_comment_response( $comment_id, $delta = -1 ) { // What type of comment count are we looking for? $status = 'all'; $parsed = parse_url( $url ); + if ( isset( $parsed['query'] ) ) { parse_str( $parsed['query'], $query_vars ); + if ( ! empty( $query_vars['comment_status'] ) ) { $status = $query_vars['comment_status']; } + if ( ! empty( $query_vars['p'] ) ) { $post_id = (int) $query_vars['p']; } + if ( ! empty( $query_vars['comment_type'] ) ) { $type = $query_vars['comment_type']; } @@ -550,36 +561,45 @@ function _wp_ajax_add_hierarchical_term() { $action = $_POST['action']; $taxonomy = get_taxonomy( substr( $action, 4 ) ); check_ajax_referer( $action, '_ajax_nonce-add-' . $taxonomy->name ); + if ( ! current_user_can( $taxonomy->cap->edit_terms ) ) { wp_die( -1 ); } + $names = explode( ',', $_POST[ 'new' . $taxonomy->name ] ); $parent = isset( $_POST[ 'new' . $taxonomy->name . '_parent' ] ) ? (int) $_POST[ 'new' . $taxonomy->name . '_parent' ] : 0; + if ( 0 > $parent ) { $parent = 0; } + if ( $taxonomy->name == 'category' ) { $post_category = isset( $_POST['post_category'] ) ? (array) $_POST['post_category'] : array(); } else { $post_category = ( isset( $_POST['tax_input'] ) && isset( $_POST['tax_input'][ $taxonomy->name ] ) ) ? (array) $_POST['tax_input'][ $taxonomy->name ] : array(); } + $checked_categories = array_map( 'absint', (array) $post_category ); $popular_ids = wp_popular_terms_checklist( $taxonomy->name, 0, 10, false ); foreach ( $names as $cat_name ) { $cat_name = trim( $cat_name ); $category_nicename = sanitize_title( $cat_name ); + if ( '' === $category_nicename ) { continue; } $cat_id = wp_insert_term( $cat_name, $taxonomy->name, array( 'parent' => $parent ) ); + if ( ! $cat_id || is_wp_error( $cat_id ) ) { continue; } else { $cat_id = $cat_id['term_id']; } + $checked_categories[] = $cat_id; + if ( $parent ) { // Do these all at once in a second continue; } @@ -670,27 +690,32 @@ function wp_ajax_delete_comment() { $id = isset( $_POST['id'] ) ? (int) $_POST['id'] : 0; $comment = get_comment( $id ); + if ( ! $comment ) { wp_die( time() ); } + if ( ! current_user_can( 'edit_comment', $comment->comment_ID ) ) { wp_die( -1 ); } check_ajax_referer( "delete-comment_$id" ); $status = wp_get_comment_status( $comment ); + $delta = -1; - $delta = -1; if ( isset( $_POST['trash'] ) && 1 == $_POST['trash'] ) { if ( 'trash' == $status ) { wp_die( time() ); } + $r = wp_trash_comment( $comment ); } elseif ( isset( $_POST['untrash'] ) && 1 == $_POST['untrash'] ) { if ( 'trash' != $status ) { wp_die( time() ); } + $r = wp_untrash_comment( $comment ); + if ( ! isset( $_POST['comment_status'] ) || $_POST['comment_status'] != 'trash' ) { // undo trash, not in trash $delta = 1; } @@ -698,12 +723,15 @@ function wp_ajax_delete_comment() { if ( 'spam' == $status ) { wp_die( time() ); } + $r = wp_spam_comment( $comment ); } elseif ( isset( $_POST['unspam'] ) && 1 == $_POST['unspam'] ) { if ( 'spam' != $status ) { wp_die( time() ); } + $r = wp_unspam_comment( $comment ); + if ( ! isset( $_POST['comment_status'] ) || $_POST['comment_status'] != 'spam' ) { // undo spam, not in spam $delta = 1; } @@ -716,6 +744,7 @@ function wp_ajax_delete_comment() { if ( $r ) { // Decide if we need to send back '1' or a more complicated response including page links and comment counts _wp_ajax_delete_comment_response( $comment->comment_ID, $delta ); } + wp_die( 0 ); } @@ -734,6 +763,7 @@ function wp_ajax_delete_tag() { $taxonomy = ! empty( $_POST['taxonomy'] ) ? $_POST['taxonomy'] : 'post_tag'; $tag = get_term( $tag_id, $taxonomy ); + if ( ! $tag || is_wp_error( $tag ) ) { wp_die( 1 ); } @@ -754,6 +784,7 @@ function wp_ajax_delete_link() { $id = isset( $_POST['id'] ) ? (int) $_POST['id'] : 0; check_ajax_referer( "delete-bookmark_$id" ); + if ( ! current_user_can( 'manage_links' ) ) { wp_die( -1 ); } @@ -780,6 +811,7 @@ function wp_ajax_delete_meta() { check_ajax_referer( "delete-meta_$id" ); $meta = get_metadata_by_mid( 'post', $id ); + if ( ! $meta ) { wp_die( 1 ); } @@ -787,9 +819,11 @@ function wp_ajax_delete_meta() { if ( is_protected_meta( $meta->meta_key, 'post' ) || ! current_user_can( 'delete_post_meta', $meta->post_id, $meta->meta_key ) ) { wp_die( -1 ); } + if ( delete_meta( $meta->meta_id ) ) { wp_die( 1 ); } + wp_die( 0 ); } @@ -804,9 +838,10 @@ function wp_ajax_delete_post( $action ) { if ( empty( $action ) ) { $action = 'delete-post'; } - $id = isset( $_POST['id'] ) ? (int) $_POST['id'] : 0; + $id = isset( $_POST['id'] ) ? (int) $_POST['id'] : 0; check_ajax_referer( "{$action}_$id" ); + if ( ! current_user_can( 'delete_post', $id ) ) { wp_die( -1 ); } @@ -833,9 +868,10 @@ function wp_ajax_trash_post( $action ) { if ( empty( $action ) ) { $action = 'trash-post'; } - $id = isset( $_POST['id'] ) ? (int) $_POST['id'] : 0; + $id = isset( $_POST['id'] ) ? (int) $_POST['id'] : 0; check_ajax_referer( "{$action}_$id" ); + if ( ! current_user_can( 'delete_post', $id ) ) { wp_die( -1 ); } @@ -868,6 +904,7 @@ function wp_ajax_untrash_post( $action ) { if ( empty( $action ) ) { $action = 'untrash-post'; } + wp_ajax_trash_post( $action ); } @@ -882,9 +919,10 @@ function wp_ajax_delete_page( $action ) { if ( empty( $action ) ) { $action = 'delete-page'; } - $id = isset( $_POST['id'] ) ? (int) $_POST['id'] : 0; + $id = isset( $_POST['id'] ) ? (int) $_POST['id'] : 0; check_ajax_referer( "{$action}_$id" ); + if ( ! current_user_can( 'delete_page', $id ) ) { wp_die( -1 ); } @@ -906,9 +944,9 @@ function wp_ajax_delete_page( $action ) { * @since 3.1.0 */ function wp_ajax_dim_comment() { - $id = isset( $_POST['id'] ) ? (int) $_POST['id'] : 0; - + $id = isset( $_POST['id'] ) ? (int) $_POST['id'] : 0; $comment = get_comment( $id ); + if ( ! $comment ) { $x = new WP_Ajax_Response( array( @@ -928,11 +966,13 @@ function wp_ajax_dim_comment() { } $current = wp_get_comment_status( $comment ); + if ( isset( $_POST['new'] ) && $_POST['new'] == $current ) { wp_die( time() ); } check_ajax_referer( "approve-comment_$id" ); + if ( in_array( $current, array( 'unapproved', 'spam' ) ) ) { $result = wp_set_comment_status( $comment, 'approve', true ); } else { @@ -965,27 +1005,35 @@ function wp_ajax_add_link_category( $action ) { if ( empty( $action ) ) { $action = 'add-link-category'; } + check_ajax_referer( $action ); $tax = get_taxonomy( 'link_category' ); + if ( ! current_user_can( $tax->cap->manage_terms ) ) { wp_die( -1 ); } + $names = explode( ',', wp_unslash( $_POST['newcat'] ) ); $x = new WP_Ajax_Response(); + foreach ( $names as $cat_name ) { $cat_name = trim( $cat_name ); $slug = sanitize_title( $cat_name ); + if ( '' === $slug ) { continue; } $cat_id = wp_insert_term( $cat_name, 'link_category' ); + if ( ! $cat_id || is_wp_error( $cat_id ) ) { continue; } else { $cat_id = $cat_id['term_id']; } + $cat_name = esc_html( $cat_name ); + $x->add( array( 'what' => 'link-category', @@ -1022,6 +1070,7 @@ function wp_ajax_add_tag() { if ( ! $tag || is_wp_error( $tag ) ) { $message = __( 'An error has occurred. Please reload the page and try again.' ); + if ( is_wp_error( $tag ) && $tag->get_error_message() ) { $message = $tag->get_error_message(); } @@ -1057,6 +1106,7 @@ function wp_ajax_add_tag() { 'supplemental' => compact( 'parents', 'noparents' ), ) ); + $x->add( array( 'what' => 'term', @@ -1064,6 +1114,7 @@ function wp_ajax_add_tag() { 'supplemental' => (array) $tag, ) ); + $x->send(); } @@ -1079,6 +1130,7 @@ function wp_ajax_get_tagcloud() { $taxonomy = sanitize_key( $_POST['tax'] ); $tax = get_taxonomy( $taxonomy ); + if ( ! $tax ) { wp_die( 0 ); } @@ -1123,7 +1175,6 @@ function wp_ajax_get_tagcloud() { } echo $return; - wp_die(); } @@ -1138,9 +1189,11 @@ function wp_ajax_get_tagcloud() { */ function wp_ajax_get_comments( $action ) { global $post_id; + if ( empty( $action ) ) { $action = 'get-comments'; } + check_ajax_referer( $action ); if ( empty( $post_id ) && ! empty( $_REQUEST['p'] ) ) { @@ -1167,6 +1220,7 @@ function wp_ajax_get_comments( $action ) { } $x = new WP_Ajax_Response(); + ob_start(); foreach ( $wp_list_table->items as $comment ) { if ( ! current_user_can( 'edit_comment', $comment->comment_ID ) && 0 === $comment->comment_approved ) { @@ -1183,6 +1237,7 @@ function wp_ajax_get_comments( $action ) { 'data' => $comment_list_item, ) ); + $x->send(); } @@ -1202,6 +1257,7 @@ function wp_ajax_replyto_comment( $action ) { $comment_post_ID = (int) $_POST['comment_post_ID']; $post = get_post( $comment_post_ID ); + if ( ! $post ) { wp_die( -1 ); } @@ -1217,6 +1273,7 @@ function wp_ajax_replyto_comment( $action ) { } $user = wp_get_current_user(); + if ( $user->exists() ) { $user_ID = $user->ID; $comment_author = wp_slash( $user->display_name ); @@ -1224,6 +1281,7 @@ function wp_ajax_replyto_comment( $action ) { $comment_author_url = wp_slash( $user->user_url ); $comment_content = trim( $_POST['content'] ); $comment_type = isset( $_POST['comment_type'] ) ? trim( $_POST['comment_type'] ) : ''; + if ( current_user_can( 'unfiltered_html' ) ) { if ( ! isset( $_POST['_wp_unfiltered_html_comment'] ) ) { $_POST['_wp_unfiltered_html_comment'] = ''; @@ -1245,9 +1303,11 @@ function wp_ajax_replyto_comment( $action ) { } $comment_parent = 0; + if ( isset( $_POST['comment_ID'] ) ) { $comment_parent = absint( $_POST['comment_ID'] ); } + $comment_auto_approved = false; $commentdata = compact( 'comment_post_ID', 'comment_author', 'comment_author_email', 'comment_author_url', 'comment_content', 'comment_type', 'comment_parent', 'user_ID' ); @@ -1273,6 +1333,7 @@ function wp_ajax_replyto_comment( $action ) { } $comment = get_comment( $comment_id ); + if ( ! $comment ) { wp_die( 1 ); } @@ -1334,6 +1395,7 @@ function wp_ajax_edit_comment() { check_ajax_referer( 'replyto-comment', '_ajax_nonce-replyto-comment' ); $comment_id = (int) $_POST['comment_ID']; + if ( ! current_user_can( 'edit_comment', $comment_id ) ) { wp_die( -1 ); } @@ -1352,6 +1414,7 @@ function wp_ajax_edit_comment() { $wp_list_table = _get_list_table( $checkbox ? 'WP_Comments_List_Table' : 'WP_Post_Comments_List_Table', array( 'screen' => 'edit-comments' ) ); $comment = get_comment( $comment_id ); + if ( empty( $comment->comment_ID ) ) { wp_die( -1 ); } @@ -1390,8 +1453,8 @@ function wp_ajax_add_menu_item() { // For performance reasons, we omit some object properties from the checklist. // The following is a hacky way to restore them when adding non-custom items. - $menu_items_data = array(); + foreach ( (array) $_POST['menu-item'] as $menu_item_data ) { if ( ! empty( $menu_item_data['menu-item-type'] ) && @@ -1431,6 +1494,7 @@ function wp_ajax_add_menu_item() { foreach ( (array) $item_ids as $menu_item_id ) { $menu_obj = get_post( $menu_item_id ); + if ( ! empty( $menu_obj->ID ) ) { $menu_obj = wp_setup_nav_menu_item( $menu_obj ); $menu_obj->title = empty( $menu_obj->title ) ? __( 'Menu Item' ) : $menu_obj->title; @@ -1454,8 +1518,10 @@ function wp_ajax_add_menu_item() { 'link_before' => '', 'walker' => new $walker_class_name, ); + echo walk_nav_menu_tree( $menu_items, 0, (object) $args ); } + wp_die(); } @@ -1474,6 +1540,7 @@ function wp_ajax_add_meta() { if ( ! current_user_can( 'edit_post', $pid ) ) { wp_die( -1 ); } + if ( isset( $_POST['metakeyselect'] ) && '#NONE#' == $_POST['metakeyselect'] && empty( $_POST['metakeyinput'] ) ) { wp_die( 1 ); } @@ -1490,6 +1557,7 @@ function wp_ajax_add_meta() { $post_data['post_title'] = sprintf( __( 'Draft created on %1$s at %2$s' ), gmdate( __( 'F j, Y' ), $now ), gmdate( __( 'g:i a' ), $now ) ); $pid = edit_post( $post_data ); + if ( $pid ) { if ( is_wp_error( $pid ) ) { $x = new WP_Ajax_Response( @@ -1518,7 +1586,8 @@ function wp_ajax_add_meta() { $meta = get_metadata_by_mid( 'post', $mid ); $pid = (int) $meta->post_id; $meta = get_object_vars( $meta ); - $x = new WP_Ajax_Response( + + $x = new WP_Ajax_Response( array( 'what' => 'meta', 'id' => $mid, @@ -1531,18 +1600,25 @@ function wp_ajax_add_meta() { $mid = (int) key( $_POST['meta'] ); $key = wp_unslash( $_POST['meta'][ $mid ]['key'] ); $value = wp_unslash( $_POST['meta'][ $mid ]['value'] ); + if ( '' == trim( $key ) ) { wp_die( __( 'Please provide a custom field name.' ) ); } + $meta = get_metadata_by_mid( 'post', $mid ); + if ( ! $meta ) { wp_die( 0 ); // if meta doesn't exist } - if ( is_protected_meta( $meta->meta_key, 'post' ) || is_protected_meta( $key, 'post' ) || + + if ( + is_protected_meta( $meta->meta_key, 'post' ) || is_protected_meta( $key, 'post' ) || ! current_user_can( 'edit_post_meta', $meta->post_id, $meta->meta_key ) || - ! current_user_can( 'edit_post_meta', $meta->post_id, $key ) ) { + ! current_user_can( 'edit_post_meta', $meta->post_id, $key ) + ) { wp_die( -1 ); } + if ( $meta->meta_value != $value || $meta->meta_key != $key ) { $u = update_metadata_by_mid( 'post', $mid, $value, $key ); if ( ! $u ) { @@ -1584,10 +1660,13 @@ function wp_ajax_add_user( $action ) { } check_ajax_referer( $action ); + if ( ! current_user_can( 'create_users' ) ) { wp_die( -1 ); } + $user_id = edit_user(); + if ( ! $user_id ) { wp_die( 0 ); } elseif ( is_wp_error( $user_id ) ) { @@ -1599,8 +1678,8 @@ function wp_ajax_add_user( $action ) { ); $x->send(); } - $user_object = get_userdata( $user_id ); + $user_object = get_userdata( $user_id ); $wp_list_table = _get_list_table( 'WP_Users_List_Table' ); $role = current( $user_object->roles ); @@ -1799,10 +1878,13 @@ function wp_ajax_menu_locations_save() { if ( ! current_user_can( 'edit_theme_options' ) ) { wp_die( -1 ); } + check_ajax_referer( 'add-menu_item', 'menu-settings-column-nonce' ); + if ( ! isset( $_POST['menu-locations'] ) ) { wp_die( 0 ); } + set_theme_mod( 'nav_menu_locations', array_map( 'absint', $_POST['menu-locations'] ) ); wp_die( 1 ); } @@ -1957,6 +2039,7 @@ function wp_ajax_inline_save() { if ( empty( $data['comment_status'] ) ) { $data['comment_status'] = 'closed'; } + if ( empty( $data['ping_status'] ) ) { $data['ping_status'] = 'closed'; } @@ -2012,6 +2095,7 @@ function wp_ajax_inline_save_tax() { $taxonomy = sanitize_key( $_POST['taxonomy'] ); $tax = get_taxonomy( $taxonomy ); + if ( ! $tax ) { wp_die( 0 ); } @@ -2032,6 +2116,7 @@ function wp_ajax_inline_save_tax() { $_POST['description'] = $tag->description; $updated = wp_update_term( $id, $taxonomy, $_POST ); + if ( $updated && ! is_wp_error( $updated ) ) { $tag = get_term( $updated['term_id'], $taxonomy ); if ( ! $tag || is_wp_error( $tag ) ) { @@ -2046,13 +2131,16 @@ function wp_ajax_inline_save_tax() { } wp_die( __( 'Item not updated.' ) ); } + $level = 0; $parent = $tag->parent; + while ( $parent > 0 ) { $parent_tag = get_term( $parent, $taxonomy ); $parent = $parent_tag->parent; $level++; } + $wp_list_table->single_row( $tag, $level ); wp_die(); } @@ -2076,6 +2164,7 @@ function wp_ajax_find_posts() { 'post_status' => 'any', 'posts_per_page' => 50, ); + if ( '' !== $s ) { $args['s'] = $s; } @@ -2141,10 +2230,13 @@ function wp_ajax_widgets_order() { // Save widgets order for all sidebars. if ( is_array( $_POST['sidebars'] ) ) { $sidebars = array(); + foreach ( wp_unslash( $_POST['sidebars'] ) as $key => $val ) { $sb = array(); + if ( ! empty( $val ) ) { $val = explode( ',', $val ); + foreach ( $val as $k => $v ) { if ( strpos( $v, 'widget-' ) === false ) { continue; @@ -2155,6 +2247,7 @@ function wp_ajax_widgets_order() { } $sidebars[ $key ] = $sb; } + wp_set_sidebars_widgets( $sidebars ); wp_die( 1 ); } @@ -2320,6 +2413,82 @@ function wp_ajax_delete_inactive_widgets() { wp_die(); } +/** + * Ajax handler for creating missing image sub-sizes for just uploaded images. + * + * @since 5.3.0 + */ +function wp_ajax_media_create_image_subsizes() { + check_ajax_referer( 'media-form' ); + + if ( ! current_user_can( 'upload_files' ) ) { + wp_send_json_error( array( 'message' => __( 'Sorry, you are not allowed to upload files.' ) ) ); + } + + // Using Plupload `file.id` as ref. + if ( ! empty( $_POST['_wp_temp_image_ref'] ) ) { + $image_ref = preg_replace( '/[^a-zA-Z0-9_]/', '', $_POST['_wp_temp_image_ref'] ); + } else { + wp_send_json_error( array( 'message' => __( 'Invalid file reference.' ) ) ); + } + + // Uploading of images usually fails while creating the sub-sizes, either because of a timeout or out of memory. + // At this point the file has been uploaded and an attachment post created, but because of the PHP fatal error + // the cliend doesn't know the attachment ID yet. + // To be able to find the new attachment_id in these cases we temporarily store an upload reference sent by the client + // in the original upload request. It is used to save a transient with the attachment_id as value. + // That reference currently is Plupload's `file.id` but can be any sufficiently random alpha-numeric string. + $attachment_id = get_transient( '_wp_temp_image_ref:' . $image_ref ); + + if ( empty( $attachment_id ) ) { + wp_send_json_error( array( 'message' => __( 'Upload failed. Please reload and try again.' ) ) ); + } + + if ( ! empty( $_POST['_wp_upload_failed_cleanup'] ) ) { + // Upload failed. Cleanup. + if ( wp_attachment_is_image( $attachment_id ) ) { + $attachment = get_post( $attachment_id ); + + // Posted at most 10 min ago. + if ( $attachment && ( time() - strtotime( $attachment->post_date_gmt ) < 600 ) ) { + /** + * Runs when an image upload fails during the post-processing phase, + * and the newly created attachment post is about to be deleted. + * + * @since 5.3.0 + * + * @param int $attachment_id The attachment post ID. + */ + do_action( 'wp_upload_failed_cleanup', $attachment_id ); + + wp_delete_attachment( $attachment_id, true ); + wp_send_json_success(); + } + } + } + + // This can still be pretty slow and cause timeout or out of memory errors. + // The js that handles the response would need to also handle HTTP 500 errors. + wp_update_image_subsizes( $attachment_id ); + + if ( ! empty( $_POST['_legasy_support'] ) ) { + // The old (inline) uploader. Only needs the attachment_id. + $response = array( 'id' => $attachment_id ); + } else { + // Media modal and Media Library grid view. + $response = wp_prepare_attachment_for_js( $attachment_id ); + + if ( ! $response ) { + wp_send_json_error( array( 'message' => __( 'Upload failed.' ) ) ); + } + } + + // At this point the image has been uploaded successfully. + delete_transient( '_wp_temp_image_ref:' . $image_ref ); + + wp_send_json_success( $response ); +} + /** * Ajax handler for uploading attachments * @@ -2349,6 +2518,7 @@ function wp_ajax_upload_attachment() { if ( isset( $_REQUEST['post_id'] ) ) { $post_id = $_REQUEST['post_id']; + if ( ! current_user_can( 'edit_post', $post_id ) ) { echo wp_json_encode( array( @@ -2375,6 +2545,7 @@ function wp_ajax_upload_attachment() { // If the context is custom header or background, make sure the uploaded file is an image. if ( isset( $post_data['context'] ) && in_array( $post_data['context'], array( 'custom-header', 'custom-background' ) ) ) { $wp_filetype = wp_check_filetype_and_ext( $_FILES['async-upload']['tmp_name'], $_FILES['async-upload']['name'] ); + if ( ! wp_match_mime_types( 'image', $wp_filetype['type'] ) ) { echo wp_json_encode( array( @@ -2438,6 +2609,7 @@ function wp_ajax_upload_attachment() { */ function wp_ajax_image_editor() { $attachment_id = intval( $_POST['postid'] ); + if ( empty( $attachment_id ) || ! current_user_can( 'edit_post', $attachment_id ) ) { wp_die( -1 ); } @@ -2649,8 +2821,10 @@ function wp_ajax_wp_remove_post_lock() { if ( empty( $_POST['post_ID'] ) || empty( $_POST['active_post_lock'] ) ) { wp_die( 0 ); } + $post_id = (int) $_POST['post_ID']; $post = get_post( $post_id ); + if ( ! $post ) { wp_die( 0 ); } @@ -2662,6 +2836,7 @@ function wp_ajax_wp_remove_post_lock() { } $active_lock = array_map( 'absint', explode( ':', $_POST['active_post_lock'] ) ); + if ( $active_lock[1] != get_current_user_id() ) { wp_die( 0 ); } @@ -2686,6 +2861,7 @@ function wp_ajax_wp_remove_post_lock() { */ function wp_ajax_dismiss_wp_pointer() { $pointer = $_POST['pointer']; + if ( $pointer != sanitize_key( $pointer ) ) { wp_die( 0 ); } @@ -2766,6 +2942,7 @@ function wp_ajax_query_attachments() { 'year', 'monthnum', ); + foreach ( get_taxonomies_for_attachments( 'objects' ) as $t ) { if ( $t->query_var && isset( $query[ $t->query_var ] ) ) { $keys[] = $t->query_var; @@ -2774,9 +2951,12 @@ function wp_ajax_query_attachments() { $query = array_intersect_key( $query, array_flip( $keys ) ); $query['post_type'] = 'attachment'; - if ( MEDIA_TRASH - && ! empty( $_REQUEST['query']['post_status'] ) - && 'trash' === $_REQUEST['query']['post_status'] ) { + + if ( + MEDIA_TRASH && + ! empty( $_REQUEST['query']['post_status'] ) && + 'trash' === $_REQUEST['query']['post_status'] + ) { $query['post_status'] = 'trash'; } else { $query['post_status'] = 'inherit'; @@ -2869,10 +3049,12 @@ function wp_ajax_save_attachment() { if ( wp_attachment_is( 'audio', $post['ID'] ) ) { $changed = false; $id3data = wp_get_attachment_metadata( $post['ID'] ); + if ( ! is_array( $id3data ) ) { $changed = true; $id3data = array(); } + foreach ( wp_get_attachment_id3_keys( (object) $post, 'edit' ) as $key => $label ) { if ( isset( $changes[ $key ] ) ) { $changed = true; @@ -2912,6 +3094,7 @@ function wp_ajax_save_attachment_compat() { if ( empty( $_REQUEST['attachments'] ) || empty( $_REQUEST['attachments'][ $id ] ) ) { wp_send_json_error(); } + $attachment_data = $_REQUEST['attachments'][ $id ]; check_ajax_referer( 'update-post_' . $id, 'nonce' ); @@ -2943,6 +3126,7 @@ function wp_ajax_save_attachment_compat() { } $attachment = wp_prepare_attachment_for_js( $id ); + if ( ! $attachment ) { wp_send_json_error(); } @@ -2981,10 +3165,13 @@ function wp_ajax_save_attachment_order() { if ( ! current_user_can( 'edit_post', $attachment_id ) ) { continue; } + $attachment = get_post( $attachment_id ); + if ( ! $attachment ) { continue; } + if ( 'attachment' != $attachment->post_type ) { continue; } @@ -3028,6 +3215,7 @@ function wp_ajax_send_attachment_to_editor() { if ( current_user_can( 'edit_post', $id ) ) { // If this attachment is unattached, attach it. Primarily a back compat thing. $insert_into_post_id = intval( $_POST['post_id'] ); + if ( 0 == $post->post_parent && $insert_into_post_id ) { wp_update_post( array( @@ -3346,6 +3534,7 @@ function wp_ajax_query_themes() { } $update_php = network_admin_url( 'update.php?action=install-theme' ); + foreach ( $api->themes as &$theme ) { $theme->install_url = add_query_arg( array( @@ -3390,7 +3579,8 @@ function wp_ajax_query_themes() { $theme->author = wp_kses( $theme->author['display_name'], $themes_allowedtags ); $theme->version = wp_kses( $theme->version, $themes_allowedtags ); $theme->description = wp_kses( $theme->description, $themes_allowedtags ); - $theme->stars = wp_star_rating( + + $theme->stars = wp_star_rating( array( 'rating' => $theme->rating, 'type' => 'percent', @@ -3398,6 +3588,7 @@ function wp_ajax_query_themes() { 'echo' => false, ) ); + $theme->num_ratings = number_format_i18n( $theme->num_ratings ); $theme->preview_url = set_url_scheme( $theme->preview_url ); } @@ -3421,9 +3612,12 @@ function wp_ajax_parse_embed() { if ( empty( $_POST['shortcode'] ) ) { wp_send_json_error(); } + $post_id = isset( $_POST['post_ID'] ) ? intval( $_POST['post_ID'] ) : 0; + if ( $post_id > 0 ) { $post = get_post( $post_id ); + if ( ! $post || ! current_user_can( 'edit_post', $post->ID ) ) { wp_send_json_error(); } @@ -3436,6 +3630,7 @@ function wp_ajax_parse_embed() { preg_match( '/' . get_shortcode_regex() . '/s', $shortcode, $matches ); $atts = shortcode_parse_atts( $matches[3] ); + if ( ! empty( $matches[5] ) ) { $url = $matches[5]; } elseif ( ! empty( $atts['src'] ) ) { @@ -3493,6 +3688,7 @@ function wp_ajax_parse_embed() { if ( has_shortcode( $parsed, 'audio' ) || has_shortcode( $parsed, 'video' ) ) { $styles = ''; $mce_styles = wpview_media_sandbox_styles(); + foreach ( $mce_styles as $style ) { $styles .= sprintf( '', $style ); } @@ -3500,9 +3696,11 @@ function wp_ajax_parse_embed() { $html = do_shortcode( $parsed ); global $wp_scripts; + if ( ! empty( $wp_scripts ) ) { $wp_scripts->done = array(); } + ob_start(); wp_print_scripts( array( 'mediaelement-vimeo', 'wp-mediaelement' ) ); $scripts = ob_get_clean(); @@ -3617,6 +3815,7 @@ function wp_ajax_parse_media_shortcode() { */ function wp_ajax_destroy_sessions() { $user = get_userdata( (int) $_POST['user_id'] ); + if ( $user ) { if ( ! current_user_can( 'edit_user', $user->ID ) ) { $user = false; @@ -3656,6 +3855,7 @@ function wp_ajax_crop_image() { $attachment_id = absint( $_POST['id'] ); check_ajax_referer( 'image_editor-' . $attachment_id, 'nonce' ); + if ( empty( $attachment_id ) || ! current_user_can( 'edit_post', $attachment_id ) ) { wp_send_json_error(); } @@ -4046,9 +4246,11 @@ function wp_ajax_delete_theme() { // Check filesystem credentials. `delete_theme()` will bail otherwise. $url = wp_nonce_url( 'themes.php?action=delete&stylesheet=' . urlencode( $stylesheet ), 'delete-theme_' . $stylesheet ); + ob_start(); $credentials = request_filesystem_credentials( $url ); ob_end_clean(); + if ( false === $credentials || ! WP_Filesystem( $credentials ) ) { global $wp_filesystem; @@ -4339,9 +4541,11 @@ function wp_ajax_delete_plugin() { // Check filesystem credentials. `delete_plugins()` will bail otherwise. $url = wp_nonce_url( 'plugins.php?action=delete-selected&verify-delete=1&checked[]=' . $plugin, 'bulk-plugins' ); + ob_start(); $credentials = request_filesystem_credentials( $url ); ob_end_clean(); + if ( false === $credentials || ! WP_Filesystem( $credentials ) ) { global $wp_filesystem; @@ -4481,6 +4685,7 @@ function wp_ajax_search_install_plugins() { */ function wp_ajax_edit_theme_plugin_file() { $r = wp_edit_theme_plugin_file( wp_unslash( $_POST ) ); // Validation of args is done in wp_edit_theme_plugin_file(). + if ( is_wp_error( $r ) ) { wp_send_json_error( array_merge( @@ -4510,6 +4715,7 @@ function wp_ajax_wp_privacy_export_personal_data() { if ( empty( $_POST['id'] ) ) { wp_send_json_error( __( 'Missing request ID.' ) ); } + $request_id = (int) $_POST['id']; if ( $request_id < 1 ) { @@ -4537,11 +4743,13 @@ function wp_ajax_wp_privacy_export_personal_data() { if ( ! isset( $_POST['exporter'] ) ) { wp_send_json_error( __( 'Missing exporter index.' ) ); } + $exporter_index = (int) $_POST['exporter']; if ( ! isset( $_POST['page'] ) ) { wp_send_json_error( __( 'Missing page index.' ) ); } + $page = (int) $_POST['page']; $send_as_email = isset( $_POST['sendAsEmail'] ) ? ( 'true' === $_POST['sendAsEmail'] ) : false; @@ -4595,6 +4803,7 @@ function wp_ajax_wp_privacy_export_personal_data() { sprintf( __( 'Expected an array describing the exporter at index %s.' ), $exporter_key ) ); } + if ( ! array_key_exists( 'exporter_friendly_name', $exporter ) ) { wp_send_json_error( /* translators: %s: Exporter array index. */ @@ -4610,6 +4819,7 @@ function wp_ajax_wp_privacy_export_personal_data() { sprintf( __( 'Exporter does not include a callback: %s.' ), esc_html( $exporter_friendly_name ) ) ); } + if ( ! is_callable( $exporter['callback'] ) ) { wp_send_json_error( /* translators: %s: Exporter friendly name. */ @@ -4630,18 +4840,21 @@ function wp_ajax_wp_privacy_export_personal_data() { sprintf( __( 'Expected response as an array from exporter: %s.' ), esc_html( $exporter_friendly_name ) ) ); } + if ( ! array_key_exists( 'data', $response ) ) { wp_send_json_error( /* translators: %s: Exporter friendly name. */ sprintf( __( 'Expected data in response array from exporter: %s.' ), esc_html( $exporter_friendly_name ) ) ); } + if ( ! is_array( $response['data'] ) ) { wp_send_json_error( /* translators: %s: Exporter friendly name. */ sprintf( __( 'Expected data array in response array from exporter: %s.' ), esc_html( $exporter_friendly_name ) ) ); } + if ( ! array_key_exists( 'done', $response ) ) { wp_send_json_error( /* translators: %s: Exporter friendly name. */ diff --git a/wp-admin/includes/image.php b/wp-admin/includes/image.php index 384fd8e9d0..1270a88c63 100644 --- a/wp-admin/includes/image.php +++ b/wp-admin/includes/image.php @@ -131,18 +131,29 @@ function wp_get_missing_image_subsizes( $attachment_id ) { * @since 5.3.0 * * @param int $attachment_id The image attachment post ID. - * @return array The updated image meta data array. + * @return array|WP_Error The updated image meta data array or WP_Error object + * if both the image meta and the attached file are missing. */ function wp_update_image_subsizes( $attachment_id ) { + $image_meta = wp_get_attachment_metadata( $attachment_id ); + $image_file = get_attached_file( $attachment_id ); + + if ( empty( $image_meta ) || ! is_array( $image_meta ) ) { + // Previously failed upload? + // If there is an uploaded file, make all sub-sizes and generate all of the attachment meta. + if ( ! empty( $image_file ) ) { + return wp_create_image_subsizes( $image_file, array(), $attachment_id ); + } else { + return new WP_Error( 'invalid_attachment', __( 'The attached file cannot be found.' ) ); + } + } + $missing_sizes = wp_get_missing_image_subsizes( $attachment_id ); - $image_meta = wp_get_attachment_metadata( $attachment_id ); if ( empty( $missing_sizes ) ) { return $image_meta; } - $image_file = get_attached_file( $attachment_id ); - // This also updates the image meta. return _wp_make_subsizes( $missing_sizes, $image_file, $image_meta, $attachment_id ); } diff --git a/wp-admin/includes/media.php b/wp-admin/includes/media.php index dcd3c42cad..956c31b25e 100644 --- a/wp-admin/includes/media.php +++ b/wp-admin/includes/media.php @@ -80,6 +80,7 @@ function the_media_upload_tabs() { if ( ! empty( $tabs ) ) { echo "\n"; } } @@ -265,10 +267,10 @@ function _cleanup_image_add_caption( $matches ) { */ function media_send_to_editor( $html ) { ?> - + ); * @return int|WP_Error ID of the attachment or a WP_Error object on failure. */ function media_handle_upload( $file_id, $post_id, $post_data = array(), $overrides = array( 'test_form' => false ) ) { - $time = current_time( 'mysql' ); $post = get_post( $post_id ); + if ( $post ) { // The post date doesn't usually matter for pages, so don't backdate this upload. if ( 'page' !== $post->post_type && substr( $post->post_date, 0, 4 ) > 0 ) { @@ -306,12 +308,13 @@ function media_handle_upload( $file_id, $post_id, $post_data = array(), $overrid $ext = pathinfo( $name, PATHINFO_EXTENSION ); $name = wp_basename( $name, ".$ext" ); - $url = $file['url']; - $type = $file['type']; - $file = $file['file']; - $title = sanitize_text_field( $name ); - $content = ''; - $excerpt = ''; + $url = $file['url']; + $type = $file['type']; + $file = $file['file']; + $title = sanitize_text_field( $name ); + $content = ''; + $excerpt = ''; + $image_ref = false; if ( preg_match( '#^audio#', $type ) ) { $meta = wp_read_audio_metadata( $file ); @@ -356,6 +359,7 @@ function media_handle_upload( $file_id, $post_id, $post_data = array(), $overrid if ( ! empty( $meta['track_number'] ) ) { $track_number = explode( '/', $meta['track_number'] ); + if ( isset( $track_number[1] ) ) { /* translators: Audio file track information. 1: Audio track number, 2: Total audio tracks. */ $content .= ' ' . sprintf( __( 'Track %1$s of %2$s.' ), number_format_i18n( $track_number[0] ), number_format_i18n( $track_number[1] ) ); @@ -372,7 +376,13 @@ function media_handle_upload( $file_id, $post_id, $post_data = array(), $overrid // Use image exif/iptc data for title and caption defaults if possible. } elseif ( 0 === strpos( $type, 'image/' ) ) { + // Image file reference passed by the uploader. + if ( ! empty( $_POST['_wp_temp_image_ref'] ) ) { + $image_ref = preg_replace( '/[^a-zA-Z0-9_]/', '', $_POST['_wp_temp_image_ref'] ); + } + $image_meta = wp_read_image_metadata( $file ); + if ( $image_meta ) { if ( trim( $image_meta['title'] ) && ! is_numeric( sanitize_title( $image_meta['title'] ) ) ) { $title = $image_meta['title']; @@ -401,13 +411,26 @@ function media_handle_upload( $file_id, $post_id, $post_data = array(), $overrid unset( $attachment['ID'] ); // Save the data - $id = wp_insert_attachment( $attachment, $file, $post_id, true ); - if ( ! is_wp_error( $id ) ) { - wp_update_attachment_metadata( $id, wp_generate_attachment_metadata( $id, $file ) ); + $attachment_id = wp_insert_attachment( $attachment, $file, $post_id, true ); + + if ( ! is_wp_error( $attachment_id ) ) { + // If an image, keep the upload reference until all image sub-sizes are created. + if ( $image_ref ) { + set_transient( '_wp_temp_image_ref:' . $image_ref, $attachment_id, HOUR_IN_SECONDS ); + } + + // The image sub-sizes are created during wp_generate_attachment_metadata(). + // This is generally slow and may cause timeouts or out of memory errors. + wp_update_attachment_metadata( $attachment_id, wp_generate_attachment_metadata( $attachment_id, $file ) ); + + // At this point the image is uploaded successfully even if there were specific errors or some sub-sizes were not created. + // The transient is not needed any more. + if ( $image_ref ) { + delete_transient( '_wp_temp_image_ref:' . $image_ref ); + } } - return $id; - + return $attachment_id; } /** @@ -426,6 +449,7 @@ function media_handle_sideload( $file_array, $post_id, $desc = null, $post_data $time = current_time( 'mysql' ); $post = get_post( $post_id ); + if ( $post ) { if ( substr( $post->post_date, 0, 4 ) > 0 ) { $time = $post->post_date; @@ -433,6 +457,7 @@ function media_handle_sideload( $file_array, $post_id, $desc = null, $post_data } $file = wp_handle_sideload( $file_array, $overrides, $time ); + if ( isset( $file['error'] ) ) { return new WP_Error( 'upload_error', $file['error'] ); } @@ -445,10 +470,12 @@ function media_handle_sideload( $file_array, $post_id, $desc = null, $post_data // Use image exif/iptc data for title and caption defaults if possible. $image_meta = wp_read_image_metadata( $file ); + if ( $image_meta ) { if ( trim( $image_meta['title'] ) && ! is_numeric( sanitize_title( $image_meta['title'] ) ) ) { $title = $image_meta['title']; } + if ( trim( $image_meta['caption'] ) ) { $content = $image_meta['caption']; } @@ -474,12 +501,13 @@ function media_handle_sideload( $file_array, $post_id, $desc = null, $post_data unset( $attachment['ID'] ); // Save the attachment metadata - $id = wp_insert_attachment( $attachment, $file, $post_id, true ); - if ( ! is_wp_error( $id ) ) { - wp_update_attachment_metadata( $id, wp_generate_attachment_metadata( $id, $file ) ); + $attachment_id = wp_insert_attachment( $attachment, $file, $post_id, true ); + + if ( ! is_wp_error( $attachment_id ) ) { + wp_update_attachment_metadata( $attachment_id, wp_generate_attachment_metadata( $attachment_id, $file ) ); } - return $id; + return $attachment_id; } /** @@ -495,22 +523,25 @@ function media_handle_sideload( $file_array, $post_id, $desc = null, $post_data function wp_iframe( $content_func ) { _wp_admin_html_begin(); ?> -<?php bloginfo( 'name' ); ?> › <?php _e( 'Uploads' ); ?> — <?php _e( 'WordPress' ); ?> + <?php bloginfo( 'name' ); ?> › <?php _e( 'Uploads' ); ?> — <?php _e( 'WordPress' ); ?> - + ; } $body_id_attr = ''; + if ( isset( $GLOBALS['body_id'] ) ) { $body_id_attr = ' id="' . $GLOBALS['body_id'] . '"'; } + ?> - - class="wp-core-ui no-js"> - + + class="wp-core-ui no-js"> + - - - + + + $post, - ) - ); + wp_enqueue_media( array( 'post' => $post ) ); $img = ' '; $id_attribute = $instance === 1 ? ' id="insert-media-button"' : ''; + printf( '', $id_attribute, esc_attr( $editor_id ), $img . __( 'Add Media' ) ); + /** * Filters the legacy (pre-3.5.0) media buttons. * @@ -709,12 +743,15 @@ function media_upload_form_handler() { if ( isset( $attachment['post_content'] ) ) { $post['post_content'] = $attachment['post_content']; } + if ( isset( $attachment['post_title'] ) ) { $post['post_title'] = $attachment['post_title']; } + if ( isset( $attachment['post_excerpt'] ) ) { $post['post_excerpt'] = $attachment['post_excerpt']; } + if ( isset( $attachment['menu_order'] ) ) { $post['menu_order'] = $attachment['menu_order']; } @@ -739,6 +776,7 @@ function media_upload_form_handler() { if ( isset( $attachment['image_alt'] ) ) { $image_alt = wp_unslash( $attachment['image_alt'] ); + if ( $image_alt != get_post_meta( $attachment_id, '_wp_attachment_image_alt', true ) ) { $image_alt = wp_strip_all_tags( $image_alt, true ); @@ -771,18 +809,21 @@ function media_upload_form_handler() { win.tb_remove(); $html"; } @@ -798,6 +839,7 @@ function media_upload_form_handler() { * @param array $attachment Array of attachment metadata. */ $html = apply_filters( 'media_send_to_editor', $html, $send_id, $attachment ); + return media_send_to_editor( $html ); } @@ -820,6 +862,7 @@ function wp_media_upload_handler() { // Upload File button was clicked $id = media_handle_upload( 'async-upload', $_REQUEST['post_id'] ); unset( $_FILES ); + if ( is_wp_error( $id ) ) { $errors['upload_error'] = $id; $id = false; @@ -828,6 +871,7 @@ function wp_media_upload_handler() { if ( ! empty( $_POST['insertonlybutton'] ) ) { $src = $_POST['src']; + if ( ! empty( $src ) && ! strpos( $src, '://' ) ) { $src = "http://$src"; } @@ -844,6 +888,7 @@ function wp_media_upload_handler() { $type = 'file'; $ext = preg_replace( '/^.+?\.([^.]+)$/', '$1', $src ); + if ( $ext ) { $ext_type = wp_ext2type( $ext ); if ( 'audio' == $ext_type || 'video' == $ext_type ) { @@ -867,10 +912,12 @@ function wp_media_upload_handler() { } else { $align = ''; $alt = esc_attr( wp_unslash( $_POST['alt'] ) ); + if ( isset( $_POST['align'] ) ) { $align = esc_attr( wp_unslash( $_POST['align'] ) ); $class = " class='align$align'"; } + if ( ! empty( $src ) ) { $html = "$alt"; } @@ -895,6 +942,7 @@ function wp_media_upload_handler() { if ( isset( $_POST['save'] ) ) { $errors['upload_notice'] = __( 'Saved.' ); wp_enqueue_script( 'admin-gallery' ); + return wp_iframe( 'media_upload_gallery_form', $errors ); } elseif ( ! empty( $_POST ) ) { @@ -903,6 +951,7 @@ function wp_media_upload_handler() { if ( is_string( $return ) ) { return $return; } + if ( is_array( $return ) ) { $errors = $return; } @@ -910,9 +959,11 @@ function wp_media_upload_handler() { if ( isset( $_GET['tab'] ) && $_GET['tab'] == 'type_url' ) { $type = 'image'; + if ( isset( $_GET['type'] ) && in_array( $_GET['type'], array( 'video', 'audio', 'file' ) ) ) { $type = $_GET['type']; } + return wp_iframe( 'media_upload_type_url_form', $type, $errors, $id ); } @@ -937,6 +988,7 @@ function media_sideload_image( $file, $post_id, $desc = null, $return = 'html' ) // Set variables for storage, fix file filename for query strings. preg_match( '/[^\?]+\.(jpe?g|jpe|gif|png)\b/i', $file, $matches ); + if ( ! $matches ) { return new WP_Error( 'image_sideload_failed', __( 'Invalid image URL' ) ); } @@ -975,6 +1027,7 @@ function media_sideload_image( $file, $post_id, $desc = null, $return = 'html' ) $alt = isset( $desc ) ? esc_attr( $desc ) : ''; $html = "$alt"; + return $html; } else { return new WP_Error( 'image_sideload_failed' ); @@ -997,6 +1050,7 @@ function media_upload_gallery() { if ( is_string( $return ) ) { return $return; } + if ( is_array( $return ) ) { $errors = $return; } @@ -1015,6 +1069,7 @@ function media_upload_gallery() { */ function media_upload_library() { $errors = array(); + if ( ! empty( $_POST ) ) { $return = media_upload_form_handler(); @@ -1050,17 +1105,20 @@ function image_align_input_fields( $post, $checked = '' ) { 'center' => __( 'Center' ), 'right' => __( 'Right' ), ); + if ( ! array_key_exists( (string) $checked, $alignments ) ) { $checked = 'none'; } $out = array(); + foreach ( $alignments as $name => $label ) { $name = esc_attr( $name ); $out[] = ""; } + return join( "\n", $out ); } @@ -1095,6 +1153,7 @@ function image_size_input_fields( $post, $check = '' ) { if ( empty( $check ) ) { $check = get_user_setting( 'imgsize', 'medium' ); } + $out = array(); foreach ( $size_names as $size => $label ) { @@ -1160,6 +1219,7 @@ function image_link_input_fields( $post, $url_type = '' ) { } $url = ''; + if ( $url_type == 'file' ) { $url = $file; } elseif ( $url_type == 'post' ) { @@ -1267,6 +1327,7 @@ function image_attachment_fields_to_save( $post, $attachment ) { */ function image_media_send_to_editor( $html, $attachment_id, $attachment ) { $post = get_post( $attachment_id ); + if ( substr( $post->post_mime_type, 0, 5 ) == 'image' ) { $url = $attachment['url']; $align = ! empty( $attachment['align'] ) ? $attachment['align'] : 'none'; @@ -1293,6 +1354,7 @@ function get_attachment_fields_to_edit( $post, $errors = null ) { if ( is_int( $post ) ) { $post = get_post( $post ); } + if ( is_array( $post ) ) { $post = new WP_Post( (object) $post ); } @@ -1338,17 +1400,21 @@ function get_attachment_fields_to_edit( $post, $errors = null ) { foreach ( get_attachment_taxonomies( $post ) as $taxonomy ) { $t = (array) get_taxonomy( $taxonomy ); + if ( ! $t['public'] || ! $t['show_ui'] ) { continue; } + if ( empty( $t['label'] ) ) { $t['label'] = $taxonomy; } + if ( empty( $t['args'] ) ) { $t['args'] = array(); } $terms = get_object_term_cache( $post->ID, $taxonomy ); + if ( false === $terms ) { $terms = wp_get_object_terms( $post->ID, $taxonomy, $t['args'] ); } @@ -1358,6 +1424,7 @@ function get_attachment_fields_to_edit( $post, $errors = null ) { foreach ( $terms as $term ) { $values[] = $term->slug; } + $t['value'] = join( ', ', $values ); $form_fields[ $taxonomy ] = $t; @@ -1370,6 +1437,7 @@ function get_attachment_fields_to_edit( $post, $errors = null ) { // This was formerly in image_attachment_fields_to_edit(). if ( substr( $post->post_mime_type, 0, 5 ) == 'image' ) { $alt = get_post_meta( $post->ID, '_wp_attachment_image_alt', true ); + if ( empty( $alt ) ) { $alt = ''; } @@ -1424,8 +1492,10 @@ function get_attachment_fields_to_edit( $post, $errors = null ) { */ function get_media_items( $post_id, $errors ) { $attachments = array(); + if ( $post_id ) { $post = get_post( $post_id ); + if ( $post && $post->post_type == 'attachment' ) { $attachments = array( $post->ID => $post ); } else { @@ -1451,7 +1521,9 @@ function get_media_items( $post_id, $errors ) { if ( $attachment->post_status == 'trash' ) { continue; } + $item = get_media_item( $id, array( 'errors' => isset( $errors[ $id ] ) ? $errors[ $id ] : null ) ); + if ( $item ) { $output .= "\n
$item\n
"; } @@ -1479,6 +1551,7 @@ function get_media_item( $attachment_id, $args = null ) { if ( $attachment_id ) { $thumb_url = wp_get_attachment_image_src( $attachment_id, 'thumbnail', true ); + if ( $thumb_url ) { $thumb_url = $thumb_url[0]; } @@ -1525,8 +1598,8 @@ function get_media_item( $attachment_id, $args = null ) { if ( $parsed_args['toggle'] ) { $class = empty( $parsed_args['errors'] ) ? 'startclosed' : 'startopen'; $toggle_links = " - $toggle_on - $toggle_off"; + $toggle_on + $toggle_off"; } else { $class = ''; $toggle_links = ''; @@ -1553,6 +1626,7 @@ function get_media_item( $attachment_id, $args = null ) { $media_dims = ''; $meta = wp_get_attachment_metadata( $post->ID ); + if ( isset( $meta['width'], $meta['height'] ) ) { $media_dims .= "{$meta['width']} × {$meta['height']} "; } @@ -1568,6 +1642,7 @@ function get_media_item( $attachment_id, $args = null ) { $media_dims = apply_filters( 'media_meta', $media_dims, $post ); $image_edit_button = ''; + if ( wp_attachment_is_image( $post->ID ) && wp_image_editor_supports( array( 'mime_type' => $post->post_mime_type ) ) ) { $nonce = wp_create_nonce( "image_editor-$post->ID" ); $image_edit_button = " "; @@ -1576,13 +1651,13 @@ function get_media_item( $attachment_id, $args = null ) { $attachment_url = get_permalink( $attachment_id ); $item = " - $type_html - $toggle_links - $order - $display_title - - - + $type_html + $toggle_links + $order + $display_title +
+ + \n"; + $item .= "\n"; $item .= " @@ -1640,11 +1716,13 @@ function get_media_item( $attachment_id, $args = null ) { $thumbnail = ''; $calling_post_id = 0; + 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 $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 ) { @@ -1658,6 +1736,7 @@ function get_media_item( $attachment_id, $args = null ) { if ( ( $parsed_args['send'] || $thumbnail || $delete ) && ! isset( $form_fields['buttons'] ) ) { $form_fields['buttons'] = array( 'tr' => "\t\t\n" ); } + $hidden_fields = array(); foreach ( $form_fields as $id => $field ) { @@ -1684,6 +1763,7 @@ function get_media_item( $attachment_id, $args = null ) { $class .= $field['required'] ? ' form-required' : ''; $item .= "\t\t\n\t\t\t\n\t\t\t\n"; } + $item .= "\t\n"; $item .= "\t

$image_edit_button

@@ -1591,11 +1666,12 @@ function get_media_item( $attachment_id, $args = null ) {

" . __( 'File name:' ) . " $filename

" . __( 'File type:' ) . " $post->post_mime_type

" . __( 'Upload date:' ) . ' ' . mysql2date( __( 'F j, Y' ), $post->post_date ) . '

'; + if ( ! empty( $media_dims ) ) { $item .= '

' . __( 'Dimensions:' ) . " $media_dims

\n"; } - $item .= "
" . $parsed_args['send'] . " $thumbnail $delete
"; + if ( ! empty( $field[ $field['input'] ] ) ) { $item .= $field[ $field['input'] ]; } elseif ( $field['input'] == 'textarea' ) { @@ -1696,6 +1776,7 @@ function get_media_item( $attachment_id, $args = null ) { } else { $item .= ""; } + if ( ! empty( $field['helps'] ) ) { $item .= "

" . join( "

\n

", array_unique( (array) $field['helps'] ) ) . '

'; } @@ -1727,6 +1808,7 @@ function get_media_item( $attachment_id, $args = null ) { if ( ! empty( $form_fields['_final'] ) ) { $item .= "\t\t
{$form_fields['_final']}
\n"; @@ -1770,17 +1852,21 @@ function get_compat_media_markup( $attachment_id, $args = null ) { if ( $args['in_modal'] ) { foreach ( get_attachment_taxonomies( $post ) as $taxonomy ) { $t = (array) get_taxonomy( $taxonomy ); + if ( ! $t['public'] || ! $t['show_ui'] ) { continue; } + if ( empty( $t['label'] ) ) { $t['label'] = $taxonomy; } + if ( empty( $t['args'] ) ) { $t['args'] = array(); } $terms = get_object_term_cache( $post->ID, $taxonomy ); + if ( false === $terms ) { $terms = wp_get_object_terms( $post->ID, $taxonomy, $t['args'] ); } @@ -1790,6 +1876,7 @@ function get_compat_media_markup( $attachment_id, $args = null ) { foreach ( $terms as $term ) { $values[] = $term->slug; } + $t['value'] = join( ', ', $values ); $t['taxonomy'] = true; @@ -1831,6 +1918,7 @@ function get_compat_media_markup( $attachment_id, $args = null ) { $hidden_fields = array(); $item = ''; + foreach ( $form_fields as $id => $field ) { if ( $id[0] == '_' ) { continue; @@ -1876,9 +1964,11 @@ function get_compat_media_markup( $attachment_id, $args = null ) { } else { $item .= ""; } + if ( ! empty( $field['helps'] ) ) { $item .= "

" . join( "

\n

", array_unique( (array) $field['helps'] ) ) . '

'; } + $item .= "\n\t\t\n"; $extra_rows = array(); @@ -1939,6 +2029,7 @@ function media_upload_header() { $post_id = isset( $_REQUEST['post_id'] ) ? intval( $_REQUEST['post_id'] ) : 0; echo ''; + if ( empty( $_GET['chromeless'] ) ) { echo '
'; the_media_upload_tabs(); @@ -1979,9 +2070,9 @@ function media_upload_form( $errors = null ) { if ( ! $max_upload_size ) { $max_upload_size = 0; } - ?> -
+ ?> +
-
-
+
+
-
+
'drag-drop-area', 'file_data_name' => 'async-upload', 'url' => $upload_action_url, - 'filters' => array( - 'max_file_size' => $max_upload_size . 'b', - ), + 'filters' => array( 'max_file_size' => $max_upload_size . 'b' ), 'multipart_params' => $post_params, ); // Currently only iOS Safari supports multiple files uploading but iOS 7.x has a bug that prevents uploading of videos // when enabled. See #29602. - if ( wp_is_mobile() && strpos( $_SERVER['HTTP_USER_AGENT'], 'OS 7_' ) !== false && - strpos( $_SERVER['HTTP_USER_AGENT'], 'like Mac OS X' ) !== false ) { - + if ( + wp_is_mobile() && + strpos( $_SERVER['HTTP_USER_AGENT'], 'OS 7_' ) !== false && + strpos( $_SERVER['HTTP_USER_AGENT'], 'like Mac OS X' ) !== false + ) { $plupload_init['multi_selection'] = false; } @@ -2069,24 +2161,27 @@ function media_upload_form( $errors = null ) { $plupload_init = apply_filters( 'plupload_init', $plupload_init ); ?> - - -
+ ?> + var resize_height = , resize_width = , + wpUploaderInit = ; + + +
; * @since 3.3.0 */ do_action( 'pre-plupload-upload-ui' ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores + ?> -
-
-

-

-

+
+
+

+

+

+
-
; */ do_action( 'post-plupload-upload-ui' ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores ?> -
+
-
+
; * @since 2.6.0 */ do_action( 'pre-html-upload-ui' ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores + ?>

@@ -2137,8 +2234,9 @@ wpUploaderInit = ; * @since 2.6.0 */ do_action( 'post-html-upload-ui' ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores + ?> -

+

+

+ + + - - - - - -

+

- -
+ +
-
-

- -

- + ?> +
+ +

+ +

+ +
+ + - - - +

-

- - + -
-
+
+
-
-
- +
+
+ + +
+ + + + + + + | + | + +
+ +

+ + +

+
+ +
+ + + + + - - - - - - + - - -
    - $reals ) { - foreach ( $reals as $real ) { - if ( isset( $num_posts[ $_type ] ) ) { - $num_posts[ $_type ] += $_num_posts[ $real ]; - } else { - $num_posts[ $_type ] = $_num_posts[ $real ]; +
      + $reals ) { + foreach ( $reals as $real ) { + if ( isset( $num_posts[ $_type ] ) ) { + $num_posts[ $_type ] += $_num_posts[ $real ]; + } else { + $num_posts[ $_type ] = $_num_posts[ $real ]; + } } } - } - // If available type specified by media button clicked, filter by that type - if ( empty( $_GET['post_mime_type'] ) && ! empty( $num_posts[ $type ] ) ) { - $_GET['post_mime_type'] = $type; - list($post_mime_types, $avail_post_mime_types) = wp_edit_attachments_query(); - } - if ( empty( $_GET['post_mime_type'] ) || $_GET['post_mime_type'] == 'all' ) { - $class = ' class="current"'; - } else { - $class = ''; - } - $type_links[] = '
    • ' . __( 'All Types' ) . ''; - foreach ( $post_mime_types as $mime_type => $label ) { - $class = ''; - - if ( ! wp_match_mime_types( $mime_type, $avail_post_mime_types ) ) { - continue; + // If available type specified by media button clicked, filter by that type + if ( empty( $_GET['post_mime_type'] ) && ! empty( $num_posts[ $type ] ) ) { + $_GET['post_mime_type'] = $type; + list($post_mime_types, $avail_post_mime_types) = wp_edit_attachments_query(); } - - if ( isset( $_GET['post_mime_type'] ) && wp_match_mime_types( $mime_type, $_GET['post_mime_type'] ) ) { + if ( empty( $_GET['post_mime_type'] ) || $_GET['post_mime_type'] == 'all' ) { $class = ' class="current"'; + } else { + $class = ''; } - $type_links[] = '
    • ' . sprintf( translate_nooped_plural( $label[2], $num_posts[ $mime_type ] ), '' . number_format_i18n( $num_posts[ $mime_type ] ) . '' ) . ''; - } - /** - * Filters the media upload mime type list items. - * - * Returned values should begin with an `
    • ` tag. - * - * @since 3.1.0 - * - * @param string[] $type_links An array of list items containing mime type link HTML. - */ - echo implode( ' |
    • ', apply_filters( 'media_upload_mime_type_links', $type_links ) ) . ''; - unset( $type_links ); - ?> -
    + ) . '"' . $class . '>' . __( 'All Types' ) . ''; + foreach ( $post_mime_types as $mime_type => $label ) { + $class = ''; -
    - - add_query_arg( 'paged', '%#%' ), - 'format' => '', - 'prev_text' => __( '«' ), - 'next_text' => __( '»' ), - 'total' => ceil( $wp_query->found_posts / 10 ), - 'current' => $q['paged'], - ) - ); - - if ( $page_links ) { - echo "
    $page_links
    "; - } - ?> - -
    - posts WHERE post_type = 'attachment' ORDER BY post_date DESC"; - - $arc_result = $wpdb->get_results( $arc_query ); - - $month_count = count( $arc_result ); - $selected_month = isset( $_GET['m'] ) ? $_GET['m'] : 0; - - if ( $month_count && ! ( 1 == $month_count && 0 == $arc_result[0]->mmonth ) ) { - ?> - - - +
    + + $arc_query = "SELECT DISTINCT YEAR(post_date) AS yyear, MONTH(post_date) AS mmonth FROM $wpdb->posts WHERE post_type = 'attachment' ORDER BY post_date DESC"; -
    -
    - + $arc_result = $wpdb->get_results( $arc_query ); -
    + $month_count = count( $arc_result ); + $selected_month = isset( $_GET['m'] ) ? $_GET['m'] : 0; + if ( $month_count && ! ( 1 == $month_count && 0 == $arc_result[0]->mmonth ) ) { + ?> + + + + + +
    + +
    +
    + + +
    - + -
    - - -
    -

    - - -

    -
    +
    + + +
    +

    + + +

    + ' . __( 'Image Caption' ) . ' - -'; + '; } else { $caption = ''; } $default_align = get_option( 'image_default_align' ); + if ( empty( $default_align ) ) { $default_align = 'none'; } @@ -2856,9 +2957,7 @@ function wp_media_insert_url_form( $default_view = 'image' ) { ' . get_submit_button( __( 'Insert into Post' ), '', 'insertonlybutton', false ) . ' - -'; - + '; } /** @@ -2926,14 +3025,16 @@ function media_upload_max_image_resize() { $a = ''; $end = ''; } + ?> -

    +

    ID ); + if ( $attachment_id ) { $thumb_url = wp_get_attachment_image_src( $attachment_id, array( 900, 450 ), true ); } @@ -2975,6 +3078,7 @@ function edit_form_image_editor( $post ) { ?>
    ID ) ) : $image_edit_button = ''; if ( wp_image_editor_supports( array( 'mime_type' => $post->post_mime_type ) ) ) { @@ -2984,13 +3088,14 @@ function edit_form_image_editor( $post ) { $open_style = ''; $not_open_style = ''; + if ( $open ) { $open_style = ' style="display:none"'; } else { $not_open_style = ' style="display:none"'; } - ?> + ?>
    class="wp_attachment_image wp-clearfix" id="media-head-"> @@ -2998,10 +3103,13 @@ function edit_form_image_editor( $post ) {

    class="image-editor" id="image-editor-"> - +
$att_url ); + if ( ! empty( $w ) && ! empty( $h ) ) { $attr['width'] = $w; $attr['height'] = $h; } $thumb_id = get_post_thumbnail_id( $attachment_id ); + if ( ! empty( $thumb_id ) ) { $attr['poster'] = wp_get_attachment_url( $thumb_id ); } @@ -3035,7 +3146,6 @@ function edit_form_image_editor( $post ) { echo wp_video_shortcode( $attr ); elseif ( isset( $thumb_url[0] ) ) : - ?>

@@ -3056,6 +3166,7 @@ function edit_form_image_editor( $post ) { do_action( 'wp_edit_form_attachment_display', $post ); endif; + ?>

@@ -3065,19 +3176,21 @@ function edit_form_image_editor( $post ) {

- Describe the purpose of the image%3$s. Leave empty if the image is purely decorative.' ), - esc_url( 'https://www.w3.org/WAI/tutorials/images/decision-tree' ), - 'target="_blank" rel="noopener noreferrer"', - sprintf( - ' %s', - /* translators: Accessibility text. */ - __( '(opens in a new tab)' ) - ) - ); - ?> + Describe the purpose of the image%3$s. Leave empty if the image is purely decorative.' ), + esc_url( 'https://www.w3.org/WAI/tutorials/images/decision-tree' ), + 'target="_blank" rel="noopener noreferrer"', + sprintf( + ' %s', + /* translators: Accessibility text. */ + __( '(opens in a new tab)' ) + ) + ); + + ?>

@@ -3087,27 +3200,32 @@ function edit_form_image_editor( $post ) {

'strong,em,link,block,del,ins,img,ul,ol,li,code,close' ); - $editor_args = array( - 'textarea_name' => 'content', - 'textarea_rows' => 5, - 'media_buttons' => false, - 'tinymce' => false, - 'quicktags' => $quicktags_settings, - ); + + $quicktags_settings = array( 'buttons' => 'strong,em,link,block,del,ins,img,ul,ol,li,code,close' ); + $editor_args = array( + 'textarea_name' => 'content', + 'textarea_rows' => 5, + 'media_buttons' => false, + 'tinymce' => false, + 'quicktags' => $quicktags_settings, + ); + ?> post_content, 'attachment_content', $editor_args ); ?>
ID ); echo $extras['item']; echo '' . "\n"; @@ -3119,20 +3237,23 @@ function edit_form_image_editor( $post ) { * @since 3.5.0 */ function attachment_submitbox_metadata() { - $post = get_post(); + $post = get_post(); + $attachment_id = $post->ID; - $file = get_attached_file( $post->ID ); + $file = get_attached_file( $attachment_id ); $filename = esc_html( wp_basename( $file ) ); $media_dims = ''; - $meta = wp_get_attachment_metadata( $post->ID ); + $meta = wp_get_attachment_metadata( $attachment_id ); + if ( isset( $meta['width'], $meta['height'] ) ) { - $media_dims .= "{$meta['width']} × {$meta['height']} "; + $media_dims .= "{$meta['width']} × {$meta['height']} "; } /** This filter is documented in wp-admin/includes/media.php */ $media_dims = apply_filters( 'media_meta', $media_dims, $post ); - $att_url = wp_get_attachment_url( $post->ID ); + $att_url = wp_get_attachment_url( $attachment_id ); + ?>
@@ -3142,25 +3263,29 @@ function attachment_submitbox_metadata() {
- - ID ), $matches ) ) { - echo esc_html( strtoupper( $matches[1] ) ); - list( $mime_type ) = explode( '/', $post->post_mime_type ); - if ( $mime_type !== 'image' && ! empty( $meta['mime_type'] ) ) { - if ( $meta['mime_type'] !== "$mime_type/" . strtolower( $matches[1] ) ) { - echo ' (' . $meta['mime_type'] . ')'; - } - } - } else { - echo strtoupper( str_replace( 'image/', '', $post->post_mime_type ) ); - } - ?> + + + ID ), $matches ) ) { + echo esc_html( strtoupper( $matches[1] ) ); + list( $mime_type ) = explode( '/', $post->post_mime_type ); + if ( $mime_type !== 'image' && ! empty( $meta['mime_type'] ) ) { + if ( $meta['mime_type'] !== "$mime_type/" . strtolower( $matches[1] ) ) { + echo ' (' . $meta['mime_type'] . ')'; + } + } + } else { + echo strtoupper( str_replace( 'image/', '', $post->post_mime_type ) ); + } + + ?>
-
- -
- + + + post_mime_type ) ) { $fields = array( @@ -3200,24 +3325,28 @@ function attachment_submitbox_metadata() { if ( empty( $meta[ $key ] ) ) { continue; } + ?> -
- - "> + + + - -
+ break; + default: + echo esc_html( $meta[ $key ] ); + break; + } + + ?> + + -
- -
+
+ +
-
- -
+
+ +
analyze( $file ); if ( isset( $data['video']['lossless'] ) ) { $metadata['lossless'] = $data['video']['lossless']; } + if ( ! empty( $data['video']['bitrate'] ) ) { $metadata['bitrate'] = (int) $data['video']['bitrate']; } + if ( ! empty( $data['video']['bitrate_mode'] ) ) { $metadata['bitrate_mode'] = $data['video']['bitrate_mode']; } + if ( ! empty( $data['filesize'] ) ) { $metadata['filesize'] = (int) $data['filesize']; } + if ( ! empty( $data['mime_type'] ) ) { $metadata['mime_type'] = $data['mime_type']; } + if ( ! empty( $data['playtime_seconds'] ) ) { $metadata['length'] = (int) round( $data['playtime_seconds'] ); } + if ( ! empty( $data['playtime_string'] ) ) { $metadata['length_formatted'] = $data['playtime_string']; } + if ( ! empty( $data['video']['resolution_x'] ) ) { $metadata['width'] = (int) $data['video']['resolution_x']; } + if ( ! empty( $data['video']['resolution_y'] ) ) { $metadata['height'] = (int) $data['video']['resolution_y']; } + if ( ! empty( $data['fileformat'] ) ) { $metadata['fileformat'] = $data['fileformat']; } + if ( ! empty( $data['video']['dataformat'] ) ) { $metadata['dataformat'] = $data['video']['dataformat']; } + if ( ! empty( $data['video']['encoder'] ) ) { $metadata['encoder'] = $data['video']['encoder']; } + if ( ! empty( $data['video']['codec'] ) ) { $metadata['codec'] = $data['video']['codec']; } @@ -3416,6 +3559,7 @@ function wp_read_audio_metadata( $file ) { if ( ! file_exists( $file ) ) { return false; } + $metadata = array(); if ( ! defined( 'GETID3_TEMP_DIR' ) ) { @@ -3425,6 +3569,7 @@ function wp_read_audio_metadata( $file ) { if ( ! class_exists( 'getID3', false ) ) { require( ABSPATH . WPINC . '/ID3/getid3.php' ); } + $id3 = new getID3(); $data = $id3->analyze( $file ); @@ -3436,15 +3581,19 @@ function wp_read_audio_metadata( $file ) { if ( ! empty( $data['fileformat'] ) ) { $metadata['fileformat'] = $data['fileformat']; } + if ( ! empty( $data['filesize'] ) ) { $metadata['filesize'] = (int) $data['filesize']; } + if ( ! empty( $data['mime_type'] ) ) { $metadata['mime_type'] = $data['mime_type']; } + if ( ! empty( $data['playtime_seconds'] ) ) { $metadata['length'] = (int) round( $data['playtime_seconds'] ); } + if ( ! empty( $data['playtime_string'] ) ) { $metadata['length_formatted'] = $data['playtime_string']; } @@ -3531,7 +3680,9 @@ function wp_media_attach_action( $parent_id, $action = 'attach' ) { if ( ! current_user_can( 'edit_post', $parent_id ) ) { wp_die( __( 'Sorry, you are not allowed to edit this post.' ) ); } + $ids = array(); + foreach ( (array) $_REQUEST['media'] as $att_id ) { $att_id = (int) $att_id; @@ -3544,6 +3695,7 @@ function wp_media_attach_action( $parent_id, $action = 'attach' ) { if ( ! empty( $ids ) ) { $ids_string = implode( ',', $ids ); + if ( 'attach' === $action ) { $result = $wpdb->query( $wpdb->prepare( "UPDATE $wpdb->posts SET post_parent = %d WHERE post_type = 'attachment' AND ID IN ( $ids_string )", $parent_id ) ); } else { @@ -3558,6 +3710,7 @@ function wp_media_attach_action( $parent_id, $action = 'attach' ) { if ( isset( $result ) ) { $location = 'upload.php'; $referer = wp_get_referer(); + if ( $referer ) { if ( false !== strpos( $referer, 'upload.php' ) ) { $location = remove_query_arg( array( 'attached', 'detach' ), $referer ); @@ -3566,6 +3719,7 @@ function wp_media_attach_action( $parent_id, $action = 'attach' ) { $key = 'attach' === $action ? 'attached' : 'detach'; $location = add_query_arg( array( $key => $result ), $location ); + wp_redirect( $location ); exit; } diff --git a/wp-includes/js/media-views.js b/wp-includes/js/media-views.js index 543412f099..45447a8410 100644 --- a/wp-includes/js/media-views.js +++ b/wp-includes/js/media-views.js @@ -5306,10 +5306,13 @@ UploaderStatus = View.extend(/** @lends wp.media.view.UploaderStatus.prototype * * @param {Backbone.Model} error */ error: function( error ) { - this.views.add( '.upload-errors', new wp.media.view.UploaderStatusError({ - filename: this.filename( error.get('file').name ), - message: error.get('message') - }), { at: 0 }); + var statusError = new wp.media.view.UploaderStatusError( { + filename: this.filename( error.get( 'file' ).name ), + message: error.get( 'message' ) + } ); + + // Can show additional info here while retrying to create image sub-sizes. + this.views.add( '.upload-errors', statusError, { at: 0 } ); }, dismiss: function() { diff --git a/wp-includes/js/media-views.min.js b/wp-includes/js/media-views.min.js index 9e2936952d..576f1135ad 100644 --- a/wp-includes/js/media-views.min.js +++ b/wp-includes/js/media-views.min.js @@ -1,4 +1,4 @@ !function(a){function b(d){if(c[d])return c[d].exports;var e=c[d]={i:d,l:!1,exports:{}};return a[d].call(e.exports,e,e.exports,b),e.l=!0,e.exports}var c={};return b.m=a,b.c=c,b.d=function(a,c,d){b.o(a,c)||Object.defineProperty(a,c,{enumerable:!0,get:d})},b.r=function(a){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(a,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(a,"__esModule",{value:!0})},b.t=function(a,c){if(1&c&&(a=b(a)),8&c)return a;if(4&c&&"object"==typeof a&&a&&a.__esModule)return a;var d=Object.create(null);if(b.r(d),Object.defineProperty(d,"default",{enumerable:!0,value:a}),2&c&&"string"!=typeof a)for(var e in a)b.d(d,e,function(b){return a[b]}.bind(null,e));return d},b.n=function(a){var c=a&&a.__esModule?function(){return a["default"]}:function(){return a};return b.d(c,"a",c),c},b.o=function(a,b){return Object.prototype.hasOwnProperty.call(a,b)},b.p="",b(b.s=29)}(Array(29).concat([function(a,b,c){a.exports=c(30)},function(a,b,c){var d,e=wp.media,f=jQuery;e.isTouchDevice="ontouchend"in document,d=e.view.l10n=window._wpMediaViewsL10n||{},e.view.settings=d.settings||{},delete d.settings,e.model.settings.post=e.view.settings.post,f.support.transition=function(){var a,b=document.documentElement.style,c={WebkitTransition:"webkitTransitionEnd",MozTransition:"transitionend",OTransition:"oTransitionEnd otransitionend",transition:"transitionend"};return a=_.find(_.keys(c),function(a){return!_.isUndefined(b[a])}),a&&{end:c[a]}}(),e.events=_.extend({},Backbone.Events),e.transition=function(a,b){var c=f.Deferred();return b=b||2e3,f.support.transition?(a instanceof f||(a=f(a)),a.first().one(f.support.transition.end,c.resolve),_.delay(c.resolve,b)):c.resolve(),c.promise()},e.controller.Region=c(31),e.controller.StateMachine=c(32),e.controller.State=c(33),e.selectionSync=c(34),e.controller.Library=c(35),e.controller.ImageDetails=c(36),e.controller.GalleryEdit=c(37),e.controller.GalleryAdd=c(38),e.controller.CollectionEdit=c(39),e.controller.CollectionAdd=c(40),e.controller.FeaturedImage=c(41),e.controller.ReplaceImage=c(42),e.controller.EditImage=c(43),e.controller.MediaLibrary=c(44),e.controller.Embed=c(45),e.controller.Cropper=c(46),e.controller.CustomizeImageCropper=c(47),e.controller.SiteIconCropper=c(48),e.View=c(49),e.view.Frame=c(50),e.view.MediaFrame=c(51),e.view.MediaFrame.Select=c(52),e.view.MediaFrame.Post=c(53),e.view.MediaFrame.ImageDetails=c(54),e.view.Modal=c(55),e.view.FocusManager=c(56),e.view.UploaderWindow=c(57),e.view.EditorUploader=c(58),e.view.UploaderInline=c(59),e.view.UploaderStatus=c(60),e.view.UploaderStatusError=c(61),e.view.Toolbar=c(62),e.view.Toolbar.Select=c(63),e.view.Toolbar.Embed=c(64),e.view.Button=c(65),e.view.ButtonGroup=c(66),e.view.PriorityList=c(67),e.view.MenuItem=c(68),e.view.Menu=c(69),e.view.RouterItem=c(70),e.view.Router=c(71),e.view.Sidebar=c(72),e.view.Attachment=c(73),e.view.Attachment.Library=c(74),e.view.Attachment.EditLibrary=c(75),e.view.Attachments=c(76),e.view.Search=c(77),e.view.AttachmentFilters=c(78),e.view.DateFilter=c(79),e.view.AttachmentFilters.Uploaded=c(80),e.view.AttachmentFilters.All=c(81),e.view.AttachmentsBrowser=c(82),e.view.Selection=c(83),e.view.Attachment.Selection=c(84),e.view.Attachments.Selection=c(85),e.view.Attachment.EditSelection=c(86),e.view.Settings=c(87),e.view.Settings.AttachmentDisplay=c(88),e.view.Settings.Gallery=c(89),e.view.Settings.Playlist=c(90),e.view.Attachment.Details=c(91),e.view.AttachmentCompat=c(92),e.view.Iframe=c(93),e.view.Embed=c(94),e.view.Label=c(95),e.view.EmbedUrl=c(96),e.view.EmbedLink=c(97),e.view.EmbedImage=c(98),e.view.ImageDetails=c(99),e.view.Cropper=c(100),e.view.SiteIconCropper=c(101),e.view.SiteIconPreview=c(102),e.view.EditImage=c(103),e.view.Spinner=c(104),e.view.Heading=c(105)},function(a,b){var c=function(a){_.extend(this,_.pick(a||{},"id","view","selector"))};c.extend=Backbone.Model.extend,_.extend(c.prototype,{mode:function(a){return a?a===this._mode?this:(this.trigger("deactivate"),this._mode=a,this.render(a),this.trigger("activate"),this):this._mode},render:function(a){if(a&&a!==this._mode)return this.mode(a);var b,c={view:null};return this.trigger("create",c),b=c.view,this.trigger("render",b),b&&this.set(b),this},get:function(){return this.view.views.first(this.selector)},set:function(a,b){return b&&(b.add=!1),this.view.views.set(this.selector,a,b)},trigger:function(a){var b,c;if(this._mode)return c=_.toArray(arguments),b=this.id+":"+a,c[0]=b+":"+this._mode,this.view.trigger.apply(this.view,c),c[0]=b,this.view.trigger.apply(this.view,c),this}}),a.exports=c},function(a,b){var c=function(a){this.states=new Backbone.Collection(a)};c.extend=Backbone.Model.extend,_.extend(c.prototype,Backbone.Events,{state:function(a){return this.states=this.states||new Backbone.Collection,a=a||this._state,a&&!this.states.get(a)&&this.states.add({id:a}),this.states.get(a)},setState:function(a){var b=this.state();return b&&a===b.id||!this.states||!this.states.get(a)?this:(b&&(b.trigger("deactivate"),this._lastState=b.id),this._state=a,this.state().trigger("activate"),this)},lastState:function(){if(this._lastState)return this.state(this._lastState)}}),_.each(["on","off","trigger"],function(a){c.prototype[a]=function(){return this.states=this.states||new Backbone.Collection,this.states[a].apply(this.states,arguments),this}}),a.exports=c},function(a,b){var c=Backbone.Model.extend({constructor:function(){this.on("activate",this._preActivate,this),this.on("activate",this.activate,this),this.on("activate",this._postActivate,this),this.on("deactivate",this._deactivate,this),this.on("deactivate",this.deactivate,this),this.on("reset",this.reset,this),this.on("ready",this._ready,this),this.on("ready",this.ready,this),Backbone.Model.apply(this,arguments),this.on("change:menu",this._updateMenu,this)},ready:function(){},activate:function(){},deactivate:function(){},reset:function(){},_ready:function(){this._updateMenu()},_preActivate:function(){this.active=!0},_postActivate:function(){this.on("change:menu",this._menu,this),this.on("change:titleMode",this._title,this),this.on("change:content",this._content,this),this.on("change:toolbar",this._toolbar,this),this.frame.on("title:render:default",this._renderTitle,this),this._title(),this._menu(),this._toolbar(),this._content(),this._router()},_deactivate:function(){this.active=!1,this.frame.off("title:render:default",this._renderTitle,this),this.off("change:menu",this._menu,this),this.off("change:titleMode",this._title,this),this.off("change:content",this._content,this),this.off("change:toolbar",this._toolbar,this)},_title:function(){this.frame.title.render(this.get("titleMode")||"default")},_renderTitle:function(a){a.$el.text(this.get("title")||"")},_router:function(){var a,b=this.frame.router,c=this.get("router");this.frame.$el.toggleClass("hide-router",!c),c&&(this.frame.router.render(c),a=b.get(),a&&a.select&&a.select(this.frame.content.mode()))},_menu:function(){var a,b=this.frame.menu,c=this.get("menu");this.frame.$el.toggleClass("hide-menu",!c),c&&(b.mode(c),a=b.get(),a&&a.select&&a.select(this.id))},_updateMenu:function(){var a=this.previous("menu"),b=this.get("menu");a&&this.frame.off("menu:render:"+a,this._renderMenu,this),b&&this.frame.on("menu:render:"+b,this._renderMenu,this)},_renderMenu:function(a){var b=this.get("menuItem"),c=this.get("title"),d=this.get("priority");!b&&c&&(b={text:c},d&&(b.priority=d)),b&&a.set(this.id,b)}});_.each(["toolbar","content"],function(a){c.prototype["_"+a]=function(){var b=this.get(a);b&&this.frame[a].render(b)}}),a.exports=c},function(a,b){var c={syncSelection:function(){var a=this.get("selection"),b=this.frame._selection;this.get("syncSelection")&&b&&a&&(a.multiple&&(a.reset([],{silent:!0}),a.validateAll(b.attachments),b.difference=_.difference(b.attachments.models,a.models)),a.single(b.single))},recordSelection:function(){var a=this.get("selection"),b=this.frame._selection;this.get("syncSelection")&&b&&a&&(a.multiple?(b.attachments.reset(a.toArray().concat(b.difference)),b.difference=[]):b.attachments.add(a.toArray()),b.single=a._single)}};a.exports=c},function(a,b){var c,d=wp.media.view.l10n,e=window.getUserSetting,f=window.setUserSetting;c=wp.media.controller.State.extend({defaults:{id:"library",title:d.mediaLibraryTitle,multiple:!1,content:"upload",menu:"default",router:"browse",toolbar:"select",searchable:!0,filterable:!1,sortable:!0,autoSelect:!0,describe:!1,contentUserSetting:!0,syncSelection:!0},initialize:function(){var a,b=this.get("selection");this.get("library")||this.set("library",wp.media.query()),b instanceof wp.media.model.Selection||(a=b,a||(a=this.get("library").props.toJSON(),a=_.omit(a,"orderby","query")),this.set("selection",new wp.media.model.Selection(null,{multiple:this.get("multiple"),props:a}))),this.resetDisplays()},activate:function(){this.syncSelection(),wp.Uploader.queue.on("add",this.uploading,this),this.get("selection").on("add remove reset",this.refreshContent,this),this.get("router")&&this.get("contentUserSetting")&&(this.frame.on("content:activate",this.saveContentMode,this),this.set("content",e("libraryContent",this.get("content"))))},deactivate:function(){this.recordSelection(),this.frame.off("content:activate",this.saveContentMode,this),this.get("selection").off(null,null,this),wp.Uploader.queue.off(null,null,this)},reset:function(){this.get("selection").reset(),this.resetDisplays(),this.refreshContent()},resetDisplays:function(){var a=wp.media.view.settings.defaultProps;this._displays=[],this._defaultDisplaySettings={align:e("align",a.align)||"none",size:e("imgsize",a.size)||"medium",link:e("urlbutton",a.link)||"none"}},display:function(a){var b=this._displays;return b[a.cid]||(b[a.cid]=new Backbone.Model(this.defaultDisplaySettings(a))),b[a.cid]},defaultDisplaySettings:function(a){var b=_.clone(this._defaultDisplaySettings);return(b.canEmbed=this.canEmbed(a))?b.link="embed":this.isImageAttachment(a)||"none"!==b.link||(b.link="file"),b},isImageAttachment:function(a){return a.get("uploading")?/\.(jpe?g|png|gif)$/i.test(a.get("filename")):"image"===a.get("type")},canEmbed:function(a){if(!a.get("uploading")){var b=a.get("type");if("audio"!==b&&"video"!==b)return!1}return _.contains(wp.media.view.settings.embedExts,a.get("filename").split(".").pop())},refreshContent:function(){var a=this.get("selection"),b=this.frame,c=b.router.get(),d=b.content.mode();this.active&&!a.length&&c&&!c.get(d)&&this.frame.content.render(this.get("content"))},uploading:function(a){var b=this.frame.content;"upload"===b.mode()&&this.frame.content.mode("browse"),this.get("autoSelect")&&(this.get("selection").add(a),this.frame.trigger("library:selection:add"))},saveContentMode:function(){if("browse"===this.get("router")){var a=this.frame.content.mode(),b=this.frame.router.get();b&&b.get(a)&&f("libraryContent",a)}}}),_.extend(c.prototype,wp.media.selectionSync),a.exports=c},function(a,b){var c,d=wp.media.controller.State,e=wp.media.controller.Library,f=wp.media.view.l10n;c=d.extend({defaults:_.defaults({id:"image-details",title:f.imageDetailsTitle,content:"image-details",menu:!1,router:!1,toolbar:"image-details",editing:!1,priority:60},e.prototype.defaults),initialize:function(a){this.image=a.image,d.prototype.initialize.apply(this,arguments)},activate:function(){this.frame.modal.$el.addClass("image-details")}}),a.exports=c},function(a,b){var c,d=wp.media.controller.Library,e=wp.media.view.l10n;c=d.extend({defaults:{id:"gallery-edit",title:e.editGalleryTitle,multiple:!1,searchable:!1,sortable:!0,date:!1,display:!1,content:"browse",toolbar:"gallery-edit",describe:!0,displaySettings:!0,dragInfo:!0,idealColumnWidth:170,editing:!1,priority:60,syncSelection:!1},initialize:function(){this.get("library")||this.set("library",new wp.media.model.Selection),this.get("AttachmentView")||this.set("AttachmentView",wp.media.view.Attachment.EditLibrary),d.prototype.initialize.apply(this,arguments)},activate:function(){var a=this.get("library");a.props.set("type","image"),this.get("library").observe(wp.Uploader.queue),this.frame.on("content:render:browse",this.gallerySettings,this),d.prototype.activate.apply(this,arguments)},deactivate:function(){this.get("library").unobserve(wp.Uploader.queue),this.frame.off("content:render:browse",this.gallerySettings,this),d.prototype.deactivate.apply(this,arguments)},gallerySettings:function(a){if(this.get("displaySettings")){var b=this.get("library");b&&a&&(b.gallery=b.gallery||new Backbone.Model,a.sidebar.set({gallery:new wp.media.view.Settings.Gallery({controller:this,model:b.gallery,priority:40})}),a.toolbar.set("reverse",{text:e.reverseOrder,priority:80,click:function(){b.reset(b.toArray().reverse())}}))}}}),a.exports=c},function(a,b){var c,d=wp.media.model.Selection,e=wp.media.controller.Library,f=wp.media.view.l10n;c=e.extend({defaults:_.defaults({id:"gallery-library",title:f.addToGalleryTitle,multiple:"add",filterable:"uploaded",menu:"gallery",toolbar:"gallery-add",priority:100,syncSelection:!1},e.prototype.defaults),initialize:function(){this.get("library")||this.set("library",wp.media.query({type:"image"})),e.prototype.initialize.apply(this,arguments)},activate:function(){var a=this.get("library"),b=this.frame.state("gallery-edit").get("library");this.editLibrary&&this.editLibrary!==b&&a.unobserve(this.editLibrary),a.validator=function(a){return!!this.mirroring.get(a.cid)&&!b.get(a.cid)&&d.prototype.validator.apply(this,arguments)},a.reset(a.mirroring.models,{silent:!0}),a.observe(b),this.editLibrary=b,e.prototype.activate.apply(this,arguments)}}),a.exports=c},function(a,b){var c,d=wp.media.controller.Library,e=wp.media.view.l10n,f=jQuery;c=d.extend({defaults:{multiple:!1,sortable:!0,date:!1,searchable:!1,content:"browse",describe:!0,dragInfo:!0,idealColumnWidth:170,editing:!1,priority:60,SettingsView:!1,syncSelection:!1},initialize:function(){var a=this.get("collectionType");"video"===this.get("type")&&(a="video-"+a),this.set("id",a+"-edit"),this.set("toolbar",a+"-edit"),this.get("library")||this.set("library",new wp.media.model.Selection),this.get("AttachmentView")||this.set("AttachmentView",wp.media.view.Attachment.EditLibrary),d.prototype.initialize.apply(this,arguments)},activate:function(){var a=this.get("library");a.props.set("type",this.get("type")),this.get("library").observe(wp.Uploader.queue),this.frame.on("content:render:browse",this.renderSettings,this),d.prototype.activate.apply(this,arguments)},deactivate:function(){this.get("library").unobserve(wp.Uploader.queue),this.frame.off("content:render:browse",this.renderSettings,this),d.prototype.deactivate.apply(this,arguments)},renderSettings:function(a){var b=this.get("library"),c=this.get("collectionType"),d=this.get("dragInfoText"),g=this.get("SettingsView"),h={};b&&a&&(b[c]=b[c]||new Backbone.Model,h[c]=new g({controller:this,model:b[c],priority:40}),a.sidebar.set(h),d&&a.toolbar.set("dragInfo",new wp.media.View({el:f('
'+d+"
")[0],priority:-40})),a.toolbar.set("reverse",{text:e.reverseOrder,priority:80,click:function(){b.reset(b.toArray().reverse())}}))}}),a.exports=c},function(a,b){var c,d=wp.media.model.Selection,e=wp.media.controller.Library;c=e.extend({defaults:_.defaults({multiple:"add",filterable:"uploaded",priority:100,syncSelection:!1},e.prototype.defaults),initialize:function(){var a=this.get("collectionType");"video"===this.get("type")&&(a="video-"+a),this.set("id",a+"-library"),this.set("toolbar",a+"-add"),this.set("menu",a),this.get("library")||this.set("library",wp.media.query({type:this.get("type")})),e.prototype.initialize.apply(this,arguments)},activate:function(){var a=this.get("library"),b=this.get("editLibrary"),c=this.frame.state(this.get("collectionType")+"-edit").get("library");b&&b!==c&&a.unobserve(b),a.validator=function(a){return!!this.mirroring.get(a.cid)&&!c.get(a.cid)&&d.prototype.validator.apply(this,arguments)},a.reset(a.mirroring.models,{silent:!0}),a.observe(c),this.set("editLibrary",c),e.prototype.activate.apply(this,arguments)}}),a.exports=c},function(a,b){var c,d=wp.media.model.Attachment,e=wp.media.controller.Library,f=wp.media.view.l10n;c=e.extend({defaults:_.defaults({id:"featured-image",title:f.setFeaturedImageTitle,multiple:!1,filterable:"uploaded",toolbar:"featured-image",priority:60,syncSelection:!0},e.prototype.defaults),initialize:function(){var a,b;this.get("library")||this.set("library",wp.media.query({type:"image"})),e.prototype.initialize.apply(this,arguments),a=this.get("library"),b=a.comparator,a.comparator=function(a,c){var d=!!this.mirroring.get(a.cid),e=!!this.mirroring.get(c.cid);return!d&&e?-1:d&&!e?1:b.apply(this,arguments)},a.observe(this.get("selection"))},activate:function(){this.updateSelection(),this.frame.on("open",this.updateSelection,this),e.prototype.activate.apply(this,arguments)},deactivate:function(){this.frame.off("open",this.updateSelection,this),e.prototype.deactivate.apply(this,arguments)},updateSelection:function(){var a,b=this.get("selection"),c=wp.media.view.settings.post.featuredImageId;""!==c&&-1!==c&&(a=d.get(c),a.fetch()),b.reset(a?[a]:[])}}),a.exports=c},function(a,b){var c,d=wp.media.controller.Library,e=wp.media.view.l10n;c=d.extend({defaults:_.defaults({id:"replace-image",title:e.replaceImageTitle,multiple:!1,filterable:"uploaded",toolbar:"replace",menu:!1,priority:60,syncSelection:!0},d.prototype.defaults),initialize:function(a){var b,c;this.image=a.image,this.get("library")||this.set("library",wp.media.query({type:"image"})),d.prototype.initialize.apply(this,arguments),b=this.get("library"),c=b.comparator,b.comparator=function(a,b){var d=!!this.mirroring.get(a.cid),e=!!this.mirroring.get(b.cid);return!d&&e?-1:d&&!e?1:c.apply(this,arguments)},b.observe(this.get("selection"))},activate:function(){this.updateSelection(),d.prototype.activate.apply(this,arguments)},updateSelection:function(){var a=this.get("selection"),b=this.image.attachment;a.reset(b?[b]:[])}}),a.exports=c},function(a,b){var c,d=wp.media.view.l10n;c=wp.media.controller.State.extend({defaults:{id:"edit-image",title:d.editImage,menu:!1,toolbar:"edit-image",content:"edit-image",url:""},activate:function(){this.frame.on("toolbar:render:edit-image",_.bind(this.toolbar,this))},deactivate:function(){this.frame.off("toolbar:render:edit-image")},toolbar:function(){var a=this.frame,b=a.lastState(),c=b&&b.id;a.toolbar.set(new wp.media.view.Toolbar({controller:a,items:{back:{style:"primary",text:d.back,priority:20,click:function(){c?a.setState(c):a.close()}}}}))}}),a.exports=c},function(a,b){var c,d=wp.media.controller.Library;c=d.extend({defaults:_.defaults({filterable:"uploaded",displaySettings:!1,priority:80,syncSelection:!1},d.prototype.defaults),initialize:function(a){this.media=a.media,this.type=a.type,this.set("library",wp.media.query({type:this.type})),d.prototype.initialize.apply(this,arguments)},activate:function(){wp.media.frame.lastMime&&(this.set("library",wp.media.query({type:wp.media.frame.lastMime})),delete wp.media.frame.lastMime),d.prototype.activate.apply(this,arguments)}}),a.exports=c},function(a,b){var c,d=wp.media.view.l10n,e=Backbone.$;c=wp.media.controller.State.extend({defaults:{id:"embed",title:d.insertFromUrlTitle,content:"embed",menu:"default",toolbar:"main-embed",priority:120,type:"link",url:"",metadata:{}},sensitivity:400,initialize:function(a){this.metadata=a.metadata,this.debouncedScan=_.debounce(_.bind(this.scan,this),this.sensitivity),this.props=new Backbone.Model(this.metadata||{url:""}),this.props.on("change:url",this.debouncedScan,this),this.props.on("change:url",this.refresh,this),this.on("scan",this.scanImage,this)},scan:function(){var a,b=this,c={type:"link",scanners:[]};this.props.get("url")&&this.trigger("scan",c),c.scanners.length?(a=c.scanners=e.when.apply(e,c.scanners),a.always(function(){b.get("scanners")===a&&b.set("loading",!1)})):c.scanners=null,c.loading=!!c.scanners,this.set(c)},scanImage:function(a){var b=this.frame,c=this,d=this.props.get("url"),f=new Image,g=e.Deferred();a.scanners.push(g.promise()),f.onload=function(){g.resolve(),c===b.state()&&d===c.props.get("url")&&(c.set({type:"image"}),c.props.set({width:f.width,height:f.height}))},f.onerror=g.reject,f.src=d},refresh:function(){this.frame.toolbar.get().refresh()},reset:function(){this.props.clear().set({url:""}),this.active&&this.refresh()}}),a.exports=c},function(a,b){var c,d=wp.media.view.l10n;c=wp.media.controller.State.extend({defaults:{id:"cropper",title:d.cropImage,toolbar:"crop",content:"crop",router:!1,canSkipCrop:!1,doCropArgs:{}},activate:function(){this.frame.on("content:create:crop",this.createCropContent,this),this.frame.on("close",this.removeCropper,this),this.set("selection",new Backbone.Collection(this.frame._selection.single))},deactivate:function(){this.frame.toolbar.mode("browse")},createCropContent:function(){this.cropperView=new wp.media.view.Cropper({controller:this,attachment:this.get("selection").first()}),this.cropperView.on("image-loaded",this.createCropToolbar,this),this.frame.content.set(this.cropperView)},removeCropper:function(){this.imgSelect.cancelSelection(),this.imgSelect.setOptions({remove:!0}),this.imgSelect.update(),this.cropperView.remove()},createCropToolbar:function(){var a,b;a=this.get("canSkipCrop")||!1,b={controller:this.frame,items:{insert:{style:"primary",text:d.cropImage,priority:80,requires:{library:!1,selection:!1},click:function(){var a,b=this.controller;a=b.state().get("selection").first(),a.set({cropDetails:b.state().imgSelect.getSelection()}),this.$el.text(d.cropping),this.$el.attr("disabled",!0),b.state().doCrop(a).done(function(a){b.trigger("cropped",a),b.close()}).fail(function(){b.trigger("content:error:crop")})}}}},a&&_.extend(b.items,{skip:{style:"secondary",text:d.skipCropping,priority:70,requires:{library:!1,selection:!1},click:function(){var a=this.controller.state().get("selection").first();this.controller.state().cropperView.remove(),this.controller.trigger("skippedcrop",a),this.controller.close()}}}),this.frame.toolbar.set(new wp.media.view.Toolbar(b))},doCrop:function(a){return wp.ajax.post("custom-header-crop",_.extend({},this.defaults.doCropArgs,{nonce:a.get("nonces").edit,id:a.get("id"),cropDetails:a.get("cropDetails")}))}}),a.exports=c},function(a,b){var c,d=wp.media.controller;c=d.Cropper.extend({doCrop:function(a){var b=a.get("cropDetails"),c=this.get("control"),d=b.width/b.height;return c.params.flex_width&&c.params.flex_height?(b.dst_width=b.width,b.dst_height=b.height):(b.dst_width=c.params.flex_width?c.params.height*d:c.params.width,b.dst_height=c.params.flex_height?c.params.width/d:c.params.height),wp.ajax.post("crop-image",{wp_customize:"on",nonce:a.get("nonces").edit,id:a.get("id"),context:c.id,cropDetails:b})}}),a.exports=c},function(a,b){var c,d=wp.media.controller;c=d.Cropper.extend({activate:function(){this.frame.on("content:create:crop",this.createCropContent,this),this.frame.on("close",this.removeCropper,this),this.set("selection",new Backbone.Collection(this.frame._selection.single))},createCropContent:function(){this.cropperView=new wp.media.view.SiteIconCropper({controller:this,attachment:this.get("selection").first()}),this.cropperView.on("image-loaded",this.createCropToolbar,this),this.frame.content.set(this.cropperView)},doCrop:function(a){var b=a.get("cropDetails"),c=this.get("control");return b.dst_width=c.params.width,b.dst_height=c.params.height,wp.ajax.post("crop-image",{nonce:a.get("nonces").edit,id:a.get("id"),context:"site-icon",cropDetails:b})}}),a.exports=c},function(a,b){var c=wp.Backbone.View.extend({constructor:function(a){a&&a.controller&&(this.controller=a.controller),wp.Backbone.View.apply(this,arguments)},dispose:function(){return this.undelegateEvents(),this.model&&this.model.off&&this.model.off(null,null,this),this.collection&&this.collection.off&&this.collection.off(null,null,this),this.controller&&this.controller.off&&this.controller.off(null,null,this),this},remove:function(){return this.dispose(),wp.Backbone.View.prototype.remove.apply(this,arguments)}});a.exports=c},function(a,b){var c=wp.media.View.extend({initialize:function(){_.defaults(this.options,{mode:["select"]}),this._createRegions(),this._createStates(),this._createModes()},_createRegions:function(){this.regions=this.regions?this.regions.slice():[],_.each(this.regions,function(a){this[a]=new wp.media.controller.Region({view:this,id:a,selector:".media-frame-"+a})},this)},_createStates:function(){this.states=new Backbone.Collection(null,{model:wp.media.controller.State}),this.states.on("add",function(a){a.frame=this,a.trigger("ready")},this),this.options.states&&this.states.add(this.options.states)},_createModes:function(){this.activeModes=new Backbone.Collection,this.activeModes.on("add remove reset",_.bind(this.triggerModeEvents,this)),_.each(this.options.mode,function(a){this.activateMode(a)},this)},reset:function(){return this.states.invoke("trigger","reset"),this},triggerModeEvents:function(a,b,c){var d,e,f={add:"activate",remove:"deactivate"};_.each(c,function(a,b){a&&(d=b)}),_.has(f,d)&&(e=a.get("id")+":"+f[d],this.trigger(e))},activateMode:function(a){if(!this.isModeActive(a))return this.activeModes.add([{id:a}]),this.$el.addClass("mode-"+a),this},deactivateMode:function(a){return this.isModeActive(a)?(this.activeModes.remove(this.activeModes.where({id:a})),this.$el.removeClass("mode-"+a),this.trigger(a+":deactivate"),this):this},isModeActive:function(a){return Boolean(this.activeModes.where({id:a}).length)}});_.extend(c.prototype,wp.media.controller.StateMachine.prototype),a.exports=c},function(a,b){var c,d=wp.media.view.Frame,e=wp.media.view.l10n,f=jQuery;c=d.extend({className:"media-frame",template:wp.template("media-frame"),regions:["menu","title","content","toolbar","router"],events:{"click div.media-frame-title h1":"toggleMenu"},initialize:function(){d.prototype.initialize.apply(this,arguments),_.defaults(this.options,{title:e.mediaFrameDefaultTitle,modal:!0,uploader:!0}),this.$el.addClass("wp-core-ui"),this.options.modal&&(this.modal=new wp.media.view.Modal({controller:this,title:this.options.title}),this.modal.content(this)),!wp.Uploader.limitExceeded&&wp.Uploader.browser.supported||(this.options.uploader=!1),this.options.uploader&&(this.uploader=new wp.media.view.UploaderWindow({controller:this,uploader:{dropzone:this.modal?this.modal.$el:this.$el,container:this.$el}}),this.views.set(".media-frame-uploader",this.uploader)),this.on("attach",_.bind(this.views.ready,this.views),this),this.on("title:create:default",this.createTitle,this),this.title.mode("default"),this.on("title:render",function(a){a.$el.append('')}),this.on("menu:create:default",this.createMenu,this)},render:function(){return!this.state()&&this.options.state&&this.setState(this.options.state),d.prototype.render.apply(this,arguments)},createTitle:function(a){a.view=new wp.media.View({controller:this,tagName:"h1"})},createMenu:function(a){a.view=new wp.media.view.Menu({controller:this})},toggleMenu:function(){this.$el.find(".media-menu").toggleClass("visible")},createToolbar:function(a){a.view=new wp.media.view.Toolbar({controller:this})},createRouter:function(a){a.view=new wp.media.view.Router({controller:this})},createIframeStates:function(a){var b,c=wp.media.view.settings,d=c.tabs,e=c.tabUrl;d&&e&&(b=f("#post_ID"),b.length&&(e+="&post_id="+b.val()),_.each(d,function(b,c){this.state("iframe:"+c).set(_.defaults({tab:c,src:e+"&tab="+c,title:b,content:"iframe",menu:"default"},a))},this),this.on("content:create:iframe",this.iframeContent,this),this.on("content:deactivate:iframe",this.iframeContentCleanup,this),this.on("menu:render:default",this.iframeMenu,this),this.on("open",this.hijackThickbox,this),this.on("close",this.restoreThickbox,this))},iframeContent:function(a){this.$el.addClass("hide-toolbar"),a.view=new wp.media.view.Iframe({controller:this})},iframeContentCleanup:function(){this.$el.removeClass("hide-toolbar")},iframeMenu:function(a){var b={};a&&(_.each(wp.media.view.settings.tabs,function(a,c){b["iframe:"+c]={text:this.state("iframe:"+c).get("title"),priority:200}},this),a.set(b))},hijackThickbox:function(){var a=this;window.tb_remove&&!this._tb_remove&&(this._tb_remove=window.tb_remove,window.tb_remove=function(){a.close(),a.reset(),a.setState(a.options.state),a._tb_remove.call(window)})},restoreThickbox:function(){this._tb_remove&&(window.tb_remove=this._tb_remove,delete this._tb_remove)}}),_.each(["open","close","attach","detach","escape"],function(a){c.prototype[a]=function(){return this.modal&&this.modal[a].apply(this.modal,arguments),this}}),a.exports=c},function(a,b){var c,d=wp.media.view.MediaFrame,e=wp.media.view.l10n;c=d.extend({initialize:function(){d.prototype.initialize.apply(this,arguments),_.defaults(this.options,{selection:[],library:{},multiple:!1,state:"library"}),this.createSelection(),this.createStates(),this.bindHandlers()},createSelection:function(){var a=this.options.selection;a instanceof wp.media.model.Selection||(this.options.selection=new wp.media.model.Selection(a,{multiple:this.options.multiple})),this._selection={attachments:new wp.media.model.Attachments,difference:[]}},createStates:function(){var a=this.options;this.options.states||this.states.add([new wp.media.controller.Library({library:wp.media.query(a.library),multiple:a.multiple,title:a.title,priority:20})])},bindHandlers:function(){this.on("router:create:browse",this.createRouter,this),this.on("router:render:browse",this.browseRouter,this),this.on("content:create:browse",this.browseContent,this),this.on("content:render:upload",this.uploadContent,this),this.on("toolbar:create:select",this.createSelectToolbar,this)},browseRouter:function(a){a.set({upload:{text:e.uploadFilesTitle,priority:20},browse:{text:e.mediaLibraryTitle,priority:40}})},browseContent:function(a){var b=this.state();this.$el.removeClass("hide-toolbar"),a.view=new wp.media.view.AttachmentsBrowser({controller:this,collection:b.get("library"),selection:b.get("selection"),model:b,sortable:b.get("sortable"),search:b.get("searchable"),filters:b.get("filterable"),date:b.get("date"),display:b.has("display")?b.get("display"):b.get("displaySettings"),dragInfo:b.get("dragInfo"),idealColumnWidth:b.get("idealColumnWidth"),suggestedWidth:b.get("suggestedWidth"),suggestedHeight:b.get("suggestedHeight"),AttachmentView:b.get("AttachmentView")})},uploadContent:function(){this.$el.removeClass("hide-toolbar"),this.content.set(new wp.media.view.UploaderInline({controller:this}))},createSelectToolbar:function(a,b){b=b||this.options.button||{},b.controller=this,a.view=new wp.media.view.Toolbar.Select(b)}}),a.exports=c},function(a,b){var c,d=wp.media.view.MediaFrame.Select,e=wp.media.controller.Library,f=wp.media.view.l10n;c=d.extend({initialize:function(){this.counts={audio:{count:wp.media.view.settings.attachmentCounts.audio,state:"playlist"},video:{count:wp.media.view.settings.attachmentCounts.video,state:"video-playlist"}},_.defaults(this.options,{multiple:!0,editing:!1,state:"insert",metadata:{}}),d.prototype.initialize.apply(this,arguments),this.createIframeStates()},createStates:function(){var a=this.options;this.states.add([new e({id:"insert",title:f.insertMediaTitle,priority:20,toolbar:"main-insert",filterable:"all",library:wp.media.query(a.library),multiple:!!a.multiple&&"reset",editable:!0,allowLocalEdits:!0,displaySettings:!0,displayUserSettings:!0}),new e({id:"gallery",title:f.createGalleryTitle,priority:40,toolbar:"main-gallery",filterable:"uploaded",multiple:"add",editable:!1,library:wp.media.query(_.defaults({type:"image"},a.library))}),new wp.media.controller.Embed({metadata:a.metadata}),new wp.media.controller.EditImage({model:a.editImage}),new wp.media.controller.GalleryEdit({library:a.selection,editing:a.editing,menu:"gallery"}),new wp.media.controller.GalleryAdd,new e({id:"playlist",title:f.createPlaylistTitle,priority:60,toolbar:"main-playlist",filterable:"uploaded",multiple:"add",editable:!1,library:wp.media.query(_.defaults({type:"audio" -},a.library))}),new wp.media.controller.CollectionEdit({type:"audio",collectionType:"playlist",title:f.editPlaylistTitle,SettingsView:wp.media.view.Settings.Playlist,library:a.selection,editing:a.editing,menu:"playlist",dragInfoText:f.playlistDragInfo,dragInfo:!1}),new wp.media.controller.CollectionAdd({type:"audio",collectionType:"playlist",title:f.addToPlaylistTitle}),new e({id:"video-playlist",title:f.createVideoPlaylistTitle,priority:60,toolbar:"main-video-playlist",filterable:"uploaded",multiple:"add",editable:!1,library:wp.media.query(_.defaults({type:"video"},a.library))}),new wp.media.controller.CollectionEdit({type:"video",collectionType:"playlist",title:f.editVideoPlaylistTitle,SettingsView:wp.media.view.Settings.Playlist,library:a.selection,editing:a.editing,menu:"video-playlist",dragInfoText:f.videoPlaylistDragInfo,dragInfo:!1}),new wp.media.controller.CollectionAdd({type:"video",collectionType:"playlist",title:f.addToVideoPlaylistTitle})]),wp.media.view.settings.post.featuredImageId&&this.states.add(new wp.media.controller.FeaturedImage)},bindHandlers:function(){var a,b;d.prototype.bindHandlers.apply(this,arguments),this.on("activate",this.activate,this),b=_.find(this.counts,function(a){return 0===a.count}),"undefined"!=typeof b&&this.listenTo(wp.media.model.Attachments.all,"change:type",this.mediaTypeCounts),this.on("menu:create:gallery",this.createMenu,this),this.on("menu:create:playlist",this.createMenu,this),this.on("menu:create:video-playlist",this.createMenu,this),this.on("toolbar:create:main-insert",this.createToolbar,this),this.on("toolbar:create:main-gallery",this.createToolbar,this),this.on("toolbar:create:main-playlist",this.createToolbar,this),this.on("toolbar:create:main-video-playlist",this.createToolbar,this),this.on("toolbar:create:featured-image",this.featuredImageToolbar,this),this.on("toolbar:create:main-embed",this.mainEmbedToolbar,this),a={menu:{"default":"mainMenu",gallery:"galleryMenu",playlist:"playlistMenu","video-playlist":"videoPlaylistMenu"},content:{embed:"embedContent","edit-image":"editImageContent","edit-selection":"editSelectionContent"},toolbar:{"main-insert":"mainInsertToolbar","main-gallery":"mainGalleryToolbar","gallery-edit":"galleryEditToolbar","gallery-add":"galleryAddToolbar","main-playlist":"mainPlaylistToolbar","playlist-edit":"playlistEditToolbar","playlist-add":"playlistAddToolbar","main-video-playlist":"mainVideoPlaylistToolbar","video-playlist-edit":"videoPlaylistEditToolbar","video-playlist-add":"videoPlaylistAddToolbar"}},_.each(a,function(a,b){_.each(a,function(a,c){this.on(b+":render:"+c,this[a],this)},this)},this)},activate:function(){_.each(this.counts,function(a){a.count<1&&this.menuItemVisibility(a.state,"hide")},this)},mediaTypeCounts:function(a,b){"undefined"!=typeof this.counts[b]&&this.counts[b].count<1&&(this.counts[b].count++,this.menuItemVisibility(this.counts[b].state,"show"))},mainMenu:function(a){a.set({"library-separator":new wp.media.View({className:"separator",priority:100})})},menuItemVisibility:function(a,b){var c=this.menu.get();"hide"===b?c.hide(a):"show"===b&&c.show(a)},galleryMenu:function(a){var b=this.lastState(),c=b&&b.id,d=this;a.set({cancel:{text:f.cancelGalleryTitle,priority:20,click:function(){c?d.setState(c):d.close(),this.controller.modal.focusManager.focus()}},separateCancel:new wp.media.View({className:"separator",priority:40})})},playlistMenu:function(a){var b=this.lastState(),c=b&&b.id,d=this;a.set({cancel:{text:f.cancelPlaylistTitle,priority:20,click:function(){c?d.setState(c):d.close(),this.controller.modal.focusManager.focus()}},separateCancel:new wp.media.View({className:"separator",priority:40})})},videoPlaylistMenu:function(a){var b=this.lastState(),c=b&&b.id,d=this;a.set({cancel:{text:f.cancelVideoPlaylistTitle,priority:20,click:function(){c?d.setState(c):d.close(),this.controller.modal.focusManager.focus()}},separateCancel:new wp.media.View({className:"separator",priority:40})})},embedContent:function(){var a=new wp.media.view.Embed({controller:this,model:this.state()}).render();this.content.set(a)},editSelectionContent:function(){var a,b=this.state(),c=b.get("selection");a=new wp.media.view.AttachmentsBrowser({controller:this,collection:c,selection:c,model:b,sortable:!0,search:!1,date:!1,dragInfo:!0,AttachmentView:wp.media.view.Attachments.EditSelection}).render(),a.toolbar.set("backToLibrary",{text:f.returnToLibrary,priority:-100,click:function(){this.controller.content.mode("browse"),this.controller.modal.focusManager.focus()}}),this.content.set(a),this.trigger("edit:selection",this)},editImageContent:function(){var a=this.state().get("image"),b=new wp.media.view.EditImage({model:a,controller:this}).render();this.content.set(b),b.loadEditor()},selectionStatusToolbar:function(a){var b=this.state().get("editable");a.set("selection",new wp.media.view.Selection({controller:this,collection:this.state().get("selection"),priority:-40,editable:b&&function(){this.controller.content.mode("edit-selection")}}).render())},mainInsertToolbar:function(a){var b=this;this.selectionStatusToolbar(a),a.set("insert",{style:"primary",priority:80,text:f.insertIntoPost,requires:{selection:!0},click:function(){var a=b.state(),c=a.get("selection");b.close(),a.trigger("insert",c).reset()}})},mainGalleryToolbar:function(a){var b=this;this.selectionStatusToolbar(a),a.set("gallery",{style:"primary",text:f.createNewGallery,priority:60,requires:{selection:!0},click:function(){var a=b.state().get("selection"),c=b.state("gallery-edit"),d=a.where({type:"image"});c.set("library",new wp.media.model.Selection(d,{props:a.props.toJSON(),multiple:!0})),this.controller.setState("gallery-edit"),this.controller.modal.focusManager.focus()}})},mainPlaylistToolbar:function(a){var b=this;this.selectionStatusToolbar(a),a.set("playlist",{style:"primary",text:f.createNewPlaylist,priority:100,requires:{selection:!0},click:function(){var a=b.state().get("selection"),c=b.state("playlist-edit"),d=a.where({type:"audio"});c.set("library",new wp.media.model.Selection(d,{props:a.props.toJSON(),multiple:!0})),this.controller.setState("playlist-edit"),this.controller.modal.focusManager.focus()}})},mainVideoPlaylistToolbar:function(a){var b=this;this.selectionStatusToolbar(a),a.set("video-playlist",{style:"primary",text:f.createNewVideoPlaylist,priority:100,requires:{selection:!0},click:function(){var a=b.state().get("selection"),c=b.state("video-playlist-edit"),d=a.where({type:"video"});c.set("library",new wp.media.model.Selection(d,{props:a.props.toJSON(),multiple:!0})),this.controller.setState("video-playlist-edit"),this.controller.modal.focusManager.focus()}})},featuredImageToolbar:function(a){this.createSelectToolbar(a,{text:f.setFeaturedImage,state:this.options.state})},mainEmbedToolbar:function(a){a.view=new wp.media.view.Toolbar.Embed({controller:this})},galleryEditToolbar:function(){var a=this.state().get("editing");this.toolbar.set(new wp.media.view.Toolbar({controller:this,items:{insert:{style:"primary",text:a?f.updateGallery:f.insertGallery,priority:80,requires:{library:!0},click:function(){var a=this.controller,b=a.state();a.close(),b.trigger("update",b.get("library")),a.setState(a.options.state),a.reset()}}}}))},galleryAddToolbar:function(){this.toolbar.set(new wp.media.view.Toolbar({controller:this,items:{insert:{style:"primary",text:f.addToGallery,priority:80,requires:{selection:!0},click:function(){var a=this.controller,b=a.state(),c=a.state("gallery-edit");c.get("library").add(b.get("selection").models),b.trigger("reset"),a.setState("gallery-edit"),this.controller.modal.focusManager.focus()}}}}))},playlistEditToolbar:function(){var a=this.state().get("editing");this.toolbar.set(new wp.media.view.Toolbar({controller:this,items:{insert:{style:"primary",text:a?f.updatePlaylist:f.insertPlaylist,priority:80,requires:{library:!0},click:function(){var a=this.controller,b=a.state();a.close(),b.trigger("update",b.get("library")),a.setState(a.options.state),a.reset()}}}}))},playlistAddToolbar:function(){this.toolbar.set(new wp.media.view.Toolbar({controller:this,items:{insert:{style:"primary",text:f.addToPlaylist,priority:80,requires:{selection:!0},click:function(){var a=this.controller,b=a.state(),c=a.state("playlist-edit");c.get("library").add(b.get("selection").models),b.trigger("reset"),a.setState("playlist-edit"),this.controller.modal.focusManager.focus()}}}}))},videoPlaylistEditToolbar:function(){var a=this.state().get("editing");this.toolbar.set(new wp.media.view.Toolbar({controller:this,items:{insert:{style:"primary",text:a?f.updateVideoPlaylist:f.insertVideoPlaylist,priority:140,requires:{library:!0},click:function(){var a=this.controller,b=a.state(),c=b.get("library");c.type="video",a.close(),b.trigger("update",c),a.setState(a.options.state),a.reset()}}}}))},videoPlaylistAddToolbar:function(){this.toolbar.set(new wp.media.view.Toolbar({controller:this,items:{insert:{style:"primary",text:f.addToVideoPlaylist,priority:140,requires:{selection:!0},click:function(){var a=this.controller,b=a.state(),c=a.state("video-playlist-edit");c.get("library").add(b.get("selection").models),b.trigger("reset"),a.setState("video-playlist-edit"),this.controller.modal.focusManager.focus()}}}}))}}),a.exports=c},function(a,b){var c,d=wp.media.view.MediaFrame.Select,e=wp.media.view.l10n;c=d.extend({defaults:{id:"image",url:"",menu:"image-details",content:"image-details",toolbar:"image-details",type:"link",title:e.imageDetailsTitle,priority:120},initialize:function(a){this.image=new wp.media.model.PostImage(a.metadata),this.options.selection=new wp.media.model.Selection(this.image.attachment,{multiple:!1}),d.prototype.initialize.apply(this,arguments)},bindHandlers:function(){d.prototype.bindHandlers.apply(this,arguments),this.on("menu:create:image-details",this.createMenu,this),this.on("content:create:image-details",this.imageDetailsContent,this),this.on("content:render:edit-image",this.editImageContent,this),this.on("toolbar:render:image-details",this.renderImageDetailsToolbar,this),this.on("toolbar:render:replace",this.renderReplaceImageToolbar,this)},createStates:function(){this.states.add([new wp.media.controller.ImageDetails({image:this.image,editable:!1}),new wp.media.controller.ReplaceImage({id:"replace-image",library:wp.media.query({type:"image"}),image:this.image,multiple:!1,title:e.imageReplaceTitle,toolbar:"replace",priority:80,displaySettings:!0}),new wp.media.controller.EditImage({image:this.image,selection:this.options.selection})])},imageDetailsContent:function(a){a.view=new wp.media.view.ImageDetails({controller:this,model:this.state().image,attachment:this.state().image.attachment})},editImageContent:function(){var a,b=this.state(),c=b.get("image");c&&(a=new wp.media.view.EditImage({model:c,controller:this}).render(),this.content.set(a),a.loadEditor())},renderImageDetailsToolbar:function(){this.toolbar.set(new wp.media.view.Toolbar({controller:this,items:{select:{style:"primary",text:e.update,priority:80,click:function(){var a=this.controller,b=a.state();a.close(),b.trigger("update",a.image.toJSON()),a.setState(a.options.state),a.reset()}}}}))},renderReplaceImageToolbar:function(){var a=this,b=a.lastState(),c=b&&b.id;this.toolbar.set(new wp.media.view.Toolbar({controller:this,items:{back:{text:e.back,priority:80,click:function(){c?a.setState(c):a.close()}},replace:{style:"primary",text:e.replace,priority:20,requires:{selection:!0},click:function(){var a=this.controller,b=a.state(),c=b.get("selection"),d=c.single();a.close(),a.image.changeAttachment(d,b.display(d)),b.trigger("replace",a.image.toJSON()),a.setState(a.options.state),a.reset()}}}}))}}),a.exports=c},function(a,b){var c,d=jQuery;c=wp.media.View.extend({tagName:"div",template:wp.template("media-modal"),events:{"click .media-modal-backdrop, .media-modal-close":"escapeHandler",keydown:"keydown"},clickedOpenerEl:null,initialize:function(){_.defaults(this.options,{container:document.body,title:"",propagate:!0,hasCloseButton:!0}),this.focusManager=new wp.media.view.FocusManager({el:this.el})},prepare:function(){return{title:this.options.title,hasCloseButton:this.options.hasCloseButton}},attach:function(){return this.views.attached?this:(this.views.rendered||this.render(),this.$el.appendTo(this.options.container),this.views.attached=!0,this.views.ready(),this.propagate("attach"))},detach:function(){return this.$el.is(":visible")&&this.close(),this.$el.detach(),this.views.attached=!1,this.propagate("detach")},open:function(){var a,b=this.$el;return b.is(":visible")?this:(this.clickedOpenerEl=document.activeElement,this.views.attached||this.attach(),d("body").addClass("modal-open"),b.show(),"ontouchend"in document&&(a=window.tinymce&&window.tinymce.activeEditor)&&!a.isHidden()&&a.iframeElement&&(a.iframeElement.focus(),a.iframeElement.blur(),setTimeout(function(){a.iframeElement.blur()},100)),this.$(".media-modal").focus(),this.focusManager.setAriaHiddenOnBodyChildren(b),this.propagate("open"))},close:function(a){return this.views.attached&&this.$el.is(":visible")?(d("body").removeClass("modal-open"),this.$el.hide().undelegate("keydown"),this.focusManager.removeAriaHiddenFromBodyChildren(),null!==this.clickedOpenerEl?this.clickedOpenerEl.focus():d("#wpbody-content").attr("tabindex","-1").focus(),this.propagate("close"),a&&a.escape&&this.propagate("escape"),this):this},escape:function(){return this.close({escape:!0})},escapeHandler:function(a){a.preventDefault(),this.escape()},content:function(a){return this.views.set(".media-modal-content",a),this},propagate:function(a){return this.trigger(a),this.options.propagate&&this.controller.trigger(a),this},keydown:function(a){27===a.which&&this.$el.is(":visible")&&(this.escape(),a.stopImmediatePropagation())}}),a.exports=c},function(a,b){var c=wp.media.View.extend({events:{keydown:"constrainTabbing"},getTabbables:function(){return this.$(":tabbable").not('.moxie-shim input[type="file"]')},focus:function(){this.$(".media-modal").focus()},constrainTabbing:function(a){var b;if(9===a.keyCode)return b=this.getTabbables(),b.last()[0]!==a.target||a.shiftKey?b.first()[0]===a.target&&a.shiftKey?(b.last().focus(),!1):void 0:(b.first().focus(),!1)},setAriaHiddenOnBodyChildren:function(a){var b,c=this;this.isBodyAriaHidden||(b=document.body.children,_.each(b,function(b){b!==a[0]&&c.elementShouldBeHidden(b)&&(b.setAttribute("aria-hidden","true"),c.ariaHiddenElements.push(b))}),this.isBodyAriaHidden=!0)},removeAriaHiddenFromBodyChildren:function(){_.each(this.ariaHiddenElements,function(a){a.removeAttribute("aria-hidden")}),this.ariaHiddenElements=[],this.isBodyAriaHidden=!1},elementShouldBeHidden:function(a){var b=a.getAttribute("role"),c=["alert","status","log","marquee","timer"];return!("SCRIPT"===a.tagName||a.hasAttribute("aria-hidden")||a.hasAttribute("aria-live")||c.indexOf(b)!==-1)},isBodyAriaHidden:!1,ariaHiddenElements:[]});a.exports=c},function(a,b){var c,d=jQuery;c=wp.media.View.extend({tagName:"div",className:"uploader-window",template:wp.template("uploader-window"),initialize:function(){var a;this.$browser=d('