NEXT craftinamerica.org. Base setup for headless wordpress https://www.craftinamerica.org
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

dropdown.php 1.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. /**
  3. * A dropdown above a list table in wp-admin
  4. */
  5. abstract class P2P_Dropdown {
  6. protected $ctype;
  7. protected $title;
  8. function __construct( $directed, $title ) {
  9. $this->ctype = $directed;
  10. $this->title = $title;
  11. }
  12. function show_dropdown() {
  13. echo $this->render_dropdown();
  14. }
  15. protected function render_dropdown() {
  16. $direction = $this->ctype->flip_direction()->get_direction();
  17. $labels = $this->ctype->get( 'current', 'labels' );
  18. if ( isset( $labels->dropdown_title ) )
  19. $title = $labels->dropdown_title;
  20. elseif ( isset( $labels->column_title ) )
  21. $title = $labels->column_title;
  22. else
  23. $title = $this->title;
  24. return scbForms::input( array(
  25. 'type' => 'select',
  26. 'name' => array( 'p2p', $this->ctype->name, $direction ),
  27. 'choices' => self::get_choices( $this->ctype ),
  28. 'text' => $title,
  29. ), $_GET );
  30. }
  31. protected static function get_qv() {
  32. if ( !isset( $_GET['p2p'] ) )
  33. return array();
  34. $args = array();
  35. $tmp = reset( $_GET['p2p'] );
  36. $args['connected_type'] = key( $_GET['p2p'] );
  37. list( $args['connected_direction'], $args['connected_items'] ) = each( $tmp );
  38. if ( !$args['connected_items'] )
  39. return array();
  40. return $args;
  41. }
  42. protected static function get_choices( $directed ) {
  43. $extra_qv = array(
  44. 'p2p:per_page' => -1,
  45. 'p2p:context' => 'admin_dropdown'
  46. );
  47. $connected = $directed->get_connected( 'any', $extra_qv, 'abstract' );
  48. $options = array();
  49. foreach ( $connected->items as $item )
  50. $options[ $item->get_id() ] = $item->get_title();
  51. return $options;
  52. }
  53. }