PluginProbe
WPJAM Basic / trunk
WPJAM Basic vtrunk
wpjam-basic / extends / quick-excerpt.php

quick-excerpt.php in WPJAM Basic trunk, at extends/quick-excerpt.php

31 lines 1.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /*
3 Name: 摘要快速编辑
4 URI: https://mp.weixin.qq.com/s/0W73N71wNJv10kMEjbQMGw
5 Description: 后台文章列表的快速编辑支持编辑摘要。
6 Version: 1.0
7 Admin: true
8 */
9 wpjam_add_admin_load([
10 'base' => 'edit',
11 'callback' => function($screen){
12 if(post_type_supports($screen->post_type, 'excerpt')){
13 if(!wp_doing_ajax()){
14 wpjam_script(<<<'JS'
15 $('body').on('quick_edit', '#the-list', function(event, id){
16 let $edit = $('#edit-'+id);
17
18 if($('textarea[name="the_excerpt"]', $edit).length == 0){
19 $('.inline-edit-date', $edit).before('<label><span class="title">摘要</span><span class="input-text-wrap"><textarea cols="22" rows="2" name="the_excerpt"></textarea></span></label>');
20 $('textarea[name="the_excerpt"]', $edit).val($('#inline_'+id+' div.post_excerpt').text());
21 }
22 });
23 JS);
24 }
25
26 isset($_POST['the_excerpt']) && wpjam_hook('wp_insert_post_data', '+', ['post_excerpt'=>$_POST['the_excerpt']]);
27
28 wpjam_hook('add_inline_data', 'echo', fn($post)=> '<div class="post_excerpt">'.esc_textarea(trim($post->post_excerpt)).'</div>');
29 }
30 }
31 ]);