@@ -198,6 +198,7 @@ public function register_routes() {
198198 public function get_items ( $ request ): WP_REST_Response {
199199 $ network = $ request ->get_param ( 'network ' );
200200 $ all_snippets = get_snippets ( [], $ network );
201+ $ all_snippets = $ this ->get_network_items ( $ all_snippets , $ network );
201202
202203 // Get collection params (page, per_page).
203204 $ collection_params = $ this ->get_collection_params ();
@@ -229,6 +230,36 @@ public function get_items( $request ): WP_REST_Response {
229230 return $ response ;
230231 }
231232
233+ /**
234+ * Retrieve and merge shared network snippets.
235+ *
236+ * @param array<Snippet> $all_snippets List of snippets to merge with.
237+ * @param bool|null $network Whether fetching network snippets.
238+ *
239+ * @return array<Snippet> Modified list of snippets.
240+ */
241+ private function get_network_items ( array $ all_snippets , $ network ): array {
242+ if ( ! is_multisite () || $ network ) {
243+ return $ all_snippets ;
244+ }
245+
246+ $ shared_ids = get_site_option ( 'shared_network_snippets ' );
247+
248+ if ( ! $ shared_ids || ! is_array ( $ shared_ids ) ) {
249+ return $ all_snippets ;
250+ }
251+
252+ $ active_shared_snippets = get_option ( 'active_shared_network_snippets ' , array () );
253+ $ shared_snippets = get_snippets ( $ shared_ids , true );
254+
255+ foreach ( $ shared_snippets as $ snippet ) {
256+ $ snippet ->shared_network = true ;
257+ $ snippet ->active = in_array ( $ snippet ->id , $ active_shared_snippets , true );
258+ }
259+
260+ return array_merge ( $ all_snippets , $ shared_snippets );
261+ }
262+
232263 /**
233264 * Retrieves one item from the collection.
234265 *
0 commit comments