$dependencies, 'platform' => $platform, ] ); if ( is_wp_error( $checked ) ) { // Resolver failure should not itself block import — the real // import call will still surface any genuine problem. return true; } $data = $checked->get_data(); $unmet = array_values( array_filter( $data['dependencies'] ?? [], static function ( $dep ) { $is_active = is_object( $dep ) ? ( $dep->is_active ?? null ) : ( $dep['is_active'] ?? null ); return empty( $is_active ); } ) ); if ( ! empty( $unmet ) ) { return new WP_Error( 'dependency_required', __( 'This template requires plugins that are not active on this site.', 'templately' ), [ 'dependencies' => $unmet ] ); } return true; } /** * Resolve a template's item detail regardless of which backend collection * it lives in. * * `/items/{id}` scopes its GraphQL lookup by the `type` param, and each * template type lives in a different collection: block/section templates in * `items`, page templates in `pages`, packs in `packs`. Hardcoding a single * `type` here silently 404s ("Item data not found") for every other type — * that is why page-type templates failed the dependency gate before the * import could run. Try each collection until one resolves. * * @param int $template_id * @return array|WP_Error The item detail array, or the last WP_Error. */ private static function resolve_item( int $template_id ) { $last = null; foreach ( [ 'items', 'pages', 'packs' ] as $type ) { $detail = RestDispatcher::dispatch( 'GET', '/templately/v1/items/' . $template_id, [ 'type' => $type ] ); if ( is_wp_error( $detail ) ) { $last = $detail; continue; } $data = $detail->get_data(); if ( ! empty( $data['id'] ) ) { return $data; } $last = $data; } if ( is_wp_error( $last ) ) { return $last; } return new WP_Error( 'not_found', __( 'Template not found.', 'templately' ) ); } }