From 52f05426e07b5a26d6394e815d3e6e69496ebac9 Mon Sep 17 00:00:00 2001 From: ryan Date: Tue, 25 May 2010 02:18:07 +0000 Subject: [PATCH] Allow searching custom post types when attaching media. Props markoheijnen. fixes #13229 git-svn-id: http://svn.automattic.com/wordpress/trunk@14869 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/admin-ajax.php | 12 +++++++++--- wp-admin/includes/template.php | 14 ++++++++++---- wp-admin/js/media.dev.js | 9 ++++----- wp-admin/js/media.js | 2 +- wp-includes/script-loader.php | 2 +- 5 files changed, 25 insertions(+), 14 deletions(-) diff --git a/wp-admin/admin-ajax.php b/wp-admin/admin-ajax.php index c0d01d5d2a..a31b153f2b 100644 --- a/wp-admin/admin-ajax.php +++ b/wp-admin/admin-ajax.php @@ -1254,7 +1254,11 @@ case 'find_posts': if ( empty($_POST['ps']) ) exit; - $what = isset($_POST['pages']) ? 'page' : 'post'; + if ( !empty($_POST['post_type']) && in_array( $_POST['post_type'], get_post_types() ) ) + $what = $_POST['post_type']; + else + $what = 'post'; + $s = stripslashes($_POST['ps']); preg_match_all('/".*?("|$)|((?<=[\\s",+])|^)[^\\s",+]+/', $s, $matches); $search_terms = array_map('_search_terms_tidy', $matches[0]); @@ -1271,8 +1275,10 @@ case 'find_posts': $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" ); - if ( ! $posts ) - exit( __('No posts found.') ); + if ( ! $posts ) { + $posttype = get_post_type_object($what); + exit($posttype->labels->not_found); + } $html = ''; foreach ( $posts as $post ) { diff --git a/wp-admin/includes/template.php b/wp-admin/includes/template.php index ff8c22ae7f..6f3272a6ce 100644 --- a/wp-admin/includes/template.php +++ b/wp-admin/includes/template.php @@ -3275,10 +3275,16 @@ function find_posts_div($found_action = '') {
- - - - + true), 'objects' ); + foreach ( $post_types as $post ) { + if ( 'attachment' == $post->name ) + continue; + ?> + name, 'post'); ?> /> + +
diff --git a/wp-admin/js/media.dev.js b/wp-admin/js/media.dev.js index 7c6f4d2725..92749daeac 100644 --- a/wp-admin/js/media.dev.js +++ b/wp-admin/js/media.dev.js @@ -31,11 +31,10 @@ var findPosts; _ajax_nonce: $('#_ajax_nonce').val() }; - if ( $('#find-posts-pages').is(':checked') ) { - post['pages'] = 1; - } else { - post['posts'] = 1; - } + var selectedItem; + $("input[@name='itemSelect[]']:checked").each(function() { selectedItem = $(this).val() }); + post['post_type'] = selectedItem; + $.ajax({ type : 'POST', url : ajaxurl, diff --git a/wp-admin/js/media.js b/wp-admin/js/media.js index 4818f81bfe..4d338a413a 100644 --- a/wp-admin/js/media.js +++ b/wp-admin/js/media.js @@ -1 +1 @@ -var findPosts;(function(a){findPosts={open:function(d,c){var b=document.documentElement.scrollTop||a(document).scrollTop();if(d&&c){a("#affected").attr("name",d).val(c)}a("#find-posts").show().draggable({handle:"#find-posts-head"}).css({top:b+50+"px",left:"50%",marginLeft:"-250px"});a("#find-posts-input").focus().keyup(function(f){if(f.which==27){findPosts.close()}});return false},close:function(){a("#find-posts-response").html("");a("#find-posts").draggable("destroy").hide()},send:function(){var b={ps:a("#find-posts-input").val(),action:"find_posts",_ajax_nonce:a("#_ajax_nonce").val()};if(a("#find-posts-pages").is(":checked")){b.pages=1}else{b.posts=1}a.ajax({type:"POST",url:ajaxurl,data:b,success:function(c){findPosts.show(c)},error:function(c){findPosts.error(c)}})},show:function(b){if(typeof(b)=="string"){this.error({responseText:b});return}var c=wpAjax.parseAjaxResponse(b);if(c.errors){this.error({responseText:wpAjax.broken})}c=c.responses[0];a("#find-posts-response").html(c.data)},error:function(b){var c=b.statusText;if(b.responseText){c=b.responseText.replace(/<.[^<>]*?>/g,"")}if(c){a("#find-posts-response").html(c)}}};a(document).ready(function(){a("#find-posts-submit").click(function(b){if(""==a("#find-posts-response").html()){b.preventDefault()}});a("#doaction, #doaction2").click(function(b){a('select[name^="action"]').each(function(){if(a(this).val()=="attach"){b.preventDefault();findPosts.open()}})})})})(jQuery); \ No newline at end of file +var findPosts;(function(a){findPosts={open:function(d,c){var b=document.documentElement.scrollTop||a(document).scrollTop();if(d&&c){a("#affected").attr("name",d).val(c)}a("#find-posts").show().draggable({handle:"#find-posts-head"}).css({top:b+50+"px",left:"50%",marginLeft:"-250px"});a("#find-posts-input").focus().keyup(function(f){if(f.which==27){findPosts.close()}});return false},close:function(){a("#find-posts-response").html("");a("#find-posts").draggable("destroy").hide()},send:function(){var b={ps:a("#find-posts-input").val(),action:"find_posts",_ajax_nonce:a("#_ajax_nonce").val()};var c;a("input[@name='itemSelect[]']:checked").each(function(){c=a(this).val()});b.post_type=c;a.ajax({type:"POST",url:ajaxurl,data:b,success:function(d){findPosts.show(d)},error:function(d){findPosts.error(d)}})},show:function(b){if(typeof(b)=="string"){this.error({responseText:b});return}var c=wpAjax.parseAjaxResponse(b);if(c.errors){this.error({responseText:wpAjax.broken})}c=c.responses[0];a("#find-posts-response").html(c.data)},error:function(b){var c=b.statusText;if(b.responseText){c=b.responseText.replace(/<.[^<>]*?>/g,"")}if(c){a("#find-posts-response").html(c)}}};a(document).ready(function(){a("#find-posts-submit").click(function(b){if(""==a("#find-posts-response").html()){b.preventDefault()}});a("#doaction, #doaction2").click(function(b){a('select[name^="action"]').each(function(){if(a(this).val()=="attach"){b.preventDefault();findPosts.open()}})})})})(jQuery); \ No newline at end of file diff --git a/wp-includes/script-loader.php b/wp-includes/script-loader.php index 3a14267299..f67141636e 100644 --- a/wp-includes/script-loader.php +++ b/wp-includes/script-loader.php @@ -369,7 +369,7 @@ function wp_default_scripts( &$scripts ) { $scripts->add( 'list-revisions', "/wp-includes/js/wp-list-revisions$suffix.js", null, '20091223' ); - $scripts->add( 'media', "/wp-admin/js/media$suffix.js", array( 'jquery-ui-draggable' ), '20090415' ); + $scripts->add( 'media', "/wp-admin/js/media$suffix.js", array( 'jquery-ui-draggable' ), '20100524' ); $scripts->add_data( 'media', 'group', 1 ); $scripts->add( 'image-edit', "/wp-admin/js/image-edit$suffix.js", array('jquery', 'json2', 'imgareaselect'), '20091111' );

'.__('Title').''.__('Date').''.__('Status').'