'sg7g_media', 'post_status' => array( 'publish', 'draft', 'pending', 'private', 'future' ), 'posts_per_page' => 50, 'fields' => 'ids', 'orderby' => 'ID', 'order' => 'ASC', // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_query -- One-time migration query for legacy validation data. 'meta_query' => array( 'relation' => 'OR', array( 'key' => '_sg7g_validation_schema', 'compare' => 'NOT EXISTS', ), array( 'key' => '_sg7g_validation_schema', 'value' => self::VALIDATION_SCHEMA, 'compare' => '!=', ), ), ) ); foreach ( $post_ids as $post_id ) { $post_id = absint( $post_id ); $type = (string) get_post_meta( $post_id, '_sg7g_media_type', true ); $source = (string) get_post_meta( $post_id, '_sg7g_source', true ); $url = (string) get_post_meta( $post_id, '_sg7g_source_url', true ); $file_id = absint( get_post_meta( $post_id, '_sg7g_file_id', true ) ); if ( ! in_array( $type, array( 'video', 'audio' ), true ) ) { $detected = $url ? SG7G_Meta_Boxes::detect_source( $url ) : array(); $type = ! empty( $detected['type'] ) ? (string) $detected['type'] : ( str_starts_with( (string) get_post_mime_type( $file_id ), 'audio/' ) ? 'audio' : 'video' ); } $sources = SG7G_Meta_Boxes::sources(); if ( ! isset( $sources[ $type ][ $source ] ) ) { $detected = $url ? SG7G_Meta_Boxes::detect_source( $url ) : array(); $source = ! empty( $detected['source'] ) ? (string) $detected['source'] : ( 'audio' === $type ? 'local_audio' : 'local_video' ); } update_post_meta( $post_id, '_sg7g_media_type', $type ); update_post_meta( $post_id, '_sg7g_source', $source ); $validation = SG7G_Meta_Boxes::validate_source( $type, $source, $url, $file_id ); update_post_meta( $post_id, '_sg7g_source_valid', is_wp_error( $validation ) ? 0 : 1 ); update_post_meta( $post_id, '_sg7g_validation_schema', self::VALIDATION_SCHEMA ); if ( is_wp_error( $validation ) ) { update_post_meta( $post_id, '_sg7g_source_error', $validation->get_error_message() ); } else { delete_post_meta( $post_id, '_sg7g_source_error' ); } } if ( count( $post_ids ) < 50 ) { update_option( 'sg7g_validation_schema', self::VALIDATION_SCHEMA, false ); } } }