WordPress.org

Make WordPress Core

Ticket #13229: 13229-2.diff

File 13229-2.diff, 5.6 KB (added by markoheijnen, 5 years ago)

use function get_post_types. Changed post type var media_add to attachment. Also add comment line for the attachment var for post type. Still need to look for futher implementation.

Line 
1Index: wp-includes/post.php
2===================================================================
3--- wp-includes/post.php        (revision 14447)
4+++ wp-includes/post.php        (working copy)
5@@ -26,6 +26,7 @@
6                'hierarchical' => false,
7                'rewrite' => false,
8                'query_var' => false,
9+               'attachment' => true,
10                'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'trackbacks', 'custom-fields', 'comments', 'revisions' ),
11        ) );
12 
13@@ -40,6 +41,7 @@
14                'hierarchical' => true,
15                'rewrite' => false,
16                'query_var' => false,
17+               'attachment' => true,
18                'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'page-attributes', 'custom-fields', 'comments', 'revisions' ),
19        ) );
20 
21@@ -795,6 +797,7 @@
22  * supports - An alias for calling add_post_type_support() directly. See add_post_type_support() for Documentation. Defaults to none.
23  * register_meta_box_cb - Provide a callback function that will be called when setting up the meta boxes for the edit form.  Do remove_meta_box() and add_meta_box() calls in the callback.
24  * taxonomies - An array of taxonomy identifiers that will be registered for the post type.  Default is no taxonomies. Taxonomies can be registered later with register_taxonomy() or register_taxonomy_for_object_type().
25+ * attachment - Whether to add attachments to this post type. Defaults to false.
26  *
27  * @package WordPress
28  * @subpackage Post
29@@ -811,7 +814,7 @@
30                $wp_post_types = array();
31 
32        // Args prefixed with an underscore are reserved for internal use.
33-       $defaults = array('label' => false, 'singular_label' => false, 'description' => '', 'publicly_queryable' => null, 'exclude_from_search' => null, '_builtin' => false, '_edit_link' => 'post.php?post=%d', 'capability_type' => 'post', 'hierarchical' => false, 'public' => false, 'rewrite' => true, 'query_var' => true, 'supports' => array(), 'register_meta_box_cb' => null, 'taxonomies' => array(), 'show_ui' => null, 'menu_position' => null, 'menu_icon' => null, 'permalink_epmask' => EP_PERMALINK, 'can_export' => true );
34+       $defaults = array('label' => false, 'singular_label' => false, 'description' => '', 'publicly_queryable' => null, 'exclude_from_search' => null, '_builtin' => false, '_edit_link' => 'post.php?post=%d', 'capability_type' => 'post', 'hierarchical' => false, 'public' => false, 'rewrite' => true, 'query_var' => true, 'supports' => array(), 'register_meta_box_cb' => null, 'taxonomies' => array(), 'show_ui' => null, 'menu_position' => null, 'menu_icon' => null, 'permalink_epmask' => EP_PERMALINK, 'can_export' => true, 'attachment' => false );
35        $args = wp_parse_args($args, $defaults);
36        $args = (object) $args;
37Index: wp-admin/admin-ajax.php
38===================================================================
39--- wp-admin/admin-ajax.php     (revision 14447)
40+++ wp-admin/admin-ajax.php     (working copy)
41@@ -1253,7 +1253,12 @@
42        if ( empty($_POST['ps']) )
43                exit;
44 
45-       $what = isset($_POST['pages']) ? 'page' : 'post';
46+       if(!empty($_POST['post_type']) && in_array($_POST['post_type'], get_post_types(array('attachment' => true)))) {
47+               $what = $_POST['post_type'];
48+       } else {
49+               $what = 'post';
50+       }
51+
52        $s = stripslashes($_POST['ps']);
53        preg_match_all('/".*?("|$)|((?<=[\\s",+])|^)[^\\s",+]+/', $s, $matches);
54        $search_terms = array_map('_search_terms_tidy', $matches[0]);
55@@ -1271,7 +1276,7 @@
56        $posts = $wpdb->get_results( "SELECT ID, post_title, post_status, post_date FROM $wpdb->posts WHERE post_type = '$what' AND post_status IN ('draft', 'publish') AND ($search) ORDER BY post_date_gmt DESC LIMIT 50" );
57 
58        if ( ! $posts )
59-               exit( __('No posts found.') );
60+               exit( __('No '. $what .' found.') );
61 
62        $html = '<table class="widefat" cellspacing="0"><thead><tr><th class="found-radio"><br /></th><th>'.__('Title').'</th><th>'.__('Date').'</th><th>'.__('Status').'</th></tr></thead><tbody>';
63        foreach ( $posts as $post ) {
64Index: wp-admin/includes/template.php
65===================================================================
66--- wp-admin/includes/template.php      (revision 14447)
67+++ wp-admin/includes/template.php      (working copy)
68@@ -3284,10 +3284,16 @@
69                                <input type="text" id="find-posts-input" name="ps" value="" />
70                                <input type="button" onclick="findPosts.send();" value="<?php esc_attr_e( 'Search' ); ?>" class="button" /><br />
71 
72-                               <input type="radio" name="find-posts-what" id="find-posts-posts" checked="checked" value="posts" />
73-                               <label for="find-posts-posts"><?php _e( 'Posts' ); ?></label>
74-                               <input type="radio" name="find-posts-what" id="find-posts-pages" value="pages" />
75-                               <label for="find-posts-pages"><?php _e( 'Pages' ); ?></label>
76+                               <?php
77+                               $selected = 'checked="checked" ';
78+                               $post_types = get_post_types(array('attachment' => true), 'objects');
79+                               foreach ($post_types AS $post) {
80+                               ?>
81+                               <input type="radio" name="find-posts-what" id="find-posts-<?php echo $post->name; ?>" value="<?php echo $post->name; ?>" <?php echo $selected?>/>
82+                               <label for="find-posts-<?php echo $post->name; ?>"><?php echo $post->label; ?></label>
83+                               <?php
84+                                       $selected = '';
85+                               } ?>
86                        </div>
87                        <div id="find-posts-response"></div>
88                </div>
89Index: wp-admin/js/media.dev.js
90===================================================================
91--- wp-admin/js/media.dev.js    (revision 14447)
92+++ wp-admin/js/media.dev.js    (working copy)
93@@ -31,11 +31,10 @@
94                                _ajax_nonce: $('#_ajax_nonce').val()
95                        };
96 
97-                       if ( $('#find-posts-pages').is(':checked') ) {
98-                               post['pages'] = 1;
99-                       } else {
100-                               post['posts'] = 1;
101-                       }
102+                       var selectedItem;
103+                       $("input[@name='itemSelect[]']:checked").each(function() { selectedItem = $(this).val() });
104+                       post['post_type'] = selectedItem;
105+
106                        $.ajax({
107                                type : 'POST',
108                                url : ajaxurl,