Skip to content

Commit 1a89a7f

Browse files
authored
Merge pull request #289 from codesnippetspro/fix/share-with-subsites
fix: share with subsites
2 parents 6020f8f + 88cf042 commit 1a89a7f

File tree

9 files changed

+327
-141
lines changed

9 files changed

+327
-141
lines changed

src/composer.lock

Lines changed: 32 additions & 33 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/css/common/_badges.scss

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,27 @@
2020
gap: 5px;
2121
line-height: 1;
2222

23+
@at-root .row-actions & {
24+
color: #8c8c8c;
25+
padding-inline: 0px;
26+
text-transform: capitalize;
27+
font-weight: 500;
28+
}
29+
2330
.dashicons {
2431
font-size: 18px;
2532
inline-size: 18px;
2633
block-size: 18px;
2734
}
2835
}
2936

37+
.network-shared {
38+
color: #2271b1;
39+
font-size: 22px;
40+
width: 100%;
41+
cursor: help;
42+
}
43+
3044
.small-badge {
3145
block-size: auto;
3246
inline-size: auto;
@@ -73,6 +87,33 @@
7387
.inverted-badges .badge {
7488
color: #fff;
7589
background-color: #a7aaad;
90+
border-color: #fff !important;
91+
92+
.dashicons {
93+
color: #fff;
94+
}
95+
}
96+
97+
.nav-tab-inactive {
98+
$colors: map.get(theme.$badges, 'pro');
99+
$text-color: list.nth($colors, 2);
100+
$background-color: list.nth($colors, 1);
101+
102+
.badge.pro-badge {
103+
color: $text-color;
104+
background-color: $background-color;
105+
}
106+
107+
&:hover {
108+
&.button, .dashicons-external {
109+
color: #3c434a;
110+
}
111+
112+
.badge.pro-badge {
113+
color: $background-color;
114+
background-color: $text-color;
115+
}
116+
}
76117
}
77118

78119
.nav-tab-inactive {

src/css/manage.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
}
2525
}
2626

27-
.active-snippet .column-name > a {
27+
.active-snippet .column-name > .snippet-name {
2828
font-weight: 600;
2929
}
3030

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,41 @@
11
import React from 'react'
22
import { __ } from '@wordpress/i18n'
33
import { useSnippetForm } from '../../../hooks/useSnippetForm'
4+
import { Tooltip } from '../../common/Tooltip'
45

56
export const MultisiteSharingSettings: React.FC = () => {
67
const { snippet, setSnippet, isReadOnly } = useSnippetForm()
78

89
return (
9-
<div>
10+
<div className="inline-form-field activation-switch-container">
1011
<h4>
11-
<label htmlFor="snippet_sharing">
12-
{__('Share with Subsites', 'code-snippets')}
13-
</label>
12+
{__('Share with Subsites', 'code-snippets')}
1413
</h4>
1514

16-
<div className="tooltip-bottom">
17-
<span className="dashicons dashicons-editor-help"></span>
18-
<span className="tooltip-content">{
19-
__('Instead of running on every site, allow this snippet to be activated on individual sites on the network.', 'code-snippets')
20-
}</span>
21-
</div>
15+
<Tooltip inline start>
16+
{__('Instead of running on every site, allow this snippet to be activated on individual sites on the network.', 'code-snippets')}
17+
</Tooltip>
2218

23-
<input
24-
id="snippet_sharing"
25-
name="snippet_sharing"
26-
type="checkbox"
27-
className="switch"
28-
checked={true === snippet.shared_network}
29-
disabled={isReadOnly}
30-
onChange={event =>
31-
setSnippet(previous => ({
32-
...previous,
33-
active: false,
34-
shared_network: event.target.checked
35-
}))}
36-
/>
19+
<label>
20+
{snippet.shared_network
21+
? __('Enabled', 'code-snippets')
22+
: __('Disabled', 'code-snippets')}
23+
24+
<input
25+
id="snippet_sharing"
26+
name="snippet_sharing"
27+
type="checkbox"
28+
className="switch"
29+
checked={!!snippet.shared_network}
30+
disabled={isReadOnly}
31+
onChange={event =>
32+
setSnippet(previous => ({
33+
...previous,
34+
active: false,
35+
shared_network: event.target.checked
36+
}))}
37+
/>
38+
</label>
3739
</div>
3840
)
3941
}

src/js/utils/snippets/api.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ const mapToSchema = ({
3535
priority,
3636
active,
3737
network,
38+
shared_network,
3839
conditionId
3940
}: Partial<Snippet>): WritableSnippetSchema => ({
4041
name,
@@ -45,6 +46,7 @@ const mapToSchema = ({
4546
priority,
4647
active,
4748
network,
49+
shared_network,
4850
condition_id: conditionId
4951
})
5052

src/php/class-admin.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ public function run() {
6363
add_action( 'init', array( $this, 'load_classes' ), 11 );
6464

6565
add_filter( 'mu_menu_items', array( $this, 'mu_menu_items' ) );
66+
add_filter( 'manage_sites_action_links', array( $this, 'add_sites_row_action' ), 10, 2 );
6667
add_filter( 'plugin_action_links_' . plugin_basename( PLUGIN_FILE ), array( $this, 'plugin_action_links' ), 10, 2 );
6768
add_filter( 'plugin_row_meta', array( $this, 'plugin_row_meta' ), 10, 2 );
6869
add_filter( 'debug_information', array( $this, 'debug_information' ) );
@@ -89,6 +90,29 @@ public function mu_menu_items( array $menu_items ): array {
8990
return $menu_items;
9091
}
9192

93+
/**
94+
* Add a "Snippets" row action to the Network Sites table.
95+
*
96+
* @param array<string, string> $actions Existing row actions.
97+
* @param int $site_id Current site ID.
98+
*
99+
* @return array<string, string>
100+
*/
101+
public function add_sites_row_action( array $actions, int $site_id ): array {
102+
if ( ! is_multisite() || ! current_user_can( code_snippets()->get_network_cap_name() ) ) {
103+
return $actions;
104+
}
105+
106+
$menu_slug = code_snippets()->get_menu_slug();
107+
$actions['code_snippets'] = sprintf(
108+
'<a href="%s">%s</a>',
109+
esc_url( get_admin_url( $site_id, 'admin.php?page=' . $menu_slug ) ),
110+
esc_html__( 'Snippets', 'code-snippets' )
111+
);
112+
113+
return $actions;
114+
}
115+
92116
/**
93117
* Modify the action links for this plugin.
94118
*

0 commit comments

Comments
 (0)