PluginProbe
Code Snippets / 3.6.3
Code Snippets v3.6.3
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 3.0.1 All 64 releases
code-snippets / php / class-contextual-help.php

class-contextual-help.php in Code Snippets 3.6.3, at php/class-contextual-help.php

187 lines 6.2 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;
4
5 use WP_Screen;
6
7 /**
8 * This file holds all the content for the contextual help screens.
9 *
10 * @package Code_Snippets
11 */
12 class Contextual_Help {
13
14 /**
15 * Current screen object
16 *
17 * @see get_current_screen()
18 *
19 * @var WP_Screen
20 */
21 public $screen;
22
23 /**
24 * Name of current screen
25 *
26 * @see get_current_screen()
27 *
28 * @var string
29 */
30 public $screen_name;
31
32 /**
33 * Class constructor
34 *
35 * @param string $screen_name Name of current screen.
36 */
37 public function __construct( string $screen_name ) {
38 $this->screen_name = $screen_name;
39 }
40
41 /**
42 * Load the contextual help
43 */
44 public function load() {
45 $this->screen = get_current_screen();
46
47 if ( method_exists( $this, "load_{$this->screen_name}_help" ) ) {
48 call_user_func( array( $this, "load_{$this->screen_name}_help" ) );
49 }
50
51 $this->load_help_sidebar();
52 }
53
54 /**
55 * Load the help sidebar
56 */
57 private function load_help_sidebar() {
58 $sidebar_links = [
59 'https://wordpress.org/plugins/code-snippets' => __( 'About Plugin', 'code-snippets' ),
60 'https://help.codesnippets.pro/collection/3-faq' => __( 'FAQ', 'code-snippets' ),
61 'https://wordpress.org/support/plugin/code-snippets' => __( 'Support Forum', 'code-snippets' ),
62 'https://codesnippets.pro' => __( 'Plugin Website', 'code-snippets' ),
63 ];
64
65 $contents = '<p><strong>' . __( 'For more information:', 'code-snippets' ) . "</strong></p>\n";
66
67 foreach ( $sidebar_links as $url => $label ) {
68 $contents .= "\n" . sprintf( '<p><a href="%s">%s</a></p>', esc_url( $url ), esc_html( $label ) );
69 }
70
71 $this->screen->set_help_sidebar( wp_kses_post( $contents ) );
72 }
73
74 /**
75 * Add a help tab to the current screen.
76 *
77 * @param string $id Screen ID.
78 * @param string $title Screen title.
79 * @param string|array<string> $paragraphs List of paragraphs to display as content.
80 *
81 * @return void
82 */
83 private function add_help_tab( string $id, string $title, $paragraphs ) {
84 $this->screen->add_help_tab(
85 array(
86 'title' => $title,
87 'id' => $id,
88 'content' => wp_kses_post(
89 implode(
90 "\n",
91 array_map(
92 function ( $content ) {
93 return '<p>' . $content . '</p>';
94 },
95 is_array( $paragraphs ) ? $paragraphs : [ $paragraphs ]
96 )
97 )
98 ),
99 )
100 );
101 }
102
103 /**
104 * Reusable introduction text
105 *
106 * @return string
107 */
108 private function get_intro_text(): string {
109 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' );
110 }
111
112 /**
113 * Register and handle the help tabs for the manage snippets admin page
114 */
115 private function load_manage_help() {
116 $this->add_help_tab(
117 'overview',
118 __( 'Overview', 'code-snippets' ),
119 $this->get_intro_text() .
120 __( 'Here you can manage your existing snippets and perform tasks on them such as activating, deactivating, deleting and exporting.', 'code-snippets' )
121 );
122
123 $this->add_help_tab(
124 'safe-mode',
125 __( 'Safe Mode', 'code-snippets' ),
126 [
127 __( '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' ),
128 __( "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' ),
129 __( 'You can find out how to enable safe mode in the <a href="https://help.codesnippets.pro/article/12-safe-mode">Code Snippets Pro Docs</a>.', 'code-snippets' ),
130 ]
131 );
132 }
133
134 /**
135 * Register and handle the help tabs for the single snippet admin page
136 */
137 private function load_edit_help() {
138 $this->add_help_tab(
139 'overview',
140 __( 'Overview', 'code-snippets' ),
141 [
142 $this->get_intro_text() .
143 __( 'Here you can add a new snippet, or edit an existing one.', 'code-snippets' ),
144 __( "If you're not sure about the types of snippets you can add, take a look at the <a href=\"https://help.codesnippets.pro/collection/2-adding-snippets\">Code Snippets Pro Docs</a> for inspiration.", 'code-snippets' ),
145 ]
146 );
147
148 $this->add_help_tab(
149 'adding',
150 __( 'Adding Snippets', 'code-snippets' ),
151 [
152 __( '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' ),
153 __( '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 minimise the chance of a faulty snippet becoming active on your site.', 'code-snippets' ),
154 ]
155 );
156 }
157
158 /**
159 * Register and handle the help tabs for the import snippets admin page
160 */
161 private function load_import_help() {
162 $manage_url = code_snippets()->get_menu_url( 'manage' );
163
164 $this->add_help_tab(
165 'overview',
166 __( 'Overview', 'code-snippets' ),
167 $this->get_intro_text() .
168 __( 'Here you can load snippets from a code snippets export file into the database alongside existing snippets.', 'code-snippets' )
169 );
170
171 $this->add_help_tab(
172 'import',
173 __( 'Importing', 'code-snippets' ),
174 __( 'You can load your snippets from a code snippets export file using this page.', 'code-snippets' ) .
175 /* translators: %s: URL to Snippets admin menu */
176 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 )
177 );
178
179 $this->add_help_tab(
180 'export',
181 __( 'Exporting', 'code-snippets' ),
182 /* translators: %s: URL to Manage Snippets admin menu */
183 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 )
184 );
185 }
186 }
187