1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
<?php
use SIW\Data\Social_Network;
function siw_get_social_networks( $context = 'all' ) {
$social_networks = wp_cache_get( "{$context}", 'siw_social_networks' );
if ( false !== $social_networks ) {
return $social_networks;
}
$data = siw_get_data( 'social-networks' );
$data = wp_list_sort( $data, 'name' );
$data = array_column( $data , null, 'slug' );
$social_networks = array_map(
function( $item ) {
return new Social_Network( $item );
},
$data
);
$social_networks = array_filter(
$social_networks,
function( $social_network ) use ( $context ) {
return ( 'all' == $context
|| ( 'share' == $context && $social_network->is_for_sharing() )
|| ( 'follow' == $context && $social_network->is_for_following() )
);
}
);
wp_cache_set( "{$context}", $social_networks, 'siw_social_networks' );
return $social_networks;
}