314
314
$post_data = apply_filters( 'attachment_fields_to_save', $post_data, $attachment_data );
317
// Convert taxonomy input to term IDs, to avoid ambiguity.
318
if ( isset( $post_data['tax_input'] ) ) {
319
foreach ( (array) $post_data['tax_input'] as $taxonomy => $terms ) {
320
// Hierarchical taxonomy data is already sent as term IDs, so no conversion is necessary.
321
if ( is_taxonomy_hierarchical( $taxonomy ) ) {
326
* Assume that a 'tax_input' string is a comma-separated list of term names.
327
* Some languages may use a character other than a comma as a delimiter, so we standardize on
328
* commas before parsing the list.
330
if ( ! is_array( $terms ) ) {
331
$comma = _x( ',', 'tag delimiter' );
332
if ( ',' !== $comma ) {
333
$terms = str_replace( $comma, ',', $terms );
335
$terms = explode( ',', trim( $terms, " \n\t\r\0\x0B," ) );
338
$clean_terms = array();
339
foreach ( $terms as $term ) {
340
// Empty terms are invalid input.
341
if ( empty( $term ) ) {
345
$_term = get_terms( $taxonomy, array(
348
'hide_empty' => false,
351
if ( ! empty( $_term ) ) {
352
$clean_terms[] = intval( $_term[0] );
354
// No existing term was found, so pass the string. A new term will be created.
355
$clean_terms[] = $term;
359
$post_data['tax_input'][ $taxonomy ] = $clean_terms;
317
363
add_meta( $post_ID );
319
365
update_post_meta( $post_ID, '_edit_last', get_current_user_id() );
1024
* Executes a query for attachments. An array of WP_Query arguments
1025
* can be passed in, which will override the arguments set by this function.
1029
* @param array|bool $q Array of query variables to use to build the query or false to use $_GET superglobal.
1069
* Get the query variables for the current attachments request.
1073
* @param array|false $q Optional. Array of query variables to use to build the query or false
1074
* to use $_GET superglobal. Default false.
1075
* @return array The parsed query vars.
1032
function wp_edit_attachments_query( $q = false ) {
1077
function wp_edit_attachments_query_vars( $q = false ) {
1078
if ( false === $q ) {
1036
1081
$q['m'] = isset( $q['m'] ) ? (int) $q['m'] : 0;
1037
1082
$q['cat'] = isset( $q['cat'] ) ? (int) $q['cat'] : 0;
1038
1083
$q['post_type'] = 'attachment';
1039
1084
$post_type = get_post_type_object( 'attachment' );
1040
1085
$states = 'inherit';
1041
if ( current_user_can( $post_type->cap->read_private_posts ) )
1086
if ( current_user_can( $post_type->cap->read_private_posts ) ) {
1042
1087
$states .= ',private';
1044
1090
$q['post_status'] = isset( $q['status'] ) && 'trash' == $q['status'] ? 'trash' : $states;
1045
1091
$q['post_status'] = isset( $q['attachment-filter'] ) && 'trash' == $q['attachment-filter'] ? 'trash' : $states;
1047
1093
$media_per_page = (int) get_user_option( 'upload_per_page' );
1048
if ( empty( $media_per_page ) || $media_per_page < 1 )
1094
if ( empty( $media_per_page ) || $media_per_page < 1 ) {
1049
1095
$media_per_page = 20;
1052
1099
* Filter the number of items to list per page when listing media items.
1058
1105
$q['posts_per_page'] = apply_filters( 'upload_per_page', $media_per_page );
1060
1107
$post_mime_types = get_post_mime_types();
1061
$avail_post_mime_types = get_available_post_mime_types('attachment');
1063
if ( isset($q['post_mime_type']) && !array_intersect( (array) $q['post_mime_type'], array_keys($post_mime_types) ) )
1108
if ( isset($q['post_mime_type']) && !array_intersect( (array) $q['post_mime_type'], array_keys($post_mime_types) ) ) {
1064
1109
unset($q['post_mime_type']);
1066
1112
foreach( array_keys( $post_mime_types ) as $type ) {
1067
1113
if ( isset( $q['attachment-filter'] ) && "post_mime_type:$type" == $q['attachment-filter'] ) {
1074
1120
$q['post_parent'] = 0;
1079
return array($post_mime_types, $avail_post_mime_types);
1127
* Executes a query for attachments. An array of WP_Query arguments
1128
* can be passed in, which will override the arguments set by this function.
1132
* @param array|false $q Array of query variables to use to build the query or false to use $_GET superglobal.
1135
function wp_edit_attachments_query( $q = false ) {
1136
wp( wp_edit_attachments_query_vars( $q ) );
1138
$post_mime_types = get_post_mime_types();
1139
$avail_post_mime_types = get_available_post_mime_types( 'attachment' );
1141
return array( $post_mime_types, $avail_post_mime_types );
1137
1199
$original_name = $post->post_name;
1139
1201
// Hack: get_permalink() would return ugly permalink for drafts, so we will fake that our post is published.
1140
if ( in_array( $post->post_status, array( 'draft', 'pending' ) ) ) {
1202
if ( in_array( $post->post_status, array( 'draft', 'pending', 'future' ) ) ) {
1141
1203
$post->post_status = 'publish';
1142
1204
$post->post_name = sanitize_title($post->post_name ? $post->post_name : $post->post_title, $post->ID);
1159
1221
// Handle page hierarchy
1160
1222
if ( $ptype->hierarchical ) {
1161
1223
$uri = get_page_uri($post);
1162
$uri = untrailingslashit($uri);
1163
$uri = strrev( stristr( strrev( $uri ), '/' ) );
1164
$uri = untrailingslashit($uri);
1225
$uri = untrailingslashit($uri);
1226
$uri = strrev( stristr( strrev( $uri ), '/' ) );
1227
$uri = untrailingslashit($uri);
1166
1230
/** This filter is documented in wp-admin/edit-tag-form.php */
1167
1231
$uri = apply_filters( 'editable_slug', $uri );
1231
1295
$post_name_html = '<span id="editable-post-name" title="' . $title . '">' . $post_name_abridged . '</span>';
1232
1296
$display_link = str_replace( array( '%pagename%', '%postname%' ), $post_name_html, urldecode( $permalink ) );
1297
$pretty_permalink = str_replace( array( '%pagename%', '%postname%' ), $post_name, urldecode( $permalink ) );
1234
1299
$return = '<strong>' . __( 'Permalink:' ) . "</strong>\n";
1235
1300
$return .= '<span id="sample-permalink" tabindex="-1">' . $display_link . "</span>\n";
1245
1310
$preview_link = apply_filters( 'preview_post_link', add_query_arg( 'preview', 'true', $preview_link ), $post );
1246
1311
$return .= "<span id='view-post-btn'><a href='" . esc_url( $preview_link ) . "' class='button button-small' target='wp-preview-{$post->ID}'>$view_post</a></span>\n";
1248
$return .= "<span id='view-post-btn'><a href='" . get_permalink( $post ) . "' class='button button-small'>$view_post</a></span>\n";
1313
if ( empty( $pretty_permalink ) ) {
1314
$pretty_permalink = $permalink;
1317
$return .= "<span id='view-post-btn'><a href='" . $pretty_permalink . "' class='button button-small'>$view_post</a></span>\n";
1487
1556
<div class="post-locked-avatar"></div>
1488
1557
<p class="wp-tab-first" tabindex="0">
1489
1558
<span class="currently-editing"></span><br />
1490
<span class="locked-saving hidden"><img src="images/wpspin_light-2x.gif" width="16" height="16" /> <?php _e('Saving revision...'); ?></span>
1559
<span class="locked-saving hidden"><img src="<?php echo esc_url( admin_url( 'images/spinner-2x.gif' ) ); ?>" width="16" height="16" /> <?php _e('Saving revision...'); ?></span>
1491
1560
<span class="locked-saved hidden"><?php _e('Your latest changes were saved as a revision.'); ?></span>
1604
1673
$is_autosave = true;
1606
if ( 'auto-draft' == $_POST['post_status'] )
1675
if ( isset( $_POST['post_status'] ) && 'auto-draft' == $_POST['post_status'] )
1607
1676
$_POST['post_status'] = 'draft';
1609
1678
$saved_post_id = wp_create_post_autosave( $post->ID );