__( 'All disclosure states', 'aiviso-ai-image-disclosure' ), 'generated' => __( 'AI-generated', 'aiviso-ai-image-disclosure' ), 'modified' => __( 'AI-modified', 'aiviso-ai-image-disclosure' ), 'custom' => __( 'Custom disclosure', 'aiviso-ai-image-disclosure' ), 'unmarked' => __( 'Unmarked', 'aiviso-ai-image-disclosure' ), 'missing_source' => __( 'Missing digital source type', 'aiviso-ai-image-disclosure' ) ); echo ''; } public function query( \WP_Query $query ): void { if ( ! is_admin() || ! $query->is_main_query() || 'attachment' !== $query->get( 'post_type' ) || ! isset( $_GET['aiviso_state'] ) ) { return; } $state = is_scalar( $_GET['aiviso_state'] ) ? sanitize_key( (string) wp_unslash( $_GET['aiviso_state'] ) ) : ''; if ( ! in_array( $state, array( 'generated', 'modified', 'custom', 'unmarked', 'missing_source' ), true ) ) { return; } $query->set( 'post_mime_type', 'image' ); $meta = array(); if ( 'unmarked' === $state ) { $meta[] = array( 'key' => AI_State::META_KEY, 'compare' => 'NOT EXISTS' ); } elseif ( 'missing_source' === $state ) { $meta = array( 'relation' => 'AND', array( 'key' => AI_State::META_KEY, 'value' => '1' ), array( 'key' => AI_State::TYPE_META_KEY, 'value' => 'custom' ), array( 'relation' => 'OR', array( 'key' => Digital_Source_Type::META_KEY, 'compare' => 'NOT EXISTS' ), array( 'key' => Digital_Source_Type::META_KEY, 'value' => '' ) ) ); } else { $meta = array( 'relation' => 'AND', array( 'key' => AI_State::META_KEY, 'value' => '1' ), array( 'key' => AI_State::TYPE_META_KEY, 'value' => $state ) ); } $query->set( 'meta_query', $meta ); } /** @param array $actions @return array */ public function bulk_actions( array $actions ): array { return array_merge( $actions, Disclosure_Bulk_Actions::actions() ); } /** @param string $redirect @param string $action @param int[] $ids */ public function handle_bulk( string $redirect, string $action, array $ids ): string { $result = Disclosure_Bulk_Actions::process( $action, $ids ); if ( 0 === $result['changed'] && 0 === $result['skipped'] ) { return $redirect; } return add_query_arg( array( 'aiviso_changed' => $result['changed'], 'aiviso_skipped' => $result['skipped'] ), $redirect ); } public function notice(): void { if ( ! isset( $_GET['aiviso_changed'] ) && ! isset( $_GET['aiviso_skipped'] ) ) { return; } $changed = isset( $_GET['aiviso_changed'] ) ? absint( $_GET['aiviso_changed'] ) : 0; $skipped = isset( $_GET['aiviso_skipped'] ) ? absint( $_GET['aiviso_skipped'] ) : 0; echo '

' . esc_html( sprintf( _n( '%d image changed.', '%d images changed.', $changed, 'aiviso-ai-image-disclosure' ), $changed ) . ( $skipped ? ' ' . sprintf( _n( '%d image skipped.', '%d images skipped.', $skipped, 'aiviso-ai-image-disclosure' ), $skipped ) : '' ) ) . '

'; } }