@@ -307,7 +307,14 @@ protected function column_activate( Snippet $snippet ): string {
307307 return '' ;
308308 }
309309
310- if ( $ this ->is_network && ( $ snippet ->shared_network || ( ! $ this ->is_network && $ snippet ->network && ! $ snippet ->shared_network ) ) ) {
310+ // Show icon for shared network snippets on network admin.
311+ if ( $ snippet ->shared_network && $ this ->is_network ) {
312+ return '<span class="dashicons dashicons-networking network-shared" title=" ' .
313+ esc_attr__ ( 'Shared with Subsites ' , 'code-snippets ' ) .
314+ '"></span> ' ;
315+ }
316+
317+ if ( $ this ->is_network && ( ! $ this ->is_network && $ snippet ->network && ! $ snippet ->shared_network ) ) {
311318 return '' ;
312319 }
313320
@@ -377,10 +384,6 @@ protected function column_name( Snippet $snippet ): string {
377384 );
378385 }
379386
380- if ( $ snippet ->shared_network ) {
381- $ out .= ' <span class="badge"> ' . esc_html__ ( 'Shared on Network ' , 'code-snippets ' ) . '</span> ' ;
382- }
383-
384387 $ out = apply_filters ( 'code_snippets/list_table/column_name ' , $ out , $ snippet );
385388 return $ out . $ row_actions ;
386389 }
@@ -986,46 +989,43 @@ public function no_items() {
986989 /**
987990 * Fetch all shared network snippets for the current site.
988991 *
989- * @return void
992+ * @param array<Snippet> $all_snippets List of snippets to merge with.
993+ *
994+ * @return array<Snippet> Updated list of snippets.
990995 */
991- private function fetch_shared_network_snippets () {
992- /**
993- * Table data.
994- *
995- * @var $snippets array<string, Snippet[]>
996- */
997- global $ snippets ;
996+ private function fetch_shared_network_snippets ( array $ all_snippets ): array {
997+ if ( ! is_multisite () ) {
998+ return $ all_snippets ;
999+ }
9981000
999- $ ids = get_site_option ( 'shared_network_snippets ' );
1001+ $ shared_ids = get_site_option ( 'shared_network_snippets ' );
10001002
1001- if ( ! is_multisite () || ! $ ids ) {
1002- return ;
1003+ if ( ! $ shared_ids || ! is_array ( $ shared_ids ) ) {
1004+ return $ all_snippets ;
10031005 }
10041006
10051007 if ( $ this ->is_network ) {
1006- $ limit = count ( $ snippets ['all ' ] );
1007-
1008- for ( $ i = 0 ; $ i < $ limit ; $ i ++ ) {
1009- $ snippet = &$ snippets ['all ' ][ $ i ];
1010-
1011- if ( in_array ( $ snippet ->id , $ ids , true ) ) {
1008+ // Mark shared network snippets on the network admin page.
1009+ foreach ( $ all_snippets as $ snippet ) {
1010+ if ( in_array ( $ snippet ->id , $ shared_ids , true ) ) {
10121011 $ snippet ->shared_network = true ;
1013- $ snippet ->tags = array_merge ( $ snippet ->tags , array ( 'shared on network ' ) );
10141012 $ snippet ->active = false ;
10151013 }
10161014 }
10171015 } else {
1016+ // Fetch shared network snippets for subsites.
10181017 $ active_shared_snippets = get_option ( 'active_shared_network_snippets ' , array () );
1019- $ shared_snippets = get_snippets ( $ ids , true );
1018+ $ shared_snippets = get_snippets ( $ shared_ids , true );
10201019
10211020 foreach ( $ shared_snippets as $ snippet ) {
10221021 $ snippet ->shared_network = true ;
1023- $ snippet ->tags = array_merge ( $ snippet ->tags , array ( 'shared on network ' ) );
10241022 $ snippet ->active = in_array ( $ snippet ->id , $ active_shared_snippets , true );
10251023 }
10261024
1027- $ snippets [ ' all ' ] = array_merge ( $ snippets [ ' all ' ] , $ shared_snippets );
1025+ $ all_snippets = array_merge ( $ all_snippets , $ shared_snippets );
10281026 }
1027+
1028+ return $ all_snippets ;
10291029 }
10301030
10311031 /**
@@ -1062,7 +1062,7 @@ public function prepare_items() {
10621062 $ snippets = array_fill_keys ( $ this ->statuses , array () );
10631063
10641064 $ all_snippets = apply_filters ( 'code_snippets/list_table/get_snippets ' , get_snippets () );
1065- $ this ->fetch_shared_network_snippets ();
1065+ $ all_snippets = $ this ->fetch_shared_network_snippets ( $ all_snippets );
10661066
10671067 // Separate trashed snippets from the main collection
10681068 $ snippets ['trashed ' ] = array_filter ( $ all_snippets , function ( $ snippet ) {
0 commit comments