WordPress.org

Make WordPress Core

Changeset 14869


Ignore:
Timestamp:
05/25/2010 02:18:07 AM (10 years ago)
Author:
ryan
Message:

Allow searching custom post types when attaching media. Props markoheijnen. fixes #13229

Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/admin-ajax.php

    r14852 r14869  
    12551255        exit;
    12561256
    1257     $what = isset($_POST['pages']) ? 'page' : 'post';
     1257    if ( !empty($_POST['post_type']) && in_array( $_POST['post_type'], get_post_types() ) )
     1258        $what = $_POST['post_type'];
     1259    else
     1260        $what = 'post';
     1261
    12581262    $s = stripslashes($_POST['ps']);
    12591263    preg_match_all('/".*?("|$)|((?<=[\\s",+])|^)[^\\s",+]+/', $s, $matches);
     
    12721276    $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" );
    12731277
    1274     if ( ! $posts )
    1275         exit( __('No posts found.') );
     1278    if ( ! $posts ) {
     1279        $posttype = get_post_type_object($what);
     1280        exit($posttype->labels->not_found);
     1281    }
    12761282
    12771283    $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>';
  • trunk/wp-admin/includes/template.php

    r14859 r14869  
    32763276                <input type="button" onclick="findPosts.send();" value="<?php esc_attr_e( 'Search' ); ?>" class="button" /><br />
    32773277
    3278                 <input type="radio" name="find-posts-what" id="find-posts-posts" checked="checked" value="posts" />
    3279                 <label for="find-posts-posts"><?php _e( 'Posts' ); ?></label>
    3280                 <input type="radio" name="find-posts-what" id="find-posts-pages" value="pages" />
    3281                 <label for="find-posts-pages"><?php _e( 'Pages' ); ?></label>
     3278                <?php
     3279                $post_types = get_post_types( array('public' => true), 'objects' );
     3280                foreach ( $post_types as $post ) {
     3281                    if ( 'attachment' == $post->name )
     3282                        continue;
     3283                ?>
     3284                <input type="radio" name="find-posts-what" id="find-posts-<?php echo esc_attr($post->name); ?>" value="<?php echo esc_attr($post->name); ?>" <?php checked($post->name,  'post'); ?> />
     3285                <label for="find-posts-<?php echo esc_attr($post->name); ?>"><?php echo $post->label; ?></label>
     3286                <?php
     3287                } ?>
    32823288            </div>
    32833289            <div id="find-posts-response"></div>
  • trunk/wp-admin/js/media.dev.js

    r12196 r14869  
    3232            };
    3333
    34             if ( $('#find-posts-pages').is(':checked') ) {
    35                 post['pages'] = 1;
    36             } else {
    37                 post['posts'] = 1;
    38             }
     34            var selectedItem;
     35            $("input[@name='itemSelect[]']:checked").each(function() { selectedItem = $(this).val() });
     36            post['post_type'] = selectedItem;
     37
    3938            $.ajax({
    4039                type : 'POST',
  • trunk/wp-admin/js/media.js

    r12196 r14869  
    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);
     1var 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);
  • trunk/wp-includes/script-loader.php

    r14852 r14869  
    370370        $scripts->add( 'list-revisions', "/wp-includes/js/wp-list-revisions$suffix.js", null, '20091223' );
    371371
    372         $scripts->add( 'media', "/wp-admin/js/media$suffix.js", array( 'jquery-ui-draggable' ), '20090415' );
     372        $scripts->add( 'media', "/wp-admin/js/media$suffix.js", array( 'jquery-ui-draggable' ), '20100524' );
    373373        $scripts->add_data( 'media', 'group', 1 );
    374374
Note: See TracChangeset for help on using the changeset viewer.