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 / php / Admin / Contextual_Help.php

Contextual_Help.php in Code Snippets 4.0.0-beta.2, at php/Admin/Contextual_Help.php

416 lines 12.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Code_Snippets\Admin;
4
5 use WP_Screen;
6 use function Code_Snippets\code_snippets;
7
8 /**
9 * This file holds all the content for the contextual help screens.
10 *
11 * @package Code_Snippets
12 */
13 class Contextual_Help {
14
15 /**
16 * Current screen object
17 *
18 * @see get_current_screen()
19 *
20 * @var WP_Screen
21 */
22 public WP_Screen $screen;
23
24 /**
25 * Name of current screen
26 *
27 * @see get_current_screen()
28 *
29 * @var string
30 */
31 public string $screen_name;
32
33 /**
34 * Class constructor
35 *
36 * @param string $screen_name Name of current screen.
37 */
38 public function __construct( string $screen_name ) {
39 $this->screen_name = $screen_name;
40 }
41
42 /**
43 * Load the contextual help
44 */
45 public function load() {
46 $this->screen = get_current_screen();
47
48 switch ( $this->screen_name ) {
49 case 'manage':
50 $this->load_manage_help();
51 break;
52
53 case 'edit':
54 $this->load_edit_help();
55 break;
56
57 case 'cloud-library':
58 $this->load_cloud_library_help();
59 break;
60
61 case 'blueprints':
62 $this->load_blueprints_help();
63 break;
64
65 case 'ai-agent':
66 $this->load_ai_agent_help();
67 break;
68
69 case 'insights':
70 $this->load_insights_help();
71 break;
72
73 case 'import':
74 $this->load_import_help();
75 break;
76
77 case 'settings':
78 $this->load_settings_help();
79 break;
80
81 case 'welcome':
82 $this->load_welcome_help();
83 break;
84 }
85
86 $this->load_help_sidebar();
87 }
88
89 /**
90 * Load the help sidebar
91 */
92 private function load_help_sidebar() {
93 $sidebar_links = [
94 'https://wordpress.org/plugins/code-snippets' => __( 'About Plugin', 'code-snippets' ),
95 'https://codesnippets.pro/docs/faq/' => __( 'FAQ', 'code-snippets' ),
96 'https://wordpress.org/support/plugin/code-snippets' => __( 'Support Forum', 'code-snippets' ),
97 'https://codesnippets.pro' => __( 'Plugin Website', 'code-snippets' ),
98 ];
99
100 $allowed_html = [
101 'p' => [],
102 'strong' => [],
103 'a' => [ 'href' => [] ],
104 ];
105
106 $contents = sprintf( "<p><strong>%s</strong></p>\n", esc_html__( 'For more information:', 'code-snippets' ) );
107
108 foreach ( $sidebar_links as $url => $label ) {
109 $contents .= "\n" . sprintf( '<p><a href="%s">%s</a></p>', esc_url( $url ), esc_html( $label ) );
110 }
111
112 $this->screen->set_help_sidebar( wp_kses( $contents, $allowed_html ) );
113 }
114
115 /**
116 * Add a help tab to the current screen.
117 *
118 * @param string $id Screen ID.
119 * @param string $title Screen title.
120 * @param string|array<string> $paragraphs List of paragraphs to display as content.
121 *
122 * @return void
123 */
124 private function add_help_tab( string $id, string $title, $paragraphs ) {
125 $this->screen->add_help_tab(
126 array(
127 'title' => $title,
128 'id' => $id,
129 'content' => wp_kses_post(
130 implode(
131 "\n",
132 array_map(
133 function ( $content ) {
134 return '<p>' . $content . '</p>';
135 },
136 is_array( $paragraphs ) ? $paragraphs : [ $paragraphs ]
137 )
138 )
139 ),
140 )
141 );
142 }
143
144 /**
145 * Reusable introduction text
146 *
147 * @return string
148 */
149 private function get_intro_text(): string {
150 return __( 'Snippets are similar to plugins - they both extend and expand the functionality of WordPress. Snippets are more light-weight, just a few lines of code, and do not put as much load on your server. ', 'code-snippets' );
151 }
152
153 /**
154 * Register and handle the help tabs for the manage snippets admin page
155 */
156 private function load_manage_help() {
157 $this->add_help_tab(
158 'overview',
159 __( 'Overview', 'code-snippets' ),
160 [
161 $this->get_intro_text(),
162 __( 'Here you can manage your existing snippets and perform tasks on them such as activating, deactivating, deleting and exporting.', 'code-snippets' ),
163 ]
164 );
165
166 $this->add_help_tab(
167 'safe-mode',
168 __( 'Safe Mode', 'code-snippets' ),
169 [
170 __( 'Be sure to check your snippets for errors before you activate them, as a faulty snippet could bring your whole blog down. If your site starts doing strange things, deactivate all your snippets and activate them one at a time.', 'code-snippets' ),
171 __( "If something goes wrong with a snippet, and you can't use WordPress, you can cause all snippets to stop executing by turning on <strong>safe mode</strong>.", 'code-snippets' ),
172 /* translators: %s: URL to Code Snippets Pro Docs */
173 sprintf( __( 'You can find out how to enable safe mode in the <a href="%s">Code Snippets Pro Docs</a>.', 'code-snippets' ), 'https://codesnippets.pro/doc/safe-mode/' ),
174 ]
175 );
176 }
177
178 /**
179 * Register and handle the help tabs for the single snippet admin page
180 */
181 private function load_edit_help() {
182 $this->add_help_tab(
183 'overview',
184 __( 'Overview', 'code-snippets' ),
185 [
186 $this->get_intro_text() .
187 __( 'Here you can add a new snippet, or edit an existing one.', 'code-snippets' ),
188 /* translators: %s: URL to Code Snippets Pro Docs */
189 sprintf( __( "If you're not sure about the types of snippets you can add, take a look at the <a href=\"%s\">Code Snippets Pro Docs</a> for inspiration.", 'code-snippets' ), 'https://codesnippets.pro/docs/adding-snippets/' ),
190 ]
191 );
192
193 $this->add_help_tab(
194 'adding',
195 __( 'Adding Snippets', 'code-snippets' ),
196 [
197 __( 'You need to fill out the name and code fields for your snippet to be added. While the description field will add more information about how your snippet works, what is does and where you found it, it is completely optional.', 'code-snippets' ),
198 __( 'Please be sure to check that your snippet is valid PHP code and will not produce errors before adding it through this page. While doing so will not become active straight away, it will help to minimize the chance of a faulty snippet becoming active on your site.', 'code-snippets' ),
199 ]
200 );
201 }
202
203 /**
204 * Register and handle the help tabs for the Cloud Library demo page.
205 */
206 private function load_cloud_library_help() {
207 $this->add_help_tab(
208 'overview',
209 __( 'Overview', 'code-snippets' ),
210 [
211 $this->get_intro_text(),
212 __( 'Cloud Library lets you reuse snippets across the sites connected to your Code Snippets Cloud.', 'code-snippets' ),
213 ]
214 );
215 }
216
217 /**
218 * Register and handle the help tabs for the Blueprints demo page.
219 */
220 private function load_blueprints_help() {
221 $this->add_help_tab(
222 'overview',
223 __( 'Overview', 'code-snippets' ),
224 [
225 $this->get_intro_text(),
226 __( 'Blueprints help you create snippets from templates for supported WordPress features.', 'code-snippets' ),
227 ]
228 );
229
230 $this->add_help_tab(
231 'using-blueprints',
232 __( 'Using Blueprints', 'code-snippets' ),
233 [
234 __( 'Blueprints provide guided forms for creating snippets from supported WordPress features.', 'code-snippets' ),
235 __( 'Choose a blueprint, complete its fields and review the generated snippet before saving it.', 'code-snippets' ),
236 ]
237 );
238
239 $this->add_help_tab(
240 'generating-snippets',
241 __( 'Generating Snippets', 'code-snippets' ),
242 [
243 __( 'Code Snippets Pro combines your choices with the required boilerplate to generate a complete snippet.', 'code-snippets' ),
244 __( 'Review the generated snippet before saving or activating it on your site.', 'code-snippets' ),
245 ]
246 );
247 }
248
249 /**
250 * Register and handle the help tabs for the AI Agent demo page.
251 */
252 private function load_ai_agent_help() {
253 $this->add_help_tab(
254 'overview',
255 __( 'Overview', 'code-snippets' ),
256 [
257 $this->get_intro_text(),
258 __( 'The AI Agent can plan, build and refine snippets from prompts.', 'code-snippets' ),
259 ]
260 );
261
262 $this->add_help_tab(
263 'writing-prompts',
264 __( 'Writing Prompts', 'code-snippets' ),
265 [
266 __( 'Describe what you want your site to do in plain language, including any relevant details.', 'code-snippets' ),
267 __( 'The AI Agent uses your prompt to prepare a plan before creating snippets.', 'code-snippets' ),
268 ]
269 );
270
271 $this->add_help_tab(
272 'reviewing-plans',
273 __( 'Reviewing Plans', 'code-snippets' ),
274 [
275 __( 'Review the plan to see what the AI Agent intends to build before it creates any snippets.', 'code-snippets' ),
276 __( 'Accept the plan to continue, or ask for changes when it does not match your requirements.', 'code-snippets' ),
277 ]
278 );
279
280 $this->add_help_tab(
281 'reviewing-snippets',
282 __( 'Reviewing Snippets', 'code-snippets' ),
283 [
284 __( 'New snippets are added inactive, so you can review the code before it runs on your site.', 'code-snippets' ),
285 __( 'Activate each snippet only after confirming that it does what you expect.', 'code-snippets' ),
286 ]
287 );
288 }
289
290 /**
291 * Register and handle the help tabs for the Insights admin page.
292 */
293 private function load_insights_help() {
294 $this->add_help_tab(
295 'overview',
296 __( 'Overview', 'code-snippets' ),
297 [
298 $this->get_intro_text() .
299 __( 'Here you can view snippets statistics, and get insights how the snippets are being used on this website.', 'code-snippets' ),
300 ]
301 );
302
303 $this->add_help_tab(
304 'insights',
305 __( 'Insights', 'code-snippets' ),
306 __( 'Get detailed information about your snippets usage, including which snippets types are being most used, their activation status, where they are located, and more.', 'code-snippets' )
307 );
308 }
309
310 /**
311 * Register and handle the help tabs for the import snippets admin page
312 */
313 private function load_import_help() {
314 $manage_url = code_snippets()->get_menu_url( 'manage' );
315
316 $this->add_help_tab(
317 'overview',
318 __( 'Overview', 'code-snippets' ),
319 [
320 $this->get_intro_text() .
321 __( 'Here you can load snippets from a code snippets export file into the database alongside existing snippets.', 'code-snippets' ),
322 ]
323 );
324
325 $this->add_help_tab(
326 'import',
327 __( 'Importing', 'code-snippets' ),
328 [
329 __( 'You can load your snippets from a code snippets export file using this page.', 'code-snippets' ) .
330 /* translators: %s: URL to Snippets admin menu */
331 sprintf( __( 'Imported snippets will be added to the database along with your existing snippets. Regardless of whether the snippets were active on the previous site, imported snippets are always inactive until activated using the <a href="%s">Manage Snippets</a> page.', 'code-snippets' ), $manage_url ),
332 ]
333 );
334
335 $this->add_help_tab(
336 'export',
337 __( 'Exporting', 'code-snippets' ),
338 /* translators: %s: URL to Manage Snippets admin menu */
339 sprintf( __( 'You can save your snippets to a code snippets export file using the <a href="%s">Manage Snippets</a> page.', 'code-snippets' ), $manage_url )
340 );
341
342 $this->add_help_tab(
343 'migrating',
344 __( 'Migrating', 'code-snippets' ),
345 __( 'If you are using another snippets plugin, you can import those existing snippets to your Code Snippets library.', 'code-snippets' )
346 );
347 }
348
349 /**
350 * Register and handle the help tabs for the settings admin page.
351 */
352 private function load_settings_help() {
353 $this->add_help_tab(
354 'overview',
355 __( 'Overview', 'code-snippets' ),
356 [
357 $this->get_intro_text() .
358 __( 'Here you can configure how Code Snippets works on your site, including snippet editing, execution and display preferences.', 'code-snippets' ),
359 ]
360 );
361
362 $this->add_help_tab(
363 'editing',
364 __( 'Editing', 'code-snippets' ),
365 __( 'Configure snippet fields and the code editor, including its theme, indentation and display preferences.', 'code-snippets' ),
366 );
367
368 $this->add_help_tab(
369 'running',
370 __( 'Running', 'code-snippets' ),
371 __( 'Choose how snippets run and whether new snippets are activated when you save them.', 'code-snippets' ),
372 );
373
374 $this->add_help_tab(
375 'library',
376 __( 'Library', 'code-snippets' ),
377 __( 'Manage snippet revisions, deleted snippets and cloud library connections.', 'code-snippets' ),
378 );
379
380 $this->add_help_tab(
381 'interface',
382 __( 'Interface', 'code-snippets' ),
383 __( 'Configure the snippets list, code highlighting, the admin bar menu and upgrade notices.', 'code-snippets' ),
384 );
385
386 $this->add_help_tab(
387 'advanced',
388 __( 'Advanced', 'code-snippets' ),
389 __( 'Control access, maintenance actions, version changes and complete uninstallation.', 'code-snippets' ),
390 );
391 }
392
393 /**
394 * Register and handle the help tabs for the welcome admin page.
395 */
396 private function load_welcome_help() {
397 $this->add_help_tab(
398 'overview',
399 __( 'Overview', 'code-snippets' ),
400 [
401 $this->get_intro_text() .
402 __( 'Here you can find the latest Code Snippets news and release updates, plus helpful articles and partner offers.', 'code-snippets' ),
403 ]
404 );
405
406 $this->add_help_tab(
407 'whats-new',
408 __( "What's New", 'code-snippets' ),
409 [
410 __( 'The Latest Changes section summarizes new features, improvements, bug fixes, security updates and other changes in recent releases.', 'code-snippets' ),
411 __( 'Select View Changelog to read the complete release notes.', 'code-snippets' ),
412 ]
413 );
414 }
415 }
416