class-ajax.php
3 months ago
class-bulk-edit.php
3 months ago
class-create-modal.php
3 months ago
class-edit-modal.php
2 months ago
class-list-table.php
1 week ago
class-quick-edit.php
2 months ago
class-quick-edit.php
75 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Admin Placement Quick Edit. |
| 4 | * |
| 5 | * @package AdvancedAds |
| 6 | * @author Advanced Ads <info@wpadvancedads.com> |
| 7 | * @since 1.50.0 |
| 8 | */ |
| 9 | |
| 10 | namespace AdvancedAds\Admin\Placements; |
| 11 | |
| 12 | use AdvancedAds\Constants; |
| 13 | use AdvancedAds\Framework\Interfaces\Integration_Interface; |
| 14 | use AdvancedAds\Framework\Utilities\Params; |
| 15 | use AdvancedAds\Utilities\Conditional; |
| 16 | |
| 17 | defined( 'ABSPATH' ) || exit; |
| 18 | |
| 19 | /** |
| 20 | * Admin Placement Quick Edit. |
| 21 | */ |
| 22 | class Quick_Edit implements Integration_Interface { |
| 23 | |
| 24 | /** |
| 25 | * Hook into WordPress. |
| 26 | * |
| 27 | * @return void |
| 28 | */ |
| 29 | public function hooks(): void { |
| 30 | if ( ! Conditional::user_can( 'advanced_ads_manage_placements' ) ) { |
| 31 | return; |
| 32 | } |
| 33 | add_action( 'quick_edit_custom_box', [ $this, 'add_quick_edit_fields' ], 10, 2 ); |
| 34 | add_action( 'save_post', [ $this, 'save_quick_edits' ], 100 ); |
| 35 | } |
| 36 | |
| 37 | /** |
| 38 | * Add fields to the quick edit form |
| 39 | * |
| 40 | * @param string $column currently processed column. |
| 41 | * @param string $post_type the post type. |
| 42 | * |
| 43 | * @return void |
| 44 | */ |
| 45 | public function add_quick_edit_fields( $column, $post_type ): void { |
| 46 | if ( Constants::POST_TYPE_PLACEMENT !== $post_type || 'type' !== $column ) { |
| 47 | return; |
| 48 | } |
| 49 | include plugin_dir_path( ADVADS_FILE ) . 'views/admin/placements/quick-edit.php'; |
| 50 | } |
| 51 | |
| 52 | /** |
| 53 | * Save quick edit data |
| 54 | * |
| 55 | * @param int $id the placement id. |
| 56 | * |
| 57 | * @return void |
| 58 | */ |
| 59 | public function save_quick_edits( $id ): void { |
| 60 | // Not inline edit, or no permission. |
| 61 | if ( ! wp_verify_nonce( sanitize_key( Params::post( '_inline_edit' ) ), 'inlineeditnonce' ) ) { |
| 62 | return; |
| 63 | } |
| 64 | |
| 65 | $placement = wp_advads_get_placement( $id ); |
| 66 | |
| 67 | if ( ! $placement ) { |
| 68 | return; |
| 69 | } |
| 70 | $placement->set_status( Params::post( 'status', '', FILTER_UNSAFE_RAW ) ); |
| 71 | $placement->save(); |
| 72 | ( new Placement_List_Table() )->hooks(); |
| 73 | } |
| 74 | } |
| 75 |