| 1 |
<?php |
| 2 |
|
| 3 |
namespace ISC\Image_Sources; |
| 4 |
|
| 5 |
/** |
| 6 |
* Admin features for image sources |
| 7 |
*/ |
| 8 |
class Admin extends Image_Sources { |
| 9 |
/** |
| 10 |
* Initiate admin functions |
| 11 |
*/ |
| 12 |
public function __construct() { |
| 13 |
parent::__construct(); |
| 14 |
|
| 15 |
// load components |
| 16 |
new Image_Sources_Admin_Scripts(); |
| 17 |
new Admin_Menu(); |
| 18 |
new Admin_Fields(); |
| 19 |
new Admin_Notices(); |
| 20 |
new Admin_Ajax(); |
| 21 |
new Admin_Media_Library_Filters(); |
| 22 |
|
| 23 |
// fire when an attachment is removed |
| 24 |
add_action( 'delete_attachment', [ $this, 'delete_attachment' ] ); |
| 25 |
|
| 26 |
// add links to setting and source list to plugin page |
| 27 |
add_action( 'plugin_action_links_' . ISCBASE, [ $this, 'add_links_to_plugin_page' ] ); |
| 28 |
} |
| 29 |
|
| 30 |
/** |
| 31 |
* Actions to perform when an attachment is removed |
| 32 |
* - delete it from the ISC storage |
| 33 |
* |
| 34 |
* @param int $post_id WP_Post ID. |
| 35 |
*/ |
| 36 |
public function delete_attachment( $post_id ) { |
| 37 |
// prevent a fatal error during plugin updates in case this class was ever renamed or moved |
| 38 |
if ( ! class_exists( '\ISC_Storage_Model', false ) ) { |
| 39 |
return; |
| 40 |
} |
| 41 |
$storage_model = new \ISC_Storage_Model(); |
| 42 |
$storage_model->remove_image_by_id( $post_id ); |
| 43 |
} |
| 44 |
|
| 45 |
/** |
| 46 |
* Add links to pages from plugins.php |
| 47 |
* |
| 48 |
* @param array $links existing plugin links. |
| 49 |
* |
| 50 |
* @return array |
| 51 |
*/ |
| 52 |
public function add_links_to_plugin_page( $links ): array { |
| 53 |
// image source link |
| 54 |
$links[] = sprintf( |
| 55 |
'<a href="%s">%s</a>', |
| 56 |
esc_url( add_query_arg( 'page', 'isc-sources', get_admin_url() . 'upload.php' ) ), |
| 57 |
__( 'Image Sources', 'image-source-control-isc' ) |
| 58 |
); |
| 59 |
|
| 60 |
return $links; |
| 61 |
} |
| 62 |
} |