diff --git a/classes/Media/ServiceProvider.php b/classes/Media/ServiceProvider.php
new file mode 100644
index 00000000..b6f4191b
--- /dev/null
+++ b/classes/Media/ServiceProvider.php
@@ -0,0 +1,63 @@
+provides, true );
+ }
+
+ /**
+ * Returns the subscribers array
+ *
+ * @return array
+ */
+ public function get_subscribers(): array {
+ return $this->subscribers;
+ }
+
+ /**
+ * Registers the provided classes
+ *
+ * @return void
+ */
+ public function register(): void {
+ $this->getContainer()->add( Upload::class );
+
+ $this->getContainer()->addShared( Subscriber::class )
+ ->addArgument( Upload::class );
+ }
+}
diff --git a/classes/Media/Subscriber.php b/classes/Media/Subscriber.php
new file mode 100644
index 00000000..2844dfd8
--- /dev/null
+++ b/classes/Media/Subscriber.php
@@ -0,0 +1,46 @@
+upload = $upload;
+ }
+
+ /**
+ * Returns an array of events that this subscriber wants to listen to.
+ *
+ * @return array
+ */
+ public static function get_subscribed_events(): array {
+ return [
+ 'restrict_manage_posts' => 'imagify_attachments_filter_dropdown',
+ ];
+ }
+
+ /**
+ * Adds a dropdown that allows filtering on the attachments Imagify status.
+ *
+ * @return void
+ */
+ public function imagify_attachments_filter_dropdown() {
+ $this->upload->add_imagify_filter_to_attachments_dropdown();
+ }
+}
diff --git a/classes/Media/Upload/Upload.php b/classes/Media/Upload/Upload.php
new file mode 100644
index 00000000..7bb50447
--- /dev/null
+++ b/classes/Media/Upload/Upload.php
@@ -0,0 +1,51 @@
+is_wp_library_page() ) {
+ return;
+ }
+
+ /**
+ * Tell if imagify stats query should run.
+ *
+ * @param bool $boolean True if the query should be run. False otherwise.
+ */
+ if ( apply_filters( 'imagify_display_library_stats', false ) ) {
+ $optimized = imagify_count_optimized_attachments();
+ $unoptimized = imagify_count_unoptimized_attachments();
+ $errors = imagify_count_error_attachments();
+ }
+
+ $status = isset( $_GET['imagify-status'] ) ? wp_unslash( $_GET['imagify-status'] ) : 0; // WPCS: CSRF ok.
+ $options = array(
+ 'optimized' => _x( 'Optimized', 'Media Files', 'imagify' ),
+ 'unoptimized' => _x( 'Unoptimized', 'Media Files', 'imagify' ),
+ 'errors' => _x( 'Errors', 'Media Files', 'imagify' ),
+ );
+
+ echo '';
+ echo ' ';
+ }
+}
diff --git a/config/providers.php b/config/providers.php
index 8c3f4be0..1f29c89f 100644
--- a/config/providers.php
+++ b/config/providers.php
@@ -8,4 +8,5 @@
'Imagify\Stats\ServiceProvider',
'Imagify\Webp\ServiceProvider',
'Imagify\ThirdParty\ServiceProvider',
+ 'Imagify\Media\ServiceProvider',
];
diff --git a/inc/admin/upload.php b/inc/admin/upload.php
index b24249a5..d2bb42f0 100755
--- a/inc/admin/upload.php
+++ b/inc/admin/upload.php
@@ -39,38 +39,6 @@ function _imagify_manage_media_custom_column( $column_name, $attachment_id ) {
echo get_imagify_media_column_content( $process );
}
-add_action( 'restrict_manage_posts', '_imagify_attachments_filter_dropdown' );
-/**
- * Adds a dropdown that allows filtering on the attachments Imagify status.
- *
- * @since 1.0
- * @author Jonathan Buttigieg
- */
-function _imagify_attachments_filter_dropdown() {
- if ( ! Imagify_Views::get_instance()->is_wp_library_page() ) {
- return;
- }
-
- $optimized = imagify_count_optimized_attachments();
- $unoptimized = imagify_count_unoptimized_attachments();
- $errors = imagify_count_error_attachments();
- $status = isset( $_GET['imagify-status'] ) ? wp_unslash( $_GET['imagify-status'] ) : 0; // WPCS: CSRF ok.
- $options = array(
- 'optimized' => _x( 'Optimized', 'Media Files', 'imagify' ),
- 'unoptimized' => _x( 'Unoptimized', 'Media Files', 'imagify' ),
- 'errors' => _x( 'Errors', 'Media Files', 'imagify' ),
- );
-
- echo '';
- echo ' ';
-}
-
add_filter( 'request', '_imagify_sort_attachments_by_status' );
/**
* Modify the query based on the imagify-status variable in $_GET.