NEXT craftinamerica.org. Base setup for headless wordpress https://www.craftinamerica.org
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

column.php 1.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <?php
  2. /**
  3. * A column in a list table in wp-admin
  4. */
  5. abstract class P2P_Column {
  6. protected $ctype;
  7. protected $connected = array();
  8. function __construct( $directed ) {
  9. $this->ctype = $directed;
  10. $this->column_id = sprintf( 'p2p-%s-%s',
  11. $this->ctype->get_direction(),
  12. $this->ctype->name
  13. );
  14. }
  15. function add_column( $columns ) {
  16. $this->prepare_items();
  17. $labels = $this->ctype->get( 'current', 'labels' );
  18. $title = isset( $labels->column_title )
  19. ? $labels->column_title
  20. : $this->ctype->get( 'current', 'title' );
  21. return array_splice( $columns, 0, -1 ) + array( $this->column_id => $title ) + $columns;
  22. }
  23. protected abstract function get_items();
  24. protected function prepare_items() {
  25. $items = $this->get_items();
  26. $extra_qv = array(
  27. 'p2p:per_page' => -1,
  28. 'p2p:context' => 'admin_column'
  29. );
  30. $connected = $this->ctype->get_connected( $items, $extra_qv, 'abstract' );
  31. $this->connected = scb_list_group_by( $connected->items, '_p2p_get_other_id' );
  32. }
  33. function styles() {
  34. ?>
  35. <style type="text/css">
  36. .column-<?php echo $this->column_id; ?> ul {
  37. margin-top: 0;
  38. margin-bottom: 0;
  39. }
  40. </style>
  41. <?php
  42. }
  43. abstract function get_admin_link( $item );
  44. protected function render_column( $column, $item_id ) {
  45. if ( $this->column_id != $column )
  46. return;
  47. if ( !isset( $this->connected[ $item_id ] ) )
  48. return;
  49. $out = '<ul>';
  50. foreach ( $this->connected[ $item_id ] as $item ) {
  51. $out .= html( 'li', html_link( $this->get_admin_link( $item ), $item->get_title() ) );
  52. }
  53. $out .= '</ul>';
  54. return $out;
  55. }
  56. }