使WordPress成为核心

变更集57580


忽略:
时间戳:
2024年9月2日下午07:48:41(4个月(之前)
作者:
乔多尔森
消息:

快速/批量编辑:预先填充类别字段及其状态。

快速/批量编辑表单中的预填充类别字段及其当前状态。

批量编辑时,如果只有某些选定项目位于给定类别中,则该类别的复选框将显示一行以指示不确定状态。

最初提交于[56172],但由于删除了所有类别的错误而恢复。更新的提交修复了错误,添加了单元测试,并提高了不确定状态复选框的可访问性。

Props pavelevap、scru、chasedsiedu、helen、joshcanhelp、ubernaut、Cyberchink、laumindproductscomau、SergeyBiryukov、Marcevich、tomybyte、thinkluke、virtality-marketing-solutions、Michalooki、dmsnell、itecrs、pannelars、WHSajid、samba45、Mte90、johnbillion、tomluckies、soulseekah、francina、oglekler、ajmcfadyen、mukesh27、costdev、,hellofromTonya、peterwilsoncc、joedolson、pbiron、oglekler、webcommsat、jorbin、ajmcfadyen、huzaifaalmesbah。
修复#11302.

地点:
大旅行箱
文件夹:
4编辑

图例:

未修改
补充
远离的
  • trunk/src/js/_enqueues/admin/inline-edit-post.js

    r57093号 57580兰特  
    179179setBulk:函数(){
    180180var te=“”,type=this.type,c=true;
     181var checkedPosts=$('tbody th.check-column input[type=“checkbox”]:checked');
     182var类别={};
    181183this.revert();
    182184
     
    217219//填充要批量编辑的项目列表。
    218220$('#bulk-titles').html('<ul id=“bulk-ttles-list”role=“list”>'+te+'</ul>');
     221
     222//收集一些统计信息,了解这些检查过的帖子中哪些属于哪些类别。
     223checkedPosts.each(函数(){
     224var id=$(this).val();
     225var checked=$('#category_'+id).text().split(',');
     226
     227checked.map(函数(cid){
     228categories[cid]||(categories[cid]=0);
     229//只需记录该类别已被选中。
     230类别[cid]++;
     231            } );
     232        } );
     233
     234//计算初始状态。
     235$('.inline-edit-categories input[name=“post_category[]”]').each(function(){
     236if(类别[$(this).val()]==checkedPosts.length){
     237//如果选中的类别数与选中的帖子数相匹配,则所有帖子都在该类别中。
     238$(this).prop('checked',true);
     239}else if(类别[$(this).val()]>0){
     240//如果数量小于所选帖子的数量,则不确定。
     241$(this).prop('unterminate',true);
     242if(!$(this).parent().find('输入[名称=“unterminate_post_category[]”]).length){
     243//获取术语标签文本。
     244var标签=$(this).parent().text();
     245//为后端设置不确定状态。为不确定输入添加可访问的文本。
     246$(this).after('<input type=“hidden”name=“unterminate_post_category[]”value=“'+$(this).val()+'”>').attr('aria-label',label.trim()+'':'+wp.i18n__('一些选定的帖子具有此类别');
     247                }
     248            }
     249        } );
     250
     251$('.inline-edit-categories input[name=“post_category[]”]:不确定').on('change',function(){
     252//删除可访问的标签文本。删除不确定标志,因为存在特定的状态更改。
     253$(this).removeAttr('aria-label').parent().find('input[name=“unterminate_post_category[]”]').remov();
     254        } );
     255
     256$('.inline-edit-save按钮').on('click',function(){
     257$('.inline-edit-categories input[name=“post_category[]”]').prop('unterminate',false);
     258        } );
    219259
    220260        /**
  • trunk/src/wp-admin/css/list-tables.css

    57553兰特 57580兰特  
    11501150}
    11511151
     1152ul.cat-checklist输入[name=“post_category[]”]:不确定::之前{
     1153内容:“”;
     1154边框顶部:2 x纯灰色;
     1155宽度:65%;
     1156高度:2px;
     1157位置:绝对;
     1158顶部:计算值(50%+1px);
     1159左:50%;
     1160转换:转换(-50%,-50%);
     1161}
     1162
    11521163#散货。ntdelbutton,
    11531164#散货。ntdeltitle,
  • trunk/src/wp-admin/includes/post.php

    57521兰特 57580兰特  
    650650
    651651if(isset($newcats)&&in_array('类别',$tax_names,true)){
    652 $cats=(数组)wp_get_post_categories($post_id);
    653 $post_data['post_category']=数组唯一(数组合并($cats,$new_cats));
     652$cats=(数组)wp_get_post_categories($post_id);
     653
     654如果(
     655isset($post_data['indetermente_post_category'])
     656&&is_array($post_data['indetement_post_category'])
     657){
     658$unterminate_post_category=$post_data['indetermine_post_category'];
     659}其他{
     660$unterminate_post_category=数组();
     661            }
     662
     663$unterminate_cats=array_intersect($cats,$interminate_post_category);
     664$determine_cats=array_diff($new_cats,$unterminate_post_category);
     665$post_data['post_category']=数组唯一(数组合并($unterminate_cats,$determinate_cats));
     666
    654667取消设置($post_data['tax_input']['category']);
    655668}
  • trunk/tests/phpunit/tests/admin/includesPost.php

    57068兰特 57580兰特  
    383383$this->assertSame('aside',get_post_format($post_id));
    384384}
     385}
     386
     387    /**
     388*@门票11302
     389     */
     390公共函数test_bulk_edit_if_categories_unchanged(){
     391wp_set_current_user(自身::$admin_id);
     392
     393$post_ids=self::factory()->post->create_many(3);
     394
     395wp_set_post_categories($post_ids[0],数组(“test1”,“test2”);
     396wp_set_post_categories($post_ids[1],数组(“test2”,“test3”);
     397wp_set_post_categories($post_ids[2],数组('test1','test3'));
     398
     399$terms1=wp_get_post_categories($post_ids[0]);
     400$terms2=wp_get_post_categories($post_ids[1]);
     401$terms3=wp_get_post_categories($post_ids[2]);
     402
     403$unterminate_categories=array_merge($terms1、$terms2和$terms3);
     404
     405$request=数组(
     406“_状态”=>-1,
     407“帖子”=>$post_id,
     408“unterminate_post_category”=>$unterminite_categories,
     409);
     410
     411bulk_edit_posts($request);
     412
     413$updated_terms1=wp_get_post_categories($post_ids[0]);
     414$updated_terms2=wp_get_post_categories($post_ids[1]);
     415$updated_terms3=wp_get_post_categories($post_ids[2]);
     416
     417$this->assertSame($terms1,$updated_terms1,‘Post 1应该有terms 1和2’);
     418$this->assertSame($terms2,$updated_terms2,‘Post 2应该有术语2和3。’);
     419$this->assertSame($terms3,$updated_terms3,‘Post 3应该有术语1和3’);
     420}
     421
     422    /**
     423*@门票11302
     424     */
     425公共函数test_bulk_edit_if_some_categories_added(){
     426wp_set_current_user(自身::$admin_id);
     427
     428$post_ids=self::factory()->post->create_many(3);
     429$term1=wp_create_category('test1');
     430$term2=wp_create_category('test2');
     431$term3=wp_create_category('test3');
     432$term4=wp_create_category('test4');
     433
     434wp_set_post_categories($post_ids[0],数组($term1,$term2));
     435wp_set_post_categories($post_ids[1],数组($term2,$term3));
     436wp_set_post_categories($post_ids[2],数组($term1,$term3));
     437
     438$terms1=wp_get_post_categories($post_ids[0],数组(“字段”=>“ids”);
     439$terms2=wp_get_post_categories($post_ids[1],数组('fields'=>'ids'));
     440$terms3=wp_get_post_categories($post_ids[2],数组('fields'=>'ids'));
     441//所有现有类别都是不确定的。
     442$unterminate=数组唯一(数组合并($terms1、$terms2、$terms));
     443//添加新类别。
     444$categories[]=$term4;
     445
     446$request=数组(
     447“_状态”=>-1,
     448“帖子”=>$post_id,
     449“post_category”=>$categories,
     450“unterminate_post_category”=>$unterminete,
     451);
     452
     453bulk_edit_posts($request);
     454
     455$updated_terms1=wp_get_post_categories($post_ids[0],数组(“字段”=>“id”);
     456$updated_terms2=wp_get_post_categories($post_ids[1],数组('fields'=>'ids'));
     457$updated_terms3=wp_get_post_categories($post_ids[2],数组('fields'=>'ids'));
     458
     459//每个帖子的类别应与之前相同,并添加术语4。
     460$this->assertSame(数组($term1、$term2、$term4),$updated_terms1,“帖子应该有词条1、2和4”);
     461$this->assertSame(数组($term2、$term3、$term4),$updated_terms2,‘帖子应该有术语2、3和4。’);
     462$this->assertSame(数组($term1、$term3、$term 4),$updated_terms3,“帖子应该有词条1、3和4。”);
     463}
     464
     465    /**
     466*@门票11302
     467     */
     468公共函数test_bulk_edit_if_some_categories_removed(){
     469wp_set_current_user(自身::$admin_id);
     470
     471$post_ids=self::factory()->post->create_many(3);
     472$term1=wp_create_category('test1');
     473$term2=wp_create_category('test2');
     474$term3=wp_create_category('test3');
     475
     476wp_set_post_categories($post_ids[0],数组($term1,$term2));
     477wp_set_post_categories($post_ids[1],数组($term2,$term3));
     478wp_set_post_categories($post_ids[2],数组($term1,$term3));
     479
     480$terms1=wp_get_post_categories($post_ids[0],数组(“字段”=>“ids”);
     481$terms2=wp_get_post_categories($post_ids[1],数组('fields'=>'ids'));
     482$terms3=wp_get_post_categories($post_ids[2],数组('fields'=>'ids'));
     483
     484//第2和第3项处于不确定状态。
     485$unterminate=数组($term2,$term3);
     486//从所选类别中删除术语1。
     487$categories=数组唯一(array_merge($terms1、$terms2和$terms3));
     488$remove_key=数组搜索($term1,$categories,true);
     489取消设置($categories[$removekey]);
     490
     491$request=数组(
     492“_状态”=>-1,
     493“帖子”=>$post_id,
     494“post_category”=>$categories,
     495“unterminate_post_category”=>$unterminete,
     496);
     497
     498bulk_edit_posts($request);
     499
     500$updated_terms1=wp_get_post_categories($post_ids[0],数组('fields'=>'ids'));
     501$updated_terms2=wp_get_post_categories($post_ids[1],数组(“字段”=>“id”));
     502$updated_terms3=wp_get_post_categories($post_ids[2],数组('fields'=>'ids'));
     503
     504//帖子1应该只有术语2。
     505$this->assertSame($updated_terms1,array($term2),“Post 1应该只有term 2”);
     506//岗位2应保持不变。
     507$this->assertSame($terms2,$updated_terms2,‘Post 2 should be unchanged.’);
     508//帖子3应该只有术语3。
     509$this->assertSame($updated_terms3,array($term3),‘Post 3应该只有term 3’);
    385510}
    386511
注:请参见TracChangeset(跟踪变更集)获取有关使用变更集查看器的帮助。