Skip to content

Commit

Permalink
Merge branch 'master' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
sheabunge committed May 13, 2017
2 parents 0b9e264 + bb1f453 commit 4375678
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 6 deletions.
27 changes: 21 additions & 6 deletions php/class-list-table.php
Original file line number Diff line number Diff line change
Expand Up @@ -742,11 +742,11 @@ private function fetch_shared_network_snippets() {
$shared_snippets = $wpdb->get_results( $wpdb->prepare( $sql, $ids ), ARRAY_A );

foreach ( $shared_snippets as $index => $snippet ) {
$snippet = new Snippet( $snippet );
$snippet->network = true;
$snippet = new Snippet( $snippet );
$snippet->network = true;
$snippet->shared_network = true;
$snippet->tags = array_merge( $snippet->tags, array( 'shared on network' ) );
$snippet->active = in_array( $snippet->id, $active_shared_snippets );
$snippet->tags = array_merge( $snippet->tags, array( 'shared on network' ) );
$snippet->active = in_array( $snippet->id, $active_shared_snippets );

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

/* Fetch all snippets */
if ( is_multisite() && ! $this->is_network ) {
$local_snippets = get_snippets( array(), false );
if ( is_multisite() && ! $this->is_network && code_snippets_get_setting( 'general', 'show_network_snippets' ) ) {
$network_snippets = get_snippets( array(), true );
$network_snippets = array_filter( $network_snippets, array( $this, 'exclude_shared_network_snippets' ) );

$local_snippets = get_snippets( array(), false );
$snippets['all'] = array_merge( $local_snippets, $network_snippets );
} else {
$snippets['all'] = get_snippets( array() );
Expand Down Expand Up @@ -896,6 +898,19 @@ public function prepare_items() {
) );
}

/**
* Callback for array_filter() to exclude shared network snippets from the
*
* @ignore
*
* @param Snippet $snippet The current snippet item being filtered
*
* @return bool false if the snippet is a shared network snippet
*/
private function exclude_shared_network_snippets( $snippet ) {
return ! $snippet->shared_network;
}

/**
* Callback for usort() used to sort snippets
*
Expand Down
12 changes: 12 additions & 0 deletions php/settings/settings-fields.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,14 @@ function code_snippets_get_settings_fields() {
'label' => __( 'Show snippet descriptions on admin pages', 'code-snippets' ),
'default' => true,
),

'show_network_snippets' => array(
'name' => __( 'Show Network Snippets', 'code-snippets' ),
'type' => 'checkbox',
'label' => __( 'Show network-wide snippets in the snippets table on subsites', 'code-snippets' ),
'default' => true,
),

'disable_prism' => array(
'name' => __( 'Disable shortcode syntax highlighter', 'code-snippets' ),
'type' => 'checkbox',
Expand All @@ -73,6 +81,10 @@ function code_snippets_get_settings_fields() {
),
);

if ( ! is_multisite() ) {
unset( $fields['general']['show_network_snippets'] );
}

/* Description Editor settings section */
$fields['description_editor'] = array(

Expand Down

0 comments on commit 4375678

Please sign in to comment.