Skip to content

Commit 4375678

Browse files
committed
Merge branch 'master' into develop
2 parents 0b9e264 + bb1f453 commit 4375678

File tree

2 files changed

+33
-6
lines changed

2 files changed

+33
-6
lines changed

php/class-list-table.php

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -742,11 +742,11 @@ private function fetch_shared_network_snippets() {
742742
$shared_snippets = $wpdb->get_results( $wpdb->prepare( $sql, $ids ), ARRAY_A );
743743

744744
foreach ( $shared_snippets as $index => $snippet ) {
745-
$snippet = new Snippet( $snippet );
746-
$snippet->network = true;
745+
$snippet = new Snippet( $snippet );
746+
$snippet->network = true;
747747
$snippet->shared_network = true;
748-
$snippet->tags = array_merge( $snippet->tags, array( 'shared on network' ) );
749-
$snippet->active = in_array( $snippet->id, $active_shared_snippets );
748+
$snippet->tags = array_merge( $snippet->tags, array( 'shared on network' ) );
749+
$snippet->active = in_array( $snippet->id, $active_shared_snippets );
750750

751751
$shared_snippets[ $index ] = $snippet;
752752
}
@@ -774,9 +774,11 @@ public function prepare_items() {
774774
$snippets = array_fill_keys( $this->statuses, array() );
775775

776776
/* Fetch all snippets */
777-
if ( is_multisite() && ! $this->is_network ) {
778-
$local_snippets = get_snippets( array(), false );
777+
if ( is_multisite() && ! $this->is_network && code_snippets_get_setting( 'general', 'show_network_snippets' ) ) {
779778
$network_snippets = get_snippets( array(), true );
779+
$network_snippets = array_filter( $network_snippets, array( $this, 'exclude_shared_network_snippets' ) );
780+
781+
$local_snippets = get_snippets( array(), false );
780782
$snippets['all'] = array_merge( $local_snippets, $network_snippets );
781783
} else {
782784
$snippets['all'] = get_snippets( array() );
@@ -896,6 +898,19 @@ public function prepare_items() {
896898
) );
897899
}
898900

901+
/**
902+
* Callback for array_filter() to exclude shared network snippets from the
903+
*
904+
* @ignore
905+
*
906+
* @param Snippet $snippet The current snippet item being filtered
907+
*
908+
* @return bool false if the snippet is a shared network snippet
909+
*/
910+
private function exclude_shared_network_snippets( $snippet ) {
911+
return ! $snippet->shared_network;
912+
}
913+
899914
/**
900915
* Callback for usort() used to sort snippets
901916
*

php/settings/settings-fields.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,14 @@ function code_snippets_get_settings_fields() {
6565
'label' => __( 'Show snippet descriptions on admin pages', 'code-snippets' ),
6666
'default' => true,
6767
),
68+
69+
'show_network_snippets' => array(
70+
'name' => __( 'Show Network Snippets', 'code-snippets' ),
71+
'type' => 'checkbox',
72+
'label' => __( 'Show network-wide snippets in the snippets table on subsites', 'code-snippets' ),
73+
'default' => true,
74+
),
75+
6876
'disable_prism' => array(
6977
'name' => __( 'Disable shortcode syntax highlighter', 'code-snippets' ),
7078
'type' => 'checkbox',
@@ -73,6 +81,10 @@ function code_snippets_get_settings_fields() {
7381
),
7482
);
7583

84+
if ( ! is_multisite() ) {
85+
unset( $fields['general']['show_network_snippets'] );
86+
}
87+
7688
/* Description Editor settings section */
7789
$fields['description_editor'] = array(
7890

0 commit comments

Comments
 (0)