AdminBar.php
3 days ago
AdminBarEditColumns.php
3 days ago
Colors.php
3 days ago
CommonAssets.php
3 days ago
CurrentTable.php
3 days ago
ManageHeadings.php
3 days ago
ManageValue.php
3 days ago
NoticeChecks.php
3 days ago
PluginUpdate.php
3 days ago
PromoChecks.php
3 days ago
QuickEdit.php
3 days ago
SaveHeadings.php
3 days ago
Setup.php
3 days ago
TableRows.php
3 days ago
Tooltips.php
3 days ago
View.php
3 days ago
QuickEdit.php
99 lines
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace AC\Service; |
| 6 | |
| 7 | use AC\ListScreenRepository\Storage; |
| 8 | use AC\Registerable; |
| 9 | use AC\Table\PrimaryColumnFactory; |
| 10 | use AC\Table\TablePreference; |
| 11 | use AC\TableScreenFactory; |
| 12 | use AC\Type\TableId; |
| 13 | |
| 14 | class QuickEdit implements Registerable |
| 15 | { |
| 16 | private Storage $storage; |
| 17 | |
| 18 | private TablePreference $preference; |
| 19 | |
| 20 | private PrimaryColumnFactory $primary_column_factory; |
| 21 | |
| 22 | private TableScreenFactory $table_screen_factory; |
| 23 | |
| 24 | public function __construct( |
| 25 | Storage $storage, |
| 26 | TablePreference $preference, |
| 27 | PrimaryColumnFactory $primary_column_factory, |
| 28 | TableScreenFactory $table_screen_factory |
| 29 | ) { |
| 30 | $this->storage = $storage; |
| 31 | $this->preference = $preference; |
| 32 | $this->primary_column_factory = $primary_column_factory; |
| 33 | $this->table_screen_factory = $table_screen_factory; |
| 34 | } |
| 35 | |
| 36 | public function register(): void |
| 37 | { |
| 38 | add_action('admin_init', [$this, 'init_columns_on_quick_edit']); |
| 39 | } |
| 40 | |
| 41 | /** |
| 42 | * Get list screen when doing Quick Edit, a native WordPress ajax call |
| 43 | */ |
| 44 | public function init_columns_on_quick_edit(): void |
| 45 | { |
| 46 | if (! wp_doing_ajax()) { |
| 47 | return; |
| 48 | } |
| 49 | |
| 50 | switch (filter_input(INPUT_POST, 'action')) { |
| 51 | // Quick edit post |
| 52 | case 'pll_update_post_rows': |
| 53 | case 'inline-save' : |
| 54 | $table_id = (string)filter_input(INPUT_POST, 'post_type'); |
| 55 | break; |
| 56 | |
| 57 | // Adding term & Quick edit term |
| 58 | case 'pll_update_term_rows': |
| 59 | case 'add-tag' : |
| 60 | case 'inline-save-tax' : |
| 61 | $table_id = 'wp-taxonomy_' . filter_input(INPUT_POST, 'taxonomy'); |
| 62 | break; |
| 63 | |
| 64 | // Quick edit comment & Inline reply on comment |
| 65 | case 'edit-comment' : |
| 66 | case 'replyto-comment' : |
| 67 | $table_id = 'wp-comments'; |
| 68 | break; |
| 69 | |
| 70 | default: |
| 71 | return; |
| 72 | } |
| 73 | |
| 74 | $list_id = $this->preference->get_list_id(new TableId($table_id)); |
| 75 | |
| 76 | if (! $list_id) { |
| 77 | return; |
| 78 | } |
| 79 | |
| 80 | $list_screen = $this->storage->find($list_id); |
| 81 | |
| 82 | if (! $list_screen || ! $list_screen->is_user_allowed(wp_get_current_user())) { |
| 83 | return; |
| 84 | } |
| 85 | |
| 86 | $table_screen = $this->table_screen_factory->create($list_screen->get_table_id()); |
| 87 | |
| 88 | add_filter( |
| 89 | 'list_table_primary_column', |
| 90 | [$this->primary_column_factory->create($list_screen), 'set_primary_column'], |
| 91 | 20 |
| 92 | ); |
| 93 | |
| 94 | (new ManageHeadings())->handle($list_screen, $table_screen); |
| 95 | (new ManageValue())->handle($list_screen, $table_screen); |
| 96 | } |
| 97 | |
| 98 | } |
| 99 |