~canonical-sysadmins/wordpress/4.2.4

« back to all changes in this revision

Viewing changes to wp-admin/includes/post.php

  • Committer: Paul Gear
  • Date: 2015-04-24 01:35:20 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: paul.gear@canonical.com-20150424013520-w4p9ksth76zh6opw
Merge new upstream release 4.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
314
314
                $post_data = apply_filters( 'attachment_fields_to_save', $post_data, $attachment_data );
315
315
        }
316
316
 
 
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 ) ) {
 
322
                                continue;
 
323
                        }
 
324
 
 
325
                        /*
 
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.
 
329
                         */
 
330
                        if ( ! is_array( $terms ) ) {
 
331
                                $comma = _x( ',', 'tag delimiter' );
 
332
                                if ( ',' !== $comma ) {
 
333
                                        $terms = str_replace( $comma, ',', $terms );
 
334
                                }
 
335
                                $terms = explode( ',', trim( $terms, " \n\t\r\0\x0B," ) );
 
336
                        }
 
337
 
 
338
                        $clean_terms = array();
 
339
                        foreach ( $terms as $term ) {
 
340
                                // Empty terms are invalid input.
 
341
                                if ( empty( $term ) ) {
 
342
                                        continue;
 
343
                                }
 
344
 
 
345
                                $_term = get_terms( $taxonomy, array(
 
346
                                        'name' => $term,
 
347
                                        'fields' => 'ids',
 
348
                                        'hide_empty' => false,
 
349
                                ) );
 
350
 
 
351
                                if ( ! empty( $_term ) ) {
 
352
                                        $clean_terms[] = intval( $_term[0] );
 
353
                                } else {
 
354
                                        // No existing term was found, so pass the string. A new term will be created.
 
355
                                        $clean_terms[] = $term;
 
356
                                }
 
357
                        }
 
358
 
 
359
                        $post_data['tax_input'][ $taxonomy ] = $clean_terms;
 
360
                }
 
361
        }
 
362
 
317
363
        add_meta( $post_ID );
318
364
 
319
365
        update_post_meta( $post_ID, '_edit_last', get_current_user_id() );
733
779
//
734
780
 
735
781
/**
736
 
 * {@internal Missing Short Description}}
 
782
 * Add post meta data defined in $_POST superglobal for post with given ID.
737
783
 *
738
784
 * @since 1.2.0
739
785
 *
772
818
} // add_meta
773
819
 
774
820
/**
775
 
 * {@internal Missing Short Description}}
 
821
 * Delete post meta data by meta ID.
776
822
 *
777
823
 * @since 1.2.0
778
824
 *
803
849
}
804
850
 
805
851
/**
806
 
 * {@internal Missing Short Description}}
 
852
 * Get post meta data by meta ID.
807
853
 *
808
854
 * @since 2.1.0
809
855
 *
815
861
}
816
862
 
817
863
/**
818
 
 * {@internal Missing Short Description}}
819
 
 *
820
 
 * Some postmeta stuff.
 
864
 * Get meta data for the given post ID.
821
865
 *
822
866
 * @since 1.2.0
823
867
 *
833
877
}
834
878
 
835
879
/**
836
 
 * {@internal Missing Short Description}}
 
880
 * Update post meta data by meta ID.
837
881
 *
838
882
 * @since 1.2.0
839
883
 *
995
1039
                $query['order'] = 'asc';
996
1040
                $query['posts_per_page'] = -1;
997
1041
                $query['posts_per_archive_page'] = -1;
 
1042
                $query['fields'] = 'id=>parent';
998
1043
        }
999
1044
 
1000
1045
        if ( ! empty( $q['show_sticky'] ) )
1006
1051
}
1007
1052
 
1008
1053
/**
1009
 
 * {@internal Missing Short Description}}
 
1054
 * Get all available post MIME types for a given post type.
1010
1055
 *
1011
1056
 * @since 2.5.0
1012
1057
 *
1021
1066
}
1022
1067
 
1023
1068
/**
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.
1026
 
 *
1027
 
 * @since 2.5.0
1028
 
 *
1029
 
 * @param array|bool $q Array of query variables to use to build the query or false to use $_GET superglobal.
1030
 
 * @return array
 
1069
 * Get the query variables for the current attachments request.
 
1070
 *
 
1071
 * @since 4.2.0
 
1072
 *
 
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.
1031
1076
 */
1032
 
function wp_edit_attachments_query( $q = false ) {
1033
 
        if ( false === $q )
 
1077
function wp_edit_attachments_query_vars( $q = false ) {
 
1078
        if ( false === $q ) {
1034
1079
                $q = $_GET;
1035
 
 
 
1080
        }
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';
 
1088
        }
1043
1089
 
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;
1046
1092
 
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;
 
1096
        }
1050
1097
 
1051
1098
        /**
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 );
1059
1106
 
1060
1107
        $post_mime_types = get_post_mime_types();
1061
 
        $avail_post_mime_types = get_available_post_mime_types('attachment');
1062
 
 
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']);
 
1110
        }
1065
1111
 
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;
1075
1121
        }
1076
1122
 
1077
 
        wp( $q );
1078
 
 
1079
 
        return array($post_mime_types, $avail_post_mime_types);
 
1123
        return $q;
 
1124
}
 
1125
 
 
1126
/**
 
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.
 
1129
 *
 
1130
 * @since 2.5.0
 
1131
 *
 
1132
 * @param array|false $q Array of query variables to use to build the query or false to use $_GET superglobal.
 
1133
 * @return array
 
1134
 */
 
1135
function wp_edit_attachments_query( $q = false ) {
 
1136
        wp( wp_edit_attachments_query_vars( $q ) );
 
1137
 
 
1138
        $post_mime_types = get_post_mime_types();
 
1139
        $avail_post_mime_types = get_available_post_mime_types( 'attachment' );
 
1140
 
 
1141
        return array( $post_mime_types, $avail_post_mime_types );
1080
1142
}
1081
1143
 
1082
1144
/**
1137
1199
        $original_name = $post->post_name;
1138
1200
 
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);
1143
1205
        }
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);
 
1224
                if ( $uri ) {
 
1225
                        $uri = untrailingslashit($uri);
 
1226
                        $uri = strrev( stristr( strrev( $uri ), '/' ) );
 
1227
                        $uri = untrailingslashit($uri);
 
1228
                }
1165
1229
 
1166
1230
                /** This filter is documented in wp-admin/edit-tag-form.php */
1167
1231
                $uri = apply_filters( 'editable_slug', $uri );
1230
1294
 
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 ) );
1233
1298
 
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";
1247
1312
                } else {
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;
 
1315
                        }
 
1316
 
 
1317
                        $return .= "<span id='view-post-btn'><a href='" . $pretty_permalink . "' class='button button-small'>$view_post</a></span>\n";
1249
1318
                }
1250
1319
        }
1251
1320
 
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>
1492
1561
                        </p>
1493
1562
                        <?php
1603
1672
        } else {
1604
1673
                $is_autosave = true;
1605
1674
 
1606
 
                if ( 'auto-draft' == $_POST['post_status'] )
 
1675
                if ( isset( $_POST['post_status'] ) && 'auto-draft' == $_POST['post_status'] )
1607
1676
                        $_POST['post_status'] = 'draft';
1608
1677
 
1609
1678
                $saved_post_id = wp_create_post_autosave( $post->ID );