QuickEdit.php
79 lines
| 1 | <?php |
| 2 | |
| 3 | namespace AC\Screen; |
| 4 | |
| 5 | use AC\ListScreenRepository\Storage; |
| 6 | use AC\Registrable; |
| 7 | use AC\ScreenController; |
| 8 | use AC\Table\Preference; |
| 9 | use AC\Type\ListScreenId; |
| 10 | |
| 11 | class QuickEdit implements Registrable { |
| 12 | |
| 13 | /** |
| 14 | * @var Storage |
| 15 | */ |
| 16 | private $storage; |
| 17 | |
| 18 | /** |
| 19 | * @var Preference |
| 20 | */ |
| 21 | private $preference; |
| 22 | |
| 23 | public function __construct( Storage $storage, Preference $preference ) { |
| 24 | $this->storage = $storage; |
| 25 | $this->preference = $preference; |
| 26 | } |
| 27 | |
| 28 | public function register() { |
| 29 | add_action( 'admin_init', [ $this, 'init_columns_on_quick_edit' ] ); |
| 30 | } |
| 31 | |
| 32 | /** |
| 33 | * Get list screen when doing Quick Edit, a native WordPress ajax call |
| 34 | */ |
| 35 | public function init_columns_on_quick_edit() { |
| 36 | if ( ! wp_doing_ajax() ) { |
| 37 | return; |
| 38 | } |
| 39 | |
| 40 | switch ( filter_input( INPUT_POST, 'action' ) ) { |
| 41 | |
| 42 | // Quick edit post |
| 43 | case 'inline-save' : |
| 44 | $type = filter_input( INPUT_POST, 'post_type' ); |
| 45 | break; |
| 46 | |
| 47 | // Adding term & Quick edit term |
| 48 | case 'add-tag' : |
| 49 | case 'inline-save-tax' : |
| 50 | $type = 'wp-taxonomy_' . filter_input( INPUT_POST, 'taxonomy' ); |
| 51 | break; |
| 52 | |
| 53 | // Quick edit comment & Inline reply on comment |
| 54 | case 'edit-comment' : |
| 55 | case 'replyto-comment' : |
| 56 | $type = 'wp-comments'; |
| 57 | break; |
| 58 | |
| 59 | default: |
| 60 | return; |
| 61 | } |
| 62 | |
| 63 | $id = $this->preference->get( $type ); |
| 64 | |
| 65 | if ( ! $id ) { |
| 66 | return; |
| 67 | } |
| 68 | |
| 69 | $list_screen = $this->storage->find( new ListScreenId( $id ) ); |
| 70 | |
| 71 | if ( ! $list_screen ) { |
| 72 | return; |
| 73 | } |
| 74 | |
| 75 | $screen_controller = new ScreenController( $list_screen ); |
| 76 | $screen_controller->register(); |
| 77 | } |
| 78 | |
| 79 | } |