PluginProbe
Code Snippets / 4.0.0-beta.2
Code Snippets v4.0.0-beta.2
4.0.0-beta.2 3.10.2 3.10.1 3.10.0 3.10.0-beta.2 3.10.0-beta.1 4.0.0-beta.1 3.9.6 trunk 2.10.0 2.10.1 2.12.0 2.12.1 2.13.0 2.13.1 2.13.2 2.13.3 2.14.0 2.14.1 2.14.2 2.14.3 2.14.4 2.14.5 2.14.6 3.0.0 All 65 releases
code-snippets / js / components / ManageMenu / CloudLibraryDemo / demoCloudSnippets.ts

demoCloudSnippets.ts in Code Snippets 4.0.0-beta.2, at js/components/ManageMenu/CloudLibraryDemo/demoCloudSnippets.ts

101 lines 3.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import { __ } from '@wordpress/i18n'
2 import { CloudStatus } from '../../../types/schema/CloudSnippetSchema'
3 import type { CloudSnippetSchema } from '../../../types/schema/CloudSnippetSchema'
4
5 /** The snippet the walkthrough previews, downloads, and then shows synced. */
6 export const FEATURED_SNIPPET_ID = 4821
7
8 const CODEVAULT = __('My Code Vault', 'code-snippets')
9
10 const FEATURED_CODE = `add_filter( 'wp_mail_from_name', function () {
11 return get_bloginfo( 'name' );
12 } );
13
14 add_filter( 'wp_mail_from', function ( $from ) {
15 $domain = wp_parse_url( home_url(), PHP_URL_HOST );
16
17 return $domain ? 'no-reply@' . str_ireplace( 'www.', '', $domain ) : $from;
18 } );`
19
20 const base = (snippet: Partial<CloudSnippetSchema>): CloudSnippetSchema => ({
21 id: 0,
22 slug: '',
23 name: '',
24 description: '',
25 code: '',
26 tags: [],
27 scope: 'global',
28 codevault: CODEVAULT,
29 total_votes: 0,
30 vote_count: 0,
31 wp_tested: '6.8',
32 status: CloudStatus.Private,
33 created: '2026-05-04T09:12:00Z',
34 updated: '2026-07-22T14:38:00Z',
35 revision: 1,
36 is_owner: true,
37 local_id: null,
38 update_available: false,
39 ...snippet
40 })
41
42 /**
43 * A small cloud library, deliberately short: the walkthrough scrolls past it to
44 * the closing panel, so a full page of rows would bury the ending.
45 */
46 // eslint-disable-next-line max-lines-per-function -- one library of example content.
47 export const getDemoCloudSnippets = (): CloudSnippetSchema[] => [
48 base({
49 id: FEATURED_SNIPPET_ID,
50 slug: 'sender-name-and-address',
51 name: __('Fix outgoing email sender name', 'code-snippets'),
52 description: __('Sends site email from the site name and a no-reply address on your own domain, instead of “WordPress”.', 'code-snippets'),
53 code: FEATURED_CODE,
54 tags: ['email', 'admin'],
55 scope: 'global',
56 status: CloudStatus.Pro_Verified,
57 updated: '2026-08-11T10:04:00Z'
58 }),
59 base({
60 id: 4788,
61 slug: 'disable-comments-everywhere',
62 name: __('Disable comments everywhere', 'code-snippets'),
63 description: __('Closes comments on every post type and hides the comment menus from the admin.', 'code-snippets'),
64 code: "add_filter( 'comments_open', '__return_false', 20, 2 );",
65 tags: ['comments', 'cleanup'],
66 scope: 'global',
67 status: CloudStatus.Private,
68 updated: '2026-07-02T16:20:00Z'
69 }),
70 base({
71 id: 4712,
72 slug: 'checkout-field-styles',
73 name: __('Checkout field styles', 'code-snippets'),
74 description: __('Tidies the spacing and focus states on the checkout form fields.', 'code-snippets'),
75 code: [
76 '.woocommerce-checkout .form-row input:focus {',
77 '\toutline: 2px solid #2271b1;',
78 '}'
79 ].join('\n'),
80 tags: ['woocommerce', 'styles'],
81 scope: 'site-css',
82 status: CloudStatus.Public,
83 updated: '2026-06-18T08:55:00Z'
84 }),
85 base({
86 id: 4655,
87 slug: 'lazy-load-embeds',
88 name: __('Lazy load video embeds', 'code-snippets'),
89 description: __('Defers YouTube and Vimeo iframes until they are scrolled into view.', 'code-snippets'),
90 code: [
91 "add_filter( 'embed_oembed_html', function ( $html ) {",
92 "\treturn str_replace( '<iframe', '<iframe loading=\"lazy\"', $html );",
93 '} );'
94 ].join('\n'),
95 tags: ['performance'],
96 scope: 'front-end',
97 status: CloudStatus.AI_Verified,
98 updated: '2026-05-29T11:47:00Z'
99 })
100 ]
101