diff --git a/.github/workflows/wp_dam_hook_integrity_on_pull_request.yml b/.github/workflows/wp_dam_hook_integrity_on_pull_request.yml new file mode 100644 index 0000000000..d37de4b822 --- /dev/null +++ b/.github/workflows/wp_dam_hook_integrity_on_pull_request.yml @@ -0,0 +1,44 @@ +on: + pull_request: + # Deny-list, mirroring GODAM_EXCLUDED_ROOT_DIRS in + # bin/hook-check/shared.php — an allow-list of specific directories here + # previously meant attachment-touching code added to godam.php, lib/, or + # any new top-level directory would never even trigger this workflow. + # bin/hook-check/*.php is re-included as the one exception inside the + # otherwise-excluded bin/: those ARE the checker's own files, and a + # change to them needs to re-run the checks they define. + paths: + - '**/*.php' + - '!.git/**' + - '!.github/**' + - '!.husky/**' + - '!.idea/**' + - '!node_modules/**' + - '!tests/**' + - '!languages/**' + - '!bin/**' + - 'bin/hook-check/*.php' + +name: wp-dam hook integrity + +permissions: + contents: read + +jobs: + checkHooks: + name: Check rtgodam_before/after_attachment_lookup hook integrity + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v6 + with: + ref: ${{ github.event.pull_request.head.sha }} + - name: Set up PHP + uses: shivammathur/setup-php@v2 + with: + php-version: '8.4' + coverage: none + - name: Run hook integrity check + run: php bin/hook-check/balance.php check + - name: Run attachment-access coverage check + if: always() + run: php bin/hook-check/coverage.php check diff --git a/.husky/pre-commit b/.husky/pre-commit index 1fb913e3d5..fd8e7b5380 100644 --- a/.husky/pre-commit +++ b/.husky/pre-commit @@ -1 +1 @@ -npm run lint:staged +npm run lint:staged && ./bin/hook-check/pre-commit.sh diff --git a/admin/class-rtgodam-retranscodemedia.php b/admin/class-rtgodam-retranscodemedia.php index e7e5d770ea..8e6c4db0f2 100644 --- a/admin/class-rtgodam-retranscodemedia.php +++ b/admin/class-rtgodam-retranscodemedia.php @@ -173,11 +173,21 @@ public function admin_enqueues( $hook_suffix ) { if ( ! empty( $ids ) ) { $ids = explode( ',', $ids ); } else { + /** + * Fires before this fallback "no explicit IDs" scan reads any + * attachment data, so integrations that centralize media on another + * site can switch context first. + * + * @since 2.2.0 + */ + do_action( 'rtgodam_before_attachment_lookup' ); + add_filter( 'posts_where', array( $this, 'add_search_mime_types' ) ); - $query = new WP_Query( array( 'post_type' => 'attachments' ) ); + $query = new WP_Query( array( 'post_type' => 'attachment' ) ); $media = $query->get_posts(); remove_filter( 'posts_where', array( $this, 'add_search_mime_types' ) ); if ( empty( $media ) || is_wp_error( $media ) ) { + do_action( 'rtgodam_after_attachment_lookup' ); // translators: Link to the media page. echo '
' . sprintf( esc_html__( "Unable to find any media. Are you sure some exist?", 'godam' ), esc_url( admin_url( 'upload.php' ) ) ) . '
'; @@ -198,6 +208,8 @@ public function admin_enqueues( $hook_suffix ) { ); } } + + do_action( 'rtgodam_after_attachment_lookup' ); } $stopping_text = esc_html__( 'Stopping...', 'godam' ); @@ -240,6 +252,17 @@ public function admin_enqueues( $hook_suffix ) { */ public function add_media_row_action( $actions, $post ) { + /** + * Fires before checking whether this attachment is a supported + * document type, so integrations that centralize media on another + * site can switch context first. + * + * @since 2.2.0 + */ + do_action( 'rtgodam_before_attachment_lookup' ); + $is_supported_document = rtgodam_is_supported_document_attachment( $post->ID ); + do_action( 'rtgodam_after_attachment_lookup' ); + // Documents are included so files already in the library — which predate document // support and so were never sent to GoDAM Central — can have a preview generated // without re-uploading them. Tested against the attachment rather than its MIME alone, @@ -248,7 +271,7 @@ public function add_media_row_action( $actions, $post ) { if ( ( 'audio/' !== substr( $post->post_mime_type, 0, 6 ) && 'video/' !== substr( $post->post_mime_type, 0, 6 ) && - ! rtgodam_is_supported_document_attachment( $post->ID ) + ! $is_supported_document ) || // Safe fallback via filter; PHPCS can't resolve dynamic capability. // phpcs:ignore WordPress.WP.Capabilities.Undetermined @@ -375,6 +398,18 @@ public function retranscode_interface() { // Create the list of image IDs. $usage_info = get_option( 'rtgodam-usage' ); $ids = rtgodam_filter_input( INPUT_GET, 'ids', FILTER_SANITIZE_FULL_SPECIAL_CHARS ); + + /** + * Fires before either branch below reads attachment data + * (get_attached_file()/get_the_title(), explicit IDs or the + * fallback WP_Query scan), so integrations that centralize + * media on another site can switch context first. Unlike + * admin_enqueues(), both branches here touch attachment + * data, so both are wrapped. + * + * @since 2.2.0 + */ + do_action( 'rtgodam_before_attachment_lookup' ); if ( ! empty( $ids ) ) { $media = array_map( 'intval', explode( ',', trim( $ids, ',' ) ) ); $ids = implode( ',', $media ); @@ -391,10 +426,11 @@ public function retranscode_interface() { } } else { add_filter( 'posts_where', array( $this, 'add_search_mime_types' ) ); - $query = new WP_Query( array( 'post_type' => 'attachments' ) ); + $query = new WP_Query( array( 'post_type' => 'attachment' ) ); $media = $query->get_posts(); remove_filter( 'posts_where', array( $this, 'add_search_mime_types' ) ); if ( empty( $media ) || is_wp_error( $media ) ) { + do_action( 'rtgodam_after_attachment_lookup' ); // translators: Link to the media page. echo '' . sprintf( esc_html__( "Unable to find any media. Are you sure some exist?", 'godam' ), esc_url( admin_url( 'upload.php' ) ) ) . '
'; @@ -417,6 +453,7 @@ public function retranscode_interface() { } $ids = implode( ',', $ids ); } + do_action( 'rtgodam_after_attachment_lookup' ); if ( empty( $ids ) ) { echo '' . esc_html__( 'There are no media available to send for transcoding.', 'godam' ) . '
'; @@ -556,8 +593,23 @@ public function retranscode_interface() { * @param string $message Error message. */ public function die_json_error_msg( $id, $message ) { + /** + * Fires before reading this attachment's title for the error payload below. + * + * No caller currently reaches this method (kept as a public JSON-error + * helper), but the read is wrapped defensively rather than relying on + * every future caller to remember to. die()/exit() never run a + * try/finally's finally block, so the after-hook fires here — before + * die() — rather than wrapping the die() call itself. + * + * @since 2.2.0 + */ + do_action( 'rtgodam_before_attachment_lookup' ); + $title = get_the_title( $id ); + do_action( 'rtgodam_after_attachment_lookup' ); + // translators: Media name, Media ID and message for failed transcode. - die( wp_json_encode( array( 'error' => sprintf( __( '"%1$s" (ID %2$s) failed to send. The error message was: %3$s', 'godam' ), esc_html( get_the_title( $id ) ), $id, $message ) ) ) ); + die( wp_json_encode( array( 'error' => sprintf( __( '"%1$s" (ID %2$s) failed to send. The error message was: %3$s', 'godam' ), esc_html( $title ), $id, $message ) ) ) ); } /** @@ -595,7 +647,24 @@ public function rtgodam_before_thumbnail_store( $media_id = '', $post_request = return; } + /** + * Fires before this listener's own postmeta delete. + * + * 'rtgodam_before_thumbnail_store' is a public, third-party-triggerable + * extension point, not a private implementation detail — any code that + * fires it directly (a third-party plugin, WP-CLI, or a future GoDAM + * code path) would otherwise run this delete completely unwrapped. + * Wrapped here defensively rather than relying on + * add_media_thumbnails()'s own before/after pair to always be the one + * true caller. + * + * @since 2.2.0 + */ + do_action( 'rtgodam_before_attachment_lookup' ); + delete_post_meta( $media_id, 'rtgodam_media_thumbnails' ); + + do_action( 'rtgodam_after_attachment_lookup' ); } /** @@ -609,6 +678,21 @@ public function rtgodam_before_transcoded_media_store( $media_id = '', $transcod return; } + /** + * Fires before this listener's own postmeta read/delete. + * + * 'rtgodam_before_transcoded_media_store' is a public, + * third-party-triggerable extension point, not a private + * implementation detail — any code that fires it directly (a + * third-party plugin, WP-CLI, or a future GoDAM code path) would + * otherwise run this read/delete completely unwrapped. Wrapped here + * defensively rather than relying on add_transcoded_files()'s own + * before/after pair to always be the one true caller. + * + * @since 2.2.0 + */ + do_action( 'rtgodam_before_attachment_lookup' ); + $current_files = get_post_meta( $media_id, 'rtgodam_media_transcoded_files', true ); if ( ! empty( $current_files ) && is_array( $current_files ) ) { @@ -619,6 +703,8 @@ public function rtgodam_before_transcoded_media_store( $media_id = '', $transcod } } delete_post_meta( $media_id, 'rtgodam_media_transcoded_files' ); + + do_action( 'rtgodam_after_attachment_lookup' ); } /** @@ -631,34 +717,55 @@ public function transcoded_thumbnails_added( $media_id = '' ) { return; } - $current_thumbnail = get_post_meta( $media_id, 'rtgodam_media_video_thumbnail', true ); - $custom_thumbnails = get_post_meta( $media_id, 'rtgodam_custom_media_thumbnails', true ); - $custom_thumbnails = is_array( $custom_thumbnails ) ? $custom_thumbnails : array(); - - // If the current selected thumbnail is one of the custom uploaded thumbnails, do not overwrite it. - if ( ! empty( $current_thumbnail ) && in_array( $current_thumbnail, $custom_thumbnails, true ) ) { - return; - } + /** + * Fires before this listener's own postmeta reads/writes. + * + * 'rtgodam_transcoded_thumbnails_added' is a public, + * third-party-triggerable extension point, not a private + * implementation detail — any code that fires it directly (a + * third-party plugin, WP-CLI, or a future GoDAM code path) would + * otherwise run this method's postmeta access completely unwrapped. + * Wrapped here defensively — in a try/finally, since this method has + * its own early return below — rather than relying on + * add_media_thumbnails()'s own before/after pair to always be the one + * true caller. + * + * @since 2.2.0 + */ + do_action( 'rtgodam_before_attachment_lookup' ); + + try { + $current_thumbnail = get_post_meta( $media_id, 'rtgodam_media_video_thumbnail', true ); + $custom_thumbnails = get_post_meta( $media_id, 'rtgodam_custom_media_thumbnails', true ); + $custom_thumbnails = is_array( $custom_thumbnails ) ? $custom_thumbnails : array(); + + // If the current selected thumbnail is one of the custom uploaded thumbnails, do not overwrite it. + if ( ! empty( $current_thumbnail ) && in_array( $current_thumbnail, $custom_thumbnails, true ) ) { + return; + } - $new_thumbs = get_post_meta( $media_id, 'rtgodam_media_thumbnails', true ); - $new_thumbs = is_array( $new_thumbs ) ? $new_thumbs : array(); + $new_thumbs = get_post_meta( $media_id, 'rtgodam_media_thumbnails', true ); + $new_thumbs = is_array( $new_thumbs ) ? $new_thumbs : array(); - if ( ! empty( $new_thumbs ) ) { - update_post_meta( $media_id, 'rtgodam_media_video_thumbnail', $new_thumbs[0] ); - } + if ( ! empty( $new_thumbs ) ) { + update_post_meta( $media_id, 'rtgodam_media_video_thumbnail', $new_thumbs[0] ); + } - $primary_remote_thumbnail_url = get_post_meta( $media_id, 'rtgodam_media_video_thumbnail', true ); + $primary_remote_thumbnail_url = get_post_meta( $media_id, 'rtgodam_media_video_thumbnail', true ); - if ( ! empty( $primary_remote_thumbnail_url ) ) { - do_action( 'rtgodam_primary_remote_thumbnail_set', $media_id, $primary_remote_thumbnail_url ); + if ( ! empty( $primary_remote_thumbnail_url ) ) { + do_action( 'rtgodam_primary_remote_thumbnail_set', $media_id, $primary_remote_thumbnail_url ); - // Sync placeholder thumbnail for the newly set primary thumbnail. - $godam_placeholder_map = get_post_meta( $media_id, 'rtgodam_media_placeholder_thumbnails', true ); - if ( is_array( $godam_placeholder_map ) && isset( $godam_placeholder_map[ $primary_remote_thumbnail_url ] ) ) { - update_post_meta( $media_id, 'rtgodam_media_video_placeholder_thumbnail', $godam_placeholder_map[ $primary_remote_thumbnail_url ] ); - } else { - delete_post_meta( $media_id, 'rtgodam_media_video_placeholder_thumbnail' ); + // Sync placeholder thumbnail for the newly set primary thumbnail. + $godam_placeholder_map = get_post_meta( $media_id, 'rtgodam_media_placeholder_thumbnails', true ); + if ( is_array( $godam_placeholder_map ) && isset( $godam_placeholder_map[ $primary_remote_thumbnail_url ] ) ) { + update_post_meta( $media_id, 'rtgodam_media_video_placeholder_thumbnail', $godam_placeholder_map[ $primary_remote_thumbnail_url ] ); + } else { + delete_post_meta( $media_id, 'rtgodam_media_video_placeholder_thumbnail' ); + } } + } finally { + do_action( 'rtgodam_after_attachment_lookup' ); } } @@ -674,6 +781,20 @@ public function rtgodam_handle_callback_finished( $attachment_id = '', $job_id = return; } + /** + * Fires before reading/clearing this attachment's retranscoding-sent + * flag, so integrations that centralize media on another site can + * switch context first. Unlike this class's other transcoder-pipeline + * hook handlers, the 'rtgodam_handle_callback_finished' action fires + * unconditionally at the end of handle_callback() + * (admin/class-rtgodam-transcoder-rest-routes.php), outside of any of + * that method's own per-branch before/after pairs, so this postmeta + * access has no coverage from its caller. + * + * @since 2.2.0 + */ + do_action( 'rtgodam_before_attachment_lookup' ); + $is_retranscoding_job = get_post_meta( $attachment_id, 'rtgodam_retranscoding_sent', true ); if ( $is_retranscoding_job ) { @@ -681,6 +802,8 @@ public function rtgodam_handle_callback_finished( $attachment_id = '', $job_id = delete_post_meta( $attachment_id, 'rtgodam_retranscoding_sent' ); } + + do_action( 'rtgodam_after_attachment_lookup' ); } /** diff --git a/admin/class-rtgodam-transcoder-handler.php b/admin/class-rtgodam-transcoder-handler.php index e1ddbf1702..7ad06a3cb1 100644 --- a/admin/class-rtgodam-transcoder-handler.php +++ b/admin/class-rtgodam-transcoder-handler.php @@ -210,19 +210,33 @@ public function __construct( $no_init = false ) { * @param int $attachment_id ID of attachment. */ public function send_transcoding_request( $attachment_id ) { + /** + * Fires before reading this attachment's metadata and dispatching + * its transcoding request, so integrations that centralize media on + * another site can switch context first. Hooked to `add_attachment`, + * which can fire synchronously from inside an already-open bracket + * (e.g. create_virtual_attachment()) — this method's own attachment + * reads, and wp_media_transcoding()'s internal ones, both need it. + * + * @since 2.2.0 + */ + do_action( 'rtgodam_before_attachment_lookup' ); + try { + $metadata = wp_get_attachment_metadata( $attachment_id ); - $metadata = wp_get_attachment_metadata( $attachment_id ); + $mime_type = get_post_mime_type( $attachment_id ); - $mime_type = get_post_mime_type( $attachment_id ); + if ( empty( $metadata ) ) { + $metadata = array( 'mime_type' => $mime_type ); + } elseif ( empty( $metadata['mime_type'] ) ) { + $metadata['mime_type'] = $mime_type; + } - if ( empty( $metadata ) ) { - $metadata = array( 'mime_type' => $mime_type ); - } elseif ( empty( $metadata['mime_type'] ) ) { - $metadata['mime_type'] = $mime_type; + // Send the transcoding request. + $this->wp_media_transcoding( $metadata, $attachment_id ); + } finally { + do_action( 'rtgodam_after_attachment_lookup' ); } - - // Send the transcoding request. - $this->wp_media_transcoding( $metadata, $attachment_id ); } /** @@ -422,20 +436,12 @@ public function wp_media_transcoding( $wp_metadata, $attachment_id, $autoformat } } - if ( ! defined( 'RTGODAM_TRANSCODER_CALLBACK_URL' ) || empty( RTGODAM_TRANSCODER_CALLBACK_URL ) ) { - include_once RTGODAM_PATH . 'admin/class-rtgodam-transcoder-rest-routes.php'; // phpcs:ignore WordPressVIPMinimum.Files.IncludingFile.UsingCustomConstant - define( 'RTGODAM_TRANSCODER_CALLBACK_URL', RTGODAM_Transcoder_Rest_Routes::get_callback_url() ); - } - - $callback_url = RTGODAM_TRANSCODER_CALLBACK_URL; - - /** - * Manually setting the rest api endpoint, we can refactor that later to use similar functionality as callback_url. - */ - $status_callback_url = get_rest_url( get_current_blog_id(), '/godam/v1/transcoding/transcoding-status' ); + include_once RTGODAM_PATH . 'admin/class-rtgodam-transcoder-rest-routes.php'; + $callback_url = RTGODAM_Transcoder_Rest_Routes::get_callback_url(); + $status_callback_url = RTGODAM_Transcoder_Rest_Routes::get_callback_url( 'status' ); // Get attachment author information. - $attachment_author_id = get_post_field( 'post_author', $attachment_id ); + $attachment_author_id = get_post_field( 'post_author', $attachment_id ); // godam-coverage-ignore -- wp_media_transcoding(): covered transitively — every real call site (send_transcoding_request() here, Retranscode_Failed_Media::retranscode_failed_media(), and class-transcoding.php's retranscode_media() via retranscode_media_centralized()) already wraps the call in its own before/after pair. $attachment_author = get_user_by( 'id', $attachment_author_id ); $site_url = get_site_url(); @@ -477,7 +483,7 @@ public function wp_media_transcoding( $wp_metadata, $attachment_id, $autoformat 'video_quality' => $rtgodam_video_compress_quality, 'mime_type' => $metadata['mime_type'], 'title' => sanitize_text_field( get_the_title( $attachment_id ) ), - 'description' => sanitize_textarea_field( (string) get_post_field( 'post_content', $attachment_id ) ), + 'description' => sanitize_textarea_field( (string) get_post_field( 'post_content', $attachment_id ) ), // godam-coverage-ignore -- wp_media_transcoding(): covered transitively — every real call site (send_transcoding_request() here, Retranscode_Failed_Media::retranscode_failed_media(), and class-transcoding.php's retranscode_media() via retranscode_media_centralized()) already wraps the call in its own before/after pair. 'wp_author_email' => apply_filters( 'godam_author_email_to_send', $author_email, $attachment_id ), 'wp_site' => $site_url, 'wp_author_first_name' => apply_filters( 'godam_author_first_name_to_send', $author_first_name, $attachment_id ), @@ -797,17 +803,17 @@ public function add_media_thumbnails( $post_array ) { } // rtMedia support. - update_post_meta( $post_id, '_rt_media_source', $post_thumbs_array['job_for'] ); - update_post_meta( $post_id, '_rt_media_thumbnails', $thumbnail_urls ); + update_post_meta( $post_id, '_rt_media_source', $post_thumbs_array['job_for'] ); // godam-coverage-ignore -- add_media_thumbnails(): covered transitively — sole caller (handle_wp_media_transcoding_callback) already runs inside its own caller's before/after pair. + update_post_meta( $post_id, '_rt_media_thumbnails', $thumbnail_urls ); // godam-coverage-ignore -- add_media_thumbnails(): covered transitively — sole caller (handle_wp_media_transcoding_callback) already runs inside its own caller's before/after pair. - update_post_meta( $post_id, 'rtgodam_media_source', $post_thumbs_array['job_for'] ); - update_post_meta( $post_id, 'rtgodam_media_thumbnails', $thumbnail_urls ); + update_post_meta( $post_id, 'rtgodam_media_source', $post_thumbs_array['job_for'] ); // godam-coverage-ignore -- add_media_thumbnails(): covered transitively — sole caller (handle_wp_media_transcoding_callback) already runs inside its own caller's before/after pair. + update_post_meta( $post_id, 'rtgodam_media_thumbnails', $thumbnail_urls ); // godam-coverage-ignore -- add_media_thumbnails(): covered transitively — sole caller (handle_wp_media_transcoding_callback) already runs inside its own caller's before/after pair. // Store thumbnail → placeholder mapping, or clear stale meta when no valid placeholders. if ( ! empty( $placeholder_map ) ) { - update_post_meta( $post_id, 'rtgodam_media_placeholder_thumbnails', $placeholder_map ); + update_post_meta( $post_id, 'rtgodam_media_placeholder_thumbnails', $placeholder_map ); // godam-coverage-ignore -- add_media_thumbnails(): covered transitively — sole caller (handle_wp_media_transcoding_callback) already runs inside its own caller's before/after pair. } else { - delete_post_meta( $post_id, 'rtgodam_media_placeholder_thumbnails' ); + delete_post_meta( $post_id, 'rtgodam_media_placeholder_thumbnails' ); // godam-coverage-ignore -- add_media_thumbnails(): covered transitively — sole caller (handle_wp_media_transcoding_callback) already runs inside its own caller's before/after pair. } do_action( 'rtgodam_transcoded_thumbnails_added', $post_id ); @@ -815,25 +821,25 @@ public function add_media_thumbnails( $post_array ) { if ( $first_thumbnail_url ) { // rtMedia support. - update_post_meta( $post_id, '_rt_media_video_thumbnail', $first_thumbnail_url ); + update_post_meta( $post_id, '_rt_media_video_thumbnail', $first_thumbnail_url ); // godam-coverage-ignore -- add_media_thumbnails(): covered transitively — sole caller (handle_wp_media_transcoding_callback) already runs inside its own caller's before/after pair. if ( class_exists( 'RTMediaModel' ) && ! empty( $media_id ) ) { $model->update( array( 'cover_art' => $first_thumbnail_url ), array( 'media_id' => $post_id ) ); update_activity_after_thumb_set( $media_id ); } - $current_thumbnail = get_post_meta( $post_id, 'rtgodam_media_video_thumbnail', true ); - $custom_thumbnails = get_post_meta( $post_id, 'rtgodam_custom_media_thumbnails', true ); + $current_thumbnail = get_post_meta( $post_id, 'rtgodam_media_video_thumbnail', true ); // godam-coverage-ignore -- add_media_thumbnails(): covered transitively — sole caller (handle_wp_media_transcoding_callback) already runs inside its own caller's before/after pair. + $custom_thumbnails = get_post_meta( $post_id, 'rtgodam_custom_media_thumbnails', true ); // godam-coverage-ignore -- add_media_thumbnails(): covered transitively — sole caller (handle_wp_media_transcoding_callback) already runs inside its own caller's before/after pair. $custom_thumbnails = is_array( $custom_thumbnails ) ? $custom_thumbnails : array(); // If the current selected thumbnail is NOT one of the custom uploaded thumbnails, overwrite it. if ( empty( $current_thumbnail ) || ! in_array( $current_thumbnail, $custom_thumbnails, true ) ) { - update_post_meta( $post_id, 'rtgodam_media_video_thumbnail', $first_thumbnail_url ); + update_post_meta( $post_id, 'rtgodam_media_video_thumbnail', $first_thumbnail_url ); // godam-coverage-ignore -- add_media_thumbnails(): covered transitively — sole caller (handle_wp_media_transcoding_callback) already runs inside its own caller's before/after pair. // Sync placeholder for the newly set primary thumbnail using the verified map. if ( isset( $placeholder_map[ $first_thumbnail_url ] ) ) { - update_post_meta( $post_id, 'rtgodam_media_video_placeholder_thumbnail', $placeholder_map[ $first_thumbnail_url ] ); + update_post_meta( $post_id, 'rtgodam_media_video_placeholder_thumbnail', $placeholder_map[ $first_thumbnail_url ] ); // godam-coverage-ignore -- add_media_thumbnails(): covered transitively — sole caller (handle_wp_media_transcoding_callback) already runs inside its own caller's before/after pair. } else { - delete_post_meta( $post_id, 'rtgodam_media_video_placeholder_thumbnail' ); + delete_post_meta( $post_id, 'rtgodam_media_video_placeholder_thumbnail' ); // godam-coverage-ignore -- add_media_thumbnails(): covered transitively — sole caller (handle_wp_media_transcoding_callback) already runs inside its own caller's before/after pair. } } @@ -930,14 +936,14 @@ public function add_transcoded_files( $file_post_array, $attachment_id, $job_for $mime_type = get_post_mime_type( $attachment_id ); if ( strpos( $mime_type, 'audio' ) !== false ) { - wp_update_post( + wp_update_post( // godam-coverage-ignore -- add_transcoded_files(): covered transitively — sole caller (handle_wp_media_transcoding_callback) already runs inside its own caller's before/after pair. array( 'ID' => $attachment_id, 'post_mime_type' => 'audio/mp3', ) ); } else { - wp_update_post( + wp_update_post( // godam-coverage-ignore -- add_transcoded_files(): covered transitively — sole caller (handle_wp_media_transcoding_callback) already runs inside its own caller's before/after pair. array( 'ID' => $attachment_id, 'post_mime_type' => 'video/mp4', @@ -973,7 +979,7 @@ public function get_post_id_by_meta_key_and_value( $key, $value ) { $meta = wp_cache_get( $cache_key, 'godam' ); if ( empty( $meta ) ) { - $meta = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->postmeta} WHERE meta_key = %s AND meta_value = %s", $key, $value ) ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery + $meta = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->postmeta} WHERE meta_key = %s AND meta_value = %s", $key, $value ) ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, godam-coverage-ignore -- get_post_id_by_meta_key_and_value(): covered transitively — every real call site (rest-routes.php, including via handle_wp_media_transcoding_callback, and class-video-migration.php) already runs inside its own before/after pair. wp_cache_set( $cache_key, $meta, 'godam', HOUR_IN_SECONDS ); } diff --git a/admin/class-rtgodam-transcoder-rest-routes.php b/admin/class-rtgodam-transcoder-rest-routes.php index c9b86df5f8..138c364f91 100644 --- a/admin/class-rtgodam-transcoder-rest-routes.php +++ b/admin/class-rtgodam-transcoder-rest-routes.php @@ -37,10 +37,6 @@ class RTGODAM_Transcoder_Rest_Routes extends WP_REST_Controller { */ public function __construct() { $this->rtgodam_transcoder_handler = new RTGODAM_Transcoder_Handler( true ); - - if ( ! defined( 'RTGODAM_TRANSCODER_CALLBACK_URL' ) ) { - define( 'RTGODAM_TRANSCODER_CALLBACK_URL', self::get_callback_url() ); - } } /** @@ -198,12 +194,38 @@ public function register_routes() { } /** - * Return the callback URL for the transcoder. + * REST paths (relative to this namespace, each with a leading slash) that + * get_callback_url() ever builds a URL for — keyed by a short, + * referenceable name. The one canonical list backing that accessor, so + * any other code that needs the *complete* set of callback paths (e.g. an + * integration wrapping every centralized-media callback in a site switch) + * has one place to read it from, instead of a hand-maintained shadow list + * that can silently miss a newly added one. + * + * @var array