Changeset 3238453
- Timestamp:
- 02/11/2025 09:38:07 AM (14 months ago)
- Location:
- wpjam-basic/trunk
- Files:
-
- 4 edited
-
includes/class-wpjam-admin.php (modified) (2 diffs)
-
includes/class-wpjam-list-table.php (modified) (7 diffs)
-
static/script.js (modified) (5 diffs)
-
wpjam-basic.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
wpjam-basic/trunk/includes/class-wpjam-admin.php
r3236921 r3238453 851 851 852 852 public function render(){ 853 $tag = wpjam_tag(($this->tab_page ? 'h2' : 'h1'), ['wp-heading-inline'], ($this->page_title ?? $this->title)); 854 $tag = $tag->after([ 855 $this->function == 'list_table' ? "\n".wpjam_tag('a', ['page-title-action'], '') : '', 856 "\n".wpjam_tag('hr', ['wp-header-end']) 857 ]); 858 859 $summary = $this->summary; 860 861 if($summary){ 853 $tag = wpjam_tag('h1', ['wp-heading-inline'], ($this->page_title ?? $this->title))->after('hr', ['wp-header-end']); 854 855 if($summary = $this->summary){ 862 856 if(is_callable($summary)){ 863 857 $summary = $summary(...$this->cb_args); … … 888 882 889 883 if($this->tab_page){ 890 return $tag ;884 return $tag->tag('h2'); 891 885 } 892 886 -
wpjam-basic/trunk/includes/class-wpjam-list-table.php
r3238028 r3238453 77 77 78 78 wpjam_add_item('page_setting', 'list_table', fn()=> $this->get_setting()); 79 wpjam_add_item('page_setting', 'page_title_action', fn()=> $this->get_row_action('add', ['class'=>'page-title-action']) ?: ''); 79 80 80 81 wpjam_map([ … … 83 84 'sortable_columns' => 'manage_'.$screen->id.'_sortable_columns' 84 85 ], fn($filter, $key)=> add_filter($filter, fn($value)=> array_merge($value, $this->$key ?: []))); 85 86 if(!wp_doing_ajax()){87 $page_title_action = $this->layout == 'left' ? '' : $this->get_row_action('add', ['class'=>'page-title-action']);88 89 if($page_title_action || !$this->builtin){90 add_filter('wpjam_html', fn($html)=> preg_replace('/<a[^>]*class="page-title-action">[^>]*<\/a>/i', ($page_title_action ?: ''), $html));91 }92 }93 86 94 87 $this->_args = array_merge($this->_args, $args); … … 739 732 }elseif($key == 'response'){ 740 733 return ($this->overall && $this->name != 'add') ? 'list' : $this->name; 741 }elseif($key == 'overall'){742 return $this->name == 'add' && $this->layout == 'left';743 734 }elseif($key == 'row_action'){ 744 735 return ($this->bulk !== 'only' && $this->name != 'add'); … … 1298 1289 wpjam_map(wpjam_slice($args, ['data_type', 'meta_type']), fn($v, $k)=> $screen->add_option($k, $v)); 1299 1290 1300 if(!wp_is_json_request()){1301 add_filter('wpjam_html', [$this, 'filter_display']);1302 }1303 1304 1291 add_filter('manage_'.$screen->id.'_columns', fn($columns)=> wpjam_add_at($columns, -1, $this->get_columns())); 1305 1292 … … 1316 1303 } 1317 1304 1305 if(!wp_is_json_request()){ 1306 add_filter('wpjam_html', [$this, 'filter_display']); 1307 } 1308 1318 1309 parent::__construct($args); 1319 1310 } … … 1347 1338 $this->prepare_items_by_builtin(); 1348 1339 } 1349 }1350 1351 public function filter_custom_column(...$args){1352 $value = $this->get_column_value(...array_reverse($args));1353 1354 return count($args) == 2 ? wpjam_echo($value) : $value;1355 }1356 1357 public function on_parse_query($query){1358 if(array_any(debug_backtrace(), fn($v)=> wpjam_get($v, 'class') == $this->builtin)){1359 $vars = &$query->query_vars;1360 $by = $vars['orderby'] ?? '';1361 $object = ($by && is_string($by)) ? $this->get_object($by, 'column') : null;1362 $type = $object ? ($object->sortable === true ? 'meta_value' : $object->sortable) : '';1363 $vars = array_merge($vars, ['list_table_query'=>true], in_array($type, ['meta_value_num', 'meta_value']) ? ['orderby'=>$type, 'meta_key'=>$by] : []);1364 }1365 }1366 1367 public function filter_row_actions($actions, $item){1368 $id = $item->{$this->primary_key};1369 $actions = wpjam_except($actions, $this->get_removed('action'));1370 $actions += wpjam_filter($this->get_row_actions($id), fn($v, $k)=> $v && $this->filter_row_action($this->get_object($k), $item));1371 $actions += wpjam_pull($actions, ['delete', 'trash', 'spam', 'remove', 'view'])+['id'=>'ID: '.$id];1372 1373 return $actions;1374 }1375 1376 protected function filter_row_action($object, $item){1377 if($this->data_type == 'post_type'){1378 return wpjam_compare(get_post_status($item), ...($object->post_status ? [$object->post_status] : ['!=', 'trash']));1379 }elseif($this->data_type == 'user'){1380 return (is_null($object->roles) || array_intersect($user->roles, (array)$object->roles));1381 }1382 1383 return true;1384 1340 } 1385 1341 … … 1415 1371 } 1416 1372 1373 public function filter_custom_column(...$args){ 1374 $value = $this->get_column_value(...array_reverse($args)); 1375 1376 return count($args) == 2 ? wpjam_echo($value) : $value; 1377 } 1378 1379 public function on_parse_query($query){ 1380 if(array_any(debug_backtrace(), fn($v)=> wpjam_get($v, 'class') == $this->builtin)){ 1381 $vars = &$query->query_vars; 1382 $by = $vars['orderby'] ?? ''; 1383 $object = ($by && is_string($by)) ? $this->get_object($by, 'column') : null; 1384 $type = $object ? ($object->sortable === true ? 'meta_value' : $object->sortable) : ''; 1385 $vars = array_merge($vars, ['list_table_query'=>true], in_array($type, ['meta_value_num', 'meta_value']) ? ['orderby'=>$type, 'meta_key'=>$by] : []); 1386 } 1387 } 1388 1389 public function filter_row_actions($actions, $item){ 1390 $id = $item->{$this->primary_key}; 1391 $actions = wpjam_except($actions, $this->get_removed('action')); 1392 $actions += wpjam_filter($this->get_row_actions($id), fn($v, $k)=> $v && $this->filter_row_action($this->get_object($k), $item)); 1393 $actions += wpjam_pull($actions, ['delete', 'trash', 'spam', 'remove', 'view'])+['id'=>'ID: '.$id]; 1394 1395 return $actions; 1396 } 1397 1398 protected function filter_row_action($object, $item){ 1399 if($this->data_type == 'post_type'){ 1400 return wpjam_compare(get_post_status($item), ...($object->post_status ? [$object->post_status] : ['!=', 'trash'])); 1401 }elseif($this->data_type == 'user'){ 1402 return (is_null($object->roles) || array_intersect($user->roles, (array)$object->roles)); 1403 } 1404 1405 return true; 1406 } 1407 1417 1408 public static function load($screen){ 1418 1409 return new static($screen); -
wpjam-basic/trunk/static/script.js
r3236921 r3238453 483 483 if($('#notice_modal').length){ 484 484 this.add_modal('notice_modal'); 485 } 486 487 if(this.page_title_action){ 488 $('a.page-title-action').remove(); 489 490 $('.wp-heading-inline').last().after(this.page_title_action || ''); 485 491 } 486 492 … … 910 916 let id = $el.attr('id'); 911 917 912 if(['doaction', 'doaction2' , 'bulk-action-selector-top', 'bulk-action-selector-bottom'].includes(id)){913 let $select = $el. is('select') ? $el : $el.prev('select');918 if(['doaction', 'doaction2'].includes(id)){ 919 let $select = $el.prev('select'); 914 920 let name = $select.val(); 915 921 let ids = $form.find('th.check-column input[type="checkbox"]:checked').toArray().map(cb => cb.value); … … 926 932 } 927 933 }else if(wpjam.ajax_list_action !== false){ 928 if($form.wpjam_validity()){ 929 $form.wpjam_query(id == 'current-page-selector' ? _.extend(wpjam.params, {paged: parseInt($el.val())}) : ''); 930 } 931 932 return false; 934 if($el.is('[name=filter_action]') || id == 'search-submit'){ 935 if($form.wpjam_validity()){ 936 $form.wpjam_query(); 937 } 938 939 return false; 940 } 941 } 942 }).on('keydown', '.tablenav :input', function(e){ 943 if(e.key === 'Enter' && wpjam.ajax_list_action !== false){ 944 let $input = $(this); 945 946 if($input.is('#current-page-selector')){ 947 if($form.wpjam_validity()){ 948 $form.wpjam_query(_.extend(wpjam.params, {paged: parseInt($input.val())})); 949 } 950 951 return false; 952 }else{ 953 let $el = $input.closest(':has(:submit)').find(':submit'); 954 955 if($el.length){ 956 $el.first().focus().click(); 957 958 return false; 959 } 960 } 933 961 } 934 962 }).on('click', '.tablenav .prev-day, .tablenav .next-day', function(e){ … … 986 1014 $left.prop('novalidate', true).on('init', function(){ 987 1015 $left_paged = $left.find('input.current-page').addClass('expandable'); 1016 988 1017 let paged = parseInt($left_paged.val()); 989 1018 let total = parseInt($left_paged.attr('max')); … … 1105 1134 1106 1135 if(update.table || update.tablenav){ 1107 let $nav = $form.find('.tablenav.top').find('.overall-action').remove().end(); 1108 let $actions = $nav.find('div.actions'); 1109 1110 if($actions.length){ 1111 $actions.last().append(this.overall_actions || ''); 1136 if($left.length && $('a.page-title-action').length){ 1137 this.overall_actions.unshift($('a.page-title-action').hide().clone().show().toggleClass('page-title-action button').prop('outerHTML')); 1138 } 1139 1140 let $nav = $form.find('.tablenav.top').find('.overall-action').remove().end(); 1141 1142 if($nav.find('div.actions').length){ 1143 $nav.find('div.actions').last().append(this.overall_actions || ''); 1112 1144 }else{ 1113 1145 $nav.prepend(this.overall_actions || ''); -
wpjam-basic/trunk/wpjam-basic.php
r3238028 r3238453 4 4 Plugin URI: https://blog.wpjam.com/project/wpjam-basic/ 5 5 Description: WPJAM 常用的函数和接口,屏蔽所有 WordPress 不常用的功能。 6 Version: 6.7.4 6 Version: 6.7.4.1 7 7 Requires at least: 6.4 8 8 Tested up to: 6.5
Note: See TracChangeset
for help on using the changeset viewer.