get_var( // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery -- fallback when attachment_url_to_postid misses; cached in the flipset group. $wpdb->prepare( "SELECT post_id FROM {$wpdb->postmeta} WHERE meta_key = '_wp_attached_file' AND meta_value = %s LIMIT 1", $relative ) ); wp_cache_set( $cache_key, $found, 'flipset' ); } return absint( $found ); } /** * @param int $attachment_id Attachment ID. * @return int */ public static function translate_attachment_id( $attachment_id ) { $original = absint( $attachment_id ); $attachment_id = $original; if ( ! $attachment_id ) { return 0; } if ( has_filter( 'wpml_object_id' ) ) { $translated = absint( apply_filters( 'wpml_object_id', $attachment_id, 'attachment', true ) ); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound -- WPML public API. if ( $translated ) { $attachment_id = $translated; } } elseif ( function_exists( 'pll_get_post' ) ) { $translated = absint( pll_get_post( $attachment_id ) ); if ( $translated ) { $attachment_id = $translated; } } /** * Filter: flipset/translate_attachment_id * * Override which Media Library attachment is used for the current * language after WPML / Polylang have had a chance to swap it. * * @param int $attachment_id Resolved attachment ID. * @param int $original ID parsed from the file URL. */ $filtered = apply_filters( 'flipset/translate_attachment_id', $attachment_id, $original ); return absint( $filtered ) ? absint( $filtered ) : $attachment_id; } /** * @param string $tag Script tag. * @param string $handle Script handle. * @return string */ public function script_loader_tag( $tag, $handle ) { if ( ! in_array( $handle, $this->js_handles(), true ) ) { return $tag; } // The tag string can start with an inline "before" script (the PDF.js // capture snippet), so target the